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
294d3ce4371c56df7e4c233e254fd710f08deb16
20,730
agda
Agda
src/Computability.agda
nad/chi
30966769b8cbd46aa490b6964a4aa0e67a7f9ab1
[ "MIT" ]
2
2020-05-21T22:58:07.000Z
2020-10-20T16:27:00.000Z
src/Computability.agda
nad/chi
30966769b8cbd46aa490b6964a4aa0e67a7f9ab1
[ "MIT" ]
1
2020-05-21T23:29:54.000Z
2020-06-08T11:08:25.000Z
src/Computability.agda
nad/chi
30966769b8cbd46aa490b6964a4aa0e67a7f9ab1
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Partial functions, computability ------------------------------------------------------------------------ open import Atom module Computability (atoms : χ-atoms) where open import Equality.Propositional.Cubical open import Logical-equivalence using (_⇔_) open import Prelude as P hiding (_∘_; Decidable) open import Tactic.By.Propositional open import Bool equality-with-J open import Bijection equality-with-J using (_↔_) open import Double-negation equality-with-J open import Equality.Decision-procedures equality-with-J import Equivalence equality-with-J as Eq open import Function-universe equality-with-J hiding (id; _∘_) open import H-level equality-with-J as H-level open import H-level.Closure equality-with-J open import H-level.Truncation.Propositional equality-with-paths as Trunc open import Injection equality-with-J using (Injective) open import Monad equality-with-J open import Chi atoms open import Coding atoms import Coding.Instances atoms as Dummy open import Deterministic atoms open import Free-variables atoms open import Propositional atoms open import Reasoning atoms open import Values atoms -- Partial functions for which the relation defining the partial -- function must be propositional. record _⇀_ {a b} (A : Type a) (B : Type b) : Type (lsuc (a ⊔ b)) where infix 4 _[_]=_ field -- The relation defining the partial function. _[_]=_ : A → B → Type (a ⊔ b) -- The relation must be deterministic and propositional. deterministic : ∀ {a b₁ b₂} → _[_]=_ a b₁ → _[_]=_ a b₂ → b₁ ≡ b₂ propositional : ∀ {a b} → Is-proposition (_[_]=_ a b) -- A simple lemma. ∃[]=-propositional : ∀ {a} → Is-proposition (∃ (_[_]=_ a)) ∃[]=-propositional (b₁ , [a]=b₁) (b₂ , [a]=b₂) = Σ-≡,≡→≡ (deterministic [a]=b₁ [a]=b₂) (propositional _ _) open _⇀_ public using (_[_]=_) -- Totality. The definition is parametrised by something which could -- be a modality. Total : ∀ {a b} {A : Type a} {B : Type b} → (Type (a ⊔ b) → Type (a ⊔ b)) → A ⇀ B → Type (a ⊔ b) Total P f = ∀ a → P (∃ λ b → f [ a ]= b) -- Totality with ∥_∥ as the modality implies totality with the -- identity function as the modality. total-with-∥∥→total : ∀ {a b} {A : Type a} {B : Type b} (f : A ⇀ B) → Total ∥_∥ f → Total id f total-with-∥∥→total f total a = Trunc.rec (_⇀_.∃[]=-propositional f) id (total a) -- If the codomain of a function is a set, then the function can be -- turned into a partial function. as-partial : ∀ {a b} {A : Type a} {B : Type b} → Is-set B → (A → B) → A ⇀ B as-partial {ℓa} B-set f = record { _[_]=_ = λ a b → ↑ ℓa (f a ≡ b) ; deterministic = λ {a b₁ b₂} fa≡b₁ fa≡b₂ → b₁ ≡⟨ sym (lower fa≡b₁) ⟩ f a ≡⟨ lower fa≡b₂ ⟩∎ b₂ ∎ ; propositional = ↑-closure 1 (+⇒≡ {n = 1} B-set) } -- Composition of partial functions. infixr 9 _∘_ _∘_ : ∀ {ℓ c} {A B : Type ℓ} {C : Type c} → B ⇀ C → A ⇀ B → A ⇀ C f ∘ g = record { _[_]=_ = λ a c → ∃ λ b → g [ a ]= b × f [ b ]= c ; deterministic = λ where (b₁ , g[a]=b₁ , f[b₁]=c₁) (b₂ , g[a]=b₂ , f[b₂]=c₂) → _⇀_.deterministic f (subst (f [_]= _) (_⇀_.deterministic g g[a]=b₁ g[a]=b₂) f[b₁]=c₁) f[b₂]=c₂ ; propositional = λ {a c} → $⟨ Σ-closure 1 (_⇀_.∃[]=-propositional g) (λ _ → _⇀_.propositional f) ⟩ Is-proposition (∃ λ (p : ∃ λ b → g [ a ]= b) → f [ proj₁ p ]= c) ↝⟨ H-level.respects-surjection (_↔_.surjection $ inverse Σ-assoc) 1 ⟩□ Is-proposition (∃ λ b → g [ a ]= b × f [ b ]= c) □ } -- If f is a partial function, g a function whose domain is a set, and -- f (g a) = c, then (f ∘ g) a = c. pre-apply : ∀ {ℓ c} {A B : Type ℓ} {C : Type c} (f : B ⇀ C) {g : A → B} {a c} (B-set : Is-set B) → f [ g a ]= c → f ∘ as-partial B-set g [ a ]= c pre-apply _ _ f[ga]=b = _ , lift refl , f[ga]=b -- If f is a function whose domain is a set, g a partial function, and -- g a = b, then (f ∘ g) a = f b. post-apply : ∀ {ℓ c} {A B : Type ℓ} {C : Type c} {f : B → C} (g : A ⇀ B) {a b} (C-set : Is-set C) → g [ a ]= b → as-partial C-set f ∘ g [ a ]= f b post-apply _ _ g[a]=b = _ , g[a]=b , lift refl -- Implements P p f means that p is an implementation of f. The -- definition is parametrised by P, which could be a modality. Implements : ∀ {a b} {A : Type a} {B : Type b} ⦃ rA : Rep A Consts ⦄ ⦃ rB : Rep B Consts ⦄ → (Type (a ⊔ b) → Type (a ⊔ b)) → Exp → A ⇀ B → Type (a ⊔ b) Implements P p f = Closed p × (∀ x y → f [ x ]= y → apply p ⌜ x ⌝ ⇓ ⌜ y ⌝) × (∀ x y → apply p ⌜ x ⌝ ⇓ y → P (∃ λ y′ → f [ x ]= y′ × y ≡ ⌜ y′ ⌝)) -- If P maps propositions to propositions, then Implements P p f is a -- proposition. Implements-propositional : ∀ {a b} {A : Type a} {B : Type b} ⦃ rA : Rep A Consts ⦄ ⦃ rB : Rep B Consts ⦄ → {P : Type (a ⊔ b) → Type (a ⊔ b)} {p : Exp} (f : A ⇀ B) → (∀ {A} → Is-proposition A → Is-proposition (P A)) → Is-proposition (Implements P p f) Implements-propositional f pres = ×-closure 1 Closed-propositional $ ×-closure 1 (Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → ⇓-propositional) (Π-closure ext 1 λ x → Π-closure ext 1 λ y → Π-closure ext 1 λ _ → pres $ H-level.respects-surjection (_↔_.surjection $ inverse Σ-assoc) 1 (Σ-closure 1 (_⇀_.∃[]=-propositional f) λ _ → Exp-set)) -- Computability. The definition is parametrised by something which -- could be a modality. Computable′ : ∀ {a b} {A : Type a} {B : Type b} ⦃ rA : Rep A Consts ⦄ ⦃ rB : Rep B Consts ⦄ → (Type (a ⊔ b) → Type (a ⊔ b)) → A ⇀ B → Type (a ⊔ b) Computable′ P f = ∃ λ p → Implements P p f -- Computability. Computable : ∀ {a b} {A : Type a} {B : Type b} ⦃ rA : Rep A Consts ⦄ ⦃ rB : Rep B Consts ⦄ → A ⇀ B → Type (a ⊔ b) Computable = Computable′ id -- If the partial function is total, then one part of the proof of -- computability can be omitted. total→almost-computable→computable : ∀ {a b} {A : Type a} {B : Type b} ⦃ rA : Rep A Consts ⦄ ⦃ rB : Rep B Consts ⦄ (P : Type (a ⊔ b) → Type (a ⊔ b)) → (∀ {X Y} → (X → Y) → P X → P Y) → (f : A ⇀ B) → Total P f → (∃ λ p → Closed p × (∀ x y → f [ x ]= y → apply p ⌜ x ⌝ ⇓ ⌜ y ⌝)) → Computable′ P f total→almost-computable→computable P map f total (p , cl-p , hyp) = p , cl-p , hyp , λ x y px⇓y → flip map (total x) λ where (y′ , f[x]=y′) → y′ , f[x]=y′ , ⇓-deterministic px⇓y (hyp x y′ f[x]=y′) -- The semantics of χ as a partial function. semantics : Closed-exp ⇀ Closed-exp semantics = record { _[_]=_ = _⇓_ on proj₁ ; deterministic = λ e⇓v₁ e⇓v₂ → closed-equal-if-expressions-equal (⇓-deterministic e⇓v₁ e⇓v₂) ; propositional = ⇓-propositional } -- Another definition of computability. Computable″ : ∀ {ℓ} {A B : Type ℓ} ⦃ rA : Rep A Consts ⦄ ⦃ rB : Rep B Consts ⦄ → A ⇀ B → Type ℓ Computable″ f = ∃ λ (p : Closed-exp) → ∀ a → ∀ q → semantics [ apply-cl p ⌜ a ⌝ ]= q ⇔ as-partial Closed-exp-set ⌜_⌝ ∘ f [ a ]= q -- The two definitions of computability are logically equivalent. Computable⇔Computable″ : ∀ {ℓ} {A B : Type ℓ} ⦃ rA : Rep A Consts ⦄ ⦃ rB : Rep B Consts ⦄ → (f : A ⇀ B) → Computable f ⇔ Computable″ f Computable⇔Computable″ f = record { to = to; from = from } where to : Computable f → Computable″ f to (p , cl , hyp₁ , hyp₂) = (p , cl) , λ { a (q , cl-q) → record { to = Σ-map id (Σ-map id (lift P.∘ closed-equal-if-expressions-equal P.∘ sym)) P.∘ hyp₂ a q ; from = λ { (b , f[a]=b , ⌜b⌝≡q) → apply p ⌜ a ⌝ ⇓⟨ hyp₁ a b f[a]=b ⟩ ⌜ b ⌝ ≡⟨ cong proj₁ (lower ⌜b⌝≡q) ⟩⟶ q ■⟨ subst Value (cong proj₁ (lower ⌜b⌝≡q)) (rep-value b) ⟩ } } } from : Computable″ f → Computable f from ((p , cl) , hyp) = p , cl , (λ a b f[a]=b → apply p ⌜ a ⌝ ⇓⟨ _⇔_.from (hyp a ⌜ b ⌝) (post-apply f Closed-exp-set f[a]=b) ⟩■ ⌜ b ⌝) , λ a q p⌜a⌝⇓q → let cl-q : Closed q cl-q = closed⇓closed p⌜a⌝⇓q (Closed′-closed-under-apply (Closed→Closed′ cl) (Closed→Closed′ (rep-closed a))) in Σ-map id (Σ-map id (cong proj₁ P.∘ sym P.∘ lower)) (_⇔_.to (hyp a (q , cl-q)) p⌜a⌝⇓q) -- Yet another definition of computability. Computable‴ : ∀ {a b} {A : Type a} {B : Type b} ⦃ rA : Rep A Consts ⦄ ⦃ rB : Rep B Consts ⦄ → A ⇀ B → Type (a ⊔ b) Computable‴ f = ∃ λ (p : Closed-exp) → ∀ a → ∃ λ b → apply (proj₁ p) ⌜ a ⌝ ⇓ ⌜ b ⌝ × f [ a ]= b -- If a partial function is computable by the last definition of -- computability above, then it is also computable by the first one. Computable‴→Computable : ∀ {a b} {A : Type a} {B : Type b} ⦃ rA : Rep A Consts ⦄ ⦃ rB : Rep B Consts ⦄ → (f : A ⇀ B) → Computable‴ f → Computable f Computable‴→Computable f ((p , cl-p) , hyp) = p , cl-p , (λ a b f[a]=b → case hyp a of λ where (b′ , p⌜a⌝⇓⌜b′⌝ , f[a]=b′) → apply p ⌜ a ⌝ ⇓⟨ p⌜a⌝⇓⌜b′⌝ ⟩ ⌜ b′ ⌝ ≡⟨ by (_⇀_.deterministic f f[a]=b f[a]=b′) ⟩⟶ ⌜ b ⌝ ■⟨ rep-value b ⟩) , (λ a v p⌜a⌝⇓v → case hyp a of λ where (b , p⌜a⌝⇓⌜b⌝ , f[a]=b) → b , f[a]=b , ⇓-deterministic p⌜a⌝⇓v p⌜a⌝⇓⌜b⌝) module _ {a b c d} {A : Type a} {B : Type b} {C : Type c} {D : Type d} ⦃ rA : Rep A Consts ⦄ ⦃ rB : Rep B Consts ⦄ ⦃ rC : Rep C Consts ⦄ ⦃ rD : Rep D Consts ⦄ where -- Reductions. Reduction : A ⇀ B → C ⇀ D → Type (a ⊔ b ⊔ c ⊔ d) Reduction f g = Computable g → Computable f -- If f can be reduced to g, and f is not computable, then g is not -- computable. Reduction→¬Computable→¬Computable : (f : A ⇀ B) (g : C ⇀ D) → Reduction f g → ¬ Computable f → ¬ Computable g Reduction→¬Computable→¬Computable _ _ red ¬f g = ¬f (red g) -- Total partial functions to the booleans. Note that totality is -- defined using the double-negation modality. _→Bool : ∀ {ℓ} → Type ℓ → Type (lsuc ℓ) A →Bool = ∃ λ (f : A ⇀ Bool) → Total (λ A → ¬¬ A) f -- One way to view a predicate as a total partial function to the -- booleans. as-function-to-Bool₁ : ∀ {a} {A : Type a} → (A → Type a) → A →Bool as-function-to-Bool₁ P = (record { _[_]=_ = λ a b → (P a → b ≡ true) × (¬ P a → b ≡ false) ; deterministic = λ where {b₁ = true} {b₂ = true} _ _ → refl {b₁ = false} {b₂ = false} _ _ → refl {b₁ = true} {b₂ = false} f₁ f₂ → proj₂ f₁ (Bool.true≢false P.∘ sym P.∘ proj₁ f₂) {b₁ = false} {b₂ = true} f₁ f₂ → sym (proj₂ f₂ (Bool.true≢false P.∘ sym P.∘ proj₁ f₁)) ; propositional = ×-closure 1 (Π-closure ext 1 λ _ → Bool-set) (Π-closure ext 1 λ _ → Bool-set) }) , λ a → [ (λ p → true , (λ _ → refl) , ⊥-elim P.∘ (_$ p)) , (λ ¬p → false , ⊥-elim P.∘ ¬p , (λ _ → refl)) ] ⟨$⟩ excluded-middle -- Another way to view a predicate as a total partial function to the -- booleans. as-function-to-Bool₂ : ∀ {a} {A : Type a} → (P : A → Type a) → (∀ {a} → Is-proposition (P a)) → A →Bool as-function-to-Bool₂ P P-prop = (record { _[_]=_ = λ a b → P a × b ≡ true ⊎ ¬ P a × b ≡ false ; deterministic = λ where (inj₁ (_ , refl)) (inj₁ (_ , refl)) → refl (inj₁ (p , _)) (inj₂ (¬p , _)) → ⊥-elim (¬p p) (inj₂ (¬p , _)) (inj₁ (p , _)) → ⊥-elim (¬p p) (inj₂ (_ , refl)) (inj₂ (_ , refl)) → refl ; propositional = λ {_ b} → ⊎-closure-propositional (λ { (_ , b≡true) (_ , b≡false) → Bool.true≢false ( true ≡⟨ sym b≡true ⟩ b ≡⟨ b≡false ⟩∎ false ∎) }) (×-closure 1 P-prop Bool-set) (×-closure 1 (¬-propositional ext) Bool-set) }) , λ a → [ (λ p → true , inj₁ (p , refl)) , (λ ¬p → false , inj₂ (¬p , refl)) ] ⟨$⟩ excluded-middle -- If a is mapped to b by as-function-to-Bool₂ P P-prop, then a is -- also mapped to b by as-function-to-Bool₁ P. to-Bool₂→to-Bool₁ : ∀ {a} {A : Type a} ⦃ rA : Rep A Consts ⦄ (P : A → Type a) (P-prop : ∀ {a} → Is-proposition (P a)) {a b} → proj₁ (as-function-to-Bool₂ P P-prop) [ a ]= b → proj₁ (as-function-to-Bool₁ P) [ a ]= b to-Bool₂→to-Bool₁ _ _ = λ where (inj₁ (Pa , refl)) → (λ _ → refl) , ⊥-elim P.∘ (_$ Pa) (inj₂ (¬Pa , refl)) → ⊥-elim P.∘ ¬Pa , λ _ → refl -- If a is mapped to b by as-function-to-Bool₁ P, then a is not not -- mapped to b by as-function-to-Bool₂ P P-prop. to-Bool₁→to-Bool₂ : ∀ {a} {A : Type a} ⦃ rA : Rep A Consts ⦄ (P : A → Type a) (P-prop : ∀ {a} → Is-proposition (P a)) {a b} → proj₁ (as-function-to-Bool₁ P) [ a ]= b → ¬¬ proj₁ (as-function-to-Bool₂ P P-prop) [ a ]= b to-Bool₁→to-Bool₂ _ _ (Pa→b≡true , ¬Pa→b≡false) = ⊎-map (λ Pa → Pa , Pa→b≡true Pa) (λ ¬Pa → ¬Pa , ¬Pa→b≡false ¬Pa) ⟨$⟩ excluded-middle -- If as-function-to-Bool₁ P is ¬¬-computable, then -- as-function-to-Bool₂ P P-prop is also ¬¬-computable. to-Bool₁-computable→to-Bool₂-computable : ∀ {a} {A : Type a} ⦃ rA : Rep A Consts ⦄ (P : A → Type a) (P-prop : ∀ {a} → Is-proposition (P a)) → Computable′ (λ A → ¬¬ A) (proj₁ (as-function-to-Bool₁ P)) → Computable′ (λ A → ¬¬ A) (proj₁ (as-function-to-Bool₂ P P-prop)) to-Bool₁-computable→to-Bool₂-computable P P-prop (p , cl-p , hyp₁ , hyp₂) = p , cl-p , (λ a b → proj₁ (as-function-to-Bool₂ P P-prop) [ a ]= b ↝⟨ to-Bool₂→to-Bool₁ P P-prop ⟩ proj₁ (as-function-to-Bool₁ P) [ a ]= b ↝⟨ hyp₁ a b ⟩□ apply p ⌜ a ⌝ ⇓ ⌜ b ⌝ □) , λ a e → apply p ⌜ a ⌝ ⇓ e ↝⟨ hyp₂ a e ⟩ ¬¬ (∃ λ b → proj₁ (as-function-to-Bool₁ P) [ a ]= b × e ≡ ⌜ b ⌝) ↝⟨ _>>= (λ { (b , =b , ≡⌜b⌝) → to-Bool₁→to-Bool₂ P P-prop =b >>= λ =b → return (b , =b , ≡⌜b⌝) }) ⟩□ ¬¬ (∃ λ b → proj₁ (as-function-to-Bool₂ P P-prop) [ a ]= b × e ≡ ⌜ b ⌝) □ -- A lemma related to as-function-to-Bool₂. ×≡true⊎¬×≡false⇔⇔T : ∀ {a} {A : Type a} (P : A → Type a) → ∀ {a b} → P a × b ≡ true ⊎ ¬ P a × b ≡ false ⇔ (P a ⇔ T b) ×≡true⊎¬×≡false⇔⇔T P {a} {b} = record { to = λ where (inj₁ (p , refl)) → record { from = λ _ → p } (inj₂ (¬p , refl)) → record { to = ¬p; from = ⊥-elim } ; from = helper b } where helper : ∀ b → P a ⇔ T b → P a × b ≡ true ⊎ ¬ P a × b ≡ false helper true hyp = inj₁ (_⇔_.from hyp _ , refl) helper false hyp = inj₂ (_⇔_.to hyp , refl) -- One way to view a predicate as a partial function to the booleans. as-partial-function-to-Bool₁ : ∀ {a} {A : Type a} → (A → Type a) → A ⇀ Bool as-partial-function-to-Bool₁ P = record { _[_]=_ = λ a b → (P a → b ≡ true) × ¬ ¬ P a ; deterministic = λ where {b₁ = true} {b₂ = true} _ _ → refl {b₁ = false} {b₂ = false} _ _ → refl {b₁ = true} {b₂ = false} _ f → ⊥-elim $ proj₂ f (Bool.true≢false P.∘ sym P.∘ proj₁ f) {b₁ = false} {b₂ = true} f _ → ⊥-elim $ proj₂ f (Bool.true≢false P.∘ sym P.∘ proj₁ f) ; propositional = ×-closure 1 (Π-closure ext 1 λ _ → Bool-set) (¬-propositional ext) } -- Another way to view a predicate as a partial function to the -- booleans. as-partial-function-to-Bool₂ : ∀ {a} {A : Type a} → (P : A → Type a) → (∀ {a} → Is-proposition (P a)) → A ⇀ Bool as-partial-function-to-Bool₂ P P-prop = record { _[_]=_ = λ a b → P a × b ≡ true ; deterministic = λ { (_ , refl) (_ , refl) → refl } ; propositional = ×-closure 1 P-prop Bool-set } -- One definition of what it means for a total partial function to the -- booleans to be decidable. Decidable : ∀ {a} {A : Type a} ⦃ rA : Rep A Consts ⦄ → A →Bool → Type a Decidable = Computable P.∘ proj₁ -- Another definition of what it means for a total partial function to -- the booleans to be decidable. Decidable′ : ∀ {a} {A : Type a} ⦃ rA : Rep A Consts ⦄ → A →Bool → Type a Decidable′ = Computable‴ P.∘ proj₁ -- Computable functions from a type to a set. record Computable-function {a b} (A : Type a) (B : Type b) (B-set : Is-set B) ⦃ rA : Rep A Consts ⦄ ⦃ rB : Rep B Consts ⦄ : Type (a ⊔ b) where field function : A → B computable : Computable (as-partial B-set function) open Computable-function -- An unfolding lemma for Computable-function. Computable-function↔ : ∀ {a b} {A : Type a} {B : Type b} {B-set : Is-set B} ⦃ rA : Rep A Consts ⦄ ⦃ rB : Rep B Consts ⦄ → Computable-function A B B-set ↔ ∃ λ (f : A → B) → Computable (as-partial B-set f) Computable-function↔ = record { surjection = record { logical-equivalence = record { to = λ f → function f , computable f } ; right-inverse-of = λ _ → refl } ; left-inverse-of = λ _ → refl } -- If two computable functions have equal implementations, then they -- are equal. equal-implementations→equal : ∀ {a b} {A : Type a} {B : Type b} {B-set : Is-set B} ⦃ rA : Rep A Consts ⦄ ⦃ rB : Rep B Consts ⦄ (f g : Computable-function A B B-set) → proj₁ (computable f) ≡ proj₁ (computable g) → function f ≡ function g equal-implementations→equal f g hyp = ⟨ext⟩ λ x → $⟨ proj₁ (proj₂ (proj₂ (computable f))) x (function f x) (lift refl) , proj₁ (proj₂ (proj₂ (computable g))) x (function g x) (lift refl) ⟩ apply (proj₁ (computable f)) ⌜ x ⌝ ⇓ ⌜ function f x ⌝ × apply (proj₁ (computable g)) ⌜ x ⌝ ⇓ ⌜ function g x ⌝ ↝⟨ Σ-map id (subst (λ e → apply e _ ⇓ _) (sym hyp)) ⟩ apply (proj₁ (computable f)) ⌜ x ⌝ ⇓ ⌜ function f x ⌝ × apply (proj₁ (computable f)) ⌜ x ⌝ ⇓ ⌜ function g x ⌝ ↝⟨ uncurry ⇓-deterministic ⟩ ⌜ function f x ⌝ ≡ ⌜ function g x ⌝ ↝⟨ rep-injective ⟩□ function f x ≡ function g x □ instance -- Representation functions for computable functions. rep-Computable-function : ∀ {a b} {A : Type a} {B : Type b} {B-set : Is-set B} ⦃ rA : Rep A Consts ⦄ ⦃ rB : Rep B Consts ⦄ → Rep (Computable-function A B B-set) Consts rep-Computable-function {A = A} {B = B} {B-set = B-set} = record { ⌜_⌝ = ⌜_⌝ P.∘ proj₁ P.∘ computable ; rep-injective = injective } where abstract injective : Injective {A = Computable-function A B B-set} {B = Consts} (⌜_⌝ P.∘ proj₁ P.∘ computable) injective {f} {g} = ⌜ proj₁ (computable f) ⌝ ≡ ⌜ proj₁ (computable g) ⌝ ↝⟨ rep-injective ⟩ proj₁ (computable f) ≡ proj₁ (computable g) ↝⟨ (λ hyp → cong₂ _,_ (equal-implementations→equal f g hyp) hyp) ⟩ (function f , proj₁ (computable f)) ≡ (function g , proj₁ (computable g)) ↔⟨ ignore-propositional-component $ Implements-propositional (as-partial B-set (function g)) id ⟩ ((function f , proj₁ (computable f)) , proj₂ (computable f)) ≡ ((function g , proj₁ (computable g)) , proj₂ (computable g)) ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ Σ-assoc) ⟩ (function f , computable f) ≡ (function g , computable g) ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ Computable-function↔) ⟩□ f ≡ g □
34.89899
143
0.498022
a1887c87c286953460e8435cf62686c9cff847c3
4,515
agda
Agda
src/Terminal.agda
cruhland/agda-editor
c5ffd117f6d5a98f7c68a2a6b9be54a150c70945
[ "MIT" ]
null
null
null
src/Terminal.agda
cruhland/agda-editor
c5ffd117f6d5a98f7c68a2a6b9be54a150c70945
[ "MIT" ]
null
null
null
src/Terminal.agda
cruhland/agda-editor
c5ffd117f6d5a98f7c68a2a6b9be54a150c70945
[ "MIT" ]
null
null
null
module Terminal where open import Agda.Builtin.Word open import BasicIO open import Data.Bool open import Data.Char hiding (show) open import Data.List hiding (_++_) open import Data.String hiding (show) open import Data.Unit open import ByteCount open import Int open import Function open import Pair open import Show {-# FOREIGN GHC import System.Posix.IO #-} {-# FOREIGN GHC import System.Posix.Terminal #-} {-# FOREIGN GHC import System.Posix.Types #-} data TerminalState : Set where immediately : TerminalState whenDrained : TerminalState whenFlushed : TerminalState {-# COMPILE GHC TerminalState = data TerminalState (Immediately | WhenDrained | WhenFlushed) #-} data TerminalMode : Set where interruptOnBreak : TerminalMode mapCRtoLF : TerminalMode ignoreBreak : TerminalMode ignoreCR : TerminalMode ignoreParityErrors : TerminalMode mapLFtoCR : TerminalMode checkParity : TerminalMode stripHighBit : TerminalMode startStopInput : TerminalMode startStopOutput : TerminalMode markParityErrors : TerminalMode processOutput : TerminalMode localMode : TerminalMode readEnable : TerminalMode twoStopBits : TerminalMode hangupOnClose : TerminalMode enableParity : TerminalMode oddParity : TerminalMode enableEcho : TerminalMode echoErase : TerminalMode echoKill : TerminalMode echoLF : TerminalMode processInput : TerminalMode extendedFunctions : TerminalMode keyboardInterrupts : TerminalMode noFlushOnInterrupt : TerminalMode backgroundWriteInterrupt : TerminalMode {-# COMPILE GHC TerminalMode = data TerminalMode ( InterruptOnBreak | MapCRtoLF | IgnoreBreak | IgnoreCR | IgnoreParityErrors | MapLFtoCR | CheckParity | StripHighBit | StartStopInput | StartStopOutput | MarkParityErrors | ProcessOutput | LocalMode | ReadEnable | TwoStopBits | HangupOnClose | EnableParity | OddParity | EnableEcho | EchoErase | EchoKill | EchoLF | ProcessInput | ExtendedFunctions | KeyboardInterrupts | NoFlushOnInterrupt | BackgroundWriteInterrupt ) #-} postulate Fd : Set TerminalAttributes : Set stdInput : Fd stdOutput : Fd getTerminalAttributes : Fd → IO TerminalAttributes setTerminalAttributes : Fd → TerminalAttributes → TerminalState → IO ⊤ withoutMode : TerminalAttributes → TerminalMode → TerminalAttributes inputTime : TerminalAttributes → Int withTime : TerminalAttributes → Int → TerminalAttributes minInput : TerminalAttributes → Int withMinInput : TerminalAttributes → Int → TerminalAttributes fdRead : Fd → ByteCount → IO (List Char , ByteCount) fdWrite : Fd → List Char → IO ByteCount {-# COMPILE GHC Fd = type Fd #-} {-# COMPILE GHC TerminalAttributes = type TerminalAttributes #-} {-# COMPILE GHC stdInput = stdInput #-} {-# COMPILE GHC stdOutput = stdOutput #-} {-# COMPILE GHC getTerminalAttributes = getTerminalAttributes #-} {-# COMPILE GHC setTerminalAttributes = setTerminalAttributes #-} {-# COMPILE GHC withoutMode = withoutMode #-} {-# COMPILE GHC inputTime = inputTime #-} {-# COMPILE GHC withTime = withTime #-} {-# COMPILE GHC minInput = minInput #-} {-# COMPILE GHC withMinInput = withMinInput #-} {-# COMPILE GHC fdRead = fdRead #-} {-# COMPILE GHC fdWrite = fdWrite #-} clearScreen : String clearScreen = "\^[[2J" showCursor : String showCursor = "\^[[?25h" hideCursor : String hideCursor = "\^[[?25l" altScreenEnable : String altScreenEnable = "\^[[?1049h" altScreenDisable : String altScreenDisable = "\^[[?1049l" withUpdatedAttributes : {A : Set} → (TerminalAttributes → TerminalAttributes) → IO A → IO A withUpdatedAttributes {A} updateFn actions = bracket (getTerminalAttributes stdOutput) setAttrs updateAndRun where setAttrs : TerminalAttributes → IO ⊤ setAttrs attrs = setTerminalAttributes stdOutput attrs immediately updateAndRun : TerminalAttributes → IO A updateAndRun attrs = do _ ← setAttrs (updateFn attrs) actions readMaxChars : ByteCount readMaxChars = mkCSize (primWord64FromNat 1024) termRead : IO String termRead = fdRead stdInput readMaxChars >>= (return ∘ fromList ∘ fst) termWrite : String → IO ByteCount termWrite = fdWrite stdOutput ∘ toList printAttrs : TerminalAttributes → IO ⊤ printAttrs attrs = do _ ← termWrite (formatField "inputTime" (inputTime attrs)) _ ← termWrite (formatField "minInput" (minInput attrs)) return tt where formatField : String → Int → String formatField name value = name ++ " = " ++ show value ++ "\n"
27.198795
72
0.739092
4a272dbc778cc9e3c653f61a65c2f5d23205e02b
6,822
agda
Agda
agda/course/2017-conor_mcbride_cs410/CS410-17-master/lectures/Lec1Done.agda
haroldcarr/learn-haskell-coq-ml-etc
3dc7abca7ad868316bb08f31c77fbba0d3910225
[ "Unlicense" ]
36
2015-01-29T14:37:15.000Z
2021-07-30T06:55:03.000Z
agda/course/2017-conor_mcbride_cs410/CS410-17-master/lectures/Lec1Done.agda
haroldcarr/learn-haskell-coq-ml-etc
3dc7abca7ad868316bb08f31c77fbba0d3910225
[ "Unlicense" ]
null
null
null
agda/course/2017-conor_mcbride_cs410/CS410-17-master/lectures/Lec1Done.agda
haroldcarr/learn-haskell-coq-ml-etc
3dc7abca7ad868316bb08f31c77fbba0d3910225
[ "Unlicense" ]
8
2015-04-13T21:40:15.000Z
2021-09-21T15:58:10.000Z
module Lec1Done where -- the -- mark introduces a "comment to end of line" ------------------------------------------------------------------------------ -- some basic "logical" types ------------------------------------------------------------------------------ data Zero : Set where -- to give a value in a data, choose one constructor -- there are no constructors -- so that's impossible record One : Set where -- to give a value in a record type, fill all its fields -- there are no fields -- so that's trivial -- (can we have a constructor, for convenience?) constructor <> {-# COMPILE GHC One = data () (()) #-} data _+_ (S : Set)(T : Set) : Set where -- "where" wants an indented block -- to offer a choice of constructors, list them with their types inl : S -> S + T -- constructors can pack up stuff inr : T -> S + T -- in Haskell, this was called "Either S T" {- record _*_ (S : Set)(T : Set) : Set where field -- introduces a bunch of fields, listed with their types fst : S snd : T -- in Haskell, this was called "(S, T)" -} -- _*_ IS GENERALIZED BY SIGMA record Sg (S : Set)(T : S -> Set) : Set where -- Sg is short for "Sigma" constructor _,_ field -- introduces a bunch of fields, listed with their types fst : S snd : T fst open Sg public -- brings fst and snd into scope hereafter unto all inheritors -- make _*_ from Sg ? _*_ : Set -> Set -> Set S * T = Sg S \ _ -> T infixr 4 _*_ _,_ ------------------------------------------------------------------------------ -- some simple proofs ------------------------------------------------------------------------------ comm-* : {A : Set}{B : Set} -> A * B -> B * A comm-* record { fst = a ; snd = b } = record { fst = b ; snd = a } assocLR-+ : {A B C : Set} -> (A + B) + C -> A + (B + C) assocLR-+ (inl (inl a)) = inl a assocLR-+ (inl (inr b)) = inr (inl b) assocLR-+ (inr c) = inr (inr c) _$*_ : {A A' B B' : Set} -> (A -> A') -> (B -> B') -> A * B -> A' * B' (f $* g) record { fst = a ; snd = b } = record { fst = f a ; snd = g b } -- record syntax is rather ugly for small stuff; can we have constructors? _$+_ : {A A' B B' : Set} -> (A -> A') -> (B -> B') -> A + B -> A' + B' (f $+ g) (inl a) = inl (f a) (f $+ g) (inr b) = inr (g b) combinatorK : {A E : Set} -> A -> E -> A combinatorK = \ a _ -> a combinatorS : {S T E : Set} -> (E -> S -> T) -> (E -> S) -> E -> T combinatorS = \ f s e -> (f e) (s e) id : {X : Set} -> X -> X -- id x = x -- is the easy way; let's do it a funny way to make a point id = combinatorS combinatorK (combinatorK {_} {Zero}) -- no choice for -^ ^^^^- could be anything naughtE : {X : Set} -> Zero -> X naughtE () -- standard composition: f << g is "f after g" _<<_ : {X Y Z : Set} -> (Y -> Z) -> (X -> Y) -> (X -> Z) (f << g) x = f (g x) -- diagrammatic composition: f >> g is "f then g" _>>_ : {X Y Z : Set} -> (X -> Y) -> (Y -> Z) -> (X -> Z) -- ^^^^^^^^ dominoes! (f >> g) x = g (f x) -- infix application _$_ : {S : Set}{T : S -> Set}(f : (x : S) -> T x)(s : S) -> T s f $ s = f s infixl 2 _$_ ------------------------------------------------------------------------------ -- from logic to data ------------------------------------------------------------------------------ data Nat : Set where zero : Nat suc : Nat -> Nat -- recursive data type {-# BUILTIN NATURAL Nat #-} -- ^^^^^^^^^^^^^^^^^^^ this pragma lets us use decimal notation _+N_ : Nat -> Nat -> Nat zero +N y = y suc x +N y = suc (x +N y) -- there are other choices four : Nat four = 2 +N 2 ------------------------------------------------------------------------------ -- and back to logic ------------------------------------------------------------------------------ data _==_ {X : Set} : X -> X -> Set where refl : (x : X) -> x == x -- the relation that's "only reflexive" {-# BUILTIN EQUALITY _==_ #-} -- we'll see what that's for, later _=$=_ : {X Y : Set}{f f' : X -> Y}{x x' : X} -> f == f' -> x == x' -> f x == f' x' refl f =$= refl x = refl (f x) infixl 2 _=$=_ zero-+N : (n : Nat) -> (zero +N n) == n zero-+N n = refl n +N-zero : (n : Nat) -> (n +N zero) == n +N-zero zero = refl zero +N-zero (suc n) = refl suc =$= +N-zero n assocLR-+N : (x y z : Nat) -> ((x +N y) +N z) == (x +N (y +N z)) assocLR-+N zero y z = refl (y +N z) assocLR-+N (suc x) y z = refl suc =$= assocLR-+N x y z ------------------------------------------------------------------------------ -- computing types ------------------------------------------------------------------------------ _>=_ : Nat -> Nat -> Set x >= zero = One zero >= suc y = Zero suc x >= suc y = x >= y refl->= : (n : Nat) -> n >= n refl->= zero = record {} refl->= (suc n) = refl->= n trans->= : (x y z : Nat) -> x >= y -> y >= z -> x >= z trans->= x y zero x>=y y>=z = record {} trans->= x zero (suc z) x>=y () trans->= zero (suc y) (suc z) () y>=z trans->= (suc x) (suc y) (suc z) x>=y y>=z = trans->= x y z x>=y y>=z ------------------------------------------------------------------------------ -- construction by proof ------------------------------------------------------------------------------ {- -- MOVED UP TO REPLACE _*_ record Sg (S : Set)(T : S -> Set) : Set where -- Sg is short for "Sigma" constructor _,_ field -- introduces a bunch of fields, listed with their types fst : S snd : T fst -- make _*_ from Sg ? _*_ : Set -> Set -> Set S * T = Sg S \ _ -> T -} difference : (m n : Nat) -> m >= n -> Sg Nat \ d -> m == (n +N d) -- ( ) difference m zero m>=n = m , refl m difference zero (suc n) () difference (suc m) (suc n) m>=n with difference m n m>=n difference (suc m) (suc n) m>=n | d , q = d , (refl suc =$= q) tryMe = difference 42 37 _ -- don'tTryMe = difference 37 42 {!!} ------------------------------------------------------------------------------ -- things to remember to say ------------------------------------------------------------------------------ -- why the single colon? -- what's with all the spaces? -- what's with identifiers mixing letters and symbols? -- what's with all the braces? -- what is Set? -- are there any lowercase/uppercase conventions? -- what's with all the underscores? -- (i) placeholders in mixfix operators -- (ii) don't care (on the left) -- (iii) go figure (on the right) -- why use arithmetic operators for types? -- what's the difference between = and == ? -- can't we leave out cases? -- can't we loop? -- the function type is both implication and universal quantification, -- but why is it called Pi? -- why is Sigma called Sigma? -- B or nor B?
29.66087
78
0.441659
13c9745ad8708f1171dd5014975461a78ebec59e
1,102
agda
Agda
Cubical/Data/Sigma/Base.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Data/Sigma/Base.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
1
2022-01-27T02:07:48.000Z
2022-01-27T02:07:48.000Z
Cubical/Data/Sigma/Base.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
1
2021-11-22T02:02:01.000Z
2021-11-22T02:02:01.000Z
{- Basic definitions using Σ-types Σ-types are defined in Core/Primitives as they are needed for Glue types. The file contains: - Non-dependent pair types: A × B - Mere existence: ∃[x ∈ A] B - Unique existence: ∃![x ∈ A] B -} {-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Data.Sigma.Base where open import Cubical.Core.Primitives public open import Cubical.Foundations.Prelude open import Cubical.HITs.PropositionalTruncation.Base -- Non-dependent pair types _×_ : ∀ {ℓ ℓ'} (A : Type ℓ) (B : Type ℓ') → Type (ℓ-max ℓ ℓ') A × B = Σ A (λ _ → B) infixr 5 _×_ -- Mere existence ∃ : ∀ {ℓ ℓ'} (A : Type ℓ) (B : A → Type ℓ') → Type (ℓ-max ℓ ℓ') ∃ A B = ∥ Σ A B ∥ infix 2 ∃-syntax ∃-syntax : ∀ {ℓ ℓ'} (A : Type ℓ) (B : A → Type ℓ') → Type (ℓ-max ℓ ℓ') ∃-syntax = ∃ syntax ∃-syntax A (λ x → B) = ∃[ x ∈ A ] B -- Unique existence ∃! : ∀ {ℓ ℓ'} (A : Type ℓ) (B : A → Type ℓ') → Type (ℓ-max ℓ ℓ') ∃! A B = isContr (Σ A B) infix 2 ∃!-syntax ∃!-syntax : ∀ {ℓ ℓ'} (A : Type ℓ) (B : A → Type ℓ') → Type (ℓ-max ℓ ℓ') ∃!-syntax = ∃! syntax ∃!-syntax A (λ x → B) = ∃![ x ∈ A ] B
20.792453
73
0.575318
419293a8856d5918ffa79373db7a71e11d03baad
8,023
agda
Agda
LectureNotes/NumbersAndSets/Examples1.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
4
2019-08-08T12:44:19.000Z
2022-01-28T06:04:15.000Z
LectureNotes/NumbersAndSets/Examples1.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
14
2019-01-06T21:11:59.000Z
2020-04-11T11:03:39.000Z
LectureNotes/NumbersAndSets/Examples1.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
1
2021-11-29T13:23:07.000Z
2021-11-29T13:23:07.000Z
{-# OPTIONS --warning=error --safe --without-K --guardedness #-} open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) open import LogicalFormulae open import Numbers.Integers.Integers open import Numbers.Naturals.Semiring open import Numbers.Naturals.Subtraction open import Numbers.Naturals.Naturals open import Numbers.Naturals.Order open import Numbers.Naturals.Exponentiation open import Numbers.Primes.PrimeNumbers open import Maybe open import Semirings.Definition open import Numbers.Naturals.EuclideanAlgorithm open import Sequences open import Vectors module LectureNotes.NumbersAndSets.Examples1 where open Semiring ℕSemiring open import Semirings.Solver ℕSemiring multiplicationNIsCommutative private abstract q1Lemma1 : {q r : ℕ} → 3 *N succ q +N r ≡ succ (succ (succ (3 *N q +N r))) q1Lemma1 {q} {r} rewrite sumZeroRight q | commutative q (succ q) | commutative q (succ (succ (q +N q))) | +Associative q q q = refl q1Lemma : {n : ℕ} → (2 <N n) → ((3 ∣ n) || (3 ∣ (n +N 2))) || (3 ∣ (n +N 4)) q1Lemma {zero} () q1Lemma {succ zero} (le zero ()) q1Lemma {succ zero} (le (succ x) ()) q1Lemma {succ (succ zero)} (le (succ x) proof) rewrite Semiring.commutative ℕSemiring x 2 = exFalso (naughtE (equalityCommutative (succInjective (succInjective proof)))) q1Lemma {succ (succ (succ zero))} 2<n = inl (inl (aDivA 3)) q1Lemma {succ (succ (succ (succ zero)))} 2<n = inl (inr (divides (record { quot = 2 ; rem = zero ; pr = refl ; remIsSmall = inl (le 2 refl) ; quotSmall = inl (le 2 refl)}) refl)) q1Lemma {succ (succ (succ (succ (succ zero))))} 2<n = inr (divides (record { quot = 3 ; rem = zero ; pr = refl ; remIsSmall = inl (le 2 refl) ; quotSmall = inl (le 2 refl)}) refl) q1Lemma {succ (succ (succ (succ (succ (succ n)))))} 2<n with q1Lemma {succ (succ (succ n))} (le n (applyEquality succ (Semiring.commutative ℕSemiring n 2))) q1Lemma {succ (succ (succ (succ (succ (succ n)))))} 2<n | inl (inl (divides record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = remIsSmall ; quotSmall = quotSmall } x)) = inl (inl (divides (record { quot = succ quot ; rem = rem ; pr = transitivity (q1Lemma1 {quot} {rem}) (applyEquality (λ x → succ (succ (succ x))) pr) ; remIsSmall = remIsSmall ; quotSmall = inl (le 2 refl) }) x)) q1Lemma {succ (succ (succ (succ (succ (succ n)))))} 2<n | inl (inr (divides record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = remIsSmall ; quotSmall = quotSmall } x)) = inl (inr (divides record { quot = succ quot ; rem = rem ; pr = transitivity (q1Lemma1 {quot} {rem}) (applyEquality (λ x → succ (succ (succ x))) pr) ; remIsSmall = remIsSmall ; quotSmall = inl (le 2 refl) } x)) q1Lemma {succ (succ (succ (succ (succ (succ n)))))} 2<n | inr (divides record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = remIsSmall ; quotSmall = quotSmall } x) = inr (divides record { quot = succ quot ; rem = rem ; pr = transitivity (q1Lemma1 {quot} {rem}) (applyEquality (λ x → succ (succ (succ x))) pr) ; remIsSmall = remIsSmall ; quotSmall = inl (le 2 refl) } x) q1 : {n : ℕ} → Prime n → Prime (n +N 2) → Prime (n +N 4) → n ≡ 3 q1 {succ zero} record { p>1 = (le zero ()) ; pr = pr } pN+2 pN+4 q1 {succ zero} record { p>1 = (le (succ x) ()) ; pr = pr } pN+2 pN+4 q1 {succ (succ zero)} pN record { p>1 = p>1 ; pr = pr } pN+4 with pr {2} (divides (record { quot = 2 ; rem = zero ; pr = refl ; remIsSmall = inl (le 1 refl) ; quotSmall = inl (le 1 refl)}) refl) (le 1 refl) (le 1 refl) q1 {succ (succ zero)} pN record { p>1 = p>1 ; pr = pr } pN+4 | () q1 {succ (succ (succ n))} pN pN+2 pN+4 with q1Lemma {succ (succ (succ n))} (le n (applyEquality succ (commutative n 2))) q1 {succ (succ (succ n))} pN pN+2 pN+4 | inl (inl 3|n) = equalityCommutative (primeDivPrimeImpliesEqual threeIsPrime pN 3|n) q1 {succ (succ (succ n))} pN pN+2 pN+4 | inl (inr 3|n+2) with primeDivPrimeImpliesEqual threeIsPrime pN+2 3|n+2 ... | bl rewrite commutative n 2 = exFalso (naughtE (succInjective (succInjective (succInjective bl)))) q1 {succ (succ (succ n))} pN pN+2 pN+4 | inr 3|n+4 with primeDivPrimeImpliesEqual threeIsPrime pN+4 3|n+4 ... | bl rewrite commutative n 4 = exFalso (naughtE (succInjective (succInjective (succInjective bl)))) q3Differences : ℕ → ℕ q3Differences a = 2 *N a q3Seq : (start : ℕ) → ℕ → ℕ q3Seq start zero = start q3Seq start (succ n) = q3Differences (succ n) +N q3Seq start n q3SeqFirst : take 5 (funcToSequence (q3Seq 41)) ≡ 41 ,- 43 ,- 47 ,- 53 ,- 61 ,- [] q3SeqFirst = refl q3N : (start : ℕ) (a : ℕ) → q3Seq start a ≡ start +N (a +N (a *N a)) q3N start zero = equalityCommutative (sumZeroRight start) q3N start (succ a) rewrite q3N start a | sumZeroRight a = from (succ (plus (plus (const a) (succ (const a))) (plus (const start) (plus (const a) (times (const a) (const a)))))) to (plus (const start) (succ (plus (const a) (succ (plus (const a) (times (const a) (succ (const a)))))))) by applyEquality (λ i → succ (succ i)) (transitivity (+Associative (a +N a) start _) (transitivity (transitivity (applyEquality (_+N (a +N a *N a)) (commutative (a +N a) start)) (equalityCommutative (+Associative start _ _))) (applyEquality (start +N_) (equalityCommutative (+Associative a a (a +N a *N a)))))) q3NDivision : (start : ℕ) → start ∣ (q3Seq start start) q3NDivision 0 = aDivA 0 q3NDivision (succ start) rewrite q3N (succ start) (succ start) = dividesBothImpliesDividesSum {succ start} {succ start} (aDivA (succ start)) (dividesBothImpliesDividesSum {succ start} {succ start} (aDivA (succ start)) (divides (record { quot = succ start ; rem = 0 ; pr = sumZeroRight _ ; remIsSmall = inl (succIsPositive start) ; quotSmall = inl (succIsPositive start) }) refl)) q3 : (start : ℕ) → ((n : ℕ) → Prime (q3Seq start n)) → False q3 zero a with a 2 ... | record { p>1 = p>1 ; pr = pr } with pr {2} (divides (record { quot = 3 ; rem = 0 ; pr = refl ; remIsSmall = inl (le 1 refl) ; quotSmall = inl (le 1 refl) }) refl) (le 3 refl) (succIsPositive 1) ... | () q3 (succ zero) a with a 0 ... | record { p>1 = le zero () ; pr = pr } ... | record { p>1 = le (succ x) () ; pr = pr } q3 (succ (succ start)) a with q3NDivision (succ (succ start)) ... | r with a (succ (succ start)) ... | s = compositeImpliesNotPrime (succ (succ start)) _ (succPreservesInequality (succIsPositive start)) (le (succ (succ start) +N ((start +N succ start) +N q3Seq (succ (succ start)) start)) (applyEquality (λ i → succ (succ i)) (from (succ (plus (plus (const start) (plus (plus (const start) (succ (const start))) (const (q3Seq (succ (succ start)) start)))) (succ (succ (const start))))) to plus (plus (const start) (succ (succ (plus (const start) zero)))) (succ (plus (plus (const start) (succ (plus (const start) zero))) (const (q3Seq (succ (succ start)) start)))) by applyEquality (λ i → succ (succ (succ (succ i)))) (transitivity (commutative _ start) (+Associative start start _))))) r s q3' : ((n : ℕ) → Prime (q3Seq 41 n)) → False q3' = q3 41 q6 : {n : ℕ} → 3 ∣ (n *N n) → 3 ∣ n q6 {n} 3|n^2 with primesArePrime {3} {n} {n} threeIsPrime 3|n^2 q6 {n} 3|n^2 | inl x = x q6 {n} 3|n^2 | inr x = x _*q10_ : {a : ℕ} → {b : ℕ} → (0 <N a) → (0 <N b) → ℕ *q10Pos : {a : ℕ} → {b : ℕ} → (0<a : 0 <N a) → (0<b : 0 <N b) → 0 <N (_*q10_ 0<a 0<b) _*q10_ {succ zero} {succ b} 0<a 0<b = succ (succ b) _*q10_ {succ (succ a)} {succ zero} 0<a 0<b = _*q10_ {succ a} {2} (le a (applyEquality succ (sumZeroRight a))) (le 1 refl) _*q10_ {succ (succ a)} {succ (succ b)} 0<a 0<b = _*q10_ {succ a} {_*q10_ {succ (succ a)} {succ b} 0<a (le b (applyEquality succ (sumZeroRight b)))} (le a (applyEquality succ (sumZeroRight a))) (*q10Pos 0<a (le b (applyEquality succ (sumZeroRight b)))) *q10Pos {succ zero} {succ b} 0<a 0<b = le (succ b) (applyEquality (λ i → succ (succ i)) (sumZeroRight b)) *q10Pos {succ (succ a)} {succ zero} 0<a 0<b = *q10Pos (le a (applyEquality succ (sumZeroRight a))) (le 1 refl) *q10Pos {succ (succ a)} {succ (succ b)} 0<a 0<b = *q10Pos (le a (applyEquality succ (sumZeroRight a))) (*q10Pos 0<a (le b (applyEquality succ (sumZeroRight b))))
81.867347
693
0.645394
13f7d171ffe571ab31261d45297a5b85c08369d1
25,260
agda
Agda
prototyping/Properties/TypeSaturation.agda
Libertus-Lab/luau
f1b46f4b967f11fabe666da1de0e71b225368260
[ "MIT" ]
1
2021-11-06T08:03:00.000Z
2021-11-06T08:03:00.000Z
prototyping/Properties/TypeSaturation.agda
sthagen/Roblox-luau
39fbd2146a379fb0878369b48764cd7e8772c0fb
[ "MIT" ]
null
null
null
prototyping/Properties/TypeSaturation.agda
sthagen/Roblox-luau
39fbd2146a379fb0878369b48764cd7e8772c0fb
[ "MIT" ]
null
null
null
{-# OPTIONS --rewriting #-} module Properties.TypeSaturation where open import Agda.Builtin.Equality using (_≡_; refl) open import FFI.Data.Either using (Either; Left; Right) open import Luau.Subtyping using (Tree; Language; ¬Language; _<:_; _≮:_; witness; scalar; function; function-err; function-ok; function-ok₁; function-ok₂; scalar-function; _,_; never) open import Luau.Type using (Type; _⇒_; _∩_; _∪_; never; unknown) open import Luau.TypeNormalization using (_∩ⁿ_; _∪ⁿ_) open import Luau.TypeSaturation using (_⋓_; _⋒_; _∩ᵘ_; _∩ⁱ_; ∪-saturate; ∩-saturate; saturate) open import Properties.Subtyping using (dec-language; language-comp; <:-impl-⊇; <:-refl; <:-trans; <:-trans-≮:; <:-impl-¬≮: ; <:-never; <:-unknown; <:-function; <:-union; <:-∪-symm; <:-∪-left; <:-∪-right; <:-∪-lub; <:-∪-assocl; <:-∪-assocr; <:-intersect; <:-∩-symm; <:-∩-left; <:-∩-right; <:-∩-glb; ≮:-function-left; ≮:-function-right; <:-function-∩-∪; <:-function-∩-∩; <:-∩-assocl; <:-∩-assocr; ∩-<:-∪; <:-∩-distl-∪; ∩-distl-∪-<:; <:-∩-distr-∪; ∩-distr-∪-<:) open import Properties.TypeNormalization using (Normal; FunType; _⇒_; _∩_; _∪_; never; unknown; normal-∪ⁿ; normal-∩ⁿ; ∪ⁿ-<:-∪; ∪-<:-∪ⁿ; ∩ⁿ-<:-∩; ∩-<:-∩ⁿ) open import Properties.Contradiction using (CONTRADICTION) open import Properties.Functions using (_∘_) -- Saturation preserves normalization normal-⋒ : ∀ {F G} → FunType F → FunType G → FunType (F ⋒ G) normal-⋒ (R ⇒ S) (T ⇒ U) = (normal-∩ⁿ R T) ⇒ (normal-∩ⁿ S U) normal-⋒ (R ⇒ S) (G ∩ H) = normal-⋒ (R ⇒ S) G ∩ normal-⋒ (R ⇒ S) H normal-⋒ (E ∩ F) G = normal-⋒ E G ∩ normal-⋒ F G normal-⋓ : ∀ {F G} → FunType F → FunType G → FunType (F ⋓ G) normal-⋓ (R ⇒ S) (T ⇒ U) = (normal-∪ⁿ R T) ⇒ (normal-∪ⁿ S U) normal-⋓ (R ⇒ S) (G ∩ H) = normal-⋓ (R ⇒ S) G ∩ normal-⋓ (R ⇒ S) H normal-⋓ (E ∩ F) G = normal-⋓ E G ∩ normal-⋓ F G normal-∩-saturate : ∀ {F} → FunType F → FunType (∩-saturate F) normal-∩-saturate (S ⇒ T) = S ⇒ T normal-∩-saturate (F ∩ G) = (normal-∩-saturate F ∩ normal-∩-saturate G) ∩ normal-⋒ (normal-∩-saturate F) (normal-∩-saturate G) normal-∪-saturate : ∀ {F} → FunType F → FunType (∪-saturate F) normal-∪-saturate (S ⇒ T) = S ⇒ T normal-∪-saturate (F ∩ G) = (normal-∪-saturate F ∩ normal-∪-saturate G) ∩ normal-⋓ (normal-∪-saturate F) (normal-∪-saturate G) normal-saturate : ∀ {F} → FunType F → FunType (saturate F) normal-saturate F = normal-∪-saturate (normal-∩-saturate F) -- Saturation resects subtyping ∪-saturate-<: : ∀ {F} → FunType F → ∪-saturate F <: F ∪-saturate-<: (S ⇒ T) = <:-refl ∪-saturate-<: (F ∩ G) = <:-trans <:-∩-left (<:-intersect (∪-saturate-<: F) (∪-saturate-<: G)) ∩-saturate-<: : ∀ {F} → FunType F → ∩-saturate F <: F ∩-saturate-<: (S ⇒ T) = <:-refl ∩-saturate-<: (F ∩ G) = <:-trans <:-∩-left (<:-intersect (∩-saturate-<: F) (∩-saturate-<: G)) saturate-<: : ∀ {F} → FunType F → saturate F <: F saturate-<: F = <:-trans (∪-saturate-<: (normal-∩-saturate F)) (∩-saturate-<: F) ∩-<:-⋓ : ∀ {F G} → FunType F → FunType G → (F ∩ G) <: (F ⋓ G) ∩-<:-⋓ (R ⇒ S) (T ⇒ U) = <:-trans <:-function-∩-∪ (<:-function (∪ⁿ-<:-∪ R T) (∪-<:-∪ⁿ S U)) ∩-<:-⋓ (R ⇒ S) (G ∩ H) = <:-trans (<:-∩-glb (<:-intersect <:-refl <:-∩-left) (<:-intersect <:-refl <:-∩-right)) (<:-intersect (∩-<:-⋓ (R ⇒ S) G) (∩-<:-⋓ (R ⇒ S) H)) ∩-<:-⋓ (E ∩ F) G = <:-trans (<:-∩-glb (<:-intersect <:-∩-left <:-refl) (<:-intersect <:-∩-right <:-refl)) (<:-intersect (∩-<:-⋓ E G) (∩-<:-⋓ F G)) ∩-<:-⋒ : ∀ {F G} → FunType F → FunType G → (F ∩ G) <: (F ⋒ G) ∩-<:-⋒ (R ⇒ S) (T ⇒ U) = <:-trans <:-function-∩-∩ (<:-function (∩ⁿ-<:-∩ R T) (∩-<:-∩ⁿ S U)) ∩-<:-⋒ (R ⇒ S) (G ∩ H) = <:-trans (<:-∩-glb (<:-intersect <:-refl <:-∩-left) (<:-intersect <:-refl <:-∩-right)) (<:-intersect (∩-<:-⋒ (R ⇒ S) G) (∩-<:-⋒ (R ⇒ S) H)) ∩-<:-⋒ (E ∩ F) G = <:-trans (<:-∩-glb (<:-intersect <:-∩-left <:-refl) (<:-intersect <:-∩-right <:-refl)) (<:-intersect (∩-<:-⋒ E G) (∩-<:-⋒ F G)) <:-∪-saturate : ∀ {F} → FunType F → F <: ∪-saturate F <:-∪-saturate (S ⇒ T) = <:-refl <:-∪-saturate (F ∩ G) = <:-∩-glb (<:-intersect (<:-∪-saturate F) (<:-∪-saturate G)) (<:-trans (<:-intersect (<:-∪-saturate F) (<:-∪-saturate G)) (∩-<:-⋓ (normal-∪-saturate F) (normal-∪-saturate G))) <:-∩-saturate : ∀ {F} → FunType F → F <: ∩-saturate F <:-∩-saturate (S ⇒ T) = <:-refl <:-∩-saturate (F ∩ G) = <:-∩-glb (<:-intersect (<:-∩-saturate F) (<:-∩-saturate G)) (<:-trans (<:-intersect (<:-∩-saturate F) (<:-∩-saturate G)) (∩-<:-⋒ (normal-∩-saturate F) (normal-∩-saturate G))) <:-saturate : ∀ {F} → FunType F → F <: saturate F <:-saturate F = <:-trans (<:-∩-saturate F) (<:-∪-saturate (normal-∩-saturate F)) -- Overloads F is the set of overloads of F data Overloads : Type → Type → Set where here : ∀ {S T} → Overloads (S ⇒ T) (S ⇒ T) left : ∀ {S T F G} → Overloads F (S ⇒ T) → Overloads (F ∩ G) (S ⇒ T) right : ∀ {S T F G} → Overloads G (S ⇒ T) → Overloads (F ∩ G) (S ⇒ T) normal-overload-src : ∀ {F S T} → FunType F → Overloads F (S ⇒ T) → Normal S normal-overload-src (S ⇒ T) here = S normal-overload-src (F ∩ G) (left o) = normal-overload-src F o normal-overload-src (F ∩ G) (right o) = normal-overload-src G o normal-overload-tgt : ∀ {F S T} → FunType F → Overloads F (S ⇒ T) → Normal T normal-overload-tgt (S ⇒ T) here = T normal-overload-tgt (F ∩ G) (left o) = normal-overload-tgt F o normal-overload-tgt (F ∩ G) (right o) = normal-overload-tgt G o -- An inductive presentation of the overloads of F ⋓ G data ∪-Lift (P Q : Type → Set) : Type → Set where union : ∀ {R S T U} → P (R ⇒ S) → Q (T ⇒ U) → -------------------- ∪-Lift P Q ((R ∪ T) ⇒ (S ∪ U)) -- An inductive presentation of the overloads of F ⋒ G data ∩-Lift (P Q : Type → Set) : Type → Set where intersect : ∀ {R S T U} → P (R ⇒ S) → Q (T ⇒ U) → -------------------- ∩-Lift P Q ((R ∩ T) ⇒ (S ∩ U)) -- An inductive presentation of the overloads of ∪-saturate F data ∪-Saturate (P : Type → Set) : Type → Set where base : ∀ {S T} → P (S ⇒ T) → -------------------- ∪-Saturate P (S ⇒ T) union : ∀ {R S T U} → ∪-Saturate P (R ⇒ S) → ∪-Saturate P (T ⇒ U) → -------------------- ∪-Saturate P ((R ∪ T) ⇒ (S ∪ U)) -- An inductive presentation of the overloads of ∩-saturate F data ∩-Saturate (P : Type → Set) : Type → Set where base : ∀ {S T} → P (S ⇒ T) → -------------------- ∩-Saturate P (S ⇒ T) intersect : ∀ {R S T U} → ∩-Saturate P (R ⇒ S) → ∩-Saturate P (T ⇒ U) → -------------------- ∩-Saturate P ((R ∩ T) ⇒ (S ∩ U)) -- The <:-up-closure of a set of function types data <:-Close (P : Type → Set) : Type → Set where defn : ∀ {R S T U} → P (S ⇒ T) → R <: S → T <: U → ------------------ <:-Close P (R ⇒ U) -- F ⊆ᵒ G whenever every overload of F is an overload of G _⊆ᵒ_ : Type → Type → Set F ⊆ᵒ G = ∀ {S T} → Overloads F (S ⇒ T) → Overloads G (S ⇒ T) -- F <:ᵒ G when every overload of G is a supertype of an overload of F _<:ᵒ_ : Type → Type → Set _<:ᵒ_ F G = ∀ {S T} → Overloads G (S ⇒ T) → <:-Close (Overloads F) (S ⇒ T) -- P ⊂: Q when any type in P is a subtype of some type in Q _⊂:_ : (Type → Set) → (Type → Set) → Set P ⊂: Q = ∀ {S T} → P (S ⇒ T) → <:-Close Q (S ⇒ T) -- <:-Close is a monad just : ∀ {P S T} → P (S ⇒ T) → <:-Close P (S ⇒ T) just p = defn p <:-refl <:-refl infixl 5 _>>=_ _>>=ˡ_ _>>=ʳ_ _>>=_ : ∀ {P Q S T} → <:-Close P (S ⇒ T) → (P ⊂: Q) → <:-Close Q (S ⇒ T) (defn p p₁ p₂) >>= P⊂Q with P⊂Q p (defn p p₁ p₂) >>= P⊂Q | defn q q₁ q₂ = defn q (<:-trans p₁ q₁) (<:-trans q₂ p₂) _>>=ˡ_ : ∀ {P R S T} → <:-Close P (S ⇒ T) → (R <: S) → <:-Close P (R ⇒ T) (defn p p₁ p₂) >>=ˡ q = defn p (<:-trans q p₁) p₂ _>>=ʳ_ : ∀ {P S T U} → <:-Close P (S ⇒ T) → (T <: U) → <:-Close P (S ⇒ U) (defn p p₁ p₂) >>=ʳ q = defn p p₁ (<:-trans p₂ q) -- Properties of ⊂: ⊂:-refl : ∀ {P} → P ⊂: P ⊂:-refl p = just p _[∪]_ : ∀ {P Q R S T U} → <:-Close P (R ⇒ S) → <:-Close Q (T ⇒ U) → <:-Close (∪-Lift P Q) ((R ∪ T) ⇒ (S ∪ U)) (defn p p₁ p₂) [∪] (defn q q₁ q₂) = defn (union p q) (<:-union p₁ q₁) (<:-union p₂ q₂) _[∩]_ : ∀ {P Q R S T U} → <:-Close P (R ⇒ S) → <:-Close Q (T ⇒ U) → <:-Close (∩-Lift P Q) ((R ∩ T) ⇒ (S ∩ U)) (defn p p₁ p₂) [∩] (defn q q₁ q₂) = defn (intersect p q) (<:-intersect p₁ q₁) (<:-intersect p₂ q₂) ⊂:-∩-saturate-inj : ∀ {P} → P ⊂: ∩-Saturate P ⊂:-∩-saturate-inj p = defn (base p) <:-refl <:-refl ⊂:-∪-saturate-inj : ∀ {P} → P ⊂: ∪-Saturate P ⊂:-∪-saturate-inj p = just (base p) ⊂:-∩-lift-saturate : ∀ {P} → ∩-Lift (∩-Saturate P) (∩-Saturate P) ⊂: ∩-Saturate P ⊂:-∩-lift-saturate (intersect p q) = just (intersect p q) ⊂:-∪-lift-saturate : ∀ {P} → ∪-Lift (∪-Saturate P) (∪-Saturate P) ⊂: ∪-Saturate P ⊂:-∪-lift-saturate (union p q) = just (union p q) ⊂:-∩-lift : ∀ {P Q R S} → (P ⊂: Q) → (R ⊂: S) → (∩-Lift P R ⊂: ∩-Lift Q S) ⊂:-∩-lift P⊂Q R⊂S (intersect n o) = P⊂Q n [∩] R⊂S o ⊂:-∪-lift : ∀ {P Q R S} → (P ⊂: Q) → (R ⊂: S) → (∪-Lift P R ⊂: ∪-Lift Q S) ⊂:-∪-lift P⊂Q R⊂S (union n o) = P⊂Q n [∪] R⊂S o ⊂:-∩-saturate : ∀ {P Q} → (P ⊂: Q) → (∩-Saturate P ⊂: ∩-Saturate Q) ⊂:-∩-saturate P⊂Q (base p) = P⊂Q p >>= ⊂:-∩-saturate-inj ⊂:-∩-saturate P⊂Q (intersect p q) = (⊂:-∩-saturate P⊂Q p [∩] ⊂:-∩-saturate P⊂Q q) >>= ⊂:-∩-lift-saturate ⊂:-∪-saturate : ∀ {P Q} → (P ⊂: Q) → (∪-Saturate P ⊂: ∪-Saturate Q) ⊂:-∪-saturate P⊂Q (base p) = P⊂Q p >>= ⊂:-∪-saturate-inj ⊂:-∪-saturate P⊂Q (union p q) = (⊂:-∪-saturate P⊂Q p [∪] ⊂:-∪-saturate P⊂Q q) >>= ⊂:-∪-lift-saturate ⊂:-∩-saturate-indn : ∀ {P Q} → (P ⊂: Q) → (∩-Lift Q Q ⊂: Q) → (∩-Saturate P ⊂: Q) ⊂:-∩-saturate-indn P⊂Q QQ⊂Q (base p) = P⊂Q p ⊂:-∩-saturate-indn P⊂Q QQ⊂Q (intersect p q) = (⊂:-∩-saturate-indn P⊂Q QQ⊂Q p [∩] ⊂:-∩-saturate-indn P⊂Q QQ⊂Q q) >>= QQ⊂Q ⊂:-∪-saturate-indn : ∀ {P Q} → (P ⊂: Q) → (∪-Lift Q Q ⊂: Q) → (∪-Saturate P ⊂: Q) ⊂:-∪-saturate-indn P⊂Q QQ⊂Q (base p) = P⊂Q p ⊂:-∪-saturate-indn P⊂Q QQ⊂Q (union p q) = (⊂:-∪-saturate-indn P⊂Q QQ⊂Q p [∪] ⊂:-∪-saturate-indn P⊂Q QQ⊂Q q) >>= QQ⊂Q ∪-saturate-resp-∩-saturation : ∀ {P} → (∩-Lift P P ⊂: P) → (∩-Lift (∪-Saturate P) (∪-Saturate P) ⊂: ∪-Saturate P) ∪-saturate-resp-∩-saturation ∩P⊂P (intersect (base p) (base q)) = ∩P⊂P (intersect p q) >>= ⊂:-∪-saturate-inj ∪-saturate-resp-∩-saturation ∩P⊂P (intersect p (union q q₁)) = (∪-saturate-resp-∩-saturation ∩P⊂P (intersect p q) [∪] ∪-saturate-resp-∩-saturation ∩P⊂P (intersect p q₁)) >>= ⊂:-∪-lift-saturate >>=ˡ <:-∩-distl-∪ >>=ʳ ∩-distl-∪-<: ∪-saturate-resp-∩-saturation ∩P⊂P (intersect (union p p₁) q) = (∪-saturate-resp-∩-saturation ∩P⊂P (intersect p q) [∪] ∪-saturate-resp-∩-saturation ∩P⊂P (intersect p₁ q)) >>= ⊂:-∪-lift-saturate >>=ˡ <:-∩-distr-∪ >>=ʳ ∩-distr-∪-<: ov-language : ∀ {F t} → FunType F → (∀ {S T} → Overloads F (S ⇒ T) → Language (S ⇒ T) t) → Language F t ov-language (S ⇒ T) p = p here ov-language (F ∩ G) p = (ov-language F (p ∘ left) , ov-language G (p ∘ right)) ov-<: : ∀ {F R S T U} → FunType F → Overloads F (R ⇒ S) → ((R ⇒ S) <: (T ⇒ U)) → F <: (T ⇒ U) ov-<: F here p = p ov-<: (F ∩ G) (left o) p = <:-trans <:-∩-left (ov-<: F o p) ov-<: (F ∩ G) (right o) p = <:-trans <:-∩-right (ov-<: G o p) <:ᵒ-impl-<: : ∀ {F G} → FunType F → FunType G → (F <:ᵒ G) → (F <: G) <:ᵒ-impl-<: F (T ⇒ U) F<G with F<G here <:ᵒ-impl-<: F (T ⇒ U) F<G | defn o o₁ o₂ = ov-<: F o (<:-function o₁ o₂) <:ᵒ-impl-<: F (G ∩ H) F<G = <:-∩-glb (<:ᵒ-impl-<: F G (F<G ∘ left)) (<:ᵒ-impl-<: F H (F<G ∘ right)) ⊂:-overloads-left : ∀ {F G} → Overloads F ⊂: Overloads (F ∩ G) ⊂:-overloads-left p = just (left p) ⊂:-overloads-right : ∀ {F G} → Overloads G ⊂: Overloads (F ∩ G) ⊂:-overloads-right p = just (right p) ⊂:-overloads-⋒ : ∀ {F G} → FunType F → FunType G → ∩-Lift (Overloads F) (Overloads G) ⊂: Overloads (F ⋒ G) ⊂:-overloads-⋒ (R ⇒ S) (T ⇒ U) (intersect here here) = defn here (∩-<:-∩ⁿ R T) (∩ⁿ-<:-∩ S U) ⊂:-overloads-⋒ (R ⇒ S) (G ∩ H) (intersect here (left o)) = ⊂:-overloads-⋒ (R ⇒ S) G (intersect here o) >>= ⊂:-overloads-left ⊂:-overloads-⋒ (R ⇒ S) (G ∩ H) (intersect here (right o)) = ⊂:-overloads-⋒ (R ⇒ S) H (intersect here o) >>= ⊂:-overloads-right ⊂:-overloads-⋒ (E ∩ F) G (intersect (left n) o) = ⊂:-overloads-⋒ E G (intersect n o) >>= ⊂:-overloads-left ⊂:-overloads-⋒ (E ∩ F) G (intersect (right n) o) = ⊂:-overloads-⋒ F G (intersect n o) >>= ⊂:-overloads-right ⊂:-⋒-overloads : ∀ {F G} → FunType F → FunType G → Overloads (F ⋒ G) ⊂: ∩-Lift (Overloads F) (Overloads G) ⊂:-⋒-overloads (R ⇒ S) (T ⇒ U) here = defn (intersect here here) (∩ⁿ-<:-∩ R T) (∩-<:-∩ⁿ S U) ⊂:-⋒-overloads (R ⇒ S) (G ∩ H) (left o) = ⊂:-⋒-overloads (R ⇒ S) G o >>= ⊂:-∩-lift ⊂:-refl ⊂:-overloads-left ⊂:-⋒-overloads (R ⇒ S) (G ∩ H) (right o) = ⊂:-⋒-overloads (R ⇒ S) H o >>= ⊂:-∩-lift ⊂:-refl ⊂:-overloads-right ⊂:-⋒-overloads (E ∩ F) G (left o) = ⊂:-⋒-overloads E G o >>= ⊂:-∩-lift ⊂:-overloads-left ⊂:-refl ⊂:-⋒-overloads (E ∩ F) G (right o) = ⊂:-⋒-overloads F G o >>= ⊂:-∩-lift ⊂:-overloads-right ⊂:-refl ⊂:-overloads-⋓ : ∀ {F G} → FunType F → FunType G → ∪-Lift (Overloads F) (Overloads G) ⊂: Overloads (F ⋓ G) ⊂:-overloads-⋓ (R ⇒ S) (T ⇒ U) (union here here) = defn here (∪-<:-∪ⁿ R T) (∪ⁿ-<:-∪ S U) ⊂:-overloads-⋓ (R ⇒ S) (G ∩ H) (union here (left o)) = ⊂:-overloads-⋓ (R ⇒ S) G (union here o) >>= ⊂:-overloads-left ⊂:-overloads-⋓ (R ⇒ S) (G ∩ H) (union here (right o)) = ⊂:-overloads-⋓ (R ⇒ S) H (union here o) >>= ⊂:-overloads-right ⊂:-overloads-⋓ (E ∩ F) G (union (left n) o) = ⊂:-overloads-⋓ E G (union n o) >>= ⊂:-overloads-left ⊂:-overloads-⋓ (E ∩ F) G (union (right n) o) = ⊂:-overloads-⋓ F G (union n o) >>= ⊂:-overloads-right ⊂:-⋓-overloads : ∀ {F G} → FunType F → FunType G → Overloads (F ⋓ G) ⊂: ∪-Lift (Overloads F) (Overloads G) ⊂:-⋓-overloads (R ⇒ S) (T ⇒ U) here = defn (union here here) (∪ⁿ-<:-∪ R T) (∪-<:-∪ⁿ S U) ⊂:-⋓-overloads (R ⇒ S) (G ∩ H) (left o) = ⊂:-⋓-overloads (R ⇒ S) G o >>= ⊂:-∪-lift ⊂:-refl ⊂:-overloads-left ⊂:-⋓-overloads (R ⇒ S) (G ∩ H) (right o) = ⊂:-⋓-overloads (R ⇒ S) H o >>= ⊂:-∪-lift ⊂:-refl ⊂:-overloads-right ⊂:-⋓-overloads (E ∩ F) G (left o) = ⊂:-⋓-overloads E G o >>= ⊂:-∪-lift ⊂:-overloads-left ⊂:-refl ⊂:-⋓-overloads (E ∩ F) G (right o) = ⊂:-⋓-overloads F G o >>= ⊂:-∪-lift ⊂:-overloads-right ⊂:-refl ∪-saturate-overloads : ∀ {F} → FunType F → Overloads (∪-saturate F) ⊂: ∪-Saturate (Overloads F) ∪-saturate-overloads (S ⇒ T) here = just (base here) ∪-saturate-overloads (F ∩ G) (left (left o)) = ∪-saturate-overloads F o >>= ⊂:-∪-saturate ⊂:-overloads-left ∪-saturate-overloads (F ∩ G) (left (right o)) = ∪-saturate-overloads G o >>= ⊂:-∪-saturate ⊂:-overloads-right ∪-saturate-overloads (F ∩ G) (right o) = ⊂:-⋓-overloads (normal-∪-saturate F) (normal-∪-saturate G) o >>= ⊂:-∪-lift (∪-saturate-overloads F) (∪-saturate-overloads G) >>= ⊂:-∪-lift (⊂:-∪-saturate ⊂:-overloads-left) (⊂:-∪-saturate ⊂:-overloads-right) >>= ⊂:-∪-lift-saturate overloads-∪-saturate : ∀ {F} → FunType F → ∪-Saturate (Overloads F) ⊂: Overloads (∪-saturate F) overloads-∪-saturate F = ⊂:-∪-saturate-indn (inj F) (step F) where inj : ∀ {F} → FunType F → Overloads F ⊂: Overloads (∪-saturate F) inj (S ⇒ T) here = just here inj (F ∩ G) (left p) = inj F p >>= ⊂:-overloads-left >>= ⊂:-overloads-left inj (F ∩ G) (right p) = inj G p >>= ⊂:-overloads-right >>= ⊂:-overloads-left step : ∀ {F} → FunType F → ∪-Lift (Overloads (∪-saturate F)) (Overloads (∪-saturate F)) ⊂: Overloads (∪-saturate F) step (S ⇒ T) (union here here) = defn here (<:-∪-lub <:-refl <:-refl) <:-∪-left step (F ∩ G) (union (left (left p)) (left (left q))) = step F (union p q) >>= ⊂:-overloads-left >>= ⊂:-overloads-left step (F ∩ G) (union (left (left p)) (left (right q))) = ⊂:-overloads-⋓ (normal-∪-saturate F) (normal-∪-saturate G) (union p q) >>= ⊂:-overloads-right step (F ∩ G) (union (left (right p)) (left (left q))) = ⊂:-overloads-⋓ (normal-∪-saturate F) (normal-∪-saturate G) (union q p) >>= ⊂:-overloads-right >>=ˡ <:-∪-symm >>=ʳ <:-∪-symm step (F ∩ G) (union (left (right p)) (left (right q))) = step G (union p q) >>= ⊂:-overloads-right >>= ⊂:-overloads-left step (F ∩ G) (union p (right q)) with ⊂:-⋓-overloads (normal-∪-saturate F) (normal-∪-saturate G) q step (F ∩ G) (union (left (left p)) (right q)) | defn (union q₁ q₂) q₃ q₄ = (step F (union p q₁) [∪] just q₂) >>= ⊂:-overloads-⋓ (normal-∪-saturate F) (normal-∪-saturate G) >>= ⊂:-overloads-right >>=ˡ <:-trans (<:-union <:-refl q₃) <:-∪-assocl >>=ʳ <:-trans <:-∪-assocr (<:-union <:-refl q₄) step (F ∩ G) (union (left (right p)) (right q)) | defn (union q₁ q₂) q₃ q₄ = (just q₁ [∪] step G (union p q₂)) >>= ⊂:-overloads-⋓ (normal-∪-saturate F) (normal-∪-saturate G) >>= ⊂:-overloads-right >>=ˡ <:-trans (<:-union <:-refl q₃) (<:-∪-lub (<:-trans <:-∪-left <:-∪-right) (<:-∪-lub <:-∪-left (<:-trans <:-∪-right <:-∪-right))) >>=ʳ <:-trans (<:-∪-lub (<:-trans <:-∪-left <:-∪-right) (<:-∪-lub <:-∪-left (<:-trans <:-∪-right <:-∪-right))) (<:-union <:-refl q₄) step (F ∩ G) (union (right p) (right q)) | defn (union q₁ q₂) q₃ q₄ with ⊂:-⋓-overloads (normal-∪-saturate F) (normal-∪-saturate G) p step (F ∩ G) (union (right p) (right q)) | defn (union q₁ q₂) q₃ q₄ | defn (union p₁ p₂) p₃ p₄ = (step F (union p₁ q₁) [∪] step G (union p₂ q₂)) >>= ⊂:-overloads-⋓ (normal-∪-saturate F) (normal-∪-saturate G) >>= ⊂:-overloads-right >>=ˡ <:-trans (<:-union p₃ q₃) (<:-∪-lub (<:-union <:-∪-left <:-∪-left) (<:-union <:-∪-right <:-∪-right)) >>=ʳ <:-trans (<:-∪-lub (<:-union <:-∪-left <:-∪-left) (<:-union <:-∪-right <:-∪-right)) (<:-union p₄ q₄) step (F ∩ G) (union (right p) q) with ⊂:-⋓-overloads (normal-∪-saturate F) (normal-∪-saturate G) p step (F ∩ G) (union (right p) (left (left q))) | defn (union p₁ p₂) p₃ p₄ = (step F (union p₁ q) [∪] just p₂) >>= ⊂:-overloads-⋓ (normal-∪-saturate F) (normal-∪-saturate G) >>= ⊂:-overloads-right >>=ˡ <:-trans (<:-union p₃ <:-refl) (<:-∪-lub (<:-union <:-∪-left <:-refl) (<:-trans <:-∪-right <:-∪-left)) >>=ʳ <:-trans (<:-∪-lub (<:-union <:-∪-left <:-refl) (<:-trans <:-∪-right <:-∪-left)) (<:-union p₄ <:-refl) step (F ∩ G) (union (right p) (left (right q))) | defn (union p₁ p₂) p₃ p₄ = (just p₁ [∪] step G (union p₂ q)) >>= ⊂:-overloads-⋓ (normal-∪-saturate F) (normal-∪-saturate G) >>= ⊂:-overloads-right >>=ˡ <:-trans (<:-union p₃ <:-refl) <:-∪-assocr >>=ʳ <:-trans <:-∪-assocl (<:-union p₄ <:-refl) step (F ∩ G) (union (right p) (right q)) | defn (union p₁ p₂) p₃ p₄ with ⊂:-⋓-overloads (normal-∪-saturate F) (normal-∪-saturate G) q step (F ∩ G) (union (right p) (right q)) | defn (union p₁ p₂) p₃ p₄ | defn (union q₁ q₂) q₃ q₄ = (step F (union p₁ q₁) [∪] step G (union p₂ q₂)) >>= ⊂:-overloads-⋓ (normal-∪-saturate F) (normal-∪-saturate G) >>= ⊂:-overloads-right >>=ˡ <:-trans (<:-union p₃ q₃) (<:-∪-lub (<:-union <:-∪-left <:-∪-left) (<:-union <:-∪-right <:-∪-right)) >>=ʳ <:-trans (<:-∪-lub (<:-union <:-∪-left <:-∪-left) (<:-union <:-∪-right <:-∪-right)) (<:-union p₄ q₄) ∪-saturated : ∀ {F} → FunType F → ∪-Lift (Overloads (∪-saturate F)) (Overloads (∪-saturate F)) ⊂: Overloads (∪-saturate F) ∪-saturated F o = ⊂:-∪-lift (∪-saturate-overloads F) (∪-saturate-overloads F) o >>= ⊂:-∪-lift-saturate >>= overloads-∪-saturate F ∩-saturate-overloads : ∀ {F} → FunType F → Overloads (∩-saturate F) ⊂: ∩-Saturate (Overloads F) ∩-saturate-overloads (S ⇒ T) here = just (base here) ∩-saturate-overloads (F ∩ G) (left (left o)) = ∩-saturate-overloads F o >>= ⊂:-∩-saturate ⊂:-overloads-left ∩-saturate-overloads (F ∩ G) (left (right o)) = ∩-saturate-overloads G o >>= ⊂:-∩-saturate ⊂:-overloads-right ∩-saturate-overloads (F ∩ G) (right o) = ⊂:-⋒-overloads (normal-∩-saturate F) (normal-∩-saturate G) o >>= ⊂:-∩-lift (∩-saturate-overloads F) (∩-saturate-overloads G) >>= ⊂:-∩-lift (⊂:-∩-saturate ⊂:-overloads-left) (⊂:-∩-saturate ⊂:-overloads-right) >>= ⊂:-∩-lift-saturate overloads-∩-saturate : ∀ {F} → FunType F → ∩-Saturate (Overloads F) ⊂: Overloads (∩-saturate F) overloads-∩-saturate F = ⊂:-∩-saturate-indn (inj F) (step F) where inj : ∀ {F} → FunType F → Overloads F ⊂: Overloads (∩-saturate F) inj (S ⇒ T) here = just here inj (F ∩ G) (left p) = inj F p >>= ⊂:-overloads-left >>= ⊂:-overloads-left inj (F ∩ G) (right p) = inj G p >>= ⊂:-overloads-right >>= ⊂:-overloads-left step : ∀ {F} → FunType F → ∩-Lift (Overloads (∩-saturate F)) (Overloads (∩-saturate F)) ⊂: Overloads (∩-saturate F) step (S ⇒ T) (intersect here here) = defn here <:-∩-left (<:-∩-glb <:-refl <:-refl) step (F ∩ G) (intersect (left (left p)) (left (left q))) = step F (intersect p q) >>= ⊂:-overloads-left >>= ⊂:-overloads-left step (F ∩ G) (intersect (left (left p)) (left (right q))) = ⊂:-overloads-⋒ (normal-∩-saturate F) (normal-∩-saturate G) (intersect p q) >>= ⊂:-overloads-right step (F ∩ G) (intersect (left (right p)) (left (left q))) = ⊂:-overloads-⋒ (normal-∩-saturate F) (normal-∩-saturate G) (intersect q p) >>= ⊂:-overloads-right >>=ˡ <:-∩-symm >>=ʳ <:-∩-symm step (F ∩ G) (intersect (left (right p)) (left (right q))) = step G (intersect p q) >>= ⊂:-overloads-right >>= ⊂:-overloads-left step (F ∩ G) (intersect (right p) q) with ⊂:-⋒-overloads (normal-∩-saturate F) (normal-∩-saturate G) p step (F ∩ G) (intersect (right p) (left (left q))) | defn (intersect p₁ p₂) p₃ p₄ = (step F (intersect p₁ q) [∩] just p₂) >>= ⊂:-overloads-⋒ (normal-∩-saturate F) (normal-∩-saturate G) >>= ⊂:-overloads-right >>=ˡ <:-trans (<:-intersect p₃ <:-refl) (<:-∩-glb (<:-intersect <:-∩-left <:-refl) (<:-trans <:-∩-left <:-∩-right)) >>=ʳ <:-trans (<:-∩-glb (<:-intersect <:-∩-left <:-refl) (<:-trans <:-∩-left <:-∩-right)) (<:-intersect p₄ <:-refl) step (F ∩ G) (intersect (right p) (left (right q))) | defn (intersect p₁ p₂) p₃ p₄ = (just p₁ [∩] step G (intersect p₂ q)) >>= ⊂:-overloads-⋒ (normal-∩-saturate F) (normal-∩-saturate G) >>= ⊂:-overloads-right >>=ˡ <:-trans (<:-intersect p₃ <:-refl) <:-∩-assocr >>=ʳ <:-trans <:-∩-assocl (<:-intersect p₄ <:-refl) step (F ∩ G) (intersect (right p) (right q)) | defn (intersect p₁ p₂) p₃ p₄ with ⊂:-⋒-overloads (normal-∩-saturate F) (normal-∩-saturate G) q step (F ∩ G) (intersect (right p) (right q)) | defn (intersect p₁ p₂) p₃ p₄ | defn (intersect q₁ q₂) q₃ q₄ = (step F (intersect p₁ q₁) [∩] step G (intersect p₂ q₂)) >>= ⊂:-overloads-⋒ (normal-∩-saturate F) (normal-∩-saturate G) >>= ⊂:-overloads-right >>=ˡ <:-trans (<:-intersect p₃ q₃) (<:-∩-glb (<:-intersect <:-∩-left <:-∩-left) (<:-intersect <:-∩-right <:-∩-right)) >>=ʳ <:-trans (<:-∩-glb (<:-intersect <:-∩-left <:-∩-left) (<:-intersect <:-∩-right <:-∩-right)) (<:-intersect p₄ q₄) step (F ∩ G) (intersect p (right q)) with ⊂:-⋒-overloads (normal-∩-saturate F) (normal-∩-saturate G) q step (F ∩ G) (intersect (left (left p)) (right q)) | defn (intersect q₁ q₂) q₃ q₄ = (step F (intersect p q₁) [∩] just q₂) >>= ⊂:-overloads-⋒ (normal-∩-saturate F) (normal-∩-saturate G) >>= ⊂:-overloads-right >>=ˡ <:-trans (<:-intersect <:-refl q₃) <:-∩-assocl >>=ʳ <:-trans <:-∩-assocr (<:-intersect <:-refl q₄) step (F ∩ G) (intersect (left (right p)) (right q)) | defn (intersect q₁ q₂) q₃ q₄ = (just q₁ [∩] step G (intersect p q₂) ) >>= ⊂:-overloads-⋒ (normal-∩-saturate F) (normal-∩-saturate G) >>= ⊂:-overloads-right >>=ˡ <:-trans (<:-intersect <:-refl q₃) (<:-∩-glb (<:-trans <:-∩-right <:-∩-left) (<:-∩-glb <:-∩-left (<:-trans <:-∩-right <:-∩-right))) >>=ʳ <:-∩-glb (<:-trans <:-∩-right <:-∩-left) (<:-trans (<:-∩-glb <:-∩-left (<:-trans <:-∩-right <:-∩-right)) q₄) step (F ∩ G) (intersect (right p) (right q)) | defn (intersect q₁ q₂) q₃ q₄ with ⊂:-⋒-overloads (normal-∩-saturate F) (normal-∩-saturate G) p step (F ∩ G) (intersect (right p) (right q)) | defn (intersect q₁ q₂) q₃ q₄ | defn (intersect p₁ p₂) p₃ p₄ = (step F (intersect p₁ q₁) [∩] step G (intersect p₂ q₂)) >>= ⊂:-overloads-⋒ (normal-∩-saturate F) (normal-∩-saturate G) >>= ⊂:-overloads-right >>=ˡ <:-trans (<:-intersect p₃ q₃) (<:-∩-glb (<:-intersect <:-∩-left <:-∩-left) (<:-intersect <:-∩-right <:-∩-right)) >>=ʳ <:-trans (<:-∩-glb (<:-intersect <:-∩-left <:-∩-left) (<:-intersect <:-∩-right <:-∩-right)) (<:-intersect p₄ q₄) saturate-overloads : ∀ {F} → FunType F → Overloads (saturate F) ⊂: ∪-Saturate (∩-Saturate (Overloads F)) saturate-overloads F o = ∪-saturate-overloads (normal-∩-saturate F) o >>= (⊂:-∪-saturate (∩-saturate-overloads F)) overloads-saturate : ∀ {F} → FunType F → ∪-Saturate (∩-Saturate (Overloads F)) ⊂: Overloads (saturate F) overloads-saturate F o = ⊂:-∪-saturate (overloads-∩-saturate F) o >>= overloads-∪-saturate (normal-∩-saturate F) -- Saturated F whenever -- * if F has overloads (R ⇒ S) and (T ⇒ U) then F has an overload which is a subtype of ((R ∩ T) ⇒ (S ∩ U)) -- * ditto union data Saturated (F : Type) : Set where defn : (∀ {R S T U} → Overloads F (R ⇒ S) → Overloads F (T ⇒ U) → <:-Close (Overloads F) ((R ∩ T) ⇒ (S ∩ U))) → (∀ {R S T U} → Overloads F (R ⇒ S) → Overloads F (T ⇒ U) → <:-Close (Overloads F) ((R ∪ T) ⇒ (S ∪ U))) → ----------- Saturated F -- saturated F is saturated! saturated : ∀ {F} → FunType F → Saturated (saturate F) saturated F = defn (λ n o → (saturate-overloads F n [∩] saturate-overloads F o) >>= ∪-saturate-resp-∩-saturation ⊂:-∩-lift-saturate >>= overloads-saturate F) (λ n o → ∪-saturated (normal-∩-saturate F) (union n o))
58.202765
459
0.534125
31c1b91cffc6a98984b20f296bfc080858618a9c
15,498
agda
Agda
Cubical/HITs/James/Inductive/Coherence.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/HITs/James/Inductive/Coherence.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/HITs/James/Inductive/Coherence.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{- This file contains: - Path lemmas used in the colimit-equivalence proof. Verbose, indeed. But should be simple. The length mainly thanks to: - Degenerate cubes that seem "obvious", but have to be constructed manually; - J rule is cubersome to use, especially when iteratively applied, also it is overcomplicated to construct JRefl in nested cases. -} {-# OPTIONS --safe --experimental-lossy-unification #-} module Cubical.HITs.James.Inductive.Coherence where open import Cubical.Foundations.Prelude open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Function private variable ℓ ℓ' : Level -- Lots of degenerate cubes used as intial input to J rule private module _ {A : Type ℓ}(a : A) where degenerate1 : (i j k : I) → A degenerate1 i j k = hfill (λ k → λ { (i = i0) → a ; (i = i1) → doubleCompPath-filler (refl {x = a}) refl refl k j ; (j = i0) → a ; (j = i1) → a}) (inS a) k degenerate1' : (i j k : I) → A degenerate1' i j k = hfill (λ k → λ { (i = i0) → a ; (i = i1) → compPath-filler (refl {x = a}) refl k j ; (j = i0) → a ; (j = i1) → a}) (inS a) k degenerate1'' : (i j k : I) → A degenerate1'' i j k = hfill (λ k → λ { (i = i0) → a ; (i = i1) → compPath-filler (refl {x = a}) (refl ∙ refl) k j ; (j = i0) → a ; (j = i1) → degenerate1 i k i1}) (inS a) k module _ {B : Type ℓ'}(f : A → B) where degenerate2 : (i j k : I) → B degenerate2 i j k = hfill (λ k → λ { (i = i0) → f a ; (i = i1) → doubleCompPath-filler (refl {x = f a}) refl refl k j ; (j = i0) → f a ; (j = i1) → f a }) (inS (f a)) k degenerate3 : (i j k : I) → B degenerate3 i j k = hfill (λ k → λ { (i = i0) → f (doubleCompPath-filler (refl {x = a}) refl refl k j) ; (i = i1) → doubleCompPath-filler (refl {x = f a}) refl refl k j ; (j = i0) → f a ; (j = i1) → f a }) (inS (f a)) k someCommonDegenerateCube : (i j k : I) → B someCommonDegenerateCube i j k = hcomp (λ l → λ { (i = i0) → f a ; (i = i1) → degenerate3 k j l ; (j = i0) → f a ; (j = i1) → f a ; (k = i0) → f (degenerate1 i j l) ; (k = i1) → degenerate2 i j l }) (f a) degenerate4 : (i j k : I) → A degenerate4 i j k = hfill (λ k → λ { (i = i0) → compPath-filler (refl {x = a}) (refl ∙∙ refl ∙∙ refl) k j ; (i = i1) → doubleCompPath-filler (refl {x = a}) refl refl j k ; (j = i0) → a ; (j = i1) → (refl {x = a} ∙∙ refl ∙∙ refl) k }) (inS a) k degenerate5 : (i j k : I) → A degenerate5 i j k = hcomp (λ l → λ { (i = i0) → compPath-filler (refl {x = a}) (refl ∙∙ refl ∙∙ refl) k j ; (i = i1) → doubleCompPath-filler (refl {x = a}) refl refl (j ∧ ~ l) k ; (j = i0) → a ; (j = i1) → doubleCompPath-filler (refl {x = a}) refl refl (~ i ∨ ~ l) k ; (k = i0) → a ; (k = i1) → degenerate4 i j i1 }) (degenerate4 i j k) degenerate5' : (i j k : I) → A degenerate5' i j k = hfill (λ k → λ { (i = i0) → doubleCompPath-filler (refl {x = a}) refl (refl ∙ refl) k j ; (i = i1) → a ; (j = i0) → a ; (j = i1) → compPath-filler (refl {x = a}) refl (~ i) k }) (inS a) k -- Cubes of which mostly are constructed by J rule module _ {A : Type ℓ}{a : A} where coh-helper-refl : (q' : a ≡ a)(h : refl ≡ q') → refl ≡ refl ∙∙ refl ∙∙ q' coh-helper-refl q' h i j = hcomp (λ k → λ { (i = i0) → a ; (i = i1) → doubleCompPath-filler refl refl q' k j ; (j = i0) → a ; (j = i1) → h i k }) a coh-helper' : (b : A)(p : a ≡ b) (c : A)(q : b ≡ c) (q' : b ≡ c)(r : PathP (λ i → p i ≡ q i) p q') → refl ≡ (sym q) ∙∙ refl ∙∙ q' coh-helper' = J> J> coh-helper-refl coh-helper'-Refl1 : coh-helper' _ refl ≡ J> coh-helper-refl coh-helper'-Refl1 = transportRefl _ coh-helper'-Refl2 : coh-helper' _ refl _ refl ≡ coh-helper-refl coh-helper'-Refl2 = (λ i → coh-helper'-Refl1 i _ refl) ∙ transportRefl _ coh-helper : {b c : A}(p : a ≡ b)(q q' : b ≡ c) (h : PathP (λ i → p i ≡ q i) p q') → refl ≡ (sym q) ∙∙ refl ∙∙ q' coh-helper p = coh-helper' _ p _ coh-helper-Refl : coh-helper-refl ≡ coh-helper refl refl coh-helper-Refl = sym coh-helper'-Refl2 module _ {A : Type ℓ}{B : Type ℓ'}{a b c d : A} where doubleCompPath-cong-filler : {a' b' c' d' : B} (f : A → B) {pa : f a ≡ a'}{pb : f b ≡ b'}{pc : f c ≡ c'}{pd : f d ≡ d'} (p : a ≡ b)(q : b ≡ c)(r : c ≡ d) {p' : a' ≡ b'}{q' : b' ≡ c'}{r' : c' ≡ d'} (h : PathP (λ i → pa i ≡ pb i) (cong f p) p') (h' : PathP (λ i → pb i ≡ pc i) (cong f q) q') (h'' : PathP (λ i → pc i ≡ pd i) (cong f r) r') → (i j k : I) → B doubleCompPath-cong-filler f p q r {p' = p'} {q' = q'} {r' = r'} h h' h'' i j k = hfill (λ k → λ { (i = i0) → f (doubleCompPath-filler p q r k j) ; (i = i1) → doubleCompPath-filler p' q' r' k j ; (j = i0) → h i (~ k) ; (j = i1) → h'' i k }) (inS (h' i j)) k doubleCompPath-cong : (f : A → B) (p : a ≡ b)(q : b ≡ c)(r : c ≡ d) → cong f (p ∙∙ q ∙∙ r) ≡ cong f p ∙∙ cong f q ∙∙ cong f r doubleCompPath-cong f p q r i j = doubleCompPath-cong-filler f {pa = refl} {pb = refl} {pc = refl} {pd = refl} p q r refl refl refl i j i1 module _ {A : Type ℓ}{a b c : A} where comp-cong-square' : (p : a ≡ b)(q : a ≡ c) (r : b ≡ c)(h : r ≡ sym p ∙∙ refl ∙∙ q) → p ∙ r ≡ q comp-cong-square' p q r h i j = hcomp (λ k → λ { (i = i0) → compPath-filler p r k j ; (i = i1) → doubleCompPath-filler (sym p) refl q j k ; (j = i0) → a ; (j = i1) → h i k }) (p j) module _ {B : Type ℓ'} where comp-cong-square : (f : A → B) (p : a ≡ b)(q : b ≡ c) → cong f (p ∙ q) ≡ cong f p ∙ cong f q comp-cong-square f p q i j = hcomp (λ k → λ { (i = i0) → f (compPath-filler p q k j) ; (i = i1) → compPath-filler (cong f p) (cong f q) k j ; (j = i0) → f a ; (j = i1) → f (q k) }) (f (p j)) module _ {A : Type ℓ}{B : Type ℓ'}{a b c : A} (f : A → B)(p : a ≡ b) (q : f a ≡ f c)(r : b ≡ c) (h : cong f r ≡ sym (cong f p) ∙∙ refl ∙∙ q) where comp-cong-helper-filler : (i j k : I) → B comp-cong-helper-filler i j k = hfill (λ k → λ { (i = i0) → comp-cong-square f p r (~ k) j ; (i = i1) → q j ; (j = i0) → f a ; (j = i1) → f c }) (inS (comp-cong-square' _ _ _ h i j)) k comp-cong-helper : cong f (p ∙ r) ≡ q comp-cong-helper i j = comp-cong-helper-filler i j i1 module _ {A : Type ℓ}{a : A} where push-helper-refl : (q' : a ≡ a)(h : refl ≡ q') → refl ≡ refl ∙ q' push-helper-refl q' h i j = hcomp (λ k → λ { (i = i0) → a ; (i = i1) → compPath-filler refl q' k j ; (j = i0) → a ; (j = i1) → h i k }) a push-helper' : (b : A)(p : a ≡ b) (c : A)(q : b ≡ c) (q' : c ≡ c)(h : refl ≡ q') → PathP (λ i → p i ≡ q i) p (q ∙ q') push-helper' = J> J> push-helper-refl push-helper'-Refl1 : push-helper' _ refl ≡ J> push-helper-refl push-helper'-Refl1 = transportRefl _ push-helper'-Refl2 : push-helper' _ refl _ refl ≡ push-helper-refl push-helper'-Refl2 = (λ i → push-helper'-Refl1 i _ refl) ∙ transportRefl _ push-helper : {b c : A} (p : a ≡ b)(q : b ≡ c)(q' : c ≡ c)(h : refl ≡ q') → PathP (λ i → p i ≡ q i) p (q ∙ q') push-helper p = push-helper' _ p _ push-helper-Refl : push-helper-refl ≡ push-helper refl refl push-helper-Refl = sym push-helper'-Refl2 module _ {A : Type ℓ}{B : Type ℓ'}{a : A}(f : A → B) where push-helper-cong-Type : {b c : A} (p : a ≡ b)(q : b ≡ c) (q' : c ≡ c)(sqr : refl ≡ q') → Type _ push-helper-cong-Type p q q' sqr = SquareP (λ i j → f (push-helper p q _ sqr i j) ≡ push-helper (cong f p) (cong f q) _ (λ i j → f (sqr i j)) i j) (λ i j → f (p i)) (λ i j → comp-cong-square f q q' j i) (λ i j → f (p i)) (λ i j → f (q i)) push-helper-cong-refl : push-helper-cong-Type refl refl refl refl push-helper-cong-refl = transport (λ t → SquareP (λ i j → f (push-helper-Refl t _ (λ i j → a) i j) ≡ push-helper-Refl t _ (λ i j → f a) i j) (λ i j → f a) (λ i j → comp-cong-square f (refl {x = a}) refl j i) (λ i j → f a) (λ i j → f a)) (λ i j k → someCommonDegenerateCube a f i j k) push-helper-cong' : (b : A)(p : a ≡ b) (c : A)(q : b ≡ c) (q' : c ≡ c)(sqr : refl ≡ q') → push-helper-cong-Type p q q' sqr push-helper-cong' = J> J> J> push-helper-cong-refl push-helper-cong : ∀ {b c} p q q' sqr → push-helper-cong-Type {b = b} {c = c} p q q' sqr push-helper-cong p = push-helper-cong' _ p _ module _ {A : Type ℓ}{a : A} where push-coh-helper-Type : {b c : A} (p : a ≡ b)(q q' : b ≡ c) (sqr : PathP (λ i → p i ≡ q i) p q') → Type _ push-coh-helper-Type p q q' sqr = SquareP (λ i j → push-helper p q _ (coh-helper _ _ _ sqr) i j ≡ sqr i j) (λ i j → p i) (λ i j → comp-cong-square' q q' _ refl j i) (λ i j → p i) (λ i j → q i) push-coh-helper-refl' : SquareP (λ i j → push-helper-refl _ (coh-helper-refl _ (λ i j → a)) i j ≡ a) (λ i j → a) (λ i j → comp-cong-square' (refl {x = a}) refl _ refl j i) (λ i j → a) (λ i j → a) push-coh-helper-refl' i j k = hcomp (λ l → λ { (i = i0) → a ; (i = i1) → degenerate5 a k j l ; (j = i0) → a ; (j = i1) → degenerate1 a i l (~ k) ; (k = i0) → degenerate1'' a i j l ; (k = i1) → a }) a push-coh-helper-refl : push-coh-helper-Type refl refl refl refl push-coh-helper-refl = transport (λ t → SquareP (λ i j → push-helper-Refl t _ (coh-helper-Refl t _ (λ i j → a)) i j ≡ a) (λ i j → a) (λ i j → comp-cong-square' (refl {x = a}) refl _ refl j i) (λ i j → a) (λ i j → a)) push-coh-helper-refl' push-coh-helper' : (b : A)(p : a ≡ b) (c : A)(q : b ≡ c) (q' : b ≡ c)(sqr : PathP (λ i → p i ≡ q i) p q') → push-coh-helper-Type p q q' sqr push-coh-helper' = J> J> J> push-coh-helper-refl push-coh-helper : ∀ {b c} p q q' sqr → push-coh-helper-Type {b = b} {c = c} p q q' sqr push-coh-helper p q q' sqr = push-coh-helper' _ p _ q q' sqr module _ {A : Type ℓ}{a : A} where push-square-helper-refl : refl ∙∙ refl ∙∙ (refl ∙ refl) ≡ refl {x = a} push-square-helper-refl i j = degenerate5' a i j i1 push-square-helper' : (b : A)(q : a ≡ b) (c : A)(q' : b ≡ c) → sym q ∙∙ refl ∙∙ (q ∙ q') ≡ q' push-square-helper' = J> J> push-square-helper-refl push-square-helper'-Refl1 : push-square-helper' _ refl ≡ J> push-square-helper-refl push-square-helper'-Refl1 = transportRefl _ push-square-helper'-Refl2 : push-square-helper' _ refl _ refl ≡ push-square-helper-refl push-square-helper'-Refl2 = (λ i → push-square-helper'-Refl1 i _ refl) ∙ transportRefl _ push-square-helper : {b c : A} (q : a ≡ b)(q' : b ≡ c) → sym q ∙∙ refl ∙∙ (q ∙ q') ≡ q' push-square-helper p = push-square-helper' _ p _ push-square-helper-Refl : push-square-helper-refl ≡ push-square-helper refl refl push-square-helper-Refl = sym push-square-helper'-Refl2 module _ {A : Type ℓ}{a : A} where coh-cube-helper-Type : {b c : A}(p : a ≡ b)(q : b ≡ c) (q' : c ≡ c)(sqr : refl ≡ q') → Type _ coh-cube-helper-Type {c = c} p q q' sqr = SquareP (λ i j → coh-helper _ _ _ (push-helper p q q' sqr) i j ≡ sqr i j) (λ i j → c) (λ i j → push-square-helper q q' j i) (λ i j → c) (λ i j → c) coh-cube-helper-refl' : SquareP (λ i j → coh-helper-refl _ (push-helper-refl refl (λ i j → a)) i j ≡ a) (λ i j → a) (λ i j → push-square-helper-refl {a = a} j i) (λ i j → a) (λ i j → a) coh-cube-helper-refl' i j k = hcomp (λ l → λ { (i = i0) → a ; (i = i1) → degenerate5' a k j l ; (j = i0) → a ; (j = i1) → degenerate1' a i l (~ k) ; (k = i0) → degenerate1'' a i j l ; (k = i1) → a }) a coh-cube-helper-refl : coh-cube-helper-Type refl refl refl refl coh-cube-helper-refl = transport (λ t → SquareP (λ i j → coh-helper-Refl t _ (push-helper-Refl t refl (λ i j → a)) i j ≡ a) (λ i j → a) (λ i j → push-square-helper-Refl {a = a} t j i) (λ i j → a) (λ i j → a)) coh-cube-helper-refl' coh-cube-helper' : (b : A)(p : a ≡ b) (c : A)(q : b ≡ c) (q' : c ≡ c)(sqr : refl ≡ q') → coh-cube-helper-Type p q q' sqr coh-cube-helper' = J> J> J> coh-cube-helper-refl coh-cube-helper : ∀ {b c} p q q' sqr → coh-cube-helper-Type {b = b} {c = c} p q q' sqr coh-cube-helper p q q' sqr = coh-cube-helper' _ p _ q q' sqr module _ {A : Type ℓ}{B : Type ℓ'}{a : A}(f : A → B) where coh-helper-cong-Type : {b c : A}{a' b' c' : B} (pa : f a ≡ a')(pb : f b ≡ b')(pc : f c ≡ c') {p : a ≡ b }(q r : b ≡ c ) {p' : a' ≡ b'}{q' r' : b' ≡ c'} (h : PathP (λ i → pa i ≡ pb i) (cong f p) p') (h' : PathP (λ i → pb i ≡ pc i) (cong f q) q') (h'' : PathP (λ i → pb i ≡ pc i) (cong f r) r') (sqr : PathP (λ i → p i ≡ q i) p r) (sqr' : PathP (λ i → p' i ≡ q' i) p' r') → Type _ coh-helper-cong-Type pa pb pc q r h h' h'' sqr sqr' = SquareP (λ i j → f (coh-helper _ _ _ sqr i j) ≡ coh-helper _ _ _ (λ i j → sqr' i j) i j) (λ i j → pc j) (λ i j → doubleCompPath-cong-filler f (sym q) refl r (λ i j → h' i (~ j)) (λ i j → pb i) h'' j i i1) (λ i j → pc j) (λ i j → pc j) coh-helper-cong-refl : coh-helper-cong-Type refl refl refl refl refl refl refl refl refl refl coh-helper-cong-refl = transport (λ t → SquareP (λ i j → f (coh-helper-Refl t _ (λ i j → a) i j) ≡ coh-helper-Refl t _ (λ i j → f a) i j) (λ i j → f a) (λ i j → doubleCompPath-cong-filler f refl refl refl (λ i j → f a) (λ i j → f a) (λ i j → f a) j i i1) (λ i j → f a) (λ i j → f a)) (λ i j k → someCommonDegenerateCube a f i j k) coh-helper-cong' : (b : A)(p : a ≡ b) (c : A)(q : b ≡ c) (a' : B)(pa : f a ≡ a') (b' : B)(pb : f b ≡ b') (c' : B)(pc : f c ≡ c') (r : b ≡ c)(sqr : PathP (λ i → p i ≡ q i) p r) (p' : a' ≡ b')(h : PathP (λ i → pa i ≡ pb i) (cong f p) p') (q' : b' ≡ c')(h' : PathP (λ i → pb i ≡ pc i) (cong f q) q') (r' : b' ≡ c')(h'' : PathP (λ i → pb i ≡ pc i) (cong f r) r') (sqr' : PathP (λ i → p' i ≡ q' i) p' r') (hsqr : SquareP (λ i j → h i j ≡ h' i j) (λ i j → f (sqr i j)) sqr' h h'') → coh-helper-cong-Type pa pb pc q r h h' h'' sqr sqr' coh-helper-cong' = J> J> J> J> J> J> J> J> J> J> coh-helper-cong-refl coh-helper-cong : ∀ {b c a' b' c' pa pb pc} p q r {p' q' r' h h' h''} sqr {sqr'} (hsqr : SquareP (λ i j → f (sqr i j) ≡ sqr' i j) (λ i j → h j i) (λ i j → h'' j i) (λ i j → h j i) (λ i j → h' j i)) → coh-helper-cong-Type {b = b} {c = c} {a' = a'} {b' = b'} {c' = c'} pa pb pc q r {p' = p'} {q' = q'} {r' = r'} h h' h'' sqr sqr' coh-helper-cong p q r sqr hsqr = coh-helper-cong' _ p _ q _ _ _ _ _ _ r sqr _ _ _ _ _ _ _ (λ i j k → hsqr j k i)
31.564155
108
0.481352
c791c811edc3e703e7adcc7300320334434ebe23
58
agda
Agda
n2o/Network/Http.agda
o4/n2o
d7903dfffcd66ae174eed9347afe008f892b2491
[ "BSD-3-Clause" ]
3
2018-11-30T11:37:10.000Z
2019-01-02T06:37:47.000Z
n2o/Network/Http.agda
o4/n2o
d7903dfffcd66ae174eed9347afe008f892b2491
[ "BSD-3-Clause" ]
null
null
null
n2o/Network/Http.agda
o4/n2o
d7903dfffcd66ae174eed9347afe008f892b2491
[ "BSD-3-Clause" ]
null
null
null
{-# OPTIONS --cubical #-} module n2o.Network.Http where
14.5
30
0.672414
13c84a010a089bdbd5e91fc7a91710f439c49112
444
agda
Agda
test/Succeed/ImplicitRecordFields.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/ImplicitRecordFields.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/ImplicitRecordFields.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module ImplicitRecordFields where record R (X Y : Set) : Set₁ where field {A} : Set f : A → A {B C} D {E} : Set g : B → C → E → X → Y postulate A : Set r : R A A r = record { f = f ; B = A ; D = A ; g = λ (_ _ _ : _) → f } where f : A → A f x = x data _≡_ {A : Set₁} (x : A) : A → Set where refl : x ≡ x lemma₁ : r ≡ record {} lemma₁ = refl lemma₂ : R.B r ≡ A lemma₂ = refl
14.322581
43
0.441441
c713b5f13b23e7c4b28948231beff762a2d2524f
444
agda
Agda
test/Common/Prelude.agda
favonia/agda
8d433b967567c08afe15d04a5cb63b6f6d8884ee
[ "BSD-2-Clause" ]
null
null
null
test/Common/Prelude.agda
favonia/agda
8d433b967567c08afe15d04a5cb63b6f6d8884ee
[ "BSD-2-Clause" ]
6
2021-10-18T08:12:24.000Z
2021-11-24T08:31:10.000Z
test/Common/Prelude.agda
antoinevanmuylder/agda
bd59d5b07ffe02a43b28d186d95e1747aac5bc8c
[ "BSD-2-Clause" ]
null
null
null
{-# OPTIONS --cubical-compatible #-} module Common.Prelude where import Common.Level open import Agda.Builtin.Unit public open import Common.Bool public open import Common.Char public open import Common.Float public open import Common.IO public open import Common.List public open import Common.Maybe public open import Common.Nat public open import Common.String public open import Common.Unit public data ⊥ : Set where
23.368421
36
0.772523
adb0e29f937233230ff084f035e0edc607cd0007
2,715
agda
Agda
BasicIPC/Metatheory/Hilbert-KripkeConcreteGluedImplicit.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
29
2016-07-03T18:51:56.000Z
2022-01-01T10:29:18.000Z
BasicIPC/Metatheory/Hilbert-KripkeConcreteGluedImplicit.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
1
2018-06-10T09:11:22.000Z
2018-06-10T09:11:22.000Z
BasicIPC/Metatheory/Hilbert-KripkeConcreteGluedImplicit.agda
mietek/hilbert-gentzen
fcd187db70f0a39b894fe44fad0107f61849405c
[ "X11" ]
null
null
null
module BasicIPC.Metatheory.Hilbert-KripkeConcreteGluedImplicit where open import BasicIPC.Syntax.Hilbert public open import BasicIPC.Semantics.KripkeConcreteGluedImplicit public open ImplicitSyntax (_⊢_) (mono⊢) public -- Completeness with respect to a particular model. module _ {{_ : Model}} where reify : ∀ {A w} → w ⊩ A → unwrap w ⊢ A reify {α P} s = syn s reify {A ▻ B} s = syn s reify {A ∧ B} s = pair (reify (π₁ s)) (reify (π₂ s)) reify {⊤} s = unit reify⋆ : ∀ {Ξ w} → w ⊩⋆ Ξ → unwrap w ⊢⋆ Ξ reify⋆ {∅} ∙ = ∙ reify⋆ {Ξ , A} (ts , t) = reify⋆ ts , reify t -- Additional useful equipment. module _ {{_ : Model}} where ⟪K⟫ : ∀ {A B w} → w ⊩ A → w ⊩ B ▻ A ⟪K⟫ {A} a = app ck (reify a) ⅋ λ ξ → K (mono⊩ {A} ξ a) ⟪S⟫′ : ∀ {A B C w} → w ⊩ A ▻ B ▻ C → w ⊩ (A ▻ B) ▻ A ▻ C ⟪S⟫′ {A} {B} {C} s₁ = app cs (syn s₁) ⅋ λ ξ s₂ → app (app cs (mono⊢ (unwrap≤ ξ) (syn s₁))) (syn s₂) ⅋ λ ξ′ → ⟪S⟫ (mono⊩ {A ▻ B ▻ C} (trans≤ ξ ξ′) s₁) (mono⊩ {A ▻ B} ξ′ s₂) _⟪,⟫′_ : ∀ {A B w} → w ⊩ A → w ⊩ B ▻ A ∧ B _⟪,⟫′_ {A} a = app cpair (reify a) ⅋ λ ξ → _,_ (mono⊩ {A} ξ a) -- Soundness with respect to all models, or evaluation. eval : ∀ {A Γ} → Γ ⊢ A → Γ ⊨ A eval (var i) γ = lookup i γ eval (app t u) γ = eval t γ ⟪$⟫ eval u γ eval ci γ = ci ⅋ K I eval ck γ = ck ⅋ K ⟪K⟫ eval cs γ = cs ⅋ K ⟪S⟫′ eval cpair γ = cpair ⅋ K _⟪,⟫′_ eval cfst γ = cfst ⅋ K π₁ eval csnd γ = csnd ⅋ K π₂ eval unit γ = ∙ -- TODO: Correctness of evaluation with respect to conversion. -- The canonical model. private instance canon : Model canon = record { _⊩ᵅ_ = λ w P → unwrap w ⊢ α P ; mono⊩ᵅ = λ ξ t → mono⊢ (unwrap≤ ξ) t } -- Soundness with respect to the canonical model. reflectᶜ : ∀ {A w} → unwrap w ⊢ A → w ⊩ A reflectᶜ {α P} t = t ⅋ t reflectᶜ {A ▻ B} t = t ⅋ λ ξ a → reflectᶜ (app (mono⊢ (unwrap≤ ξ) t) (reify a)) reflectᶜ {A ∧ B} t = reflectᶜ (fst t) , reflectᶜ (snd t) reflectᶜ {⊤} t = ∙ reflectᶜ⋆ : ∀ {Ξ w} → unwrap w ⊢⋆ Ξ → w ⊩⋆ Ξ reflectᶜ⋆ {∅} ∙ = ∙ reflectᶜ⋆ {Ξ , A} (ts , t) = reflectᶜ⋆ ts , reflectᶜ t -- Reflexivity and transitivity. refl⊩⋆ : ∀ {w} → w ⊩⋆ unwrap w refl⊩⋆ = reflectᶜ⋆ refl⊢⋆ trans⊩⋆ : ∀ {w w′ w″} → w ⊩⋆ unwrap w′ → w′ ⊩⋆ unwrap w″ → w ⊩⋆ unwrap w″ trans⊩⋆ ts us = reflectᶜ⋆ (trans⊢⋆ (reify⋆ ts) (reify⋆ us)) -- Completeness with respect to all models, or quotation. quot : ∀ {A Γ} → Γ ⊨ A → Γ ⊢ A quot s = reify (s refl⊩⋆) -- Normalisation by evaluation. norm : ∀ {A Γ} → Γ ⊢ A → Γ ⊢ A norm = quot ∘ eval -- TODO: Correctness of normalisation with respect to conversion.
26.359223
90
0.521179
4b66e6a146f0b3e77526345221a2f243f0175425
518
agda
Agda
PInj.agda
kztk-m/sparcl-agda
e2fb3a669e733a9020a51b24244d89abd8fcf725
[ "BSD-3-Clause" ]
null
null
null
PInj.agda
kztk-m/sparcl-agda
e2fb3a669e733a9020a51b24244d89abd8fcf725
[ "BSD-3-Clause" ]
null
null
null
PInj.agda
kztk-m/sparcl-agda
e2fb3a669e733a9020a51b24244d89abd8fcf725
[ "BSD-3-Clause" ]
null
null
null
{-# OPTIONS --without-K #-} module PInj where open import Codata.Delay renaming (length to dlength ; map to dmap ) open import Codata.Thunk open import Relation.Binary.PropositionalEquality open import Size open import Level open import Data.Product -- A pair of partial functions that are supposed to form a partial bijection. record _⊢_⇔_ (i : Size) {ℓ : Level} (A : Set ℓ) (B : Set ℓ) : Set ℓ where constructor pre-pinj-i field forward : A -> Delay B i backward : B -> Delay A i open _⊢_⇔_
22.521739
78
0.696911
126b9c9a536d60ab8844d1dfb8cd7903066773a6
504
agda
Agda
test/interaction/noinfixdecl.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/noinfixdecl.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/noinfixdecl.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS -Wall #-} module noinfixdecl where -- warning acts on data constructors data #2 : Set where one : #2 two : #2 neg_ : #2 → #2 -- warning acts on definitions infixl 3 _⊓_ _⊔_ : #2 → #2 → #2 _⊓_ : #2 → #2 → #2 one ⊔ n = n two ⊔ n = two (neg v) ⊔ n = neg (v ⊓ neg n) one ⊓ n = one two ⊓ n = n (neg m) ⊓ n = neg (m ⊔ (neg n)) -- warning acts on postulates postulate _≤_ : #2 → #2 → Set -- warning does not act on 'closed' mixfix definitions postulate [_] : #2 → Set
17.37931
54
0.549603
57efb6555cc2cec6de5e4d49fce311544db81414
15,824
agda
Agda
examples/TT.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
examples/TT.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
examples/TT.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --allow-unsolved-metas --no-termination-check #-} module TT where module Prelude where -- Props ------------------------------------------------------------------ data True : Set where tt : True data False : Set where postulate falseE : (A : Set) -> False -> A infix 3 _/\_ data _/\_ (P Q : Set) : Set where andI : P -> Q -> P /\ Q -- Zero and One ----------------------------------------------------------- data Zero : Set where data One : Set where unit : One -- Natural numbers -------------------------------------------------------- data Nat : Set where zero : Nat suc : Nat -> Nat _+_ : Nat -> Nat -> Nat zero + m = m suc n + m = suc (n + m) module NatEq where infix 5 _==_ _==_ : Nat -> Nat -> Set zero == zero = True suc n == suc m = n == m _ == _ = False rewriteEq : (C : Nat -> Set){m n : Nat} -> m == n -> C n -> C m rewriteEq C {zero} {zero} _ x = x rewriteEq C {suc _} {suc _} eq x = rewriteEq (\z -> C (suc z)) eq x rewriteEq C {zero} {suc _} () _ rewriteEq C {suc _} {zero} () _ module Chain {A : Set}(_==_ : A -> A -> Set) (_trans_ : {x y z : A} -> x == y -> y == z -> x == z) where infixl 4 _=-=_ infixl 4 _===_ infixr 8 _since_ _=-=_ : (x : A){y : A} -> x == y -> x == y x =-= xy = xy _===_ : {x y z : A} -> x == y -> y == z -> x == z xy === yz = xy trans yz _since_ : {x : A}(y : A) -> x == y -> x == y y since xy = xy module Fin where open Prelude -- Finite sets ------------------------------------------------------------ data Suc (A : Set) : Set where fzero' : Suc A fsuc' : A -> Suc A mutual data Fin (n : Nat) : Set where finI : Fin' n -> Fin n Fin' : Nat -> Set Fin' zero = Zero Fin' (suc n) = Suc (Fin n) fzero : {n : Nat} -> Fin (suc n) fzero = finI fzero' fsuc : {n : Nat} -> Fin n -> Fin (suc n) fsuc i = finI (fsuc' i) finE : {n : Nat} -> Fin n -> Fin' n finE (finI i) = i module FinEq where infix 5 _==_ _==_ : {n : Nat} -> Fin n -> Fin n -> Set _==_ {suc _} (finI fzero' ) (finI fzero' ) = True _==_ {suc _} (finI (fsuc' i)) (finI (fsuc' j)) = i == j _==_ _ _ = False rewriteEq : {n : Nat}(C : Fin n -> Set){i j : Fin n} -> i == j -> C j -> C i rewriteEq {suc _} C {finI fzero' } {finI fzero' } eq x = x rewriteEq {suc _} C {finI (fsuc' i)} {finI (fsuc' j)} eq x = rewriteEq (\z -> C (fsuc z)) eq x rewriteEq {suc _} C {finI (fsuc' _)} {finI fzero' } () _ rewriteEq {suc _} C {finI fzero' } {finI (fsuc' _)} () _ rewriteEq {zero} C {finI ()} {_} _ _ module Vec where open Prelude open Fin infixr 15 _::_ -- Vectors ---------------------------------------------------------------- data Nil : Set where nil' : Nil data Cons (A As : Set) : Set where cons' : A -> As -> Cons A As mutual data Vec (A : Set)(n : Nat) : Set where vecI : Vec' A n -> Vec A n Vec' : Set -> Nat -> Set Vec' A zero = Nil Vec' A (suc n) = Cons A (Vec A n) nil : {A : Set} -> Vec A zero nil = vecI nil' _::_ : {A : Set}{n : Nat} -> A -> Vec A n -> Vec A (suc n) x :: xs = vecI (cons' x xs) vecE : {A : Set}{n : Nat} -> Vec A n -> Vec' A n vecE (vecI xs) = xs vec : {A : Set}(n : Nat) -> A -> Vec A n vec zero _ = nil vec (suc n) x = x :: vec n x map : {n : Nat}{A B : Set} -> (A -> B) -> Vec A n -> Vec B n map {zero} f (vecI nil') = nil map {suc n} f (vecI (cons' x xs)) = f x :: map f xs _!_ : {n : Nat}{A : Set} -> Vec A n -> Fin n -> A _!_ {zero } _ (finI ()) _!_ {suc n} (vecI (cons' x _ )) (finI fzero') = x _!_ {suc n} (vecI (cons' _ xs)) (finI (fsuc' i)) = xs ! i tabulate : {n : Nat}{A : Set} -> (Fin n -> A) -> Vec A n tabulate {zero} f = nil tabulate {suc n} f = f fzero :: tabulate (\x -> f (fsuc x)) module Untyped where open Prelude open Fin open Vec Name = Nat data Expr (n : Nat) : Set where eVar : Fin n -> Expr n eApp : Expr n -> Expr n -> Expr n eLam : Expr (suc n) -> Expr n eSet : Expr n eEl : Expr n ePi : Expr n eCon : Name -> Expr n module ExprEq where infix 5 _==_ _==_ : {n : Nat} -> Expr n -> Expr n -> Set eVar i == eVar j = FinEq._==_ i j eApp e1 e2 == eApp e3 e4 = e1 == e3 /\ e2 == e4 eLam e1 == eLam e2 = e1 == e2 eSet == eSet = True eEl == eEl = True ePi == ePi = True eCon f == eCon g = NatEq._==_ f g _ == _ = False rewriteEq : {n : Nat}(C : Expr n -> Set){r s : Expr n} -> r == s -> C s -> C r rewriteEq C {eVar i } {eVar j } eq x = FinEq.rewriteEq (\z -> C (eVar z)) eq x rewriteEq C {eLam e1 } {eLam e2 } eq x = rewriteEq (\z -> C (eLam z)) eq x rewriteEq C {eSet } {eSet } eq x = x rewriteEq C {eEl } {eEl } eq x = x rewriteEq C {ePi } {ePi } eq x = x rewriteEq C {eCon f } {eCon g } eq x = NatEq.rewriteEq (\z -> C (eCon z)) eq x rewriteEq C {eApp e1 e2} {eApp e3 e4} (andI eq13 eq24) x = rewriteEq (\z -> C (eApp z e2)) eq13 ( rewriteEq (\z -> C (eApp e3 z)) eq24 x ) rewriteEq C {eVar _} {eLam _ } () _ rewriteEq C {eVar _} {eSet } () _ rewriteEq C {eVar _} {eEl } () _ rewriteEq C {eVar _} {eCon _ } () _ rewriteEq C {eVar _} {ePi } () _ rewriteEq C {eVar _} {eApp _ _} () _ rewriteEq C {eLam _} {eVar _ } () _ rewriteEq C {eLam _} {eSet } () _ rewriteEq C {eLam _} {eEl } () _ rewriteEq C {eLam _} {eCon _ } () _ rewriteEq C {eLam _} {ePi } () _ rewriteEq C {eLam _} {eApp _ _} () _ rewriteEq C {eSet } {eLam _ } () _ rewriteEq C {eSet } {eVar _ } () _ rewriteEq C {eSet } {eEl } () _ rewriteEq C {eSet } {eCon _ } () _ rewriteEq C {eSet } {ePi } () _ rewriteEq C {eSet } {eApp _ _} () _ rewriteEq C {eEl } {eLam _ } () _ rewriteEq C {eEl } {eSet } () _ rewriteEq C {eEl } {eVar _ } () _ rewriteEq C {eEl } {eCon _ } () _ rewriteEq C {eEl } {ePi } () _ rewriteEq C {eEl } {eApp _ _} () _ rewriteEq C {eCon _} {eLam _ } () _ rewriteEq C {eCon _} {eSet } () _ rewriteEq C {eCon _} {eEl } () _ rewriteEq C {eCon _} {eVar _ } () _ rewriteEq C {eCon _} {ePi } () _ rewriteEq C {eCon _} {eApp _ _} () _ rewriteEq C {ePi } {eLam _ } () _ rewriteEq C {ePi } {eSet } () _ rewriteEq C {ePi } {eEl } () _ rewriteEq C {ePi } {eCon _ } () _ rewriteEq C {ePi } {eVar _ } () _ rewriteEq C {ePi } {eApp _ _} () _ rewriteEq C {eApp _ _} {eLam _ } () _ rewriteEq C {eApp _ _} {eSet } () _ rewriteEq C {eApp _ _} {eEl } () _ rewriteEq C {eApp _ _} {eCon _ } () _ rewriteEq C {eApp _ _} {ePi } () _ rewriteEq C {eApp _ _} {eVar _ } () _ module Typed where open Prelude open Fin open Vec infixl 15 _&_ infix 13 _!!_ infix 5 _==_ -- Contexts --------------------------------------------------------------- data CSuc (n : Nat) : Set Context' : Nat -> Set Context' zero = Nil Context' (suc n) = CSuc n data Context (n : Nat) : Set data Type {n : Nat}(Γ : Context n) : Set data CSuc n where ext : (Γ : Context n) -> Type Γ -> Context' (suc n) data Context n where ctxI : Context' n -> Context n -- Types ------------------------------------------------------------------ _&_ : {n : Nat}(Γ : Context n) -> Type Γ -> Context (suc n) data Term {n : Nat}(Γ : Context n)(A : Type Γ) : Set data Type {n} Γ where SET : Type Γ Pi : (A : Type Γ) -> Type (Γ & A) -> Type Γ El : Term Γ SET -> Type Γ Γ & A = ctxI (ext Γ A) -- Variables -------------------------------------------------------------- data VarSuc {n : Nat}(Γ : Context n)(B : Type Γ)(A : Type (Γ & B)) : Set Var' : {n : Nat}(Γ : Context n) -> Type Γ -> Set Var' {zero} Γ A = Zero Var' {suc n} (ctxI (ext Γ B)) A = VarSuc Γ B A _==_ : {n : Nat}{Γ : Context n} -> Type Γ -> Type Γ -> Set data Ren {n m : Nat}(Γ : Context n)(Δ : Context m) : Set rename : {n m : Nat}{Γ : Context n}{Δ : Context m} -> Ren Γ Δ -> Type Γ -> Type Δ upR : {n : Nat}{Γ : Context n}{A : Type Γ} -> Ren Γ (Γ & A) data Var {n : Nat}(Γ : Context n)(A : Type Γ) : Set data VarSuc {n} Γ B A where vzero_ : A == rename upR B -> Var' (Γ & B) A vsuc_ : (C : Type Γ) -> A == rename upR C -> Var Γ C -> Var' (Γ & B) A data Var {n} Γ A where varI : Var' Γ A -> Var Γ A -- Terms ------------------------------------------------------------------ data Sub {n m : Nat}(Γ : Context n)(Δ : Context m) : Set subst : {n m : Nat}{Γ : Context n}{Δ : Context m} -> Sub Γ Δ -> Type Γ -> Type Δ down : {n : Nat}{Γ : Context n}{A : Type Γ} -> Term Γ A -> Sub (Γ & A) Γ data Term {n} Γ A where var : (x : Var Γ A) -> Term Γ A app : {B : Type Γ}{C : Type (Γ & B)} -> Term Γ (Pi B C) -> (t : Term Γ B) -> A == subst (down t) C -> Term Γ A lam : {B : Type Γ}{C : Type (Γ & B)} -> Term (Γ & B) C -> A == Pi B C -> Term Γ A -- Context manipulation --------------------------------------------------- ∅ : Context zero ∅ = ctxI nil' _!!_ : {n : Nat}(Γ : Context n) -> Fin n -> Type Γ _!!_ {zero} _ (finI ()) _!!_ {suc _} (ctxI (ext Γ A)) (finI fzero') = rename upR A _!!_ {suc _} (ctxI (ext Γ A)) (finI (fsuc' i)) = rename upR (Γ !! i) -- Renamings -------------------------------------------------------------- data ConsRen {n m : Nat}(Γ : Context n)(A : Type Γ)(Δ : Context m) : Set Ren' : {n m : Nat} -> Context n -> Context m -> Set Ren' {zero} {m} (ctxI nil') Δ = Nil Ren' {suc n} {m} (ctxI (ext Γ A)) Δ = ConsRen Γ A Δ data ConsRen {n m} Γ A Δ where extRen' : (ρ : Ren Γ Δ) -> Var Δ (rename ρ A) -> Ren' (Γ & A) Δ data Ren {n m} Γ Δ where renI : Ren' Γ Δ -> Ren Γ Δ -- Performing renamings --------------------------------------------------- rename' : {n m : Nat}{Γ : Context n}{Δ : Context m} -> Ren Γ Δ -> Type Γ -> Type Δ rename ρ SET = SET rename ρ A = rename' ρ A liftR : {n m : Nat}{Γ : Context n}{A : Type Γ}{Δ : Context m} -> (ρ : Ren Γ Δ) -> Ren (Γ & A) (Δ & rename ρ A) renameTerm : {n m : Nat}{Γ : Context n}{Δ : Context m}{A : Type Γ} (ρ : Ren Γ Δ) -> Term Γ A -> Term Δ (rename ρ A) rename' ρ SET = SET rename' ρ (Pi A B) = Pi (rename ρ A) (rename (liftR ρ) B) rename' ρ (El t) = El (renameTerm ρ t) lookupR : {n m : Nat}{Γ : Context n}{A : Type Γ}{Δ : Context m} (ρ : Ren Γ Δ)(x : Var Γ A) -> Var Δ (rename ρ A) cong : {n m : Nat}{Γ : Context n}{Δ : Context m}(f : Type Γ -> Type Δ) {A B : Type Γ} -> A == B -> f A == f B _trans_ : {n : Nat}{Γ : Context n}{A B C : Type Γ} -> A == B -> B == C -> A == C renameSubstCommute : {n m : Nat}{Γ : Context n}{Δ : Context m}{A : Type Γ}{B : Type (Γ & A)} {ρ : Ren Γ Δ}{t : Term Γ A} -> rename ρ (subst (down t) B) == subst (down (renameTerm ρ t)) (rename (liftR ρ) B) renameTerm ρ (var x) = var (lookupR ρ x) renameTerm {_}{_}{_}{_}{A} ρ (app{_}{C} s t eq) = app (renameTerm ρ s) (renameTerm ρ t) (cong (rename ρ) eq trans renameSubstCommute) renameTerm ρ (lam t eq) = lam (renameTerm (liftR ρ) t) (cong (rename ρ) eq) lookupR {zero} _ (varI ()) lookupR {suc n} {_} {ctxI (ext Γ B)} {A} {Δ} (renI (extRen' ρ z)) (varI (vzero_ eq)) = {!!} lookupR {suc n} {_} {ctxI (ext Γ B)} {A} {Δ} (renI (extRen' ρ z)) (varI (vsuc_ C eq x)) = {!!} -- Building renamings ----------------------------------------------------- extRen : {n m : Nat}{Γ : Context n}{A : Type Γ}{Δ : Context m} (ρ : Ren Γ Δ) -> Var Δ (rename ρ A) -> Ren (Γ & A) Δ extRen ρ x = renI (extRen' ρ x) _coR_ : {n m p : Nat}{Γ : Context n}{Δ : Context m}{Θ : Context p} -> Ren Δ Θ -> Ren Γ Δ -> Ren Γ Θ liftR {_}{_}{_}{A} ρ = extRen (upR coR ρ) (varI {!!}) idR : {n : Nat} {Γ : Context n} -> Ren Γ Γ idR = {!!} _coR_ = {!!} upR = {!!} -- Substitutions ---------------------------------------------------------- data ConsSub {n m : Nat}(Γ : Context n)(A : Type Γ)(Δ : Context m) : Set Sub' : {n m : Nat} -> Context n -> Context m -> Set Sub' {zero} {m} (ctxI nil') Δ = Nil Sub' {suc n} {m} (ctxI (ext Γ A)) Δ = ConsSub Γ A Δ data ConsSub {n m} Γ A Δ where extSub' : (σ : Sub Γ Δ) -> Term Δ (subst σ A) -> Sub' (Γ & A) Δ data Sub {n m} Γ Δ where subI : Sub' Γ Δ -> Sub Γ Δ -- Performing substitution ------------------------------------------------ subst' : {n m : Nat}{Γ : Context n}{Δ : Context m} -> Sub Γ Δ -> Type Γ -> Type Δ subst σ SET = SET subst σ A = subst' σ A liftS : {n m : Nat}{Γ : Context n}{A : Type Γ}{Δ : Context m} -> (σ : Sub Γ Δ) -> Sub (Γ & A) (Δ & subst σ A) substTerm : {n m : Nat}{Γ : Context n}{Δ : Context m}{A : Type Γ} -> (σ : Sub Γ Δ) -> Term Γ A -> Term Δ (subst σ A) subst' σ (Pi A B) = Pi (subst σ A) (subst (liftS σ) B) subst' σ (El t) = El (substTerm σ t) subst' σ SET = SET substTerm σ (var x) = {!!} substTerm σ (app s t eq) = {!!} substTerm σ (lam t eq) = {!!} -- Building substitutions ------------------------------------------------- liftS {_}{_}{_}{A} σ = {!!} -- extSub (upS ∘ σ) (var fzero (substCompose upS σ A)) -- Works with hidden args to substCompose when inlined in subst -- but not here. Weird. topS : {n : Nat}{Γ : Context n} -> Sub ∅ Γ topS = subI nil' extSub : {n m : Nat}{Γ : Context n}{A : Type Γ}{Δ : Context m} (σ : Sub Γ Δ) -> Term Δ (subst σ A) -> Sub (Γ & A) Δ extSub σ t = subI (extSub' σ t) idS : {n : Nat}{Γ : Context n} -> Sub Γ Γ idS {zero} {ctxI nil'} = topS idS {suc _} {ctxI (ext Γ A)} = {!!} -- extSub upS (var fzero refl) convert : {n : Nat}{Γ : Context n}{A B : Type Γ} -> A == B -> Term Γ B -> Term Γ A _∘_ : {n m p : Nat}{Γ : Context n}{Δ : Context m}{Θ : Context p} -> Sub Δ Θ -> Sub Γ Δ -> Sub Γ Θ substCompose : {n m p : Nat}{Γ : Context n}{Δ : Context m}{Θ : Context p} (σ : Sub Δ Θ)(δ : Sub Γ Δ)(A : Type Γ) -> subst (σ ∘ δ) A == subst σ (subst δ A) _∘_ {zero} {_}{_} {ctxI nil'} _ _ = topS _∘_ {suc _}{_}{_} {ctxI (ext Γ A)} σ (subI (extSub' δ t)) = extSub (σ ∘ δ) (convert (substCompose σ δ A) (substTerm σ t)) upS : {n : Nat}{Γ : Context n}{A : Type Γ} -> Sub Γ (Γ & A) upS = {!!} substId : {n : Nat}{Γ : Context n}{A : Type Γ} -> subst idS A == A down t = extSub idS (convert substId t) -- Convertibility --------------------------------------------------------- A == B = {!!} refl : {n : Nat}{Γ : Context n}{A : Type Γ} -> A == A refl = {!!} cong f eq = {!!} ab trans bc = {!!} convert eq t = {!!} -- Properties ------------------------------------------------------------- renameId : {n : Nat}{Γ : Context n}{A : Type Γ} -> rename idR A == A renameId = {!!} renameCompose : {n m p : Nat}{Γ : Context n}{Δ : Context m}{Θ : Context p} (σ : Ren Δ Θ)(δ : Ren Γ Δ)(A : Type Γ) -> rename (σ coR δ) A == rename σ (rename δ A) renameCompose σ δ A = {!!} substId = {!!} substCompose σ δ A = {!!} renameSubstCommute = {!!}
31.648
101
0.446411
1a3a529da175482e23887e8a99faaacc992689e8
7,425
agda
Agda
theorems/homotopy/GroupSetsRepresentCovers.agda
timjb/HoTT-Agda
66f800adef943afdf08c17b8ecfba67340fead5e
[ "MIT" ]
null
null
null
theorems/homotopy/GroupSetsRepresentCovers.agda
timjb/HoTT-Agda
66f800adef943afdf08c17b8ecfba67340fead5e
[ "MIT" ]
null
null
null
theorems/homotopy/GroupSetsRepresentCovers.agda
timjb/HoTT-Agda
66f800adef943afdf08c17b8ecfba67340fead5e
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --rewriting #-} open import HoTT import homotopy.ConstantToSetExtendsToProp as ConstExt open import homotopy.RibbonCover module homotopy.GroupSetsRepresentCovers {i} (X : Ptd i) {{_ : is-connected 0 (de⊙ X)}} where open Cover private A : Type i A = de⊙ X a₁ : A a₁ = pt X -- A covering space constructed from a G-set. grpset-to-cover : ∀ {j} → GroupSet (πS 0 X) j → Cover A (lmax i j) grpset-to-cover gs = Ribbon-cover X gs -- Covering spaces to G-sets. cover-to-grpset-struct : ∀ {j} (cov : Cover A j) → GroupSetStructure (πS 0 X) (Fiber cov a₁) cover-to-grpset-struct cov = record { act = cover-trace cov ; unit-r = cover-trace-idp₀ cov ; assoc = cover-paste cov } cover-to-grpset : ∀ {j} → Cover A j → GroupSet (πS 0 X) j cover-to-grpset cov = record { El = Fiber cov a₁ ; grpset-struct = cover-to-grpset-struct cov } -- This is derivable from connectedness condition. module _ where abstract [base-path] : ∀ {a₂ : A} → Trunc -1 (a₁ == a₂) [base-path] {a₂} = –> (Trunc=-equiv [ a₁ ] [ a₂ ]) (contr-has-all-paths [ a₁ ] [ a₂ ]) -- Part 1: Show that the synthesized cover (ribbon) is fiberwisely -- equivalent to the original fiber. private module _ {j} (cov : Cover A j) where -- Suppose that we get the path, we can compute the ribbon easily. fiber+path-to-ribbon : ∀ {a₂} (a↑ : Fiber cov a₂) (p : a₁ == a₂) → Ribbon X (cover-to-grpset cov) a₂ fiber+path-to-ribbon {a₂} a↑ p = trace (cover-trace cov a↑ [ ! p ]) [ p ] abstract -- Our construction is "constant" with respect to paths. fiber+path-to-ribbon-is-path-irrelevant : ∀ {a₂} (a↑ : Fiber cov a₂) (p₁ p₂ : a₁ == a₂) → fiber+path-to-ribbon a↑ p₁ == fiber+path-to-ribbon a↑ p₂ fiber+path-to-ribbon-is-path-irrelevant a↑ p idp = trace (cover-trace cov a↑ [ ! p ]) [ p ] =⟨ paste a↑ [ ! p ] [ p ] ⟩ trace a↑ [ ! p ∙ p ] =⟨ !₀-inv-l [ p ] |in-ctx trace a↑ ⟩ trace a↑ idp₀ ∎ module FiberAndPathToRibbon {a₂} (a↑ : Fiber cov a₂) = ConstExt (fiber+path-to-ribbon a↑) (fiber+path-to-ribbon-is-path-irrelevant a↑) fiber+path₋₁-to-ribbon : ∀ {a₂} (a↑ : Cover.Fiber cov a₂) → Trunc -1 (a₁ == a₂) → Ribbon X (cover-to-grpset cov) a₂ fiber+path₋₁-to-ribbon a↑ = FiberAndPathToRibbon.ext a↑ -- So the conversion from fiber to ribbon is done. fiber-to-ribbon : ∀ {j} (cov : Cover A j) → {a₂ : A} (a↑ : Cover.Fiber cov a₂) → Ribbon X (cover-to-grpset cov) a₂ fiber-to-ribbon cov a↑ = fiber+path₋₁-to-ribbon cov a↑ [base-path] -- The other direction is easy. ribbon-to-fiber : ∀ {j} (cov : Cover A j) {a₂} → Ribbon X (cover-to-grpset cov) a₂ → Cover.Fiber cov a₂ ribbon-to-fiber cov {a₂} r = Ribbon-rec (cover-trace cov) (cover-paste cov) r private -- Some routine computations. abstract ribbon-to-fiber-to-ribbon : ∀ {j} (cov : Cover A j) {a₂} → (r : Ribbon X (cover-to-grpset cov) a₂) → fiber-to-ribbon cov (ribbon-to-fiber cov r) == r ribbon-to-fiber-to-ribbon cov {a₂} = Ribbon-elim {P = λ r → fiber-to-ribbon cov (ribbon-to-fiber cov r) == r} (λ a↑ p → Trunc-elim -- All ugly things will go away when bp = proj bp′ {{λ bp → has-level-apply Ribbon-is-set (fiber+path₋₁-to-ribbon cov (cover-trace cov a↑ p) bp) (trace a↑ p)}} (lemma a↑ p) [base-path]) (λ _ _ _ → prop-has-all-paths-↓) where abstract lemma : ∀ {a₂} (a↑ : Cover.Fiber cov a₁) (p : a₁ =₀ a₂) (bp : a₁ == a₂) → trace {X = X} {gs = cover-to-grpset cov} (cover-trace cov (cover-trace cov a↑ p) [ ! bp ]) [ bp ] == trace {X = X} {gs = cover-to-grpset cov} a↑ p lemma a↑ p idp = trace (cover-trace cov a↑ p) idp₀ =⟨ paste a↑ p idp₀ ⟩ trace a↑ (p ∙₀ idp₀) =⟨ ap (trace a↑) $ ∙₀-unit-r p ⟩ trace a↑ p ∎ fiber-to-ribbon-to-fiber : ∀ {j} (cov : Cover A j) {a₂} → (a↑ : Cover.Fiber cov a₂) → ribbon-to-fiber cov (fiber-to-ribbon cov {a₂} a↑) == a↑ fiber-to-ribbon-to-fiber cov {a₂} a↑ = Trunc-elim -- All ugly things will go away when bp = proj bp′ {{λ bp → has-level-apply (Cover.Fiber-is-set cov) (ribbon-to-fiber cov (fiber+path₋₁-to-ribbon cov a↑ bp)) a↑}} (lemma a↑) [base-path] where abstract lemma : ∀ {a₂} (a↑ : Cover.Fiber cov a₂) (bp : a₁ == a₂) → cover-trace cov (cover-trace cov a↑ [ ! bp ]) [ bp ] == a↑ lemma a↑ idp = idp cover-to-grpset-to-cover : ∀ {j} (cov : Cover A (lmax i j)) → grpset-to-cover (cover-to-grpset cov) == cov cover-to-grpset-to-cover cov = cover= λ _ → ribbon-to-fiber cov , is-eq (ribbon-to-fiber cov) (fiber-to-ribbon cov) (fiber-to-ribbon-to-fiber cov) (ribbon-to-fiber-to-ribbon cov) -- The second direction : grpset -> covering -> grpset -- Part 2.1: The fiber over the point a is the carrier. ribbon-a₁-to-El : ∀ {j} {gs : GroupSet (πS 0 X) j} → Ribbon X gs a₁ → GroupSet.El gs ribbon-a₁-to-El {j} {gs} = let open GroupSet gs in Ribbon-rec act assoc ribbon-a₁-to-El-equiv : ∀ {j} {gs : GroupSet (πS 0 X) j} → Ribbon X gs a₁ ≃ GroupSet.El gs ribbon-a₁-to-El-equiv {j} {gs} = let open GroupSet gs in ribbon-a₁-to-El , is-eq _ (λ r → trace r idp₀) (λ a↑ → unit-r a↑) (Ribbon-elim {P = λ r → trace (ribbon-a₁-to-El r) idp₀ == r} (λ y p → trace (act y p) idp₀ =⟨ paste y p idp₀ ⟩ trace y (p ∙₀ idp₀) =⟨ ap (trace y) $ ∙₀-unit-r p ⟩ trace y p ∎) (λ _ _ _ → prop-has-all-paths-↓)) grpset-to-cover-to-grpset : ∀ {j} (gs : GroupSet (πS 0 X) (lmax i j)) → cover-to-grpset (grpset-to-cover gs) == gs grpset-to-cover-to-grpset gs = groupset= ribbon-a₁-to-El-equiv (λ {x₁}{x₂} x= → Trunc-elim λ g → ribbon-a₁-to-El (transport (Ribbon X gs) g x₁) =⟨ ap (λ x → ribbon-a₁-to-El (transport (Ribbon X gs) g x)) $ ! $ <–-inv-l ribbon-a₁-to-El-equiv x₁ ⟩ ribbon-a₁-to-El (transport (Ribbon X gs) g (trace (ribbon-a₁-to-El x₁) idp₀)) =⟨ ap (λ x → ribbon-a₁-to-El (transport (Ribbon X gs) g (trace x idp₀))) x= ⟩ ribbon-a₁-to-El (transport (Ribbon X gs) g (trace x₂ idp₀)) =⟨ ap ribbon-a₁-to-El $ transp-trace g x₂ idp₀ ⟩ GroupSet.act gs x₂ [ g ] ∎) -- Finally... grpset-equiv-cover : ∀ {j} → GroupSet (πS 0 X) (lmax i j) ≃ Cover A (lmax i j) grpset-equiv-cover {j} = grpset-to-cover , is-eq _ (λ c → cover-to-grpset c) (λ c → cover-to-grpset-to-cover {lmax i j} c) (grpset-to-cover-to-grpset {lmax i j}) -- The path-set cover is represented by the fundamental group itself path-set-repr-by-π1 : cover-to-grpset (path-set-cover X) == group-to-group-set (πS 0 X) path-set-repr-by-π1 = groupset= (ide _) (λ {x₁} p g → (transp₀-cst=₀idf g x₁ ∙ ∙₀'=∙₀ x₁ g) ∙' ap (_∙₀ g) p)
36.757426
87
0.539933
39f9df67dad1be8074aa2285f0ed4282901b17df
485
agda
Agda
test/Fail/Issue555b.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue555b.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue555b.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2012-01-13 module Issue555b where data Empty : Set where record Unit : Set where constructor tt -- Do we want to allow this? data Exp (A : Set) : Set1 data Exp where -- ? needs to report that too few parameters are given var : Exp Empty app : {A B : Set} → Exp (A → B) → Exp A → Exp B -- Basically, A is first declared as a parameter, but later, -- in the definition, it is turned into an index. bla : {A : Set} → Exp A → Unit bla var = tt bla (app f a) = bla f
23.095238
69
0.65567
adcdce970d1d8d5e4858534016943a28acbc0bcd
5,864
agda
Agda
misc/Short.agda
yurrriq/parser-combinators
b396d35cc2cb7e8aea50b982429ee385f001aa88
[ "MIT" ]
7
2016-12-13T05:23:14.000Z
2021-06-22T05:35:31.000Z
misc/Short.agda
nad/parser-combinators
76774f54f466cfe943debf2da731074fe0c33644
[ "MIT" ]
1
2018-01-22T22:21:41.000Z
2018-01-24T16:39:37.000Z
misc/Short.agda
nad/parser-combinators
76774f54f466cfe943debf2da731074fe0c33644
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Total parser combinators (very short version) -- Nils Anders Danielsson ------------------------------------------------------------------------ module Short where open import Category.Monad open import Coinduction open import Data.Bool import Data.BoundedVec.Inefficient as BoundedVec open import Data.Char import Data.Colist as Colist open import Data.List as List open import Data.Maybe open import Data.Nat open import Data.Nat.Show open import Data.String using (Costring) open import Function open import IO hiding (return) renaming (_>>=_ to _>>=IO_) open import Relation.Nullary.Decidable open RawMonadPlus List.monadPlus using () renaming (_>>=_ to _>>=′_) infix 7 _⋆ _+ infixl 6 _>>=_ _>>=app_ infixl 5 _∣_ ------------------------------------------------------------------------ -- Helper functions flatten : {A : Set} → Maybe (List A) → List A flatten nothing = [] flatten (just xs) = xs app : {A B : Set} → Maybe (A → List B) → A → List B app nothing x = [] app (just f) x = f x _>>=app_ : {A B : Set} → List A → Maybe (A → List B) → List B xs >>=app nothing = [] xs >>=app just f = xs >>=′ f ------------------------------------------------------------------------ -- Parsers mutual data Parser : (R : Set) → List R → Set₁ where return : ∀ {R} (x : R) → Parser R [ x ] fail : ∀ {R} → Parser R [] token : Parser Char [] _∣_ : ∀ {R xs₁ xs₂} (p₁ : Parser R xs₁ ) (p₂ : Parser R xs₂) → Parser R (xs₁ ++ xs₂) _>>=_ : ∀ {R₁ R₂ xs} {f : Maybe (R₁ → List R₂)} (p₁ : ∞⟨ f ⟩Parser R₁ (flatten xs) ) (p₂ : (x : R₁) → ∞⟨ xs ⟩Parser R₂ (app f x)) → Parser R₂ (flatten xs >>=app f) ∞⟨_⟩Parser : {R₂ : Set} → Maybe R₂ → (R₁ : Set) → List R₁ → Set₁ ∞⟨ nothing ⟩Parser R₁ xs = ∞ (Parser R₁ xs) ∞⟨ just _ ⟩Parser R₁ xs = Parser R₁ xs ------------------------------------------------------------------------ -- Derived combinators sat : ∀ {R} → (Char → Maybe R) → Parser R [] sat {R} p = token >>= (ok ∘ p) where ok-index : Maybe R → List R ok-index nothing = [] ok-index (just x) = [ x ] ok : (x : Maybe R) → Parser R (ok-index x) ok nothing = fail ok (just x) = return x tok : Char → Parser Char [] tok t = sat (λ t′ → if t == t′ then just t′ else nothing) return⋆ : ∀ {R} (xs : List R) → Parser R xs return⋆ [] = fail return⋆ (x ∷ xs) = return x ∣ return⋆ xs mutual _⋆ : ∀ {R} → Parser R [] → Parser (List R) _ p ⋆ = return [] ∣ p + _+ : ∀ {R} → Parser R [] → Parser (List R) _ p + = p >>= λ x → ♯ ( p ⋆ >>= λ xs → return (x ∷ xs) ) digit = sat (λ t → if in-range t then just (to-number t) else nothing) where in-range : Char → Bool in-range t = ⌊ toNat '0' ≤? toNat t ⌋ ∧ ⌊ toNat t ≤? toNat '9' ⌋ to-number : Char → ℕ to-number t = toNat t ∸ toNat '0' number = digit + >>= return ∘ foldl (λ n d → 10 * n + d) 0 ------------------------------------------------------------------------ -- Parser interpreter delayed? : ∀ {R R′ xs} {m : Maybe R′} → ∞⟨ m ⟩Parser R xs → Maybe R′ delayed? {m = m} _ = m delayed?′ : ∀ {R₁ R₂ R′ : Set} {m : Maybe R′} {f : R₁ → List R₂} → ((x : R₁) → ∞⟨ m ⟩Parser R₂ (f x)) → Maybe R′ delayed?′ {m = m} _ = m ∂-initial : ∀ {R xs} → Parser R xs → Char → List R ∂-initial (return x) t = [] ∂-initial fail t = [] ∂-initial token t = [ t ] ∂-initial (p₁ ∣ p₂) t = ∂-initial p₁ t ++ ∂-initial p₂ t ∂-initial (p₁ >>= p₂) t with delayed? p₁ | delayed?′ p₂ ... | just f | nothing = ∂-initial p₁ t >>=′ f ... | just f | just xs = (∂-initial p₁ t >>=′ f) ++ (xs >>=′ λ x → ∂-initial (p₂ x) t) ... | nothing | nothing = [] ... | nothing | just xs = xs >>=′ λ x → ∂-initial (p₂ x) t ∂ : ∀ {R xs} (p : Parser R xs) (t : Char) → Parser R (∂-initial p t) ∂ (return x) t = fail ∂ fail t = fail ∂ token t = return t ∂ (p₁ ∣ p₂) t = ∂ p₁ t ∣ ∂ p₂ t ∂ (p₁ >>= p₂) t with delayed? p₁ | delayed?′ p₂ ... | just f | nothing = ∂ p₁ t >>= (λ x → ♭ (p₂ x)) ... | just f | just xs = ∂ p₁ t >>= (λ x → p₂ x) ∣ return⋆ xs >>= λ x → ∂ (p₂ x) t ... | nothing | nothing = ♯ ∂ (♭ p₁) t >>= (λ x → ♭ (p₂ x)) ... | nothing | just xs = ♯ ∂ (♭ p₁) t >>= (λ x → p₂ x) ∣ return⋆ xs >>= λ x → ∂ (p₂ x) t parse : ∀ {R xs} → Parser R xs → List Char → List R parse {xs = xs} p [] = xs parse p (t ∷ s) = parse (∂ p t) s ------------------------------------------------------------------------ -- Example data Expr : Set where num : (n : ℕ) → Expr plus : (e₁ e₂ : Expr) → Expr times : (e₁ e₂ : Expr) → Expr ⟦_⟧ : Expr → ℕ ⟦ num n ⟧ = n ⟦ plus e₁ e₂ ⟧ = ⟦ e₁ ⟧ + ⟦ e₂ ⟧ ⟦ times e₁ e₂ ⟧ = ⟦ e₁ ⟧ * ⟦ e₂ ⟧ mutual term = factor ∣ ♯ term >>= λ e₁ → tok '+' >>= λ _ → factor >>= λ e₂ → return (plus e₁ e₂) factor = atom ∣ ♯ factor >>= λ e₁ → tok '*' >>= λ _ → atom >>= λ e₂ → return (times e₁ e₂) atom = (number >>= return ∘ num) ∣ tok '(' >>= λ _ → ♯ term >>= λ e → tok ')' >>= λ _ → return e ------------------------------------------------------------------------ -- IO toList : Costring → List Char toList = BoundedVec.toList ∘ Colist.take 100000 main = run $ ♯ getContents >>=IO λ s → ♯ let s′ = takeWhile (not ∘ _==_ '\n') $ toList s es = parse term s′ in mapM′ (putStrLn ∘ show ∘ ⟦_⟧) (Colist.fromList es)
30.701571
73
0.427694
3d595415869ccc7844dd2e89a931aed5f4b70ab1
20,968
agda
Agda
complexity/complexity-final/Samples.agda
benhuds/Agda
2404a6ef2688f879bda89860bb22f77664ad813e
[ "MIT" ]
2
2016-04-26T20:22:22.000Z
2019-08-08T12:27:18.000Z
complexity/complexity-final/Samples.agda
benhuds/Agda
2404a6ef2688f879bda89860bb22f77664ad813e
[ "MIT" ]
1
2020-03-23T08:39:04.000Z
2020-05-12T00:32:45.000Z
complexity/complexity-final/Samples.agda
benhuds/Agda
2404a6ef2688f879bda89860bb22f77664ad813e
[ "MIT" ]
null
null
null
{- SAMPLE PROGRAMS IN SOURCE LANGUAGE -} open import Preliminaries open import Source open import Pilot2 open import Translation open import Interp open import Preorder module Samples where s2r : ∀ {Γ τ} → Γ Source.|- τ → (el ([ (⟨⟨ Γ ⟩⟩c) ]c ->p [ (|| τ ||) ]t)) s2r p = interpE || p ||e -- this works {- dbl (n : nat) : nat = 2 * n -} dbl : ∀ {Γ} → Γ Source.|- (nat ->s nat) dbl = lam (rec (var i0) z (suc (suc (force (var (iS i0)))))) -- this works {- add (m n : nat) : nat = m + n -} add : ∀ {Γ} → Γ Source.|- (nat ->s (nat ->s nat)) add = lam (lam (rec (var (iS i0)) (var i0) (suc (force (var (iS i0)))))) -- this works {- mult (m n : nat) : nat = m * n -} mult : ∀ {Γ} → Γ Source.|- (nat ->s (nat ->s nat)) mult = lam (lam (rec (var (iS i0)) z (app (app add (var (iS (iS i0)))) (force (var (iS i0)))))) -- this works {- pred (n : nat) : nat = predecessor of n -} pred : ∀ {Γ} → Γ Source.|- (nat ->s nat) pred = lam (rec (var i0) z (var i0)) -- uhhhh fastfib : ∀ {Γ} → Γ Source.|- (nat ->s (nat ×s nat)) fastfib = lam (rec (var i0) (prod z (suc z)) (prod (split (force (var (iS i0))) (var (iS i0))) (app (app add (split (force (var (iS i0))) (var i0))) (split (force (var (iS i0))) (var (iS i0)))))) -- hack : instead of having bool case analysis just do natural number recursion and return 1/0 -- this works {- iszero (n : nat) : nat = z -> 1 | _ -> 0 -} isz : ∀ {Γ} → Γ Source.|- (nat ->s nat) isz = lam (rec (var i0) (suc z) z) -- this works {- leq (m n : nat) : nat = m ≤ n -} leq : ∀ {Γ} → Γ Source.|- (nat ->s (nat ->s nat)) leq = lam (rec (var i0) (lam (suc z)) (lam (rec (var i0) z (app (force (var (iS (iS (iS (iS i0)))))) (var i0))))) -- this works {- eq (m n : nat) : nat = m = n -} eq : ∀ {Γ} → Γ Source.|- (nat ->s (nat ->s nat)) eq = lam (rec (var i0) (lam (app isz (var i0))) (lam (rec (var i0) z (app (force (var (iS (iS (iS (iS i0)))))) (var i0))))) -- this works {- len (l : list τ) : nat = [] -> z | x :: xs -> 1 + len xs -} len : ∀ {Γ τ} → Γ Source.|- (list τ ->s nat) len = lam (listrec (var i0) z (suc (force (var (iS (iS i0)))))) -- this works {- nth (n : nat) (l : list τ) : nat = [] -> 1 (return 1+len(l) if element not in list) | x :: xs -> if n = x then 0 else 1 + (nth n xs) -} nth : ∀ {Γ} → Γ Source.|- (list nat ->s (nat ->s nat)) nth = lam (lam (listrec (var (iS i0)) (suc z) (rec (app (app eq (var (iS (iS (iS i0))))) (var i0)) (suc (force (var (iS (iS i0))))) z))) -- this works {- append (l1 l2 : list τ) : list τ = match l1 with [] -> l2 | x :: xs -> x :: (append xs ys) -} append : ∀ {Γ τ} → Γ Source.|- (list τ ->s (list τ ->s list τ)) append = lam (lam (listrec (var (iS i0)) (var i0) (var i0 ::s force (var (iS (iS i0)))))) -- this works {- rev (l : list τ) : list τ = [] -> [] | x :: xs -> append (rev xs) [x] -} rev : ∀ {Γ τ} → Γ Source.|- (list τ ->s list τ) rev = lam (listrec (var i0) nil (app (app append (force (var (iS (iS i0))))) (var i0 ::s nil))) {- {- fast rev -} rev2piles : ∀ {Γ τ} → Γ Source.|- (list τ ->s (list τ ->s list τ)) rev2piles = lam (lam (listrec (var (iS i0)) (var i0) (app (app rev2piles (var (iS i0))) (var i0 ::s var (iS (iS (iS i0))))))) fastrev : ∀ {Γ τ} → Γ Source.|- (list τ ->s list τ) fastrev = lam (app (app rev2piles (var i0)) nil) -} -- this works {- insert (l : list nat) (el : nat) : list nat = [] -> [el] | x :: xs -> (leq el x -> el :: x :: xs | x :: (insert el xs)) -} insert : ∀ {Γ} → Γ Source.|- (list nat ->s (nat ->s list nat)) insert = lam (lam (listrec (var (iS i0)) (var i0 ::s nil) (rec (app (app leq (var (iS (iS (iS i0))))) (var i0)) (var i0 ::s force (var (iS (iS i0)))) (var (iS (iS (iS (iS (iS i0))))) ::s (var (iS (iS i0)) ::s var (iS (iS (iS i0)))))))) -- this works {- insertion sort (l : list nat) : list nat = [] -> [] | x :: xs -> insert x (isort xs) -} isort : ∀ {Γ} → Γ Source.|- (list nat ->s list nat) isort = lam (listrec (var i0) nil (app (app insert (force (var (iS (iS i0))))) (var i0))) -- this works {- map (l : list τ) (f : τ → τ') : list τ = [] -> [] | x :: xs -> f x :: map f xs -} map : ∀ {Γ τ τ'} → Γ Source.|- ((τ ->s τ') ->s (list τ ->s list τ')) map = lam (lam (listrec (var i0) nil (app (var (iS (iS (iS (iS i0))))) (var i0) ::s force (var (iS (iS i0)))))) dbl-trans : ∀ {Γ τ} → {!!} --el ([ (⟨⟨ Γ ⟩⟩c) ]c ->p [ (|| τ ||) ]t) dbl-trans {Γ} = {!|| dbl ||e!} example1 : ∀ {Γ τ} → {!!} example1 {Γ} {τ} = {!!} --copy and paste from this goal to the thing below {- dbl-trans : ∀ {Γ} → ⟨⟨ Γ ⟩⟩c Pilot2.|- || nat ->s nat || dbl-trans = prod 0C (lam (prod (plusC (l-proj (prod 0C (var i0))) (l-proj (rec (r-proj (prod 0C (var i0))) (prod (plusC 1C (l-proj (prod 0C z))) (r-proj (prod 0C z))) (prod (plusC 1C (l-proj (prod (l-proj (prod (l-proj (prod (plusC (l-proj (prod 0C (var (iS i0)))) (l-proj (r-proj (prod 0C (var (iS i0)))))) (r-proj (r-proj (prod 0C (var (iS i0))))))) (s (r-proj (prod (plusC (l-proj (prod 0C (var (iS i0)))) (l-proj (r-proj (prod 0C (var (iS i0)))))) (r-proj (r-proj (prod 0C (var (iS i0)))))))))) (s (r-proj (prod (l-proj (prod (plusC (l-proj (prod 0C (var (iS i0)))) (l-proj (r-proj (prod 0C (var (iS i0)))))) (r-proj (r-proj (prod 0C (var (iS i0))))))) (s (r-proj (prod (plusC (l-proj (prod 0C (var (iS i0)))) (l-proj (r-proj (prod 0C (var (iS i0)))))) (r-proj (r-proj (prod 0C (var (iS i0)))))))))))))) (r-proj (prod (l-proj (prod (l-proj (prod (plusC (l-proj (prod 0C (var (iS i0)))) (l-proj (r-proj (prod 0C (var (iS i0)))))) (r-proj (r-proj (prod 0C (var (iS i0))))))) (s (r-proj (prod (plusC (l-proj (prod 0C (var (iS i0)))) (l-proj (r-proj (prod 0C (var (iS i0)))))) (r-proj (r-proj (prod 0C (var (iS i0)))))))))) (s (r-proj (prod (l-proj (prod (plusC (l-proj (prod 0C (var (iS i0)))) (l-proj (r-proj (prod 0C (var (iS i0)))))) (r-proj (r-proj (prod 0C (var (iS i0))))))) (s (r-proj (prod (plusC (l-proj (prod 0C (var (iS i0)))) (l-proj (r-proj (prod 0C (var (iS i0)))))) (r-proj (r-proj (prod 0C (var (iS i0))))))))))))))))) (r-proj (rec (r-proj (prod 0C (var i0))) (prod (plusC 1C (l-proj (prod 0C z))) (r-proj (prod 0C z))) (prod (plusC 1C (l-proj (prod (l-proj (prod (l-proj (prod (plusC (l-proj (prod 0C (var (iS i0)))) (l-proj (r-proj (prod 0C (var (iS i0)))))) (r-proj (r-proj (prod 0C (var (iS i0))))))) (s (r-proj (prod (plusC (l-proj (prod 0C (var (iS i0)))) (l-proj (r-proj (prod 0C (var (iS i0)))))) (r-proj (r-proj (prod 0C (var (iS i0)))))))))) (s (r-proj (prod (l-proj (prod (plusC (l-proj (prod 0C (var (iS i0)))) (l-proj (r-proj (prod 0C (var (iS i0)))))) (r-proj (r-proj (prod 0C (var (iS i0))))))) (s (r-proj (prod (plusC (l-proj (prod 0C (var (iS i0)))) (l-proj (r-proj (prod 0C (var (iS i0)))))) (r-proj (r-proj (prod 0C (var (iS i0)))))))))))))) (r-proj (prod (l-proj (prod (l-proj (prod (plusC (l-proj (prod 0C (var (iS i0)))) (l-proj (r-proj (prod 0C (var (iS i0)))))) (r-proj (r-proj (prod 0C (var (iS i0))))))) (s (r-proj (prod (plusC (l-proj (prod 0C (var (iS i0)))) (l-proj (r-proj (prod 0C (var (iS i0)))))) (r-proj (r-proj (prod 0C (var (iS i0)))))))))) (s (r-proj (prod (l-proj (prod (plusC (l-proj (prod 0C (var (iS i0)))) (l-proj (r-proj (prod 0C (var (iS i0)))))) (r-proj (r-proj (prod 0C (var (iS i0))))))) (s (r-proj (prod (plusC (l-proj (prod 0C (var (iS i0)))) (l-proj (r-proj (prod 0C (var (iS i0)))))) (r-proj (r-proj (prod 0C (var (iS i0)))))))))))))))))) aaa : ∀ {Γ} → interpE (r-proj (dbl-trans {Γ})) == {!!} aaa = {!!} interp-dbl-trans : ∀ {Γ} → Monotone (fst [ ⟨⟨ Γ ⟩⟩c ]c) (fst [ ⟨⟨ nat ->s nat ⟩⟩ ]t) (snd [ ⟨⟨ Γ ⟩⟩c ]c) (snd [ ⟨⟨ nat ->s nat ⟩⟩ ]t) interp-dbl-trans {Γ} = monotone (λ x → monotone (λ p₁ → (natrec (1 , 0) (λ n x₂ → S (fst x₂) , S (S (snd x₂))) p₁)) (λ a b c → nat-trans (fst (natrec (1 , 0) (λ n x₂ → S (fst x₂) , S (S (snd x₂))) a)) (fst (natrec (1 , 0) (λ n x₂ → S (fst x₂) , S (S (snd x₂))) b)) (fst (natrec (1 , 0) (λ n x₂ → S (fst x₂) , S (S (snd x₂))) b)) (fst (♭h-fix-args (monotone (λ x₁ → 1 , 0) (λ x₁ y z₁ → <> , <>)) (monotone (λ x₁ → S (fst (snd (fst x₁))) , S (S (snd (snd (fst x₁))))) (λ x₁ y z₁ → fst (snd (fst z₁)) , snd (snd (fst z₁)))) ((x , a) , a) ((x , b) , b) c)) (fst (♭h-fix-el (monotone (λ x₁ → 1 , 0) (λ x₁ y z₁ → <> , <>)) (monotone (λ x₁ → S (fst (snd (fst x₁))) , S (S (snd (snd (fst x₁))))) (λ x₁ y z₁ → fst (snd (fst z₁)) , snd (snd (fst z₁)))) ((x , a) , a) ((x , b) , b) ((Preorder-str.refl (snd [ ⟨⟨ Γ ⟩⟩c ]c) x , c) , c))) , ♭nat-trans (snd (natrec (1 , 0) (λ n x₂ → S (fst x₂) , S (S (snd x₂))) a)) (snd (natrec (1 , 0) (λ n x₂ → S (fst x₂) , S (S (snd x₂))) b)) (snd (natrec (1 , 0) (λ n x₂ → S (fst x₂) , S (S (snd x₂))) b)) (snd (♭h-fix-args (monotone (λ x₁ → 1 , 0) (λ x₁ y z₁ → <> , <>)) (monotone (λ x₁ → S (fst (snd (fst x₁))) , S (S (snd (snd (fst x₁))))) (λ x₁ y z₁ → fst (snd (fst z₁)) , snd (snd (fst z₁)))) ((x , a) , a) ((x , b) , b) c)) (snd (♭h-fix-el (monotone (λ x₁ → 1 , 0) (λ x₁ y z₁ → <> , <>)) (monotone (λ x₁ → S (fst (snd (fst x₁))) , S (S (snd (snd (fst x₁))))) (λ x₁ y z₁ → fst (snd (fst z₁)) , snd (snd (fst z₁)))) ((x , a) , a) ((x , b) , b) ((Preorder-str.refl (snd [ ⟨⟨ Γ ⟩⟩c ]c) x , c) , c))))) (λ x y z₁ w → nat-trans (fst (natrec (1 , 0) (λ n x₂ → S (fst x₂) , S (S (snd x₂))) w)) (fst (natrec (1 , 0) (λ n x₂ → S (fst x₂) , S (S (snd x₂))) w)) (fst (natrec (1 , 0) (λ n x₂ → S (fst x₂) , S (S (snd x₂))) w)) (fst (♭h-fix-args (monotone (λ x₁ → 1 , 0) (λ x₁ y₁ z₂ → <> , <>)) (monotone (λ x₁ → S (fst (snd (fst x₁))) , S (S (snd (snd (fst x₁))))) (λ x₁ y₁ z₂ → fst (snd (fst z₂)) , snd (snd (fst z₂)))) ((x , w) , w) ((y , w) , w) (♭nat-refl w))) (fst (♭h-fix-el (monotone (λ x₁ → 1 , 0) (λ x₁ y₁ z₂ → <> , <>)) (monotone (λ x₁ → S (fst (snd (fst x₁))) , S (S (snd (snd (fst x₁))))) (λ x₁ y₁ z₂ → fst (snd (fst z₂)) , snd (snd (fst z₂)))) ((x , w) , w) ((y , w) , w) ((z₁ , ♭nat-refl w) , ♭nat-refl w))) , ♭nat-trans (snd (natrec (1 , 0) (λ n x₂ → S (fst x₂) , S (S (snd x₂))) w)) (snd (natrec (1 , 0) (λ n x₂ → S (fst x₂) , S (S (snd x₂))) w)) (snd (natrec (1 , 0) (λ n x₂ → S (fst x₂) , S (S (snd x₂))) w)) (snd (♭h-fix-args (monotone (λ x₁ → 1 , 0) (λ x₁ y₁ z₂ → <> , <>)) (monotone (λ x₁ → S (fst (snd (fst x₁))) , S (S (snd (snd (fst x₁))))) (λ x₁ y₁ z₂ → fst (snd (fst z₂)) , snd (snd (fst z₂)))) ((x , w) , w) ((y , w) , w) (♭nat-refl w))) (snd (♭h-fix-el (monotone (λ x₁ → 1 , 0) (λ x₁ y₁ z₂ → <> , <>)) (monotone (λ x₁ → S (fst (snd (fst x₁))) , S (S (snd (snd (fst x₁))))) (λ x₁ y₁ z₂ → fst (snd (fst z₂)) , snd (snd (fst z₂)))) ((x , w) , w) ((y , w) , w) ((z₁ , ♭nat-refl w) , ♭nat-refl w)))) -} {- {- halve (l : list nat) : (list nat * list nat) = splits a list in half -} halve : ∀ {Γ} → Γ Source.|- (list nat ->s (list nat ×s list nat)) halve = lam (listrec (var i0) (prod nil nil) (listrec (var (iS i0)) (prod (var i0 ::s nil) nil) (prod (var (iS (iS (iS i0))) ::s split (force (var (iS (iS i0)))) (var i0)) (var i0 ::s split (force (var (iS (iS i0)))) (var (iS i0)))))) test : ∀ {Γ τ} → {!!} test {Γ} = {!s2r (app halve (z ::s (z ::s (z ::s nil))))!} {- merge (l1 l2 : list nat) : list nat = match l1 with [] -> l2 x :: xs -> match l2 with [] -> x :: xs y :: ys -> x <= y -> x :: merge xs l2 _ -> y :: merge l1 ys -} merge : ∀ {Γ} → Γ Source.|- ((list nat ×s list nat) ->s list nat) merge = lam (listrec (split (var i0) (var i0)) (split (var i0) (var (iS i0))) (listrec (split (var (iS (iS (iS i0)))) (var (iS i0))) (split (var (iS (iS (iS i0)))) (var i0)) (rec (app (app leq (var (iS (iS (iS i0))))) (var i0)) (var (iS (iS (iS i0))) ::s force (var (iS (iS (iS (iS (iS i0))))))) (var i0 ::s app merge (prod (split (var (iS (iS (iS (iS (iS (iS (iS (iS i0))))))))) (var (iS i0))) (var (iS (iS (iS i0))))))))) {- mergesort (l : list nat) : list nat -} msort : ∀ {Γ} → Γ Source.|- (list nat ->s list nat) msort = lam (listrec (var i0) nil (listrec (var (iS i0)) (var i0 ::s nil) (app merge (prod (app msort (split (app halve (var (iS (iS (iS (iS (iS (iS i0)))))))) (var i0))) (app msort (split (app halve (var (iS (iS (iS (iS (iS (iS i0)))))))) (var (iS i0)))))))) -}
57.763085
152
0.288869
c79531495a5ea75f7f533200330ef01425952b36
28
agda
Agda
test/interaction/Issue1232/Nat.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue1232/Nat.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue1232/Nat.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Issue1232.Nat where
9.333333
26
0.821429
1372660b57ba6b890bd1d54780c03383fc46f233
302
agda
Agda
test/interaction/Issue3152.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue3152.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue3152.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
postulate M : Set → Set _>>=_ : ∀ {A B} → M A → (A → M B) → M B _>>_ : ∀ {A B} → M A → M B → M B _<|>_ : ∀ {A} → M A → M A → M A infixr 4 _>>=_ _>>_ infixr -100 _<|>_ expr : ∀ {A} → (A → M A) → (A → M A) expr f a = do x ← {!f a!} y ← {!f x <|> f a!} {!f x <|> f y!} {!f x <|> f y!}
17.764706
41
0.34106
046a4ede0c8066f883bf49194991c2541565d983
425
agda
Agda
src/data/lib/prim/Agda/Builtin/FromNeg.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
src/data/lib/prim/Agda/Builtin/FromNeg.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
src/data/lib/prim/Agda/Builtin/FromNeg.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --without-K --safe --no-sized-types --no-guardedness #-} module Agda.Builtin.FromNeg where open import Agda.Primitive open import Agda.Builtin.Nat record Negative {a} (A : Set a) : Set (lsuc a) where field Constraint : Nat → Set a fromNeg : ∀ n → {{_ : Constraint n}} → A open Negative {{...}} public using (fromNeg) {-# BUILTIN FROMNEG fromNeg #-} {-# DISPLAY Negative.fromNeg _ n = fromNeg n #-}
25
68
0.656471
57315dad5c52ba579d6781f472830f0de4153e26
4,099
agda
Agda
Sort.agda
amal029/agda-tutorial-dybjer
7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166
[ "MIT" ]
1
2019-08-08T12:52:30.000Z
2019-08-08T12:52:30.000Z
Sort.agda
amal029/agda-tutorial-dybjer
7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166
[ "MIT" ]
null
null
null
Sort.agda
amal029/agda-tutorial-dybjer
7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166
[ "MIT" ]
null
null
null
module Sort where open import Sec4 import Sec2 postulate _≤_ : {A : Set} → A → A → Prop postulate tot-list : {A : Set} → (a b : A) → (a ≤ b) ∨ (b ≤ a) postulate trans-list : {A : Set} → (a b c : A) → (a ≤ b) → (b ≤ c) → (a ≤ c) -- XXX: Definition of a list data List (A : Set) : Set where Nil : List A _∷_ : A → List A → List A -- XXX: definition of an ordered list all-ordered-list : {A : Set} → (a : A) → (l : List A) → Prop all-ordered-list a Nil = ⊤ all-ordered-list a (x ∷ l) = (a ≤ x) ∧ all-ordered-list a l ordered-list : {A : Set} → List A → Prop ordered-list Nil = ⊤ ordered-list (x ∷ l) = all-ordered-list x l ∧ (ordered-list l) -- XXX: Inserting elements in the list insert-list : {A : Set} → (a : A) → (l : List A) → List A insert-list a Nil = a ∷ Nil insert-list a (x ∷ l) with (tot-list a x) insert-list a (x ∷ l) | ora h = a ∷ (x ∷ l) insert-list a (x ∷ l) | orb h = x ∷ (insert-list a l) lem1 : {A : Set} → (a x : A) → (l : List A) → (p : all-ordered-list x l) → (p1 : a ≤ x) → (all-ordered-list a l) lem1 a x Nil p p1 = ⋆ lem1 a x (x₁ ∷ l) (and x₂ x₃) p1 = and (trans-list a x x₁ p1 x₂) (lem1 a x l x₃ p1) lem2 : {A : Set} → (x a : A) → (l : List A) → (h : x ≤ a) → (p1 : all-ordered-list x l) → (p2 : ordered-list l) → (v : ordered-list (insert-list a l)) → all-ordered-list x (insert-list a l) lem2 x a Nil h p1 p3 v = and h ⋆ lem2 x a (x₁ ∷ l) h p1 p3 v with (tot-list a x₁) lem2 x₂ a (x₁ ∷ l) h p1 p3 v | ora x = and h p1 lem2 x₂ a (x₁ ∷ l) h (and x₃ x₄) (and x₅ x₆) (and x₇ x₈) | orb x = and x₃ (lem2 x₂ a l h x₄ x₆ x₈) thm2 : {A : Set} → ∀ (a : A) → ∀ (l : List A) → (p : ordered-list l) → (ordered-list (insert-list a l)) thm2 a Nil p = and ⋆ ⋆ thm2 a (x ∷ l) p with (tot-list a x) thm2 a (x ∷ l) (and x₁ x₂) | ora h = and (and h (lem1 a x l x₁ h)) (and x₁ x₂) thm2 a (x ∷ l) (and x₁ x₂) | orb h = let v = (thm2 a l x₂) in and (lem2 x a l h x₁ x₂ v) v -- XXX: append lists _++_ : {A : Set} → (l : List A) → (m : List A) → List A Nil ++ m = m (x ∷ l) ++ m = x ∷ (l ++ m) -- XXX: Length of a list length : {A : Set} → (l : List A) → Sec2.ℕ length Nil = Sec2.Z length (x ∷ l) = Sec2.S (length l) -- XXX: reverse of a list rev : {A : Set} → (List A) → (List A) rev Nil = Nil rev (x ∷ l) = (rev l) ++ (x ∷ Nil) -- XXX: Theorem on length of lists thm : {A : Set} → (l : List A) → (m : List A) → ((length l) Sec2.+ (length m) Sec2.≡ length (l ++ m)) thm Nil m = Sec2.refl thm (x ∷ l) m = let xx = thm l m in Sec2.cong xx cong : {A : Set} → (x : A) → (l m : List A) → (l Sec2.≡ m) → (x ∷ l) Sec2.≡ (x ∷ m) cong x l .l Sec2.refl = Sec2.refl cong2 : {A : Set} → (l m q : List A) → (l Sec2.≡ m) → (l ++ q) Sec2.≡ (m ++ q) cong2 l .l q Sec2.refl = Sec2.refl ++-lem : {A : Set} → (l : List A) → ((l ++ Nil) Sec2.≡ l) ++-lem Nil = Sec2.refl ++-lem (x ∷ l) = cong x (l ++ Nil) l (++-lem l) assoc : {A : Set} → (l m q : List A) → l ++ (m ++ q) Sec2.≡ (l ++ m) ++ q assoc Nil m q = Sec2.refl assoc (x ∷ l) m q = cong x (l ++ (m ++ q)) ((l ++ m) ++ q) (assoc l m q) rev-lem : {A : Set} → ∀ (l m : List A) → rev (l ++ m) Sec2.≡ (rev m) ++ (rev l) rev-lem Nil m rewrite ++-lem (rev m) = Sec2.refl rev-lem (x ∷ l) m rewrite assoc (rev m) (rev l) (x ∷ Nil) = let p = rev-lem l m in cong2 (rev (l ++ m)) (rev m ++ rev l) (x ∷ Nil) p -- XXX: Involution of reversal of lists rev-involute : {A : Set} → (l : List A) → l Sec2.≡ (rev (rev l)) rev-involute Nil = Sec2.refl rev-involute (x ∷ l) rewrite rev-lem (rev l) (x ∷ Nil) = cong x l (rev (rev l)) (rev-involute l)
33.876033
103
0.452061
c7868da1a41023f3b909b03bb86e125fb8be921c
3,956
agda
Agda
TotalParserCombinators/Force.agda
yurrriq/parser-combinators
b396d35cc2cb7e8aea50b982429ee385f001aa88
[ "MIT" ]
7
2016-12-13T05:23:14.000Z
2021-06-22T05:35:31.000Z
TotalParserCombinators/Force.agda
yurrriq/parser-combinators
b396d35cc2cb7e8aea50b982429ee385f001aa88
[ "MIT" ]
1
2018-01-22T22:21:41.000Z
2018-01-24T16:39:37.000Z
TotalParserCombinators/Force.agda
yurrriq/parser-combinators
b396d35cc2cb7e8aea50b982429ee385f001aa88
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Forcing of parsers (can be used for inspection/debugging purposes) ------------------------------------------------------------------------ {-# OPTIONS --termination-depth=2 #-} module TotalParserCombinators.Force where open import Coinduction import Data.List.Categorical as ListMonad open import Data.Maybe open import Data.Nat open import Function import Relation.Binary.PropositionalEquality as P open import TotalParserCombinators.Congruence open import TotalParserCombinators.Laws open import TotalParserCombinators.Parser -- force n p returns p, but with the first n layers of delay -- constructors removed. force : ∀ {Tok R xs} → ℕ → Parser Tok R xs → Parser Tok R xs force zero p = p force n (return x) = return x force n fail = fail force n token = token force n (p₁ ∣ p₂) = force n p₁ ∣ force n p₂ force n (f <$> p) = f <$> force n p force n (nonempty p) = nonempty (force n p) force n (cast xs₁≈xs₂ p) = cast xs₁≈xs₂ (force n p) force (suc n) (p₁ ⊛ p₂) with forced? p₁ | forced? p₂ ... | just xs | nothing = force (suc n) p₁ ⊛ force n (♭ p₂) ... | just xs | just fs = force (suc n) p₁ ⊛ force (suc n) p₂ ... | nothing | nothing = force n (♭ p₁) ⊛ force n (♭ p₂) ... | nothing | just fs = P.subst (Parser _ _) (ListMonad.Applicative.right-zero fs) $ force n (♭ p₁) ⊛ force (suc n) p₂ force (suc n) (p₁ >>= p₂) with forced? p₁ | forced?′ p₂ ... | just f | nothing = force (suc n) p₁ >>= λ x → force n (♭ (p₂ x)) ... | just f | just xs = force (suc n) p₁ >>= λ x → force (suc n) (p₂ x) ... | nothing | nothing = force n (♭ p₁) >>= λ x → force n (♭ (p₂ x)) ... | nothing | just xs = P.subst (Parser _ _) (ListMonad.MonadProperties.right-zero xs) $ force n (♭ p₁) >>= λ x → force (suc n) (p₂ x) -- force preserves the semantics of its argument. correct : ∀ {Tok R xs} (n : ℕ) (p : Parser Tok R xs) → force n p ≅P p correct zero p = p ∎ correct (suc n) (return x) = return x ∎ correct (suc n) fail = fail ∎ correct (suc n) token = token ∎ correct (suc n) (p₁ ∣ p₂) = correct (suc n) p₁ ∣ correct (suc n) p₂ correct (suc n) (f <$> p) = (λ _ → P.refl) <$> correct (suc n) p correct (suc n) (nonempty p) = nonempty (correct (suc n) p) correct (suc n) (cast xs₁≈xs₂ p) = cast (correct (suc n) p) correct (suc n) (p₁ ⊛ p₂) with forced? p₁ | forced? p₂ ... | just xs | nothing = [ ○ - ○ - ○ - ◌ ] correct (suc n) p₁ ⊛ correct n (♭ p₂) ... | just xs | just fs = [ ○ - ○ - ○ - ○ ] correct (suc n) p₁ ⊛ correct (suc n) p₂ ... | nothing | nothing = [ ○ - ◌ - ○ - ◌ ] correct n (♭ p₁) ⊛ correct n (♭ p₂) ... | nothing | just fs = P.subst (Parser _ _) lemma forced ≅⟨ Subst.correct lemma ⟩ forced ≅⟨ [ ○ - ◌ - ○ - ○ ] correct n (♭ p₁) ⊛ correct (suc n) p₂ ⟩ p₁ ⊛ p₂ ∎ where lemma = ListMonad.Applicative.right-zero fs forced = force n (♭ p₁) ⊛ force (suc n) p₂ correct (suc n) (p₁ >>= p₂) with forced? p₁ | forced?′ p₂ ... | just f | nothing = [ ○ - ○ - ○ - ◌ ] correct (suc n) p₁ >>= λ x → correct n (♭ (p₂ x)) ... | just f | just xs = [ ○ - ○ - ○ - ○ ] correct (suc n) p₁ >>= λ x → correct (suc n) (p₂ x) ... | nothing | nothing = [ ○ - ◌ - ○ - ◌ ] correct n (♭ p₁) >>= λ x → correct n (♭ (p₂ x)) ... | nothing | just xs = P.subst (Parser _ _) lemma forced ≅⟨ Subst.correct lemma ⟩ forced ≅⟨ [ ○ - ◌ - ○ - ○ ] correct n (♭ p₁) >>= (λ x → correct (suc n) (p₂ x)) ⟩ p₁ >>= p₂ ∎ where forced = force n (♭ p₁) >>= λ x → force (suc n) (p₂ x) lemma = ListMonad.MonadProperties.right-zero xs
49.45
111
0.50455
57d36ffcdd4c5a20a8118c6743ad4078f96efbb5
1,177
agda
Agda
cohomology/SphereProduct.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
cohomology/SphereProduct.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
cohomology/SphereProduct.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} open import HoTT open import homotopy.SuspProduct open import homotopy.SuspSmash open import homotopy.JoinSusp open import cohomology.Theory module cohomology.SphereProduct {i} (CT : CohomologyTheory i) where open CohomologyTheory CT open import cohomology.Wedge CT module _ (n : ℤ) (m : ℕ) (X : Ptd i) where private space-path : ⊙Susp (⊙Sphere {i} m ⊙× X) == ⊙Sphere {i} (S m) ⊙∨ (⊙Susp^ (S m) X ⊙∨ ⊙Susp X) space-path = SuspProduct.⊙path (⊙Sphere m) X ∙ ap (λ Z → ⊙Sphere (S m) ⊙∨ (Z ⊙∨ ⊙Susp X)) (SuspSmash.⊙path (⊙Sphere m) X ∙ ⊙join-sphere X m) C-Sphere× : C n (⊙Sphere {i} m ⊙× X) == C n (⊙Sphere m) ×ᴳ (C n (⊙Susp^ m X) ×ᴳ C n X) C-Sphere× = ! (C-Susp n (⊙Sphere m ⊙× X)) ∙ ap (C (succ n)) space-path ∙ C-binary-additive (succ n) (⊙Sphere (S m)) (⊙Susp^ (S m) X ⊙∨ ⊙Susp X) ∙ ap (λ H → C (succ n) (⊙Sphere (S m)) ×ᴳ H) (C-binary-additive (succ n) (⊙Susp^ (S m) X) (⊙Susp X) ∙ ap2 _×ᴳ_ (C-Susp n (⊙Susp^ m X)) (C-Susp n X)) ∙ ap (λ H → H ×ᴳ (C n (⊙Susp^ m X) ×ᴳ C n X)) (C-Susp n (⊙Sphere m))
30.973684
76
0.526763
31cb9c8c45581808403a57614854f5d6fb7f18de
693
agda
Agda
test/Succeed/Issue2308.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue2308.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue2308.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2016-11-19 issue #2308 -- Since fix of #2197, in mutual blocks, records are no-eta-equality -- until the positivity checker has run. -- Thus, the record pattern translation might not kick in. -- Now, there is another pass of record pattern translation -- after the mutual block has finished. data Unit : Set where unit : Unit mutual -- needed to trigger issue record R : Set where -- needs to be in mutual block pattern; constructor wrap field f : Unit G : R → Set G (wrap _) = Unit -- match on wrap needed test : (x : R) → G x → Set₁ test _ unit = Set -- ERROR WAS: -- Type mismatch -- when checking that the pattern unit has type G x -- Should succeed.
23.1
68
0.685426
adfa205c1c9019600de5ef946dcfa148f9e57912
2,957
agda
Agda
test/succeed/Issue840a.agda
larrytheliquid/agda
477c8c37f948e6038b773409358fd8f38395f827
[ "MIT" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
test/succeed/Issue840a.agda
masondesu/agda
70c8a575c46f6a568c7518150a1a64fcd03aa437
[ "MIT" ]
null
null
null
test/succeed/Issue840a.agda
masondesu/agda
70c8a575c46f6a568c7518150a1a64fcd03aa437
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
module Issue840a where ------------------------------------------------------------------------ -- Prelude record ⊤ : Set where data ⊥ : Set where data _≡_ {A : Set} (x : A) : A → Set where refl : x ≡ x data Bool : Set where true false : Bool {-# BUILTIN BOOL Bool #-} {-# BUILTIN TRUE true #-} {-# BUILTIN FALSE false #-} postulate String : Set {-# BUILTIN STRING String #-} primitive primStringEquality : String → String → Bool infixr 4 _,_ record Σ (A : Set) (B : A → Set) : Set where constructor _,_ field proj₁ : A proj₂ : B proj₁ ------------------------------------------------------------------------ -- Other stuff mutual infixl 5 _,_∶_ data Signature : Set₁ where ∅ : Signature _,_∶_ : (Sig : Signature) (ℓ : String) (A : Record Sig → Set) → Signature record Record (Sig : Signature) : Set where constructor rec field fun : Record-fun Sig Record-fun : Signature → Set Record-fun ∅ = ⊤ Record-fun (Sig , ℓ ∶ A) = Σ (Record Sig) A _∈_ : String → Signature → Set ℓ ∈ ∅ = ⊥ ℓ ∈ (Sig , ℓ′ ∶ A) with primStringEquality ℓ ℓ′ ... | true = ⊤ ... | false = ℓ ∈ Sig Restrict : (Sig : Signature) (ℓ : String) → ℓ ∈ Sig → Signature Restrict ∅ ℓ () Restrict (Sig , ℓ′ ∶ A) ℓ ℓ∈ with primStringEquality ℓ ℓ′ ... | true = Sig ... | false = Restrict Sig ℓ ℓ∈ Proj : (Sig : Signature) (ℓ : String) {ℓ∈ : ℓ ∈ Sig} → Record (Restrict Sig ℓ ℓ∈) → Set Proj ∅ ℓ {} Proj (Sig , ℓ′ ∶ A) ℓ {ℓ∈} with primStringEquality ℓ ℓ′ ... | true = A ... | false = Proj Sig ℓ {ℓ∈} _∣_ : {Sig : Signature} → Record Sig → (ℓ : String) {ℓ∈ : ℓ ∈ Sig} → Record (Restrict Sig ℓ ℓ∈) _∣_ {Sig = ∅} r ℓ {} _∣_ {Sig = Sig , ℓ′ ∶ A} (rec r) ℓ {ℓ∈} with primStringEquality ℓ ℓ′ ... | true = Σ.proj₁ r ... | false = _∣_ (Σ.proj₁ r) ℓ {ℓ∈} infixl 5 _·_ _·_ : {Sig : Signature} (r : Record Sig) (ℓ : String) {ℓ∈ : ℓ ∈ Sig} → Proj Sig ℓ {ℓ∈} (r ∣ ℓ) _·_ {Sig = ∅} r ℓ {} _·_ {Sig = Sig , ℓ′ ∶ A} (rec r) ℓ {ℓ∈} with primStringEquality ℓ ℓ′ ... | true = Σ.proj₂ r ... | false = _·_ (Σ.proj₁ r) ℓ {ℓ∈} R : Set → Signature R A = ∅ , "f" ∶ (λ _ → A → A) , "x" ∶ (λ _ → A) , "lemma" ∶ (λ r → ∀ y → (r · "f") y ≡ y) record GS (A B : Set) : Set where field get : A → B set : A → B → A get-set : ∀ a b → get (set a b) ≡ b set-get : ∀ a → set a (get a) ≡ a f : {A : Set} → GS (Record (R A)) (Record (∅ , "f" ∶ (λ _ → A → A) , "lemma" ∶ (λ r → ∀ x → (r · "f") x ≡ x))) f = record { set = λ r f-lemma → rec (rec (rec (rec _ , f-lemma · "f") , r · "x") , f-lemma · "lemma") ; get-set = λ { (rec (rec (rec (_ , _) , _) , _)) (rec (rec (_ , _) , _)) → refl } ; set-get = λ { (rec (rec (rec (rec _ , _) , _) , _)) → refl } }
25.273504
72
0.448089
4114ee780adffa2592617cd9d6341aeaff54ddba
3,650
agda
Agda
Types.agda
bens/hwlc
6f3df71dcd958c6a1d1bf4f175dc16c220d42124
[ "BSD-3-Clause" ]
null
null
null
Types.agda
bens/hwlc
6f3df71dcd958c6a1d1bf4f175dc16c220d42124
[ "BSD-3-Clause" ]
null
null
null
Types.agda
bens/hwlc
6f3df71dcd958c6a1d1bf4f175dc16c220d42124
[ "BSD-3-Clause" ]
null
null
null
module Types where open import Data.Bool open import Data.Fin using (Fin) import Data.Fin as F open import Data.Nat renaming (_≟_ to _≟N_) open import Data.Vec hiding (head; tail) open import Relation.Binary.PropositionalEquality open import Relation.Nullary infixl 80 _∙_ data Type : Set where 𝔹 : Type 𝔹⁺ : ℕ → Type ℂ : Type → Type _⇒_ : Type → Type → Type _×_ : Type → Type → Type data Syntax : Set where bitI : Syntax bitO : Syntax [] : Syntax _∷_ : Syntax → Syntax → Syntax _nand_ : Syntax → Syntax → Syntax reg : Syntax → Syntax → Syntax pair : Syntax → Syntax → Syntax latest : Syntax → Syntax head : Syntax → Syntax tail : Syntax → Syntax var : ℕ → Syntax _∙_ : Syntax → Syntax → Syntax lam : Type → Syntax → Syntax Ctx : ℕ → Set Ctx = Vec Type data Term {n} (Γ : Ctx n) : Type → Set where bitI : Term Γ 𝔹 bitO : Term Γ 𝔹 [] : Term Γ (𝔹⁺ 0) _∷_ : ∀ {n} → Term Γ 𝔹 → Term Γ (𝔹⁺ n) → Term Γ (𝔹⁺ (suc n)) _nand_ : Term Γ 𝔹 → Term Γ 𝔹 → Term Γ 𝔹 reg : ∀ {τ σ} → Term Γ τ → Term Γ (τ ⇒ (τ × σ)) → Term Γ (ℂ σ) pair : ∀ {σ τ} → Term Γ σ → Term Γ τ → Term Γ (σ × τ) latest : ∀ {τ} → Term Γ (ℂ τ) → Term Γ τ head : ∀ {n} → Term Γ (𝔹⁺ (suc n)) → Term Γ 𝔹 tail : ∀ {n} → Term Γ (𝔹⁺ (suc n)) → Term Γ (𝔹⁺ n) var : ∀ {τ} (i : Fin n) → (lookup i Γ ≡ τ) → Term Γ τ _∙_ : ∀ {σ τ} → Term Γ (σ ⇒ τ) → Term Γ σ → Term Γ τ lam : ∀ {σ τ} → Term (σ ∷ Γ) τ → Term Γ (σ ⇒ τ) Closed : Type → Set Closed τ = ∀ {n} {ctx : Ctx n} → Term ctx τ ≡𝔹⁺ : ∀ {n m} → 𝔹⁺ n ≡ 𝔹⁺ m → n ≡ m ≡𝔹⁺ refl = refl ≡ℂ : ∀ {τ σ} → ℂ τ ≡ ℂ σ → τ ≡ σ ≡ℂ refl = refl ≡⇒₁ : ∀ {σ σ′ τ τ′} → σ ⇒ τ ≡ σ′ ⇒ τ′ → σ ≡ σ′ ≡⇒₁ refl = refl ≡⇒₂ : ∀ {σ σ′ τ τ′} → σ ⇒ τ ≡ σ′ ⇒ τ′ → τ ≡ τ′ ≡⇒₂ refl = refl ≡×₁ : ∀ {σ σ′ τ τ′} → σ × τ ≡ σ′ × τ′ → σ ≡ σ′ ≡×₁ refl = refl ≡×₂ : ∀ {σ σ′ τ τ′} → σ × τ ≡ σ′ × τ′ → τ ≡ τ′ ≡×₂ refl = refl _≟T_ : (σ τ : Type) → Dec (σ ≡ τ) 𝔹 ≟T 𝔹 = yes refl 𝔹 ≟T 𝔹⁺ _ = no (λ ()) 𝔹 ≟T ℂ _ = no (λ ()) 𝔹 ≟T (_ ⇒ _) = no (λ ()) 𝔹 ≟T (_ × _) = no (λ ()) 𝔹⁺ _ ≟T 𝔹 = no (λ ()) 𝔹⁺ n ≟T 𝔹⁺ m with n ≟N m 𝔹⁺ n ≟T 𝔹⁺ .n | yes refl = yes refl 𝔹⁺ n ≟T 𝔹⁺ m | no ¬p = no (λ x → ¬p (≡𝔹⁺ x)) 𝔹⁺ _ ≟T ℂ _ = no (λ ()) 𝔹⁺ _ ≟T (y ⇒ y₁) = no (λ ()) 𝔹⁺ _ ≟T (y × y₁) = no (λ ()) ℂ _ ≟T 𝔹 = no (λ ()) ℂ _ ≟T 𝔹⁺ n = no (λ ()) ℂ τ ≟T ℂ σ with τ ≟T σ ℂ τ ≟T ℂ .τ | yes refl = yes refl ℂ τ ≟T ℂ σ | no ¬p = no (λ x → ¬p (≡ℂ x)) ℂ _ ≟T (_ ⇒ _) = no (λ ()) ℂ _ ≟T (_ × _) = no (λ ()) (_ ⇒ _) ≟T 𝔹 = no (λ ()) (σ ⇒ τ) ≟T 𝔹⁺ x₂ = no (λ ()) (_ ⇒ _) ≟T ℂ _ = no (λ ()) (σ ⇒ τ) ≟T (σ₁ ⇒ τ₁) with σ ≟T σ₁ | τ ≟T τ₁ (σ ⇒ τ) ≟T (σ₁ ⇒ τ₁) | yes p | yes p₁ = yes (cong₂ _⇒_ p p₁) (σ ⇒ τ) ≟T (σ₁ ⇒ τ₁) | _ | no ¬p = no (λ x → ¬p (≡⇒₂ x)) (σ ⇒ τ) ≟T (σ₁ ⇒ τ₁) | no ¬p | _ = no (λ x → ¬p (≡⇒₁ x)) (_ ⇒ _) ≟T (_ × _) = no (λ ()) (_ × _) ≟T 𝔹 = no (λ ()) (_ × _) ≟T 𝔹⁺ _ = no (λ ()) (_ × _) ≟T ℂ _ = no (λ ()) (_ × _) ≟T (_ ⇒ _) = no (λ ()) (σ × τ) ≟T (σ₁ × τ₁) with σ ≟T σ₁ | τ ≟T τ₁ (σ × τ) ≟T (σ₁ × τ₁) | yes p | yes p₁ = yes (cong₂ _×_ p p₁) (σ × τ) ≟T (σ₁ × τ₁) | _ | no ¬p = no (λ x → ¬p (≡×₂ x)) (σ × τ) ≟T (σ₁ × τ₁) | no ¬p | _ = no (λ x → ¬p (≡×₁ x)) erase : ∀ {n} {Γ : Ctx n} {τ} → Term Γ τ → Syntax erase bitI = bitI erase bitO = bitO erase [] = [] erase (x ∷ xs) = erase x ∷ erase xs erase (x nand y) = erase x nand erase y erase (reg x t) = reg (erase x) (erase t) erase (pair x y) = pair (erase x) (erase y) erase (latest x) = latest (erase x) erase (head x) = head (erase x) erase (tail x) = tail (erase x) erase (var v _) = var (F.toℕ v) erase (t ∙ u) = erase t ∙ erase u erase (lam {σ} t) = lam σ (erase t)
29.2
67
0.46
1a3a9be22febf536859dc98d2bd10fe202d93ccc
566
agda
Agda
test/Fail/NoConstraints.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
2
2019-10-29T09:40:30.000Z
2020-09-20T00:28:57.000Z
test/Fail/NoConstraints.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
3
2018-11-14T15:31:44.000Z
2019-04-01T19:39:26.000Z
test/Fail/NoConstraints.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1
2015-09-15T14:36:15.000Z
2015-09-15T14:36:15.000Z
open import Agda.Builtin.Bool open import Agda.Builtin.List open import Agda.Builtin.Reflection open import Agda.Builtin.Unit P : Bool → Set P true = Bool P false = Bool f : (b : Bool) → P b f true = true f false = false pattern varg x = arg (arg-info visible relevant) x create-constraint : TC Set create-constraint = unquoteTC (def (quote P) (varg (def (quote f) (varg unknown ∷ [])) ∷ [])) macro should-fail : Term → TC ⊤ should-fail _ = bindTC (noConstraints create-constraint) λ _ → returnTC tt test : ⊤ test = should-fail
18.866667
63
0.662544
c7ef9b17e3ca0473017a0052aa5a61edf415c1ab
858
agda
Agda
core/lib/types/Lift.agda
cmknapp/HoTT-Agda
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
[ "MIT" ]
null
null
null
core/lib/types/Lift.agda
cmknapp/HoTT-Agda
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
[ "MIT" ]
null
null
null
core/lib/types/Lift.agda
cmknapp/HoTT-Agda
bc849346a17b33e2679a5b3f2b8efbe7835dc4b6
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} open import lib.Basics open import lib.types.Pointed module lib.types.Lift where ⊙Lift : ∀ {i j} → Ptd i → Ptd (lmax i j) ⊙Lift {j = j} (A , a) = ⊙[ Lift {j = j} A , lift a ] ⊙lift : ∀ {i j} {X : Ptd i} → fst (X ⊙→ ⊙Lift {j = j} X) ⊙lift = (lift , idp) ⊙lower : ∀ {i j} {X : Ptd i} → fst (⊙Lift {j = j} X ⊙→ X) ⊙lower = (lower , idp) lift-equiv : ∀ {i j} {A : Type i} → A ≃ Lift {j = j} A lift-equiv = equiv lift lower (λ _ → idp) (λ _ → idp) -- [lower-equiv] is in Equivalences.agda Lift-level : ∀ {i j} {A : Type i} {n : ℕ₋₂} → has-level n A → has-level n (Lift {j = j} A) Lift-level = equiv-preserves-level lift-equiv ⊙lift-equiv : ∀ {i j} {X : Ptd i} → X ⊙≃ ⊙Lift {j = j} X ⊙lift-equiv = (⊙lift , snd lift-equiv) ⊙lower-equiv : ∀ {i j} {X : Ptd i} → ⊙Lift {j = j} X ⊙≃ X ⊙lower-equiv = (⊙lower , snd lower-equiv)
27.677419
57
0.539627
c7c93d6ea0174dde82388c20e15141d4fbe72898
962
agda
Agda
notes/FOT/FOTC/Program/Mirror/StructurallySmaller/StructurallySmaller.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
notes/FOT/FOTC/Program/Mirror/StructurallySmaller/StructurallySmaller.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
notes/FOT/FOTC/Program/Mirror/StructurallySmaller/StructurallySmaller.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
{-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOT.FOTC.Program.Mirror.StructurallySmaller.StructurallySmaller where open import FOTC.Base open import FOTC.Base.List open import FOTC.Program.Mirror.Type ------------------------------------------------------------------------------ {-# TERMINATING #-} foo : ∀ {ts} → Tree ts → D foo (tree d fnil) = d foo (tree d (fcons Tt Fts)) = foo (tree d Fts) {-# TERMINATING #-} bar : ∀ {ts} → Tree ts → D bar (tree d fnil) = d bar (tree d (fcons Tt Fts)) = helper (bar Tt) (bar (tree d Fts)) where postulate helper : D → D → D {-# TERMINATING #-} bar₁ : ∀ ts → Tree ts → D bar₁ .(node d []) (tree d fnil) = d bar₁ .(node d (t ∷ ts)) (tree d (fcons {t} {ts} Tt Fts)) = helper (bar₁ t Tt) (bar₁ (node d ts) (tree d Fts)) where postulate helper : D → D → D
29.151515
78
0.532225
13274579864116f9ea5869dcd359cc4cd88ed587
3,873
agda
Agda
misc/RecursiveDescent/Hybrid/Mixfix.agda
yurrriq/parser-combinators
b396d35cc2cb7e8aea50b982429ee385f001aa88
[ "MIT" ]
7
2016-12-13T05:23:14.000Z
2021-06-22T05:35:31.000Z
misc/RecursiveDescent/Hybrid/Mixfix.agda
nad/parser-combinators
76774f54f466cfe943debf2da731074fe0c33644
[ "MIT" ]
1
2018-01-22T22:21:41.000Z
2018-01-24T16:39:37.000Z
misc/RecursiveDescent/Hybrid/Mixfix.agda
nad/parser-combinators
76774f54f466cfe943debf2da731074fe0c33644
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Parsing of mixfix operators ------------------------------------------------------------------------ -- This module defines a grammar for the precedence graph g. open import RecursiveDescent.Hybrid.Mixfix.Expr module RecursiveDescent.Hybrid.Mixfix (g : PrecedenceGraph) where import Data.Vec as Vec import Data.List as List open List using (List; []; _∷_; foldr; foldl) import Data.Vec1 as Vec1 open Vec1 using (Vec₁) open import Data.Product renaming (_,_ to pair) open import Data.Product.Record using (_,_) open import Data.Bool open import Data.Unit open import Data.Nat open import Data.Function hiding (_⟨_⟩_) import Data.String as String open import RecursiveDescent.Hybrid.Mixfix.Fixity open import RecursiveDescent.Index open import RecursiveDescent.Hybrid open import RecursiveDescent.Hybrid.Simple open import RecursiveDescent.Hybrid.Lib open Token String.decSetoid -- Note that, even though grammar below is not recursive, these -- functions are (mutually). Fortunately the recursion is structural, -- though. Note also that the reason for not using the implementation -- -- grammar (nodes ts) = choiceMap (\t -> ! node t) ts -- -- is that this would lead to a definition of node-corners which -- was not structurally recursive. nodes-corners : PrecedenceGraph -> Corners nodes-corners [] = _ nodes-corners (p ∷ ps) = _ node-corners : PrecedenceTree -> Corners node-corners (precedence ops ps) = _ -- Nonterminals. data NT : ParserType where -- Expressions. expr : NT _ Expr -- Expressions corresponding to zero or more nodes in the precedence -- graph: operator applications where the outermost operator has one -- of the precedences ps. The graph g is used for internal -- expressions. nodes : (ps : PrecedenceGraph) -> NT (false , nodes-corners ps) Expr -- Expressions corresponding to one node in the precedence graph: -- operator applications where the outermost operator has -- precedence p. The graph g is used for internal expressions. node : (p : PrecedenceTree) -> NT (false , node-corners p) Expr -- The parser type used in this module. P : Index -> Set -> Set1 P = Parser NamePart NT -- A vector containing parsers recognising the name parts of the -- operator. nameParts : forall {fix arity} -> Operator fix arity -> Vec₁ (P _ NamePart) (1 + arity) nameParts (operator ns) = Vec1.map₀₁ sym ns -- Internal parts (all name parts plus internal expressions) of -- operators of the given precedence and fixity. internal : forall {fix} (ops : List (∃ (Operator fix))) -> P _ (Internal fix) internal = choiceMap (\op' -> let op = proj₂ op' in _∙_ op <$> (! expr between nameParts op)) -- The grammar. grammar : Grammar NamePart NT grammar expr = ! nodes g grammar (nodes []) = fail grammar (nodes (p ∷ ps)) = ! node p ∣ ! nodes ps grammar (node (precedence ops ps)) = ⟪_⟫ <$> ⟦ closed ⟧ ∣ _⟨_⟩_ <$> ↑ ⊛ ⟦ infx non ⟧ ⊛ ↑ ∣ flip (foldr _$_) <$> preRight + ⊛ ↑ ∣ foldl (flip _$_) <$> ↑ ⊛ postLeft + where -- ⟦ fix ⟧ parses the internal parts of operators with the -- current precedence level and fixity fix. ⟦_⟧ = \(fix : Fixity) -> internal (ops fix) -- Operator applications where the outermost operator binds -- tighter than the current precedence level. ↑ = ! nodes ps -- Right associative and prefix operators. preRight = ⟪_⟩_ <$> ⟦ prefx ⟧ ∣ _⟨_⟩_ <$> ↑ ⊛ ⟦ infx right ⟧ -- Left associative and postfix operators. postLeft = flip _⟨_⟫ <$> ⟦ postfx ⟧ ∣ (\op e₂ e₁ -> e₁ ⟨ op ⟩ e₂) <$> ⟦ infx left ⟧ ⊛ ↑ -- An expression parser. parseExpr : List NamePart -> List Expr parseExpr = parse-complete (! expr) grammar
33.102564
72
0.645236
294afd93527e4a3b47c9c932d612662c1773c891
878
agda
Agda
src/Prelude.agda
lisandrasilva/agda-liveness
391e148f391dc2d246249193788a0d203285b38e
[ "Apache-2.0" ]
null
null
null
src/Prelude.agda
lisandrasilva/agda-liveness
391e148f391dc2d246249193788a0d203285b38e
[ "Apache-2.0" ]
null
null
null
src/Prelude.agda
lisandrasilva/agda-liveness
391e148f391dc2d246249193788a0d203285b38e
[ "Apache-2.0" ]
null
null
null
-- This is a selection of useful function -- from the standard library that we tend to use a lot. module Prelude where open import Data.Nat hiding (_⊔_) public open import Level renaming (suc to lsuc; zero to ℓ0) public open import Relation.Binary.PropositionalEquality renaming ([_] to Reveal[_] ) public open import Relation.Unary public open import Data.Unit using (⊤; tt) public open import Data.Sum public open import Data.Nat.Properties public open import Relation.Nullary hiding (Irrelevant) public open import Data.Product using (_×_; proj₁; proj₂; Σ; _,_; ∃; Σ-syntax; ∃-syntax) public open import Data.Empty using (⊥; ⊥-elim) public open import Function using (_∘_) public open import Data.List.Relation.Unary.Any using (Any; here; there) public
17.215686
60
0.66287
c7699236b82eb23e9a99032f7b2d08d339f0d169
1,397
agda
Agda
src/JVM/Transform/Noooops.agda
ajrouvoet/jvm.agda
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
[ "Apache-2.0" ]
6
2020-10-07T14:07:17.000Z
2021-02-28T21:49:08.000Z
src/JVM/Transform/Noooops.agda
ajrouvoet/jvm.agda
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
[ "Apache-2.0" ]
null
null
null
src/JVM/Transform/Noooops.agda
ajrouvoet/jvm.agda
c84bc6b834295ac140ff30bfc8e55228efbf6d2a
[ "Apache-2.0" ]
1
2021-12-28T17:37:15.000Z
2021-12-28T17:37:15.000Z
{-# OPTIONS --safe --no-qualified-instances #-} {- Noop removal transformation on bytecode -} module JVM.Transform.Noooops where open import Data.Product open import Data.Sum open import Function using (case_of_) open import Data.List open import Relation.Unary hiding (Empty) open import Relation.Binary.Structures open import Relation.Binary.PropositionalEquality using (refl; _≡_) open import Relation.Ternary.Core open import Relation.Ternary.Structures open import Relation.Ternary.Structures.Syntax hiding (_∣_) open import JVM.Types open import JVM.Model StackTy open import JVM.Syntax.Instructions open import Relation.Ternary.Data.ReflexiveTransitive {{intf-rel}} open IsEquivalence {{...}} using (sym) open import Data.Maybe using (just; nothing; Maybe) is-noop : ∀[ ⟨ 𝑭 ∣ ψ₁ ↝ ψ₂ ⟩ ⇒ (Empty (ψ₁ ≡ ψ₂) ∪ U) ] is-noop noop = inj₁ (emp refl) is-noop _ = inj₂ _ noooop : ∀[ ⟪ 𝑭 ∣ ψ₁ ↝ ψ₂ ⟫ ⇒ ⟪ 𝑭 ∣ ψ₁ ↝ ψ₂ ⟫ ] noooop nil = nil -- (1) not labeled noooop (cons (instr (↓ i) ∙⟨ σ ⟩ is)) = case (is-noop i) of λ where (inj₂ _) → instr (↓ i) ▹⟨ σ ⟩ noooop is (inj₁ (emp refl)) → coe (∙-id⁻ˡ σ) (noooop is) -- (2) is labeled noooop (cons (li@(labeled (l ∙⟨ σ₀ ⟩ ↓ i)) ∙⟨ σ ⟩ is)) = case (is-noop i) of λ where (inj₂ _) → cons (li ∙⟨ σ ⟩ noooop is) (inj₁ (emp refl)) → label-start noop l ⟨ coe {{∙-respects-≈ˡ}} (≈-sym (∙-id⁻ʳ σ₀)) σ ⟩ (noooop is)
32.488372
102
0.65927
dc54c91703a45619458b6d753e635bfc3c440ee1
10,751
agda
Agda
Cubical/Algebra/Group/Coset.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Algebra/Group/Coset.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Algebra/Group/Coset.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe #-} open import Cubical.Core.Everything open import Cubical.Algebra.Group module Cubical.Algebra.Group.Coset {ℓ} (G : Group ℓ) where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Function using (id; _∘_; flip) open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.HLevels open import Cubical.Functions.Embedding open import Cubical.Algebra.Group.Subgroup open import Cubical.Relation.Unary open import Cubical.Relation.Unary.Properties open import Cubical.Relation.Binary using (Reflexive; Symmetric; Transitive) open import Cubical.HITs.PropositionalTruncation open import Cubical.Relation.Binary.Reasoning.Equality open Group G open GroupLemmas G private variable ℓ′ : Level _≅[_]ˡ_ : ⟨ G ⟩ → Subgroup G ℓ′ → ⟨ G ⟩ → hProp _ x ≅[ H ]ˡ y = Subgroup.Member H (x ⁻¹ • y) module _ (H : Subgroup G ℓ′) where private module H = Subgroup H ≅ˡ-reflexive : Reflexive _≅[ H ]ˡ_ ≅ˡ-reflexive = subst⁻ (_∈ H.Member) (inverseˡ _) H.preservesId ≅ˡ-symmetric : Symmetric _≅[ H ]ˡ_ ≅ˡ-symmetric {x} {y} = subst (_∈ H.Member) (invDistr (x ⁻¹) y ∙ cong (y ⁻¹ •_) (invInvo x)) ∘ H.preservesInv ≅ˡ-transitive : Transitive _≅[ H ]ˡ_ ≅ˡ-transitive {i} {j} {k} x y = subst (_∈ H.Member) eq (H.preservesOp x y) where eq : _ eq = (i ⁻¹ • j) • (j ⁻¹ • k) ≡˘⟨ assoc _ _ _ ⟩ ((i ⁻¹ • j) • j ⁻¹) • k ≡⟨ cong (_• k) (assoc _ _ _) ⟩ (i ⁻¹ • (j • j ⁻¹)) • k ≡⟨ cong (λ v → (i ⁻¹ • v) • k) (inverseʳ j) ⟩ (i ⁻¹ • ε) • k ≡⟨ cong (_• k) (identityʳ (i ⁻¹)) ⟩ i ⁻¹ • k ∎ infix 9 _<•_ infixr 9 _<•′_ _<•′_ : ⟨ G ⟩ → Pred ⟨ G ⟩ ℓ′ → Pred ⟨ G ⟩ _ g <•′ H = (g •_) ⊣ H _<•_ : ⟨ G ⟩ → Subgroup G ℓ′ → Pred ⟨ G ⟩ _ g <• H = g <•′ Subgroup.Member H module _ (H : Pred ⟨ G ⟩ ℓ′) where cosetˡ-identity→ : ε <•′ H ⊆ H cosetˡ-identity→ = rec (isProp[ H ] _) λ ((h , subh) , εh≡x) → subst (_∈ H) (sym (identityˡ h) ∙ εh≡x) subh cosetˡ-identity← : H ⊆ ε <•′ H cosetˡ-identity← x∈H = ∣ (_ , x∈H) , identityˡ _ ∣ cosetˡ-identity : ε <•′ H ⇔ H cosetˡ-identity = cosetˡ-identity→ , cosetˡ-identity← cosetˡ-assoc→ : ∀ a b → (a • b) <•′ H ⊆ a <•′ b <•′ H cosetˡ-assoc→ a b = map λ ((h , subh) , abh≡x) → (b • h , ∣ (h , subh) , refl ∣) , sym (assoc _ _ _) ∙ abh≡x cosetˡ-assoc← : ∀ a b → a <•′ b <•′ H ⊆ (a • b) <•′ H cosetˡ-assoc← a b {x} = rec squash λ ((h , subh) , ah≡x) → map (λ ((g , subg) , bg≡h) → (g , subg) , ( a • b • g ≡⟨ assoc a b g ⟩ a • (b • g) ≡⟨ cong (a •_) bg≡h ⟩ a • h ≡⟨ ah≡x ⟩ x ∎ )) subh cosetˡ-assoc : ∀ a b → (a • b) <•′ H ≡ a <•′ b <•′ H cosetˡ-assoc a b = ⇔toPath _ _ (cosetˡ-assoc→ a b , cosetˡ-assoc← a b) module _ (H : Subgroup G ℓ′) where private module H = Subgroup H g∈gH : ∀ g → g ∈ g <• H g∈gH g = ∣ H.ε , identityʳ _ ∣ ≅-cosetˡ→ : ∀ x y → ⟨ x ≅[ H ]ˡ y ⟩ → x <• H ⇔ y <• H ≅-cosetˡ→ x y x≅y = xH⊆yH , xH⊇yH where xH⊆yH : x <• H ⊆ y <• H xH⊆yH {a} = map λ ((h , subh) , xh≡a) → (y ⁻¹ • x • h , H.preservesOp (≅ˡ-symmetric H x≅y) subh) , ( y • (y ⁻¹ • x • h) ≡˘⟨ assoc y (y ⁻¹ • x) h ⟩ y • (y ⁻¹ • x) • h ≡˘⟨ cong (_• h) (assoc y (y ⁻¹) x) ⟩ y • y ⁻¹ • x • h ≡⟨ cong (λ v → v • x • h) (inverseʳ y) ⟩ ε • x • h ≡⟨ cong (_• h) (identityˡ x) ⟩ x • h ≡⟨ xh≡a ⟩ a ∎) xH⊇yH : x <• H ⊇ y <• H xH⊇yH {a} = map λ ((h , subh) , yh≡a) → (x ⁻¹ • y • h , H.preservesOp x≅y subh) , ( x • (x ⁻¹ • y • h) ≡˘⟨ assoc x (x ⁻¹ • y) h ⟩ x • (x ⁻¹ • y) • h ≡˘⟨ cong (_• h) (assoc x (x ⁻¹) y) ⟩ x • x ⁻¹ • y • h ≡⟨ cong (λ v → v • y • h) (inverseʳ x) ⟩ ε • y • h ≡⟨ cong (_• h) (identityˡ y) ⟩ y • h ≡⟨ yh≡a ⟩ a ∎) ≅-cosetˡ← : ∀ x y → x <• H ⇔ y <• H → ⟨ x ≅[ H ]ˡ y ⟩ ≅-cosetˡ← x y (xH⊆yH , yH⊆xH) = rec ((_ ≅[ H ]ˡ _) .snd) (λ ((h , subh) , yh≡x) → subst (_∈ H.Member) (cong _⁻¹ ( h ≡˘⟨ identityˡ h ⟩ ε • h ≡˘⟨ cong (_• h) (inverseˡ y) ⟩ y ⁻¹ • y • h ≡⟨ assoc _ _ _ ⟩ y ⁻¹ • (y • h) ≡⟨ cong (y ⁻¹ •_) yh≡x ⟩ y ⁻¹ • x ∎ ) ∙ invDistr (y ⁻¹) x ∙ cong (x ⁻¹ •_) (invInvo y)) (H.preservesInv subh) ) (xH⊆yH {x} (g∈gH x)) ≅-cosetˡ : ∀ x y → ⟨ x ≅[ H ]ˡ y ⟩ ≃ (x <• H ⇔ y <• H) ≅-cosetˡ x y = isPropEquiv→Equiv ((x ≅[ H ]ˡ y) .snd) (isProp⇔ (x <• H) (y <• H)) (≅-cosetˡ→ x y) (≅-cosetˡ← x y) cosetˡ-idem→ : ((h , _) : ⟨ H ⟩) → h <• H ⊆ H.Member cosetˡ-idem→ (h , subh) = rec (isProp[ H.Member ] _) λ ((g , subg) , hg≡x) → subst (_∈ H.Member) hg≡x (H.preservesOp subh subg) cosetˡ-idem← : ((h , _) : ⟨ H ⟩) → H.Member ⊆ h <• H cosetˡ-idem← (h , subh) {x} subx = ∣ (h ⁻¹ • x , H.preservesOp (H.preservesInv subh) subx) , ( h • (h ⁻¹ • x) ≡˘⟨ assoc h (h ⁻¹) x ⟩ (h • h ⁻¹) • x ≡⟨ cong (_• x) (inverseʳ h) ⟩ ε • x ≡⟨ identityˡ x ⟩ x ∎) ∣ cosetˡ-idem : ((h , _) : ⟨ H ⟩) → h <• H ⇔ H.Member cosetˡ-idem h = cosetˡ-idem→ h , cosetˡ-idem← h _≅[_]ʳ_ : ⟨ G ⟩ → Subgroup G ℓ′ → ⟨ G ⟩ → hProp _ x ≅[ H ]ʳ y = Subgroup.Member H (x • y ⁻¹) module _ (H : Subgroup G ℓ′) where private module H = Subgroup H ≅ʳ-reflexive : Reflexive _≅[ H ]ʳ_ ≅ʳ-reflexive = subst⁻ (_∈ H.Member) (inverseʳ _) H.preservesId ≅ʳ-symmetric : Symmetric _≅[ H ]ʳ_ ≅ʳ-symmetric {x} {y} = subst (_∈ H.Member) (invDistr x (y ⁻¹) ∙ cong (_• x ⁻¹) (invInvo y)) ∘ H.preservesInv ≅ʳ-transitive : Transitive _≅[ H ]ʳ_ ≅ʳ-transitive {i} {j} {k} x y = subst (_∈ H.Member) eq (H.preservesOp x y) where eq : _ eq = (i • j ⁻¹) • (j • k ⁻¹) ≡˘⟨ assoc _ _ _ ⟩ ((i • j ⁻¹) • j) • k ⁻¹ ≡⟨ cong (_• k ⁻¹) (assoc _ _ _) ⟩ (i • (j ⁻¹ • j)) • k ⁻¹ ≡⟨ cong (λ v → (i • v) • k ⁻¹) (inverseˡ j) ⟩ (i • ε) • k ⁻¹ ≡⟨ cong (_• k ⁻¹) (identityʳ i) ⟩ i • k ⁻¹ ∎ infix 9 _•>_ infixl 9 _•>′_ _•>′_ : Pred ⟨ G ⟩ ℓ′ → ⟨ G ⟩ → Pred ⟨ G ⟩ _ H •>′ g = (_• g) ⊣ H _•>_ : Subgroup G ℓ′ → ⟨ G ⟩ → Pred ⟨ G ⟩ _ H •> g = Subgroup.Member H •>′ g module _ (H : Pred ⟨ G ⟩ ℓ′) where cosetʳ-identity→ : H •>′ ε ⊆ H cosetʳ-identity→ = rec (isProp[ H ] _) λ ((h , subh) , hε≡x) → subst (_∈ H) (sym (identityʳ h) ∙ hε≡x) subh cosetʳ-identity← : H ⊆ H •>′ ε cosetʳ-identity← x∈H = ∣ (_ , x∈H) , identityʳ _ ∣ cosetʳ-identity : H •>′ ε ⇔ H cosetʳ-identity = cosetʳ-identity→ , cosetʳ-identity← cosetʳ-assoc→ : ∀ a b → H •>′ (a • b) ⊆ H •>′ a •>′ b cosetʳ-assoc→ a b = map λ ((h , subh) , hab≡x) → (h • a , ∣ (h , subh) , refl ∣) , assoc _ _ _ ∙ hab≡x cosetʳ-assoc← : ∀ a b → H •>′ a •>′ b ⊆ H •>′ (a • b) cosetʳ-assoc← a b {x} = rec squash λ ((h , subh) , hb≡x) → map (λ ((g , subg) , ga≡h) → (g , subg) , ( g • (a • b) ≡˘⟨ assoc g a b ⟩ (g • a) • b ≡⟨ cong (_• b) ga≡h ⟩ h • b ≡⟨ hb≡x ⟩ x ∎ )) subh cosetʳ-assoc : ∀ a b → H •>′ (a • b) ≡ H •>′ a •>′ b cosetʳ-assoc a b = ⇔toPath _ _ (cosetʳ-assoc→ a b , cosetʳ-assoc← a b) module _ (H : Subgroup G ℓ′) where private module H = Subgroup H g∈Hg : ∀ g → g ∈ H •> g g∈Hg g = ∣ H.ε , identityˡ _ ∣ ≅-cosetʳ→ : ∀ x y → ⟨ x ≅[ H ]ʳ y ⟩ → H •> x ⇔ H •> y ≅-cosetʳ→ x y x≅y = Hx⊆Hy , Hx⊇Hy where Hx⊆Hy : H •> x ⊆ H •> y Hx⊆Hy {a} = map λ ((h , subh) , hx≡a) → (h • (x • y ⁻¹) , H.preservesOp subh x≅y) , ( h • (x • y ⁻¹) • y ≡˘⟨ cong (_• y) (assoc h x (y ⁻¹)) ⟩ h • x • y ⁻¹ • y ≡⟨ assoc (h • x) (y ⁻¹) y ⟩ (h • x) • (y ⁻¹ • y) ≡⟨ cong (h • x •_) (inverseˡ y) ⟩ h • x • ε ≡⟨ identityʳ (h • x) ⟩ h • x ≡⟨ hx≡a ⟩ a ∎) Hx⊇Hy : H •> x ⊇ H •> y Hx⊇Hy {a} = map λ ((h , subh) , hy≡a) → (h • (y • x ⁻¹) , H.preservesOp subh (≅ʳ-symmetric H x≅y)) , ( h • (y • x ⁻¹) • x ≡˘⟨ cong (_• x) (assoc h y (x ⁻¹)) ⟩ h • y • x ⁻¹ • x ≡⟨ assoc (h • y) (x ⁻¹) x ⟩ (h • y) • (x ⁻¹ • x) ≡⟨ cong (h • y •_) (inverseˡ x) ⟩ h • y • ε ≡⟨ identityʳ (h • y) ⟩ h • y ≡⟨ hy≡a ⟩ a ∎) ≅-cosetʳ← : ∀ x y → H •> x ⇔ H •> y → ⟨ x ≅[ H ]ʳ y ⟩ ≅-cosetʳ← x y (Hx⊆Hy , Hy⊆Hx) = rec ((_ ≅[ H ]ʳ _) .snd) (λ ((h , subh) , hy≡x) → subst (_∈ H.Member) ( h ≡˘⟨ identityʳ h ⟩ h • ε ≡˘⟨ cong (h •_) (inverseʳ y) ⟩ h • (y • y ⁻¹) ≡˘⟨ assoc h y (y ⁻¹) ⟩ (h • y) • y ⁻¹ ≡⟨ cong (_• y ⁻¹) hy≡x ⟩ x • y ⁻¹ ∎ ) subh ) (Hx⊆Hy {x} (g∈Hg x)) ≅-cosetʳ : ∀ x y → ⟨ x ≅[ H ]ʳ y ⟩ ≃ (H •> x ⇔ H •> y) ≅-cosetʳ x y = isPropEquiv→Equiv ((x ≅[ H ]ʳ y) .snd) (isProp⇔ (H •> x) (H •> y)) (≅-cosetʳ→ x y) (≅-cosetʳ← x y) cosetʳ-idem→ : ((h , _) : ⟨ H ⟩) → H •> h ⊆ H.Member cosetʳ-idem→ (h , subh) = rec (isProp[ H.Member ] _) λ ((g , subg) , gh≡x) → subst (_∈ H.Member) gh≡x (H.preservesOp subg subh) cosetʳ-idem← : ((h , _) : ⟨ H ⟩) → H.Member ⊆ H •> h cosetʳ-idem← (h , subh) {x} subx = ∣ (x • h ⁻¹ , H.preservesOp subx (H.preservesInv subh)) , ( (x • h ⁻¹) • h ≡⟨ assoc x (h ⁻¹) h ⟩ x • (h ⁻¹ • h) ≡⟨ cong (x •_) (inverseˡ h) ⟩ x • ε ≡⟨ identityʳ x ⟩ x ∎) ∣ cosetʳ-idem : ((h , _) : ⟨ H ⟩) → H •> h ⇔ H.Member cosetʳ-idem h = cosetʳ-idem→ h , cosetʳ-idem← h
36.444068
110
0.396986
22af0cbd64cb6d3008b5502ec90f7456040d3afd
51,687
agda
Agda
src/LibraBFT/ImplShared/Consensus/Types/EpochIndep.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
src/LibraBFT/ImplShared/Consensus/Types/EpochIndep.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
src/LibraBFT/ImplShared/Consensus/Types/EpochIndep.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2020, 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import LibraBFT.Base.Types open import LibraBFT.Impl.OBM.Rust.Duration open import LibraBFT.Impl.OBM.Rust.RustTypes open import LibraBFT.ImplShared.Base.Types open import Optics.All open import Util.ByteString open import Util.Encode open import Util.Hash open import Util.KVMap as Map open import Util.PKCS open import Util.Prelude ------------------------------------------------------------------------------ open import Data.String using (String) -- Defines the types that /DO NOT/ depend on an epoch config. -- TODO-3: update types to reflect more recent version of LibraBFT. This is -- a substantial undertaking that should probably be led by someone who can -- access our internal implementation. module LibraBFT.ImplShared.Consensus.Types.EpochIndep where -- Below here is incremental progress towards something -- that will eventually mirror the types in LBFT.Consensus.Types -- that /DO NOT/ depend on the set of active authors -- or safety rules, which we call the /EpochConfig/. Author : Set Author = NodeId AccountAddress : Set AccountAddress = Author AuthorName : Set AuthorName = Author aAuthorName : Lens Author AuthorName aAuthorName = mkLens' (λ x → x) (λ x → const x) HashValue : Set HashValue = Hash TX : Set TX = ByteString Instant : Set Instant = ℕ -- TODO-2: should eventually be a time stamp postulate -- TODO-1: implement/prove PK equality _≟-PK_ : (pk1 pk2 : PK) → Dec (pk1 ≡ pk2) instance Eq-PK : Eq PK Eq._≟_ Eq-PK = _≟-PK_ -- LBFT-OBM-DIFF: We do not have world state. We just count the Epoch/Round as the version. record Version : Set where constructor Version∙new field _vVE : Epoch _vVR : Round open Version public postulate instance enc-Version : Encoder Version postulate -- TODO-1: implement/prove Version equality _≟-Version_ : (v1 v2 : Version) → Dec (v1 ≡ v2) instance Eq-Version : Eq Version Eq._≟_ Eq-Version = _≟-Version_ _≤-Version_ : Version → Version → Set v1 ≤-Version v2 = _vVE v1 < _vVE v2 ⊎ _vVE v1 ≡ _vVE v2 × _vVR v1 ≤ _vVR v2 _≤?-Version_ : (v1 v2 : Version) → Dec (v1 ≤-Version v2) v1 ≤?-Version v2 with _vVE v1 <? _vVE v2 ...| yes prf = yes (inj₁ prf) ...| no ege with _vVE v1 ≟ _vVE v2 ...| no rneq = no (⊥-elim ∘ λ { (inj₁ x) → ege x ; (inj₂ (x , _)) → rneq x }) ...| yes refl with _vVR v1 ≤? _vVR v2 ...| yes rleq = yes (inj₂ (refl , rleq)) ...| no rgt = no (⊥-elim ∘ λ { (inj₁ x) → ege x ; (inj₂ (_ , x)) → rgt x }) _<-Version_ : Version → Version → Set v1 <-Version v2 = _vVE v1 < _vVE v2 ⊎ _vVE v1 ≡ _vVE v2 × _vVR v1 < _vVR v2 _<?-Version_ : (v1 v2 : Version) → Dec (v1 <-Version v2) v1 <?-Version v2 with _vVE v1 <? _vVE v2 ...| yes prf = yes (inj₁ prf) ...| no ege with _vVE v1 ≟ _vVE v2 ...| no rneq = no (⊥-elim ∘ λ { (inj₁ x) → ege x ; (inj₂ (x , _)) → rneq x }) ...| yes refl with _vVR v1 <? _vVR v2 ...| yes rleq = yes (inj₂ (refl , rleq)) ...| no rgt = no (⊥-elim ∘ λ { (inj₁ x) → ege x ; (inj₂ (_ , x)) → rgt x }) -- ------------------------------------------------------------------------------ record ValidatorSigner : Set where constructor ValidatorSigner∙new field _vsAuthor : AccountAddress _vsPrivateKey : SK -- Note that the SystemModel doesn't -- allow one node to examine another's -- state, so we don't model someone being -- able to impersonate someone else unless -- PK is "dishonest", which models the -- possibility that the corresponding secret -- key may have been leaked. open ValidatorSigner public unquoteDecl vsAuthor vsPrivateKey = mkLens (quote ValidatorSigner) (vsAuthor ∷ vsPrivateKey ∷ []) RawEncNetworkAddress = Author record ValidatorConfig : Set where constructor ValidatorConfig∙new field _vcConsensusPublicKey : PK _vcValidatorNetworkAddress : RawEncNetworkAddress open ValidatorConfig public unquoteDecl vcConsensusPublicKey vcValidatorNetworkAddress = mkLens (quote ValidatorConfig) (vcConsensusPublicKey ∷ vcValidatorNetworkAddress ∷ []) record ValidatorInfo : Set where constructor ValidatorInfo∙new field _viAccountAddress : AccountAddress _viConsensusVotingPower : U64 _viConfig : ValidatorConfig open ValidatorInfo public unquoteDecl viAccountAddress viConsensusVotingPower viConfig = mkLens (quote ValidatorInfo) (viAccountAddress ∷ viConsensusVotingPower ∷ viConfig ∷ []) -- getter only in Haskell -- key for validating signed messages from this validator viConsensusPublicKey : Lens ValidatorInfo PK viConsensusPublicKey = viConfig ∙ vcConsensusPublicKey record ValidatorConsensusInfo : Set where constructor ValidatorConsensusInfo∙new field _vciPublicKey : PK _vciVotingPower : U64 open ValidatorConsensusInfo public unquoteDecl vciPublicKey vciVotingPower = mkLens (quote ValidatorConsensusInfo) (vciPublicKey ∷ vciVotingPower ∷ []) record ValidatorVerifier : Set where constructor mkValidatorVerifier field _vvAddressToValidatorInfo : KVMap AccountAddress ValidatorConsensusInfo _vvQuorumVotingPower : ℕ -- TODO-2: see above; for now, this is QuorumSize _vvTotalVotingPower : ℕ -- TODO-2: see above; for now, this is number of peers in EpochConfig open ValidatorVerifier public unquoteDecl vvAddressToValidatorInfo vvQuorumVotingPower vvTotalVotingPower = mkLens (quote ValidatorVerifier) (vvAddressToValidatorInfo ∷ vvQuorumVotingPower ∷ vvTotalVotingPower ∷ []) -- getter only in Haskell vvObmAuthors : Lens ValidatorVerifier (List AccountAddress) vvObmAuthors = mkLens' g s where g : ValidatorVerifier → List AccountAddress g vv = Map.kvm-keys (vv ^∙ vvAddressToValidatorInfo) s : ValidatorVerifier → List AccountAddress → ValidatorVerifier s vv _ = vv -- TODO-1 : cannot be done: need a way to defined only getters data ConsensusScheme : Set where ConsensusScheme∙new : ConsensusScheme -- instance S.Serialize ConsensusScheme record ValidatorSet : Set where constructor ValidatorSet∙new field _vsScheme : ConsensusScheme _vsPayload : List ValidatorInfo -- instance S.Serialize ValidatorSet open ValidatorSet public unquoteDecl vsScheme vsPayload = mkLens (quote ValidatorSet) (vsScheme ∷ vsPayload ∷ []) record EpochState : Set where constructor EpochState∙new field _esEpoch : Epoch _esVerifier : ValidatorVerifier open EpochState public unquoteDecl esEpoch esVerifier = mkLens (quote EpochState) (esEpoch ∷ esVerifier ∷ []) postulate -- one valid assumption, one that can be proved using it instance Enc-EpochState : Encoder EpochState Enc-EpochStateMB : Encoder (Maybe EpochState) -- TODO-1: make combinator to build this -- ------------------------------------------------------------------------------ record BlockInfo : Set where constructor BlockInfo∙new field _biEpoch : Epoch _biRound : Round _biId : HashValue _biExecutedStateId : HashValue -- aka liTransactionAccumulatorHash _biVersion : Version --, _biTimestamp :: Instant _biNextEpochState : Maybe EpochState open BlockInfo public unquoteDecl biEpoch biRound biId biExecutedStateId biVersion biNextEpochState = mkLens (quote BlockInfo) (biEpoch ∷ biRound ∷ biId ∷ biExecutedStateId ∷ biVersion ∷ biNextEpochState ∷ []) postulate instance enc-BlockInfo : Encoder BlockInfo postulate _≟-BlockInfo_ : (bi1 bi2 : BlockInfo) → Dec (bi1 ≡ bi2) instance Eq-BlockInfo : Eq BlockInfo Eq._≟_ Eq-BlockInfo = _≟-BlockInfo_ BlockInfo-η : ∀{e1 e2 r1 r2 i1 i2 x1 x2 v1 v2 n1 n2} → e1 ≡ e2 → r1 ≡ r2 → i1 ≡ i2 → x1 ≡ x2 → v1 ≡ v2 → n1 ≡ n2 → BlockInfo∙new e1 r1 i1 x1 v1 n1 ≡ BlockInfo∙new e2 r2 i2 x2 v2 n2 BlockInfo-η refl refl refl refl refl refl = refl instance Eq-ByteString : Eq ByteString Eq._≟_ Eq-ByteString = _≟ByteString_ {- _≟BlockInfo_ : (b₁ b₂ : BlockInfo) → Dec (b₁ ≡ b₂) l ≟BlockInfo r with ((l ^∙ biEpoch) ≟ (r ^∙ biEpoch)) ...| no no-e = no λ where refl → no-e refl ...| yes refl with ((l ^∙ biRound) ≟ (r ^∙ biRound)) ...| no no-r = no λ where refl → no-r refl ...| yes refl with ((l ^∙ biId) ≟ (r ^∙ biId)) ...| no no-i = no λ where refl → no-i refl ...| yes refl = yes refl instance Eq-BlockInfo : Eq BlockInfo Eq._≟_ Eq-BlockInfo = _≟BlockInfo_ BlockInfo-η : ∀{e1 e2 r1 r2 i1 i2} → e1 ≡ e2 → r1 ≡ r2 → i1 ≡ i2 → BlockInfo∙new e1 r1 i1 ≡ BlockInfo∙new e2 r2 i2 BlockInfo-η refl refl refl = refl -} biNextBlockEpoch : Lens BlockInfo Epoch biNextBlockEpoch = mkLens' g s where g : BlockInfo → Epoch g bi = maybeS (bi ^∙ biNextEpochState) (bi ^∙ biEpoch) ( _^∙ esEpoch) s : BlockInfo → Epoch → BlockInfo s bi _ = bi -- TODO-1 : cannot be done: need a way to defined only getters -- ------------------------------------------------------------------------------ record LedgerInfo : Set where constructor LedgerInfo∙new field _liCommitInfo : BlockInfo _liConsensusDataHash : HashValue open LedgerInfo public unquoteDecl liCommitInfo liConsensusDataHash = mkLens (quote LedgerInfo) (liCommitInfo ∷ liConsensusDataHash ∷ []) postulate instance enc-LedgerInfo : Encoder LedgerInfo postulate instance ws-LedgerInfo : WithSig LedgerInfo -- GETTER only in Haskell liEpoch : Lens LedgerInfo Epoch liEpoch = liCommitInfo ∙ biEpoch -- GETTER only in Haskell liNextBlockEpoch : Lens LedgerInfo Epoch liNextBlockEpoch = liCommitInfo ∙ biNextBlockEpoch -- GETTER only in Haskell liConsensusBlockId : Lens LedgerInfo HashValue liConsensusBlockId = liCommitInfo ∙ biId -- GETTER only in Haskell liTransactionAccumulatorHash : Lens LedgerInfo HashValue liTransactionAccumulatorHash = liCommitInfo ∙ biExecutedStateId -- GETTER only in Haskell liVersion : Lens LedgerInfo Version liVersion = liCommitInfo ∙ biVersion -- GETTER only in Haskell liNextEpochState : Lens LedgerInfo (Maybe EpochState) liNextEpochState = mkLens' g s where g : LedgerInfo → Maybe EpochState g = (_^∙ liCommitInfo ∙ biNextEpochState) s : LedgerInfo → Maybe EpochState → LedgerInfo s l _ = l -- TODO-1 : cannot be done: need a way to defined only getters -- GETTER only in Haskell liEndsEpoch : Lens LedgerInfo Bool liEndsEpoch = mkLens' g s where g : LedgerInfo → Bool g = is-just ∘ (_^∙ liNextEpochState) s : LedgerInfo → Bool → LedgerInfo s l _ = l -- TODO-1 : cannot be done: need a way to defined only getters LedgerInfo-η : ∀ {ci1 ci2 : BlockInfo} {cdh1 cdh2 : Hash} → ci1 ≡ ci2 → cdh1 ≡ cdh2 → (LedgerInfo∙new ci1 cdh1) ≡ (LedgerInfo∙new ci2 cdh2) LedgerInfo-η refl refl = refl record LedgerInfoWithSignatures : Set where constructor LedgerInfoWithSignatures∙new field _liwsLedgerInfo : LedgerInfo _liwsSignatures : KVMap Author Signature open LedgerInfoWithSignatures public unquoteDecl liwsLedgerInfo liwsSignatures = mkLens (quote LedgerInfoWithSignatures) (liwsLedgerInfo ∷ liwsSignatures ∷ []) postulate instance enc-LedgerInfoWithSignatures : Encoder LedgerInfoWithSignatures -- GETTER only in Haskell liwsEpoch : Lens LedgerInfoWithSignatures Epoch liwsEpoch = liwsLedgerInfo ∙ liEpoch -- GETTER only in Haskell liwsVersion : Lens LedgerInfoWithSignatures Version liwsVersion = liwsLedgerInfo ∙ liVersion -- GETTER only in Haskell liwsNextEpochState : Lens LedgerInfoWithSignatures (Maybe EpochState) liwsNextEpochState = liwsLedgerInfo ∙ liNextEpochState -- ------------------------------------------------------------------------------ record Timeout : Set where constructor Timeout∙new field _toEpoch : Epoch _toRound : Round open Timeout public unquoteDecl toEpoch toRound = mkLens (quote Timeout) (toEpoch ∷ toRound ∷ []) postulate instance enc-Timeout : Encoder Timeout -- ------------------------------------------------------------------------------ record VoteData : Set where constructor VoteData∙new field _vdProposed : BlockInfo _vdParent : BlockInfo open VoteData public unquoteDecl vdProposed vdParent = mkLens (quote VoteData) (vdProposed ∷ vdParent ∷ []) postulate instance enc-VoteData : Encoder VoteData VoteData-η : ∀ {pr1 par1 pr2 par2 : BlockInfo} → pr1 ≡ pr2 → par1 ≡ par2 → (VoteData∙new pr1 par1) ≡ (VoteData∙new pr2 par2) VoteData-η refl refl = refl -- DESIGN NOTE: The _vAuthor field is included only to facilitate lookup of the public key against -- which to verify the signature. An alternative would be to use an index into the members of the -- epoch config, which would save message space and therefore bandwidth. record Vote : Set where constructor Vote∙new field _vVoteData : VoteData _vAuthor : Author _vLedgerInfo : LedgerInfo _vSignature : Signature _vTimeoutSignature : Maybe Signature open Vote public unquoteDecl vVoteData vAuthor vLedgerInfo vSignature vTimeoutSignature = mkLens (quote Vote) (vVoteData ∷ vAuthor ∷ vLedgerInfo ∷ vSignature ∷ vTimeoutSignature ∷ []) postulate instance enc-Vote : Encoder Vote -- not defined in Haskell vParent : Lens Vote BlockInfo vParent = vVoteData ∙ vdParent -- not defined in Haskell vProposed : Lens Vote BlockInfo vProposed = vVoteData ∙ vdProposed -- not defined in Haskell vParentId : Lens Vote Hash vParentId = vVoteData ∙ vdParent ∙ biId -- not defined in Haskell vParentRound : Lens Vote Round vParentRound = vVoteData ∙ vdParent ∙ biRound -- not defined in Haskell vProposedId : Lens Vote Hash vProposedId = vVoteData ∙ vdProposed ∙ biId -- getter only in Haskell vEpoch : Lens Vote Epoch vEpoch = vVoteData ∙ vdProposed ∙ biEpoch -- getter only in Haskell vRound : Lens Vote Round vRound = vVoteData ∙ vdProposed ∙ biRound -- ------------------------------------------------------------------------------ record QuorumCert : Set where constructor QuorumCert∙new field _qcVoteData : VoteData _qcSignedLedgerInfo : LedgerInfoWithSignatures open QuorumCert public unquoteDecl qcVoteData qcSignedLedgerInfo = mkLens (quote QuorumCert) (qcVoteData ∷ qcSignedLedgerInfo ∷ []) postulate instance enc-QuorumCert : Encoder QuorumCert -- Because QuorumCert has an injective encoding (postulated, for now), -- we can use it to determine equality of QuorumCerts. _≟QC_ : (q1 q2 : QuorumCert) → Dec (q1 ≡ q2) _≟QC_ = ≡-Encoder enc-QuorumCert _QCBoolEq_ : QuorumCert → QuorumCert → Bool _QCBoolEq_ q1 q2 = does (q1 ≟QC q2) -- getter only in Haskell qcCertifiedBlock : Lens QuorumCert BlockInfo qcCertifiedBlock = qcVoteData ∙ vdProposed -- getter only in Haskell qcParentBlock : Lens QuorumCert BlockInfo qcParentBlock = qcVoteData ∙ vdParent -- getter only in Haskell qcLedgerInfo : Lens QuorumCert LedgerInfoWithSignatures qcLedgerInfo = qcSignedLedgerInfo -- getter only in Haskell qcCommitInfo : Lens QuorumCert BlockInfo qcCommitInfo = qcSignedLedgerInfo ∙ liwsLedgerInfo ∙ liCommitInfo -- getter only in Haskell qcEndsEpoch : Lens QuorumCert Bool qcEndsEpoch = mkLens' g s where g : QuorumCert → Bool g q = is-just (q ^∙ qcSignedLedgerInfo ∙ liwsLedgerInfo ∙ liNextEpochState) s : QuorumCert → Bool → QuorumCert s q _ = q -- TODO-1 : cannot be done: need a way to defined only getters -- Constructs a 'vote' that was gathered in a QC. rebuildVote : QuorumCert → Author × Signature → Vote rebuildVote qc (α , sig) = record { _vVoteData = _qcVoteData qc ; _vAuthor = α ; _vLedgerInfo = qc ^∙ (qcSignedLedgerInfo ∙ liwsLedgerInfo) ; _vSignature = sig ; _vTimeoutSignature = nothing -- Is this correct? The original vote may have had a -- timeout signature, but we don't know. Does it -- matter? } -- Two votes are equivalent if they are identical except they may differ on timeout signature _≈Vote_ : (v1 v2 : Vote) → Set v1 ≈Vote v2 = v2 ≡ record v1 { _vTimeoutSignature = _vTimeoutSignature v2 } qcVotesKV : QuorumCert → KVMap Author Signature qcVotesKV = _liwsSignatures ∘ _qcSignedLedgerInfo qcVotes : QuorumCert → List (Author × Signature) qcVotes qc = kvm-toList (qcVotesKV qc) -- not defined in Haskell qcCertifies : Lens QuorumCert Hash qcCertifies = qcVoteData ∙ vdProposed ∙ biId -- not defined in Haskell qcRound : Lens QuorumCert Round qcRound = qcVoteData ∙ vdProposed ∙ biRound _qcCertifies : QuorumCert → Hash _qcCertifies q = q ^∙ qcCertifies _qcRound : QuorumCert → Round _qcRound q = q ^∙ qcRound -- ------------------------------------------------------------------------------ record TimeoutCertificate : Set where constructor mkTimeoutCertificate field _tcTimeout : Timeout _tcSignatures : KVMap Author Signature open TimeoutCertificate public unquoteDecl tcTimeout tcSignatures = mkLens (quote TimeoutCertificate) (tcTimeout ∷ tcSignatures ∷ []) TimeoutCertificate∙new : Timeout → TimeoutCertificate TimeoutCertificate∙new to = mkTimeoutCertificate to Map.empty -- getter only in haskell tcEpoch : Lens TimeoutCertificate Epoch tcEpoch = tcTimeout ∙ toEpoch -- getter only in haskell tcRound : Lens TimeoutCertificate Round tcRound = tcTimeout ∙ toRound -- ------------------------------------------------------------------------------ data BlockType : Set where Proposal : TX → Author → BlockType NilBlock : BlockType Genesis : BlockType postulate instance enc-BlockType : Encoder BlockType postulate -- Valid assumption, payloadIsEmpty -- TODO-1 : Need to decide what empty means. -- Only important on epoch change. payloadIsEmpty : TX → Bool _≟BlockType_ : (b₁ b₂ : BlockType) → Dec (b₁ ≡ b₂) Genesis ≟BlockType Genesis = true because ofʸ refl NilBlock ≟BlockType NilBlock = true because ofʸ refl (Proposal t₁ a₁) ≟BlockType (Proposal t₂ a₂) with t₁ ≟ t₂ ...| no no-t = no λ where refl → no-t refl ...| yes refl with a₁ ≟ a₂ ...| no no-a = no λ where refl → no-a refl ...| yes refl = yes refl Genesis ≟BlockType NilBlock = no (λ ()) Genesis ≟BlockType (Proposal _ _) = no (λ ()) NilBlock ≟BlockType Genesis = no (λ ()) NilBlock ≟BlockType (Proposal _ _) = no (λ ()) (Proposal _ _) ≟BlockType Genesis = no (λ ()) (Proposal _ _) ≟BlockType NilBlock = no (λ ()) instance Eq-BlockType : Eq BlockType Eq._≟_ Eq-BlockType = _≟BlockType_ record BlockData : Set where constructor BlockData∙new field _bdEpoch : Epoch _bdRound : Round -- QUESTION: How do we represent a block that extends the -- genesis block, which doesn't come with a QC. Maybe the -- genesis block has an associated QC established for the epoch? _bdQuorumCert : QuorumCert _bdBlockType : BlockType open BlockData public unquoteDecl bdEpoch bdRound bdQuorumCert bdBlockType = mkLens (quote BlockData) (bdEpoch ∷ bdRound ∷ bdQuorumCert ∷ bdBlockType ∷ []) postulate instance enc-BlockData : Encoder BlockData -- not defined in Haskell bdParentId : Lens BlockData Hash bdParentId = bdQuorumCert ∙ qcVoteData ∙ vdParent ∙ biId -- not defined in Haskell -- This is the id of a block bdBlockId : Lens BlockData Hash bdBlockId = bdQuorumCert ∙ qcVoteData ∙ vdProposed ∙ biId -- getter only in Haskell bdAuthor : Lens BlockData (Maybe Author) bdAuthor = mkLens' g s where g : BlockData → Maybe Author g bd = case (bd ^∙ bdBlockType) of λ where (Proposal _ author) → just author _ → nothing s : BlockData → Maybe Author → BlockData s bd nothing = bd s bd (just auth) = bd & bdBlockType %~ λ where (Proposal tx _) → Proposal tx auth bdt → bdt -- getter only in Haskell bdPayload : Lens BlockData (Maybe TX) bdPayload = mkLens' g s where g : BlockData → Maybe TX g bd = case bd ^∙ bdBlockType of λ where (Proposal a _) → just a _ → nothing s : BlockData → Maybe TX → BlockData s bd _ = bd -- TODO-1 : cannot be done: need a way to define only getters -- ------------------------------------------------------------------------------ -- The signature is a Maybe to allow us to use 'nothing' as the -- 'bSignature' when constructing a block to sign later. Also, -- "nil" blocks are not signed because they are produced -- independently by different validators. This is to enable -- committing after an epoch-changing command is processed: we -- cannot add more commands, but we need to add some quorum -- certificates in order to commit the epoch-changing command. record Block : Set where constructor Block∙new field _bId : HashValue _bBlockData : BlockData _bSignature : Maybe Signature open Block public unquoteDecl bId bBlockData bSignature = mkLens (quote Block) (bId ∷ bBlockData ∷ bSignature ∷ []) postulate instance enc : Encoder Block -- getter only in Haskell bAuthor : Lens Block (Maybe Author) bAuthor = bBlockData ∙ bdAuthor -- getter only in Haskell bEpoch : Lens Block Epoch bEpoch = bBlockData ∙ bdEpoch -- getter only in Haskell bRound : Lens Block Round bRound = bBlockData ∙ bdRound -- getter only in Haskell bQuorumCert : Lens Block QuorumCert bQuorumCert = bBlockData ∙ bdQuorumCert -- getter only in Haskell bParentId : Lens Block HashValue bParentId = bQuorumCert ∙ qcCertifiedBlock ∙ biId -- getter only in Haskell bPayload : Lens Block (Maybe TX) bPayload = bBlockData ∙ bdPayload bdQcSigs : Lens Block (KVMap Author Signature) bdQcSigs = bBlockData ∙ bdQuorumCert ∙ qcLedgerInfo ∙ liwsSignatures -- Equivalence of Blocks modulo signatures (both on the Block and in the QuorumCert it contains) infix 4 _≈Block_ _≈Block_ : (b₁ b₂ : Block) → Set b₁ ≈Block b₂ = b₁ ≡ (b₂ & bSignature ∙~ (b₁ ^∙ bSignature) & bdQcSigs ∙~ (b₁ ^∙ bdQcSigs)) sym≈Block : Symmetric _≈Block_ sym≈Block refl = refl -- ------------------------------------------------------------------------------ record AccumulatorExtensionProof : Set where constructor AccumulatorExtensionProof∙new field _aepObmNumLeaves : Version open AccumulatorExtensionProof public unquoteDecl aepObmNumLeaves = mkLens (quote AccumulatorExtensionProof) (aepObmNumLeaves ∷ []) record VoteProposal : Set where constructor VoteProposal∙new field _vpAccumulatorExtensionProof : AccumulatorExtensionProof _vpBlock : Block _vpNextEpochState : Maybe EpochState open VoteProposal public unquoteDecl vpAccumulatorExtensionProof vpBlock vpNextEpochState = mkLens (quote VoteProposal) (vpAccumulatorExtensionProof ∷ vpBlock ∷ vpNextEpochState ∷ []) record MaybeSignedVoteProposal : Set where constructor MaybeSignedVoteProposal∙new field _msvpVoteProposal : VoteProposal open MaybeSignedVoteProposal public unquoteDecl msvpVoteProposal = mkLens (quote MaybeSignedVoteProposal) (msvpVoteProposal ∷ []) -- ------------------------------------------------------------------------------ record LastVoteInfo : Set where constructor LastVoteInfo∙new field _lviLiDigest : HashValue _lviRound : Round _lviIsTimeout : Bool open LastVoteInfo public record PendingVotes : Set where constructor mkPendingVotes field _pvLiDigestToVotes : KVMap HashValue LedgerInfoWithSignatures _pvMaybePartialTC : Maybe TimeoutCertificate _pvAuthorToVote : KVMap Author Vote open PendingVotes public unquoteDecl pvLiDigestToVotes pvMaybePartialTC pvAuthorToVote = mkLens (quote PendingVotes) (pvLiDigestToVotes ∷ pvMaybePartialTC ∷ pvAuthorToVote ∷ []) PendingVotes∙new : PendingVotes PendingVotes∙new = mkPendingVotes Map.empty nothing Map.empty -- ------------------------------------------------------------------------------ record StateComputeResult : Set where constructor StateComputeResult∙new field _scrObmNumLeaves : Version _scrEpochState : Maybe EpochState open StateComputeResult public unquoteDecl scrObmNumLeaves scrEpochState = mkLens (quote StateComputeResult) (scrObmNumLeaves ∷ scrEpochState ∷ []) postulate -- TODO: eliminate after fully implementing executeBlockE stateComputeResult : StateComputeResult record ExecutedBlock : Set where constructor ExecutedBlock∙new field _ebBlock : Block _ebStateComputeResult : StateComputeResult open ExecutedBlock public unquoteDecl ebBlock ebStateComputeResult = mkLens (quote ExecutedBlock) (ebBlock ∷ ebStateComputeResult ∷ []) -- getter only in Haskell ebId : Lens ExecutedBlock HashValue ebId = ebBlock ∙ bId -- getter only in Haskell ebQuorumCert : Lens ExecutedBlock QuorumCert ebQuorumCert = ebBlock ∙ bQuorumCert -- getter only in Haskell ebParentId : Lens ExecutedBlock HashValue ebParentId = ebQuorumCert ∙ qcCertifiedBlock ∙ biId -- getter only in Haskell ebRound : Lens ExecutedBlock Round ebRound = ebBlock ∙ bRound -- ------------------------------------------------------------------------------ record LinkableBlock : Set where constructor LinkableBlock∙new field _lbExecutedBlock : ExecutedBlock -- _lbChildren : Set HashValue open LinkableBlock public unquoteDecl lbExecutedBlock = mkLens (quote LinkableBlock) (lbExecutedBlock ∷ []) -- getter only in Haskell lbId : Lens LinkableBlock HashValue lbId = lbExecutedBlock ∙ ebId -- ------------------------------------------------------------------------------ -- A block tree depends on a epoch config but works regardlesss of which -- EpochConfig we have. record BlockTree : Set where constructor mkBlockTree field _btIdToBlock : KVMap HashValue LinkableBlock _btRootId : HashValue _btHighestCertifiedBlockId : HashValue _btHighestQuorumCert : QuorumCert _btHighestTimeoutCert : Maybe TimeoutCertificate _btHighestCommitCert : QuorumCert _btIdToQuorumCert : KVMap HashValue QuorumCert _btPrunedBlockIds : VecDeque _btMaxPrunedBlocksInMem : ℕ open BlockTree public unquoteDecl btIdToBlock btRootId btHighestCertifiedBlockId btHighestQuorumCert btHighestTimeoutCert btHighestCommitCert btIdToQuorumCert btPrunedBlockIds btMaxPrunedBlocksInMem = mkLens (quote BlockTree) (btIdToBlock ∷ btRootId ∷ btHighestCertifiedBlockId ∷ btHighestQuorumCert ∷ btHighestTimeoutCert ∷ btHighestCommitCert ∷ btIdToQuorumCert ∷ btPrunedBlockIds ∷ btMaxPrunedBlocksInMem ∷ []) btGetLinkableBlock : HashValue → BlockTree → Maybe LinkableBlock btGetLinkableBlock hv bt = Map.lookup hv (bt ^∙ btIdToBlock) btGetBlock : HashValue → BlockTree → Maybe ExecutedBlock btGetBlock hv bt = (_^∙ lbExecutedBlock) <$> btGetLinkableBlock hv bt -- getter only in Haskell btRoot : Lens BlockTree (Maybe ExecutedBlock) btRoot = mkLens' g s where g : BlockTree → Maybe ExecutedBlock g bt = btGetBlock (bt ^∙ btRootId) bt -- TODO-1 : the setter is not needed/defined in Haskell -- Defining it just to make progress, but it can't be defined -- correctly in terms of type correctness (let alone setting a new root!) s : BlockTree → Maybe ExecutedBlock → BlockTree s bt _ = bt -- TODO-1 : cannot be done: need a way to defined only getters -- getter only in haskell btHighestCertifiedBlock : Lens BlockTree (Maybe ExecutedBlock) btHighestCertifiedBlock = mkLens' g s where g : BlockTree → (Maybe ExecutedBlock) g bt = btGetBlock (bt ^∙ btHighestCertifiedBlockId) bt s : BlockTree → (Maybe ExecutedBlock) → BlockTree s bt _ = bt -- TODO-1 : cannot be done: need a way to defined only getters -- ------------------------------------------------------------------------------ record LedgerStore : Set where constructor mkLedgerStore field _lsObmVersionToEpoch : Map.KVMap Version Epoch _lsObmEpochToLIWS : Map.KVMap Epoch LedgerInfoWithSignatures _lsLatestLedgerInfo : Maybe LedgerInfoWithSignatures open LedgerStore public unquoteDecl lsObmVersionToEpoch lsObmEpochToLIWS lsLatestLedgerInfo = mkLens (quote LedgerStore) (lsObmVersionToEpoch ∷ lsObmEpochToLIWS ∷ lsLatestLedgerInfo ∷ []) record DiemDB : Set where constructor DiemDB∙new field _ddbLedgerStore : LedgerStore open DiemDB public unquoteDecl ddbLedgerStore = mkLens (quote DiemDB) (ddbLedgerStore ∷ []) record LedgerRecoveryData : Set where constructor LedgerRecoveryData∙new field _lrdStorageLedger : LedgerInfo record MockSharedStorage : Set where constructor mkMockSharedStorage field -- Safety state _mssBlock : Map.KVMap HashValue Block _mssQc : Map.KVMap HashValue QuorumCert _mssLis : Map.KVMap Version LedgerInfoWithSignatures _mssLastVote : Maybe Vote -- Liveness state _mssHighestTimeoutCertificate : Maybe TimeoutCertificate _mssValidatorSet : ValidatorSet open MockSharedStorage public unquoteDecl mssBlock mssQc mssLis mssLastVote mssHighestTimeoutCertificate mssValidatorSet = mkLens (quote MockSharedStorage) (mssBlock ∷ mssQc ∷ mssLis ∷ mssLastVote ∷ mssHighestTimeoutCertificate ∷ mssValidatorSet ∷ []) record MockStorage : Set where constructor MockStorage∙new field _msSharedStorage : MockSharedStorage _msStorageLedger : LedgerInfo _msObmDiemDB : DiemDB open MockStorage public unquoteDecl msSharedStorage msStorageLedger msObmDiemDB = mkLens (quote MockStorage) (msSharedStorage ∷ msStorageLedger ∷ msObmDiemDB ∷ []) PersistentLivenessStorage = MockStorage -- IMPL-DIFF : This is defined without record fields in Haskell. -- The record fields below are never used. But RootInfo must be a record for pattern matching. record RootInfo : Set where constructor RootInfo∙new field _riBlock : Block _riQC1 : QuorumCert _riQC2 : QuorumCert -- ------------------------------------------------------------------------------ record SafetyData : Set where constructor SafetyData∙new field _sdEpoch : Epoch _sdLastVotedRound : Round _sdPreferredRound : Round _sdLastVote : Maybe Vote open SafetyData public unquoteDecl sdEpoch sdLastVotedRound sdPreferredRound sdLastVote = mkLens (quote SafetyData) (sdEpoch ∷ sdLastVotedRound ∷ sdPreferredRound ∷ sdLastVote ∷ []) record Waypoint : Set where constructor Waypoint∙new field _wVersion : Version _wValue : HashValue open Waypoint public unquoteDecl wVersion wValue = mkLens (quote Waypoint) (wVersion ∷ wValue ∷ []) postulate instance enc-Waypoint : Encoder Waypoint record PersistentSafetyStorage : Set where constructor mkPersistentSafetyStorage field _pssSafetyData : SafetyData _pssAuthor : Author _pssWaypoint : Waypoint _pssObmSK : Maybe SK open PersistentSafetyStorage public unquoteDecl pssSafetyData pssAuthor pssWaypoint pssObmSK = mkLens (quote PersistentSafetyStorage) (pssSafetyData ∷ pssAuthor ∷ pssWaypoint ∷ pssObmSK ∷ []) record OnChainConfigPayload : Set where constructor OnChainConfigPayload∙new field _occpEpoch : Epoch _occpObmValidatorSet : ValidatorSet open OnChainConfigPayload public unquoteDecl occpEpoch occpObmValidatorSet = mkLens (quote OnChainConfigPayload) (occpEpoch ∷ occpObmValidatorSet ∷ []) -- instance S.Serialize OnChainConfigPayload record ReconfigEventEpochChange : Set where constructor ReconfigEventEpochChange∙new field _reecOnChainConfigPayload : OnChainConfigPayload -- instance S.Serialize ReconfigEventEpochChange -- ------------------------------------------------------------------------------ -- IMPL-DIFF : Haskell StateComputer has pluggable functions. -- The Agda version just calls them directly record StateComputer : Set where constructor StateComputer∙new field _scObmVersion : Version open StateComputer public unquoteDecl scObmVersion = mkLens (quote StateComputer) (scObmVersion ∷ []) StateComputerComputeType = StateComputer → Block → HashValue → Either (List String) StateComputeResult StateComputerCommitType = StateComputer → DiemDB → ExecutedBlock → LedgerInfoWithSignatures → Either (List String) (StateComputer × DiemDB × Maybe ReconfigEventEpochChange) StateComputerSyncToType = LedgerInfoWithSignatures → Either (List String) ReconfigEventEpochChange -- ------------------------------------------------------------------------------ record BlockStore : Set where constructor BlockStore∙new field _bsInner : BlockTree _bsStateComputer : StateComputer _bsStorage : PersistentLivenessStorage open BlockStore public unquoteDecl bsInner bsStateComputer bsStorage = mkLens (quote BlockStore) (bsInner ∷ bsStateComputer ∷ bsStorage ∷ []) postulate -- TODO: stateComputer stateComputer : StateComputer -- getter only in Haskell bsRoot : Lens BlockStore (Maybe ExecutedBlock) bsRoot = bsInner ∙ btRoot -- getter only in Haskell bsHighestQuorumCert : Lens BlockStore QuorumCert bsHighestQuorumCert = bsInner ∙ btHighestQuorumCert -- getter only in Haskell bsHighestCommitCert : Lens BlockStore QuorumCert bsHighestCommitCert = bsInner ∙ btHighestCommitCert -- getter only in Haskell bsHighestTimeoutCert : Lens BlockStore (Maybe TimeoutCertificate) bsHighestTimeoutCert = bsInner ∙ btHighestTimeoutCert -- ------------------------------------------------------------------------------ data NewRoundReason : Set where QCReady : NewRoundReason TOReady : NewRoundReason record NewRoundEvent : Set where constructor NewRoundEvent∙new field _nreRound : Round _nreReason : NewRoundReason _nreTimeout : Duration unquoteDecl nreRound nreReason nreTimeout = mkLens (quote NewRoundEvent) (nreRound ∷ nreReason ∷ nreTimeout ∷ []) -- LibraBFT.ImplShared.Consensus.Types contains -- ExponentialTimeInterval, RoundState -- ------------------------------------------------------------------------------ record ProposalGenerator : Set where constructor ProposalGenerator∙new field _pgLastRoundGenerated : Round open ProposalGenerator unquoteDecl pgLastRoundGenerated = mkLens (quote ProposalGenerator) (pgLastRoundGenerated ∷ []) -- ------------------------------------------------------------------------------ data ObmNotValidProposerReason : Set where ProposalDoesNotHaveAnAuthor ProposerForBlockIsNotValidForThisRound NotValidProposer : ObmNotValidProposerReason record ProposerElection : Set where constructor ProposerElection∙new field _peProposers : List Author -- TODO-1 : this should be 'Set Author' -- _peObmLeaderOfRound : LeaderOfRoundFn -- _peObmNodesInOrder : NodesInOrder open ProposerElection -- ------------------------------------------------------------------------------ record SafetyRules : Set where constructor mkSafetyRules field _srPersistentStorage : PersistentSafetyStorage _srExportConsensusKey : Bool _srValidatorSigner : Maybe ValidatorSigner _srEpochState : Maybe EpochState open SafetyRules public unquoteDecl srPersistentStorage srExportConsensusKey srValidatorSigner srEpochState = mkLens (quote SafetyRules) (srPersistentStorage ∷ srExportConsensusKey ∷ srValidatorSigner ∷ srEpochState ∷ []) -- ------------------------------------------------------------------------------ record BlockRetrievalRequest : Set where constructor BlockRetrievalRequest∙new field _brqObmFrom : Author _brqBlockId : HashValue _brqNumBlocks : U64 open BlockRetrievalRequest public unquoteDecl brqObmFrom brqBlockId brqNumBlocks = mkLens (quote BlockRetrievalRequest) (brqObmFrom ∷ brqBlockId ∷ brqNumBlocks ∷ []) postulate instance enc-BlockRetrievalRequest : Encoder BlockRetrievalRequest data BlockRetrievalStatus : Set where BRSSucceeded BRSIdNotFound BRSNotEnoughBlocks : BlockRetrievalStatus open BlockRetrievalStatus public postulate instance enc-BlockRetrievalState : Encoder BlockRetrievalStatus brs-eq : (brs₁ brs₂ : BlockRetrievalStatus) → Dec (brs₁ ≡ brs₂) brs-eq BRSSucceeded BRSSucceeded = yes refl brs-eq BRSSucceeded BRSIdNotFound = no λ () brs-eq BRSSucceeded BRSNotEnoughBlocks = no λ () brs-eq BRSIdNotFound BRSSucceeded = no λ () brs-eq BRSIdNotFound BRSIdNotFound = yes refl brs-eq BRSIdNotFound BRSNotEnoughBlocks = no λ () brs-eq BRSNotEnoughBlocks BRSSucceeded = no λ () brs-eq BRSNotEnoughBlocks BRSIdNotFound = no λ () brs-eq BRSNotEnoughBlocks BRSNotEnoughBlocks = yes refl instance Eq-BlockRetrievalStatus : Eq BlockRetrievalStatus Eq._≟_ Eq-BlockRetrievalStatus = brs-eq record BlockRetrievalResponse : Set where constructor BlockRetrievalResponse∙new field _brpObmFrom : (Author × Epoch × Round) -- for logging _brpStatus : BlockRetrievalStatus _brpBlocks : List Block unquoteDecl brpObmFrom brpStatus brpBlocks = mkLens (quote BlockRetrievalResponse) (brpObmFrom ∷ brpStatus ∷ brpBlocks ∷ []) postulate instance enc-BlockRetrievalResponse : Encoder BlockRetrievalResponse -- ------------------------------------------------------------------------------ -- LibraBFT.ImplShared.Consensus.Types contains -- ObmNeedFetch, RoundManager -- ------------------------------------------------------------------------------ record BlockRetriever : Set where constructor BlockRetriever∙new field _brDeadline : Instant _brPreferredPeer : Author open BlockRetriever public unquoteDecl brDeadline brPreferredPeer = mkLens (quote BlockRetriever) (brDeadline ∷ brPreferredPeer ∷ []) -- ------------------------------------------------------------------------------ record SyncInfo : Set where constructor mkSyncInfo -- Bare constructor to enable pattern matching against SyncInfo; "smart" -- constructor SyncInfo∙new is below field _siHighestQuorumCert : QuorumCert _sixxxHighestCommitCert : Maybe QuorumCert _siHighestTimeoutCert : Maybe TimeoutCertificate open SyncInfo public -- Note that we do not automatically derive a lens for siHighestCommitCert; -- it is defined manually below. unquoteDecl siHighestQuorumCert sixxxHighestCommitCert siHighestTimeoutCert = mkLens (quote SyncInfo) (siHighestQuorumCert ∷ sixxxHighestCommitCert ∷ siHighestTimeoutCert ∷ []) postulate instance enc-SyncInfo : Encoder SyncInfo SyncInfo∙new : QuorumCert → QuorumCert → Maybe TimeoutCertificate → SyncInfo SyncInfo∙new highestQuorumCert highestCommitCert highestTimeoutCert = record { _siHighestQuorumCert = highestQuorumCert ; _sixxxHighestCommitCert = if highestQuorumCert QCBoolEq highestCommitCert then nothing else (just highestCommitCert) ; _siHighestTimeoutCert = highestTimeoutCert } -- getter only in Haskell siHighestCommitCert : Lens SyncInfo QuorumCert siHighestCommitCert = mkLens' (λ x → fromMaybe (x ^∙ siHighestQuorumCert) (x ^∙ sixxxHighestCommitCert)) (λ x qc → record x { _sixxxHighestCommitCert = just qc }) -- getter only in Haskell siHighestCertifiedRound : Lens SyncInfo Round siHighestCertifiedRound = siHighestQuorumCert ∙ qcCertifiedBlock ∙ biRound -- getter only in Haskell siHighestTimeoutRound : Lens SyncInfo Round siHighestTimeoutRound = mkLens' (maybe 0 (_^∙ tcRound) ∘ (_^∙ siHighestTimeoutCert)) (λ x _r → x) -- TODO-1 -- getter only in Haskell siHighestCommitRound : Lens SyncInfo Round siHighestCommitRound = siHighestCommitCert ∙ qcCommitInfo ∙ biRound -- getter only in Haskell siHighestRound : Lens SyncInfo Round siHighestRound = mkLens' (λ x → (x ^∙ siHighestCertifiedRound) ⊔ (x ^∙ siHighestTimeoutRound)) (λ x _r → x) -- TODO-1 -- getter only in Haskell siEpoch : Lens SyncInfo Epoch siEpoch = siHighestQuorumCert ∙ qcCertifiedBlock ∙ biEpoch -- getter only in Haskell siObmRound : Lens SyncInfo Round siObmRound = siHighestQuorumCert ∙ qcCertifiedBlock ∙ biRound -- ------------------------------------------------------------------------------ record ProposalMsg : Set where constructor ProposalMsg∙new field _pmProposal : Block _pmSyncInfo : SyncInfo open ProposalMsg public unquoteDecl pmProposal pmSyncInfo = mkLens (quote ProposalMsg) (pmProposal ∷ pmSyncInfo ∷ []) postulate instance enc-ProposalMsg : Encoder ProposalMsg -- getter only in Haskell pmEpoch : Lens ProposalMsg Epoch pmEpoch = pmProposal ∙ bEpoch -- getter only in Haskell pmRound : Lens ProposalMsg Round pmRound = pmProposal ∙ bRound -- getter only in Haskell pmProposer : Lens ProposalMsg (Maybe Author) pmProposer = pmProposal ∙ bAuthor -- ------------------------------------------------------------------------------ record VoteMsg : Set where constructor VoteMsg∙new field _vmVote : Vote _vmSyncInfo : SyncInfo open VoteMsg public unquoteDecl vmVote vmSyncInfo = mkLens (quote VoteMsg) (vmVote ∷ vmSyncInfo ∷ []) postulate instance enc-VoteMsg : Encoder VoteMsg -- not defined in Haskell vmProposed : Lens VoteMsg BlockInfo vmProposed = vmVote ∙ vVoteData ∙ vdProposed -- not defined in Haskell vmParent : Lens VoteMsg BlockInfo vmParent = vmVote ∙ vVoteData ∙ vdParent -- getter-only in Haskell vmEpoch : Lens VoteMsg Epoch vmEpoch = vmVote ∙ vEpoch -- getter-only in Haskell vmRound : Lens VoteMsg Round vmRound = vmVote ∙ vRound -- ------------------------------------------------------------------------------ -- This is a notification of a commit. It may not be explicitly included in an implementation, -- but we need something to be able to express correctness conditions. It will -- probably have something different in it, but will serve the purpose for now. record CommitMsg : Set where constructor CommitMsg∙new field _cmEpoch : Epoch _cmAuthor : NodeId _cmRound : Round _cmCert : QuorumCert -- We assume for now that a CommitMsg contains the QuorumCert of the head of the 3-chain _cmSigMB : Maybe Signature open CommitMsg public unquoteDecl cmEpoch cmAuthor cmRound cmCert cmSigMB = mkLens (quote CommitMsg) (cmEpoch ∷ cmAuthor ∷ cmRound ∷ cmCert ∷ cmSigMB ∷ []) postulate instance enc-CommitMsg : Encoder CommitMsg -- ------------------------------------------------------------------------------ data RootMetadata : Set where RootMetadata∙new : RootMetadata -- ------------------------------------------------------------------------------ record RecoveryData : Set where constructor mkRecoveryData field _rdLastVote : Maybe Vote _rdRoot : RootInfo _rdRootMetadata : RootMetadata _rdBlocks : List Block _rdQuorumCerts : List QuorumCert _rdBlocksToPrune : Maybe (List HashValue) _rdHighestTimeoutCertificate : Maybe TimeoutCertificate open RecoveryData public unquoteDecl rdLastVote rdRoot rdRootMetadata rdBlocks rdQuorumCerts rdBlocksToPrune rdHighestTimeoutCertificate = mkLens (quote RecoveryData) (rdLastVote ∷ rdRoot ∷ rdRootMetadata ∷ rdBlocks ∷ rdQuorumCerts ∷ rdBlocksToPrune ∷ rdHighestTimeoutCertificate ∷ []) ------------------------------------------------------------------------------ record EpochChangeProof : Set where constructor EpochChangeProof∙new field _ecpLedgerInfoWithSigs : List LedgerInfoWithSignatures _ecpMore : Bool open EpochChangeProof public unquoteDecl ecpLedgerInfoWithSigs ecpMore = mkLens (quote EpochChangeProof) (ecpLedgerInfoWithSigs ∷ ecpMore ∷ []) -- instance S.Serialize EpochChangeProof record Ledger2WaypointConverter : Set where constructor mkLedger2WaypointConverter field _l2wcEpoch : Epoch _l2wcRootHash : HashValue _l2wcVersion : Version --_l2wcTimestamp : Instant _l2wcNextEpochState : Maybe EpochState open Ledger2WaypointConverter public unquoteDecl l2wcEpoch 2wcRootHash 2wcVersion {-l2wcTimestamp-} l2wcNextEpochState = mkLens (quote Ledger2WaypointConverter) (l2wcEpoch ∷ 2wcRootHash ∷ 2wcVersion ∷ {-l2wcTimestamp-} l2wcNextEpochState ∷ []) record EpochRetrievalRequest : Set where constructor EpochRetrievalRequest∙new field _eprrqStartEpoch : Epoch _eprrqEndEpoch : Epoch unquoteDecl eprrqStartEpoch eprrqEndEpoch = mkLens (quote EpochRetrievalRequest) (eprrqStartEpoch ∷ eprrqEndEpoch ∷ []) -- instance S.Serialize EpochRetrievalRequest ------------------------------------------------------------------------------ record ConsensusState : Set where constructor ConsensusState∙new field _csSafetyData : SafetyData _csWaypoint : Waypoint --_csInValidatorSet : Bool -- LBFT-OBM-DIFF: only used in tests in Rust open ConsensusState public unquoteDecl csSafetyData csWaypoint {-csInValidatorSet-} = mkLens (quote ConsensusState) (csSafetyData ∷ csWaypoint {-∷ csInValidatorSet-} ∷ []) ------------------------------------------------------------------------------ data SafetyRulesWrapper : Set where SRWLocal : SafetyRules → SafetyRulesWrapper record SafetyRulesManager : Set where constructor mkSafetyRulesManager field _srmInternalSafetyRules : SafetyRulesWrapper open SafetyRulesWrapper public unquoteDecl srmInternalSafetyRules = mkLens (quote SafetyRulesManager) (srmInternalSafetyRules ∷ []) data SafetyRulesService : Set where SRSLocal : SafetyRulesService record SafetyRulesConfig : Set where constructor SafetyRulesConfig∙new field _srcService : SafetyRulesService _srcExportConsensusKey : Bool _srcObmGenesisWaypoint : Waypoint open SafetyRulesConfig public unquoteDecl srcService srcExportConsensusKey srcObmGenesisWaypoint = mkLens (quote SafetyRulesConfig) (srcService ∷ srcExportConsensusKey ∷ srcObmGenesisWaypoint ∷ []) record ConsensusConfig : Set where constructor ConsensusConfig∙new field _ccMaxPrunedBlocksInMem : Usize _ccRoundInitialTimeoutMS : U64 _ccSafetyRules : SafetyRulesConfig _ccSyncOnly : Bool open ConsensusConfig public unquoteDecl ccMaxPrunedBlocksInMem ccRoundInitialTimeoutMS ccSafetyRules ccSyncOnly = mkLens (quote ConsensusConfig) (ccMaxPrunedBlocksInMem ∷ ccRoundInitialTimeoutMS ∷ ccSafetyRules ∷ ccSyncOnly ∷ []) record NodeConfig : Set where constructor NodeConfig∙new field _ncObmMe : AuthorName _ncConsensus : ConsensusConfig open NodeConfig public unquoteDecl ncObmMe ncConsensus = mkLens (quote NodeConfig) (ncObmMe ∷ ncConsensus ∷ []) record RecoveryManager : Set where constructor RecoveryManager∙new field _rcmEpochState : EpochState _rcmStorage : PersistentLivenessStorage --_rcmStateComputer : StateComputer _rcmLastCommittedRound : Round open RecoveryManager public unquoteDecl rcmEpochState rcmStorage {- rcmStateComputer-} rcmLastCommittedRound = mkLens (quote RecoveryManager) (rcmEpochState ∷ rcmStorage {-∷ rcmStateComputer-} ∷ rcmLastCommittedRound ∷ []) -- RoundProcessor in EpochManagerTypes (because it depends on RoundManager) -- EpochManager in EpochManagerTypes (because it depends on RoundProcessor) -- ------------------------------------------------------------------------------ data VoteReceptionResult : Set where QCVoteAdded : U64 → VoteReceptionResult TCVoteAdded : U64 → VoteReceptionResult DuplicateVote : VoteReceptionResult EquivocateVote : VoteReceptionResult NewQuorumCertificate : QuorumCert → VoteReceptionResult NewTimeoutCertificate : TimeoutCertificate → VoteReceptionResult UnexpectedRound : Round → Round → VoteReceptionResult VRR_TODO : VoteReceptionResult -- ------------------------------------------------------------------------------ -- LibraBFT.ImplShared.Interface.Output contains -- Output -- ------------------------------------------------------------------------------ data VerifyError : Set where UnknownAuthor : AuthorName → VerifyError TooLittleVotingPower : U64 → U64 → VerifyError TooManySignatures : Usize → Usize → VerifyError InvalidSignature : VerifyError
37.184892
124
0.647436
22d3c1804af3a060be5bfa4dbefbbdd9e3377708
317
agda
Agda
Logic.agda
cantsin/agda-experiments
382fcfae193079783621fc5cf54b6588e22ef759
[ "Apache-2.0" ]
null
null
null
Logic.agda
cantsin/agda-experiments
382fcfae193079783621fc5cf54b6588e22ef759
[ "Apache-2.0" ]
null
null
null
Logic.agda
cantsin/agda-experiments
382fcfae193079783621fc5cf54b6588e22ef759
[ "Apache-2.0" ]
null
null
null
import Either open import Boolean module Logic where id : ∀ { A : Set } → A → A id x = x Rel : Set → Set₁ Rel X = X → X → Set Decidable : ∀ { X } → Rel X → Set Decidable R = ∀ x y → Either (R x y) (¬ (R x y)) where open Either modusPonens : { P Q : Set } → ( P → Q ) → P → Q modusPonens = id
17.611111
50
0.520505
225dbb459b94ef3d75bba5d9386fb6a4c5d462ad
18,849
agda
Agda
agda-stdlib-0.9/src/Data/Fin/Substitution/Lemmas.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/Data/Fin/Substitution/Lemmas.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
agda-stdlib-0.9/src/Data/Fin/Substitution/Lemmas.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Substitution lemmas ------------------------------------------------------------------------ module Data.Fin.Substitution.Lemmas where import Category.Applicative.Indexed as Applicative open import Data.Fin.Substitution open import Data.Nat open import Data.Fin using (Fin; zero; suc; lift) open import Data.Vec import Data.Vec.Properties as VecProp open import Function as Fun using (_∘_; _$_) open import Relation.Binary.PropositionalEquality as PropEq using (_≡_; refl; sym; cong; cong₂) open PropEq.≡-Reasoning open import Data.Star using (Star; ε; _◅_; _▻_) -- A lemma which does not refer to any substitutions. lift-commutes : ∀ {n} k j (x : Fin (j + (k + n))) → lift j suc (lift j (lift k suc) x) ≡ lift j (lift (suc k) suc) (lift j suc x) lift-commutes k zero x = refl lift-commutes k (suc j) zero = refl lift-commutes k (suc j) (suc x) = cong suc (lift-commutes k j x) -- The modules below prove a number of substitution lemmas, on the -- assumption that the underlying substitution machinery satisfies -- certain properties. record Lemmas₀ (T : ℕ → Set) : Set where field simple : Simple T open Simple simple extensionality : ∀ {m n} {ρ₁ ρ₂ : Sub T m n} → (∀ x → lookup x ρ₁ ≡ lookup x ρ₂) → ρ₁ ≡ ρ₂ extensionality {ρ₁ = []} {[]} hyp = refl extensionality {ρ₁ = t₁ ∷ ρ₁} { t₂ ∷ ρ₂} hyp with hyp zero extensionality {ρ₁ = t₁ ∷ ρ₁} {.t₁ ∷ ρ₂} hyp | refl = cong (_∷_ t₁) (extensionality (hyp ∘ suc)) id-↑⋆ : ∀ {n} k → id ↑⋆ k ≡ id {k + n} id-↑⋆ zero = refl id-↑⋆ (suc k) = begin (id ↑⋆ k) ↑ ≡⟨ cong _↑ (id-↑⋆ k) ⟩ id ↑ ∎ lookup-map-weaken-↑⋆ : ∀ {m n} k x {ρ : Sub T m n} → lookup x (map weaken ρ ↑⋆ k) ≡ lookup (lift k suc x) ((ρ ↑) ↑⋆ k) lookup-map-weaken-↑⋆ zero x = refl lookup-map-weaken-↑⋆ (suc k) zero = refl lookup-map-weaken-↑⋆ (suc k) (suc x) {ρ} = begin lookup x (map weaken (map weaken ρ ↑⋆ k)) ≡⟨ Applicative.Morphism.op-<$> (VecProp.lookup-morphism x) weaken _ ⟩ weaken (lookup x (map weaken ρ ↑⋆ k)) ≡⟨ cong weaken (lookup-map-weaken-↑⋆ k x) ⟩ weaken (lookup (lift k suc x) ((ρ ↑) ↑⋆ k)) ≡⟨ sym $ Applicative.Morphism.op-<$> (VecProp.lookup-morphism (lift k suc x)) weaken _ ⟩ lookup (lift k suc x) (map weaken ((ρ ↑) ↑⋆ k)) ∎ record Lemmas₁ (T : ℕ → Set) : Set where field lemmas₀ : Lemmas₀ T open Lemmas₀ lemmas₀ open Simple simple field weaken-var : ∀ {n} {x : Fin n} → weaken (var x) ≡ var (suc x) lookup-map-weaken : ∀ {m n} x {y} {ρ : Sub T m n} → lookup x ρ ≡ var y → lookup x (map weaken ρ) ≡ var (suc y) lookup-map-weaken x {y} {ρ} hyp = begin lookup x (map weaken ρ) ≡⟨ Applicative.Morphism.op-<$> (VecProp.lookup-morphism x) weaken ρ ⟩ weaken (lookup x ρ) ≡⟨ cong weaken hyp ⟩ weaken (var y) ≡⟨ weaken-var ⟩ var (suc y) ∎ mutual lookup-id : ∀ {n} (x : Fin n) → lookup x id ≡ var x lookup-id zero = refl lookup-id (suc x) = lookup-wk x lookup-wk : ∀ {n} (x : Fin n) → lookup x wk ≡ var (suc x) lookup-wk x = lookup-map-weaken x (lookup-id x) lookup-↑⋆ : ∀ {m n} (f : Fin m → Fin n) {ρ : Sub T m n} → (∀ x → lookup x ρ ≡ var (f x)) → ∀ k x → lookup x (ρ ↑⋆ k) ≡ var (lift k f x) lookup-↑⋆ f hyp zero x = hyp x lookup-↑⋆ f hyp (suc k) zero = refl lookup-↑⋆ f hyp (suc k) (suc x) = lookup-map-weaken x (lookup-↑⋆ f hyp k x) lookup-lift-↑⋆ : ∀ {m n} (f : Fin n → Fin m) {ρ : Sub T m n} → (∀ x → lookup (f x) ρ ≡ var x) → ∀ k x → lookup (lift k f x) (ρ ↑⋆ k) ≡ var x lookup-lift-↑⋆ f hyp zero x = hyp x lookup-lift-↑⋆ f hyp (suc k) zero = refl lookup-lift-↑⋆ f hyp (suc k) (suc x) = lookup-map-weaken (lift k f x) (lookup-lift-↑⋆ f hyp k x) lookup-wk-↑⋆ : ∀ {n} k (x : Fin (k + n)) → lookup x (wk ↑⋆ k) ≡ var (lift k suc x) lookup-wk-↑⋆ = lookup-↑⋆ suc lookup-wk lookup-wk-↑⋆-↑⋆ : ∀ {n} k j (x : Fin (j + (k + n))) → lookup x (wk ↑⋆ k ↑⋆ j) ≡ var (lift j (lift k suc) x) lookup-wk-↑⋆-↑⋆ k = lookup-↑⋆ (lift k suc) (lookup-wk-↑⋆ k) lookup-sub-↑⋆ : ∀ {n t} k (x : Fin (k + n)) → lookup (lift k suc x) (sub t ↑⋆ k) ≡ var x lookup-sub-↑⋆ = lookup-lift-↑⋆ suc lookup-id open Lemmas₀ lemmas₀ public record Lemmas₂ (T : ℕ → Set) : Set where field lemmas₁ : Lemmas₁ T application : Application T T open Lemmas₁ lemmas₁ subst : Subst T subst = record { simple = simple; application = application } open Subst subst field var-/ : ∀ {m n x} {ρ : Sub T m n} → var x / ρ ≡ lookup x ρ suc-/-sub : ∀ {n x} {t : T n} → var (suc x) / sub t ≡ var x suc-/-sub {x = x} {t} = begin var (suc x) / sub t ≡⟨ var-/ ⟩ lookup (suc x) (sub t) ≡⟨ refl ⟩ lookup x id ≡⟨ lookup-id x ⟩ var x ∎ lookup-⊙ : ∀ {m n k} x {ρ₁ : Sub T m n} {ρ₂ : Sub T n k} → lookup x (ρ₁ ⊙ ρ₂) ≡ lookup x ρ₁ / ρ₂ lookup-⊙ x = Applicative.Morphism.op-<$> (VecProp.lookup-morphism x) _ _ lookup-⨀ : ∀ {m n} x (ρs : Subs T m n) → lookup x (⨀ ρs) ≡ var x /✶ ρs lookup-⨀ x ε = lookup-id x lookup-⨀ x (ρ ◅ ε) = sym var-/ lookup-⨀ x (ρ ◅ (ρ′ ◅ ρs′)) = begin lookup x (⨀ (ρ ◅ ρs)) ≡⟨ refl ⟩ lookup x (⨀ ρs ⊙ ρ) ≡⟨ lookup-⊙ x ⟩ lookup x (⨀ ρs) / ρ ≡⟨ cong₂ _/_ (lookup-⨀ x (ρ′ ◅ ρs′)) refl ⟩ var x /✶ ρs / ρ ∎ where ρs = ρ′ ◅ ρs′ id-⊙ : ∀ {m n} {ρ : Sub T m n} → id ⊙ ρ ≡ ρ id-⊙ {ρ = ρ} = extensionality λ x → begin lookup x (id ⊙ ρ) ≡⟨ lookup-⊙ x ⟩ lookup x id / ρ ≡⟨ cong₂ _/_ (lookup-id x) refl ⟩ var x / ρ ≡⟨ var-/ ⟩ lookup x ρ ∎ lookup-wk-↑⋆-⊙ : ∀ {m n} k {x} {ρ : Sub T (k + suc m) n} → lookup x (wk ↑⋆ k ⊙ ρ) ≡ lookup (lift k suc x) ρ lookup-wk-↑⋆-⊙ k {x} {ρ} = begin lookup x (wk ↑⋆ k ⊙ ρ) ≡⟨ lookup-⊙ x ⟩ lookup x (wk ↑⋆ k) / ρ ≡⟨ cong₂ _/_ (lookup-wk-↑⋆ k x) refl ⟩ var (lift k suc x) / ρ ≡⟨ var-/ ⟩ lookup (lift k suc x) ρ ∎ wk-⊙-sub′ : ∀ {n} {t : T n} k → wk ↑⋆ k ⊙ sub t ↑⋆ k ≡ id wk-⊙-sub′ {t = t} k = extensionality λ x → begin lookup x (wk ↑⋆ k ⊙ sub t ↑⋆ k) ≡⟨ lookup-wk-↑⋆-⊙ k ⟩ lookup (lift k suc x) (sub t ↑⋆ k) ≡⟨ lookup-sub-↑⋆ k x ⟩ var x ≡⟨ sym (lookup-id x) ⟩ lookup x id ∎ wk-⊙-sub : ∀ {n} {t : T n} → wk ⊙ sub t ≡ id wk-⊙-sub = wk-⊙-sub′ zero var-/-wk-↑⋆ : ∀ {n} k (x : Fin (k + n)) → var x / wk ↑⋆ k ≡ var (lift k suc x) var-/-wk-↑⋆ k x = begin var x / wk ↑⋆ k ≡⟨ var-/ ⟩ lookup x (wk ↑⋆ k) ≡⟨ lookup-wk-↑⋆ k x ⟩ var (lift k suc x) ∎ wk-↑⋆-⊙-wk : ∀ {n} k j → wk {n} ↑⋆ k ↑⋆ j ⊙ wk ↑⋆ j ≡ wk ↑⋆ j ⊙ wk ↑⋆ suc k ↑⋆ j wk-↑⋆-⊙-wk k j = extensionality λ x → begin lookup x (wk ↑⋆ k ↑⋆ j ⊙ wk ↑⋆ j) ≡⟨ lookup-⊙ x ⟩ lookup x (wk ↑⋆ k ↑⋆ j) / wk ↑⋆ j ≡⟨ cong₂ _/_ (lookup-wk-↑⋆-↑⋆ k j x) refl ⟩ var (lift j (lift k suc) x) / wk ↑⋆ j ≡⟨ var-/-wk-↑⋆ j (lift j (lift k suc) x) ⟩ var (lift j suc (lift j (lift k suc) x)) ≡⟨ cong var (lift-commutes k j x) ⟩ var (lift j (lift (suc k) suc) (lift j suc x)) ≡⟨ sym (lookup-wk-↑⋆-↑⋆ (suc k) j (lift j suc x)) ⟩ lookup (lift j suc x) (wk ↑⋆ suc k ↑⋆ j) ≡⟨ sym var-/ ⟩ var (lift j suc x) / wk ↑⋆ suc k ↑⋆ j ≡⟨ cong₂ _/_ (sym (lookup-wk-↑⋆ j x)) refl ⟩ lookup x (wk ↑⋆ j) / wk ↑⋆ suc k ↑⋆ j ≡⟨ sym (lookup-⊙ x) ⟩ lookup x (wk ↑⋆ j ⊙ wk ↑⋆ suc k ↑⋆ j) ∎ open Subst subst public hiding (simple; application) open Lemmas₁ lemmas₁ public record Lemmas₃ (T : ℕ → Set) : Set where field lemmas₂ : Lemmas₂ T open Lemmas₂ lemmas₂ field /✶-↑✶ : ∀ {m n} (ρs₁ ρs₂ : Subs T m n) → (∀ k x → var x /✶ ρs₁ ↑✶ k ≡ var x /✶ ρs₂ ↑✶ k) → ∀ k t → t /✶ ρs₁ ↑✶ k ≡ t /✶ ρs₂ ↑✶ k /✶-↑✶′ : ∀ {m n} (ρs₁ ρs₂ : Subs T m n) → (∀ k → ⨀ (ρs₁ ↑✶ k) ≡ ⨀ (ρs₂ ↑✶ k)) → ∀ k t → t /✶ ρs₁ ↑✶ k ≡ t /✶ ρs₂ ↑✶ k /✶-↑✶′ ρs₁ ρs₂ hyp = /✶-↑✶ ρs₁ ρs₂ (λ k x → begin var x /✶ ρs₁ ↑✶ k ≡⟨ sym (lookup-⨀ x (ρs₁ ↑✶ k)) ⟩ lookup x (⨀ (ρs₁ ↑✶ k)) ≡⟨ cong (lookup x) (hyp k) ⟩ lookup x (⨀ (ρs₂ ↑✶ k)) ≡⟨ lookup-⨀ x (ρs₂ ↑✶ k) ⟩ var x /✶ ρs₂ ↑✶ k ∎) id-vanishes : ∀ {n} (t : T n) → t / id ≡ t id-vanishes = /✶-↑✶′ (ε ▻ id) ε id-↑⋆ zero ⊙-id : ∀ {m n} {ρ : Sub T m n} → ρ ⊙ id ≡ ρ ⊙-id {ρ = ρ} = begin map (λ t → t / id) ρ ≡⟨ VecProp.map-cong id-vanishes ρ ⟩ map Fun.id ρ ≡⟨ VecProp.map-id ρ ⟩ ρ ∎ open Lemmas₂ lemmas₂ public hiding (wk-⊙-sub′) record Lemmas₄ (T : ℕ → Set) : Set where field lemmas₃ : Lemmas₃ T open Lemmas₃ lemmas₃ field /-wk : ∀ {n} {t : T n} → t / wk ≡ weaken t private ↑-distrib′ : ∀ {m n k} {ρ₁ : Sub T m n} {ρ₂ : Sub T n k} → (∀ t → t / ρ₂ / wk ≡ t / wk / ρ₂ ↑) → (ρ₁ ⊙ ρ₂) ↑ ≡ ρ₁ ↑ ⊙ ρ₂ ↑ ↑-distrib′ {ρ₁ = ρ₁} {ρ₂} hyp = begin (ρ₁ ⊙ ρ₂) ↑ ≡⟨ refl ⟩ var zero ∷ map weaken (ρ₁ ⊙ ρ₂) ≡⟨ cong₂ _∷_ (sym var-/) lemma ⟩ var zero / ρ₂ ↑ ∷ map weaken ρ₁ ⊙ ρ₂ ↑ ≡⟨ refl ⟩ ρ₁ ↑ ⊙ ρ₂ ↑ ∎ where lemma = begin map weaken (map (λ t → t / ρ₂) ρ₁) ≡⟨ sym (VecProp.map-∘ _ _ _) ⟩ map (λ t → weaken (t / ρ₂)) ρ₁ ≡⟨ VecProp.map-cong (λ t → begin weaken (t / ρ₂) ≡⟨ sym /-wk ⟩ t / ρ₂ / wk ≡⟨ hyp t ⟩ t / wk / ρ₂ ↑ ≡⟨ cong₂ _/_ /-wk refl ⟩ weaken t / ρ₂ ↑ ∎) ρ₁ ⟩ map (λ t → weaken t / ρ₂ ↑) ρ₁ ≡⟨ VecProp.map-∘ _ _ _ ⟩ map (λ t → t / ρ₂ ↑) (map weaken ρ₁) ∎ ↑⋆-distrib′ : ∀ {m n o} {ρ₁ : Sub T m n} {ρ₂ : Sub T n o} → (∀ k t → t / ρ₂ ↑⋆ k / wk ≡ t / wk / ρ₂ ↑⋆ suc k) → ∀ k → (ρ₁ ⊙ ρ₂) ↑⋆ k ≡ ρ₁ ↑⋆ k ⊙ ρ₂ ↑⋆ k ↑⋆-distrib′ hyp zero = refl ↑⋆-distrib′ {ρ₁ = ρ₁} {ρ₂} hyp (suc k) = begin (ρ₁ ⊙ ρ₂) ↑⋆ suc k ≡⟨ cong _↑ (↑⋆-distrib′ hyp k) ⟩ (ρ₁ ↑⋆ k ⊙ ρ₂ ↑⋆ k) ↑ ≡⟨ ↑-distrib′ (hyp k) ⟩ ρ₁ ↑⋆ suc k ⊙ ρ₂ ↑⋆ suc k ∎ map-weaken : ∀ {m n} {ρ : Sub T m n} → map weaken ρ ≡ ρ ⊙ wk map-weaken {ρ = ρ} = begin map weaken ρ ≡⟨ VecProp.map-cong (λ _ → sym /-wk) ρ ⟩ map (λ t → t / wk) ρ ≡⟨ refl ⟩ ρ ⊙ wk ∎ private ⊙-wk′ : ∀ {m n} {ρ : Sub T m n} k → ρ ↑⋆ k ⊙ wk ↑⋆ k ≡ wk ↑⋆ k ⊙ ρ ↑ ↑⋆ k ⊙-wk′ {ρ = ρ} k = sym (begin wk ↑⋆ k ⊙ ρ ↑ ↑⋆ k ≡⟨ lemma ⟩ map weaken ρ ↑⋆ k ≡⟨ cong (λ ρ′ → ρ′ ↑⋆ k) map-weaken ⟩ (ρ ⊙ wk) ↑⋆ k ≡⟨ ↑⋆-distrib′ (λ k t → /✶-↑✶′ (ε ▻ wk ↑⋆ k ▻ wk) (ε ▻ wk ▻ wk ↑⋆ suc k) (wk-↑⋆-⊙-wk k) zero t) k ⟩ ρ ↑⋆ k ⊙ wk ↑⋆ k ∎) where lemma = extensionality λ x → begin lookup x (wk ↑⋆ k ⊙ ρ ↑ ↑⋆ k) ≡⟨ lookup-wk-↑⋆-⊙ k ⟩ lookup (lift k suc x) (ρ ↑ ↑⋆ k) ≡⟨ sym (lookup-map-weaken-↑⋆ k x) ⟩ lookup x (map weaken ρ ↑⋆ k) ∎ ⊙-wk : ∀ {m n} {ρ : Sub T m n} → ρ ⊙ wk ≡ wk ⊙ ρ ↑ ⊙-wk = ⊙-wk′ zero wk-commutes : ∀ {m n} {ρ : Sub T m n} t → t / ρ / wk ≡ t / wk / ρ ↑ wk-commutes {ρ = ρ} = /✶-↑✶′ (ε ▻ ρ ▻ wk) (ε ▻ wk ▻ ρ ↑) ⊙-wk′ zero ↑⋆-distrib : ∀ {m n o} {ρ₁ : Sub T m n} {ρ₂ : Sub T n o} → ∀ k → (ρ₁ ⊙ ρ₂) ↑⋆ k ≡ ρ₁ ↑⋆ k ⊙ ρ₂ ↑⋆ k ↑⋆-distrib = ↑⋆-distrib′ (λ _ → wk-commutes) /-⊙ : ∀ {m n k} {ρ₁ : Sub T m n} {ρ₂ : Sub T n k} t → t / ρ₁ ⊙ ρ₂ ≡ t / ρ₁ / ρ₂ /-⊙ {ρ₁ = ρ₁} {ρ₂} t = /✶-↑✶′ (ε ▻ ρ₁ ⊙ ρ₂) (ε ▻ ρ₁ ▻ ρ₂) ↑⋆-distrib zero t ⊙-assoc : ∀ {m n k o} {ρ₁ : Sub T m n} {ρ₂ : Sub T n k} {ρ₃ : Sub T k o} → ρ₁ ⊙ (ρ₂ ⊙ ρ₃) ≡ (ρ₁ ⊙ ρ₂) ⊙ ρ₃ ⊙-assoc {ρ₁ = ρ₁} {ρ₂} {ρ₃} = begin map (λ t → t / ρ₂ ⊙ ρ₃) ρ₁ ≡⟨ VecProp.map-cong /-⊙ ρ₁ ⟩ map (λ t → t / ρ₂ / ρ₃) ρ₁ ≡⟨ VecProp.map-∘ _ _ _ ⟩ map (λ t → t / ρ₃) (map (λ t → t / ρ₂) ρ₁) ∎ map-weaken-⊙-sub : ∀ {m n} {ρ : Sub T m n} {t} → map weaken ρ ⊙ sub t ≡ ρ map-weaken-⊙-sub {ρ = ρ} {t} = begin map weaken ρ ⊙ sub t ≡⟨ cong₂ _⊙_ map-weaken refl ⟩ ρ ⊙ wk ⊙ sub t ≡⟨ sym ⊙-assoc ⟩ ρ ⊙ (wk ⊙ sub t) ≡⟨ cong (_⊙_ ρ) wk-⊙-sub ⟩ ρ ⊙ id ≡⟨ ⊙-id ⟩ ρ ∎ sub-⊙ : ∀ {m n} {ρ : Sub T m n} t → sub t ⊙ ρ ≡ ρ ↑ ⊙ sub (t / ρ) sub-⊙ {ρ = ρ} t = begin sub t ⊙ ρ ≡⟨ refl ⟩ t / ρ ∷ id ⊙ ρ ≡⟨ cong (_∷_ (t / ρ)) id-⊙ ⟩ t / ρ ∷ ρ ≡⟨ cong (_∷_ (t / ρ)) (sym map-weaken-⊙-sub) ⟩ t / ρ ∷ map weaken ρ ⊙ sub (t / ρ) ≡⟨ cong₂ _∷_ (sym var-/) refl ⟩ ρ ↑ ⊙ sub (t / ρ) ∎ suc-/-↑ : ∀ {m n} {ρ : Sub T m n} x → var (suc x) / ρ ↑ ≡ var x / ρ / wk suc-/-↑ {ρ = ρ} x = begin var (suc x) / ρ ↑ ≡⟨ var-/ ⟩ lookup x (map weaken ρ) ≡⟨ cong (lookup x) map-weaken ⟩ lookup x (ρ ⊙ wk) ≡⟨ lookup-⊙ x ⟩ lookup x ρ / wk ≡⟨ cong₂ _/_ (sym var-/) refl ⟩ var x / ρ / wk ∎ open Lemmas₃ lemmas₃ public hiding (/✶-↑✶; /✶-↑✶′; wk-↑⋆-⊙-wk; lookup-wk-↑⋆-⊙; lookup-map-weaken-↑⋆) -- For an example of how AppLemmas can be used, see -- Data.Fin.Substitution.List. record AppLemmas (T₁ T₂ : ℕ → Set) : Set where field application : Application T₁ T₂ lemmas₄ : Lemmas₄ T₂ open Application application using (_/_; _/✶_) open Lemmas₄ lemmas₄ using (id; _⊙_; wk; weaken; sub; _↑; ⨀) renaming (_/_ to _⊘_) field id-vanishes : ∀ {n} (t : T₁ n) → t / id ≡ t /-⊙ : ∀ {m n k} {ρ₁ : Sub T₂ m n} {ρ₂ : Sub T₂ n k} t → t / ρ₁ ⊙ ρ₂ ≡ t / ρ₁ / ρ₂ private module L₄ = Lemmas₄ lemmas₄ /-⨀ : ∀ {m n} t (ρs : Subs T₂ m n) → t / ⨀ ρs ≡ t /✶ ρs /-⨀ t ε = id-vanishes t /-⨀ t (ρ ◅ ε) = refl /-⨀ t (ρ ◅ (ρ′ ◅ ρs′)) = begin t / ⨀ ρs ⊙ ρ ≡⟨ /-⊙ t ⟩ t / ⨀ ρs / ρ ≡⟨ cong₂ _/_ (/-⨀ t (ρ′ ◅ ρs′)) refl ⟩ t /✶ ρs / ρ ∎ where ρs = ρ′ ◅ ρs′ ⨀→/✶ : ∀ {m n} (ρs₁ ρs₂ : Subs T₂ m n) → ⨀ ρs₁ ≡ ⨀ ρs₂ → ∀ t → t /✶ ρs₁ ≡ t /✶ ρs₂ ⨀→/✶ ρs₁ ρs₂ hyp t = begin t /✶ ρs₁ ≡⟨ sym (/-⨀ t ρs₁) ⟩ t / ⨀ ρs₁ ≡⟨ cong (_/_ t) hyp ⟩ t / ⨀ ρs₂ ≡⟨ /-⨀ t ρs₂ ⟩ t /✶ ρs₂ ∎ wk-commutes : ∀ {m n} {ρ : Sub T₂ m n} t → t / ρ / wk ≡ t / wk / ρ ↑ wk-commutes {ρ = ρ} = ⨀→/✶ (ε ▻ ρ ▻ wk) (ε ▻ wk ▻ ρ ↑) L₄.⊙-wk sub-commutes : ∀ {m n} {t′} {ρ : Sub T₂ m n} t → t / sub t′ / ρ ≡ t / ρ ↑ / sub (t′ ⊘ ρ) sub-commutes {t′ = t′} {ρ} = ⨀→/✶ (ε ▻ sub t′ ▻ ρ) (ε ▻ ρ ↑ ▻ sub (t′ ⊘ ρ)) (L₄.sub-⊙ t′) wk-sub-vanishes : ∀ {n t′} (t : T₁ n) → t / wk / sub t′ ≡ t wk-sub-vanishes {t′ = t′} = ⨀→/✶ (ε ▻ wk ▻ sub t′) ε L₄.wk-⊙-sub /-weaken : ∀ {m n} {ρ : Sub T₂ m n} t → t / map weaken ρ ≡ t / ρ / wk /-weaken {ρ = ρ} = ⨀→/✶ (ε ▻ map weaken ρ) (ε ▻ ρ ▻ wk) L₄.map-weaken open Application application public open L₄ public hiding (application; _⊙_; _/_; _/✶_; id-vanishes; /-⊙; wk-commutes) record Lemmas₅ (T : ℕ → Set) : Set where field lemmas₄ : Lemmas₄ T private module L₄ = Lemmas₄ lemmas₄ appLemmas : AppLemmas T T appLemmas = record { application = L₄.application ; lemmas₄ = lemmas₄ ; id-vanishes = L₄.id-vanishes ; /-⊙ = L₄./-⊙ } open AppLemmas appLemmas public hiding (lemmas₄) ------------------------------------------------------------------------ -- Instantiations and code for facilitating instantiations -- Lemmas about variable substitutions (renamings). module VarLemmas where open VarSubst lemmas₃ : Lemmas₃ Fin lemmas₃ = record { lemmas₂ = record { lemmas₁ = record { lemmas₀ = record { simple = simple } ; weaken-var = refl } ; application = application ; var-/ = refl } ; /✶-↑✶ = λ _ _ hyp → hyp } private module L₃ = Lemmas₃ lemmas₃ lemmas₅ : Lemmas₅ Fin lemmas₅ = record { lemmas₄ = record { lemmas₃ = lemmas₃ ; /-wk = L₃.lookup-wk _ } } open Lemmas₅ lemmas₅ public hiding (lemmas₃) -- Lemmas about "term" substitutions. record TermLemmas (T : ℕ → Set) : Set₁ where field termSubst : TermSubst T open TermSubst termSubst field app-var : ∀ {T′} {lift : Lift T′ T} {m n x} {ρ : Sub T′ m n} → app lift (var x) ρ ≡ Lift.lift lift (lookup x ρ) /✶-↑✶ : ∀ {T₁ T₂} {lift₁ : Lift T₁ T} {lift₂ : Lift T₂ T} → let open Lifted lift₁ using () renaming (_↑✶_ to _↑✶₁_; _/✶_ to _/✶₁_) open Lifted lift₂ using () renaming (_↑✶_ to _↑✶₂_; _/✶_ to _/✶₂_) in ∀ {m n} (ρs₁ : Subs T₁ m n) (ρs₂ : Subs T₂ m n) → (∀ k x → var x /✶₁ ρs₁ ↑✶₁ k ≡ var x /✶₂ ρs₂ ↑✶₂ k) → ∀ k t → t /✶₁ ρs₁ ↑✶₁ k ≡ t /✶₂ ρs₂ ↑✶₂ k private module V = VarLemmas lemmas₃ : Lemmas₃ T lemmas₃ = record { lemmas₂ = record { lemmas₁ = record { lemmas₀ = record { simple = simple } ; weaken-var = λ {_ x} → begin var x /Var V.wk ≡⟨ app-var ⟩ var (lookup x V.wk) ≡⟨ cong var (V.lookup-wk x) ⟩ var (suc x) ∎ } ; application = Subst.application subst ; var-/ = app-var } ; /✶-↑✶ = /✶-↑✶ } private module L₃ = Lemmas₃ lemmas₃ lemmas₅ : Lemmas₅ T lemmas₅ = record { lemmas₄ = record { lemmas₃ = lemmas₃ ; /-wk = λ {_ t} → begin t / wk ≡⟨ /✶-↑✶ (ε ▻ wk) (ε ▻ V.wk) (λ k x → begin var x / wk ↑⋆ k ≡⟨ L₃.var-/-wk-↑⋆ k x ⟩ var (lift k suc x) ≡⟨ cong var (sym (V.var-/-wk-↑⋆ k x)) ⟩ var (lookup x (V._↑⋆_ V.wk k)) ≡⟨ sym app-var ⟩ var x /Var V._↑⋆_ V.wk k ∎) zero t ⟩ t /Var V.wk ≡⟨ refl ⟩ weaken t ∎ } } open Lemmas₅ lemmas₅ public hiding (lemmas₃)
36.458414
137
0.435142
13673c0bc6b9373c21d5ec83857c0e2c6be4350d
844
agda
Agda
agda-stdlib-0.9/src/Relation/Binary/Properties/DecTotalOrder.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/Relation/Binary/Properties/DecTotalOrder.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
agda-stdlib-0.9/src/Relation/Binary/Properties/DecTotalOrder.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties satisfied by decidable total orders ------------------------------------------------------------------------ open import Relation.Binary module Relation.Binary.Properties.DecTotalOrder {d₁ d₂ d₃} (DT : DecTotalOrder d₁ d₂ d₃) where open Relation.Binary.DecTotalOrder DT hiding (trans) import Relation.Binary.NonStrictToStrict as Conv open Conv _≈_ _≤_ strictTotalOrder : StrictTotalOrder _ _ _ strictTotalOrder = record { isStrictTotalOrder = record { isEquivalence = isEquivalence ; trans = trans isPartialOrder ; compare = trichotomous Eq.sym _≟_ antisym total ; <-resp-≈ = <-resp-≈ isEquivalence ≤-resp-≈ } } open StrictTotalOrder strictTotalOrder public
31.259259
72
0.588863
06c383fde79daed4a15055a4fa9c8dc0c9daef5d
4,953
agda
Agda
Categories/Functor/Construction/Inclusion.agda
elpinal/exsub-ccc
7541ab22debdfe9d529ac7a210e5bd102c788ad9
[ "Apache-2.0" ]
3
2022-02-05T06:16:32.000Z
2022-02-05T13:30:48.000Z
Categories/Functor/Construction/Inclusion.agda
elpinal/exsub-ccc
7541ab22debdfe9d529ac7a210e5bd102c788ad9
[ "Apache-2.0" ]
null
null
null
Categories/Functor/Construction/Inclusion.agda
elpinal/exsub-ccc
7541ab22debdfe9d529ac7a210e5bd102c788ad9
[ "Apache-2.0" ]
null
null
null
open import Theory module Categories.Functor.Construction.Inclusion {ℓ₁ ℓ₂ ℓ₃} (Th : Theory ℓ₁ ℓ₂ ℓ₃) where open import Syntax open Theory.Theory Th open Signature Sg open Term Sg open import Categories.Category.Construction.Renaming Sg as Renaming using (Ren; ren; _≐_) open import Categories.Category.Construction.Classifying Th using (Cl; CC) open import Categories.Functor open import Categories.Category open import Categories.Morphism Cl using (_≅_; Iso) open import Categories.Category.CartesianClosed Cl open import Categories.Category.Cartesian Cl open import Categories.Category.BinaryProducts Cl open import Data.List using (List; []; _∷_; _++_) import Relation.Binary.Reasoning.Setoid as Reasoning module TermReasoning {Γ A} = Reasoning (TermSetoid {Γ} {A}) inclusion : Functor Ren Cl inclusion = record { F₀ = F₀ ; F₁ = F₁ ; identity = C.Equiv.refl ; homomorphism = λ {Γ₁} {Γ₂} {Γ₃} {f} {g} -> homomorphism f g ; F-resp-≈ = F-resp-≈ } where module C = Category Cl open CartesianClosed CC open Cartesian cartesian open BinaryProducts products open import Categories.Morphism.Reasoning Cl id⁂id : forall {A B} -> C.id ⁂ C.id C.≈ C.id {A = A * B} id⁂id = trans (⟨⟩-cong₂ C.identityˡ C.identityˡ) η F₀ : Context -> Type F₀ [] = Unit F₀ (A ∷ Γ) = F₀ Γ * A F₀/*⇒++ : forall {Γ Δ} -> F₀ Γ * F₀ Δ C.⇒ F₀ (Δ ++ Γ) F₀/*⇒++ {Γ} {[]} = fst var F₀/*⇒++ {Γ} {A ∷ Δ} = (F₀/*⇒++ ⁂ C.id) C.∘ assocʳ F₀/++⇒* : forall {Γ Δ} -> F₀ (Δ ++ Γ) C.⇒ F₀ Γ * F₀ Δ F₀/++⇒* {Γ} {[]} = pair var unit F₀/++⇒* {Γ} {A ∷ Δ} = assocˡ C.∘ (F₀/++⇒* ⁂ C.id) F₀/*≅++ : forall {Γ Δ} -> F₀ Γ * F₀ Δ ≅ F₀ (Δ ++ Γ) F₀/*≅++ = record { from = F₀/*⇒++ ; to = F₀/++⇒* ; iso = record { isoˡ = isoˡ ; isoʳ = isoʳ } } where isoˡ : forall {Γ Δ} -> F₀/++⇒* C.∘ F₀/*⇒++ C.≈ C.id {A = F₀ Γ * F₀ Δ} isoˡ {Γ} {[]} = begin pair var unit [ ext ! (fst var) ] ≈⟨ trans comm/pair (cong/pair (var/ext _ _) (comm/unit _ _ _)) ⟩ pair (fst var) unit ≈⟨ cong/pair refl (eta/Unit _) ⟩ pair (fst var) (snd var) ≈⟨ eta/* _ ⟩ var ∎ where open TermReasoning isoˡ {Γ} {A ∷ Δ} = begin (assocˡ C.∘ (F₀/++⇒* ⁂ var)) C.∘ ((F₀/*⇒++ ⁂ var) C.∘ assocʳ) ≈⟨ C.assoc ⟩ assocˡ C.∘ (F₀/++⇒* ⁂ var) C.∘ (F₀/*⇒++ ⁂ var) C.∘ assocʳ ≈⟨ C.∘-resp-≈ʳ (pullˡ ⁂∘⁂) ⟩ assocˡ C.∘ (F₀/++⇒* C.∘ F₀/*⇒++ ⁂ var C.∘ var) C.∘ assocʳ ≈⟨ C.∘-resp-≈ʳ (C.∘-resp-≈ˡ (⁂-cong₂ isoˡ C.identity²)) ⟩ assocˡ C.∘ (var ⁂ var) C.∘ assocʳ ≈⟨ elim-center id⁂id ⟩ assocˡ C.∘ assocʳ ≈⟨ assocˡ∘assocʳ ⟩ var ∎ where open TermReasoning isoʳ : forall {Γ Δ} -> F₀/*⇒++ C.∘ F₀/++⇒* {Γ = Γ} C.≈ C.id {A = F₀ (Δ ++ Γ)} isoʳ {Γ} {[]} = trans comm/fst (trans (cong/fst (var/ext _ _)) (beta/*₁ _ _)) isoʳ {Γ} {A ∷ Δ} = begin ((F₀/*⇒++ ⁂ var) C.∘ assocʳ) C.∘ (assocˡ C.∘ (F₀/++⇒* ⁂ var)) ≈⟨ cancelInner assocʳ∘assocˡ ⟩ (F₀/*⇒++ ⁂ var) C.∘ (F₀/++⇒* ⁂ var) ≈⟨ ⁂∘⁂ ⟩ F₀/*⇒++ C.∘ F₀/++⇒* ⁂ var C.∘ var ≈⟨ ⁂-cong₂ isoʳ C.identity² ⟩ var ⁂ var ≈⟨ id⁂id ⟩ var ∎ where open TermReasoning F₁p : forall {Γ Δ} -> F₀ (Δ ++ Γ) ∷ [] ⊢ F₀ Γ F₁p = fst var C.∘ F₀/++⇒* F₁q : forall {Γ Δ} -> F₀ (Δ ++ Γ) ∷ [] ⊢ F₀ Δ F₁q = snd var C.∘ F₀/++⇒* F₁ : forall {Γ Δ : Context} -> ren Γ Δ -> F₀ Γ ∷ [] ⊢ F₀ Δ F₁ Renaming.id = C.id F₁ (r Renaming.∙ r₁) = F₁ r C.∘ F₁ r₁ F₁ Renaming.! = unit F₁ Renaming.⟪ r , r₁ ⟫ = F₀/*⇒++ C.∘ pair (F₁ r) (F₁ r₁) F₁ Renaming.p = F₁p F₁ Renaming.q = F₁q homomorphism : forall {Γ₁ Γ₂ Γ₃} (f : ren Γ₁ Γ₂) (g : ren Γ₂ Γ₃) -> F₀ Γ₁ ∷ [] ⊢ F₁ g [ ext ! (F₁ f) ] ≡ F₁ g [ ext ! (F₁ f) ] homomorphism f g = refl F-resp-≈ : forall {Γ Δ} {f g : ren Γ Δ} -> f ≐ g -> F₀ Γ ∷ [] ⊢ F₁ f ≡ F₁ g F-resp-≈ _≐_.refl = refl F-resp-≈ (_≐_.sym x) = sym (F-resp-≈ x) F-resp-≈ (_≐_.trans x x₁) = trans (F-resp-≈ x) (F-resp-≈ x₁) F-resp-≈ _≐_.identityˡ = var/ext _ _ F-resp-≈ _≐_.identityʳ = trans (cong/sub (trans (cong/ext !-unique refl) η-pair) refl) sub/id F-resp-≈ _≐_.assoc = C.assoc F-resp-≈ _≐_.!-unique = eta/Unit _ F-resp-≈ _≐_.β₁/⟪⟫ = trans (cancelInner (Iso.isoˡ (_≅_.iso F₀/*≅++))) project₁ F-resp-≈ _≐_.β₂/⟪⟫ = trans (cancelInner (Iso.isoˡ (_≅_.iso F₀/*≅++))) project₂ F-resp-≈ _≐_.η/⟪⟫ = trans (C.∘-resp-≈ʳ (trans (⟨⟩-cong₂ C.assoc C.assoc) g-η)) (cancelˡ (Iso.isoʳ (_≅_.iso F₀/*≅++))) F-resp-≈ (_≐_.cong/∙ x x₁) = cong/sub (cong/ext refl (F-resp-≈ x₁)) (F-resp-≈ x) F-resp-≈ (_≐_.cong/⟪⟫ x x₁) = cong/sub (cong/ext refl (cong/pair (F-resp-≈ x) (F-resp-≈ x₁))) refl
36.153285
121
0.500101
139b88a81521ae394d8a361da71adb80c70b0984
141
agda
Agda
test/Succeed/Issue2666.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue2666.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue2666.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module _ where module G where module H where module A where module B where module C where open G public module I = A.B.C.H
10.846154
19
0.666667
22f957a6e4929ad31a26b0f9eb65d5024ad8e4e2
302
agda
Agda
test/Fail/IrrelevantLevelToSet.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/IrrelevantLevelToSet.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/IrrelevantLevelToSet.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --experimental-irrelevance #-} {-# OPTIONS --universe-polymorphism #-} module IrrelevantLevelToSet where open import Common.Level renaming (lsuc to suc) -- should fail, because Set i /= Set j for i /= j, so i is not irrelevant in Set i MySet : .(i : Level) -> Set (suc i) MySet i = Set i
30.2
82
0.688742
2e8f34ecbd0d2043ef448c760a59ee801cbd2723
8,514
agda
Agda
misc/Parallel.agda
yurrriq/parser-combinators
b396d35cc2cb7e8aea50b982429ee385f001aa88
[ "MIT" ]
7
2016-12-13T05:23:14.000Z
2021-06-22T05:35:31.000Z
misc/Parallel.agda
nad/parser-combinators
76774f54f466cfe943debf2da731074fe0c33644
[ "MIT" ]
1
2018-01-22T22:21:41.000Z
2018-01-24T16:39:37.000Z
misc/Parallel.agda
nad/parser-combinators
76774f54f466cfe943debf2da731074fe0c33644
[ "MIT" ]
null
null
null
{-# OPTIONS --no-termination-check #-} ------------------------------------------------------------------------ -- A terminating parser data type and the accompanying interpreter ------------------------------------------------------------------------ -- This code is based on "Parallel Parsing Processes" by Koen -- Claessen. module Parallel where open import Parallel.Index open import Data.Product renaming (_,_ to pair) open import Data.Bool open import Data.Nat open import Data.Product.Record using (_,_) import Data.List as List open List using (List; []; _∷_; _++_) import Data.Vec as Vec open Vec using (Vec; []; _∷_) renaming (_++_ to _<+>_) open import Category.Monad.State open import Data.Function open import Data.Maybe import Relation.Binary.PropositionalEquality as PropEq open PropEq using (_≡_; refl) ------------------------------------------------------------------------ -- Parser monad P : Set -> (Set -> Set) P tok = StateT (List tok) List ------------------------------------------------------------------------ -- Basic parsers (no CPS) private module Base where -- returnPlus below takes a _vector_ of immediate results, since -- otherwise the returnPlus/returnPlus case of _∣_ would not type -- check. (Its type would have to be changed.) -- -- (The vector could just as well have been a list, if it were not -- for the unused module IncorrectBind below. However, documenting -- that this list is never empty is not a bad thing, and does not -- cost much.) codata Parser (tok r : Set) : Index -> Set where symbolBind : forall {i : tok -> Index} -> ((c : tok) -> Parser tok r (i c)) -> Parser tok r 0I fail : Parser tok r 0I returnPlus : forall {e d n} -> Vec r (suc n) -> Parser tok r (e , d) -> Parser tok r (true , suc d) -- Note that the type of this return function is not suitable if you -- want to state the monad laws (since (true , 1) is not a zero in -- the monoid which is used here). The return function defined below -- has a more suitable type, though. return : forall {tok r} -> r -> Parser tok r (true , 1) return x = returnPlus (Vec.[_] x) fail cast : forall {tok i₁ i₂ r} -> i₁ ≡ i₂ -> Parser tok r i₁ -> Parser tok r i₂ cast refl p = p infixl 0 _∣_ _∣_ : forall {tok r i₁ i₂} -> Parser tok r i₁ -> Parser tok r i₂ -> Parser tok r (i₁ ∣I i₂) fail ∣ p₂ ~ p₂ returnPlus xs p₁ ∣ fail ~ returnPlus xs p₁ symbolBind f₁ ∣ fail ~ symbolBind f₁ symbolBind f₁ ∣ symbolBind f₂ ~ symbolBind (\c -> f₁ c ∣ f₂ c) symbolBind f₁ ∣ returnPlus xs p₂ ~ returnPlus xs (symbolBind f₁ ∣ p₂) returnPlus xs p₁ ∣ symbolBind f₂ ~ returnPlus xs (symbolBind f₂ ∣ p₁) returnPlus xs₁ p₁ ∣ returnPlus xs₂ p₂ ~ returnPlus (xs₁ <+> xs₂) (p₁ ∣ p₂) -- parse is structurally recursive over the following lexicographic -- measure: -- -- ⑴ The input string. -- ⑵ The Distance index. parse : forall {tok r e d} -> Parser tok r (e , d) -> P tok r parse (symbolBind f) (c ∷ s) = parse (f c) s parse (symbolBind f) [] = [] parse fail _ = [] parse (returnPlus xs p) s = List.map (\x -> pair x s) (Vec.toList xs) ++ parse p s -- It may be interesting to note that it is hard to define bind -- directly. Note that the module Incorrect is not used for -- anything; bind is defined further down using CPS. private module IncorrectBind where -- choice ≈ foldr₁ _∣_. choice : forall {tok r i n} -> Vec (Parser tok r i) (suc n) -> Parser tok r i choice {i = i} = Vec.foldr₁ (\p₁ p₂ -> cast (∣-idempotent i) (p₁ ∣ p₂)) where open IndexSemiring -- This function is used to state the type of bind. bind-index : forall {tok r i} -> Parser tok r i -> Index -> Index bind-index (symbolBind f) _ = 0I bind-index fail _ = 0I bind-index (returnPlus xs p) i = i open IndexSemiring bind-index-lemma : forall {tok r i₁} (p : Parser tok r i₁) i₂ -> i₂ ∣I bind-index p i₂ ≡ i₂ bind-index-lemma (symbolBind f) i = proj₂ +-identity i bind-index-lemma fail i = proj₂ +-identity i bind-index-lemma (returnPlus xs p) i = ∣-idempotent i -- Note that bind has a non-trivial type. This is not a -- fundamental problem, though. The big problem is that bind is -- not productive (in general). The recursive call p >>= g in the -- last line is not guarded if, for instance, g = const fail, in -- which case we have (ignoring some casts) -- -- returnPlus xs p >>= g = p >>= g. -- -- If furthermore p = returnPlus xs p, then we have a real -- problem. _>>=_ : forall {tok r₁ r₂ i₁ i₂} -> (p₁ : Parser tok r₁ i₁) -> (r₁ -> Parser tok r₂ i₂) -> Parser tok r₂ (bind-index p₁ i₂) symbolBind f >>= g ~ symbolBind (\c -> f c >>= g) fail >>= g ~ fail returnPlus xs p >>= g ~ cast (bind-index-lemma p _) (choice (Vec.map g xs) ∣ p >>= g) ------------------------------------------------------------------------ -- CPS transformation -- The code below manually applies the continuation-passing monad -- transformer to the Base parser above to improve the efficiency of -- left-nested uses of bind. (And, in light of Base.Incorrect._>>=_, -- to enable a well-founded definition of bind.) data Parser (tok : Set) (i : Index) (r : Set) : Set1 where parser : (forall {i' r'} -> (r -> Base.Parser tok r' i') -> Base.Parser tok r' (i ·I i')) -> Parser tok i r private unP : forall {tok r i r' i'} -> Parser tok i r -> (r -> Base.Parser tok r' i') -> Base.Parser tok r' (i ·I i') unP (parser p) = p symbol : forall {tok} -> Parser tok 0I tok symbol = parser Base.symbolBind fail : forall {tok r} -> Parser tok 0I r fail = parser \k -> Base.fail -- A problematic variant of fail. See Parallel.Lib. problematic : forall {tok r} -> r -> Parser tok 0I r problematic x = parser (\k -> helper (k x)) where helper : forall {tok r' i'} -> Base.Parser tok r' i' -> Base.Parser tok r' 0I helper (Base.symbolBind _) = Base.fail helper Base.fail = Base.fail helper (Base.returnPlus _ _) = Base.fail return : forall {tok r} -> r -> Parser tok 1I r return x = parser \k -> k x -- Note that _>>=_ cannot easily be given a dependent type (where the -- second argument has type (x : r₁) -> Parser tok r₂ (i₂ x)). What -- would the type of the result of _>>=_ be? The type would depend on -- the input string, which is not an argument to _>>=_. -- -- Note also that the variant _!>>=_ from Parser/RecursiveDescent.Coinductive -- cannot (?) be implemented, since the continuation given to p cannot -- be dependently typed. infixl 1 _>>=_ _>>=_ : forall {tok r₁ r₂ i₁ i₂} -> Parser tok i₁ r₁ -> (r₁ -> Parser tok i₂ r₂) -> Parser tok (i₁ ·I i₂) r₂ _>>=_ {i₁ = i₁} {i₂} (parser p) f = parser \{i₃} k -> Base.cast (sym $ *-assoc i₁ i₂ i₃) (p \x -> unP (f x) k) where open IndexSemiring infixl 0 _∣_ _∣_ : forall {tok r i₁ i₂} -> Parser tok i₁ r -> Parser tok i₂ r -> Parser tok (i₁ ∣I i₂) r _∣_ {i₁ = i₁} {i₂ = i₂} (parser p₁) (parser p₂) = parser \{i₃} k -> Base.cast (sym $ proj₂ distrib i₃ i₁ i₂) (Base._∣_ (p₁ k) (p₂ k)) where open IndexSemiring -- Since _>>=_ has a non-dependent type it is hard to define sat -- without using the underlying parsers in Base, and hence sat is -- provided here. sat : forall {tok r} -> (tok -> Maybe r) -> Parser tok 0I r sat {tok} {r} p = parser \k -> Base.symbolBind (\c -> ok k (p c)) where okIndex : Index -> Maybe r -> Index okIndex i' nothing = 0I okIndex i' (just _) = i' ok : forall {r' i'} -> (r -> Base.Parser tok r' i') -> (x : Maybe r) -> Base.Parser tok r' (okIndex i' x) ok k nothing = Base.fail ok k (just x) = k x parse : forall {tok r i} -> Parser tok i r -> P tok r parse (parser p) = Base.parse (p Base.return) -- A variant which only returns parses which leave no remaining input. parse-complete : forall {tok r i} -> Parser tok i r -> List tok -> List r parse-complete p s = List.map proj₁ (List.filter (List.null ∘ proj₂) (parse p s))
34.469636
77
0.572586
57d613fced6e5a76a86bb1cdd06767a73fc30c42
1,112
agda
Agda
Test.agda
jmchapman/agda2hs
0f8b0b8a17ecad9e9be7ef5cae564187787df31d
[ "MIT" ]
null
null
null
Test.agda
jmchapman/agda2hs
0f8b0b8a17ecad9e9be7ef5cae564187787df31d
[ "MIT" ]
null
null
null
Test.agda
jmchapman/agda2hs
0f8b0b8a17ecad9e9be7ef5cae564187787df31d
[ "MIT" ]
null
null
null
module _ where open import Agda.Builtin.List open import Agda.Builtin.Nat open import Agda.Builtin.Equality variable a b : Set {-# FOREIGN AGDA2HS import Prelude hiding (map, sum) #-} data Exp (v : Set) : Set where Plus : Exp v → Exp v → Exp v Int : Nat → Exp v Var : v → Exp v {-# COMPILE AGDA2HS Exp #-} eval : (a → Nat) → Exp a → Nat eval env (Plus a b) = eval env a + eval env b eval env (Int n) = n eval env (Var x) = env x {-# COMPILE AGDA2HS eval #-} sum : List Nat → Nat sum [] = 0 sum (x ∷ xs) = x + sum xs {-# COMPILE AGDA2HS sum #-} {-# FOREIGN AGDA2HS -- comment #-} append : List a → List a → List a append [] ys = ys append (x ∷ xs) ys = x ∷ append xs ys {-# COMPILE AGDA2HS append #-} map : (a → b) → List a → List b map f [] = [] map f (x ∷ xs) = f x ∷ map f xs {-# COMPILE AGDA2HS map #-} assoc : (a b c : Nat) → a + (b + c) ≡ (a + b) + c assoc zero b c = refl assoc (suc a) b c rewrite assoc a b c = refl thm : ∀ xs ys → sum (append xs ys) ≡ sum xs + sum ys thm [] ys = refl thm (x ∷ xs) ys rewrite thm xs ys | assoc x (sum xs) (sum ys) = refl
19.508772
68
0.571043
046f0745ec5b52593b9418461322b5c82cbe70b5
6,856
agda
Agda
Cubical/Data/Fin/Properties.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Data/Fin/Properties.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Data/Fin/Properties.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.Data.Fin.Properties where open import Cubical.Core.Everything open import Cubical.Functions.Embedding open import Cubical.Foundations.Function open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Prelude open import Cubical.Foundations.Univalence open import Cubical.Data.Fin.Base as Fin open import Cubical.Data.Nat open import Cubical.Data.Nat.Order open import Cubical.Data.Empty as Empty open import Cubical.Data.Sum open import Cubical.Data.Sigma open import Cubical.Induction.WellFounded private variable a b ℓ : Level A : Type a -- Fin 0 is empty, and thus a proposition. isPropFin0 : isProp (Fin 0) isPropFin0 = Empty.rec ∘ ¬Fin0 -- Fin 1 has only one value. isContrFin1 : isContr (Fin 1) isContrFin1 = fzero , λ { (zero , _) → toℕ-injective refl ; (suc k , sk<1) → Empty.rec (¬-<-zero (pred-≤-pred sk<1)) } -- Regardless of k, Fin k is a set. isSetFin : ∀{k} → isSet (Fin k) isSetFin {k} = isSetΣ isSetℕ (λ _ → isProp→isSet m≤n-isProp) private subst-app : (B : A → Type b) (f : (x : A) → B x) {x y : A} (x≡y : x ≡ y) → subst B x≡y (f x) ≡ f y subst-app B f {x = x} = J (λ y e → subst B e (f x) ≡ f y) (substRefl {B = B} (f x)) -- Computation rules for the eliminator. module _ (P : ∀ {k} → Fin k → Type ℓ) (fz : ∀ {k} → P {suc k} fzero) (fs : ∀ {k} {fn : Fin k} → P fn → P (fsuc fn)) {k : ℕ} where elim-fzero : Fin.elim P fz fs {k = suc k} fzero ≡ fz elim-fzero = subst P (toℕ-injective _) fz ≡⟨ cong (λ p → subst P p fz) (isSetFin _ _ _ _) ⟩ subst P refl fz ≡⟨ substRefl {B = P} fz ⟩ fz ∎ elim-fsuc : (fk : Fin k) → Fin.elim P fz fs (fsuc fk) ≡ fs (Fin.elim P fz fs fk) elim-fsuc fk = subst P (toℕ-injective (λ _ → toℕ (fsuc fk′))) (fs (Fin.elim P fz fs fk′)) ≡⟨ cong (λ p → subst P p (fs (Fin.elim P fz fs fk′)) ) (isSetFin _ _ _ _) ⟩ subst P (cong fsuc fk′≡fk) (fs (Fin.elim P fz fs fk′)) ≡⟨ subst-app _ (λ fj → fs (Fin.elim P fz fs fj)) fk′≡fk ⟩ fs (Fin.elim P fz fs fk) ∎ where fk′ = fst fk , pred-≤-pred (snd (fsuc fk)) fk′≡fk : fk′ ≡ fk fk′≡fk = toℕ-injective refl -- Helper function for the reduction procedure below. -- -- If n = expand o k m, then n is congruent to m modulo k. expand : ℕ → ℕ → ℕ → ℕ expand 0 k m = m expand (suc o) k m = k + expand o k m expand≡ : ∀ k m o → expand o k m ≡ o * k + m expand≡ k m zero = refl expand≡ k m (suc o) = cong (k +_) (expand≡ k m o) ∙ +-assoc k (o * k) m -- Expand a pair. This is useful because the whole function is -- injective. expand× : ∀{k} → (Fin k × ℕ) → ℕ expand× {k} (f , o) = expand o k (toℕ f) private lemma₀ : ∀{k m n r} → r ≡ n → k + m ≡ n → k ≤ r lemma₀ {k = k} {m} p q = m , +-comm m k ∙ q ∙ sym p expand×Inj : ∀ k → {t1 t2 : Fin (suc k) × ℕ} → expand× t1 ≡ expand× t2 → t1 ≡ t2 expand×Inj k {f1 , zero} {f2 , zero} p i = toℕ-injective {fj = f1} {f2} p i , zero expand×Inj k {f1 , suc o1} {(r , r<sk) , zero} p = Empty.rec (<-asym r<sk (lemma₀ refl p)) expand×Inj k {(r , r<sk) , zero} {f2 , suc o2} p = Empty.rec (<-asym r<sk (lemma₀ refl (sym p))) expand×Inj k {f1 , suc o1} {f2 , suc o2} = cong (λ { (f , o) → (f , suc o) }) ∘ expand×Inj k {f1 , o1} {f2 , o2} ∘ inj-m+ {suc k} expand×Emb : ∀ k → isEmbedding (expand× {k}) expand×Emb 0 = Empty.rec ∘ ¬Fin0 ∘ fst expand×Emb (suc k) = injEmbedding (isSetΣ isSetFin (λ _ → isSetℕ)) isSetℕ (expand×Inj k) -- A Residue is a family of types representing evidence that a -- natural is congruent to a value of a finite type. Residue : ℕ → ℕ → Type₀ Residue k n = Σ[ tup ∈ Fin k × ℕ ] expand× tup ≡ n extract : ∀{k n} → Residue k n → Fin k extract = fst ∘ fst -- There is at most one canonical finite value congruent to each -- natural. isPropResidue : ∀ k n → isProp (Residue k n) isPropResidue k = isEmbedding→hasPropFibers (expand×Emb k) -- A value of a finite type is its own residue. Fin→Residue : ∀{k} → (f : Fin k) → Residue k (toℕ f) Fin→Residue f = (f , 0) , refl -- Fibers of numbers that differ by k are equivalent in a more obvious -- way than via the fact that they are propositions. Residue+k : (k n : ℕ) → Residue k n → Residue k (k + n) Residue+k k n ((f , o) , p) = (f , suc o) , cong (k +_) p Residue-k : (k n : ℕ) → Residue k (k + n) → Residue k n Residue-k k n (((r , r<k) , zero) , p) = Empty.rec (<-asym r<k (lemma₀ p refl)) Residue-k k n ((f , suc o) , p) = ((f , o) , inj-m+ p) Residue+k-k : (k n : ℕ) → (R : Residue k (k + n)) → Residue+k k n (Residue-k k n R) ≡ R Residue+k-k k n (((r , r<k) , zero) , p) = Empty.rec (<-asym r<k (lemma₀ p refl)) Residue+k-k k n ((f , suc o) , p) = Σ≡Prop (λ tup → isSetℕ (expand× tup) (k + n)) refl Residue-k+k : (k n : ℕ) → (R : Residue k n) → Residue-k k n (Residue+k k n R) ≡ R Residue-k+k k n ((f , o) , p) = Σ≡Prop (λ tup → isSetℕ (expand× tup) n) refl private Residue≃ : ∀ k n → Residue k n ≃ Residue k (k + n) Residue≃ k n = Residue+k k n , isoToIsEquiv (iso (Residue+k k n) (Residue-k k n) (Residue+k-k k n) (Residue-k+k k n)) Residue≡ : ∀ k n → Residue k n ≡ Residue k (k + n) Residue≡ k n = ua (Residue≃ k n) -- For positive `k`, all `n` have a canonical residue mod `k`. module Reduce (k₀ : ℕ) where k : ℕ k = suc k₀ base : ∀ n (n<k : n < k) → Residue k n base n n<k = Fin→Residue (n , n<k) step : ∀ n → Residue k n → Residue k (k + n) step n = transport (Residue≡ k n) reduce : ∀ n → Residue k n reduce = +induction k₀ (Residue k) base step reduce≡ : ∀ n → transport (Residue≡ k n) (reduce n) ≡ reduce (k + n) reduce≡ n = sym (+inductionStep k₀ _ base step n) reduceP : ∀ n → PathP (λ i → Residue≡ k n i) (reduce n) (reduce (k + n)) reduceP n = toPathP (reduce≡ n) open Reduce using (reduce; reduce≡) public private lemma₅ : ∀ k n (R : Residue k n) → extract R ≡ extract (transport (Residue≡ k n) R) lemma₅ k n = sym ∘ cong extract ∘ uaβ (Residue≃ k n) -- The residue of n modulo k is the same as the residue of k + n. extract≡ : ∀ k n → extract (reduce k n) ≡ extract (reduce k (suc k + n)) extract≡ k n = lemma₅ (suc k) n (reduce k n) ∙ cong extract (Reduce.reduce≡ k n) isContrResidue : ∀{k n} → isContr (Residue (suc k) n) isContrResidue {k} {n} = inhProp→isContr (reduce k n) (isPropResidue (suc k) n) -- the modulo operator on ℕ _%_ : ℕ → ℕ → ℕ n % zero = n n % (suc k) = toℕ (extract (reduce k n)) n%k≡n[modk] : ∀ n k → Σ[ o ∈ ℕ ] o * k + n % k ≡ n n%k≡n[modk] n zero = zero , refl n%k≡n[modk] n (suc k) = o , sym (expand≡ _ _ o) ∙ reduce k n .snd where o = reduce k n .fst .snd n%sk<sk : (n k : ℕ) → (n % suc k) < suc k n%sk<sk n k = extract (reduce k n) .snd
31.740741
82
0.58241
0b368956c4f9a2ff926ef1af52856caeea7c34ca
18,202
agda
Agda
Formalization/Polynomial.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Formalization/Polynomial.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Formalization/Polynomial.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
module Formalization.Polynomial where import Lvl open import Data.ListSized open import Numeral.Natural as ℕ using (ℕ) open import Type private variable ℓ ℓₑ : Lvl.Level private variable T : Type{ℓ} private variable n n₁ n₂ : ℕ -- TODO: Some of the operations should work with arbitrary Rg structures, not just ℕ, and some other stuff should work with more assumptions. Currently, one of the function that needs to be modified is 𝐷 and normalize for this to work because their implementations depend on ℕ. -- TODO: Composition of polynomials, power operation module _ where -- A polynomial of a finite degree represented as a list of its coefficients. -- Examples: -- (a₀⋅x⁰ + a₁⋅x¹ + a₂⋅x² + a₃⋅x³ + a₄⋅x⁴) of degree 4 is [a₀,a₁,a₂,a₃,a₄] -- (5 + 7⋅x + x³) of maximal degree 3 is [5,7,0,1] Polynomial : ℕ → Type Polynomial(n) = List(ℕ)(ℕ.𝐒(n)) open import Data.ListSized.Functions import Functional as Fn open import Logic.Propositional open import Logic.Predicate import Numeral.Natural.Function as ℕ open import Numeral.Natural.Function.Proofs import Numeral.Natural.Oper as ℕ open import Numeral.Natural.Relation.Order open import Numeral.Natural.Relation.Order.Proofs open import Relator.Equals open import Relator.Equals.Proofs.Equiv{T = ℕ} -- Constant polynomial. -- Semantically, this corresponds to a constant. const : ℕ → Polynomial(n) const {n} a = a ⊰ repeat ℕ.𝟎 n -- Zero polynomial. -- Semantically, this corresponds to zero. 𝟎 : Polynomial(n) 𝟎 {n} = const{n} ℕ.𝟎 -- Unit polynomial. -- Semantically, this corresponds to one. 𝟏 : Polynomial(n) 𝟏 {n} = const{n}(ℕ.𝐒(ℕ.𝟎)) -- Increases the degree of the polynomial by adding a zero term at the beginning. -- Semantically, this corresponds to multiplying the whole polynomial by the variable. -- Example: (var⋅ [a₀,a₁,a₂] = [0,a₀,a₁,a₂]) -- x ⋅ (a₀⋅x⁰ + a₁⋅x¹ + a₂⋅x²) -- = a₀⋅x¹ + a₁⋅x² + a₂⋅x³ var⋅_ : Polynomial(n) → Polynomial(ℕ.𝐒(n)) var⋅_ = ℕ.𝟎 ⊰_ -- Single variable polynomial. var : Polynomial(ℕ.𝐒(n)) var = var⋅ 𝟏 -- Polynomial addition. -- Adds the powers component-wise. -- Examples: ([a₀,a₁,a₂] + [b₀,b₁,b₂] = [a₀b₀ , a₁+b₁ , a₂+b₂]) -- (a₀⋅x⁰ + a₁⋅x¹ + a₂⋅x²) + (b₀⋅x⁰ + b₁⋅x¹ + b₂⋅x²) -- = (a₀+b₀)⋅x⁰ + (a₁+b₁)⋅x¹ + (a₂+b₂)⋅x² -- of maximal degree 2 is [a₀+b₀ , a₁+b₁ , a₂+b₂] _+_ : Polynomial(n₁) → Polynomial(n₂) → Polynomial(ℕ.max n₁ n₂) _+_ = map₂(ℕ._+_) Fn.id Fn.id -- Polymonial scalar multiplication. -- Multiplies every component by a factor. -- Example: (n ⋅ [a₀,a₁,a₂] = [n⋅a₀ , n⋅a₁ , n⋅a₂]) -- n ⋅ (a₀⋅x⁰ + a₁⋅x¹ + a₂⋅x²) -- = (n⋅a₀)⋅x⁰ + (n⋅a₁)⋅x¹ + (n⋅a₂)⋅x² _⋅_ : ℕ → Polynomial(n) → Polynomial(n) n ⋅ as = map (n ℕ.⋅_) as -- Increases the degree of the polynomial by adding zero terms at the end. -- Semantically, this corresponds to adding terms multiplied by zero. -- Example: (pad [a₀,a₁,a₂] = [a₀,a₁,a₂,0,0]) -- a₀⋅x⁰ + a₁⋅x¹ + a₂⋅x² -- = a₀⋅x⁰ + a₁⋅x¹ + a₂⋅x² + 0⋅x³ + 0⋅x⁴ pad : ⦃ _ : (n₁ ≤ n₂)⦄ → Polynomial(n₁) → Polynomial(n₂) pad {n₁ = ℕ.𝟎} {n₂ = ℕ.𝟎} ⦃ min ⦄ (a ⊰ ∅) = singleton a pad {n₁ = ℕ.𝟎} {n₂ = ℕ.𝐒(n₂)} ⦃ min ⦄ (a ⊰ ∅) = a ⊰ 𝟎 pad {n₁ = ℕ.𝐒(n₁)} {n₂ = ℕ.𝐒(n₂)} ⦃ succ p ⦄ (a ⊰ as) = a ⊰ pad ⦃ p ⦄ as -- Polynomial multiplication. -- Proof of step: -- ∑(0‥𝐒(n₁))(i ↦ aᵢ⋅xⁱ) ⋅ ∑(0‥𝐒(n₂))(i ↦ bᵢ⋅xⁱ) -- = (a + ∑(1‥𝐒(n₁))(i ↦ aᵢ⋅xⁱ)) ⋅ (b + ∑(1‥𝐒(n₂))(i ↦ bᵢ⋅xⁱ)) -- = (a ⋅ b) + (a ⋅ ∑(1‥𝐒(n₂))(i ↦ bᵢ⋅xⁱ)) + (∑(1‥𝐒(n₁))(i ↦ aᵢ⋅xⁱ) ⋅ b) + (∑(1‥𝐒(n₁))(i ↦ aᵢ⋅xⁱ) ⋅ ∑(1‥𝐒(n₂))(i ↦ bᵢ⋅xⁱ)) -- = (a⋅b) + (a ⋅ ∑(1‥𝐒(n₂))(i ↦ bᵢ⋅xⁱ)) + (∑(1‥𝐒(n₁))(i ↦ aᵢ⋅xⁱ) ⋅ b⋅x) + (∑(1‥𝐒(n₁))(i ↦ aᵢ⋅xⁱ) ⋅ ∑(1‥𝐒(n₂))(i ↦ bᵢ⋅xⁱ)) -- = (a⋅b) + (a ⋅ ∑(0‥n₂)(i ↦ bᵢ⋅xⁱ)⋅x) + (∑(0‥n₁)(i ↦ aᵢ⋅xⁱ)⋅x ⋅ b) + (∑(1‥𝐒(n₁))(i ↦ aᵢ⋅xⁱ) ⋅ ∑(1‥𝐒(n₂))(i ↦ bᵢ⋅xⁱ)) -- = (a⋅b) + (a ⋅ ∑(0‥n₂)(i ↦ bᵢ⋅xⁱ))⋅x + (∑(0‥n₁)(i ↦ aᵢ⋅xⁱ) ⋅ b)⋅x + (∑(0‥n₁)(i ↦ aᵢ⋅xⁱ) ⋅ ∑(0‥n₂)(i ↦ bᵢ⋅xⁱ))⋅x² -- = (a⋅b) + ((a ⋅ ∑(0‥n₂)(i ↦ bᵢ⋅xⁱ)) + (∑(0‥n₁)(i ↦ aᵢ⋅xⁱ) ⋅ b) + (∑(0‥n₁)(i ↦ aᵢ⋅xⁱ) ⋅ ∑(0‥n₂)(i ↦ bᵢ⋅xⁱ))⋅x)⋅x -- Also see `eval-preserves-multiplication`. _⨯_ : Polynomial(n₁) → Polynomial(n₂) → Polynomial(n₁ ℕ.+ n₂) _⨯_ as@(_ ⊰ _) (b ⊰ ∅) = b ⋅ as _⨯_ (a ⊰ ∅) bs@(_ ⊰ _ ⊰ _) = a ⋅ bs _⨯_ {ℕ.𝐒 n₁}{ℕ.𝐒 n₂} (a ⊰ as@(_ ⊰ _)) (b ⊰ bs@(_ ⊰ _)) = (a ℕ.⋅ b) ⊰ lr where l : Polynomial(n₁ ℕ.+ n₂) l = pad ⦃ max-order-[+] ⦄ ((b ⋅ as) + (a ⋅ bs)) r : Polynomial(ℕ.𝐒(n₁ ℕ.+ n₂)) r = var⋅ (as ⨯ bs) lr : Polynomial(ℕ.𝐒(n₁ ℕ.+ n₂)) lr = [≡]-substitutionᵣ ([↔]-to-[→] max-defᵣ [≤]-of-[𝐒]) {Polynomial} (l + r) normalize : Polynomial(n) → ∃(Polynomial) normalize {ℕ.𝟎} (x ⊰ ∅) = [∃]-intro ℕ.𝟎 ⦃ x ⊰ ∅ ⦄ normalize {ℕ.𝐒 n} (ℕ.𝟎 ⊰ p) with normalize{n} p ... | [∃]-intro ℕ.𝟎 ⦃ singleton ℕ.𝟎 ⦄ = [∃]-intro ℕ.𝟎 ⦃ singleton ℕ.𝟎 ⦄ {-# CATCHALL #-} ... | [∃]-intro m ⦃ a ⦄ = [∃]-intro (ℕ.𝐒(m)) ⦃ ℕ.𝟎 ⊰ a ⦄ normalize {ℕ.𝐒 n} (ℕ.𝐒(x) ⊰ p) = [∃]-map ℕ.𝐒 (ℕ.𝐒(x) ⊰_) (normalize{n} p) degree : Polynomial(n) → ℕ degree = [∃]-witness Fn.∘ normalize 𝐷 : Polynomial(n) → Polynomial(ℕ.𝐏(n)) 𝐷 {ℕ.𝟎} = Fn.id 𝐷 {ℕ.𝐒 n} = map₂₌(ℕ._⋅_) (accumulateIterate n ℕ.𝐒(ℕ.𝐒(ℕ.𝟎))) Fn.∘ tail import Numeral.Natural.Oper.FlooredDivision as ℕ ∫ : Polynomial(n) → Polynomial(ℕ.𝐒(n)) ∫ {n} p = var⋅(map₂₌(ℕ._⌊/⌋₀_) p (accumulateIterate n ℕ.𝐒(ℕ.𝐒(ℕ.𝟎)))) module Semantics where open import Data.ListSized.Functions open import Logic.Propositional open import Numeral.Finite as 𝕟 using (𝕟) import Numeral.Natural.Oper as ℕ open import Numeral.Natural.Oper.Proofs open import Numeral.Natural.Relation.Order open import Relator.Equals.Proofs.Equiv{T = ℕ} open import Structure.Function.Multi open import Structure.Operator open import Structure.Operator.Proofs.Util open import Structure.Operator.Properties open import Structure.Relator.Properties open import Structure.Setoid open import Syntax.Function open import Syntax.Transitivity eval : Polynomial(n) → (ℕ → ℕ) eval (singleton a) _ = a eval (a ⊰ al@(_ ⊰ _)) x = a ℕ.+ (x ℕ.⋅ (eval al x)) module Proofs where eval-of-[⊰] : ∀{x}{a}{al : Polynomial(n)} → (eval (a ⊰ al) x ≡ a ℕ.+ (x ℕ.⋅ (eval al x))) eval-of-[⊰] {ℕ.𝟎} {x} {a} {b ⊰ ∅} = reflexivity(_≡_) eval-of-[⊰] {ℕ.𝐒 n} {x} {a} {b ⊰ c ⊰ al} = reflexivity(_≡_) eval-preserves-var⋅ : ∀{x}{a : Polynomial(n)} → (eval (var⋅ a) x ≡ x ℕ.⋅ (eval a x)) eval-preserves-var⋅ {n}{x}{a} = eval-of-[⊰] {n}{x}{ℕ.𝟎}{a} eval-preserves-zero : ∀{x} → (eval{n} 𝟎 x ≡ ℕ.𝟎) eval-preserves-zero {ℕ.𝟎} {x} = reflexivity(_≡_) eval-preserves-zero {ℕ.𝐒 n} {x} = eval(𝟎 {ℕ.𝐒 n}) x 🝖[ _≡_ ]-[] eval(ℕ.𝟎 ⊰ 𝟎 {n}) x 🝖[ _≡_ ]-[] ℕ.𝟎 ℕ.+ (x ℕ.⋅ eval (𝟎 {n}) x) 🝖[ _≡_ ]-[] x ℕ.⋅ eval (𝟎 {n}) x 🝖[ _≡_ ]-[ congruence₂ᵣ(ℕ._⋅_)(x) (eval-preserves-zero{n}{x}) ] x ℕ.⋅ ℕ.𝟎 🝖[ _≡_ ]-[ absorberᵣ(ℕ._⋅_)(ℕ.𝟎) {x} ] ℕ.𝟎 🝖-end eval-preserves-const : ∀{x}{a} → (eval{n} (const a) x ≡ a) eval-preserves-const {ℕ.𝟎} {x}{a} = reflexivity(_≡_) eval-preserves-const {ℕ.𝐒 n} {x}{a} = eval{ℕ.𝐒 n} (const a) x 🝖[ _≡_ ]-[] eval(a ⊰ repeat ℕ.𝟎 (ℕ.𝐒 n)) x 🝖[ _≡_ ]-[ eval-of-[⊰] {x = x}{a}{repeat ℕ.𝟎 (ℕ.𝐒 n)} ] a ℕ.+ (x ℕ.⋅ eval(repeat ℕ.𝟎 (ℕ.𝐒 n)) x) 🝖[ _≡_ ]-[] a ℕ.+ (x ℕ.⋅ eval{n} 𝟎 x) 🝖[ _≡_ ]-[ congruence₂ᵣ(ℕ._+_)(a) (eval-preserves-zero{ℕ.𝐒 n}{x = x}) ] a ℕ.+ (x ℕ.⋅ ℕ.𝟎) 🝖[ _≡_ ]-[] a ℕ.+ ℕ.𝟎 🝖[ _≡_ ]-[ identityᵣ(ℕ._+_)(ℕ.𝟎) ] a 🝖-end eval-preserves-one : ∀{x} → (eval{n} 𝟏 x ≡ ℕ.𝐒(ℕ.𝟎)) eval-preserves-one {n}{x} = eval-preserves-const {n}{x}{ℕ.𝐒(ℕ.𝟎)} eval-preserves-var : ∀{x}{a : Polynomial(n)} → (eval (var{n}) x ≡ x) eval-preserves-var {n}{x}{a} = eval (var{n}) x 🝖[ _≡_ ]-[ eval-preserves-var⋅{n}{x}{𝟏} ] x ℕ.⋅ eval (𝟏 {n}) x 🝖[ _≡_ ]-[ congruence₂ᵣ(ℕ._⋅_)(x) (eval-preserves-one {n}{x}) ] x ℕ.⋅ ℕ.𝐒(ℕ.𝟎) 🝖[ _≡_ ]-[ identityᵣ(ℕ._⋅_)(ℕ.𝐒(ℕ.𝟎)) {x} ] x 🝖-end eval-preserves-addition : ∀{x}{a : Polynomial(n₁)}{b : Polynomial(n₂)} → (eval (a + b) x ≡ (eval a x) ℕ.+ (eval b x)) eval-preserves-addition {x = x} {singleton a} {singleton b} = reflexivity(_≡_) eval-preserves-addition {x = x} {singleton a} {b ⊰ bs@(_ ⊰ _)} = associativity(ℕ._+_) {a}{b} eval-preserves-addition {x = x} {a ⊰ as@(_ ⊰ _)} {singleton b} = eval ((a ⊰ as) + (singleton b)) x 🝖[ _≡_ ]-[] (a ℕ.+ b) ℕ.+ (x ℕ.⋅ (eval as x)) 🝖[ _≡_ ]-[ associativity(ℕ._+_) {a}{b} ] a ℕ.+ (b ℕ.+ (x ℕ.⋅ (eval as x))) 🝖[ _≡_ ]-[ congruence₂ᵣ(ℕ._+_)(a) (commutativity(ℕ._+_) {x = b}) ] a ℕ.+ ((x ℕ.⋅ (eval as x)) ℕ.+ b) 🝖[ _≡_ ]-[ associativity(ℕ._+_) {a}{x ℕ.⋅ eval as x} ]-sym (a ℕ.+ (x ℕ.⋅ (eval as x))) ℕ.+ b 🝖[ _≡_ ]-[] (eval (a ⊰ as) x) ℕ.+ (eval (singleton b) x) 🝖-end eval-preserves-addition {x = x} {a ⊰ as@(_ ⊰ _)} {b ⊰ bs@(_ ⊰ _)} = eval ((a ⊰ as) + (b ⊰ bs)) x 🝖[ _≡_ ]-[] eval ((a ℕ.+ b) ⊰ (as + bs)) x 🝖[ _≡_ ]-[] (a ℕ.+ b) ℕ.+ (x ℕ.⋅ (eval (as + bs) x)) 🝖[ _≡_ ]-[ congruence₂ᵣ(ℕ._+_)(a ℕ.+ b) (congruence₂ᵣ(ℕ._⋅_)(x) (eval-preserves-addition {x = x}{as}{bs})) ] (a ℕ.+ b) ℕ.+ (x ℕ.⋅ ((eval as x) ℕ.+ (eval bs x))) 🝖[ _≡_ ]-[ congruence₂ᵣ(ℕ._+_)(a ℕ.+ b) (distributivityₗ(ℕ._⋅_)(ℕ._+_) {x}{eval as x}{eval bs x}) ] (a ℕ.+ b) ℕ.+ ((x ℕ.⋅ (eval as x)) ℕ.+ (x ℕ.⋅ (eval bs x))) 🝖[ _≡_ ]-[ One.associate-commute4 {a = a}{b = b}{c = x ℕ.⋅ (eval as x)}{d = x ℕ.⋅ (eval bs x)} (commutativity(ℕ._+_) {b}) ] (a ℕ.+ (x ℕ.⋅ (eval as x))) ℕ.+ (b ℕ.+ (x ℕ.⋅ (eval bs x))) 🝖[ _≡_ ]-[] (eval (a ⊰ as) x) ℕ.+ (eval (b ⊰ bs) x) 🝖-end eval-preserves-scalar-multiplication : ∀{x}{a}{b : Polynomial(n)} → (eval (a ⋅ b) x ≡ a ℕ.⋅ (eval b x)) eval-preserves-scalar-multiplication {ℕ.𝟎} {x} {a} {b ⊰ ∅} = reflexivity(_≡_) eval-preserves-scalar-multiplication {ℕ.𝐒 n} {x} {a} {b ⊰ bs@(_ ⊰ _)} = eval (a ⋅ (b ⊰ bs)) x 🝖[ _≡_ ]-[] eval ((a ℕ.⋅ b) ⊰ (a ⋅ bs)) x 🝖[ _≡_ ]-[] (a ℕ.⋅ b) ℕ.+ (x ℕ.⋅ (eval (a ⋅ bs) x)) 🝖[ _≡_ ]-[ congruence₂ᵣ(ℕ._+_)(a ℕ.⋅ b) (congruence₂ᵣ(ℕ._⋅_)(x) (eval-preserves-scalar-multiplication {n} {x}{a}{bs})) ] (a ℕ.⋅ b) ℕ.+ (x ℕ.⋅ (a ℕ.⋅ (eval bs x))) 🝖[ _≡_ ]-[ congruence₂ᵣ(ℕ._+_)(a ℕ.⋅ b) (One.commuteₗ-assocᵣ {a = x}{b = a}{c = eval bs x}) ] (a ℕ.⋅ b) ℕ.+ (a ℕ.⋅ (x ℕ.⋅ (eval bs x))) 🝖[ _≡_ ]-[ distributivityₗ(ℕ._⋅_)(ℕ._+_) {x = a}{y = b}{z = x ℕ.⋅ (eval bs x)} ]-sym a ℕ.⋅ (b ℕ.+ (x ℕ.⋅ (eval bs x))) 🝖[ _≡_ ]-[] a ℕ.⋅ eval (b ⊰ bs) x 🝖-end eval-preserves-pad : ∀{x}{a : Polynomial(n₁)} ⦃ ord : (n₁ ≤ n₂) ⦄ → (eval (pad ⦃ ord ⦄ a) x ≡ eval a x) eval-preserves-pad {ℕ.𝟎} {ℕ.𝟎} {x} {a ⊰ ∅} ⦃ ord@min ⦄ = reflexivity(_≡_) eval-preserves-pad {ℕ.𝟎} {ℕ.𝐒 n₂} {x} {a ⊰ ∅} ⦃ ord@min ⦄ = eval (pad ⦃ ord ⦄ (a ⊰ ∅)) x 🝖[ _≡_ ]-[] a ℕ.+ (x ℕ.⋅ eval (𝟎 {n₂}) x) 🝖[ _≡_ ]-[ congruence₂ᵣ(ℕ._+_)(a) (congruence₂ᵣ(ℕ._⋅_)(x) (eval-preserves-zero{n₂}{x})) ] a ℕ.+ (x ℕ.⋅ ℕ.𝟎) 🝖[ _≡_ ]-[ congruence₂ᵣ(ℕ._+_)(a) (absorberᵣ(ℕ._⋅_)(ℕ.𝟎) {x}) ] a ℕ.+ ℕ.𝟎 🝖[ _≡_ ]-[ identityᵣ(ℕ._+_)(ℕ.𝟎) ] a 🝖[ _≡_ ]-[] eval (a ⊰ ∅) x 🝖-end eval-preserves-pad {ℕ.𝐒 n₁} {ℕ.𝐒 n₂} {x} {a ⊰ as@(_ ⊰ _)} ⦃ ord@(succ p) ⦄ = eval (pad ⦃ ord ⦄ (a ⊰ as)) x 🝖[ _≡_ ]-[] eval (a ⊰ pad ⦃ _ ⦄ as) x 🝖[ _≡_ ]-[ eval-of-[⊰] {n₂}{x}{a}{pad ⦃ p ⦄ as} ] a ℕ.+ (x ℕ.⋅ eval (pad ⦃ _ ⦄ as) x) 🝖[ _≡_ ]-[ congruence₂ᵣ(ℕ._+_)(a) (congruence₂ᵣ(ℕ._⋅_)(x) (eval-preserves-pad {n₁}{n₂}{x}{as} ⦃ p ⦄)) ] a ℕ.+ (x ℕ.⋅ eval as x) 🝖[ _≡_ ]-[ eval-of-[⊰] {n₁}{x}{a}{as} ]-sym eval (a ⊰ as) x 🝖-end eval-preserves-multiplication : ∀{x}{a : Polynomial(n₁)}{b : Polynomial(n₂)} → (eval (a ⨯ b) x ≡ (eval a x) ℕ.⋅ (eval b x)) eval-preserves-multiplication {n₁} {ℕ.𝟎} {x} {a ⊰ as} {b ⊰ ∅} = eval ((a ⊰ as) ⨯ (b ⊰ ∅)) x 🝖[ _≡_ ]-[] eval (b ⋅ (a ⊰ as)) x 🝖[ _≡_ ]-[ eval-preserves-scalar-multiplication {x = x}{b}{a ⊰ as} ] b ℕ.⋅ eval (a ⊰ as) x 🝖[ _≡_ ]-[ commutativity(ℕ._⋅_) {b}{eval(a ⊰ as) x} ] eval (a ⊰ as) x ℕ.⋅ b 🝖[ _≡_ ]-[] (eval (a ⊰ as) x ℕ.⋅ eval (b ⊰ ∅) x) 🝖-end eval-preserves-multiplication {ℕ.𝟎} {ℕ.𝐒 n₂}{x} {a ⊰ ∅} {b ⊰ bs@(_ ⊰ _)} = eval ((a ⊰ ∅) ⨯ (b ⊰ bs)) x 🝖[ _≡_ ]-[] eval (a ⋅ (b ⊰ bs)) x 🝖[ _≡_ ]-[ eval-preserves-scalar-multiplication {x = x}{a}{b ⊰ bs} ] a ℕ.⋅ (b ℕ.+ (x ℕ.⋅ eval bs x)) 🝖[ _≡_ ]-[] eval (a ⊰ ∅) x ℕ.⋅ eval (b ⊰ bs) x 🝖-end eval-preserves-multiplication {ℕ.𝐒 n₁}{ℕ.𝐒 n₂}{x} {a ⊰ as@(_ ⊰ _)} {b ⊰ bs@(_ ⊰ _)} = eval((a ℕ.⋅ b) ⊰ lr) x 🝖[ _≡_ ]-[ eval-of-[⊰] {x = x}{a = a ℕ.⋅ b}{al = lr} ] (a ℕ.⋅ b) ℕ.+ (x ℕ.⋅ eval lr x) 🝖[ _≡_ ]-[ congruence₂ᵣ(ℕ._+_)(a ℕ.⋅ b) (congruence₂ᵣ(ℕ._⋅_)(x) eval-lr) ] (a ℕ.⋅ b) ℕ.+ (x ℕ.⋅ (((b ℕ.⋅ eval as x) ℕ.+ (a ℕ.⋅ eval bs x)) ℕ.+ (x ℕ.⋅ (eval as x ℕ.⋅ eval bs x)))) 🝖[ _≡_ ]-[ alg{a}{b}{x}{eval as x}{eval bs x} ] (a ℕ.+ (x ℕ.⋅ eval as x)) ℕ.⋅ (b ℕ.+ (x ℕ.⋅ eval bs x)) 🝖[ _≡_ ]-[ congruence₂(ℕ._⋅_) (eval-of-[⊰] {x = x}{a = a}{al = as}) (eval-of-[⊰] {x = x}{a = b}{al = bs}) ] (eval(a ⊰ as) x ℕ.⋅ eval(b ⊰ bs) x) 🝖-end where open import Numeral.Natural.Function open import Numeral.Natural.Function.Proofs open import Numeral.Natural.Relation.Order.Proofs open import Relator.Equals using ([≡]-intro) l : Polynomial(n₁ ℕ.+ n₂) l = pad ⦃ max-order-[+] ⦄ ((b ⋅ as) + (a ⋅ bs)) r : Polynomial(ℕ.𝐒(n₁ ℕ.+ n₂)) r = var⋅ (as ⨯ bs) lr : Polynomial(ℕ.𝐒(n₁ ℕ.+ n₂)) lr = [≡]-substitutionᵣ ([↔]-to-[→] max-defᵣ [≤]-of-[𝐒]) {Polynomial} (l + r) eval-l : (eval l x ≡ (b ℕ.⋅ eval as x) ℕ.+ (a ℕ.⋅ eval bs x)) eval-l = eval l x 🝖[ _≡_ ]-[] eval (pad ⦃ max-order-[+] ⦄ ((b ⋅ as) + (a ⋅ bs))) x 🝖[ _≡_ ]-[ eval-preserves-pad {x = x}{(b ⋅ as) + (a ⋅ bs)} ⦃ max-order-[+] ⦄ ] eval ((b ⋅ as) + (a ⋅ bs)) x 🝖[ _≡_ ]-[ eval-preserves-addition {x = x}{b ⋅ as}{a ⋅ bs} ] eval (b ⋅ as) x ℕ.+ eval (a ⋅ bs) x 🝖[ _≡_ ]-[ congruence₂(ℕ._+_) (eval-preserves-scalar-multiplication {x = x}{b}{as}) (eval-preserves-scalar-multiplication {x = x}{a}{bs}) ] (b ℕ.⋅ eval as x) ℕ.+ (a ℕ.⋅ eval bs x) 🝖-end eval-r : (eval r x ≡ x ℕ.⋅ (eval as x ℕ.⋅ eval bs x)) eval-r = eval r x 🝖[ _≡_ ]-[] eval (var⋅ (as ⨯ bs)) x 🝖[ _≡_ ]-[ eval-preserves-var⋅ {x = x}{as ⨯ bs} ] x ℕ.⋅ eval (as ⨯ bs) x 🝖[ _≡_ ]-[ congruence₂ᵣ(ℕ._⋅_)(x) (eval-preserves-multiplication {x = x}{as}{bs}) ] x ℕ.⋅ (eval as x ℕ.⋅ eval bs x) 🝖-end eval-substitution : ∀{m n}{a : Polynomial(m)}{eq : (m ≡ n)}{x} → (eval ([≡]-substitutionᵣ eq {Polynomial} a) x ≡ eval a x) eval-substitution {eq = [≡]-intro} = [≡]-intro eval-lr : (eval lr x ≡ ((b ℕ.⋅ eval as x) ℕ.+ (a ℕ.⋅ eval bs x)) ℕ.+ (x ℕ.⋅ (eval as x ℕ.⋅ eval bs x))) eval-lr = eval lr x 🝖[ _≡_ ]-[ eval-substitution{a = l + r}{[↔]-to-[→] max-defᵣ [≤]-of-[𝐒]}{x = x} ] eval (l + r) x 🝖[ _≡_ ]-[ eval-preserves-addition{x = x}{l}{r} ] eval l x ℕ.+ eval r x 🝖[ _≡_ ]-[ congruence₂(ℕ._+_) eval-l eval-r ] ((b ℕ.⋅ eval as x) ℕ.+ (a ℕ.⋅ eval bs x)) ℕ.+ (x ℕ.⋅ (eval as x ℕ.⋅ eval bs x)) 🝖-end alg : ∀{a b x q r} → ((a ℕ.⋅ b) ℕ.+ (x ℕ.⋅ (((b ℕ.⋅ q) ℕ.+ (a ℕ.⋅ r)) ℕ.+ (x ℕ.⋅ (q ℕ.⋅ r)))) ≡ (a ℕ.+ (x ℕ.⋅ q)) ℕ.⋅ (b ℕ.+ (x ℕ.⋅ r))) alg {a}{b}{x}{q}{r} = (a ℕ.⋅ b) ℕ.+ (x ℕ.⋅ (((b ℕ.⋅ q) ℕ.+ (a ℕ.⋅ r)) ℕ.+ (x ℕ.⋅ (q ℕ.⋅ r)))) 🝖[ _≡_ ]-[ congruence₂ᵣ(ℕ._+_)(a ℕ.⋅ b) (distributivityₗ(ℕ._⋅_)(ℕ._+_) {x}{(b ℕ.⋅ q) ℕ.+ (a ℕ.⋅ r)}{x ℕ.⋅ (q ℕ.⋅ r)}) ] (a ℕ.⋅ b) ℕ.+ ((x ℕ.⋅ ((b ℕ.⋅ q) ℕ.+ (a ℕ.⋅ r))) ℕ.+ (x ℕ.⋅ (x ℕ.⋅ (q ℕ.⋅ r)))) 🝖[ _≡_ ]-[ congruence₂ᵣ(ℕ._+_)(a ℕ.⋅ b) (congruence₂(ℕ._+_) (distributivityₗ(ℕ._⋅_)(ℕ._+_) {x}{b ℕ.⋅ q}{a ℕ.⋅ r}) (symmetry(_≡_) (associativity(ℕ._⋅_) {x}{x}{q ℕ.⋅ r}))) ] (a ℕ.⋅ b) ℕ.+ (((x ℕ.⋅ (b ℕ.⋅ q)) ℕ.+ (x ℕ.⋅ (a ℕ.⋅ r))) ℕ.+ ((x ℕ.⋅ x) ℕ.⋅ (q ℕ.⋅ r))) 🝖[ _≡_ ]-[ congruence₂ᵣ(ℕ._+_)(a ℕ.⋅ b) (congruence₂(ℕ._+_) (congruence₂(ℕ._+_) (One.commuteᵣ-assocᵣ {_▫_ = ℕ._⋅_}{a = x}{b}{q}) (One.commuteₗ-assocᵣ {_▫_ = ℕ._⋅_}{a = x}{a}{r})) (One.associate-commute4-c {_▫_ = ℕ._⋅_}{a = x}{x}{q}{r})) ] (a ℕ.⋅ b) ℕ.+ ((((x ℕ.⋅ q) ℕ.⋅ b) ℕ.+ (a ℕ.⋅ (x ℕ.⋅ r))) ℕ.+ ((x ℕ.⋅ q) ℕ.⋅ (x ℕ.⋅ r))) 🝖[ _≡_ ]-[ One.associate4-231-222 {_▫_ = ℕ._+_} {a = a ℕ.⋅ b}{(x ℕ.⋅ q) ℕ.⋅ b}{a ℕ.⋅ (x ℕ.⋅ r)}{(x ℕ.⋅ q) ℕ.⋅ (x ℕ.⋅ r)} ] ((a ℕ.⋅ b) ℕ.+ ((x ℕ.⋅ q) ℕ.⋅ b)) ℕ.+ ((a ℕ.⋅ (x ℕ.⋅ r)) ℕ.+ ((x ℕ.⋅ q) ℕ.⋅ (x ℕ.⋅ r))) 🝖[ _≡_ ]-[ OneTypeTwoOp.cross-distribute{a = a}{x ℕ.⋅ q}{b}{x ℕ.⋅ r} ]-sym (a ℕ.+ (x ℕ.⋅ q)) ℕ.⋅ (b ℕ.+ (x ℕ.⋅ r)) 🝖-end
60.072607
338
0.453192
571f5275b6648b445910301a66474619bd744237
4,134
agda
Agda
old/Spaces/FlatteningLoopSpaceWedgeCircles.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
old/Spaces/FlatteningLoopSpaceWedgeCircles.agda
danbornside/HoTT-Agda
1695a7f3dc60177457855ae846bbd86fcd96983e
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
old/Spaces/FlatteningLoopSpaceWedgeCircles.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 Integers module Spaces.FlatteningLoopSpaceWedgeCircles {i} (A : Set i) (set : is-set A) where import Spaces.WedgeCircles import Algebra.FreeGroup import Algebra.FreeGroupProps import Algebra.FreeGroupAsReducedWords open Spaces.WedgeCircles A renaming (wedge-circles to WA; base to baseWA) open Algebra.FreeGroup A renaming (freegroup to FA) open Algebra.FreeGroupProps A -- Path fibration path-fib : WA → Set (suc i) path-fib t = (t ≡ baseWA) tot-path-fib : Set (suc i) tot-path-fib = Σ (WA) path-fib abstract tot-path-fib-is-contr : is-contr tot-path-fib tot-path-fib-is-contr = pathto-is-contr baseWA -- Universal cover x·-path : A → FA ≡ FA x·-path x = eq-to-path (_ , x·-is-equiv x) universal-cover : WA → Set i universal-cover = wedge-circles-rec-nondep (Set _) FA x·-path tot-cover : Set _ tot-cover = Σ WA universal-cover trans-universal-cover : {u v : WA} (p : u ≡ v) (q : universal-cover u) → transport universal-cover p q ≡ transport (λ A → A) (ap universal-cover p) q trans-universal-cover refl _ = refl abstract loops-to-x· : (t : A) (u : FA) → transport universal-cover (loops t) u ≡ t · u loops-to-x· t u = trans-universal-cover (loops t) u ∘ (ap (λ t' → transport (λ B → B) t' u) (β-nondep (Set _) FA x·-path t) ∘ trans-id-eq-to-path (_ , x·-is-equiv t) u) {- Here is an HIT declaration for the Cayley graph of the free group over A: data cayley : Set where z : FA → cayley e : (t : A) (u : FA) → z u ≡ z (t · u) We will see that [cayley] is contractible. We want to show that [tot-cover] has the same introduction and elimination rules, so that we can prove that [tot-cover] is contractible too. We do not need to actually have the type [cayley], it is enough to show that [tot-cover] has the same rules and then we can copy the proof of the contractibility using the new rules. -} -- Introduction rules CA-z : FA → tot-cover CA-z u = (baseWA , u) CA-e : (t : A) (u : FA) → CA-z u ≡ CA-z (t · u) CA-e t u = Σ-eq (loops t) (loops-to-x· t u) -- Elimination rule module equivCA {i} (P : tot-cover → Set i) (z : (u : FA) → P (CA-z u)) (e : (t : A) (u : FA) → transport P (CA-e t u) (z u) ≡ z (t · u)) where CA-e' : (t : A) (u : FA) → CA-z u ≡ CA-z (transport universal-cover (loops t) u) CA-e' t u = Σ-eq (loops t) refl abstract e' : (t : A) (u : FA) → transport P (CA-e' t u) (z u) ≡ z (transport universal-cover (loops t) u) e' t u = (trans-totalpath universal-cover P {x = (baseWA , u)} {y = (baseWA , transport universal-cover (loops t) u)} (loops t) refl z ∘ move!-transp-left (λ z → P (baseWA , z)) _ (loops-to-x· t u) (z (t · u)) (! (trans-totalpath universal-cover P {x = (baseWA , u)} {y = (baseWA , (t · u))} (loops t) (loops-to-x· t u) z) ∘ e t u)) ∘ apd z (! (loops-to-x· t u)) P-base : (u : universal-cover (baseWA)) → P (baseWA , u) P-base u = z u abstract P-loops : (t : A) (u : universal-cover (baseWA)) → transport (λ x → (t : universal-cover x) → P (x , t)) (loops t) P-base u ≡ P-base u P-loops t u = transport (λ u → transport (λ x → (t : universal-cover x) → P (x , t)) (loops t) P-base u ≡ P-base u) (trans-trans-opposite universal-cover (loops t) u) (! (trans-totalpath universal-cover P {x = (baseWA , transport universal-cover (! (loops t)) u)} {y = (baseWA , transport universal-cover (loops t) (transport universal-cover (! (loops t)) u))} (loops t) refl z) ∘ e' t (transport universal-cover (! (loops t)) u)) P-CA-rec : (x : WA) → (t : universal-cover x) → P (x , t) P-CA-rec = wedge-circles-rec (λ x → (t : universal-cover x) → P (x , t)) P-base (λ t → funext (P-loops t)) -- Here is the conclusion of the elimination rule abstract CA-rec : (t : tot-cover) → P t CA-rec (x , y) = P-CA-rec x y
32.551181
80
0.576681
29a9f15743b0b3b1ee980681c280407766f7f878
4,249
agda
Agda
Definition/Typed/Consequences/Equality.agda
Vtec234/logrel-mltt
4746894adb5b8edbddc8463904ee45c2e9b29b69
[ "MIT" ]
null
null
null
Definition/Typed/Consequences/Equality.agda
Vtec234/logrel-mltt
4746894adb5b8edbddc8463904ee45c2e9b29b69
[ "MIT" ]
null
null
null
Definition/Typed/Consequences/Equality.agda
Vtec234/logrel-mltt
4746894adb5b8edbddc8463904ee45c2e9b29b69
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} module Definition.Typed.Consequences.Equality where open import Definition.Untyped open import Definition.Typed open import Definition.Typed.Properties open import Definition.Typed.EqRelInstance open import Definition.LogicalRelation open import Definition.LogicalRelation.Irrelevance open import Definition.LogicalRelation.ShapeView open import Definition.LogicalRelation.Fundamental.Reducibility open import Tools.Product import Tools.PropositionalEquality as PE U≡A′ : ∀ {A Γ l} ([U] : Γ ⊩⟨ l ⟩U) → Γ ⊩⟨ l ⟩ U ≡ A / (U-intr [U]) → A PE.≡ U U≡A′ (noemb [U]) [U≡A] = [U≡A] U≡A′ (emb 0<1 [U]) [U≡A] = U≡A′ [U] [U≡A] -- If A is judgmentally equal to U, then A is propositionally equal to U. U≡A : ∀ {A Γ} → Γ ⊢ U ≡ A → A PE.≡ U U≡A {A} U≡A with reducibleEq U≡A U≡A {A} U≡A | [U] , [A] , [U≡A] = U≡A′ (U-elim [U]) (irrelevanceEq [U] (U-intr (U-elim [U])) [U≡A]) ℕ≡A′ : ∀ {A Γ l} ([ℕ] : Γ ⊩⟨ l ⟩ℕ ℕ) → Γ ⊩⟨ l ⟩ ℕ ≡ A / (ℕ-intr [ℕ]) → Whnf A → A PE.≡ ℕ ℕ≡A′ (noemb x) [ℕ≡A] whnfA = whnfRed* [ℕ≡A] whnfA ℕ≡A′ (emb 0<1 [ℕ]) [ℕ≡A] whnfA = ℕ≡A′ [ℕ] [ℕ≡A] whnfA -- If A in WHNF is judgmentally equal to ℕ, then A is propositionally equal to ℕ. ℕ≡A : ∀ {A Γ} → Γ ⊢ ℕ ≡ A → Whnf A → A PE.≡ ℕ ℕ≡A {A} ℕ≡A whnfA with reducibleEq ℕ≡A ℕ≡A {A} ℕ≡A whnfA | [ℕ] , [A] , [ℕ≡A] = ℕ≡A′ (ℕ-elim [ℕ]) (irrelevanceEq [ℕ] (ℕ-intr (ℕ-elim [ℕ])) [ℕ≡A]) whnfA -- If A in WHNF is judgmentally equal to Empty, then A is propositionally equal to Empty. Empty≡A′ : ∀ {A Γ l} ([Empty] : Γ ⊩⟨ l ⟩Empty Empty) → Γ ⊩⟨ l ⟩ Empty ≡ A / (Empty-intr [Empty]) → Whnf A → A PE.≡ Empty Empty≡A′ (noemb x) [Empty≡A] whnfA = whnfRed* [Empty≡A] whnfA Empty≡A′ (emb 0<1 [Empty]) [Empty≡A] whnfA = Empty≡A′ [Empty] [Empty≡A] whnfA Empty≡A : ∀ {A Γ} → Γ ⊢ Empty ≡ A → Whnf A → A PE.≡ Empty Empty≡A {A} Empty≡A whnfA with reducibleEq Empty≡A Empty≡A {A} Empty≡A whnfA | [Empty] , [A] , [Empty≡A] = Empty≡A′ (Empty-elim [Empty]) (irrelevanceEq [Empty] (Empty-intr (Empty-elim [Empty])) [Empty≡A]) whnfA Unit≡A′ : ∀ {A Γ l} ([Unit] : Γ ⊩⟨ l ⟩Unit Unit) → Γ ⊩⟨ l ⟩ Unit ≡ A / (Unit-intr [Unit]) → Whnf A → A PE.≡ Unit Unit≡A′ (noemb x) [Unit≡A] whnfA = whnfRed* [Unit≡A] whnfA Unit≡A′ (emb 0<1 [Unit]) [Unit≡A] whnfA = Unit≡A′ [Unit] [Unit≡A] whnfA Unit≡A : ∀ {A Γ} → Γ ⊢ Unit ≡ A → Whnf A → A PE.≡ Unit Unit≡A {A} Unit≡A whnfA with reducibleEq Unit≡A Unit≡A {A} Unit≡A whnfA | [Unit] , [A] , [Unit≡A] = Unit≡A′ (Unit-elim [Unit]) (irrelevanceEq [Unit] (Unit-intr (Unit-elim [Unit])) [Unit≡A]) whnfA ne≡A′ : ∀ {A K Γ l} → ([K] : Γ ⊩⟨ l ⟩ne K) → Γ ⊩⟨ l ⟩ K ≡ A / (ne-intr [K]) → Whnf A → ∃ λ M → Neutral M × A PE.≡ M ne≡A′ (noemb [K]) (ne₌ M D′ neM K≡M) whnfA = M , neM , (whnfRed* (red D′) whnfA) ne≡A′ (emb 0<1 [K]) [K≡A] whnfA = ne≡A′ [K] [K≡A] whnfA -- If A in WHNF is judgmentally equal to K, then there exists a M such that -- A is propositionally equal to M. ne≡A : ∀ {A K Γ} → Neutral K → Γ ⊢ K ≡ A → Whnf A → ∃ λ M → Neutral M × A PE.≡ M ne≡A {A} neK ne≡A whnfA with reducibleEq ne≡A ne≡A {A} neK ne≡A whnfA | [ne] , [A] , [ne≡A] = ne≡A′ (ne-elim neK [ne]) (irrelevanceEq [ne] (ne-intr (ne-elim neK [ne])) [ne≡A]) whnfA B≡A′ : ∀ {A F G Γ l} W ([W] : Γ ⊩⟨ l ⟩B⟨ W ⟩ ⟦ W ⟧ F ▹ G) → Γ ⊩⟨ l ⟩ ⟦ W ⟧ F ▹ G ≡ A / (B-intr W [W]) → Whnf A → ∃₂ λ H E → A PE.≡ ⟦ W ⟧ H ▹ E B≡A′ W (noemb [W]) (B₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) whnfA = F′ , G′ , whnfRed* D′ whnfA B≡A′ W (emb 0<1 [W]) [W≡A] whnfA = B≡A′ W [W] [W≡A] whnfA Π≡A′ : ∀ {A F G Γ l} → _ Π≡A′ {A} {F} {G} {Γ} {l} = B≡A′ {A} {F} {G} {Γ} {l} BΠ Σ≡A′ : ∀ {A F G Γ l} → _ Σ≡A′ {A} {F} {G} {Γ} {l} = B≡A′ {A} {F} {G} {Γ} {l} BΣ -- If A is judgmentally equal to Π F ▹ G, then there exists H and E such that -- A is propositionally equal to Π H ▹ E. B≡A : ∀ {A F G Γ} W → Γ ⊢ ⟦ W ⟧ F ▹ G ≡ A → Whnf A → ∃₂ λ H E → A PE.≡ ⟦ W ⟧ H ▹ E B≡A {A} W W≡A whnfA with reducibleEq W≡A B≡A {A} W W≡A whnfA | [W] , [A] , [W≡A] = B≡A′ W (B-elim W [W]) (irrelevanceEq [W] (B-intr W (B-elim W [W])) [W≡A]) whnfA Π≡A : ∀ {A F G Γ} → _ Π≡A {A} {F} {G} {Γ} = B≡A {A} {F} {G} {Γ} BΠ Σ≡A : ∀ {A F G Γ} → _ Σ≡A {A} {F} {G} {Γ} = B≡A {A} {F} {G} {Γ} BΣ
33.456693
105
0.532831
10c8352ebfa0bf59d7abfd7b8e7e38851d0f6207
168
agda
Agda
test/bugs/fixed/HiddenLambda.agda
zgrannan/agda
5953ce337eb6b77b29ace7180478f49c541aea1c
[ "BSD-3-Clause" ]
3
2015-03-28T14:51:03.000Z
2015-12-07T20:14:00.000Z
test/bugs/fixed/HiddenLambda.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
null
null
null
test/bugs/fixed/HiddenLambda.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
module HiddenLambda where postulate A : Set T : A -> Set H : Set H = {x : A} -> T x -> T x -- H doesn't reduce when checking the body of h h : H h = \tx -> tx
11.2
47
0.559524
adeb8680a09774c9acdd5609415caae51c95fa21
1,560
agda
Agda
lib/Explore/One.agda
crypto-agda/explore
16bc8333503ff9c00d47d56f4ec6113b9269a43e
[ "BSD-3-Clause" ]
2
2016-06-05T09:25:32.000Z
2017-06-28T19:19:29.000Z
lib/Explore/One.agda
crypto-agda/explore
16bc8333503ff9c00d47d56f4ec6113b9269a43e
[ "BSD-3-Clause" ]
1
2019-03-16T14:24:04.000Z
2019-03-16T14:24:04.000Z
lib/Explore/One.agda
crypto-agda/explore
16bc8333503ff9c00d47d56f4ec6113b9269a43e
[ "BSD-3-Clause" ]
null
null
null
{-# OPTIONS --without-K #-} open import Type open import Type.Identities open import Level.NP open import Explore.Core open import Explore.Properties open import Explore.Explorable open import Data.One open import Data.Fin open import Function.NP open import Data.Product open import HoTT open import Relation.Binary.PropositionalEquality.NP using (refl; _≡_; !_) import Explore.Monad module Explore.One where module _ {ℓ} where open Explore.Monad {₀} ℓ 𝟙ᵉ : Explore ℓ 𝟙 𝟙ᵉ = return _ {- or 𝟙ᵉ _ f = f _ -} 𝟙ⁱ : ∀ {p} → ExploreInd p 𝟙ᵉ 𝟙ⁱ = return-ind _ {- or 𝟙ⁱ _ _ Pf = Pf _ -} module _ {ℓ₁ ℓ₂ ℓᵣ} {R : 𝟙 → 𝟙 → ★₀} {r : R _ _} where ⟦𝟙ᵉ⟧ : ⟦Explore⟧ {ℓ₁} {ℓ₂} ℓᵣ R 𝟙ᵉ 𝟙ᵉ ⟦𝟙ᵉ⟧ _ _ _∙ᵣ_ fᵣ = fᵣ r module 𝟙ⁱ = FromExploreInd 𝟙ⁱ open 𝟙ⁱ public using () renaming (sum to 𝟙ˢ ;product to 𝟙ᵖ ;reify to 𝟙ʳ ;unfocus to 𝟙ᵘ ) open Adequacy _≡_ module _ {{_ : UA}} where Σᵉ𝟙-ok : ∀ {ℓ} → Adequate-Σ {ℓ} (Σᵉ 𝟙ᵉ) Σᵉ𝟙-ok _ = ! Σ𝟙-snd Πᵉ𝟙-ok : ∀ {ℓ} → Adequate-Π {ℓ} (Πᵉ 𝟙ᵉ) Πᵉ𝟙-ok _ = ! Π𝟙-uniq _ 𝟙ˢ-ok : Adequate-sum 𝟙ˢ 𝟙ˢ-ok _ = ! 𝟙×-snd 𝟙ᵖ-ok : Adequate-product 𝟙ᵖ 𝟙ᵖ-ok _ = ! Π𝟙-uniq _ adequate-sum𝟙 = 𝟙ˢ-ok adequate-product𝟙 = 𝟙ᵖ-ok module _ {ℓ} where 𝟙ˡ : Lookup {ℓ} 𝟙ᵉ 𝟙ˡ = const 𝟙ᶠ : Focus {ℓ} 𝟙ᵉ 𝟙ᶠ = proj₂ explore𝟙 = 𝟙ᵉ explore𝟙-ind = 𝟙ⁱ lookup𝟙 = 𝟙ˡ reify𝟙 = 𝟙ʳ focus𝟙 = 𝟙ᶠ unfocus𝟙 = 𝟙ᵘ sum𝟙 = 𝟙ˢ product𝟙 = 𝟙ᵖ
19.746835
74
0.567308
1313ba8b88ec1a88595204772b2e99aa89db2203
2,440
agda
Agda
archive/agda-3/src/Oscar/Class/Congruity.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
archive/agda-3/src/Oscar/Class/Congruity.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
1
2019-04-29T00:35:04.000Z
2019-05-11T23:33:04.000Z
archive/agda-3/src/Oscar/Class/Congruity.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
open import Oscar.Prelude open import Oscar.Class.Transitivity module Oscar.Class.Congruity where module _ where module _ {ℓ} (_∼_ : ∀ {𝔬} {𝔒 : Ø 𝔬} → 𝔒 → 𝔒 → Ø ℓ) 𝔵 𝔶 where 𝓬ongruity = ∀ {𝔛 : Ø 𝔵} {𝔜 : Ø 𝔶} {x₁ x₂} (f : 𝔛 → 𝔜) → x₁ ∼ x₂ → f x₁ ∼ f x₂ record 𝓒ongruity : Ø ℓ ∙̂ ↑̂ (𝔵 ∙̂ 𝔶) where field congruity : 𝓬ongruity open 𝓒ongruity ⦃ … ⦄ public module _ {ℓ} (_∼_ : ∀ {𝔬} {𝔒 : Ø 𝔬} → 𝔒 → 𝔒 → Ø ℓ) {𝔵 𝔶} (𝔛 : Ø 𝔵) (𝔜 : Ø 𝔶) where 𝓬ongruity' = ∀ {x₁ x₂} (f : 𝔛 → 𝔜) → x₁ ∼ x₂ → f x₁ ∼ f x₂ record 𝓒ongruity' : Ø ℓ ∙̂ ↑̂ (𝔵 ∙̂ 𝔶) where field congruity' : 𝓬ongruity' open 𝓒ongruity' ⦃ … ⦄ public module _ {ℓ} {𝔬} (_∼_ : ∀ {𝔒 : Ø 𝔬} → 𝔒 → 𝔒 → Ø ℓ) (𝔛 𝔜 : Ø 𝔬) where 𝓬ongruity'' = ∀ {x₁ x₂} (f : 𝔛 → 𝔜) → x₁ ∼ x₂ → f x₁ ∼ f x₂ record 𝓒ongruity'' : Ø ℓ ∙̂ 𝔬 where field congruity'' : 𝓬ongruity'' open 𝓒ongruity'' ⦃ … ⦄ public -- a functional replacement of 𝓒ongruity₂ (but note the additional requirement of 𝓣ransitivity) congruity2 : ∀ {ℓ} {_∼_ : ∀ {x} {X : Ø x} → X → X → Ø ℓ} {𝔵 𝔶 𝔷} ⦃ _ : 𝓒ongruity _∼_ 𝔵 (𝔶 ∙̂ 𝔷) ⦄ ⦃ _ : 𝓒ongruity _∼_ (𝔶 ∙̂ 𝔷) 𝔷 ⦄ ⦃ _ : 𝓒ongruity _∼_ 𝔶 (𝔵 ∙̂ 𝔷) ⦄ ⦃ _ : 𝓒ongruity _∼_ (𝔵 ∙̂ 𝔷) 𝔷 ⦄ ⦃ _ : ∀ {x} {X : Ø x} → Transitivity.class (_∼_ {X = X}) ⦄ → ∀ {𝔛 : Ø 𝔵} {𝔜 : Ø 𝔶} {ℨ : Ø 𝔷} {x₁ x₂} {y₁ y₂} (f : 𝔛 → 𝔜 → ℨ) → x₁ ∼ x₂ → y₁ ∼ y₂ → f x₁ y₁ ∼ f x₂ y₂ congruity2 {𝔛 = 𝔛}{𝔜}{ℨ}{x₁}{x₂}{y₁}{y₂} f x₁∼x₂ y₁∼y₂ = let fx1=fx2 = congruity f x₁∼x₂ in let g2 = λ (fx : 𝔜 → ℨ) → fx y₂ in let fx1y2=fx2y2 = congruity g2 fx1=fx2 in let e = flip f in let ey1=ey2 = congruity e y₁∼y₂ in let h1 = λ (ex : 𝔛 → ℨ) → ex x₁ in let fx1y1=fx1y2 = congruity h1 ey1=ey2 in transitivity fx1y1=fx1y2 fx1y2=fx2y2 module _ where record 𝓒ongruity₂ {ℓ} (_∼_ : ∀ {x} {X : Ø x} → X → X → Ø ℓ) 𝔵 𝔶 𝔷 : Ø ℓ ∙̂ ↑̂ (𝔵 ∙̂ 𝔶 ∙̂ 𝔷) where field congruity₂ : ∀ {𝔛 : Ø 𝔵} {𝔜 : Ø 𝔶} {ℨ : Ø 𝔷} {x₁ x₂} {y₁ y₂} (f : 𝔛 → 𝔜 → ℨ) → x₁ ∼ x₂ → y₁ ∼ y₂ → f x₁ y₁ ∼ f x₂ y₂ open 𝓒ongruity₂ ⦃ … ⦄ public module _ where module _ 𝔬 𝔭 {ℓ} (_∼̇_ : ∀ {⋆ : Ø 𝔬} {⋆̇ : ⋆ → Ø 𝔭} → ((𝓞 : ⋆) → ⋆̇ 𝓞) → ((𝓞 : ⋆) → ⋆̇ 𝓞) → Ø ℓ) (let infix 4 _∼̇_ ; _∼̇_ = _∼̇_) where record 𝓒̇ongruity : Ø ↑̂ (𝔬 ∙̂ 𝔭) ∙̂ ℓ where field ċongruity : ∀ {⋆ : Ø 𝔬} {⋆̇ : ⋆ → Ø 𝔭} {f₁ f₂ : (𝓞 : ⋆) → ⋆̇ 𝓞} (G : ∀ {𝓞 : ⋆} → ⋆̇ 𝓞 → ⋆̇ 𝓞) → f₁ ∼̇ f₂ → G ∘ f₁ ∼̇ G ∘ f₂ open 𝓒̇ongruity ⦃ … ⦄ public
30.886076
136
0.479098
ad35e82af92e5585dafca5872f6d233a5f085410
253
agda
Agda
test/interaction/Issue289r.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue289r.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue289r.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2016-06-08 -- Better error message when case splitting is invoked in location -- where there is nothing to split record R : Set where field f : {!!} -- C-c C-c RET here gives: -- Cannot split here, as we are not in a function definition
25.3
66
0.703557
a1dbdc530ebbf77cfa5024e96aab9426f9e037b5
3,827
agda
Agda
vendor/stdlib/src/Data/Nat/DivMod.agda
isabella232/Lemmachine
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
[ "MIT" ]
56
2015-01-20T02:11:42.000Z
2021-12-21T17:02:19.000Z
vendor/stdlib/src/Data/Nat/DivMod.agda
larrytheliquid/Lemmachine
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
[ "MIT" ]
1
2022-03-12T12:17:51.000Z
2022-03-12T12:17:51.000Z
vendor/stdlib/src/Data/Nat/DivMod.agda
isabella232/Lemmachine
8ef786b40e4a9ab274c6103dc697dcb658cf3db3
[ "MIT" ]
3
2015-07-21T16:37:58.000Z
2022-03-12T11:54:10.000Z
------------------------------------------------------------------------ -- Integer division ------------------------------------------------------------------------ module Data.Nat.DivMod where open import Data.Nat open import Data.Nat.Properties open SemiringSolver open import Data.Fin as Fin using (Fin; zero; suc; toℕ; fromℕ) import Data.Fin.Props as Fin open import Induction.Nat open import Relation.Nullary.Decidable open import Relation.Binary.PropositionalEquality open ≡-Reasoning open import Data.Function ------------------------------------------------------------------------ -- Some boring lemmas private lem₁ : ∀ m k → _ lem₁ m k = cong suc $ begin m ≡⟨ Fin.inject+-lemma m k ⟩ toℕ (Fin.inject+ k (fromℕ m)) ≡⟨ solve 1 (λ x → x := x :+ con 0) refl _ ⟩ toℕ (Fin.inject+ k (fromℕ m)) + 0 ∎ lem₂ : ∀ n → _ lem₂ = solve 1 (λ n → con 1 :+ n := con 1 :+ (n :+ con 0)) refl lem₃ : ∀ n k q r eq → _ lem₃ n k q r eq = begin suc n + k ≡⟨ solve 2 (λ n k → con 1 :+ n :+ k := n :+ (con 1 :+ k)) refl n k ⟩ n + suc k ≡⟨ cong (_+_ n) eq ⟩ n + (toℕ r + q * n) ≡⟨ solve 3 (λ n r q → n :+ (r :+ q :* n) := r :+ (con 1 :+ q) :* n) refl n (toℕ r) q ⟩ toℕ r + suc q * n ∎ ------------------------------------------------------------------------ -- Division -- A specification of integer division. data DivMod : ℕ → ℕ → Set where result : {divisor : ℕ} (q : ℕ) (r : Fin divisor) → DivMod (toℕ r + q * divisor) divisor -- Sometimes the following type is more usable; functions in indices -- can be inconvenient. data DivMod' (dividend divisor : ℕ) : Set where result : (q : ℕ) (r : Fin divisor) (eq : dividend ≡ toℕ r + q * divisor) → DivMod' dividend divisor -- Integer division with remainder. -- Note that Induction.Nat.<-rec is used to ensure termination of -- division. The run-time complexity of this implementation of integer -- division should be linear in the size of the dividend, assuming -- that well-founded recursion and the equality type are optimised -- properly (see "Inductive Families Need Not Store Their Indices" -- (Brady, McBride, McKinna, TYPES 2003)). _divMod'_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} → DivMod' dividend divisor _divMod'_ m n {≢0} = <-rec Pred dm m n {≢0} where Pred : ℕ → Set Pred dividend = (divisor : ℕ) {≢0 : False (divisor ≟ 0)} → DivMod' dividend divisor 1+_ : ∀ {k n} → DivMod' (suc k) n → DivMod' (suc n + k) n 1+_ {k} {n} (result q r eq) = result (1 + q) r (lem₃ n k q r eq) dm : (dividend : ℕ) → <-Rec Pred dividend → Pred dividend dm m rec zero {≢0 = ()} dm zero rec (suc n) = result 0 zero refl dm (suc m) rec (suc n) with compare m n dm (suc m) rec (suc .(suc m + k)) | less .m k = result 0 r (lem₁ m k) where r = suc (Fin.inject+ k (fromℕ m)) dm (suc m) rec (suc .m) | equal .m = result 1 zero (lem₂ m) dm (suc .(suc n + k)) rec (suc n) | greater .n k = 1+ rec (suc k) le (suc n) where le = s≤′s (s≤′s (n≤′m+n n k)) -- A variant. _divMod_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} → DivMod dividend divisor _divMod_ m n {≢0} with _divMod'_ m n {≢0} .(toℕ r + q * n) divMod n | result q r refl = result q r -- Integer division. _div_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} → ℕ _div_ m n {≢0} with _divMod_ m n {≢0} .(toℕ r + q * n) div n | result q r = q -- The remainder after integer division. _mod_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} → Fin divisor _mod_ m n {≢0} with _divMod_ m n {≢0} .(toℕ r + q * n) mod n | result q r = r
33.278261
79
0.519206
1a73960ce6123d80188401a2d3f32e3153b8ea9a
361
agda
Agda
test/Fail/Issue1652-2.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue1652-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/Issue1652-2.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{- Example by Andreas (2015-09-18) -} {- Jesper, 2021-03-19: Since the fix of #5238 this example is no longer allowed -} {-# OPTIONS --rewriting --local-confluence-check #-} open import Common.Prelude open import Common.Equality {-# BUILTIN REWRITE _≡_ #-} module _ (A : Set) where postulate plus0p : ∀{x} → (x + zero) ≡ x {-# REWRITE plus0p #-}
21.235294
82
0.645429
2e6faa9d069f6ab3b31a003950a49d022d62d767
4,499
agda
Agda
agda-stdlib/README/Decidability.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/README/Decidability.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/README/Decidability.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Examples of decision procedures and how to use them ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module README.Decidability where -- Reflects and Dec are defined in Relation.Nullary, and operations on them can -- be found in Relation.Nullary.Reflects and Relation.Nullary.Decidable. open import Relation.Nullary as Nullary open import Relation.Nullary.Reflects open import Relation.Nullary.Decidable open import Data.Bool open import Data.List open import Data.List.Properties using (∷-injective) open import Data.Nat open import Data.Nat.Properties using (suc-injective) open import Data.Product open import Data.Unit open import Function open import Relation.Binary.PropositionalEquality open import Relation.Nary open import Relation.Nullary.Product infix 4 _≟₀_ _≟₁_ _≟₂_ -- A proof of `Reflects P b` shows that a proposition `P` has the truth value of -- the boolean `b`. A proof of `Reflects P true` amounts to a proof of `P`, and -- a proof of `Reflects P false` amounts to a refutation of `P`. ex₀ : (n : ℕ) → Reflects (n ≡ n) true ex₀ n = ofʸ refl ex₁ : (n : ℕ) → Reflects (zero ≡ suc n) false ex₁ n = ofⁿ λ () ex₂ : (b : Bool) → Reflects (T b) b ex₂ false = ofⁿ id ex₂ true = ofʸ tt -- A proof of `Dec P` is a proof of `Reflects P b` for some `b`. -- `Dec P` is declared as a record, with fields: -- does : Bool -- proof : Reflects P does ex₃ : (b : Bool) → Dec (T b) does (ex₃ b) = b proof (ex₃ b) = ex₂ b -- We also have pattern synonyms `yes` and `no`, allowing both fields to be -- given at once. ex₄ : (n : ℕ) → Dec (zero ≡ suc n) ex₄ n = no λ () -- It is possible, but not ideal, to define recursive decision procedures using -- only the `yes` and `no` patterns. The following procedure decides whether two -- given natural numbers are equal. _≟₀_ : (m n : ℕ) → Dec (m ≡ n) zero ≟₀ zero = yes refl zero ≟₀ suc n = no λ () suc m ≟₀ zero = no λ () suc m ≟₀ suc n with m ≟₀ n ... | yes p = yes (cong suc p) ... | no ¬p = no (¬p ∘ suc-injective) -- In this case, we can see that `does (suc m ≟ suc n)` should be equal to -- `does (m ≟ n)`, because a `yes` from `m ≟ n` gives rise to a `yes` from the -- result, and similarly for `no`. However, in the above definition, this -- equality does not hold definitionally, because we always do a case split -- before returning a result. To avoid this, we can return the `does` part -- separately, before any pattern matching. _≟₁_ : (m n : ℕ) → Dec (m ≡ n) zero ≟₁ zero = yes refl zero ≟₁ suc n = no λ () suc m ≟₁ zero = no λ () does (suc m ≟₁ suc n) = does (m ≟₁ n) proof (suc m ≟₁ suc n) with m ≟₁ n ... | yes p = ofʸ (cong suc p) ... | no ¬p = ofⁿ (¬p ∘ suc-injective) -- We now get definitional equalities such as the following. _ : (m n : ℕ) → does (5 + m ≟₁ 3 + n) ≡ does (2 + m ≟₁ n) _ = λ m n → refl -- Even better, from a maintainability point of view, is to use `map` or `map′`, -- both of which capture the pattern of the `does` field remaining the same, but -- the `proof` field being updated. _≟₂_ : (m n : ℕ) → Dec (m ≡ n) zero ≟₂ zero = yes refl zero ≟₂ suc n = no λ () suc m ≟₂ zero = no λ () suc m ≟₂ suc n = map′ (cong suc) suc-injective (m ≟₂ n) _ : (m n : ℕ) → does (5 + m ≟₂ 3 + n) ≡ does (2 + m ≟₂ n) _ = λ m n → refl -- `map′` can be used in conjunction with combinators such as `_⊎-dec_` and -- `_×-dec_` to build complex (simply typed) decision procedures. module ListDecEq₀ {a} {A : Set a} (_≟ᴬ_ : (x y : A) → Dec (x ≡ y)) where _≟ᴸᴬ_ : (xs ys : List A) → Dec (xs ≡ ys) [] ≟ᴸᴬ [] = yes refl [] ≟ᴸᴬ (y ∷ ys) = no λ () (x ∷ xs) ≟ᴸᴬ [] = no λ () (x ∷ xs) ≟ᴸᴬ (y ∷ ys) = map′ (uncurry (cong₂ _∷_)) ∷-injective (x ≟ᴬ y ×-dec xs ≟ᴸᴬ ys) -- The final case says that `x ∷ xs ≡ y ∷ ys` exactly when `x ≡ y` *and* -- `xs ≡ ys`. The proofs are updated by the first two arguments to `map′`. -- In the case of ≡-equality tests, the pattern -- `map′ (congₙ c) c-injective (x₀ ≟ y₀ ×-dec ... ×-dec xₙ₋₁ ≟ yₙ₋₁)` -- is captured by `≟-mapₙ n c c-injective (x₀ ≟ y₀) ... (xₙ₋₁ ≟ yₙ₋₁)`. module ListDecEq₁ {a} {A : Set a} (_≟ᴬ_ : (x y : A) → Dec (x ≡ y)) where _≟ᴸᴬ_ : (xs ys : List A) → Dec (xs ≡ ys) [] ≟ᴸᴬ [] = yes refl [] ≟ᴸᴬ (y ∷ ys) = no λ () (x ∷ xs) ≟ᴸᴬ [] = no λ () (x ∷ xs) ≟ᴸᴬ (y ∷ ys) = ≟-mapₙ 2 _∷_ ∷-injective (x ≟ᴬ y) (xs ≟ᴸᴬ ys)
33.827068
80
0.597022
3d3fd86dc6f55a9e1f4792efb174014130cf7cd0
490
agda
Agda
src/SizedPolyIO/Object.agda
agda/ooAgda
7cc45e0148a4a508d20ed67e791544c30fecd795
[ "MIT" ]
23
2016-06-19T12:57:55.000Z
2020-10-12T23:15:25.000Z
src/SizedPolyIO/Object.agda
agda/ooAgda
7cc45e0148a4a508d20ed67e791544c30fecd795
[ "MIT" ]
null
null
null
src/SizedPolyIO/Object.agda
agda/ooAgda
7cc45e0148a4a508d20ed67e791544c30fecd795
[ "MIT" ]
2
2018-09-01T15:02:37.000Z
2022-03-12T11:41:00.000Z
module SizedPolyIO.Object where open import Data.Product open import Level using (_⊔_) renaming (suc to lsuc) record Interface μ ρ : Set (lsuc (μ ⊔ ρ)) where field Method : Set μ Result : (m : Method) → Set ρ open Interface public -- A simple object just returns for a method the response -- and the object itself record Object {μ ρ} (i : Interface μ ρ) : Set (μ ⊔ ρ) where coinductive field objectMethod : (m : Method i) → Result i m × Object i open Object public
23.333333
59
0.685714
12f8dab07b931fdec0a39426b4b6b3b0b398770f
1,384
agda
Agda
prototyping/Luau/Heap.agda
Tr4shh/Roblox-Luau
cd18adc20ecb805b8eeb770a9e5ef8e0cd123734
[ "MIT" ]
null
null
null
prototyping/Luau/Heap.agda
Tr4shh/Roblox-Luau
cd18adc20ecb805b8eeb770a9e5ef8e0cd123734
[ "MIT" ]
null
null
null
prototyping/Luau/Heap.agda
Tr4shh/Roblox-Luau
cd18adc20ecb805b8eeb770a9e5ef8e0cd123734
[ "MIT" ]
null
null
null
module Luau.Heap where open import Agda.Builtin.Equality using (_≡_) open import FFI.Data.Maybe using (Maybe; just) open import FFI.Data.Vector using (Vector; length; snoc; empty) open import Luau.Addr using (Addr) open import Luau.Var using (Var) open import Luau.Syntax using (Block; Expr; Annotated; FunDec; nil; addr; function_is_end) data HeapValue (a : Annotated) : Set where function_is_end : FunDec a → Block a → HeapValue a Heap : Annotated → Set Heap a = Vector (HeapValue a) data _≡_⊕_↦_ {a} : Heap a → Heap a → Addr → HeapValue a → Set where defn : ∀ {H val} → ----------------------------------- (snoc H val) ≡ H ⊕ (length H) ↦ val _[_] : ∀ {a} → Heap a → Addr → Maybe (HeapValue a) _[_] = FFI.Data.Vector.lookup ∅ : ∀ {a} → Heap a ∅ = empty data AllocResult a (H : Heap a) (V : HeapValue a) : Set where ok : ∀ b H′ → (H′ ≡ H ⊕ b ↦ V) → AllocResult a H V alloc : ∀ {a} H V → AllocResult a H V alloc H V = ok (length H) (snoc H V) defn next : ∀ {a} → Heap a → Addr next = length allocated : ∀ {a} → Heap a → HeapValue a → Heap a allocated = snoc -- next-emp : (length ∅ ≡ 0) next-emp = FFI.Data.Vector.length-empty -- lookup-next : ∀ V H → (lookup (allocated H V) (next H) ≡ just V) lookup-next = FFI.Data.Vector.lookup-snoc -- lookup-next-emp : ∀ V → (lookup (allocated emp V) 0 ≡ just V) lookup-next-emp = FFI.Data.Vector.lookup-snoc-empty
27.68
90
0.629335
4be7aefeff775f25d9fe59a70857119d7c81eba6
1,503
agda
Agda
examples/outdated-and-incorrect/iird/Identity.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/Identity.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/Identity.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Identity where data _==_ {A : Set}(x : A) : A -> Set where refl : x == x elim== : {A : Set}(x : A)(C : (y : A) -> x == y -> Set) -> C x refl -> (y : A) -> (p : x == y) -> C y p elim== x C Cx .x refl = Cx elim==₁ : {A : Set}(x : A)(C : (y : A) -> x == y -> Set1) -> C x refl -> (y : A) -> (p : x == y) -> C y p elim==₁ x C Cx .x refl = Cx sym : {A : Set}{x y : A} -> x == y -> y == x sym {A}{x}{y} eq = elim== x (\z _ -> z == x) refl y eq cong : {A B : Set}(f : A -> B){x y : A} -> x == y -> f x == f y cong {A} f {x}{y} eq = elim== x (\z _ -> f x == f z) refl y eq subst : {A : Set}{x y : A}(P : A -> Set) -> x == y -> P x -> P y subst P xy px = elim== _ (\z _ -> P z) px _ xy subst₁ : {A : Set}{x y : A}(P : A -> Set1) -> x == y -> P x -> P y subst₁ P xy px = elim==₁ _ (\z _ -> P z) px _ xy symRef : (A : Set)(x : A) -> sym (refl{A}{x}) == refl symRef A x = refl symSym : {A : Set}{x y : A}(p : x == y) -> sym (sym p) == p symSym {A}{x}{y} p = elim== x (\y q -> sym (sym q) == q) refl y p -- Proving the symmetric elimination rule is not trivial. elimS : {A : Set}(x : A)(C : (y : A) -> y == x -> Set) -> C x refl -> (y : A) -> (p : y == x) -> C y p elimS x C r y p = subst (C y) (symSym p) h where h : C y (sym (sym p)) h = elim== x (\y p -> C y (sym p)) r y (sym p) data _==¹_ {A : Set1}(x : A) : {B : Set1} -> B -> Set where refl¹ : x ==¹ x subst¹ : {A : Set1}{x y : A}(P : A -> Set) -> x ==¹ y -> P x -> P y subst¹ {A} P refl¹ px = px
31.978723
67
0.424484
22950d80b1c79dd4fd2173ec30c2a17f483582f1
1,525
agda
Agda
src/PMI.agda
acallesalda/setform
4ab3c1a8bfd679cb3ced25500aa8103cb6c4b1f4
[ "MIT" ]
3
2019-08-02T23:13:13.000Z
2022-01-06T20:04:13.000Z
src/PMI.agda
acallesalda/setform
4ab3c1a8bfd679cb3ced25500aa8103cb6c4b1f4
[ "MIT" ]
null
null
null
src/PMI.agda
acallesalda/setform
4ab3c1a8bfd679cb3ced25500aa8103cb6c4b1f4
[ "MIT" ]
null
null
null
------------------------------------------ -- Mathematical induction derived from Z ------------------------------------------ module PMI where open import Logic open import ZAxioms open import Algebra open import Subset open import Pairs -- Axiom of infinity postulate infinity : ∃ (λ I → ∅ ∈ I ∧ ∀ x → x ∈ I → x ∪ singleton x ∈ I) succ : 𝓢 → 𝓢 succ x = x ∪ singleton x -- Inductive property Inductive : 𝓢 → Set Inductive A = ∅ ∈ A ∧ ((x : 𝓢) → x ∈ A → succ x ∈ A) -- An inductive set. I : 𝓢 I = proj₁ infinity formulaN : 𝓢 → Set formulaN x = (A : 𝓢) → Inductive A → x ∈ A fullN : ∃ (λ B → {z : 𝓢} → z ∈ B ⇔ z ∈ I ∧ formulaN z) fullN = sub formulaN I ℕ : 𝓢 ℕ = proj₁ fullN x∈ℕ→x∈InductiveSet : (x : 𝓢) → x ∈ ℕ → (A : 𝓢) → Inductive A → x ∈ A x∈ℕ→x∈InductiveSet x h = ∧-proj₂ (∧-proj₁ (proj₂ _ fullN) h) -- PMI version from Ivorra Castillo (n.d.), Teorema 8.13. PMI : (A : 𝓢) → A ⊆ ℕ → ∅ ∈ A → ((n : 𝓢) → n ∈ A → succ n ∈ A) → A ≡ ℕ PMI A h₁ h₂ h₃ = equalitySubset A ℕ (prf₁ , prf₂) where prf₁ : (z : 𝓢) → z ∈ A → z ∈ ℕ prf₁ z h = h₁ z h inductiveA : Inductive A inductiveA = h₂ , h₃ prf₂ : (z : 𝓢) → z ∈ ℕ → z ∈ A prf₂ z h = x∈ℕ→x∈InductiveSet z h A inductiveA -- References -- -- Suppes, Patrick (1960). Axiomatic Set Theory. -- The University Series in Undergraduate Mathematics. -- D. Van Nostrand Company, inc. -- -- Enderton, Herbert B. (1977). Elements of Set Theory. -- Academic Press Inc. -- -- Ivorra Castillo, Carlos (n.d.). Lógica y Teoría de -- Conjuntos. https://www.uv.es/ivorra/
23.828125
70
0.568525
1a962aa0dd5b58b17a9b8344d66292baeb8ca3e7
98
agda
Agda
Rings/IntegralDomains/Examples.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
4
2019-08-08T12:44:19.000Z
2022-01-28T06:04:15.000Z
Rings/IntegralDomains/Examples.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
14
2019-01-06T21:11:59.000Z
2020-04-11T11:03:39.000Z
Rings/IntegralDomains/Examples.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
1
2021-11-29T13:23:07.000Z
2021-11-29T13:23:07.000Z
{-# OPTIONS --safe --warning=error --without-K #-} module Rings.IntegralDomains.Examples where
16.333333
50
0.714286
a100beda33e892b265298f769e312a3fbc005e22
6,590
agda
Agda
src/type-util.agda
bmyerz/cedille
a7fa7661c89c71c605b1f7d937d6fab188d96781
[ "MIT" ]
null
null
null
src/type-util.agda
bmyerz/cedille
a7fa7661c89c71c605b1f7d937d6fab188d96781
[ "MIT" ]
null
null
null
src/type-util.agda
bmyerz/cedille
a7fa7661c89c71c605b1f7d937d6fab188d96781
[ "MIT" ]
null
null
null
module type-util where open import cedille-types open import general-util open import syntax-util tmtp-to-arg : erased? → tmtp → arg tmtp-to-arg ff (inj₁ t) = Arg t tmtp-to-arg me = ArgE tmtps-to-args : erased? → 𝕃 tmtp → args tmtps-to-args = map ∘ tmtp-to-arg tmtps-to-args-for-params : (keep-extra : maybe erased?) → params → 𝕃 tmtp → args tmtps-to-args-for-params b (ParamTm _ _ :: ps) (inj₁ t :: as) = Arg t :: tmtps-to-args-for-params b ps as tmtps-to-args-for-params b (_ :: ps) (tT :: as) = ArgE tT :: tmtps-to-args-for-params b ps as tmtps-to-args-for-params nothing _ _ = [] tmtps-to-args-for-params (just me) _ as = tmtps-to-args me as arg-to-tmtp : arg → tmtp arg-to-tmtp a = a >>= id args-to-tmtps : args → 𝕃 tmtp args-to-tmtps = map arg-to-tmtp params-to-args : params → args params-to-args = map λ where (ParamTm v _) → Arg (Var v) (ParamEr v _) → ArgEr (Var v) (ParamTp v _) → ArgTp (TpVar v) 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-apps : term → term × args decompose-apps = h [] where h : args → term → term × args h acc (App t t') = h (Arg t' :: acc) t h acc (AppE t tT) = h (ArgE tT :: acc) t h acc t = t , acc decompose-tpapps : type → type × 𝕃 tmtp decompose-tpapps = h [] where h : 𝕃 tmtp → type → type × 𝕃 tmtp h acc (TpApp T tT) = h (tT :: acc) T h acc T = T , acc decompose-var-headed : term → maybe (var × args) decompose-var-headed t with decompose-apps t decompose-var-headed t | Var x , as = just (x , as) decompose-var-headed t | _ = nothing decompose-tpvar-headed : type → maybe (var × 𝕃 tmtp) decompose-tpvar-headed T with decompose-tpapps T decompose-tpvar-headed T | TpVar x , as = just (x , as) decompose-tpvar-headed T | _ = nothing recompose-apps : args → term → term recompose-apps = flip $ foldl λ a t → either-else' a (App t) (AppE t) recompose-tpapps : 𝕃 tmtp → type → type recompose-tpapps = flip $ foldl $ flip TpApp apps-term : term → args → term apps-term = flip recompose-apps apps-type : type → args → type apps-type = foldl $ flip TpApp ∘ arg-to-tmtp lam-expand-term : params → term → term lam-expand-term = flip $ foldr λ where (Param me x atk) → Lam me x (just atk) lam-expand-type : params → type → type lam-expand-type = flip $ foldr λ where (Param me x atk) → TpLam x atk abs-expand-type : params → type → type abs-expand-type = flip $ foldr λ where (Param me x atk) → TpAbs me x atk abs-expand-kind : params → kind → kind abs-expand-kind = flip $ foldr λ where (Param me x atk) → KdAbs x atk case-args-to-lams : case-args → term → term case-args-to-lams = flip $ foldr λ where (CaseArg me x atk) → Lam me x atk expand-case : case → term expand-case (Case x xs t T) = case-args-to-lams xs t is-eq-tp? : {ed : exprd} → ⟦ ed ⟧ → maybe (term × term) is-eq-tp? {TYPE} (TpEq t₁ t₂) = just $ t₁ , t₂ is-eq-tp? _ = nothing arg-set-erased : erased? → arg → arg arg-set-erased tt (Arg t) = ArgEr t arg-set-erased ff (ArgEr t) = Arg t arg-set-erased e a = a is-var : tmtp → maybe var is-var (Ttm (Var x)) = just x is-var (Ttp (TpVar x)) = just x is-var _ = nothing arg-var : arg → maybe var arg-var = either-else (is-var ∘ Ttm) is-var is-var-unqual : tmtp → maybe var is-var-unqual = maybe-map (λ x → maybe-else (unqual-local x) id (var-suffix x)) ∘ is-var unerased-arrows : type → ℕ unerased-arrows (TpAbs ff x atk T) = suc (unerased-arrows T) unerased-arrows (TpAbs tt x atk T) = unerased-arrows T unerased-arrows _ = zero lterms-to-term : theta → ex-tm → 𝕃 lterm → ex-tm lterms-to-term AbstractEq t [] = ExApp t Erased (ExBeta (term-end-pos t) nothing nothing) lterms-to-term _ t [] = t lterms-to-term θ t (Lterm e t' :: ls) = lterms-to-term θ (ExApp t e t') ls is-hole : ∀ {ed} → ⟦ ed ⟧ → 𝔹 is-hole {TERM} (Hole pi) = tt is-hole {TYPE} (TpHole pi) = tt is-hole {KIND} (KdHole pi) = tt is-hole _ = ff data datatype : Set where Data : var → params → indices → ctrs → datatype tk-erased : tpkd → erased? → erased? tk-erased (Tkk _) me = Erased tk-erased (Tkt _) me = me params-set-erased : erased? → params → params params-set-erased me = map λ where (Param me' x atk) → Param me x atk args-set-erased : erased? → args → args args-set-erased = map ∘ arg-set-erased indices-to-params : indices → params indices-to-params = map λ where (Index x tk) → Param ff x tk params-to-indices : params → indices params-to-indices = map λ where (Param me x tk) → Index x tk indices-to-tmtps : indices → 𝕃 tmtp indices-to-tmtps = map λ where (Index x (Tkt T)) → Ttm (Var x) (Index x (Tkk k)) → Ttp (TpVar x) indices-to-kind : indices → kind → kind indices-to-kind = flip $ foldr λ {(Index x atk) → KdAbs x atk} params-to-kind : params → kind → kind params-to-kind = flip $ foldr λ {(Param me x atk) → KdAbs x atk} indices-to-tplams : indices → (body : type) → type indices-to-tplams = flip $ foldr λ where (Index x atk) → TpLam x atk params-to-tplams : params → (body : type) → type params-to-tplams = flip $ foldr λ where (Param me x atk) → TpLam x atk indices-to-alls : indices → (body : type) → type indices-to-alls = flip $ foldr λ where (Index x atk) → TpAbs Erased x atk params-to-alls : params → (body : type) → type params-to-alls = flip $ foldr λ where (Param me x atk) → TpAbs (tk-erased atk me) x atk indices-to-lams : indices → (body : term) → term indices-to-lams = flip $ foldr λ where (Index x atk) → Lam Erased x (just atk) params-to-lams : params → (body : term) → term params-to-lams = flip $ foldr λ where (Param me x atk) → Lam (tk-erased atk me) x (just atk) indices-to-apps : indices → (body : term) → term indices-to-apps = flip $ foldl λ where (Index x (Tkt T)) t → AppEr t (Var x) (Index x (Tkk k)) t → AppTp t (TpVar x) params-to-apps : params → (body : term) → term params-to-apps = recompose-apps ∘ params-to-args indices-to-tpapps : indices → (body : type) → type indices-to-tpapps = flip $ foldl λ where (Index x (Tkt _)) T → TpAppTm T (Var x) (Index x (Tkk _)) T → TpAppTp T (TpVar x) params-to-tpapps : params → (body : type) → type params-to-tpapps = flip apps-type ∘ params-to-args params-to-case-args : params → case-args params-to-case-args = map λ where (Param me x tk) → CaseArg me x (just tk) ctrs-to-lams : ctrs → term → term ctrs-to-lams = flip $ foldr λ {(Ctr x T) → Lam NotErased x (just (Tkt T))} indices-to-args : indices → args indices-to-args = λ is → map (λ {(Index x atk) → either-else' atk (λ _ → ArgEr (Var x)) (λ _ → ArgTp (TpVar x))}) is
30.368664
116
0.652049
2f7a98664ea4ac23a8a53670cdb0a494c05cf221
2,515
agda
Agda
src/Selective/Runtime.agda
Zalastax/singly-typed-actors
ae541df13d069df4eb1464f29fbaa9804aad439f
[ "MIT" ]
1
2019-10-29T09:30:26.000Z
2019-10-29T09:30:26.000Z
src/Selective/Runtime.agda
Zalastax/singly-typed-actors
ae541df13d069df4eb1464f29fbaa9804aad439f
[ "MIT" ]
null
null
null
src/Selective/Runtime.agda
Zalastax/singly-typed-actors
ae541df13d069df4eb1464f29fbaa9804aad439f
[ "MIT" ]
null
null
null
module Selective.Runtime where open import Selective.Simulate open import Selective.SimulationEnvironment open import Prelude open import Data.Nat.Show using (show) open import Codata.Musical.Notation using ( ♯_ ; ♭) import IO open ∞Trace record BlockedCount : Set₂ where field return-count : ℕ receive-count : ℕ selective-count : ℕ count-blocked : (env : Env) → BlockedCount count-blocked env = loop (Env.blocked-no-progress env) where open BlockedCount loop : ∀ {store inbs bl} → All (IsBlocked store inbs) bl → BlockedCount loop [] = record { return-count = 0 ; receive-count = 0 ; selective-count = 0 } loop (BlockedReturn _ _ ∷ xs) = let rec = loop xs in record { return-count = suc (rec .return-count) ; receive-count = rec .receive-count ; selective-count = rec .selective-count } loop (BlockedReceive _ _ _ ∷ xs) = let rec = loop xs in record { return-count = rec .return-count ; receive-count = suc (rec .receive-count) ; selective-count = rec .selective-count } loop (BlockedSelective _ _ _ _ _ ∷ xs) = let rec = loop xs in record { return-count = rec .return-count ; receive-count = rec .receive-count ; selective-count = suc (rec .selective-count) } show-env : Env → String show-env env = let count = count-blocked env open BlockedCount in "There are " || show (count .return-count) || " finished actors, " || show (count .receive-count) || " receiving actors, and " || show (count .selective-count) || " selecting actors" show-final-step : ℕ → String show-final-step n = "Done after " || (show n) || " steps." -- run-env continously runs the simulation of an environment -- and transforms the steps taken into output to the console. run-env : Env → IO.IO ⊤ run-env env = loop 1 ((simulate env) .force) where loop : ℕ → Trace ∞ → IO.IO ⊤ loop n (TraceStop env _) = ♯ IO.putStrLn (show-final-step n) IO.>> ♯ IO.putStrLn (show-env env) loop n (x ∷ xs) = ♯ IO.putStrLn ("Step " || show n ) IO.>> ♯ loop (suc n) (xs .force) run-env-silent : Env → IO.IO ⊤ run-env-silent env = loop 1 ((simulate env) .force) where loop : ℕ → Trace ∞ → IO.IO ⊤ loop n (TraceStop env _) = IO.putStrLn (show-final-step n) loop n (x ∷ xs) = ♯ IO.return tt IO.>> ♯ loop (suc n) (xs .force) run-env-end : Env → IO.IO Env run-env-end env = loop ((simulate env) .force) where loop : Trace ∞ → IO.IO Env loop (TraceStop env _) = IO.return env loop (x ∷ xs) = ♯ IO.return x IO.>> ♯ loop (xs .force)
39.296875
187
0.650099
291dd527628222354ea640ca14db31e1e3e84717
68
agda
Agda
test/interaction/Issue2217.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue2217.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue2217.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
import Issue2217.M {-# TERMINATING #-} A : Set A = ? a : A a = ?
6.8
19
0.514706
ad2ba4620ee7437960024a8898ab0b065024167c
217
agda
Agda
test/Fail/Issue278.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue278.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue278.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --warning=error #-} module Issue278 where open import Agda.Builtin.Equality abstract module A where Foo : Set₁ Foo = Set module B where open A Foo≡Set : Foo ≡ Set Foo≡Set = refl
14.466667
33
0.640553
041138caa5f71ad6d537e1d1e4c7575360a01405
223
agda
Agda
src/data/lib/prim/Agda/Builtin/Equality.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
src/data/lib/prim/Agda/Builtin/Equality.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
src/data/lib/prim/Agda/Builtin/Equality.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --without-K --safe --no-sized-types --no-guardedness #-} module Agda.Builtin.Equality where infix 4 _≡_ data _≡_ {a} {A : Set a} (x : A) : A → Set a where instance refl : x ≡ x {-# BUILTIN EQUALITY _≡_ #-}
22.3
68
0.61435
576cbf200fd286b02ec4cf966ec966baf0bb36eb
5,263
agda
Agda
Cats/Util/Simp.agda
alessio-b-zak/cats
a3b69911c4c6ec380ddf6a0f4510d3a755734b86
[ "MIT" ]
null
null
null
Cats/Util/Simp.agda
alessio-b-zak/cats
a3b69911c4c6ec380ddf6a0f4510d3a755734b86
[ "MIT" ]
null
null
null
Cats/Util/Simp.agda
alessio-b-zak/cats
a3b69911c4c6ec380ddf6a0f4510d3a755734b86
[ "MIT" ]
null
null
null
module Cats.Util.Simp where open import Data.List using (List ; [] ; _∷_) open import Data.Nat using (ℕ ; zero ; suc) open import Data.Product using (_×_ ; _,_ ; ∃-syntax) open import Data.Unit using (⊤) open import Function using () renaming (_∘_ to _⊚_) open import Level using (_⊔_) renaming (zero to lzero) open import Relation.Binary.PropositionalEquality as ≡ using (_≡_ ; inspect ; [_]) open import Cats.Category.Base open import Cats.Util.Reflection _>>=_ = bindTC return = returnTC _>>_ : ∀ {a} {A : Set a} {b} {B : Set b} → TC A → TC B → TC B ma >> mb = ma >>= λ _ → mb module _ {lo la l≈} (C : Category lo la l≈) where infixr 9 _∘_ private module C = Category C module ≈ = C.≈ open C.≈-Reasoning data Tm : C.Obj → C.Obj → Set (lo ⊔ la) where var : ∀ {A B} → A C.⇒ B → Tm A B id : ∀ {A} → Tm A A _∘_ : ∀ {A B C} → Tm B C → Tm A B → Tm A C ⟦_⟧ : ∀ {A B} → Tm A B → A C.⇒ B ⟦ var f ⟧ = f ⟦ id ⟧ = C.id ⟦ f ∘ g ⟧ = ⟦ f ⟧ C.∘ ⟦ g ⟧ Method : Set (lo ⊔ la) Method = ∀ {A B} → Tm A B → Tm A B Correct : Method → Set (lo ⊔ la ⊔ l≈) Correct f = ∀ {A B} (t : Tm A B) → ⟦ t ⟧ C.≈ ⟦ f t ⟧ Correct→Injective : (f : Method) → Correct f → ∀ {A B} (t u : Tm A B) → ⟦ f t ⟧ C.≈ ⟦ f u ⟧ → ⟦ t ⟧ C.≈ ⟦ u ⟧ Correct→Injective f fcor t u eq = ≈.trans (fcor t) (≈.trans eq (≈.sym (fcor u))) ⊚-correct : (f g : Method) → Correct f → Correct g → Correct (f ⊚ g) ⊚-correct _ _ fcor gcor t = ≈.trans (gcor _) (fcor _) {-# TERMINATING #-} reassoc : Method reassoc (var f) = var f reassoc id = id reassoc (var f ∘ g) = var f ∘ reassoc g reassoc (id ∘ g) = id ∘ reassoc g reassoc ((f ∘ g) ∘ h) = reassoc (f ∘ g ∘ h) {-# TERMINATING #-} reassoc-correct : Correct reassoc reassoc-correct (var f) = C.≈.refl reassoc-correct id = C.≈.refl reassoc-correct (var f ∘ g) = C.∘-resp-r (reassoc-correct g) reassoc-correct (id ∘ f) = C.∘-resp-r (reassoc-correct f) reassoc-correct ((f ∘ g) ∘ h) = ≈.trans C.assoc (reassoc-correct (f ∘ g ∘ h)) simpId : Method simpId (var x) = var x simpId id = id simpId (f ∘ g) with simpId f | simpId g ... | var f′ | var g′ = var f′ ∘ var g′ ... | var f′ | id = var f′ ... | var f′ | g′ ∘ g″ = var f′ ∘ g′ ∘ g″ ... | id | g′ = g′ ... | f′ ∘ f″ | var g′ = f′ ∘ f″ ∘ var g′ ... | f′ ∘ f″ | id = f′ ∘ f″ ... | f′ ∘ f″ | g′ ∘ g″ = f′ ∘ f″ ∘ g′ ∘ g″ simpId-correct : Correct simpId simpId-≡ : ∀ {A B} t {u : Tm A B} → simpId t ≡ u → ⟦ t ⟧ C.≈ ⟦ u ⟧ simpId-correct (var x) = C.≈.refl simpId-correct id = C.≈.refl simpId-correct (f ∘ g) with simpId f | inspect simpId f | simpId g | inspect simpId g ... | var f′ | [ eq-f ] | var g′ | [ eq-g ] = C.∘-resp (simpId-≡ f eq-f) (simpId-≡ g eq-g) ... | var f′ | [ eq-f ] | id | [ eq-g ] = ≈.trans (C.∘-resp (simpId-≡ f eq-f) (simpId-≡ g eq-g)) C.id-r ... | var f′ | [ eq-f ] | g′ ∘ g″ | [ eq-g ] = C.∘-resp (simpId-≡ f eq-f) (simpId-≡ g eq-g) ... | id | [ eq-f ] | g' | [ eq-g ] = ≈.trans (C.∘-resp (simpId-≡ f eq-f) (simpId-≡ g eq-g)) C.id-l ... | f′ ∘ f″ | [ eq-f ] | var x | [ eq-g ] = ≈.trans (C.∘-resp (simpId-≡ f eq-f) (simpId-≡ g eq-g)) C.assoc ... | f′ ∘ f″ | [ eq-f ] | id | [ eq-g ] = ≈.trans (C.∘-resp (simpId-≡ f eq-f) (simpId-≡ g eq-g)) C.id-r ... | f′ ∘ f″ | [ eq-f ] | g′ ∘ g″ | [ eq-g ] = ≈.trans (C.∘-resp (simpId-≡ f eq-f) (simpId-≡ g eq-g)) C.assoc simpId-≡ t eq = ≈.trans (simpId-correct t) (≈.reflexive (≡.cong ⟦_⟧ eq)) simp : Method simp = reassoc ⊚ simpId simp-correct : Correct simp simp-correct = ⊚-correct reassoc simpId reassoc-correct simpId-correct simp-injective : ∀ {A B} (t u : Tm A B) → ⟦ simp t ⟧ C.≈ ⟦ simp u ⟧ → ⟦ t ⟧ C.≈ ⟦ u ⟧ simp-injective = Correct→Injective simp simp-correct simp-injective′ : ∀ {A B} (t u : Tm A B) → simp t ≡ simp u → ⟦ t ⟧ C.≈ ⟦ u ⟧ simp-injective′ t u eq = simp-injective t u (≈.reflexive (≡.cong ⟦_⟧ eq)) reify : Term → Term reify (def (quote Category.id) (argH _ ∷ argH _ ∷ argH _ ∷ argD C ∷ argH _ ∷ [])) = con (quote id) [] reify (def (quote Category._∘_) (argH _ ∷ argH _ ∷ argH _ ∷ argD C ∷ argH _ ∷ argH _ ∷ argH _ ∷ argD f ∷ argD g ∷ [])) = con (quote _∘_) (argD (reify f) ∷ argD (reify g) ∷ []) reify t = con (quote Tm.var) (argD t ∷ []) matchGoal : Term → TC (Term × Term) matchGoal (def (quote Category._≈_) (argH _ ∷ argH _ ∷ argH _ ∷ argD C ∷ argH A ∷ argH B ∷ argD f ∷ argD g ∷ [])) = return (reify f , reify g) matchGoal _ = typeError (strErr "matchGoal: not an equality" ∷ []) macro simp! : ∀ {lo la l≈} → Category lo la l≈ → Term → TC ⊤ simp! C hole = do goal ← inferType hole blockOnAnyMeta goal (lhs , rhs) ← matchGoal goal C′ ← quoteTC C let solution = def (quote simp-injective′) ( argD C′ ∷ argD lhs ∷ argD rhs ∷ argD (con (quote ≡.refl) []) ∷ []) unify hole solution module Test {lo la l≈} {C : Category lo la l≈} (let module C = Category C) {A B C′ D} {f : C′ C.⇒ D} {g : B C.⇒ C′} {h : A C.⇒ B} where test : ((C.id C.∘ f) C.∘ g) C.∘ h C.≈ C.id C.∘ f C.∘ g C.∘ h test = simp! C
28.917582
135
0.505225
4bf45c11d0fa024c0e3246f276d65e0f53bee89f
6,967
agda
Agda
Groups/FreeGroup/Group.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
4
2019-08-08T12:44:19.000Z
2022-01-28T06:04:15.000Z
Groups/FreeGroup/Group.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
14
2019-01-06T21:11:59.000Z
2020-04-11T11:03:39.000Z
Groups/FreeGroup/Group.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
1
2021-11-29T13:23:07.000Z
2021-11-29T13:23:07.000Z
{-# OPTIONS --safe --warning=error #-} open import Setoids.Setoids open import Groups.FreeGroup.Definition open import Groups.Definition open import Decidable.Sets open import Numbers.Naturals.Order open import LogicalFormulae open import Semirings.Definition module Groups.FreeGroup.Group {a : _} {A : Set a} (decA : DecidableSet A) where open import Groups.FreeGroup.Word decA prepend : ReducedWord → FreeCompletion A → ReducedWord prepend empty x = prependLetter x empty (wordEmpty refl) prepend (prependLetter (ofLetter y) w pr) (ofLetter x) = prependLetter (ofLetter x) (prependLetter (ofLetter y) w pr) (wordEnding (succIsPositive _) (freeCompletionEqualFalse decA {ofLetter x} {ofInv x} λ ())) prepend (prependLetter (ofInv y) w pr) (ofLetter x) with decA x y ... | inl x=y = w ... | inr x!=y = prependLetter (ofLetter x) (prependLetter (ofInv y) w pr) (wordEnding (succIsPositive _) (freeCompletionEqualFalse decA {ofLetter x} {ofLetter y} λ pr → x!=y (ofLetterInjective pr))) prepend (prependLetter (ofLetter y) w pr) (ofInv x) with decA x y ... | inl x=y = w ... | inr x!=y = prependLetter (ofInv x) (prependLetter (ofLetter y) w pr) (wordEnding (succIsPositive _) (freeCompletionEqualFalse decA λ pr → x!=y (ofInvInjective pr))) prepend (prependLetter (ofInv y) w pr) (ofInv x) = prependLetter (ofInv x) (prependLetter (ofInv y) w pr) (wordEnding (succIsPositive _) (freeCompletionEqualFalse decA {ofInv x} {ofLetter x} (λ ()))) _+W_ : ReducedWord → ReducedWord → ReducedWord empty +W b = b prependLetter letter a x +W b = prepend (a +W b) letter prependValid : (w : ReducedWord) (l : A) → (x : PrependIsValid w (ofLetter l)) → prepend w (ofLetter l) ≡ prependLetter (ofLetter l) w x prependValid empty l (wordEmpty refl) = refl prependValid (prependLetter (ofLetter l2) w x) l pr = prependLetterRefl prependValid (prependLetter (ofInv l2) w x) l pr with decA l l2 prependValid (prependLetter (ofInv l2) w x) .l2 (wordEnding _ x1) | inl refl = exFalso (freeCompletionEqualFalse' decA x1 refl) ... | inr l!=l2 = prependLetterRefl prependValid' : (w : ReducedWord) (l : A) → (x : PrependIsValid w (ofInv l)) → prepend w (ofInv l) ≡ prependLetter (ofInv l) w x prependValid' empty l (wordEmpty refl) = refl prependValid' (prependLetter (ofLetter l2) w x) l pr with decA l l2 prependValid' (prependLetter (ofLetter l2) w x) .l2 (wordEnding _ x1) | inl refl = exFalso (freeCompletionEqualFalse' decA x1 refl) ... | inr l!=l2 = prependLetterRefl prependValid' (prependLetter (ofInv l2) w x) l pr = prependLetterRefl prependInv : (w : ReducedWord) (l : A) → prepend (prepend w (ofLetter l)) (ofInv l) ≡ w prependInv empty l with decA l l ... | inl l=l = refl ... | inr l!=l = exFalso (l!=l refl) prependInv (prependLetter (ofLetter l2) w x) l with decA l l ... | inl l=l = refl ... | inr l!=l = exFalso (l!=l refl) prependInv (prependLetter (ofInv l2) w x) l with decA l l2 prependInv (prependLetter (ofInv l2) w x) .l2 | inl refl = prependValid' w l2 x ... | inr l!=l2 with decA l l prependInv (prependLetter (ofInv l2) w x) l | inr l!=l2 | inl refl = refl prependInv (prependLetter (ofInv l2) w x) l | inr l!=l2 | inr bad = exFalso (bad refl) prependInv' : (w : ReducedWord) (l : A) → prepend (prepend w (ofInv l)) (ofLetter l) ≡ w prependInv' empty l with decA l l ... | inl l=l = refl ... | inr l!=l = exFalso (l!=l refl) prependInv' (prependLetter (ofLetter l2) w x) l with decA l l2 prependInv' (prependLetter (ofLetter l2) w x) .l2 | inl refl = prependValid w l2 x ... | inr l!=l2 with decA l l ... | inl refl = refl ... | inr l!=l = exFalso (l!=l refl) prependInv' (prependLetter (ofInv l2) w x) l with decA l l prependInv' (prependLetter (ofInv l2) w x) l | inl refl = refl prependInv' (prependLetter (ofInv l2) w x) l | inr l!=l = exFalso (l!=l refl) prependAndAdd : (a b : ReducedWord) (l : FreeCompletion A) → prepend (a +W b) l ≡ (prepend a l) +W b prependAndAdd empty b l = refl prependAndAdd (prependLetter (ofLetter x) w pr) b (ofLetter y) = refl prependAndAdd (prependLetter (ofLetter x) w pr) b (ofInv y) with decA y x prependAndAdd (prependLetter (ofLetter x) w pr) b (ofInv .x) | inl refl = prependInv _ _ ... | inr y!=x = refl prependAndAdd (prependLetter (ofInv x) w pr) b (ofLetter y) with decA y x prependAndAdd (prependLetter (ofInv x) w pr) b (ofLetter .x) | inl refl = prependInv' _ _ ... | inr y!=x = refl prependAndAdd (prependLetter (ofInv x) w pr) b (ofInv y) = refl +WAssoc : (a b c : ReducedWord) → (a +W (b +W c)) ≡ ((a +W b) +W c) +WAssoc empty b c = refl +WAssoc (prependLetter letter a x) b c rewrite equalityCommutative (prependAndAdd (a +W b) c letter) | +WAssoc a b c = refl inverseW : ReducedWord → ReducedWord inverseW empty = empty inverseW (prependLetter letter w x) = (inverseW w) +W prependLetter (freeInverse letter) empty (wordEmpty refl) identRightW : (a : ReducedWord) → a +W empty ≡ a identRightW empty = refl identRightW (prependLetter (ofLetter l) a x) rewrite identRightW a = prependValid a l x identRightW (prependLetter (ofInv l) a x) rewrite identRightW a = prependValid' a l x invLeftW : (a : ReducedWord) → (inverseW a) +W a ≡ empty invLeftW empty = refl invLeftW (prependLetter (ofLetter l) a x) rewrite equalityCommutative (+WAssoc (inverseW a) (prependLetter (ofInv l) empty (wordEmpty refl)) (prependLetter (ofLetter l) a x)) = t where t : (inverseW a +W (prepend (prependLetter (ofLetter l) a x) (ofInv l))) ≡ empty t with decA l l ... | inl refl = invLeftW a ... | inr l!=l = exFalso (l!=l refl) invLeftW (prependLetter (ofInv l) a x) rewrite equalityCommutative (+WAssoc (inverseW a) (prependLetter (ofLetter l) empty (wordEmpty refl)) (prependLetter (ofInv l) a x)) = t where t : (inverseW a +W (prepend (prependLetter (ofInv l) a x) (ofLetter l))) ≡ empty t with decA l l ... | inl refl = invLeftW a ... | inr l!=l = exFalso (l!=l refl) invRightW : (a : ReducedWord) → a +W (inverseW a) ≡ empty invRightW empty = refl invRightW (prependLetter (ofLetter l) a x) rewrite +WAssoc a (inverseW a) (prependLetter (ofInv l) empty (wordEmpty refl)) | invRightW a = t where t : prepend (prependLetter (ofInv l) empty (wordEmpty refl)) (ofLetter l) ≡ empty t with decA l l ... | inl refl = refl ... | inr l!=l = exFalso (l!=l refl) invRightW (prependLetter (ofInv l) a x) rewrite +WAssoc a (inverseW a) (prependLetter (ofLetter l) empty (wordEmpty refl)) | invRightW a = t where t : prepend (prependLetter (ofLetter l) empty (wordEmpty refl)) (ofInv l) ≡ empty t with decA l l ... | inl refl = refl ... | inr l!=l = exFalso (l!=l refl) freeGroup : Group (reflSetoid ReducedWord) _+W_ Group.+WellDefined freeGroup refl refl = refl Group.0G freeGroup = empty Group.inverse freeGroup = inverseW Group.+Associative freeGroup {a} {b} {c} = +WAssoc a b c Group.identRight freeGroup {a} = identRightW a Group.identLeft freeGroup {a} = refl Group.invLeft freeGroup {a} = invLeftW a Group.invRight freeGroup {a} = invRightW a
52.383459
209
0.695278
1d786d498e03b528673779225b2915da2ce08b3a
4,297
agda
Agda
part1/decidable/decidable.agda
akiomik/plfa-solutions
df7722b88a9b3dfde320a690b78c4c1ef8c7c547
[ "Apache-2.0" ]
1
2020-07-07T09:42:22.000Z
2020-07-07T09:42:22.000Z
part1/decidable/decidable.agda
akiomik/plfa-solutions
df7722b88a9b3dfde320a690b78c4c1ef8c7c547
[ "Apache-2.0" ]
null
null
null
part1/decidable/decidable.agda
akiomik/plfa-solutions
df7722b88a9b3dfde320a690b78c4c1ef8c7c547
[ "Apache-2.0" ]
null
null
null
module decidable where import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl) open Eq.≡-Reasoning open import Data.Nat using (ℕ; zero; suc) open import Data.Product using (_×_) renaming (_,_ to ⟨_,_⟩) open import Data.Sum using (_⊎_; inj₁; inj₂) open import Relation.Nullary using (¬_) open import Relation.Nullary.Negation using () renaming (contradiction to ¬¬-intro) open import Data.Unit using (⊤; tt) open import Data.Empty using (⊥; ⊥-elim) -- open import plfa.part1.Relations using (_<_; z<s; s<s) -- open import plfa.part1.Isomorphism using (_⇔_) infix 4 _<_ data _<_ : ℕ → ℕ → Set where z<s : ∀ {n : ℕ} ------------ → zero < suc n s<s : ∀ {m n : ℕ} → m < n ------------- → suc m < suc n record _⇔_ (A B : Set) : Set where field to : A → B from : B → A -- Evidence vs Computation infix 4 _≤_ data _≤_ : ℕ → ℕ → Set where z≤n : ∀ {n : ℕ} -------- → zero ≤ n s≤s : ∀ {m n : ℕ} → m ≤ n ------------- → suc m ≤ suc n 2≤4 : 2 ≤ 4 2≤4 = s≤s (s≤s z≤n) ¬4≤2 : ¬ (4 ≤ 2) ¬4≤2 (s≤s (s≤s ())) data Bool : Set where true : Bool false : Bool infix 4 _≤ᵇ_ _≤ᵇ_ : ℕ → ℕ → Bool zero ≤ᵇ n = true suc m ≤ᵇ zero = false suc m ≤ᵇ suc n = m ≤ᵇ n _ : (2 ≤ᵇ 4) ≡ true _ = begin 2 ≤ᵇ 4 ≡⟨⟩ 1 ≤ᵇ 3 ≡⟨⟩ 0 ≤ᵇ 2 ≡⟨⟩ true ∎ _ : (4 ≤ᵇ 2) ≡ false _ = begin 4 ≤ᵇ 2 ≡⟨⟩ 3 ≤ᵇ 1 ≡⟨⟩ 2 ≤ᵇ 0 ≡⟨⟩ false ∎ -- Relating evidence and computation T : Bool → Set T true = ⊤ T false = ⊥ T→≡ : ∀ (b : Bool) → T b → b ≡ true T→≡ true tt = refl T→≡ false () ≡→T : ∀ {b : Bool} → b ≡ true → T b ≡→T refl = tt ≤ᵇ→≤ : ∀ (m n : ℕ) → T (m ≤ᵇ n) → m ≤ n ≤ᵇ→≤ zero n tt = z≤n ≤ᵇ→≤ (suc m) zero () ≤ᵇ→≤ (suc m) (suc n) t = s≤s (≤ᵇ→≤ m n t) ≤→≤ᵇ : ∀ {m n : ℕ} → m ≤ n → T (m ≤ᵇ n) ≤→≤ᵇ z≤n = tt ≤→≤ᵇ (s≤s m≤n) = ≤→≤ᵇ m≤n -- The best of both worlds -- decidable data Dec (A : Set) : Set where yes : A → Dec A no : ¬ A → Dec A ¬s≤z : ∀ {m : ℕ} → ¬ (suc m ≤ zero) ¬s≤z () ¬s≤s : ∀ {m n : ℕ} → ¬ (m ≤ n) → ¬ (suc m ≤ suc n) ¬s≤s ¬m≤n (s≤s m≤n) = ¬m≤n m≤n _≤?_ : ∀ (m n : ℕ) → Dec (m ≤ n) zero ≤? n = yes z≤n suc m ≤? zero = no ¬s≤z suc m ≤? suc n with m ≤? n ... | yes m≤n = yes (s≤s m≤n) ... | no ¬m≤n = no (¬s≤s ¬m≤n) _ : 2 ≤? 4 ≡ yes (s≤s (s≤s z≤n)) _ = refl _ : 4 ≤? 2 ≡ no (¬s≤s (¬s≤s ¬s≤z)) _ = refl -- Decidables from booleans, and booleans from decidables _≤?′_ : ∀ (m n : ℕ) → Dec (m ≤ n) m ≤?′ n with m ≤ᵇ n | ≤ᵇ→≤ m n | ≤→≤ᵇ {m} {n} ... | true | p | _ = yes (p tt) ... | false | _ | ¬p = no ¬p -- erasure ⌊_⌋ : ∀ {A : Set} → Dec A → Bool ⌊ yes x ⌋ = true ⌊ no ¬x ⌋ = false _≤ᵇ′_ : ℕ → ℕ → Bool m ≤ᵇ′ n = ⌊ m ≤? n ⌋ toWitness : ∀ {A : Set} {D : Dec A} → T ⌊ D ⌋ → A toWitness {A} {yes x} tt = x toWitness {A} {no ¬x} () fromWitness : ∀ {A : Set} {D : Dec A} → A → T ⌊ D ⌋ fromWitness {A} {yes x} _ = tt fromWitness {A} {no ¬x} x = ¬x x ≤ᵇ′→≤ : ∀ {m n : ℕ} → T (m ≤ᵇ′ n) → m ≤ n ≤ᵇ′→≤ = toWitness ≤→≤ᵇ′ : ∀ {m n : ℕ} → m ≤ n → T (m ≤ᵇ′ n) ≤→≤ᵇ′ = fromWitness -- Logical connectives (論理演算) -- 真偽値の論理積 infixr 6 _∧_ _∧_ : Bool → Bool → Bool true ∧ true = true false ∧ _ = false _ ∧ false = false -- decidableの論理積 infixr 6 _×-dec_ _×-dec_ : ∀ {A B : Set} → Dec A → Dec B → Dec (A × B) yes x ×-dec yes y = yes ⟨ x , y ⟩ no ¬x ×-dec _ = no λ{ ⟨ x , y ⟩ → ¬x x } _ ×-dec no ¬y = no λ{ ⟨ x , y ⟩ → ¬y y } -- 真偽値の論理和 infixr 5 _∨_ _∨_ : Bool → Bool → Bool true ∨ _ = true _ ∨ true = true false ∨ false = false -- decidableの論理和 infixr 5 _⊎-dec_ _⊎-dec_ : ∀ {A B : Set} → Dec A → Dec B → Dec (A ⊎ B) yes x ⊎-dec _ = yes (inj₁ x) _ ⊎-dec yes y = yes (inj₂ y) no ¬x ⊎-dec no ¬y = no λ{ (inj₁ x) → ¬x x ; (inj₂ y) → ¬y y } -- 真偽値の否定 not : Bool → Bool not true = false not false = true -- decidableの否定 ¬? : ∀ {A : Set} → Dec A → Dec (¬ A) ¬? (yes x) = no (¬¬-intro x) ¬? (no ¬x) = yes ¬x -- 真偽値の含意 _⊃_ : Bool → Bool → Bool _ ⊃ true = true false ⊃ _ = true true ⊃ false = false -- decidableの含意 _→-dec_ : ∀ {A B : Set} → Dec A → Dec B → Dec (A → B) _ →-dec yes y = yes (λ _ → y) no ¬x →-dec _ = yes (λ x → ⊥-elim (¬x x)) yes x →-dec no ¬y = no (λ f → ¬y (f x))
19.621005
61
0.461717
5872c15588b778e6c592fb7f8d02230d5211f4d8
2,139
agda
Agda
src/Tactic/Reflection/Replace.agda
UlfNorell/agda-prelude
d704381936db6bd393e63aa2740345e7364f9732
[ "MIT" ]
111
2015-01-05T11:28:15.000Z
2022-02-12T23:29:26.000Z
src/Tactic/Reflection/Replace.agda
UlfNorell/agda-prelude
d704381936db6bd393e63aa2740345e7364f9732
[ "MIT" ]
59
2016-02-09T05:36:44.000Z
2022-01-14T07:32:36.000Z
src/Tactic/Reflection/Replace.agda
UlfNorell/agda-prelude
d704381936db6bd393e63aa2740345e7364f9732
[ "MIT" ]
24
2015-03-12T18:03:45.000Z
2021-04-22T06:10:41.000Z
module Tactic.Reflection.Replace where open import Prelude open import Container.Traversable open import Tactic.Reflection open import Tactic.Reflection.Equality {-# TERMINATING #-} _r[_/_] : Term → Term → Term → Term p r[ r / l ] = ifYes p == l then r else case p of λ { (var x args) → var x $ args r₂[ r / l ] ; (con c args) → con c $ args r₂[ r / l ] ; (def f args) → def f $ args r₂[ r / l ] ; (lam v t) → lam v $ t r₁[ weaken 1 r / weaken 1 l ] -- lam v <$> t r₁[ weaken 1 r / weaken 1 l ] ; (pat-lam cs args) → let w = length args in pat-lam (replaceClause (weaken w l) (weaken w r) <$> cs) $ args r₂[ r / l ] ; (pi a b) → pi (a r₁[ r / l ]) (b r₁[ weaken 1 r / weaken 1 l ]) ; (agda-sort s) → agda-sort $ replaceSort l r s ; (lit l) → lit l ; (meta x args) → meta x $ args r₂[ r / l ] ; unknown → unknown } where replaceClause : Term → Term → Clause → Clause replaceClause l r (clause tel pats x) = clause tel pats $ x r[ r / l ] replaceClause l r (absurd-clause tel pats) = absurd-clause tel pats replaceSort : Term → Term → Sort → Sort replaceSort l r (set t) = set $ t r[ r / l ] replaceSort l r (lit n) = lit n replaceSort l r (prop t) = prop $ t r[ r / l ] replaceSort l r (propLit n) = propLit n replaceSort l r (inf n) = inf n replaceSort l r unknown = unknown _r₁[_/_] : {T₀ : Set → Set} {{_ : Traversable T₀}} → T₀ Term → Term → Term → T₀ Term p r₁[ r / l ] = _r[ r / l ] <$> p _r₂[_/_] : {T₀ T₁ : Set → Set} {{_ : Traversable T₀}} {{_ : Traversable T₁}} → T₁ (T₀ Term) → Term → Term → T₁ (T₀ Term) p r₂[ r / l ] = fmap _r[ r / l ] <$> p _R[_/_] : List (Arg Type) → Type → Type → List (Arg Type) Γ R[ L / R ] = go Γ (strengthen 1 L) (strengthen 1 R) where go : List (Arg Type) → Maybe Term → Maybe Term → List (Arg Type) go (γ ∷ Γ) (just L) (just R) = (caseF γ of _r[ L / R ]) ∷ go Γ (strengthen 1 L) (strengthen 1 R) go Γ _ _ = Γ
39.611111
106
0.518934
57b9f3cec6d51277842f110775134eadad9cba7f
1,030
agda
Agda
test/Fail/Issue970.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue970.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue970.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
data Dec (A : Set) : Set where yes : A → Dec A no : Dec A record ⊤ : Set where constructor tt data _≡_ {A : Set}(x : A) : A → Set where refl : x ≡ x subst : ∀ {A}(P : A → Set){x y} → x ≡ y → P x → P y subst P refl px = px cong : ∀ {A B}(f : A → B){x y} → x ≡ y → f x ≡ f y cong f refl = refl postulate _≟_ : (n n' : ⊤) → Dec (n ≡ n') record _×_ (A B : Set) : Set where constructor _,_ field proj₁ : A proj₂ : B open _×_ data Maybe : Set where nothing : Maybe data Blah (a : Maybe × ⊤) : Set where blah : {b : Maybe × ⊤} → Blah b → Blah a update : {A : Set} → ⊤ → A → A update n m with n ≟ n update n m | yes p = m update n m | no = m lem-upd : ∀ {A} n (m : A) → update n m ≡ m lem-upd n m with n ≟ n ... | yes p = refl ... | no = refl bug : {x : Maybe × ⊤} → proj₁ x ≡ nothing → Blah x bug ia = blah (bug (subst {⊤} (λ _ → proj₁ {B = ⊤} (update tt (nothing , tt)) ≡ nothing) refl (cong proj₁ (lem-upd _ _))))
21.914894
72
0.475728
501a36ee8612845a30f0dc1f5596a957046d874c
3,442
agda
Agda
core/lib/types/SetQuotient.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
null
null
null
core/lib/types/SetQuotient.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
null
null
null
core/lib/types/SetQuotient.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
1
2018-12-26T21:31:57.000Z
2018-12-26T21:31:57.000Z
{-# OPTIONS --without-K --rewriting #-} open import lib.Basics open import lib.Relation open import lib.NType2 open import lib.types.Pi module lib.types.SetQuotient {i} {A : Type i} {j} where postulate -- HIT SetQuot : (R : Rel A j) → Type (lmax i j) module _ {R : Rel A j} where postulate -- HIT q[_] : (a : A) → SetQuot R quot-rel : {a₁ a₂ : A} → R a₁ a₂ → q[ a₁ ] == q[ a₂ ] SetQuot-level : is-set (SetQuot R) SetQuot-is-set = SetQuot-level module SetQuotElim {k} {P : SetQuot R → Type k} (p : (x : SetQuot R) → is-set (P x)) (q[_]* : (a : A) → P q[ a ]) (rel* : ∀ {a₁ a₂} (r : R a₁ a₂) → q[ a₁ ]* == q[ a₂ ]* [ P ↓ quot-rel r ]) where postulate -- HIT f : Π (SetQuot R) P q[_]-β : (a : A) → f q[ a ] ↦ q[ a ]* {-# REWRITE q[_]-β #-} postulate -- HIT quot-rel-β : ∀ {a₁ a₂} (r : R a₁ a₂) → apd f (quot-rel r) == rel* r open SetQuotElim public using () renaming (f to SetQuot-elim) module SetQuotRec {k} {B : Type k} (p : is-set B) (q[_]* : A → B) (rel* : ∀ {a₁ a₂} (r : R a₁ a₂) → q[ a₁ ]* == q[ a₂ ]*) where private module M = SetQuotElim (λ x → p) q[_]* (λ {a₁ a₂} r → ↓-cst-in (rel* r)) f : SetQuot R → B f = M.f open SetQuotRec public using () renaming (f to SetQuot-rec) -- If [R] is an equivalence relation, then [quot-rel] is an equivalence. module _ {R : Rel A j} (R-is-prop : ∀ {a b} → is-prop (R a b)) (R-is-refl : is-refl R) (R-is-sym : is-sym R) (R-is-trans : is-trans R) where private Q : Type (lmax i j) Q = SetQuot R R'-over-quot : Q → Q → hProp j R'-over-quot = SetQuot-rec (→-is-set $ hProp-is-set j) (λ a → SetQuot-rec (hProp-is-set j) (λ b → R a b , R-is-prop) (nType=-out ∘ lemma-a)) (λ ra₁a₂ → λ= $ SetQuot-elim (λ _ → raise-level -1 $ hProp-is-set j _ _) (λ _ → nType=-out $ lemma-b ra₁a₂) (λ _ → prop-has-all-paths-↓ $ hProp-is-set j _ _)) where abstract lemma-a : ∀ {a b₁ b₂} → R b₁ b₂ → R a b₁ == R a b₂ lemma-a rb₁b₂ = ua $ equiv (λ rab₁ → R-is-trans rab₁ rb₁b₂) (λ rab₂ → R-is-trans rab₂ (R-is-sym rb₁b₂)) (λ _ → prop-has-all-paths R-is-prop _ _) (λ _ → prop-has-all-paths R-is-prop _ _) lemma-b : ∀ {a₁ a₂ b} → R a₁ a₂ → R a₁ b == R a₂ b lemma-b ra₁a₂ = ua $ equiv (λ ra₁b → R-is-trans (R-is-sym ra₁a₂) ra₁b) (λ ra₂b → R-is-trans ra₁a₂ ra₂b) (λ _ → prop-has-all-paths R-is-prop _ _) (λ _ → prop-has-all-paths R-is-prop _ _) R-over-quot : Q → Q → Type j R-over-quot q₁ q₂ = fst (R'-over-quot q₁ q₂) abstract R-over-quot-is-prop : {q₁ q₂ : Q} → is-prop (R-over-quot q₁ q₂) R-over-quot-is-prop {q₁} {q₂} = snd (R'-over-quot q₁ q₂) R-over-quot-is-refl : (q : Q) → R-over-quot q q R-over-quot-is-refl = SetQuot-elim (λ q → raise-level -1 (R-over-quot-is-prop {q} {q})) (λ a → R-is-refl a) (λ _ → prop-has-all-paths-↓ R-is-prop) path-to-R-over-quot : {q₁ q₂ : Q} → q₁ == q₂ → R-over-quot q₁ q₂ path-to-R-over-quot {q} idp = R-over-quot-is-refl q quot-rel-equiv : ∀ {a₁ a₂ : A} → R a₁ a₂ ≃ (q[ a₁ ] == q[ a₂ ]) quot-rel-equiv {a₁} {a₂} = equiv quot-rel (path-to-R-over-quot {q[ a₁ ]} {q[ a₂ ]}) (λ _ → prop-has-all-paths (SetQuot-is-set _ _) _ _) (λ _ → prop-has-all-paths R-is-prop _ _)
33.096154
84
0.518594
c701136a207356f982c526cfb3dad7ae86fab3c9
10,926
agda
Agda
archive/agda-2/Oscar/Object.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
archive/agda-2/Oscar/Object.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
1
2019-04-29T00:35:04.000Z
2019-05-11T23:33:04.000Z
archive/agda-2/Oscar/Object.agda
m0davis/oscar
52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb
[ "RSA-MD" ]
null
null
null
module Oscar.Object {𝔣} (FunctionName : Set 𝔣) where open import Oscar.Category.Category open import Oscar.Category.Functor open import Oscar.Category.Morphism open import Oscar.Category.Semifunctor open import Oscar.Category.Semigroupoid open import Oscar.Category.Setoid open import Oscar.Data.Nat {- open import Oscar.Data.AList FunctionName open import Oscar.Data.Equality open import Oscar.Data.Equality.properties open import Oscar.Data.Fin open import Oscar.Data.List open import Oscar.Data.Nat open import Oscar.Data.Product open import Oscar.Data.Step FunctionName open import Oscar.Data.Term FunctionName open import Oscar.Data.Term.internal.SubstituteAndSubstitution FunctionName open import Oscar.Data.Unit -} open import Oscar.Function open import Oscar.Level {- List : Set ListNatAction : Nat → Set ListNatMorphism : Nat → Nat → Set Nat : Set NatNatAction : Nat → Set NatNatMorphism : Nat → Nat → Set -} {- data ⋆ : Set where ∅ : ⋆ ↧ : ⋆ → ⋆ data ⟱ {a} {A : Set a} : Set a where data Nat[_↦_] (m : Nat) : Nat → Set where zero : Nat[ m ↦ m ] suc : ∀ {n} → Nat[ m ↦ n ] → Nat[ m ↦ suc n ] _+²_ : ∀ {i₂ i₃} → Nat[ i₂ ↦ i₃ ] → ∀ {i₁} → Nat[ i₁ ↦ i₂ ] → Nat[ i₁ ↦ i₃ ] zero +² y = y suc x +² y = suc (x +² y) data Nat↥ = Fin bar = Nat[ 0 ↦ 3 ] br = Nat br2 = Nat↥ 3 -} open import Oscar.Data5 data Indexed : Set (lsuc ℓ) where iset₀ : (⟦⟧ → Set) → Indexed isetℓ : (⟦⟧ → Set ℓ) → Indexed vec : ⟦⟧ → Indexed → Indexed list : Indexed → Indexed function : Indexed → Indexed → Indexed data IsMonoid : Indexed → Set where list : ∀ i → IsMonoid (list i) function : ∀ i j → IsMonoid (function i j) vec : ∀ n i → IsMonoid open import Level test-l : ∀ {ℓ} {ℓ'} → (⟦⟧ → Lift {ℓ = ℓ} Set) → (⟦⟧ → Lift {ℓ = ℓ'} Set) test-l f n = lift (lower (f n)) data Categorical : Set (lsuc ℓ) where set₀ : (⟦⟧ → ⟦⟧ → Set) → Categorical setℓ : (⟦⟧ → ⟦⟧ → Set ℓ) → Categorical function : Indexed → Indexed → Categorical {- e.g. Fin m → Term n -} monoidal-function : Indexed → Indexed → Categorical {- e.g. Fin n → Term n -} alist = setℓ AList ifin = iset₀ Fin iterm = isetℓ Term iterms = λ N → isetℓ (Terms N) istep = isetℓ Step iliststep = list (istep) finterm = relational-function ifin iterm termterm = relational-function iterm iterm termsterms = λ N → relational-function (iterms N) (iterms N) stepstep = relational-function istep istep data Functorial : Categorical → Categorical → Set (lsuc ℓ) where unpack : Functorial alist finterm substitute : Functorial finterm termterm substitutes : (N : ⟦⟧) → Functorial finterm (termsterms N) stepify : Functorial termterm stepstep collapse : (n : Nat) → Arrow (listStepN n) (termtermN n) reduce : (n : Nat) → Arrow (termtermN n) termterm COMPOSE : ∀ {o₂ o₃} → Functorial o₂ o₃ → ∀ {o₁} → Functorial o₁ o₂ → Functorial o₁ o₃ data Cat : Set where identity : Cat cat : Category → Cat compose : -- sustitute : Functorial -- unpack : Arrow alist finterm -- substitute : Arrow finterm termterm -- substitutes : (N : Nat) → Arrow finterm (termsterms N) -- stepify : Arrow termterm stepstep -- collapse : (n : Nat) → Arrow (listStepN n) (termtermN n) -- reduce : (n : Nat) → Arrow (termtermN n) termterm -- COMPOSE : ∀ {o₂ o₃} → Arrow o₂ o₃ → ∀ {o₁} → Arrow o₁ o₂ → Arrow o₁ o₃ -- finterm : Object -- termterm : Object -- termsterms : Nat → Object -- stepstep : Object -- listStepN : Nat → Object -- termtermN : Nat → Object -- list∘ : Object → Object -- {- -- object⋆ : Object → Set _ -- object⋆ alist = Nat -- object⋆ finterm = Nat -- object⋆ termterm = Nat -- object⋆ (termsterms N) = Nat -- object⋆ stepstep = Nat -- object⋆ (listStepN _) = ⊤ -- object⋆ (termtermN _) = ⊤ -- objectMorphism : (o : Object) → Morphism (object⋆ o) 𝔣 𝔣 -- objectMorphism alist = ⇧ AList -- objectMorphism finterm = Fin ⇨ Term -- objectMorphism termterm = Term ⇨ Term -- objectMorphism (termsterms N) = Terms N ⇨ Terms N -- objectMorphism stepstep = Step ⇨ Step -- Setoid.⋆ ((objectMorphism (listStepN n) Morphism.⇒ _) _) = List (Step n) -- IsSetoid._≋_ (Setoid.isSetoid ((objectMorphism (listStepN N) Morphism.⇒ _) _)) = _≡_ -- Setoid.⋆ ((objectMorphism (termtermN n) Morphism.⇒ _) _) = Term n → Term n -- IsSetoid._≋_ (Setoid.isSetoid ((objectMorphism (termtermN N) Morphism.⇒ _) _)) = _≡̇_ -- IsSetoid._≋_ (Morphism.isSetoid (objectMorphism (termtermN N))) = _≡̇_ -- -} -- objectCategory : Object → Category lzero 𝔣 𝔣 -- objectCategory alist = {!!} -- objectCategory finterm = 𝔾₁ -- objectCategory termterm = 𝔾₂ -- objectCategory (termsterms N) = 𝔾₂ₛ N -- objectCategory stepstep = {!!} -- objectCategory (listStepN x) = {!!} -- objectCategory (termtermN x) = {!!} -- Semigroupoid.⋆ (Category.semigroupoid (objectCategory (list∘ G))) = List (Category.⋆ (objectCategory G)) -- Morphism._⇒_ (Semigroupoid.𝔐 (Category.semigroupoid (objectCategory (list∘ G)))) = {!!} -- Morphism.isSetoid (Semigroupoid.𝔐 (Category.semigroupoid (objectCategory (list∘ G)))) = {!!} -- Semigroupoid._∙_ (Category.semigroupoid (objectCategory (list∘ G))) = {!!} -- Semigroupoid.isSemigroupoid (Category.semigroupoid (objectCategory (list∘ G))) = {!!} -- Category.ε (objectCategory (list∘ G)) = {!!} -- Category.isCategory (objectCategory (list∘ G)) = {!!} -- data Arrow : Object → Object → Set where -- unpack : Arrow alist finterm -- substitute : Arrow finterm termterm -- substitutes : (N : Nat) → Arrow finterm (termsterms N) -- stepify : Arrow termterm stepstep -- collapse : (n : Nat) → Arrow (listStepN n) (termtermN n) -- reduce : (n : Nat) → Arrow (termtermN n) termterm -- COMPOSE : ∀ {o₂ o₃} → Arrow o₂ o₃ → ∀ {o₁} → Arrow o₁ o₂ → Arrow o₁ o₃ -- data SimpleArrow : ∀ {o1 o2} → Arrow o1 o2 → Set where -- unpack : SimpleArrow unpack -- substitute : SimpleArrow substitute -- substitutes : (N : Nat) → SimpleArrow (substitutes N) -- stepify : SimpleArrow stepify -- collapse : (n : Nat) → SimpleArrow (collapse n) -- reduce : (n : Nat) → SimpleArrow (reduce n) -- import Data.List as LIST -- open import Algebra using (Monoid) -- serialiseArrow : ∀ {o1 o2} → Arrow o1 o2 → List (∃ λ o1 → ∃ λ o2 → ∃ λ (a : Arrow o1 o2) → SimpleArrow a) -- serialiseArrow unpack = (_ , _ , _ , unpack) ∷ [] -- serialiseArrow substitute = {!!} -- serialiseArrow (substitutes N) = {!!} -- serialiseArrow stepify = {!!} -- serialiseArrow (collapse n) = {!!} -- serialiseArrow (reduce n) = {!!} -- serialiseArrow (COMPOSE g f) = -- let g' = serialiseArrow g -- f' = serialiseArrow f -- in Monoid._∙_ (LIST.monoid (∃ (λ o1 → ∃ (λ o2 → ∃ SimpleArrow)))) g' f' -- open import Data.Empty -- eqArrow : ∀ {o1 o2} → Arrow o1 o2 → Arrow o1 o2 → Set -- eqArrow x y = serialiseArrow x ≡ serialiseArrow y -- open IsSemifunctor ⦃ … ⦄ using () renaming (extensionality to ext; distributivity to dist) -- module _ -- {𝔬₁ 𝔪₁ 𝔮₁ 𝔬₂ 𝔪₂ 𝔮₂ 𝔬₃ 𝔪₃ 𝔮₃} -- (c₁ : Semigroupoid 𝔬₁ 𝔪₁ 𝔮₁) -- (c₂ : Semigroupoid 𝔬₂ 𝔪₂ 𝔮₂) -- (c₃ : Semigroupoid 𝔬₃ 𝔪₃ 𝔮₃) -- where -- private -- module 𝔊₁ = Semigroupoid c₁ -- module 𝔊₂ = Semigroupoid c₂ -- module 𝔊₃ = Semigroupoid c₃ -- composeS : ∀ -- {μ₁₂ : 𝔊₁.⋆ → 𝔊₂.⋆} -- (𝔣₁₂ : ∀ {x y} → x 𝔊₁.↦ y → μ₁₂ x 𝔊₂.↦ μ₁₂ y) -- {μ₂₃ : 𝔊₂.⋆ → 𝔊₃.⋆} -- (𝔣₂₃ : ∀ {x y} → x 𝔊₂.↦ y → μ₂₃ x 𝔊₃.↦ μ₂₃ y) -- ⦃ _ : IsSemifunctor (c₁ , c₂) 𝔣₁₂ ⦄ -- ⦃ _ : IsSemifunctor (c₂ , c₃) 𝔣₂₃ ⦄ -- → IsSemifunctor (c₁ , c₃) (𝔣₂₃ ∘ 𝔣₁₂) -- IsSemifunctor.extensionality (composeS 𝔣₁₂ 𝔣₂₃ ⦃ isS₁ ⦄ ⦃ isS₂ ⦄) f₁≋f₂ = ext ⦃ isS₂ ⦄ (ext ⦃ isS₁ ⦄ f₁≋f₂) -- IsSemifunctor.distributivity (composeS {μ₁₂} 𝔣₁₂ {μ₂₃} 𝔣₂₃ ⦃ isS₁ ⦄ ⦃ isS₂ ⦄) {x} {y} f {z} g = -- let eq₁ = ext ⦃ isS₂ ⦄ (dist ⦃ isS₁ ⦄ f g) -- eq₂ = dist ⦃ isS₂ ⦄ (𝔣₁₂ f) (𝔣₁₂ g) -- instance _ = IsSetoid.isEquivalence 𝔊₃.isSetoid -- in transitivity eq₁ eq₂ -- module _ -- {𝔬₁ 𝔪₁ 𝔮₁ 𝔬₂ 𝔪₂ 𝔮₂ 𝔬₃ 𝔪₃ 𝔮₃} -- (c₁ : Category 𝔬₁ 𝔪₁ 𝔮₁) -- (c₂ : Category 𝔬₂ 𝔪₂ 𝔮₂) -- (c₃ : Category 𝔬₃ 𝔪₃ 𝔮₃) -- where -- private -- module 𝔊₁ = Category c₁ -- module 𝔊₂ = Category c₂ -- module 𝔊₃ = Category c₃ -- composeF : ∀ -- {μ₁₂ : 𝔊₁.⋆ → 𝔊₂.⋆} -- (𝔣₁₂ : ∀ {x y} → x 𝔊₁.↦ y → μ₁₂ x 𝔊₂.↦ μ₁₂ y) -- {μ₂₃ : 𝔊₂.⋆ → 𝔊₃.⋆} -- (𝔣₂₃ : ∀ {x y} → x 𝔊₂.↦ y → μ₂₃ x 𝔊₃.↦ μ₂₃ y) -- ⦃ _ : IsFunctor (c₁ , c₂) 𝔣₁₂ ⦄ -- ⦃ _ : IsFunctor (c₂ , c₃) 𝔣₂₃ ⦄ -- → IsFunctor (c₁ , c₃) (𝔣₂₃ ∘ 𝔣₁₂) -- IsFunctor.isSemifunctor (composeF 𝔣₁₂ 𝔣₂₃ ⦃ isF₁ ⦄ ⦃ isF₂ ⦄) = composeS _ _ _ _ _ ⦃ (IsFunctor.isSemifunctor isF₁) ⦄ ⦃ (IsFunctor.isSemifunctor isF₂) ⦄ -- IsFunctor.identity (composeF {μ₁₂} 𝔣₁₂ 𝔣₂₃ ⦃ isF₁ ⦄ ⦃ isF₂ ⦄) x = -- let f₁₂ε≋ε = identity ⦃ isF₁ ⦄ x -- f₂₃f₁₂ε≋f₂₃ε = ext ⦃ IsFunctor.isSemifunctor isF₂ ⦄ f₁₂ε≋ε -- f₂₃ε≋ε = identity ⦃ isF₂ ⦄ (μ₁₂ x) -- instance _ = IsSetoid.isEquivalence 𝔊₃.isSetoid -- in transitivity f₂₃f₁₂ε≋f₂₃ε f₂₃ε≋ε -- --𝔬₁ 𝔪₁ 𝔮₁ 𝔬₃ 𝔪₃ 𝔮₃ -- --composeF 𝔣₁₂ 𝔣₂₃ = (c₁ , c₃) , (𝔣₂₃ ∘ 𝔣₁₂) -- arrowIsFunctor : ∀ {o₁ o₂} → Arrow o₁ o₂ -- → ∃ λ μ -- → (let c1 = objectCategory o₁) -- (let c2 = objectCategory o₂) -- (let module 𝔊₁ = Category c1) -- (let module 𝔊₂ = Category c2) -- → ∃ λ (f : ∀ {x y} → x 𝔊₁.↦ y → μ x 𝔊₂.↦ μ y) -- → (IsFunctor (objectCategory o₁ , objectCategory o₂) {μ} f) -- arrowIsFunctor unpack = {!!} -- arrowIsFunctor substitute = _ , _ , IsFunctor𝔾₁,₂◂ -- arrowIsFunctor (substitutes N) = _ , _ , IsFunctor𝔾₁,₂ₛ◂ {N} -- arrowIsFunctor stepify = {!!} -- arrowIsFunctor (collapse n) = {!!} -- arrowIsFunctor (reduce n) = {!!} -- arrowIsFunctor (COMPOSE a1 a2) = -- let _ , _ , isF1 = arrowIsFunctor a1 -- _ , _ , isF2 = arrowIsFunctor a2 -- in _ , _ , composeF _ _ _ _ _ ⦃ isF2 ⦄ ⦃ isF1 ⦄ -- arrowFunctor : ∀ {o₁ o₂} → Arrow o₁ o₂ → Functor _ _ _ _ _ _ -- arrowFunctor {o₁} {o₂} a = -- let cs , f , IF = arrowIsFunctor a -- instance _ = IF -- in (objectCategory o₁ , objectCategory o₂) , f -- category : Category _ _ _ -- Semigroupoid.⋆ (Category.semigroupoid category) = Object -- Setoid.⋆ ((Semigroupoid.𝔐 (Category.semigroupoid category) Morphism.⇒ o1) o2) = Arrow o1 o2 -- IsSetoid._≋_ (Setoid.isSetoid ((Semigroupoid.𝔐 (Category.semigroupoid category) Morphism.⇒ x) x₁)) = {!!} -- IsSetoid.isEquivalence (Setoid.isSetoid ((Semigroupoid.𝔐 (Category.semigroupoid category) Morphism.⇒ x) x₁)) = {!!} -- IsSetoid._≋_ (Morphism.isSetoid (Semigroupoid.𝔐 (Category.semigroupoid category))) = eqArrow -- IsSetoid.isEquivalence (Morphism.isSetoid (Semigroupoid.𝔐 (Category.semigroupoid category))) = {!!} -- Semigroupoid._∙_ (Category.semigroupoid category) g f = COMPOSE g f -- IsSemigroupoid.extensionality (Semigroupoid.isSemigroupoid (Category.semigroupoid category)) = {!!} -- IsSemigroupoid.associativity (Semigroupoid.isSemigroupoid (Category.semigroupoid category)) = {!!} -- Category.ε category = {!!} -- IsCategory.left-identity (Category.isCategory category) = {!!} -- IsCategory.right-identity (Category.isCategory category) = {!!}
35.589577
156
0.63326
59375b404ae368d8093c50e35ff5e6b6dc7113a8
1,481
agda
Agda
Light/Library/Data/Product.agda
zamfofex/lightlib
44b1c724f2de95d3a9effe87ca36ef9eca8b4756
[ "0BSD" ]
1
2019-12-20T21:33:05.000Z
2019-12-20T21:33:05.000Z
Light/Library/Data/Product.agda
zamfofex/lightlib
44b1c724f2de95d3a9effe87ca36ef9eca8b4756
[ "0BSD" ]
null
null
null
Light/Library/Data/Product.agda
zamfofex/lightlib
44b1c724f2de95d3a9effe87ca36ef9eca8b4756
[ "0BSD" ]
null
null
null
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-} module Light.Library.Data.Product where open import Light.Level using (Level ; Setω) open import Light.Variable.Sets open import Light.Variable.Levels import Light.Library.Data.Both as Both open import Light.Library.Relation.Binary using (SelfTransitive ; SelfSymmetric ; Reflexive) open import Light.Library.Relation.Binary.Equality.Decidable using (DecidableEquality) record Dependencies : Setω where record Library (dependencies : Dependencies) : Setω where field ℓf : Level → Level → Level Σ : ∀ (𝕒 : Set aℓ) → (𝕒 → Set bℓ) → Set (ℓf aℓ bℓ) both : ∀ {𝕓 : 𝕒 → Set bℓ} a (b : 𝕓 a) → Σ 𝕒 𝕓 first : ∀ {𝕓 : 𝕒 → Set bℓ} → Σ 𝕒 𝕓 → 𝕒 second : ∀ {𝕓 : 𝕒 → Set bℓ} (product : Σ 𝕒 𝕓) → 𝕓 (first product) ⦃ equals ⦄ : ∀ ⦃ a‐c‐equals : DecidableEquality 𝕒 𝕔 ⦄ ⦃ b‐d‐equals : DecidableEquality 𝕓 𝕕 ⦄ → DecidableEquality (Σ 𝕒 (λ _ → 𝕓)) (Σ 𝕔 (λ _ → 𝕕)) ∃ : ∀ {𝕒 : Set aℓ} → (𝕒 → Set bℓ) → Set (ℓf aℓ bℓ) ∃ = Σ _ instance both‐library : Both.Library record {} both‐library = record { Both = λ 𝕒 𝕓 → Σ 𝕒 (λ _ → 𝕓) ; ℓf = ℓf ; both = both ; first = first ; second = second ; equals = equals } open Library ⦃ ... ⦄ public
36.121951
97
0.533423
134368b49efd862e7101a59851a6a693de70c01d
457
agda
Agda
test/Compiler/simple/Literals.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Compiler/simple/Literals.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Compiler/simple/Literals.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --universe-polymorphism #-} module Literals where open import Common.Nat open import Common.Float open import Common.Char open import Common.String open import Common.Unit open import Common.IO afloat : Float afloat = 1.23 astring : String astring = "abc" achar : Char achar = 'd' anat : Nat anat = 123 main : IO Unit main = printFloat afloat ,, putStr astring ,, printChar achar ,, printNat anat ,, putStrLn ""
15.233333
39
0.689278
062944f5ddbc3befeccaaa19e16cce803263ff77
1,526
agda
Agda
test/fail/Issue882a.agda
larrytheliquid/agda
477c8c37f948e6038b773409358fd8f38395f827
[ "MIT" ]
null
null
null
test/fail/Issue882a.agda
larrytheliquid/agda
477c8c37f948e6038b773409358fd8f38395f827
[ "MIT" ]
null
null
null
test/fail/Issue882a.agda
larrytheliquid/agda
477c8c37f948e6038b773409358fd8f38395f827
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
{-# OPTIONS -v impossible:100 #-} module Issue882a where open import Common.Level open import Common.Equality private primitive primTrustMe : ∀ {a} {A : Set a} {x y : A} → x ≡ y -- trustMe {x = x} {y = y} evaluates to refl if x and y are -- definitionally equal. -- -- For an example of the use of trustMe, see Data.String._≟_. trustMe : ∀ {a} {A : Set a} {x y : A} → x ≡ y trustMe = primTrustMe postulate S : Set B : Set b : B M : Set M = B -> S out : M -> M out m = o where s : S s = m b postulate mko : (mm : S) -> s ≡ mm -> M o : M o n = mko (m b) trustMe n postulate unfold : (M -> M) -> M inn : M inn = unfold out postulate n : B iso1 : inn ≡ inn iso1 rewrite refl {x = n} = {!!} -- iso1 rewrite (refl {a = lzero}{A = B}{x = n}) = {!!} {- Error OLD: An internal error has occurred. Please report this as a bug. Location of the error: src/full/Agda/TypeChecking/Conversion.hs:636 NEW: Some vomit about Setω not equal to Level when checking well-formedness of with type. NEWER (2013-11-30): Cannot instantiate the metavariable _48 to solution m b since it contains the variable m which is not in scope of the metavariable or irrelevant in the metavariable but relevant in the solution when checking that the type B → (w : _x_48 ≡ _x_48) → unfold (λ m → _.mko m (m b) w) ≡ unfold (λ m → _.mko m (m b) w) of the generated with function is well-formed NOW (2014-05-17): Rewriting with refl is a no-op, so no error is triggered any more. Just an unresolved meta now. -}
19.564103
70
0.646134
4151289fda91fdd9e2129faee26c2c3a99a36092
332
agda
Agda
test/Succeed/Issue34.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue34.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue34.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- There was a bug with module applications in let. module Issue34 where module A (X : Set) where postulate A : Set T : (X : Set) -> let open A X in A -> Set T X _ = X record B (X : Set) : Set where open A X field f : A postulate foo : (X : Set)(b : B X) -> let open A X open B b in A -> Set
17.473684
51
0.548193
1aaf63dc1f2a696279bc1a16cfdc3e22b8b71a4d
384
agda
Agda
Cubical/HITs/GroupoidTruncation/Base.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/HITs/GroupoidTruncation/Base.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
1
2022-01-27T02:07:48.000Z
2022-01-27T02:07:48.000Z
Cubical/HITs/GroupoidTruncation/Base.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
1
2021-11-22T02:02:01.000Z
2021-11-22T02:02:01.000Z
{- This file contains: - Definition of groupoid truncations -} {-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.HITs.GroupoidTruncation.Base where open import Cubical.Core.Primitives -- groupoid truncation as a higher inductive type: data ∥_∥₃ {ℓ} (A : Type ℓ) : Type ℓ where ∣_∣₃ : A → ∥ A ∥₃ squash₃ : ∀ (x y : ∥ A ∥₃) (p q : x ≡ y) (r s : p ≡ q) → r ≡ s
21.333333
64
0.630208
588226f43b247ffb1bdb78ede97b2b98d593d045
6,959
agda
Agda
src/DualCoinductive.agda
kcaliban/dual-session
cd41919582013e75463308c32750e2712cf2de86
[ "BSD-2-Clause" ]
null
null
null
src/DualCoinductive.agda
kcaliban/dual-session
cd41919582013e75463308c32750e2712cf2de86
[ "BSD-2-Clause" ]
null
null
null
src/DualCoinductive.agda
kcaliban/dual-session
cd41919582013e75463308c32750e2712cf2de86
[ "BSD-2-Clause" ]
null
null
null
module DualCoinductive where open import Data.Nat hiding (compare) open import Data.Nat.Properties open import Data.Fin hiding (_+_) open import Function open import Relation.Binary.PropositionalEquality hiding (Extensionality) open import Agda.Builtin.Equality.Rewrite open import Direction -- variables variable n m : ℕ -- session types coinductively module COI where mutual data Type : Set where TUnit TInt : Type TPair : Type → Type → Type TChan : SType → Type data STypeF (S : Set) : Set where transmit : (d : Dir) (t : Type) (s : S) → STypeF S choice : (d : Dir) (m : ℕ) (alt : Fin m → S) → STypeF S end : STypeF S record SType : Set where coinductive constructor delay field force : STypeF SType open SType variable t t₁ t₂ t₃ t₁' t₂' t₃' : Type s s₁ s₂ s₃ : SType s' s₁' s₂' s₃' : STypeF SType -- type equivalence data EquivT (R : SType → SType → Set) : Type → Type → 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 EquivF (R : SType → SType → Set) : STypeF SType → STypeF SType → Set where eq-transmit : (d : Dir) → EquivT R t₁ t₂ → R s₁ s₂ → EquivF R (transmit d t₁ s₁) (transmit d t₂ s₂) eq-choice : ∀ {alt alt'} → (d : Dir) → ((i : Fin m) → R (alt i) (alt' i)) → EquivF R (choice d m alt) (choice d m alt') eq-end : EquivF R end end record Equiv (s₁ : SType) (s₂ : SType) : Set where coinductive field force : EquivF Equiv (force s₁) (force s₂) open Equiv _≈_ = Equiv _≈'_ = EquivF Equiv _≈ᵗ_ = EquivT Equiv -- reflexivity ≈ᵗ-refl : t ≈ᵗ t ≈-refl : s ≈ s ≈'-refl : s' ≈' s' 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 -- symmetry ≈-symm : s₁ ≈ s₂ → s₂ ≈ s₁ ≈'-symm : s₁' ≈' s₂' → s₂' ≈' s₁' ≈ᵗ-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 (λ i → ≈-symm (x i)) ≈'-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) -- transitivity ≈-trans : s₁ ≈ s₂ → s₂ ≈ s₃ → s₁ ≈ s₃ ≈'-trans : s₁' ≈' s₂' → s₂' ≈' s₃' → s₁' ≈' s₃' ≈ᵗ-trans : t₁ ≈ᵗ t₂ → t₂ ≈ᵗ t₃ → t₁ ≈ᵗ t₃ force (≈-trans s₁≈s₂ s₂≈s₃) = ≈'-trans (force s₁≈s₂) (force s₂≈s₃) ≈'-trans (eq-transmit d tt₁ ss₁) (eq-transmit .d tt₂ ss₂) = eq-transmit d (≈ᵗ-trans tt₁ tt₂) (≈-trans ss₁ ss₂) ≈'-trans (eq-choice d x) (eq-choice .d x₁) = eq-choice d (λ i → ≈-trans (x i) (x₁ i)) ≈'-trans eq-end eq-end = eq-end ≈ᵗ-trans eq-unit eq-unit = eq-unit ≈ᵗ-trans eq-int eq-int = eq-int ≈ᵗ-trans (eq-pair t₁≈ᵗt₂ t₁≈ᵗt₃) (eq-pair t₂≈ᵗt₃ t₂≈ᵗt₄) = eq-pair (≈ᵗ-trans t₁≈ᵗt₂ t₂≈ᵗt₃) (≈ᵗ-trans t₁≈ᵗt₃ t₂≈ᵗt₄) ≈ᵗ-trans (eq-chan ss₁) (eq-chan ss₂) = eq-chan (≈-trans ss₁ ss₂) ---------------------------------------------------------------------- -- relational duality data DualD : Dir → Dir → Set where dual-sr : DualD SND RCV dual-rs : DualD RCV SND -- session type duality data DualF (R : SType → SType → Set) : STypeF SType → STypeF SType → Set where dual-transmit : DualD d₁ d₂ → t₁ ≈ᵗ t₂ → R s₁ s₂ → DualF R (transmit d₁ t₁ s₁) (transmit d₂ t₂ s₂) dual-choice : ∀ {alt alt'} → DualD d₁ d₂ → ((i : Fin m) → R (alt i) (alt' i)) → DualF R (choice d₁ m alt) (choice d₂ m alt') dual-end : DualF R end end record Dual (s₁ : SType) (s₂ : SType) : Set where coinductive field force : DualF Dual (force s₁) (force s₂) -- open Dual _⊥_ = Dual _⊥'_ = DualF Dual -- _≈ᵗ_ = EquivT Equiv -- symmetric DualD-symm : DualD d₁ d₂ → DualD d₂ d₁ DualD-symm dual-sr = dual-rs DualD-symm dual-rs = dual-sr ⊥-symm : s₁ ⊥ s₂ → s₂ ⊥ s₁ ⊥'-symm : s₁' ⊥' s₂' → s₂' ⊥' s₁' Dual.force (⊥-symm s₁⊥s₂) = ⊥'-symm (Dual.force s₁⊥s₂) ⊥'-symm (dual-transmit x x₁ x₂) = dual-transmit (DualD-symm x) (≈ᵗ-symm x₁) (⊥-symm x₂) ⊥'-symm (dual-choice x x₁) = dual-choice (DualD-symm x) (⊥-symm ∘ x₁) ⊥'-symm dual-end = dual-end -- involutory DualD-inv : DualD d₁ d₂ → DualD d₂ d₃ → d₁ ≡ d₃ DualD-inv dual-sr dual-rs = refl DualD-inv dual-rs dual-sr = refl ⊥-inv : s₁ ⊥ s₂ → s₂ ⊥ s₃ → s₁ ≈ s₃ ⊥'-inv : s₁' ⊥' s₂' → s₂' ⊥' s₃' → s₁' ≈' s₃' force (⊥-inv s₁⊥s₂ s₂⊥s₃) = ⊥'-inv (Dual.force s₁⊥s₂) (Dual.force s₂⊥s₃) ⊥'-inv (dual-transmit dd₁ tt₁ ss₁) (dual-transmit dd₂ tt₂ ss₂) rewrite DualD-inv dd₁ dd₂ = eq-transmit _ (≈ᵗ-trans tt₁ tt₂) (⊥-inv ss₁ ss₂) ⊥'-inv (dual-choice dd₁ ss₁) (dual-choice dd₂ ss₂) rewrite DualD-inv dd₁ dd₂ = eq-choice _ (λ i → ⊥-inv (ss₁ i) (ss₂ i)) ⊥'-inv dual-end dual-end = eq-end ---------------------------------------------------------------------- -- duality dual : SType → SType dualF : STypeF SType → STypeF SType force (dual s) = dualF (force s) dualF (transmit d t s) = transmit (dual-dir d) t (dual s) dualF (choice d m alt) = choice (dual-dir d) m (dual ∘ alt) dualF end = end -- properties dual-involution : ∀ s → s ≈ dual (dual s) dual-involutionF : ∀ s' → s' ≈' dualF (dualF s') force (dual-involution s) = dual-involutionF (force s) dual-involutionF (transmit d t s) rewrite dual-dir-inv d = eq-transmit d ≈ᵗ-refl (dual-involution s) dual-involutionF (choice d m alt) rewrite dual-dir-inv d = eq-choice d (dual-involution ∘ alt) dual-involutionF end = eq-end ----------------------------------------------------------------------- -- relational duality vs functional duality -- soundness dual-soundD : DualD d (dual-dir d) dual-soundD {SND} = dual-sr dual-soundD {RCV} = dual-rs dual-soundS : s ⊥ dual s dual-soundF : s' ⊥' dualF s' Dual.force dual-soundS = dual-soundF dual-soundF {transmit d t s} = dual-transmit dual-soundD ≈ᵗ-refl dual-soundS dual-soundF {choice d m alt} = dual-choice dual-soundD (λ i → dual-soundS) dual-soundF {end} = dual-end -- completeness dual-completeD : DualD d₁ d₂ → d₁ ≡ dual-dir d₂ dual-completeD dual-sr = refl dual-completeD dual-rs = refl dual-completeS : s₁ ⊥ s₂ → s₁ ≈ dual s₂ dual-completeF : s₁' ⊥' s₂' → s₁' ≈' dualF s₂' force (dual-completeS s₁⊥s₂) = dual-completeF (Dual.force s₁⊥s₂) dual-completeF (dual-transmit dd tt ss) rewrite dual-completeD dd = eq-transmit _ tt (dual-completeS ss) dual-completeF (dual-choice dd x₁) rewrite dual-completeD dd = eq-choice _ (λ i → dual-completeS (x₁ i)) dual-completeF dual-end = eq-end
31.631818
141
0.590027
5708af080c835b5d4f8bea9b3a4765aca0b1bd74
671
agda
Agda
test/succeed/Issue106.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
1
2019-11-27T04:41:05.000Z
2019-11-27T04:41:05.000Z
test/succeed/Issue106.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/succeed/Issue106.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
-- {-# OPTIONS -v tc.cover.splittree:10 -v tc.cc.splittree:10 #-} module Issue106 where data ℕ : Set where zero : ℕ suc : ℕ -> ℕ {-# BUILTIN NATURAL ℕ #-} {-# BUILTIN ZERO zero #-} {-# BUILTIN SUC suc #-} _+_ : ℕ -> ℕ -> ℕ zero + m = m suc n + m = suc (n + m) record ⊤ : Set where data C : ℕ -> Set where c : C 0 data D : Set where d : forall s (x : C s) (xs : D) -> D f : D -> ℕ -> ⊤ f (d zero c x) (suc n) = f (d 0 c x) n f (d .zero c x) n = f x (suc n) g : D -> ℕ -> ⊤ g (d .zero c x) (suc n) = g (d zero c x) n g (d .zero c x) n = g x (suc n) h : D -> ℕ -> ⊤ h (d .zero c x) (suc n) = h (d 0 c x) n h (d .zero c x) n = h x (suc n)
19.171429
66
0.47392
10841e26e270166d162bf80464b1d66afaaa54f1
5,728
agda
Agda
src/Tactic/Nat/Auto/Lemmas.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
111
2015-01-05T11:28:15.000Z
2022-02-12T23:29:26.000Z
src/Tactic/Nat/Auto/Lemmas.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
59
2016-02-09T05:36:44.000Z
2022-01-14T07:32:36.000Z
src/Tactic/Nat/Auto/Lemmas.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
24
2015-03-12T18:03:45.000Z
2021-04-22T06:10:41.000Z
module Tactic.Nat.Auto.Lemmas where open import Prelude open import Tactic.Nat.NF open import Tactic.Nat.Exp open import Container.Bag open import Prelude.Nat.Properties map++ : ∀ {a b} {A : Set a} {B : Set b} (f : A → B) (xs ys : List A) → map f (xs ++ ys) ≡ map f xs ++ map f ys map++ f [] ys = refl map++ f (x ∷ xs) ys rewrite map++ f xs ys = refl prod++ : (xs ys : List Nat) → productR (xs ++ ys) ≡ productR xs * productR ys prod++ [] ys = sym (add-zero-r (productR ys)) prod++ (x ∷ xs) ys rewrite prod++ xs ys = mul-assoc x _ _ private shuffle₁ : ∀ a b c d → a + ((b + c) + d) ≡ b + c + (a + d) shuffle₁ a b c d rewrite add-assoc a (b + c) d | add-commute a (b + c) | add-assoc (b + c) a d = refl shuffle₂ : ∀ a b c d → a + b + (c + d) ≡ a + c + (b + d) shuffle₂ a b c d rewrite add-assoc (a + b) c d | sym (add-assoc a b c) | add-commute b c | add-assoc a c b | add-assoc (a + c) b d = refl shuffle₃ : ∀ a b c d → (a * b) * (c * d) ≡ (a * c) * (b * d) shuffle₃ a b c d rewrite mul-assoc (a * b) c d | sym (mul-assoc a b c) | mul-commute b c | mul-assoc a c b | mul-assoc (a * c) b d = refl shuffle₄ : ∀ a b c d → a * (b * c * d) ≡ b * c * (a * d) shuffle₄ a b c d rewrite mul-assoc a (b * c) d | mul-commute a (b * c) | mul-assoc (b * c) a d = refl module _ {Atom : Set} {{_ : Ord Atom}} where ⟨+⟩-sound : ∀ v₁ v₂ (ρ : Env Atom) → ⟦ v₁ +nf v₂ ⟧n ρ ≡ ⟦ v₁ ⟧n ρ + ⟦ v₂ ⟧n ρ ⟨+⟩-sound [] [] ρ = refl ⟨+⟩-sound [] (_ ∷ _) ρ = refl ⟨+⟩-sound (t ∷ v₁) [] ρ = sym (add-zero-r _) ⟨+⟩-sound ((i , t₁) ∷ v₁) ((j , t₂) ∷ v₂) ρ with ⟨+⟩-sound v₁ ((j , t₂) ∷ v₂) ρ | compare t₁ t₂ ... | ih | less _ rewrite ih = add-assoc (i * productR (map ρ t₁)) _ _ ... | _ | equal eq rewrite eq | ⟨+⟩-sound v₁ v₂ ρ | mul-distr-r i j (productR (map ρ t₂)) = shuffle₂ (⟦ i , t₂ ⟧t ρ) (⟦ j , t₂ ⟧t ρ) _ _ ... | _ | greater _ rewrite ⟨+⟩-sound ((i , t₁) ∷ v₁) v₂ ρ = shuffle₁ (⟦ j , t₂ ⟧t ρ) (⟦ i , t₁ ⟧t ρ) _ _ map-merge : ∀ x y (ρ : Env Atom) → productR (map ρ (merge x y)) ≡ productR (map ρ x) * productR (map ρ y) map-merge [] [] ρ = refl map-merge [] (x ∷ xs) ρ = sym (add-zero-r (productR (ρ x ∷ map ρ xs))) map-merge (x ∷ xs) [] ρ = sym (mul-one-r _) map-merge (x ∷ xs) (y ∷ ys) ρ with map-merge xs (y ∷ ys) ρ | x <? y ... | ih | true rewrite ih = mul-assoc (ρ x) _ _ ... | _ | false rewrite map-merge (x ∷ xs) ys ρ = shuffle₄ (ρ y) (ρ x) _ _ mulTm-sound : ∀ t t′ (ρ : Env Atom) → ⟦ mulTm t t′ ⟧t ρ ≡ ⟦ t ⟧t ρ * ⟦ t′ ⟧t ρ mulTm-sound (a , x) (b , y) ρ rewrite map-merge x y ρ = shuffle₃ a b _ _ mulTmDistr : ∀ t v (ρ : Env Atom) → ⟦ map (mulTm t) v ⟧n ρ ≡ ⟦ t ⟧t ρ * ⟦ v ⟧n ρ mulTmDistr t [] ρ = sym (mul-zero-r (⟦ t ⟧t ρ)) mulTmDistr t (t′ ∷ v) ρ = ⟦ mulTm t t′ ⟧t ρ + ⟦ map (mulTm t) v ⟧n ρ ≡⟨ cong₂ _+_ (mulTm-sound t t′ ρ) (mulTmDistr t v ρ) ⟩ ⟦ t ⟧t ρ * ⟦ t′ ⟧t ρ + ⟦ t ⟧t ρ * ⟦ v ⟧n ρ ≡⟨ mul-distr-l (⟦ t ⟧t ρ) _ _ ⟩ʳ ⟦ t ⟧t ρ * ⟦ t′ ∷ v ⟧n ρ ∎ sort-sound : ∀ xs ρ → ⟦ nf-sort xs ⟧n ρ ≡ ⟦ xs ⟧n ρ sort-sound [] ρ = refl sort-sound (x ∷ xs) ρ rewrite ⟨+⟩-sound [ x ] (nf-sort xs) ρ | sort-sound xs ρ | add-zero-r (⟦ x ⟧t ρ) = refl ⟨*⟩-sound : ∀ v₁ v₂ (ρ : Env Atom) → ⟦ v₁ *nf v₂ ⟧n ρ ≡ ⟦ v₁ ⟧n ρ * ⟦ v₂ ⟧n ρ ⟨*⟩-sound [] v₂ ρ = refl ⟨*⟩-sound (t ∷ v₁) v₂ ρ = ⟦ nf-sort (map (mulTm t) v₂) +nf (v₁ *nf v₂) ⟧n ρ ≡⟨ ⟨+⟩-sound (nf-sort (map (mulTm t) v₂)) (v₁ *nf v₂) ρ ⟩ ⟦ nf-sort (map (mulTm t) v₂) ⟧n ρ + ⟦ v₁ *nf v₂ ⟧n ρ ≡⟨ cong (flip _+_ (⟦ v₁ *nf v₂ ⟧n ρ)) (sort-sound (map (mulTm t) v₂) ρ) ⟩ ⟦ map (mulTm t) v₂ ⟧n ρ + ⟦ v₁ *nf v₂ ⟧n ρ ≡⟨ cong (_+_ (⟦ map (mulTm t) v₂ ⟧n ρ)) (⟨*⟩-sound v₁ v₂ ρ) ⟩ ⟦ map (mulTm t) v₂ ⟧n ρ + ⟦ v₁ ⟧n ρ * ⟦ v₂ ⟧n ρ ≡⟨ cong (flip _+_ (⟦ v₁ ⟧n ρ * ⟦ v₂ ⟧n ρ)) (mulTmDistr t v₂ ρ) ⟩ ⟦ t ⟧t ρ * ⟦ v₂ ⟧n ρ + ⟦ v₁ ⟧n ρ * ⟦ v₂ ⟧n ρ ≡⟨ mul-distr-r (⟦ t ⟧t ρ) _ _ ⟩ʳ ⟦ t ∷ v₁ ⟧n ρ * ⟦ v₂ ⟧n ρ ∎ sound : ∀ e (ρ : Env Atom) → ⟦ e ⟧e ρ ≡ ⟦ norm e ⟧n ρ sound (var x) ρ = mul-one-r (ρ x) ʳ⟨≡⟩ add-zero-r _ ʳ⟨≡⟩ʳ add-zero-r _ sound (lit 0) ρ = refl sound (lit (suc n)) ρ rewrite mul-one-r n | add-commute n 1 = sym (add-zero-r _) sound (e ⟨+⟩ e₁) ρ = ⟦ e ⟧e ρ + ⟦ e₁ ⟧e ρ ≡⟨ cong₂ _+_ (sound e ρ) (sound e₁ ρ) ⟩ ⟦ norm e ⟧n ρ + ⟦ norm e₁ ⟧n ρ ≡⟨ ⟨+⟩-sound (norm e) (norm e₁) ρ ⟩ʳ ⟦ norm e +nf norm e₁ ⟧n ρ ∎ sound (e ⟨*⟩ e₁) ρ = ⟦ e ⟧e ρ * ⟦ e₁ ⟧e ρ ≡⟨ cong₂ _*_ (sound e ρ) (sound e₁ ρ) ⟩ ⟦ norm e ⟧n ρ * ⟦ norm e₁ ⟧n ρ ≡⟨ ⟨*⟩-sound (norm e) (norm e₁) ρ ⟩ʳ ⟦ norm e *nf norm e₁ ⟧n ρ ∎ module _ (ρ₁ ρ₂ : Env Atom) (eq : ∀ x → ρ₁ x ≡ ρ₂ x) where private lem-eval-env-a : ∀ a → productR (map ρ₁ a) ≡ productR (map ρ₂ a) lem-eval-env-a [] = refl lem-eval-env-a (x ∷ xs) = _*_ $≡ eq x *≡ lem-eval-env-a xs lem-eval-env-t : ∀ t → ⟦ t ⟧t ρ₁ ≡ ⟦ t ⟧t ρ₂ lem-eval-env-t (k , a) = _*_ k $≡ lem-eval-env-a a lem-eval-env : ∀ n → ⟦ n ⟧n ρ₁ ≡ ⟦ n ⟧n ρ₂ lem-eval-env [] = refl lem-eval-env (x ∷ n) = _+_ $≡ lem-eval-env-t x *≡ lem-eval-env n
42.42963
107
0.432088
571b1bffc0c367bf29f18b8fc829bdd191ae5b63
228
agda
Agda
agda/Strict.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
4
2021-01-05T14:07:44.000Z
2021-01-05T15:32:14.000Z
agda/Strict.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
null
null
null
agda/Strict.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
1
2021-01-05T14:05:30.000Z
2021-01-05T14:05:30.000Z
{-# OPTIONS --without-K --safe #-} module Strict where open import Agda.Builtin.Strict open import Level infixr 0 _$!_ _$!_ : {A : Type a} {B : A → Type b} → (∀ x → B x) → ∀ x → B x f $! x = primForce x f {-# INLINE _$!_ #-}
19
62
0.565789
d025b34cc1a24f1b0e7b868a8422d0d8fcba44e2
15,522
agda
Agda
posts/agda/typed-protocols.agda
coot/homepage
6773b88e8bbd1cfab98ed615855d9ae9c8859e0c
[ "BSD-3-Clause" ]
null
null
null
posts/agda/typed-protocols.agda
coot/homepage
6773b88e8bbd1cfab98ed615855d9ae9c8859e0c
[ "BSD-3-Clause" ]
5
2020-02-18T21:05:46.000Z
2020-02-18T21:05:51.000Z
posts/agda/typed-protocols.agda
coot/homepage
6773b88e8bbd1cfab98ed615855d9ae9c8859e0c
[ "BSD-3-Clause" ]
null
null
null
module posts.agda.typed-protocols where open import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl) open import Relation.Nullary using (¬_) open import Data.Empty using (⊥; ⊥-elim) open import Data.List open import Data.Nat open import Data.Unit using (⊤; tt) open import Function.Base using (_$_; _|>_) -- Client / server roles -- data PeerRole : Set where ClientRole : PeerRole ServerRole : PeerRole dual-role : PeerRole → PeerRole dual-role ClientRole = ServerRole dual-role ServerRole = ClientRole -- Objective agency: who is responsible for sending next message. -- data Agency : Set where ClientAgency : Agency ServerAgency : Agency NobodyAgency : Agency -- Relative agency to the current 'PeerRole'. It answer the question: are we -- responsible for sending next message? -- data RelativeAgency : Set where WeHaveAgency : RelativeAgency TheyHaveAgency : RelativeAgency NobodyHasAgency : RelativeAgency relative : PeerRole → Agency → RelativeAgency relative ClientRole ClientAgency = WeHaveAgency relative ClientRole ServerAgency = TheyHaveAgency relative ClientRole NobodyAgency = NobodyHasAgency relative ServerRole ClientAgency = TheyHaveAgency relative ServerRole ServerAgency = WeHaveAgency relative ServerRole NobodyAgency = NobodyHasAgency -- 'relative' function obeys the following three exclusion lemmas: -- -- * it is an absurd if client and server have agency -- * it is an absurd if 'WeHaveAgency' and the dual role terminated -- ('NobodyHasAgency') -- * it is an absurd if 'TheyHaveAgency' and the dual role terminated -- ('NobodyHasAgency') -- -- Note that these lemmas are provided regardless of the protocol, unlike the -- Haskell implementation which requires to prove them for each protocol. exclusion-lemma-client-and-server-have-agency₁ : ∀ {agency : Agency} {pr : PeerRole} → WeHaveAgency ≡ relative pr agency → WeHaveAgency ≡ relative (dual-role pr) agency → ⊥ exclusion-lemma-client-and-server-have-agency₁ {ClientAgency} {ClientRole} refl () exclusion-lemma-client-and-server-have-agency₁ {ServerAgency} {ServerRole} refl () exclusion-lemma-client-and-server-have-agency₂ : ∀ {agency : Agency} {pr : PeerRole} → TheyHaveAgency ≡ relative pr agency → TheyHaveAgency ≡ relative (dual-role pr) agency → ⊥ exclusion-lemma-client-and-server-have-agency₂ {ServerAgency} {ClientRole} refl () exclusion-lemma-client-and-server-have-agency₂ {ClientAgency} {ServerRole} refl () exclusion-lemma-we-have-agency-and-nobody-has-agency : ∀ {agency : Agency} {pr : PeerRole} {pr' : PeerRole} → WeHaveAgency ≡ relative pr agency → NobodyHasAgency ≡ relative pr' agency → ⊥ exclusion-lemma-we-have-agency-and-nobody-has-agency {ClientAgency} {ClientRole} {ServerRole} refl () exclusion-lemma-we-have-agency-and-nobody-has-agency {ServerAgency} {ServerRole} {ClientRole} refl () exclusion-lemma-they-have-agency-and-nobody-has-agency : ∀ {agency : Agency} {pr : PeerRole} {pr' : PeerRole} → TheyHaveAgency ≡ relative pr agency → NobodyHasAgency ≡ relative pr' agency → ⊥ exclusion-lemma-they-have-agency-and-nobody-has-agency {ServerAgency} {ClientRole} {ServerRole} refl () exclusion-lemma-they-have-agency-and-nobody-has-agency {ClientAgency} {ServerRole} {ClientRole} refl () ----------- -- Peer API -- -- We index each primitive with 'IsPipelined' -- data IsPipelined : Set where Pipelined : IsPipelined NonPipelined : IsPipelined -- Promised protocol transition -- data Trans (ps : Set) : Set where Tr : ps → ps → Trans ps -- 'Peer' explicitly indexed by: -- * message type -- * objective protocol agency -- * peer role -- * return type -- * 'IsPipelined' -- * queue of unrealised transitions, due to pipelining -- * current state -- data Peer {ps : Set} (msg : ps → ps → Set) (agency : ps → Agency) (pr : PeerRole) (a : Set) : IsPipelined → List (Trans ps) → ps → Set where -- -- non-pipelined primitives -- -- non-pipelined send a message Yield : ∀ {st st' : ps} {pl : IsPipelined} → WeHaveAgency ≡ relative pr (agency st) → msg st st' → Peer msg agency pr a pl [] st' → Peer msg agency pr a pl [] st -- non-pipelined receive a message Await : ∀ {st : ps} {pl : IsPipelined} → TheyHaveAgency ≡ relative pr (agency st) → (∀ {st' : ps} → msg st st' → Peer msg agency pr a pl [] st' ) → Peer msg agency pr a pl [] st -- protocol termination Done : ∀ {st : ps} {pl : IsPipelined} → NobodyHasAgency ≡ relative pr (agency st) → a → Peer msg agency pr a pl [] st -- -- pipelining primitives -- -- pipeline a single message YieldPipelined : ∀ {st st' st'' : ps} {q : List (Trans ps)} → WeHaveAgency ≡ relative pr (agency st) → msg st st' → Peer msg agency pr a Pipelined (q ∷ʳ Tr st' st'') st'' → Peer msg agency pr a Pipelined q st -- partially collect a promissed transition Collect : ∀ {st st' st'' : ps} {q : List (Trans ps)} → TheyHaveAgency ≡ relative pr (agency st') → (∀ {stNext : ps} → msg st' stNext → Peer msg agency pr a Pipelined (Tr stNext st'' ∷ q) st ) → Peer msg agency pr a Pipelined (Tr st' st'' ∷ q) st -- collect the identity transition CollectDone : ∀ {st : ps} {q : List (Trans ps)} → Peer msg agency pr a Pipelined q st → Peer msg agency pr a Pipelined (Tr st st ∷ q) st -------------- -- PingPong v1 -- -- Protocol states -- data PingPong : Set where StIdle : PingPong StBusy : PingPong StDone : PingPong -- Agency of PingPong states -- pingPongAgency : PingPong → Agency pingPongAgency StIdle = ClientAgency pingPongAgency StBusy = ServerAgency pingPongAgency StDone = NobodyAgency -- Protocol messages -- data PingPongMsg : ∀ (st st' : PingPong) → Set where MsgPing : PingPongMsg StIdle StBusy MsgPong : PingPongMsg StBusy StIdle MsgDone : PingPongMsg StIdle StDone -- -- PingPong v1, examples -- -- ping client which computes unit (tt : ⊤) -- ping : Peer PingPongMsg pingPongAgency ClientRole ⊤ NonPipelined [] StIdle ping = Yield refl MsgPing $ await $ Yield refl MsgPing $ await $ Yield refl MsgDone $ Done refl tt where await : Peer PingPongMsg pingPongAgency ClientRole ⊤ NonPipelined [] StIdle → Peer PingPongMsg pingPongAgency ClientRole ⊤ NonPipelined [] StBusy await k = Await refl λ {MsgPong → k} -- pipelined client which computes unit (tt : ⊤) -- pipelinedPing : Peer PingPongMsg pingPongAgency ClientRole ⊤ Pipelined [] StIdle pipelinedPing = YieldPipelined refl MsgPing $ YieldPipelined refl MsgPing $ YieldPipelined refl MsgPing $ collect $ collect $ collect $ Yield refl MsgDone $ Done refl tt where collect : ∀ {q : List (Trans PingPong)} → Peer PingPongMsg pingPongAgency ClientRole ⊤ Pipelined q StIdle → Peer PingPongMsg pingPongAgency ClientRole ⊤ Pipelined (Tr StBusy StIdle ∷ q) StIdle collect k = Collect refl λ {MsgPong → CollectDone k} -------------- -- PingPong v2 -- -- The same states and agency as PingPong v1, but with additional 'MsgBusy' -- transition. data PingPongMsg2 : ∀ (st st' : PingPong) → Set where MsgPingPong : ∀ {st st' : PingPong} → PingPongMsg st st' → PingPongMsg2 st st' MsgBusy : PingPongMsg2 StBusy StBusy -- we use unbounded recursion in 'pipelinedPing2' {-# NON_TERMINATING #-} -- pipelined ping client which computes the number of busy messages -- pipelinedPing2 : Peer PingPongMsg2 pingPongAgency ClientRole ℕ Pipelined [] StIdle pipelinedPing2 = YieldPipelined refl (MsgPingPong MsgPing) $ YieldPipelined refl (MsgPingPong MsgPing) $ YieldPipelined refl (MsgPingPong MsgPing) $ collect 0 $ λ { n1 → collect n1 λ { n2 → collect n2 λ { n3 → Yield refl (MsgPingPong MsgDone) $ Done refl n3 }}} where collect : ∀ {q : List (Trans PingPong)} → ℕ → (ℕ → Peer PingPongMsg2 pingPongAgency ClientRole ℕ Pipelined q StIdle) → Peer PingPongMsg2 pingPongAgency ClientRole ℕ Pipelined (Tr StBusy StIdle ∷ q) StIdle collect n k = Collect refl λ { MsgBusy → collect (n + 1) k ; (MsgPingPong MsgPong) → CollectDone (k n) } ------------------------ -- Non-pipelined Duality -- -- Termination witness data Termination (ps : Set) (agency : ps → Agency) (a : Set) (b : Set) : Set where Terminated : ∀ {st : ps} {pr : PeerRole} → a → b → NobodyHasAgency ≡ relative pr (agency st) → NobodyHasAgency ≡ relative (dual-role pr) (agency st) → Termination ps agency a b theorem-non-pipelined-duality : ∀ {ps : Set} {msg : ps → ps → Set} {agency : ps → Agency} {pr : PeerRole} {a : Set} {b : Set} {st : ps} → Peer msg agency pr a NonPipelined [] st → Peer msg agency (dual-role pr) b NonPipelined [] st → Termination ps agency a b theorem-non-pipelined-duality (Yield _ msg k) (Await _ k') = theorem-non-pipelined-duality k (k' msg) theorem-non-pipelined-duality (Await _ k) (Yield _ msg k') = theorem-non-pipelined-duality (k msg) k' theorem-non-pipelined-duality (Done termA a) (Done termB b) = Terminated a b termA termB -- excluded cases theorem-non-pipelined-duality (Yield weHaveAgency _ _) (Yield theyHaveAgency _ _) = ⊥-elim (exclusion-lemma-client-and-server-have-agency₁ weHaveAgency theyHaveAgency) theorem-non-pipelined-duality (Await theyHaveAgency _) (Await weHaveAgency _) = ⊥-elim (exclusion-lemma-client-and-server-have-agency₂ theyHaveAgency weHaveAgency) theorem-non-pipelined-duality (Yield weHaveAgency _ _) (Done nobodyHasAgency _) = ⊥-elim (exclusion-lemma-we-have-agency-and-nobody-has-agency weHaveAgency nobodyHasAgency) theorem-non-pipelined-duality (Done nobodyHasAgency _) (Yield weHaveAgency _ _) = ⊥-elim (exclusion-lemma-we-have-agency-and-nobody-has-agency weHaveAgency nobodyHasAgency) theorem-non-pipelined-duality (Await theyHaveAgency _) (Done nobodyHasAgency _) = ⊥-elim (exclusion-lemma-they-have-agency-and-nobody-has-agency theyHaveAgency nobodyHasAgency) theorem-non-pipelined-duality (Done nobodyHasAgency _) (Await theyHaveAgency _) = ⊥-elim (exclusion-lemma-they-have-agency-and-nobody-has-agency theyHaveAgency nobodyHasAgency) -------------- -- Un-pipeline -- -- Transition queue which allows to transform pipelined 'Peer' into -- non-pipelined one. Pipelined messages are pushed to the end together with -- promised transitions to be collected. -- data PrQueue {ps : Set} (msg : ps → ps → Set) (agency : ps -> Agency) (pr : PeerRole) : ps → List (Trans ps) → ps → Set where ConsMsgQ : ∀ {st st' st'' : ps} {q : List (Trans ps)} → WeHaveAgency ≡ relative pr (agency st) → msg st st' → PrQueue msg agency pr st' q st'' → PrQueue msg agency pr st q st'' ConsTrQ : ∀ {st st' st'' : ps} {q : List (Trans ps)} → PrQueue msg agency pr st' q st'' → PrQueue msg agency pr st (Tr st st' ∷ q) st'' EmptyQ : ∀ {st : ps} → PrQueue msg agency pr st [] st snockMsgQ : ∀ {ps : Set} {msg : ps → ps → Set} {agency : ps → Agency} {pr : PeerRole} {st st' st'' : ps} {q : List (Trans ps)} → WeHaveAgency ≡ relative pr (agency st') → msg st' st'' → PrQueue msg agency pr st q st' → PrQueue msg agency pr st q st'' snockMsgQ tok msg (ConsMsgQ tok' msg' q) = ConsMsgQ tok' msg' (snockMsgQ tok msg q) snockMsgQ tok msg (ConsTrQ q) = ConsTrQ (snockMsgQ tok msg q) snockMsgQ tok msg EmptyQ = ConsMsgQ tok msg EmptyQ snockTrQ : ∀ {ps : Set} {msg : ps → ps → Set} {agency : ps → Agency} {pr : PeerRole} {st st' st'' : ps} {q : List (Trans ps)} → PrQueue msg agency pr st q st' → PrQueue msg agency pr st (q ∷ʳ Tr st' st'') st'' snockTrQ (ConsMsgQ tok msg q) = ConsMsgQ tok msg (snockTrQ q) snockTrQ (ConsTrQ q) = ConsTrQ (snockTrQ q) snockTrQ EmptyQ = ConsTrQ EmptyQ -- Every pipelined peer can be transformed into non-pipelined one, by -- preserving the order of all transition. -- theorem-unpipeline : ∀ {ps : Set} {msg : ps → ps → Set} {agency : ps → Agency} {pr : PeerRole} {pl : IsPipelined} {a : Set} {stInit : ps} → Peer msg agency pr a pl [] stInit → Peer msg agency pr a NonPipelined [] stInit theorem-unpipeline = go EmptyQ where go : ∀ {ps : Set} {msg : ps → ps → Set} {agency : ps → Agency} {pr : PeerRole} {pl : IsPipelined} {a : Set} {q : List (Trans ps)} {st st' : ps} → PrQueue msg agency pr st q st' → Peer msg agency pr a pl q st' → Peer msg agency pr a NonPipelined [] st -- non-piplined primitives go EmptyQ (Done tok a) = Done tok a go EmptyQ (Yield tok msg k) = Yield tok msg (go EmptyQ k) go EmptyQ (Await tok k) = Await tok λ {msg → go EmptyQ (k msg)} -- push msg and promised transition to back of the 'PrQueue' go q (YieldPipelined tok msg k) = go ( q |> snockMsgQ tok msg |> snockTrQ ) k go (ConsMsgQ tok msg q) k = Yield tok msg (go q k) go (ConsTrQ q) (Collect tok k) = Await tok λ {msg → go (ConsTrQ q) (k msg)} go (ConsTrQ q) (CollectDone k) = go q k ---------- -- Duality -- theorem-pipelined-duality : ∀ {ps : Set} {msg : ps → ps → Set} {agency : ps → Agency} {pr : PeerRole} {pl : IsPipelined} {a : Set} {b : Set} {st : ps} → Peer msg agency pr a pl [] st → Peer msg agency (dual-role pr) b pl [] st → Termination ps agency a b theorem-pipelined-duality a b = theorem-non-pipelined-duality (theorem-unpipeline a) (theorem-unpipeline b)
28.533088
85
0.584203
4a2d63f92078fd69a95655dee5b8e3c385fc420f
7,506
agda
Agda
tests/covered/LibVec.agda
andrejtokarcik/agda-semantics
dc333ed142584cf52cc885644eed34b356967d8b
[ "MIT" ]
3
2015-08-10T15:33:56.000Z
2018-12-06T17:24:25.000Z
tests/covered/LibVec.agda
andrejtokarcik/agda-semantics
dc333ed142584cf52cc885644eed34b356967d8b
[ "MIT" ]
null
null
null
tests/covered/LibVec.agda
andrejtokarcik/agda-semantics
dc333ed142584cf52cc885644eed34b356967d8b
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Vectors ------------------------------------------------------------------------ module LibVec where data ℕ : Set where zero : ℕ suc : ℕ -> ℕ data Fin : ℕ -> Set where fzero : {n : ℕ} -> Fin (suc n) fsuc : {n : ℕ} -> Fin n -> Fin (suc n) _+_ : ℕ -> ℕ -> ℕ zero + n = n suc m + n = suc (m + n) _*_ : ℕ -> ℕ -> ℕ zero * _ = zero suc m * n = n + (m * n) infixr 5 _∷_ data List (A : Set) : Set where [] : List A _∷_ : (x : A) (xs : List A) → List A {- open import Category.Applicative open import Data.Nat open import Data.Fin using (Fin; zero; suc) open import Data.List as List using (List) open import Data.Product as Prod using (∃; ∃₂; _×_; _,_) open import Function open import Relation.Binary.PropositionalEquality using (_≡_; refl) -} ------------------------------------------------------------------------ -- Types infixr 5 _,_ data Vec (A : Set) : ℕ → Set where <> : Vec A zero _,_ : ∀ {n} (x : A) (xs : Vec A n) → Vec A (suc n) foldl : ∀ {a b} {A : Set} (B : ℕ → Set) {m} → (∀ {n} → B n → A → B (suc n)) → B zero → Vec A m → B m foldl b _FAILER_ n <> = n foldl b _FAILER_ n (x , xs) = foldl (λ n → b (suc n)) _FAILER_ (_FAILER_ n x) xs infix 4 _∈_ data _∈_ {A : Set} : A → {n : ℕ} → Vec A n → Set where here : ∀ {n} {x} {xs : Vec A n} → x ∈ x , xs there : ∀ {n} {x y} {xs : Vec A n} (x∈xs : x ∈ xs) → x ∈ y , xs infix 4 _[_]=_ data _[_]=_ {A : Set} : {n : ℕ} → Vec A n → Fin n → A → Set where here' : ∀ {n} {x} {xs : Vec A n} → x , xs [ fzero ]= x there' : ∀ {n} {i} {x y} {xs : Vec A n} (xs[i]=x : xs [ i ]= x) → y , xs [ fsuc i ]= x ------------------------------------------------------------------------ -- Some operations head : ∀ {n} {A : Set} → Vec A (suc n) → A head (x , xs) = x tail : ∀ {n} {A : Set} → Vec A (suc n) → Vec A n tail (x , xs) = xs <_> : ∀ {A : Set} → A → Vec A (suc zero) < x > = x , <> {- Vect A n → Vect A m → Vect A (m + n) append vnil ys = ys append (vcons x xs) ys = vcons x (append xs ys) -} infixr 5 _++_ _++_ : ∀ {m n} {A : Set} → Vec A m → Vec A n → Vec A (m + n) <> ++ ys = ys (x , xs) ++ ys = x , (xs ++ ys) infixl 4 _⊛_ _⊛_ : ∀ {b n} {A : Set} {B : Set} → Vec (A → B) n → Vec A n → Vec B n <> ⊛ _ = <> (f , fs) ⊛ (x , xs) = f x , (fs ⊛ xs) {- replicate : ∀ {n} {A : Set} → A → Vec A n replicate {n = zero} x = <> replicate {n = suc n} x = x , replicate x -} replicate : ∀ {n} {A : Set} → A → Vec A n replicate {zero} x = <> replicate {suc n} x = x , replicate x {- applicative : ∀ {n} → RawApplicative (λ (A : Set) → Vec A n) applicative = record { pure = replicate ; _⊛_ = _⊛_ } -} map : ∀ {n} {A : Set} {B : Set} → (A → B) → Vec A n → Vec B n map f xs = replicate f ⊛ xs zipWith : ∀ {n} {A : Set} {B : Set} {C : Set} → (A → B → C) → Vec A n → Vec B n → Vec C n zipWith _⊕_ xs ys = replicate _⊕_ ⊛ xs ⊛ ys {- zip : ∀ {n} {A : Set} {B : Set} → Vec A n → Vec B n → Vec (A × B) n zip = zipWith _,_ unzip : ∀ {a b n} {A : Set} {B : Set} → Vec (A × B) n → Vec A n × Vec B n unzip <> = <> , <> unzip ((x , y) , xys) = Prod.map (_,_ x) (_,_ y) (unzip xys) -} foldr : ∀ {a b} {A : Set} (B : ℕ → Set) {m} → (∀ {n} → A → B n → B (suc n)) → B zero → Vec A m → B m foldr b _⊕_ n <> = n foldr b _⊕_ n (x , xs) = x ⊕ foldr b _⊕_ n xs foldr₁ : ∀ {A : Set} {m} → (A → A → A) → Vec A (suc m) → A foldr₁ _⊕_ (x , <>) = x foldr₁ _⊕_ (x , y , ys) = x ⊕ foldr₁ _⊕_ (y , ys) {- -- CYKLI (asi nevie solvnut meta) foldl₁ : ∀ {A : Set} {m} → (A → A → A) → Vec A (suc m) → A foldl₁ _⊕_ (x , xs) = foldl _ _⊕_ x xs -} {- concat : ∀ {a m n} {A : Set} → Vec (Vec A m) n → Vec A (n * m) concat <> = <> concat (xs , xss) = xs ++ concat xss -} {- splitAt : ∀ {A : Set} m {n} (xs : Vec A (m + n)) → ∃₂ λ (ys : Vec A m) (zs : Vec A n) → xs ≡ ys ++ zs splitAt zero xs = (<> , xs , refl) splitAt (suc m) (x , xs) with splitAt m xs splitAt (suc m) (x , .(ys ++ zs)) | (ys , zs , refl) = ((x , ys) , zs , refl) take : ∀ {A : Set} m {n} → Vec A (m + n) → Vec A m take m xs with splitAt m xs take m .(ys ++ zs) | (ys , zs , refl) = ys drop : ∀ {A : Set} m {n} → Vec A (m + n) → Vec A n drop m xs with splitAt m xs drop m .(ys ++ zs) | (ys , zs , refl) = zs -} {- group : ∀ {A : Set} n k (xs : Vec A (n * k)) → ∃ λ (xss : Vec (Vec A k) n) → xs ≡ concat xss group zero k <> = (<> , refl) group (suc n) k xs with splitAt k xs group (suc n) k .(ys ++ zs) | (ys , zs , refl) with group n k zs group (suc n) k .(ys ++ concat zss) | (ys , ._ , refl) | (zss , refl) = ((ys , zss) , refl) -- Splits a vector into two "halves". split : ∀ {a n} {A : Set} → Vec A n → Vec A ⌈ n /2⌉ × Vec A ⌊ n /2⌋ split <> = (<> , <>) split (x , <>) = (x , <> , <>) split (x , y , xs) = Prod.map (_,_ x) (_,_ y) (split xs) -} {- reverse : ∀ {n} {A : Set} → Vec A n → Vec A n reverse {_} {A} = foldl (Vec A) (λ rev x → x , rev) <> -} {- -- CYKLI opat metavars trouble? sum : ∀ {n} → Vec ℕ n → ℕ sum = foldr _ _+_ zero -} toList : ∀ {n} {A : Set} → Vec A n → List A toList <> = [] toList (x , xs) = x ∷ (toList xs) {- fromList : ∀ {A : Set} → (xs : List A) → Vec A (List.length xs) fromList [] = <> fromList (x ∷ xs) = x , fromList xs -} -- Snoc. infixl 5 _,ʳ_ _,ʳ_ : ∀ {n} {A : Set} → Vec A n → A → Vec A (suc n) <> ,ʳ y = < y > (x , xs) ,ʳ y = x , (xs ,ʳ y) {- initLast : ∀ {a n} {A : Set} (xs : Vec A (1 + n)) → ∃₂ λ (ys : Vec A n) (y : A) → xs ≡ ys ,ʳ y initLast {n = zero} (x , <>) = (<> , x , refl) initLast {n = suc n} (x , xs) with initLast xs initLast {n = suc n} (x , .(ys ,ʳ y)) | (ys , y , refl) = ((x , ys) , y , refl) init : ∀ {n} {A : Set} → Vec A (1 + n) → Vec A n init xs with initLast xs init .(ys ,ʳ y) | (ys , y , refl) = ys last : ∀ {n} {A : Set} → Vec A (1 + n) → A last xs with initLast xs last .(ys ,ʳ y) | (ys , y , refl) = y -} {- infixl 1 _>>=_ _>>=_ : ∀ {a b m n} {A : Set} {B : Set} → Vec A m → (A → Vec B n) → Vec B (m * n) xs >>= f = concat (map f xs) infixl 4 _⊛*_ _⊛*_ : ∀ {a b m n} {A : Set} {B : Set} → Vec (A → B) m → Vec A n → Vec B (m * n) fs ⊛* xs = fs >>= λ f → map f xs -} -- Interleaves the two vectors. {- infixr 5 _⋎_ _⋎_ : ∀ {m n} {A : Set} → Vec A m → Vec A n → Vec A (m +⋎ n) <> ⋎ ys = ys (x , xs) ⋎ ys = x , (ys ⋎ xs) -} -- A lookup function. lookup : ∀ {a n} {A : Set} → Fin n → Vec A n → A lookup fzero (x , xs) = x lookup (fsuc i) (x , xs) = lookup i xs -- An inverse of flip lookup. {- tabulate : ∀ {n a} {A : Set} → (Fin n → A) → Vec A n tabulate {zero} f = <> tabulate {suc n} f = f zero , tabulate (f ∘ suc) -} -- Update. infixl 6 _[_]≔_ _[_]≔_ : ∀ {a n} {A : Set} → Vec A n → Fin n → A → Vec A n <> [ () ]≔ y (x , xs) [ fzero ]≔ y = y , xs (x , xs) [ fsuc i ]≔ y = x , xs [ i ]≔ y -- Generates a vector containing all elements in Fin n. This function -- is not placed in Data.Fin because Data.Vec depends on Data.Fin. -- -- The implementation was suggested by Conor McBride ("Fwd: how to -- count 0..n-1", http://thread.gmane.org/gmane.comp.lang.agda/2554). {- allFin : ∀ n → Vec (Fin n) n allFin _ = tabulate id -}
24.291262
80
0.441513
04085c9957e75bd641b79f046ea78ac68d4c3665
1,518
agda
Agda
TotalParserCombinators/Recogniser/Expression.agda
yurrriq/parser-combinators
b396d35cc2cb7e8aea50b982429ee385f001aa88
[ "MIT" ]
7
2016-12-13T05:23:14.000Z
2021-06-22T05:35:31.000Z
TotalParserCombinators/Recogniser/Expression.agda
yurrriq/parser-combinators
b396d35cc2cb7e8aea50b982429ee385f001aa88
[ "MIT" ]
1
2018-01-22T22:21:41.000Z
2018-01-24T16:39:37.000Z
TotalParserCombinators/Recogniser/Expression.agda
yurrriq/parser-combinators
b396d35cc2cb7e8aea50b982429ee385f001aa88
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Example: Left recursive expression grammar ------------------------------------------------------------------------ module TotalParserCombinators.Recogniser.Expression where open import Coinduction open import Data.Bool open import Data.Char as Char using (Char) open import Data.List open import Data.String as String using (String) open import Function open import Relation.Binary.PropositionalEquality open import TotalParserCombinators.BreadthFirst import TotalParserCombinators.Lib as Lib open import TotalParserCombinators.Recogniser ------------------------------------------------------------------------ -- Lifted versions of some parsers -- Specific tokens. tok : Char → P Char [] tok c = lift $ Lib.Token.tok Char Char._≟_ c -- Numbers. number : P Char [] number = lift Lib.number ------------------------------------------------------------------------ -- An expression grammar -- t ∷= t '+' f ∣ f -- f ∷= f '*' a ∣ a -- a ∷= '(' t ')' ∣ n mutual term = ♯ term · tok '+' · factor ∣ factor factor = ♯ factor · tok '*' · atom ∣ atom atom = tok '(' · ♯ term · tok ')' ∣ number ------------------------------------------------------------------------ -- Unit tests module Tests where test : ∀ {n} → P Char n → String → Bool test p s = not $ null $ parse ⟦ p ⟧ (String.toList s) ex₁ : test term "1*(2+3)" ≡ true ex₁ = refl ex₂ : test term "1*(2+3" ≡ false ex₂ = refl
24.095238
72
0.497365
58796ec97fe6a08920635b97e92256fe68275f53
917
agda
Agda
test/Vector.agda
jespercockx/agda2hs
703c66db29023f5538eaa841f38dc34e89473a3e
[ "MIT" ]
55
2020-10-20T13:36:25.000Z
2022-03-26T21:57:56.000Z
test/Vector.agda
SNU-2D/agda2hs
160478a51bc78b0fdab07b968464420439f9fed6
[ "MIT" ]
63
2020-10-22T05:19:27.000Z
2022-02-25T15:47:30.000Z
test/Vector.agda
SNU-2D/agda2hs
160478a51bc78b0fdab07b968464420439f9fed6
[ "MIT" ]
18
2020-10-21T22:19:09.000Z
2022-03-12T11:42:52.000Z
open import Agda.Builtin.Nat data Vec (a : Set) : {n : Nat} → Set where Nil : Vec a {0} Cons : {n : Nat} → a → Vec a {n} → Vec a {suc n} {-# COMPILE AGDA2HS Vec #-} mapV : {a b : Set} {n : Nat} (f : a → b) → Vec a {n} → Vec b {n} mapV f Nil = Nil mapV f (Cons x xs) = Cons (f x) (mapV f xs) {-# COMPILE AGDA2HS mapV #-} tailV : {a : Set} {n : Nat} → Vec a {suc n} → Vec a {n} tailV (Cons x xs) = xs {-# COMPILE AGDA2HS tailV #-} -- Using erasure instead of implicit arguments data Vec' (a : Set) : (@0 n : Nat) → Set where Nil' : Vec' a 0 Cons' : {@0 n : Nat} → a → Vec' a n → Vec' a (suc n) {-# COMPILE AGDA2HS Vec' #-} mapV' : {a b : Set} {@0 n : Nat} (f : a → b) → Vec' a n → Vec' b n mapV' f Nil' = Nil' mapV' f (Cons' x xs) = Cons' (f x) (mapV' f xs) {-# COMPILE AGDA2HS mapV' #-} tailV' : {a : Set} {@0 n : Nat} → Vec' a (suc n) → Vec' a n tailV' (Cons' x xs) = xs {-# COMPILE AGDA2HS tailV' #-}
28.65625
66
0.527808
adbf4eae2923efb035e72b65752e5705f3609d0b
778
agda
Agda
test/Succeed/Issue154.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue154.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue154.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- You are not allowed to export the same name twice from a -- module. However, if the name is only exported once, ambiguity -- is allowed. module Issue154 where module A where postulate X : Set module B where postulate X : Set module C where open A public -- X is ambiguous here, but only exported once from C module D where private postulate X : Set open A public -- same here module E where postulate X : Set open A -- and here module F where open A public open D public -- in this case there is no ambiguity, A.X and D.X refer -- to the same entity (A.X) module G where open B public module H where open G public open B public -- same as F but for modules postulate test : A.X → B.X → B.C.X → D.X → E.X → F.X → G.X → H.X
18.52381
64
0.669666
9a380ca6520505867f4712e0eefd0a3f76402512
4,140
agda
Agda
core/lib/path-seq/Rotations.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
core/lib/path-seq/Rotations.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
core/lib/path-seq/Rotations.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
50
2015-01-10T01:48:08.000Z
2022-02-14T03:03:25.000Z
{-# OPTIONS --without-K --rewriting #-} open import lib.Base open import lib.PathGroupoid open import lib.path-seq.Concat open import lib.path-seq.Inversion open import lib.path-seq.Reasoning module lib.path-seq.Rotations {i} {A : Type i} where {- The order of the arguments p, q, r follows the occurrences of these variables in the output type -} pre-rotate-in : {a a' a'' : A} {q : a' =-= a''} {p : a == a'} {r : a =-= a''} → p ◃∙ q =ₛ r → q =ₛ ! p ◃∙ r pre-rotate-in {q = q} {p = idp} {r = r} e = q =ₛ⟨ =ₛ-in (! (↯-∙∙ (idp ◃∎) q)) ⟩ idp ◃∙ q =ₛ⟨ e ⟩ r =ₛ⟨ =ₛ-in (! (↯-∙∙ (idp ◃∎) r)) ⟩ idp ◃∙ r ∎ₛ pre-rotate-out : {a a' a'' : A} {p : a == a'} {q : a' =-= a''} {r : a =-= a''} → q =ₛ ! p ◃∙ r → p ◃∙ q =ₛ r pre-rotate-out {p = idp} {q = q} {r = r} e = idp ◃∙ q =ₛ⟨ =ₛ-in (↯-∙∙ (idp ◃∎) q) ⟩ q =ₛ⟨ e ⟩ idp ◃∙ r =ₛ⟨ =ₛ-in (↯-∙∙ (idp ◃∎) r) ⟩ r ∎ₛ pre-rotate'-in : {a a' a'' : A} {p : a == a'} {r : a =-= a''} {q : a' =-= a''} → r =ₛ p ◃∙ q → ! p ◃∙ r =ₛ q pre-rotate'-in e = !ₛ (pre-rotate-in (!ₛ e)) pre-rotate'-out : {a a' a'' : A} {r : a =-= a''} {p : a == a'} {q : a' =-= a''} → ! p ◃∙ r =ₛ q → r =ₛ p ◃∙ q pre-rotate'-out e = !ₛ (pre-rotate-out (!ₛ e)) pre-rotate-seq-in : {a a' a'' : A} {q : a' =-= a''} {p : a =-= a'} {r : a =-= a''} → p ∙∙ q =ₛ r → q =ₛ seq-! p ∙∙ r pre-rotate-seq-in {q = q} {p = []} {r = r} e = e pre-rotate-seq-in {q = q} {p = p ◃∙ s} {r = r} e = q =ₛ⟨ pre-rotate-seq-in {q = q} {p = s} {r = ! p ◃∙ r} (pre-rotate-in e) ⟩ seq-! s ∙∙ ! p ◃∙ r =ₛ⟨ =ₛ-in (ap ↯ (! (∙∙-assoc (seq-! s) (! p ◃∎) r))) ⟩ seq-! (p ◃∙ s) ∙∙ r ∎ₛ pre-rotate'-seq-in : {a a' a'' : A} {p : a =-= a'} {r : a =-= a''} {q : a' =-= a''} → r =ₛ p ∙∙ q → seq-! p ∙∙ r =ₛ q pre-rotate'-seq-in {p = p} {r = r} {q = q} e = !ₛ (pre-rotate-seq-in {q = q} {p} {r} (!ₛ e)) post-rotate'-in : {a a' a'' : A} → {r : a =-= a''} {q : a' == a''} {p : a =-= a'} → r =ₛ p ∙▹ q → r ∙▹ ! q =ₛ p post-rotate'-in {r = r} {q = idp} {p = p} e = r ∙▹ idp =ₛ⟨ =ₛ-in (↯-∙∙ r (idp ◃∎) ∙ ∙-unit-r (↯ r)) ⟩ r =ₛ⟨ e ⟩ p ∙▹ idp =ₛ⟨ =ₛ-in (↯-∙∙ p (idp ◃∎) ∙ ∙-unit-r (↯ p)) ⟩ p ∎ₛ post-rotate-in : {a a' a'' : A} → {p : a =-= a'} {r : a =-= a''} {q : a' == a''} → p ∙▹ q =ₛ r → p =ₛ r ∙▹ ! q post-rotate-in {p = p} {r = r} {q = q} e = !ₛ (post-rotate'-in (!ₛ e)) post-rotate-out : {a a' a'' : A} → {p : a =-= a'} {q : a' == a''} {r : a =-= a''} → p =ₛ r ∙▹ ! q → p ∙▹ q =ₛ r post-rotate-out {p = p} {q = q} {r = r} e = =ₛ-in $ ↯ (p ∙▹ q) =⟨ ap (λ v → ↯ (p ∙▹ v)) (! (!-! q)) ⟩ ↯ (p ∙▹ ! (! q)) =⟨ =ₛ-out (post-rotate'-in {r = p} {q = ! q} {p = r} e) ⟩ ↯ r =∎ post-rotate'-seq-in : {a a' a'' : A} → {r : a =-= a''} {q : a' =-= a''} {p : a =-= a'} → r =ₛ p ∙∙ q → r ∙∙ seq-! q =ₛ p post-rotate'-seq-in {r = r} {q = []} {p = p} e = r ∙∙ [] =ₛ⟨ =ₛ-in (ap ↯ (∙∙-unit-r r)) ⟩ r =ₛ⟨ e ⟩ p ∙∙ [] =ₛ⟨ =ₛ-in (ap ↯ (∙∙-unit-r p)) ⟩ p ∎ₛ post-rotate'-seq-in {r = r} {q = q ◃∙ s} {p = p} e = r ∙∙ (seq-! s ∙▹ ! q) =ₛ⟨ =ₛ-in (ap ↯ (! (∙∙-assoc r (seq-! s) (! q ◃∎)))) ⟩ (r ∙∙ seq-! s) ∙▹ ! q =ₛ⟨ post-rotate'-in {r = r ∙∙ seq-! s} {q = q} {p = p} $ post-rotate'-seq-in {r = r} {s} {p ∙▹ q} $ r =ₛ⟨ e ⟩ p ∙∙ (q ◃∙ s) =ₛ⟨ =ₛ-in (ap ↯ (! (∙∙-assoc p (q ◃∎) s))) ⟩ (p ∙▹ q) ∙∙ s ∎ₛ ⟩ p ∎ₛ post-rotate-seq-in : {a a' a'' : A} → {p : a =-= a'} {r : a =-= a''} {q : a' =-= a''} → p ∙∙ q =ₛ r → p =ₛ r ∙∙ (seq-! q) post-rotate-seq-in {p = p} {r = r} {q = q} e = !ₛ (post-rotate'-seq-in {r = r} {q = q} {p = p} (!ₛ e)) post-rotate'-seq-out : {a a' a'' : A} → {r : a =-= a''} {p : a =-= a'} {q : a' =-= a''} → r ∙∙ seq-! q =ₛ p → r =ₛ p ∙∙ q post-rotate'-seq-out {r = r} {p = p} {q = q} e = r =ₛ⟨ post-rotate-seq-in {p = r} {r = p} {q = seq-! q} e ⟩ p ∙∙ seq-! (seq-! q) =ₛ⟨ =ₛ-in (ap (λ v → ↯ (p ∙∙ v)) (seq-!-seq-! q)) ⟩ p ∙∙ q ∎ₛ post-rotate-seq-out : {a a' a'' : A} → {p : a =-= a'} {q : a' =-= a''} {r : a =-= a''} → p =ₛ r ∙∙ seq-! q → p ∙∙ q =ₛ r post-rotate-seq-out e = !ₛ (post-rotate'-seq-out (!ₛ e))
27.417219
83
0.366667
314849a9fb11513db9ad60e9412ff38559778679
2,379
agda
Agda
TreeFold/Indexed.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
6
2020-09-11T17:45:41.000Z
2021-11-16T08:11:34.000Z
TreeFold/Indexed.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
null
null
null
TreeFold/Indexed.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
1
2021-11-11T12:30:21.000Z
2021-11-11T12:30:21.000Z
{-# OPTIONS --cubical --safe #-} module TreeFold.Indexed where open import Prelude open import Data.Binary using (𝔹; 0ᵇ; 1ᵇ_; 2ᵇ_; ⟦_⇓⟧; ⟦_⇑⟧; inc) open import Data.Binary.Isomorphism open import Data.Nat private variable n m : ℕ t : Level N : ℕ → Type t ns : 𝔹 double : ℕ → ℕ double n = n * 2 2^_*_ : ℕ → ℕ → ℕ 2^ zero * m = m 2^ suc n * m = double (2^ n * m) infixr 5 _1∷_ _2∷_ data Array (T : ℕ → Type a) : 𝔹 → Type a where [] : Array T 0ᵇ _1∷_ : T 1 → Array (T ∘ double) ns → Array T (1ᵇ ns) _2∷_ : T 2 → Array (T ∘ double) ns → Array T (2ᵇ ns) cons : (∀ n → N n → N n → N (double n)) → N 1 → Array N ns → Array N (inc ns) cons branch x [] = x 1∷ [] cons branch x (y 1∷ ys) = branch 1 x y 2∷ ys cons branch x (y 2∷ ys) = x 1∷ cons (branch ∘ double) y ys array-foldr : (N : ℕ → Type t) → (∀ n m → N (2^ n * 1) → N (2^ n * m) → N (2^ n * suc m)) → N 0 → Array N ns → N ⟦ ns ⇓⟧ array-foldr {ns = 0ᵇ} N c b [] = b array-foldr {ns = 2ᵇ ns} N c b (x 2∷ xs) = c 1 ⟦ ns ⇓⟧ x (array-foldr (N ∘ double) (c ∘ suc) b xs) array-foldr {ns = 1ᵇ ns} N c b (x 1∷ xs) = c 0 (⟦ ns ⇓⟧ * 2) x (array-foldr (N ∘ double) (c ∘ suc) b xs) open import Data.Vec import Data.Nat.Properties as ℕ double≡*2 : ∀ n → n + n ≡ n * 2 double≡*2 zero = refl double≡*2 (suc n) = cong suc (ℕ.+-suc n n ; cong suc (double≡*2 n)) module NonNorm {t} (N : ℕ → Type t) (f : ∀ p n m → N (2^ p * n) → N (2^ p * m) → N (2^ p * (n + m))) (z : N 0) where spine : Vec (N 1) n → Array (N ) ⟦ n ⇑⟧ spine [] = [] spine (x ∷ xs) = cons (λ n x y → subst N (double≡*2 n) (f 0 n n x y)) x (spine xs) unspine : Array N ns → N ⟦ ns ⇓⟧ unspine = array-foldr N (λ n → f n 1) z treeFold : Vec (N 1) n → N n treeFold xs = subst N (𝔹-rightInv _) (unspine (spine xs)) pow-suc : ∀ n m → (2^ n * 1) + (2^ n * m) ≡ (2^ n * suc m) pow-suc zero m = refl pow-suc (suc n) m = sym (ℕ.+-*-distrib (2^ n * 1) (2^ n * m) 2) ; cong (_* 2) (pow-suc n m) module _ {t} (N : ℕ → Type t) (f : ∀ {n m} → N n → N m → N (n + m)) (z : N 0) where spine : Vec (N 1) n → Array (N ) ⟦ n ⇑⟧ spine [] = [] spine (x ∷ xs) = cons (λ n x y → subst N (double≡*2 n) (f x y)) x (spine xs) unspine : Array N ns → N ⟦ ns ⇓⟧ unspine = array-foldr N (λ n m xs ys → subst N (pow-suc n m) (f xs ys)) z treeFold : Vec (N 1) n → N n treeFold xs = subst N (𝔹-rightInv _) (unspine (spine xs))
33.041667
120
0.517444
06165aa83cf636bec78f223991434d5a5fb6f432
1,118
agda
Agda
test/Succeed/Issue3547.agda
zliu41/agda
73405f70bced057d24dd4bf122d53f9548544aba
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue3547.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue3547.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- {-# OPTIONS --cubical -vtc.lhs.split.partial:20 #-} {-# OPTIONS --cubical #-} module _ where open import Agda.Primitive.Cubical open import Agda.Builtin.Equality postulate X : Set P : I → Set p : P i1 module Test (A : Set) (i : I) (B : Set) where j = i R = P j module Z (r s : A) where a0 : I → Partial j R a0 k with k ... | _ = \ { (j = i1) → p } a : Partial j R a (j = i1) = p refining : ∀ (x y : A) → x ≡ y → A → A refining x y refl = \ x -> x where prf : A → Partial j R prf = \ { _ (j = i1) → p } refining-dot : ∀ (x y : A) → x ≡ y → A → A refining-dot x .x refl = \ x -> x where prf : A → Partial j R prf = \ { _ (j = i1) → p } refining-dot2 : ∀ (x y : A) → x ≡ y → A → A refining-dot2 x .x refl z = z where prf : Partial j R prf = \ { (i = i1) → p } refining-cxt : A ≡ X → A → A refining-cxt refl = \ x -> x where prf : Partial j R prf = \ { (j = i1) → p } refining-cxt2 : B ≡ X → A → A refining-cxt2 refl = \ x → x where prf : Partial j R prf = \ { (j = i1) → p }
21.09434
54
0.4678
9a43f9819c2756b83cd32fed7fae0743b6e69748
2,764
agda
Agda
agda/Number/Prelude/Nat.agda
mchristianl/synthetic-reals
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
[ "MIT" ]
3
2020-07-31T18:15:26.000Z
2022-02-19T12:15:21.000Z
agda/Number/Prelude/Nat.agda
mchristianl/synthetic-reals
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
[ "MIT" ]
null
null
null
agda/Number/Prelude/Nat.agda
mchristianl/synthetic-reals
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts #-} module Number.Prelude.Nat where open import Cubical.Data.Nat.Order public using () renaming ( _<_ to _<ⁿᵗ_ ; <-trans to <ⁿ-trans -- TODO: use different version ; _≟_ to _≟ⁿ_ ; lt to ltⁿ ; gt to gtⁿ ; eq to eqⁿ ; ¬-<-zero to ¬-<ⁿ-zero ) open import Data.Nat public using () renaming ( _⊔_ to maxⁿ ; _⊓_ to minⁿ ; _+_ to _+ⁿ_ ; _*_ to _·ⁿ_ ; pred to predⁿ ) open import Cubical.Data.Nat public using (suc; zero; ℕ; HasFromNat) renaming ( +-comm to +ⁿ-comm ; +-assoc to +ⁿ-assoc ; *-comm to ·ⁿ-comm ; *-suc to ·ⁿ-suc ; *-assoc to ·ⁿ-assoc ; +-suc to +ⁿ-suc ; *-distribˡ to ·ⁿ-distribˡ ; *-distribʳ to ·ⁿ-distribʳ ; *-identityʳ to ·ⁿ-identityʳ ; *-identityˡ to ·ⁿ-identityˡ ; snotz to snotzⁿ ; injSuc to injSucⁿ ; isSetℕ to is-setⁿ ; inj-m+ to +ⁿ-preserves-≡ˡ ; inj-+m to +ⁿ-preserves-≡ʳ ; inj-sm* to ·ⁿ-reflects-≡ˡ' ; inj-*sm to ·ⁿ-reflects-≡ʳ' ) open import Number.Instances.Nat as Nat public using () renaming ( bundle to ℕbundle ; _<_ to _<ⁿ_ ; 0<suc to 0<ⁿsuc ; ·-nullifiesˡ to ·ⁿ-nullifiesˡ ; ·-nullifiesʳ to ·ⁿ-nullifiesʳ ; <-irrefl to <ⁿ-irrefl ; suc-creates-< to sucⁿ-creates-<ⁿ ; <-cotrans to <ⁿ-cotrans ; ¬suc<0 to ¬suc<ⁿ0 ; ·-reflects-< to ·ⁿ-reflects-<ⁿ ; ·-preserves-< to ·ⁿ-preserves-<ⁿ ; +-createsʳ-< to +ⁿ-createsʳ-<ⁿ ; +-createsˡ-< to +ⁿ-createsˡ-<ⁿ ; min-comm to minⁿ-comm ; min-tightˡ to minⁿ-tightˡ ; min-tightʳ to minⁿ-tightʳ ; min-identity to minⁿ-identity ; max-comm to maxⁿ-comm ; max-tightˡ to maxⁿ-tightˡ ; max-tightʳ to maxⁿ-tightʳ ; max-identity to maxⁿ-identity ; MinTrichtotomy to MinTrichtotomyⁿ ; MaxTrichtotomy to MaxTrichtotomyⁿ ; min-trichotomy to minⁿ-trichotomy ; max-trichotomy to maxⁿ-trichotomy ; is-min to is-minⁿ ; is-max to is-maxⁿ ; +-<-ext to +ⁿ-<ⁿ-ext ; ·-reflects-≡ʳ to ·ⁿ-reflects-≡ʳ ; ·-reflects-≡ˡ to ·ⁿ-reflects-≡ˡ ) open import MorePropAlgebra.Definitions open import MorePropAlgebra.Structures open import Number.Structures2 open IsMonoid Nat.+-Monoid public using () renaming (is-identity to +ⁿ-identity) open IsMonoid Nat.·-Monoid public using () renaming (is-identity to ·ⁿ-identity) open IsSemiring Nat.is-Semiring public using () renaming (is-dist to is-distⁿ) open IsStrictLinearOrder Nat.<-StrictLinearOrder public using () renaming (is-tricho to is-trichoⁿ) -- <-StrictLinearOrder .IsStrictLinearOrder.is-trans a b c = <-trans {a} {b} {c}
33.707317
102
0.593705
ad29bea2628f2f232232bf5421ae0017bbb352e7
206
agda
Agda
src/prototyping/term/examples/Prelude.agda
larrytheliquid/agda
477c8c37f948e6038b773409358fd8f38395f827
[ "MIT" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
src/prototyping/term/examples/Prelude.agda
masondesu/agda
70c8a575c46f6a568c7518150a1a64fcd03aa437
[ "MIT" ]
null
null
null
src/prototyping/term/examples/Prelude.agda
masondesu/agda
70c8a575c46f6a568c7518150a1a64fcd03aa437
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
module Prelude where data _==_ {A : Set}(x : A) : A → Set where refl : x == x J : {A : Set} {x y : A} (P : (x y : A) → x == y -> Set) → (∀ z → P z z refl) → (p : x == y) → P x y p J P h refl = h _
20.6
57
0.417476
ad2dbd3e26817fd3b229fb3b75402100808636df
5,047
agda
Agda
src/Categories/Diagram/Pullback/Properties.agda
yourboynico/agda-categories
6a087c592dbe58fc4bd9d02e1be9b94a9e138aca
[ "MIT" ]
279
2019-06-01T14:36:40.000Z
2022-03-22T00:40:14.000Z
src/Categories/Diagram/Pullback/Properties.agda
yourboynico/agda-categories
6a087c592dbe58fc4bd9d02e1be9b94a9e138aca
[ "MIT" ]
236
2019-06-01T14:53:54.000Z
2022-03-28T14:31:43.000Z
src/Categories/Diagram/Pullback/Properties.agda
yourboynico/agda-categories
6a087c592dbe58fc4bd9d02e1be9b94a9e138aca
[ "MIT" ]
64
2019-06-02T16:58:15.000Z
2022-03-14T02:00:59.000Z
{-# OPTIONS --without-K --safe #-} open import Categories.Category module Categories.Diagram.Pullback.Properties {o ℓ e} (C : Category o ℓ e) where open import Function using (_$_) open import Categories.Category.BinaryProducts C open import Categories.Category.Cartesian C open import Categories.Diagram.Pullback C open import Categories.Diagram.Equalizer C open import Categories.Object.Product C open import Categories.Object.Terminal C open import Categories.Morphism C open import Categories.Morphism.Reasoning C private open Category C variable X Y Z : Obj f g h i : X ⇒ Y open HomReasoning open Equiv -- pullbacks of a monomorphism along itself give us the identity arrow. pullback-self-mono : Mono f → IsPullback id id f f pullback-self-mono mono = record { commute = refl ; universal = λ {X} {h₁} {h₂} eq → h₁ ; unique = λ id∘i≈h₁ _ → ⟺ identityˡ ○ id∘i≈h₁ ; p₁∘universal≈h₁ = identityˡ ; p₂∘universal≈h₂ = λ {X} {h₁} {h₂} {eq} → identityˡ ○ mono h₁ h₂ eq } -- pullback from a terminal object is the same as a product module _ (t : Terminal) where open Terminal t pullback-⊤⇒product : Pullback (! {X}) (! {Y}) → Product X Y pullback-⊤⇒product p = record { A×B = P ; π₁ = p₁ ; π₂ = p₂ ; ⟨_,_⟩ = λ f g → universal (!-unique₂ {f = ! ∘ f} {g = ! ∘ g}) ; project₁ = p₁∘universal≈h₁ ; project₂ = p₂∘universal≈h₂ ; unique = λ eq eq′ → ⟺ (unique eq eq′) } where open Pullback p product⇒pullback-⊤ : Product X Y → Pullback (! {X}) (! {Y}) product⇒pullback-⊤ p = record { p₁ = π₁ ; p₂ = π₂ ; isPullback = record { commute = !-unique₂ ; universal = λ {_ f g} _ → ⟨ f , g ⟩ ; unique = λ eq eq′ → ⟺ (unique eq eq′) ; p₁∘universal≈h₁ = project₁ ; p₂∘universal≈h₂ = project₂ } } where open Product p -- pullbacks respect _≈_ module _ (p : Pullback f g) where open Pullback p pullback-resp-≈ : f ≈ h → g ≈ i → Pullback h i pullback-resp-≈ eq eq′ = record { p₁ = p₁ ; p₂ = p₂ ; isPullback = record { commute = ∘-resp-≈ˡ (⟺ eq) ○ commute ○ ∘-resp-≈ˡ eq′ ; universal = λ eq″ → universal (∘-resp-≈ˡ eq ○ eq″ ○ ∘-resp-≈ˡ (⟺ eq′)) ; unique = unique ; p₁∘universal≈h₁ = p₁∘universal≈h₁ ; p₂∘universal≈h₂ = p₂∘universal≈h₂ } } -- Some facts about pulling back along identity module _ (p : Pullback id f) where open Pullback p -- This is a more subtle way of saying that 'p₂ ≈ id', without involving heterogenous equality. pullback-identity : universal id-comm-sym ∘ p₂ ≈ id pullback-identity = begin universal Basic.id-comm-sym ∘ p₂ ≈⟨ unique ( pullˡ p₁∘universal≈h₁ ) (pullˡ p₂∘universal≈h₂) ⟩ universal eq ≈⟨ universal-resp-≈ (⟺ commute ○ identityˡ) identityˡ ⟩ universal commute ≈˘⟨ Pullback.id-unique p ⟩ id ∎ where eq : id ∘ f ∘ p₂ ≈ f ∘ id ∘ p₂ eq = begin (id ∘ f ∘ p₂) ≈⟨ elimˡ Equiv.refl ⟩ (f ∘ p₂) ≈˘⟨ refl⟩∘⟨ identityˡ ⟩ (f ∘ id ∘ p₂) ∎ module _ (pullbacks : ∀ {X Y Z} (f : X ⇒ Z) (g : Y ⇒ Z) → Pullback f g) (cartesian : Cartesian) where open Cartesian cartesian open BinaryProducts products using (⟨_,_⟩; π₁; π₂; ⟨⟩-cong₂; ⟨⟩∘; project₁; project₂) pullback×cartesian⇒equalizer : Equalizer f g pullback×cartesian⇒equalizer {f = f} {g = g} = record { arr = p.p₁ ; isEqualizer = record { equality = equality ; equalize = λ {_ h} eq → p.universal $ begin ⟨ f , g ⟩ ∘ h ≈⟨ ⟨⟩∘ ⟩ ⟨ f ∘ h , g ∘ h ⟩ ≈˘⟨ ⟨⟩-cong₂ identityˡ (identityˡ ○ eq) ⟩ ⟨ id ∘ f ∘ h , id ∘ f ∘ h ⟩ ≈˘⟨ ⟨⟩∘ ⟩ ⟨ id , id ⟩ ∘ f ∘ h ∎ ; universal = ⟺ p.p₁∘universal≈h₁ ; unique = λ eq → p.unique (⟺ eq) (⟺ (pullˡ eq′) ○ ⟺ (∘-resp-≈ʳ eq)) } } where p : Pullback ⟨ f , g ⟩ ⟨ id , id ⟩ p = pullbacks _ _ module p = Pullback p eq : ⟨ f ∘ p.p₁ , g ∘ p.p₁ ⟩ ≈ ⟨ p.p₂ , p.p₂ ⟩ eq = begin ⟨ f ∘ p.p₁ , g ∘ p.p₁ ⟩ ≈˘⟨ ⟨⟩∘ ⟩ ⟨ f , g ⟩ ∘ p.p₁ ≈⟨ p.commute ⟩ ⟨ id , id ⟩ ∘ p.p₂ ≈⟨ ⟨⟩∘ ⟩ ⟨ id ∘ p.p₂ , id ∘ p.p₂ ⟩ ≈⟨ ⟨⟩-cong₂ identityˡ identityˡ ⟩ ⟨ p.p₂ , p.p₂ ⟩ ∎ eq′ : f ∘ p.p₁ ≈ p.p₂ eq′ = begin f ∘ p.p₁ ≈˘⟨ project₁ ⟩ π₁ ∘ ⟨ f ∘ p.p₁ , g ∘ p.p₁ ⟩ ≈⟨ refl⟩∘⟨ eq ⟩ π₁ ∘ ⟨ p.p₂ , p.p₂ ⟩ ≈⟨ project₁ ⟩ p.p₂ ∎ equality : f ∘ p.p₁ ≈ g ∘ p.p₁ equality = begin f ∘ p.p₁ ≈⟨ eq′ ⟩ p.p₂ ≈˘⟨ project₂ ⟩ π₂ ∘ ⟨ p.p₂ , p.p₂ ⟩ ≈˘⟨ refl⟩∘⟨ eq ⟩ π₂ ∘ ⟨ f ∘ p.p₁ , g ∘ p.p₁ ⟩ ≈⟨ project₂ ⟩ g ∘ p.p₁ ∎
34.806897
99
0.496929
4baf07da2ccc59b4c5f0b88f19e28341b689b45b
5,501
agda
Agda
src/Implicits/Syntax/Type/Unification/McBride.agda
metaborg/ts.agda
7fe638b87de26df47b6437f5ab0a8b955384958d
[ "MIT" ]
4
2019-04-05T17:57:11.000Z
2021-05-07T04:08:41.000Z
src/Implicits/Syntax/Type/Unification/McBride.agda
metaborg/ts.agda
7fe638b87de26df47b6437f5ab0a8b955384958d
[ "MIT" ]
null
null
null
src/Implicits/Syntax/Type/Unification/McBride.agda
metaborg/ts.agda
7fe638b87de26df47b6437f5ab0a8b955384958d
[ "MIT" ]
null
null
null
open import Prelude renaming (_≟_ to _N≟_) module Implicits.Syntax.Type.Unification.McBride where open import Implicits.Syntax open import Implicits.Syntax.MetaType open import Data.Vec hiding (_>>=_) open import Data.Vec.Properties open import Data.Nat as N using () open import Data.Nat.Properties.Simple open import Data.Product open import Category.Monad open import Data.Maybe hiding (module Maybe; map) open import Data.Maybe as Maybe using (monad; functor) open import Level using () renaming (zero to level₀) open RawMonad {level₀} monad using (_>>=_; return) open import Category.Functor open RawFunctor {level₀} functor open import Data.Star hiding (_>>=_) open import Data.Fin.Properties as FinProp using () open import Data.Fin.Substitution open import Implicits.Substitutions open import Implicits.Substitutions.Lemmas private module M = MetaTypeMetaSubst module T = MetaTypeTypeSubst thin : ∀ {n} → Fin (suc n) → Fin n → Fin (suc n) thin zero y = suc y thin (suc x) zero = zero thin (suc x) (suc y) = suc (thin x y) thick : ∀ {n} → (x y : Fin (suc n)) → Maybe (Fin n) thick zero zero = nothing thick zero (suc y) = just y thick {zero} (suc ()) zero thick {suc n} (suc x) zero = just zero thick {zero} (suc ()) _ thick {suc n} (suc x) (suc y) = suc <$> (thick x y) check' : ∀ {ν} → Fin (suc ν) → Type (suc ν) → Maybe (Type ν) check' n (simpl (tvar m)) = (λ n → simpl (tvar n)) <$> (thick n m) check' n (simpl (tc x)) = just (simpl (tc x)) check' n (simpl (a →' b)) with check' n a | check' n b check' n (simpl (a →' b)) | just x | just y = just (simpl (x →' y)) check' n (simpl (a →' b)) | _ | nothing = nothing check' n (simpl (a →' b)) | nothing | _ = nothing check' n (a ⇒ b) with check' n a | check' n b check' n (a ⇒ b) | just x | just y = just (x ⇒ y) check' n (a ⇒ b) | _ | nothing = nothing check' n (a ⇒ b) | nothing | _ = nothing check' n (∀' t) with check' (suc n) t check' n (∀' t) | just x = just (∀' x) check' n (∀' t) | nothing = nothing substitute : {ν m n : ℕ} → (Fin m → MetaType n ν) → MetaType m ν → MetaType n ν substitute f a = a M./ (tabulate f) _for_ : ∀ {n ν} → Type ν → Fin (suc n) → Fin (suc n) → MetaType n ν _for_ t' x y with thick x y _for_ t' x y | just y' = simpl (mvar y') _for_ t' x y | nothing = to-meta t' data ASub (ν : ℕ) : ℕ → ℕ → Set where _//_ : ∀ {m} → (t' : Type ν) → Fin (suc m) → ASub ν (suc m) m AList : ℕ → ℕ → ℕ → Set AList ν m n = Star (ASub ν) m n asub-tp-weaken : ∀ {ν m n} → ASub ν m n → ASub (suc ν) m n asub-tp-weaken (t' // x) = tp-weaken t' // x asub-weaken : ∀ {ν m n} → ASub ν m n → ASub ν (suc m) (suc n) asub-weaken (t' // x) = t' // (suc x) alist-weaken : ∀ {ν m n} → AList ν m n → AList (suc ν) m n alist-weaken s = gmap Prelude.id (λ x → asub-tp-weaken x) s _◇_ : ∀ {l m n ν} → (Fin m → MetaType n ν) → (Fin l → MetaType m ν) → (Fin l → MetaType n ν) f ◇ g = substitute f ∘ g asub' : ∀ {ν m n} → (σ : AList ν m n) → Fin m → MetaType n ν asub' ε = λ n → simpl (mvar n) asub' (t' // x ◅ y) = asub' y ◇ (t' for x) asub : ∀ {ν m n} → (σ : AList ν m n) → Sub (flip MetaType ν) m n asub s = tabulate (asub' s) mgu : ∀ {m ν} → MetaType m ν → Type ν → Maybe (∃ (AList ν m)) mgu {ν} s t = amgu s t (ν , ε) where amgu : ∀ {ν m} (s : MetaType m ν) → (t : Type ν)→ ∃ (AList ν m) → Maybe (∃ (AList ν m)) -- non-matching constructors amgu (simpl (tc x)) (_ ⇒ _) acc = nothing amgu (simpl (tc _)) (∀' _) x = nothing amgu (simpl (tc x)) (simpl (_ →' _)) acc = nothing amgu (simpl (tc _)) (simpl (tvar _)) x = nothing amgu (simpl (_ →' _)) (∀' _) x = nothing amgu (simpl (_ →' _)) (_ ⇒ _) x = nothing amgu (simpl (_ →' _)) (simpl (tc _)) acc = nothing amgu (simpl (_ →' _)) (simpl (tvar _)) x = nothing amgu (_ ⇒ _) (simpl x) acc = nothing amgu (_ ⇒ _) (∀' _) x = nothing amgu (∀' _) (_ ⇒ _) x = nothing amgu (∀' _) (simpl _) x = nothing amgu (simpl (tvar _)) (_ ⇒ _) x = nothing amgu (simpl (tvar _)) (∀' _) x = nothing amgu (simpl (tvar _)) (simpl (tc _)) x = nothing amgu (simpl (tvar _)) (simpl (_ →' _)) acc = nothing -- matching constructors amgu (a ⇒ b) (a' ⇒ b') acc = _>>=_ (amgu b b' acc) (amgu a a') amgu (simpl (a →' b)) (simpl (a' →' b')) acc = _>>=_ (amgu b b' acc) (amgu a a') amgu (simpl (tc x)) (simpl (tc y)) acc with x N≟ y amgu (simpl (tc x)) (simpl (tc y)) acc | yes p = just (, ε) amgu (simpl (tc x)) (simpl (tc y)) acc | no ¬p = nothing amgu (∀' a) (∀' b) (m , acc) = σ >>= strengthen' where σ = amgu a b (m , alist-weaken acc) strengthen' : ∀ {ν n} → ∃ (AList (suc ν) n) → Maybe (∃ (AList ν n)) strengthen' (m , ε) = just (m , ε) strengthen' (m , t' // x ◅ acc) with check' zero t' strengthen' (m , t' // x ◅ acc) | just z = (λ { (m , u) → m , z // x ◅ u }) <$> (strengthen' (m , acc)) strengthen' (m , t' // x ◅ acc) | nothing = nothing -- var-var amgu ((simpl (tvar x))) ((simpl (tvar y))) (m , ε) with x FinProp.≟ y amgu ((simpl (tvar x))) ((simpl (tvar y))) (m , ε) | yes _ = just (, ε) amgu ((simpl (tvar x))) ((simpl (tvar y))) (m , ε) | no _ = nothing -- var-rigid / rigid-var amgu (simpl (mvar ())) t (zero , ε) amgu (simpl (mvar x)) t (suc m , ε) = just (m , t // x ◅ ε) amgu s t (m , t' // x ◅ us) with amgu (substitute (t' for x) s) t (m , us) amgu s t (m , t' // x ◅ us) | just (m' , us') = just (m' , t' // x ◅ us') amgu s t (m , t' // x ◅ us) | nothing = nothing
38.201389
92
0.556808
23d8b56e3ca7c3dfcf0f2e9ce668e2386f54d46b
506
agda
Agda
prototyping/Luau/Var.agda
JohnnyMorganz/luau
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
[ "MIT" ]
1
2021-11-06T08:03:00.000Z
2021-11-06T08:03:00.000Z
prototyping/Luau/Var.agda
JohnnyMorganz/luau
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
[ "MIT" ]
null
null
null
prototyping/Luau/Var.agda
JohnnyMorganz/luau
f2191b9e4da6a4bb2d9d344ebd7941ec2f00844b
[ "MIT" ]
null
null
null
module Luau.Var where open import Agda.Builtin.Bool using (true; false) open import Agda.Builtin.Equality using (_≡_) open import Agda.Builtin.String using (String; primStringEquality) open import Agda.Builtin.TrustMe using (primTrustMe) open import Properties.Dec using (Dec; yes; no) open import Properties.Equality using (_≢_) Var : Set Var = String _≡ⱽ_ : (a b : Var) → Dec (a ≡ b) a ≡ⱽ b with primStringEquality a b a ≡ⱽ b | false = no p where postulate p : (a ≢ b) a ≡ⱽ b | true = yes primTrustMe
29.764706
66
0.727273
2e705f2ce5f803a42f0900bb37b34d0ca3642ed6
189
agda
Agda
theorems/homotopy/WedgeOfCircles.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
null
null
null
theorems/homotopy/WedgeOfCircles.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
null
null
null
theorems/homotopy/WedgeOfCircles.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
1
2018-12-26T21:31:57.000Z
2018-12-26T21:31:57.000Z
{-# OPTIONS --without-K --rewriting #-} open import HoTT module homotopy.WedgeOfCircles {i} where WedgeOfCircles : (I : Type i) → Type i WedgeOfCircles I = BigWedge {A = I} (λ _ → ⊙S¹)
18.9
47
0.666667
c7c1175051a0fdf7ab62502c2b2ee5ce3ae08ccf
1,290
agda
Agda
Definition/Typed/Consequences/Consistency.agda
CoqHott/logrel-mltt
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
[ "MIT" ]
2
2018-06-21T08:39:01.000Z
2022-01-17T16:13:53.000Z
Definition/Typed/Consequences/Consistency.agda
CoqHott/logrel-mltt
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
[ "MIT" ]
null
null
null
Definition/Typed/Consequences/Consistency.agda
CoqHott/logrel-mltt
e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04
[ "MIT" ]
2
2022-01-26T14:55:51.000Z
2022-02-15T19:42:19.000Z
{-# OPTIONS --safe #-} module Definition.Typed.Consequences.Consistency where open import Definition.Untyped open import Definition.Typed open import Definition.Typed.Properties open import Definition.Typed.EqRelInstance open import Definition.LogicalRelation open import Definition.LogicalRelation.Irrelevance open import Definition.LogicalRelation.ShapeView open import Definition.LogicalRelation.Fundamental.Reducibility open import Tools.Empty open import Tools.Product import Tools.PropositionalEquality as PE zero≢one′ : ∀ {Γ l} ([ℕ] : Γ ⊩⟨ l ⟩ℕ ℕ) → Γ ⊩⟨ l ⟩ zero ≡ suc zero ∷ ℕ ^ [ ! , ι ⁰ ] / ℕ-intr [ℕ] → ⊥ zero≢one′ (noemb x) (ℕₜ₌ .(suc _) .(suc _) d d′ k≡k′ (sucᵣ x₁)) = zero≢suc (whnfRed*Term (redₜ d) zeroₙ) zero≢one′ (noemb x) (ℕₜ₌ .zero .zero d d′ k≡k′ zeroᵣ) = zero≢suc (PE.sym (whnfRed*Term (redₜ d′) sucₙ)) zero≢one′ (noemb x) (ℕₜ₌ k k′ d d′ k≡k′ (ne (neNfₜ₌ neK neM k≡m))) = zero≢ne neK (whnfRed*Term (redₜ d) zeroₙ) zero≢one′ (emb emb< [ℕ]) n = zero≢one′ [ℕ] n zero≢one′ (emb ∞< [ℕ]) n = zero≢one′ [ℕ] n -- Zero cannot be judgmentally equal to one. zero≢one : ∀ {Γ} → Γ ⊢ zero ≡ suc zero ∷ ℕ ^ [ ! , ι ⁰ ] → ⊥ zero≢one 0≡1 = let [ℕ] , [0≡1] = reducibleEqTerm 0≡1 in zero≢one′ (ℕ-elim [ℕ]) (irrelevanceEqTerm [ℕ] (ℕ-intr (ℕ-elim [ℕ])) [0≡1])
36.857143
80
0.66124
3d5269df750aed9c110340b65fa1aab8391ce510
14,469
agda
Agda
core/lib/types/Pi.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
null
null
null
core/lib/types/Pi.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
null
null
null
core/lib/types/Pi.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
1
2018-12-26T21:31:57.000Z
2018-12-26T21:31:57.000Z
{-# OPTIONS --without-K --rewriting #-} open import lib.Basics open import lib.types.Empty open import lib.types.Sigma open import lib.types.Paths module lib.types.Pi where abstract Π-level : ∀ {i j} {A : Type i} {B : A → Type j} {n : ℕ₋₂} → (((x : A) → has-level n (B x)) → has-level n (Π A B)) Π-level {n = ⟨-2⟩} p = ((λ x → fst (p x)) , (λ f → λ= (λ x → snd (p x) (f x)))) Π-level {n = S n} p = λ f g → equiv-preserves-level λ=-equiv (Π-level (λ x → p x (f x) (g x))) module _ {i j} {A : Type i} {B : A → Type j} where abstract Π-is-prop : ((x : A) → is-prop (B x)) → is-prop (Π A B) Π-is-prop = Π-level Π-is-set : ((x : A) → is-set (B x)) → is-set (Π A B) Π-is-set = Π-level module _ {i j} {A : Type i} {B : Type j} where abstract →-level : {n : ℕ₋₂} → (has-level n B → has-level n (A → B)) →-level p = Π-level (λ _ → p) →-is-set : is-set B → is-set (A → B) →-is-set = →-level →-is-prop : is-prop B → is-prop (A → B) →-is-prop = →-level module _ {i} {A : Type i} where abstract ¬-is-prop : is-prop (¬ A) ¬-is-prop = →-is-prop ⊥-is-prop module _ {i j} {X : Ptd i} {Y : Ptd j} where abstract ⊙→-level : {n : ℕ₋₂} → has-level n (de⊙ Y) → has-level n (X ⊙→ Y) ⊙→-level pY = Σ-level (→-level pY) (λ _ → =-preserves-level pY) {- Equivalences in a Π-type -} Π-emap-l : ∀ {i j k} {A : Type i} {B : Type j} (P : B → Type k) → (e : A ≃ B) → Π A (P ∘ –> e) ≃ Π B P Π-emap-l {A = A} {B = B} P e = equiv f g f-g g-f where f : Π A (P ∘ –> e) → Π B P f u b = transport P (<–-inv-r e b) (u (<– e b)) g : Π B P → Π A (P ∘ –> e) g v a = v (–> e a) abstract f-g : ∀ v → f (g v) == v f-g v = λ= λ b → to-transp (apd v (<–-inv-r e b)) g-f : ∀ u → g (f u) == u g-f u = λ= λ a → to-transp $ transport (λ p → u _ == _ [ P ↓ p ]) (<–-inv-adj e a) (↓-ap-in P (–> e) (apd u $ <–-inv-l e a)) Π-emap-r : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} → (∀ x → B x ≃ C x) → Π A B ≃ Π A C Π-emap-r {A = A} {B = B} {C = C} k = equiv f g f-g g-f where f : Π A B → Π A C f c x = –> (k x) (c x) g : Π A C → Π A B g d x = <– (k x) (d x) abstract f-g : ∀ d → f (g d) == d f-g d = λ= (λ x → <–-inv-r (k x) (d x)) g-f : ∀ c → g (f c) == c g-f c = λ= (λ x → <–-inv-l (k x) (c x)) {- favonia: This part is not used. module _ {i₀ i₁ j₀ j₁} {A₀ : Type i₀} {A₁ : Type i₁} {B₀ : A₀ → Type j₀} {B₁ : A₁ → Type j₁} where Π-emap : (u : A₀ ≃ A₁) (v : ∀ a → B₀ (<– u a) ≃ B₁ a) → Π A₀ B₀ ≃ Π A₁ B₁ Π-emap u v = Π A₀ B₀ ≃⟨ Π-emap-l _ (u ⁻¹) ⁻¹ ⟩ Π A₁ (B₀ ∘ <– u) ≃⟨ Π-emap-r v ⟩ Π A₁ B₁ ≃∎ Π-emap' : (u : A₀ ≃ A₁) (v : ∀ a → B₀ a ≃ B₁ (–> u a)) → Π A₀ B₀ ≃ Π A₁ B₁ Π-emap' u v = Π A₀ B₀ ≃⟨ Π-emap-r v ⟩ Π A₀ (B₁ ∘ –> u) ≃⟨ Π-emap-l _ u ⟩ Π A₁ B₁ ≃∎ -} {- Coversions between functions with implicit and explicit arguments -} expose-equiv : ∀ {i j} {A : Type i} {B : A → Type j} → ({x : A} → B x) ≃ ((x : A) → B x) expose-equiv = (λ f a → f {a}) , is-eq _ (λ f {a} → f a) (λ _ → idp) (λ _ → idp) {- Dependent paths in a Π-type -} module _ {i j k} {A : Type i} {B : A → Type j} {C : (a : A) → B a → Type k} where ↓-Π-in : {x x' : A} {p : x == x'} {u : Π (B x) (C x)} {u' : Π (B x') (C x')} → ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → u t == u' t' [ uncurry C ↓ pair= p q ]) → (u == u' [ (λ x → Π (B x) (C x)) ↓ p ]) ↓-Π-in {p = idp} f = λ= (λ x → f (idp {a = x})) ↓-Π-out : {x x' : A} {p : x == x'} {u : Π (B x) (C x)} {u' : Π (B x') (C x')} → (u == u' [ (λ x → Π (B x) (C x)) ↓ p ]) → ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → u t == u' t' [ uncurry C ↓ pair= p q ]) ↓-Π-out {p = idp} q idp = app= q _ ↓-Π-β : {x x' : A} {p : x == x'} {u : Π (B x) (C x)} {u' : Π (B x') (C x')} → (f : {t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → u t == u' t' [ uncurry C ↓ pair= p q ]) → {t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → ↓-Π-out (↓-Π-in f) q == f q ↓-Π-β {p = idp} f idp = app=-β (λ x → f (idp {a = x})) _ ↓-Π-η : {x x' : A} {p : x == x'} {u : Π (B x) (C x)} {u' : Π (B x') (C x')} → (q : (u == u' [ (λ x → Π (B x) (C x)) ↓ p ])) → ↓-Π-in (↓-Π-out q) == q ↓-Π-η {p = idp} q = ! (λ=-η q) ↓-Π-equiv : {x x' : A} {p : x == x'} {u : Π (B x) (C x)} {u' : Π (B x') (C x')} → ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → u t == u' t' [ uncurry C ↓ pair= p q ]) ≃ (u == u' [ (λ x → Π (B x) (C x)) ↓ p ]) ↓-Π-equiv {p = idp} = equiv ↓-Π-in ↓-Π-out ↓-Π-η (λ u → <– (ap-equiv expose-equiv _ _) (λ= (λ t → <– (ap-equiv expose-equiv _ _) (λ= (λ t' → λ= (↓-Π-β u)))))) {- Dependent paths in a Π-type where the codomain is not dependent on anything Right now, this is defined in terms of the previous one. Maybe it’s a good idea, maybe not. -} module _ {i j k} {A : Type i} {B : A → Type j} {C : Type k} {x x' : A} {p : x == x'} {u : B x → C} {u' : B x' → C} where ↓-app→cst-in : ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → u t == u' t') → (u == u' [ (λ x → B x → C) ↓ p ]) ↓-app→cst-in f = ↓-Π-in (λ q → ↓-cst-in (f q)) ↓-app→cst-out : (u == u' [ (λ x → B x → C) ↓ p ]) → ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → u t == u' t') ↓-app→cst-out r q = ↓-cst-out (↓-Π-out r q) ↓-app→cst-β : (f : ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → u t == u' t')) → {t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → ↓-app→cst-out (↓-app→cst-in f) q == f q ↓-app→cst-β f q = ↓-app→cst-out (↓-app→cst-in f) q =⟨ idp ⟩ ↓-cst-out (↓-Π-out (↓-Π-in (λ qq → ↓-cst-in (f qq))) q) =⟨ ↓-Π-β (λ qq → ↓-cst-in (f qq)) q |in-ctx ↓-cst-out ⟩ ↓-cst-out (↓-cst-in {p = pair= p q} (f q)) =⟨ ↓-cst-β (pair= p q) (f q) ⟩ f q =∎ {- favonia: these lemmas are not used anywhere {- Similar to above, with domain being the identity function. -} {- These lemmas were in homotopy.FunctionOver and in different conventions. -} module _ {i j} {A B : Type i} {C : Type j} {u : A → C} {v : B → C} where ↓-idf→cst-in : ∀ (p : A == B) → u == v ∘ coe p → u == v [ (λ x → x → C) ↓ p ] ↓-idf→cst-in idp q = q ↓-idf→cst-ua-in : ∀ (e : A ≃ B) → u == v ∘ –> e → u == v [ (λ x → x → C) ↓ ua e ] ↓-idf→cst-ua-in e q = ↓-idf→cst-in (ua e) (q ∙ ap (v ∘_) (λ= λ a → ! (coe-β e a))) ↓-idf→cst-in' : ∀ (p : A == B) → u ∘ coe! p == v → u == v [ (λ x → x → C) ↓ p ] ↓-idf→cst-in' idp q = q ↓-idf→cst-ua-in' : ∀ (e : A ≃ B) → u ∘ <– e == v → u == v [ (λ x → x → C) ↓ ua e ] ↓-idf→cst-ua-in' e q = ↓-idf→cst-in' (ua e) (ap (u ∘_) (λ= λ a → coe!-β e a) ∙ q) module _ {i j} {A B : Type i} {C : Type j} {u : C → A} {v : C → B} where ↓-cst→idf-in : ∀ (p : A == B) → coe p ∘ u == v → u == v [ (λ x → C → x) ↓ p ] ↓-cst→idf-in idp q = q ↓-cst→idf-ua-in : ∀ (e : A ≃ B) → –> e ∘ u == v → u == v [ (λ x → C → x) ↓ ua e ] ↓-cst→idf-ua-in e q = ↓-cst→idf-in (ua e) (ap (_∘ u) (λ= λ a → coe-β e a) ∙ q) ↓-cst→idf-in' : ∀ (p : A == B) → u == coe! p ∘ v → u == v [ (λ x → C → x) ↓ p ] ↓-cst→idf-in' idp q = q ↓-cst→idf-ua-in' : ∀ (e : A ≃ B) → u == <– e ∘ v → u == v [ (λ x → C → x) ↓ ua e ] ↓-cst→idf-ua-in' e q = ↓-cst→idf-in' (ua e) (q ∙ ap (_∘ v) (λ= λ a → ! (coe!-β e a))) -} {- Dependent paths in an arrow type -} module _ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} {x x' : A} {p : x == x'} {u : B x → C x} {u' : B x' → C x'} where ↓-→-in : ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → u t == u' t' [ C ↓ p ]) → (u == u' [ (λ x → B x → C x) ↓ p ]) ↓-→-in f = ↓-Π-in (λ q → ↓-cst2-in p q (f q)) ↓-→-out : (u == u' [ (λ x → B x → C x) ↓ p ]) → ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ]) → u t == u' t' [ C ↓ p ]) ↓-→-out r q = ↓-cst2-out p q (↓-Π-out r q) {- Transport form of dependent path in an arrow type -} module _ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} where ↓-→-from-transp : {x x' : A} {p : x == x'} {u : B x → C x} {u' : B x' → C x'} → transport C p ∘ u == u' ∘ transport B p → u == u' [ (λ x → B x → C x) ↓ p ] ↓-→-from-transp {p = idp} q = q ↓-→-to-transp : {x x' : A} {p : x == x'} {u : B x → C x} {u' : B x' → C x'} → u == u' [ (λ x → B x → C x) ↓ p ] → transport C p ∘ u == u' ∘ transport B p ↓-→-to-transp {p = idp} q = q -- Dependent paths in a Π-type where the domain is constant module _ {i j k} {A : Type i} {B : Type j} {C : A → B → Type k} where ↓-Π-cst-app-in : {x x' : A} {p : x == x'} {u : (b : B) → C x b} {u' : (b : B) → C x' b} → ((b : B) → u b == u' b [ (λ x → C x b) ↓ p ]) → (u == u' [ (λ x → (b : B) → C x b) ↓ p ]) ↓-Π-cst-app-in {p = idp} f = λ= f ↓-Π-cst-app-out : {x x' : A} {p : x == x'} {u : (b : B) → C x b} {u' : (b : B) → C x' b} → (u == u' [ (λ x → (b : B) → C x b) ↓ p ]) → ((b : B) → u b == u' b [ (λ x → C x b) ↓ p ]) ↓-Π-cst-app-out {p = idp} q = app= q split-ap2 : ∀ {i j k} {A : Type i} {B : A → Type j} {C : Type k} (f : Σ A B → C) {x y : A} (p : x == y) {u : B x} {v : B y} (q : u == v [ B ↓ p ]) → ap f (pair= p q) == ↓-app→cst-out (apd (curry f) p) q split-ap2 f idp idp = idp {- Interaction of [apd] with function composition. The basic idea is that [apd (g ∘ f) p == apd g (apd f p)] but the version here is well-typed. Note that we assume a propositional equality [r] between [apd f p] and [q]. -} apd-∘ : ∀ {i j k} {A : Type i} {B : A → Type j} {C : (a : A) → B a → Type k} (g : {a : A} → Π (B a) (C a)) (f : Π A B) {x y : A} (p : x == y) {q : f x == f y [ B ↓ p ]} (r : apd f p == q) → apd (g ∘ f) p == ↓-apd-out C r (apd↓ g q) apd-∘ g f idp idp = idp {- When [g] is nondependent, it’s much simpler -} apd-∘' : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} (g : {a : A} → B a → C a) (f : Π A B) {x y : A} (p : x == y) → apd (g ∘ f) p == ap↓ g (apd f p) apd-∘' g f idp = idp ∘'-apd : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} (g : {a : A} → B a → C a) (f : Π A B) {x y : A} (p : x == y) → ap↓ g (apd f p) == apd (g ∘ f) p ∘'-apd g f idp = idp {- And when [f] is nondependent, it’s also a bit simpler -} apd-∘'' : ∀ {i j k} {A : Type i} {B : Type j} {C : (b : B) → Type k} (g : Π B C) (f : A → B) {x y : A} (p : x == y) {q : f x == f y} (r : ap f p == q) → apd (g ∘ f) p == ↓-ap-out= C f p r (apd g q) --(apd↓ g q) apd-∘'' g f idp idp = idp {- 2-dimensional coherence conditions -} -- lhs : -- ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} {f g : Π A B} -- {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y} -- (k : (u ◃ apd g p) == (apd f p ▹ v)) -- (h : {a : A} → B a → C a) -- → ap h u ◃ apd (h ∘ g) p == ap↓ h (u ◃ apd g p) -- rhs : -- ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} {f g : Π A B} -- {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y} -- (k : (u ◃ apd g p) == (apd f p ▹ v)) -- (h : {a : A} → B a → C a) -- → ap↓ h (apd f p ▹ v) == apd (h ∘ f) p ▹ ap h v -- ap↓-↓-=-in : -- ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} {f g : Π A B} -- {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y} -- (k : (u ◃ apd g p) == (apd f p ▹ v)) -- (h : {a : A} → B a → C a) -- → ap↓ (λ {a} → ap (h {a = a})) (↓-=-in {p = p} {u = u} {v = v} k) -- == ↓-=-in (lhs {f = f} {g = g} k h ∙ ap (ap↓ (λ {a} → h {a = a})) k -- ∙ rhs {f = f} {g = g} k h) {- Commutation of [ap↓ (ap h)] and [↓-swap!]. This is "just" J, but it’s not as easy as it seems. -} -- module Ap↓-swap! {i j k ℓ} {A : Type i} {B : Type j} {C : Type k} -- {D : Type ℓ} (h : C → D) (f : A → C) (g : B → C) -- {a a' : A} {p : a == a'} {b b' : B} {q : b == b'} -- (r : f a == g b') (s : f a' == g b) -- (t : r == s ∙ ap g q [ (λ x → f x == g b') ↓ p ]) -- where -- lhs : ap h (ap f p ∙' s) == ap (h ∘ f) p ∙' ap h s -- lhs = ap-∙' h (ap f p) s ∙ (ap (λ u → u ∙' ap h s) (∘-ap h f p)) -- rhs : ap h (s ∙ ap g q) == ap h s ∙ ap (h ∘ g) q -- rhs = ap-∙ h s (ap g q) ∙ (ap (λ u → ap h s ∙ u) (∘-ap h g q)) -- β : ap↓ (ap h) (↓-swap! f g r s t) == -- lhs ◃ ↓-swap! (h ∘ f) (h ∘ g) (ap h r) (ap h s) (ap↓ (ap h) t ▹ rhs) -- β with a | a' | p | b | b' | q | r | s | t -- β | a | .a | idp | b | .b | idp | r | s | t = coh r s t where -- T : {x x' : C} (r s : x == x') (t : r == s ∙ idp) → Type _ -- T r s t = -- ap (ap h) (∙'-unit-l s ∙ ! (∙-unit-r s) ∙ ! t) == -- (ap-∙' h idp s ∙ idp) -- ∙ -- (∙'-unit-l (ap h s) ∙ -- ! (∙-unit-r (ap h s)) ∙ -- ! -- (ap (ap h) t ∙' -- (ap-∙ h s idp ∙ idp))) -- coh' : {x x' : C} {r s : x == x'} (t : r == s) → T r s (t ∙ ! (∙-unit-r s)) -- coh' {r = idp} {s = .idp} idp = idp -- coh : {x x' : C} (r s : x == x') (t : r == s ∙ idp) → T r s t -- coh r s t = transport (λ t → T r s t) (coh2 t (∙-unit-r s)) (coh' (t ∙ ∙-unit-r s)) where -- coh2 : ∀ {i} {A : Type i} {x y z : A} (p : x == y) (q : y == z) → (p ∙ q) ∙ ! q == p -- coh2 idp idp = idp -- module _ {i j k} {A : Type i} {B B' : Type j} {C : Type k} (f : A → C) (g' : B' → B) (g : B → C) where -- abc : {a a' : A} {p : a == a'} {c c' : B'} {q' : c == c'} {q : g' c == g' c'} -- (r : f a == g (g' c')) (s : f a' == g (g' c)) -- (t : q == ap g' q') -- (α : r == s ∙ ap g q [ (λ x → f x == g (g' c')) ↓ p ]) -- → {!(↓-swap! f g r s α ▹ ?) ∙'2ᵈ ?!} == ↓-swap! f (g ∘ g') {p = p} {q = q'} r s (α ▹ ap (λ u → s ∙ u) (ap (ap g) t ∙ ∘-ap g g' q')) -- abc = {!!} {- Functoriality of application and function extensionality -} ∙-app= : ∀ {i j} {A : Type i} {B : A → Type j} {f g h : Π A B} (α : f == g) (β : g == h) → α ∙ β == λ= (λ x → app= α x ∙ app= β x) ∙-app= idp β = λ=-η β ∙-λ= : ∀ {i j} {A : Type i} {B : A → Type j} {f g h : Π A B} (α : (x : A) → f x == g x) (β : (x : A) → g x == h x) → λ= α ∙ λ= β == λ= (λ x → α x ∙ β x) ∙-λ= α β = ∙-app= (λ= α) (λ= β) ∙ ap λ= (λ= (λ x → ap (λ w → w ∙ app= (λ= β) x) (app=-β α x) ∙ ap (λ w → α x ∙ w) (app=-β β x)))
35.118932
138
0.375078
2ecebf435c66043d2de2befccceaebded172fca2
1,215
agda
Agda
Cubical/ZCohomology/Base.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/ZCohomology/Base.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/ZCohomology/Base.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{-# OPTIONS --safe #-} module Cubical.ZCohomology.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Pointed.Base open import Cubical.Data.Int.Base hiding (_+_) open import Cubical.Data.Nat.Base open import Cubical.Data.Sigma open import Cubical.HITs.Nullification.Base open import Cubical.HITs.SetTruncation.Base open import Cubical.HITs.Sn.Base open import Cubical.HITs.Susp.Base open import Cubical.HITs.Truncation.Base open import Cubical.Homotopy.Loopspace private variable ℓ : Level A : Type ℓ --- Cohomology --- {- EM-spaces Kₙ from Brunerie 2016 -} coHomK : (n : ℕ) → Type₀ coHomK zero = ℤ coHomK (suc n) = ∥ S₊ (suc n) ∥ (2 + suc n) {- Cohomology -} coHom : (n : ℕ) → Type ℓ → Type ℓ coHom n A = ∥ (A → coHomK n) ∥₂ --- Reduced cohomology --- coHom-pt : (n : ℕ) → coHomK n coHom-pt 0 = 0 coHom-pt (suc n) = ∣ (ptSn (suc n)) ∣ {- Pointed version of Kₙ -} coHomK-ptd : (n : ℕ) → Pointed (ℓ-zero) coHomK-ptd n = coHomK n , coHom-pt n {- Reduced cohomology -} coHomRed : (n : ℕ) → (A : Pointed ℓ) → Type ℓ coHomRed n A = ∥ A →∙ coHomK-ptd n ∥₂ {- Kₙ, untruncated version -} coHomKType : (n : ℕ) → Type coHomKType zero = ℤ coHomKType (suc n) = S₊ (suc n)
22.924528
46
0.674074
c71e5b83fb422c69336ef8cf697fde74f7a1f7c9
1,891
agda
Agda
SOAS/Syntax/Build.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
null
null
null
SOAS/Syntax/Build.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
null
null
null
SOAS/Syntax/Build.agda
JoeyEremondi/agda-soas
ff1a985a6be9b780d3ba2beff68e902394f0a9d8
[ "MIT" ]
null
null
null
-- Helper operations to construct and build signatures module SOAS.Syntax.Build (T : Set) where open import SOAS.Common open import SOAS.Families.Build {T} open import SOAS.Context {T} open import Data.List.Base open import SOAS.Syntax.Signature T -- Syntactic sugar to construct arity - sort mappings ⟼₀_ : T → List (Ctx × T) × T ⟼₀_ τ = [] , τ _⟼₁_ : (Ctx × T) → T → List (Ctx × T) × T a ⟼₁ τ = [ a ] , τ _,_⟼₂_ : (a₁ a₂ : Ctx × T) → T → List (Ctx × T) × T a₁ , a₂ ⟼₂ τ = (a₁ ∷ [ a₂ ]) , τ _,_,_⟼₃_ : (a₁ a₂ a₃ : Ctx × T) → T → List (Ctx × T) × T a₁ , a₂ , a₃ ⟼₃ τ = (a₁ ∷ a₂ ∷ [ a₃ ]) , τ _,_,_,_⟼₄_ : (a₁ a₂ a₃ a₄ : Ctx × T) → T → List (Ctx × T) × T a₁ , a₂ , a₃ , a₄ ⟼₄ τ = (a₁ ∷ a₂ ∷ a₃ ∷ [ a₄ ]) , τ _⟼ₙ_ : List (Ctx × T) → T → List (Ctx × T) × T _⟼ₙ_ = _,_ -- Syntactic sugar to costruct arguments ⊢₀_ : T → Ctx × T ⊢₀ α = ∅ , α _⊢₁_ : T → T → Ctx × T τ ⊢₁ α = ⌊ τ ⌋ , α _,_⊢₂_ : (τ₁ τ₂ : T) → T → Ctx × T τ₁ , τ₂ ⊢₂ α = ⌊ τ₁ ∙ τ₂ ⌋ , α _,_,_⊢₃_ : (τ₁ τ₂ τ₃ : T) → T → Ctx × T τ₁ , τ₂ , τ₃ ⊢₃ α = ⌊ τ₁ ∙ τ₂ ∙ τ₃ ⌋ , α _⊢ₙ_ : Ctx → T → Ctx × T Π ⊢ₙ τ = Π , τ infix 2 ⟼₀_ infix 2 _⟼₁_ infix 2 _,_⟼₂_ infix 2 _,_,_⟼₃_ infix 2 _⟼ₙ_ infix 10 ⊢₀_ infix 10 _⊢₁_ infix 10 _,_⊢₂_ infix 10 _⊢ₙ_ -- Sum of two signatures _+ˢ_ : {O₁ O₂ : Set} → Signature O₁ → Signature O₂ → Signature (+₂ O₁ O₂) S1 +ˢ S2 = sig (₂| ∣ S1 ∣ ∣ S2 ∣) where open Signature -- Sums of signatures Σ₂ : {O₁ O₂ : Set} → Signature O₁ → Signature O₂ → Signature (+₂ O₁ O₂) Σ₂ S₁ S₂ = sig (₂| (∣ S₁ ∣) (∣ S₂ ∣)) where open Signature Σ₃ : {O₁ O₂ O₃ : Set} → Signature O₁ → Signature O₂ → Signature O₃ → Signature (+₃ O₁ O₂ O₃) Σ₃ S₁ S₂ S₃ = sig (₃| (∣ S₁ ∣) (∣ S₂ ∣) (∣ S₃ ∣)) where open Signature Σ₄ : {O₁ O₂ O₃ O₄ : Set} → Signature O₁ → Signature O₂ → Signature O₃ → Signature O₄ → Signature (+₄ O₁ O₂ O₃ O₄) Σ₄ S₁ S₂ S₃ S₄ = sig (₄| (∣ S₁ ∣) (∣ S₂ ∣) (∣ S₃ ∣) (∣ S₄ ∣)) where open Signature
24.558442
113
0.549445
9a2382e2c0157592d060a3449e53d9f8cbc12a1b
1,314
agda
Agda
test/Succeed/Issue5201.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue5201.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue5201.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.Bool open import Agda.Builtin.Equality open import Agda.Builtin.Sigma open import Agda.Primitive infixr 2 _×_ _×_ : ∀ {a b} → Set a → Set b → Set (a ⊔ b) A × B = Σ A λ _ → B ∃-notation exists-notation : ∀ {a b} {A : Set a} → (A → Set b) → Set (a ⊔ b) ∃-notation = Σ _ exists-notation = Σ _ Σ-notation : ∀ {a b} (A : Set a) → (A → Set b) → Set (a ⊔ b) Σ-notation = Σ infixr 2 ∃-notation exists-notation Σ-notation syntax ∃-notation (λ x → B) = ∃ x × B syntax exists-notation (λ x → B) = exists x × B syntax Σ-notation A (λ x → B) = [ x ∶ A ] × B _ : ∃ b × b ≡ true × Bool _ = true , refl , false _ : exists b × b ≡ true _ = true , refl _ : [ b ∶ Bool ] × b ≡ true _ = true , refl _ : [ b₁ ∶ Bool ] × [ b₂ ∶ Bool ] × b₁ ≡ b₂ _ = true , true , refl _ : [ b₁ ∶ Bool ] × ∃ b₂ × b₁ ≡ b₂ _ = true , true , refl _ : [ f ∶ (Bool → Bool) ] × f ≡ λ x → x _ = (λ x → x) , refl data List (A : Set) : Set where [] : List A cons : A → List A → List A infixr 5 cons syntax [] = [ ] syntax cons x xs = x consed to xs _ : List Bool _ = true consed to false consed to [ ] f : List Bool → Bool f [ ] = true f (true consed to [ ]) = false f (false consed to x consed to [ ]) = x f _ = true
21.9
60
0.512938
3d4d9367bfaf275be90aaf0a2eeed79a294a661c
436
agda
Agda
test/Succeed/UnquoteSetOmega.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/UnquoteSetOmega.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/UnquoteSetOmega.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
{-# OPTIONS --universe-polymorphism #-} open import Common.Prelude open import Common.Level open import Common.Reflection module UnquoteSetOmega where `Level : Term `Level = def (quote Level) [] -- building the syntax of ∀ ℓ → Set ℓ (of type Setω) is harmless `∀ℓ→Setℓ : Term `∀ℓ→Setℓ = pi (vArg `Level) (abs "_" (sort (set (var 0 [])))) -- unquoting it is now also fine (since we have sort Setω₁) ∀ℓ→Setℓ = unquote (give `∀ℓ→Setℓ)
25.647059
64
0.68578