Search is not available for this dataset
text
string | meta
dict |
---|---|
{-# OPTIONS --cubical --safe #-}
module Path where
open import Cubical.Foundations.Everything
using ( _≡_
; sym
; refl
; subst
; transport
; Path
; PathP
; I
; i0
; i1
; funExt
; cong
; toPathP
; cong₂
; ~_
; _∧_
; _∨_
; hcomp
; transp
; J
)
renaming (_∙_ to _;_; subst2 to subst₂)
public
open import Data.Empty using (¬_)
open import Level
infix 4 _≢_
_≢_ : {A : Type a} → A → A → Type a
x ≢ y = ¬ (x ≡ y)
infix 4 PathP-syntax
PathP-syntax = PathP
{-# DISPLAY PathP-syntax = PathP #-}
syntax PathP-syntax (λ i → Ty) lhs rhs = lhs ≡[ i ≔ Ty ]≡ rhs
import Agda.Builtin.Equality as MLTT
builtin-eq-to-path : {A : Type a} {x y : A} → x MLTT.≡ y → x ≡ y
builtin-eq-to-path {x = x} MLTT.refl i = x
path-to-builtin-eq : {A : Type a} {x y : A} → x ≡ y → x MLTT.≡ y
path-to-builtin-eq {x = x} x≡y = subst (x MLTT.≡_) x≡y MLTT.refl
| {
"alphanum_fraction": 0.5080160321,
"avg_line_length": 19.96,
"ext": "agda",
"hexsha": "1ac4acdfef0d29b2bad86ea26b880e15282a604b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Path.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Path.agda",
"max_line_length": 64,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Path.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 371,
"size": 998
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Fin Literals
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Fin.Literals where
open import Agda.Builtin.FromNat
open import Data.Nat using (suc; _≤?_)
open import Data.Fin using (Fin ; #_)
open import Relation.Nullary.Decidable using (True)
number : ∀ n → Number (Fin n)
number n = record
{ Constraint = λ m → True (suc m ≤? n)
; fromNat = λ m {{pr}} → (# m) {n} {pr}
}
| {
"alphanum_fraction": 0.475177305,
"avg_line_length": 26.8571428571,
"ext": "agda",
"hexsha": "54610e8d93294fe656e370b6ec1777b134923add",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Fin/Literals.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Fin/Literals.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Fin/Literals.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 133,
"size": 564
} |
------------------------------------------------------------------------
-- A theorem related to pointwise equality
------------------------------------------------------------------------
-- To simplify the development, let's work with actual natural numbers
-- as variables and constants (see
-- Atom.one-can-restrict-attention-to-χ-ℕ-atoms).
open import Atom
open import Chi χ-ℕ-atoms
open import Coding χ-ℕ-atoms
open import Free-variables χ-ℕ-atoms
import Coding.Instances.Nat
-- The results are stated and proved under the assumption that a
-- correct self-interpreter can be implemented.
module Pointwise-equality
(eval : Exp)
(cl-eval : Closed eval)
(eval-correct₁ : ∀ p v → Closed p → p ⇓ v → apply eval ⌜ p ⌝ ⇓ ⌜ v ⌝)
where
open import Equality.Propositional
open import Prelude hiding (const; Decidable)
open import Bag-equivalence equality-with-J
open import Equality.Decision-procedures equality-with-J
open import H-level.Closure equality-with-J
open import Computability χ-ℕ-atoms
open import Constants χ-ℕ-atoms
open import Reasoning χ-ℕ-atoms
open import Values χ-ℕ-atoms
open Computable-function
open χ-atoms χ-ℕ-atoms
open import Combinators hiding (id; if_then_else_)
-- Pointwise equality of computable functions to Bool.
Pointwise-equal :
∀ {a} (A : Type a) ⦃ rA : Rep A Consts ⦄ →
let F = Computable-function A Bool Bool-set in
(F × F) →Bool
Pointwise-equal _ =
as-function-to-Bool₁
(λ { (f , g) → ∀ x → function f x ≡ function g x })
-- Pointwise equality of computable functions from Bool to Bool is
-- decidable.
pointwise-equal-Bool : Decidable (Pointwise-equal Bool)
pointwise-equal-Bool =
total→almost-computable→computable
id
id
(proj₁ (Pointwise-equal Bool))
total
( pointwise-equal
, closed
, correct
)
where
F = Computable-function Bool Bool Bool-set
pointwise-equal′ : F × F → Bool
pointwise-equal′ (f , g) =
(if function f true Bool.≟ function g true then true else false)
∧
(if function f false Bool.≟ function g false then true else false)
total : Total id (proj₁ (Pointwise-equal Bool))
total p@(f , g) = result , true-lemma , false-lemma
where
result = pointwise-equal′ p
true-lemma : (∀ b → function f b ≡ function g b) → result ≡ true
true-lemma hyp
with function f true Bool.≟ function g true | hyp true
... | no f≢g | f≡g = ⊥-elim (f≢g f≡g)
... | yes _ | _
with function f false Bool.≟ function g false | hyp false
... | no f≢g | f≡g = ⊥-elim (f≢g f≡g)
... | yes _ | _ = refl
false-lemma : ¬ (∀ b → function f b ≡ function g b) → result ≡ false
false-lemma hyp
with function f true Bool.≟ function g true
| function f false Bool.≟ function g false
... | yes ft≡gt | yes ff≡gf = ⊥-elim $ hyp Prelude.[ (λ _ → ft≡gt)
, (λ _ → ff≡gf)
]
... | yes _ | no _ = refl
... | no _ | yes _ = refl
... | no _ | no _ = refl
infix 10 _at_
_at_ : Exp → Bool → Exp
f at b =
decode-Bool
(apply eval (const c-apply (f ∷ ⌜ ⌜ b ⌝ ⦂ Exp ⌝ ∷ [])))
test : Bool → Exp
test b = equal-Bool (var v-f at b) (var v-g at b)
pointwise-equal : Exp
pointwise-equal =
lambda v-p (case (var v-p) (
branch c-pair (v-f ∷ v-g ∷ [])
(and (test true) (test false)) ∷ []))
-- This proof could have been simplified if eval had been a concrete
-- implementation, rather than a variable.
closed : Closed pointwise-equal
closed =
Closed′-closed-under-lambda $
Closed′-closed-under-case
(Closed′-closed-under-var (inj₁ refl))
(λ where
(inj₁ refl) → and-closed (test-closed true) (test-closed false)
(inj₂ ()))
where
variables = v-f ∷ v-g ∷ v-p ∷ []
at-closed : ∀ f b → f ∈ variables → Closed′ variables (var f at b)
at-closed f b f∈ =
decode-Bool-closed $
Closed′-closed-under-apply
(Closed→Closed′ cl-eval)
(Closed′-closed-under-const λ where
_ (inj₁ refl) → Closed′-closed-under-var f∈
_ (inj₂ (inj₁ refl)) → Closed→Closed′ $
rep-closed (⌜ b ⌝ ⦂ Exp)
_ (inj₂ (inj₂ ())))
test-closed : ∀ b → Closed′ variables (test b)
test-closed b =
equal-Bool-closed
(at-closed v-f b (from-⊎ (V.member v-f variables)))
(at-closed v-g b (from-⊎ (V.member v-g variables)))
at-correct :
∀ (f : F) b → ⌜ f ⌝ at b ⇓ ⌜ function f b ⌝
at-correct f b = decode-Bool-correct (function f b) (
apply eval ⌜ apply (proj₁ (computable f)) ⌜ b ⌝ ⦂ Exp ⌝ ⇓⟨ eval-correct₁
(apply (proj₁ $ computable f) ⌜ b ⌝)
⌜ function f b ⌝
(Closed′-closed-under-apply
(proj₁ $ proj₂ $ computable f)
(rep-closed b))
(proj₁ (proj₂ $ proj₂ $ computable f)
b
(function f b)
(lift refl)) ⟩■
⌜ ⌜ function f b ⌝ ⦂ Exp ⌝)
test-correct :
∀ b (f g : F) →
test b [ v-g ← ⌜ g ⌝ ] [ v-f ← ⌜ f ⌝ ] ⇓
⌜ if function f b Bool.≟ function g b then true else false ⌝
test-correct b f g =
equal-Bool-correct (function f b) (function g b)
(var v-f at b [ v-g ← ⌜ g ⌝ ] [ v-f ← ⌜ f ⌝ ] ≡⟨ lemma ⌜ f ⌝ ⟩⟶
⌜ f ⌝ at b ⇓⟨ at-correct f b ⟩■
⌜ function f b ⌝)
(var v-g at b [ v-g ← ⌜ g ⌝ ] [ v-f ← ⌜ f ⌝ ] ≡⟨ lemma (⌜ g ⌝ [ v-f ← ⌜ f ⌝ ]) ⟩⟶
(⌜ g ⌝ [ v-f ← ⌜ f ⌝ ]) at b ≡⟨ cong (_at b) (subst-rep g) ⟩⟶
⌜ g ⌝ at b ⇓⟨ at-correct g b ⟩■
⌜ function g b ⌝)
where
ss = (v-f , ⌜ f ⌝) ∷ (v-g , ⌜ g ⌝) ∷ []
lemma : ∀ _ → _
lemma = λ e →
cong₂ (λ e₁ e₂ → decode-Bool (apply e₁ (const _ (e ∷ e₂ ∷ []))))
(substs-closed eval cl-eval ss)
(substs-rep (⌜ b ⌝ ⦂ Exp) ss)
correct :
∀ p b →
proj₁ (Pointwise-equal Bool) [ p ]= b →
apply pointwise-equal ⌜ p ⌝ ⇓ ⌜ b ⌝
correct p@(f , g) b [p]=b =
apply pointwise-equal ⌜ p ⌝ ⟶⟨ apply lambda (rep⇓rep p) ⟩
case ⌜ p ⌝ (
branch c-pair (v-f ∷ v-g ∷ [])
(and (test true) (test false) [ v-p ← ⌜ p ⌝ ]) ∷ []) ≡⟨ cong₂ (λ e₁ e₂ → case ⌜ p ⌝ (branch c-pair (v-f ∷ v-g ∷ []) (and e₁ e₂) ∷ []))
(test-lemma true)
(test-lemma false) ⟩⟶
case ⌜ p ⌝ (
branch c-pair (v-f ∷ v-g ∷ [])
(and (test true) (test false)) ∷ []) ⟶⟨ case (rep⇓rep p) here (∷ ∷ []) ⟩
and (test true [ v-g ← ⌜ g ⌝ ] [ v-f ← ⌜ f ⌝ ])
(test false [ v-g ← ⌜ g ⌝ ] [ v-f ← ⌜ f ⌝ ]) ⇓⟨ and-correct (if function f true Bool.≟ function g true then true else false)
(if function f false Bool.≟ function g false then true else false)
(test-correct true f g) (test-correct false f g) ⟩
⌜ pointwise-equal′ p ⌝ ≡⟨ cong ⌜_⌝ (_⇀_.deterministic (proj₁ (Pointwise-equal Bool)) {a = p}
(proj₂ (total p)) [p]=b) ⟩⟶
⌜ b ⌝ ■⟨ rep-value b ⟩
where
at-lemma :
∀ b f → v-p ≢ f → var f at b [ v-p ← ⌜ p ⌝ ] ≡ var f at b
at-lemma b f p≢f =
var f at b [ v-p ← ⌜ p ⌝ ] ≡⟨⟩
decode-Bool (apply (eval [ v-p ← ⌜ p ⌝ ]) (const c-apply
(var f [ v-p ← ⌜ p ⌝ ] ∷ ⌜ ⌜ b ⌝ ⦂ Exp ⌝ [ v-p ← ⌜ p ⌝ ] ∷ []))) ≡⟨ cong (λ e → decode-Bool (apply e (const _
(var f [ v-p ← ⌜ p ⌝ ] ∷
⌜ ⌜ b ⌝ ⦂ Exp ⌝ [ v-p ← ⌜ p ⌝ ] ∷ []))))
(subst-closed v-p ⌜ p ⌝ cl-eval) ⟩
decode-Bool (apply eval (const c-apply
(var f [ v-p ← ⌜ p ⌝ ] ∷ ⌜ ⌜ b ⌝ ⦂ Exp ⌝ [ v-p ← ⌜ p ⌝ ] ∷ []))) ≡⟨ cong (λ e → decode-Bool (apply _ (const _ (e ∷ _))))
(subst-∉ v-p (var f) λ { (var p≡f) → p≢f p≡f }) ⟩
decode-Bool (apply eval (const c-apply
(var f ∷ ⌜ ⌜ b ⌝ ⦂ Exp ⌝ [ v-p ← ⌜ p ⌝ ] ∷ []))) ≡⟨ cong (λ e → decode-Bool (apply _ (const _ (_ ∷ e ∷ _))))
(subst-rep (⌜ b ⌝ ⦂ Exp)) ⟩
decode-Bool (apply eval (const c-apply
(var f ∷ ⌜ ⌜ b ⌝ ⦂ Exp ⌝ ∷ []))) ≡⟨⟩
var f at b ∎
test-lemma : ∀ b → test b [ v-p ← ⌜ p ⌝ ] ≡ test b
test-lemma b =
cong₂ equal-Bool (at-lemma b v-f (λ ())) (at-lemma b v-g (λ ()))
| {
"alphanum_fraction": 0.4324130145,
"avg_line_length": 40.9369747899,
"ext": "agda",
"hexsha": "800b6e985426d05b67b94133e396cfe25ca268b0",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/chi",
"max_forks_repo_path": "src/Pointwise-equality.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_issues_repo_issues_event_max_datetime": "2020-06-08T11:08:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-05-21T23:29:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/chi",
"max_issues_repo_path": "src/Pointwise-equality.agda",
"max_line_length": 143,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/chi",
"max_stars_repo_path": "src/Pointwise-equality.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-20T16:27:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:07.000Z",
"num_tokens": 3084,
"size": 9743
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Machine words
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Word where
------------------------------------------------------------------------
-- Re-export built-ins publically
open import Agda.Builtin.Word public
using (Word64)
renaming
( primWord64ToNat to toℕ
; primWord64FromNat to fromℕ
)
| {
"alphanum_fraction": 0.3894523327,
"avg_line_length": 24.65,
"ext": "agda",
"hexsha": "afaa266ec689f8d74495889bfbc86b87fc78c791",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Word.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Word.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Word.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 84,
"size": 493
} |
module examplesPaperJFP.SpaceShipCell where
open import SizedIO.Base
open import StateSizedIO.GUI.BaseStateDependent
open import Data.Bool.Base
open import Data.List.Base
open import Data.Integer
open import Data.Product hiding (map)
open import SizedIO.Object
open import SizedIO.IOObject
open import NativeIO
open import Sized.SimpleCell hiding (main; program)
open import StateSizedIO.GUI.WxBindingsFFI
open import StateSizedIO.GUI.VariableList
open import StateSizedIO.GUI.WxGraphicsLib
open import StateSized.GUI.BitMaps
VarType = Object (cellJ ℤ)
cellℤC : (z : ℤ ) → VarType
objectMethod (cellℤC z) get = ( z , cellℤC z )
objectMethod (cellℤC z) (put z′) = ( unit , cellℤC z′ )
varInit : VarType
varInit = cellℤC (+ 150)
onPaint : ∀{i} → VarType → DC → Rect → IO GuiLev1Interface i VarType
onPaint c dc rect =
let (z , c₁) = objectMethod c get in
exec (drawBitmap dc ship (z , (+ 150)) true) λ _ →
return c₁
moveSpaceShip : ∀{i} → Frame → VarType
→ IO GuiLev1Interface i VarType
moveSpaceShip fra c =
let (z , c₁) = objectMethod c get
(_ , c₂) = objectMethod c₁ (put (z + (+ 20)))
in return c₂
callRepaint : ∀{i} → Frame → VarType → IO GuiLev1Interface i VarType
callRepaint fra c = exec (repaint fra) λ _ → return c
program : ∀{i} → IOˢ GuiLev2Interface i (λ _ → Unit) []
program = execˢ (level1C makeFrame) λ fra →
execˢ (level1C (makeButton fra)) λ bt →
execˢ (level1C (addButton fra bt)) λ _ →
execˢ (createVar varInit) λ _ →
execˢ (setButtonHandler bt (moveSpaceShip fra
∷ [ callRepaint fra ])) λ _ →
execˢ (setOnPaint fra [ onPaint ])
returnˢ
main : NativeIO Unit
main = start (translateLev2 program)
| {
"alphanum_fraction": 0.6404736276,
"avg_line_length": 26.1690140845,
"ext": "agda",
"hexsha": "f938ec9f162c840fc75238059ba7d2487199839c",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z",
"max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/ooAgda",
"max_forks_repo_path": "examples/examplesPaperJFP/SpaceShipCell.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/ooAgda",
"max_issues_repo_path": "examples/examplesPaperJFP/SpaceShipCell.agda",
"max_line_length": 71,
"max_stars_count": 23,
"max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/ooAgda",
"max_stars_repo_path": "examples/examplesPaperJFP/SpaceShipCell.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z",
"num_tokens": 586,
"size": 1858
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of interleaving using setoid equality
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary using (Setoid)
module Data.List.Relation.Ternary.Interleaving.Setoid.Properties
{c ℓ} (S : Setoid c ℓ) where
open import Data.List.Base using (List; []; _∷_; filter; _++_)
open import Relation.Unary using (Decidable)
open import Relation.Nullary using (yes; no)
open import Relation.Nullary.Negation using (¬?)
open import Function
open import Data.List.Relation.Binary.Equality.Setoid S using (≋-refl)
open import Data.List.Relation.Ternary.Interleaving.Setoid S
open Setoid S renaming (Carrier to A)
------------------------------------------------------------------------
-- Re-exporting existing properties
open import Data.List.Relation.Ternary.Interleaving.Properties public
------------------------------------------------------------------------
-- _++_
++-linear : (xs ys : List A) → Interleaving xs ys (xs ++ ys)
++-linear xs ys = ++-disjoint (left ≋-refl) (right ≋-refl)
------------------------------------------------------------------------
-- filter
module _ {p} {P : A → Set p} (P? : Decidable P) where
filter⁺ : ∀ xs → Interleaving (filter P? xs) (filter (¬? ∘ P?) xs) xs
filter⁺ [] = []
filter⁺ (x ∷ xs) with P? x
... | yes px = refl ∷ˡ filter⁺ xs
... | no ¬px = refl ∷ʳ filter⁺ xs
| {
"alphanum_fraction": 0.520026264,
"avg_line_length": 33.8444444444,
"ext": "agda",
"hexsha": "316a4a2fcebff50d380e70126b55aa760e97667e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Ternary/Interleaving/Setoid/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Ternary/Interleaving/Setoid/Properties.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Ternary/Interleaving/Setoid/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 365,
"size": 1523
} |
module Algebra.Linear.Category.Vect where
| {
"alphanum_fraction": 0.8571428571,
"avg_line_length": 21,
"ext": "agda",
"hexsha": "933978e9997bf13d1d9229484be92d0f5c87afb5",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "felko/linear-algebra",
"max_forks_repo_path": "src/Algebra/Linear/Morphism/Structures/Vect.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "felko/linear-algebra",
"max_issues_repo_path": "src/Algebra/Linear/Morphism/Structures/Vect.agda",
"max_line_length": 41,
"max_stars_count": 15,
"max_stars_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "felko/linear-algebra",
"max_stars_repo_path": "src/Algebra/Linear/Morphism/Structures/Vect.agda",
"max_stars_repo_stars_event_max_datetime": "2020-12-30T06:18:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-02T14:11:00.000Z",
"num_tokens": 8,
"size": 42
} |
module Issue309a where
data D : Set where
d : D → D
syntax d x x = e x
g : D → D
g (d x) = e x
| {
"alphanum_fraction": 0.55,
"avg_line_length": 10,
"ext": "agda",
"hexsha": "87719375746c3eb1310dfcc2e070007f3ad07430",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue309a.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue309a.agda",
"max_line_length": 22,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue309a.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 42,
"size": 100
} |
{-# OPTIONS --rewriting #-}
data _≡_ {ℓ} {A : Set ℓ} (x : A) : A → Set ℓ where
instance refl : x ≡ x
{-# BUILTIN REWRITE _≡_ #-}
postulate
admit : ∀ {ℓ} {A : Set ℓ} → A
X : Set
postulate
Wrap : Set → Set
wrap : {A : Set} → A → Wrap A
rec : (A : Set) (P : Set) → (A → P) → Wrap A → P
Rec : (A : Set) (P : Set₁) → (A → P) → Wrap A → P
Rec-β : {A : Set} (P : Set₁) → ∀ f → (a : A) → Rec A P f (wrap a) ≡ f a
{-# REWRITE Rec-β #-} -- bug disappears without this
record Σ {ℓ} (A : Set ℓ) (B : A → Set) : Set ℓ where
constructor _,_
field
fst : A
snd : B fst
open Σ public
-- bug disappears if Comp or isFib is not wrapped in a record
record Comp (A : X → Set) : Set where
field
comp : ∀ s → A s
open Comp public
record isFib {Γ : Set} (A : Γ → Set) : Set where
field
lift : (p : X → Γ) → Comp (λ x → A (p x))
open isFib public
compSys : (ψ : X → Set)
(A : Σ X (λ x → Wrap (ψ x)) → Set)
(u : ∀ s → Wrap (ψ s)) (s : X)
→ A (s , u s)
compSys ψ A u s =
rec (∀ i → ψ i) (A (s , u s))
(λ v →
subst (λ s → wrap (v s)) (λ s → u s) admit
.lift (λ s → s) .comp s)
admit
where
subst : (w w' : ∀ i → Wrap (ψ i)) → isFib (λ s → A (s , w s)) → isFib (λ s → A (s , w' s))
subst = admit
-- bug disappears if ×id is inlined
×id : {A A' : Set} {B : A' → Set} (f : A → A') → Σ A (λ x → B (f x)) → Σ A' B
×id f (a , b) = (f a , b)
fib : (ψ : X → Set) (A : Σ X (λ x → Wrap (ψ x)) → Set) → isFib A
fib ψ A .lift p .comp =
compSys (λ x → ψ (p x .fst)) (λ xu → A (×id (λ x → p x .fst) xu)) (λ x → p x .snd)
-- bug seems to disappear if the underscore in (Σ Set _) is filled in
template : (ψ : X → Set) → X → Σ (Σ X (λ x → Wrap (ψ x)) → Set) isFib
template ψ n =
(_ , fib ψ (λ b → Rec (ψ (b .fst)) (Σ Set _) (λ _ → admit) (b .snd) .fst))
eq : {B : Set₁} (f : X → B) {x y : X} → f x ≡ f y
eq = admit
templateEq : (ψ : X → Set) (n₀ : X) → template ψ n₀ ≡ template ψ n₀
templateEq ψ n₀ = eq (template ψ)
| {
"alphanum_fraction": 0.489102889,
"avg_line_length": 24.9746835443,
"ext": "agda",
"hexsha": "347582945ec4c8a4e04be35bc1616f68153d8f57",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue3882.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue3882.agda",
"max_line_length": 92,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue3882.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 870,
"size": 1973
} |
module Builtin.Size where
open import Agda.Builtin.Size public
| {
"alphanum_fraction": 0.8153846154,
"avg_line_length": 13,
"ext": "agda",
"hexsha": "821594da1a1419d11dbb2b64edd98e79ba8c5509",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "L-TChen/agda-prelude",
"max_forks_repo_path": "src/Builtin/Size.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "L-TChen/agda-prelude",
"max_issues_repo_path": "src/Builtin/Size.agda",
"max_line_length": 36,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "L-TChen/agda-prelude",
"max_stars_repo_path": "src/Builtin/Size.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 16,
"size": 65
} |
{-# OPTIONS --without-K #-}
open import HoTT.Base
open import HoTT.Equivalence
module HoTT.Identity.Boolean where
private
variable
x y : 𝟐
_=𝟐_ : 𝟐 → 𝟐 → 𝒰₀
0₂ =𝟐 0₂ = 𝟏
0₂ =𝟐 1₂ = 𝟎
1₂ =𝟐 0₂ = 𝟎
1₂ =𝟐 1₂ = 𝟏
=𝟐-equiv : x == y ≃ x =𝟐 y
=𝟐-equiv = f , qinv→isequiv (g , η , ε)
where
f : x == y → x =𝟐 y
f {0₂} p = transport (0₂ =𝟐_) p ★
f {1₂} p = transport (1₂ =𝟐_) p ★
g : x =𝟐 y → x == y
g {0₂} {0₂} _ = refl
g {0₂} {1₂} ()
g {1₂} {0₂} ()
g {1₂} {1₂} _ = refl
η : g ∘ f {x} {y} ~ id
η {0₂} refl = refl
η {1₂} refl = refl
ε : f ∘ g {x} {y} ~ id
ε {0₂} {0₂} ★ = refl
ε {0₂} {1₂} ()
ε {1₂} {0₂} ()
ε {1₂} {1₂} ★ = refl
| {
"alphanum_fraction": 0.4773413897,
"avg_line_length": 18.3888888889,
"ext": "agda",
"hexsha": "c1b33165fa0f2997ce6f04e4f71d5e915b02cd56",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "michaelforney/hott",
"max_forks_repo_path": "HoTT/Identity/Boolean.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "michaelforney/hott",
"max_issues_repo_path": "HoTT/Identity/Boolean.agda",
"max_line_length": 39,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "michaelforney/hott",
"max_stars_repo_path": "HoTT/Identity/Boolean.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 387,
"size": 662
} |
open import Categories.Category
open import Categories.Category.CartesianClosed
open import Theory
module Categories.Category.Construction.Models
{ℓ₁ ℓ₂ ℓ₃}
(Th : Theory.Theory ℓ₁ ℓ₂ ℓ₃)
{o ℓ e}
(𝒞 : Category o ℓ e)
(cartesianClosed : CartesianClosed 𝒞)
where
open import Categories.Category.Cartesian 𝒞
open import Categories.Category.BinaryProducts 𝒞
open import Categories.Object.Terminal 𝒞
import Categories.Object.Product 𝒞 as P
open import Categories.Morphism 𝒞
open import Categories.Functor.Construction.Product using (Product)
open import Categories.Functor.Construction.Exponential using (Exp)
open import Categories.Functor.Properties using ([_]-resp-≅)
open Category 𝒞
open CartesianClosed cartesianClosed
open Cartesian cartesian
open BinaryProducts products
module T = Terminal terminal
open HomReasoning
open import Categories.Morphism.Reasoning 𝒞
open import Syntax
open Theory.Theory Th
open import Semantics 𝒞 cartesianClosed Sg
open Signature Sg
open import Data.Product using (Σ; Σ-syntax; proj₁; proj₂; _,_)
open import Relation.Binary using (Rel; IsEquivalence)
open import Level using (_⊔_)
⁂-id : forall {A B} -> id {A = A} ⁂ id {A = B} ≈ id
⁂-id = Equiv.trans (⟨⟩-cong₂ identityˡ identityˡ) η
module Homomorphism {M N : Model 𝒞 cartesianClosed Th}
(h : (g : Gr) -> ⟦ g ⟧G (proj₁ M) ≅ ⟦ g ⟧G (proj₁ N))
where
open _≅_
open Iso
H : (A : Type) -> ⟦ A ⟧T (proj₁ M) ≅ ⟦ A ⟧T (proj₁ N)
H ⌊ g ⌋ = h g
H Unit = up-to-iso terminal terminal
H (A * A₁) = [ Product 𝒞 cartesian ]-resp-≅
(record
{ from = from (H A) , from (H A₁)
; to = to (H A) , to (H A₁)
; iso = record { isoˡ = isoˡ (iso (H A)) , isoˡ (iso (H A₁)) ; isoʳ = isoʳ (iso (H A)) , isoʳ (iso (H A₁)) }
})
H (A => A₁) = [ Exp 𝒞 cartesianClosed ]-resp-≅
(record
{ from = from (H A₁) , to (H A)
; to = to (H A₁) , from (H A)
; iso = record { isoˡ = isoˡ (iso (H A₁)) , isoˡ (iso (H A)) ; isoʳ = isoʳ (iso (H A₁)) , isoʳ (iso (H A)) }
})
record homomorphism (M N : Model 𝒞 cartesianClosed Th) : Set (ℓ₁ ⊔ ℓ₂ ⊔ ℓ ⊔ e) where
field
h : (g : Gr) -> ⟦ g ⟧G (proj₁ M) ≅ ⟦ g ⟧G (proj₁ N)
open Homomorphism {M} {N} h public
field
comm : (f : Func) -> _≅_.from (H (cod f)) ∘ ⟦ f ⟧F (proj₁ M) ≈ ⟦ f ⟧F (proj₁ N) ∘ _≅_.from (H (dom f))
module _ {M N : Model 𝒞 cartesianClosed Th} where
_≗_ : Rel (homomorphism M N) (ℓ₁ ⊔ e)
_≗_ x y = (g : Gr) -> _≅_.from (homomorphism.h x g) ≈ _≅_.from (homomorphism.h y g)
module Id {M : Model 𝒞 cartesianClosed Th} where
open Homomorphism {M} {M} (λ _ → IsEquivalence.refl ≅-isEquivalence)
open Structure (proj₁ M)
-- The components of the homomorphism generated by identity morphisms are also identities.
H-id : forall A -> _≅_.from (H A) ≈ Category.id 𝒞
H-id˘ : forall A -> _≅_.to (H A) ≈ Category.id 𝒞
H-id ⌊ x ⌋ = Equiv.refl
H-id Unit = T.!-unique (Category.id 𝒞)
H-id (A * A₁) =
begin
_≅_.from (H A) ⁂ _≅_.from (H A₁)
≈⟨ ⁂-cong₂ (H-id A) (H-id A₁) ⟩
Category.id 𝒞 ⁂ Category.id 𝒞
≈⟨ ⟨⟩-cong₂ identityˡ identityˡ ⟩
⟨ π₁ , π₂ ⟩
≈⟨ η ⟩
Category.id 𝒞
∎
H-id (A => A₁) =
begin
λg (_≅_.from (H A₁) ∘ eval′ ∘ (id ⁂ _≅_.to (H A)))
≈⟨ λ-cong (∘-resp-≈ˡ (H-id A₁)) ⟩
λg (id ∘ eval′ ∘ (id ⁂ _≅_.to (H A)))
≈⟨ λ-cong (pullˡ identityˡ) ⟩
λg (eval′ ∘ (id ⁂ _≅_.to (H A)))
≈⟨ λ-cong (∘-resp-≈ʳ (⁂-cong₂ Equiv.refl (H-id˘ A))) ⟩
λg (eval′ ∘ (id ⁂ id))
≈⟨ λ-cong (elimʳ ⁂-id) ⟩
λg eval′
≈⟨ η-id′ ⟩
id
∎
H-id˘ ⌊ x ⌋ = Equiv.refl
H-id˘ Unit = T.!-unique id
H-id˘ (A * A₁) =
begin
_≅_.to (H A) ⁂ _≅_.to (H A₁)
≈⟨ ⁂-cong₂ (H-id˘ A) (H-id˘ A₁) ⟩
id ⁂ id
≈⟨ ⁂-id ⟩
id
∎
H-id˘ (A => A₁) =
begin
λg (_≅_.to (H A₁) ∘ eval′ ∘ (id ⁂ _≅_.from (H A)))
≈⟨ λ-cong (elimˡ (H-id˘ A₁)) ⟩
λg (eval′ ∘ (id ⁂ _≅_.from (H A)))
≈⟨ λ-cong (∘-resp-≈ʳ (⁂-cong₂ Equiv.refl (H-id A))) ⟩
λg (eval′ ∘ (id ⁂ id))
≈⟨ λ-cong (elimʳ ⁂-id) ⟩
λg eval′
≈⟨ η-id′ ⟩
id
∎
comm : (f : Func) -> _≅_.from (H (cod f)) ∘ ⟦ f ⟧F ≈ ⟦ f ⟧F ∘ _≅_.from (H (dom f))
comm f =
begin
_≅_.from (H (cod f)) ∘ ⟦ f ⟧F
≈⟨ elimˡ (H-id (cod f)) ⟩
⟦ f ⟧F
≈˘⟨ elimʳ (H-id (dom f)) ⟩
⟦ f ⟧F ∘ _≅_.from (H (dom f))
∎
id′ : homomorphism M M
id′ = record { h = λ _ → IsEquivalence.refl ≅-isEquivalence ; comm = comm }
module Compose {M N O : Model 𝒞 cartesianClosed Th} where
open _≅_
compose : homomorphism N O -> homomorphism M N -> homomorphism M O
compose x y = record
{ h = h
; comm = λ f →
begin
from (MO.H (cod f)) ∘ ⟦ f ⟧F (proj₁ M)
≈⟨ pushˡ (H-compose (cod f)) ⟩
from (NO.H (cod f)) ∘ from (MN.H (cod f)) ∘ ⟦ f ⟧F (proj₁ M)
≈⟨ ∘-resp-≈ʳ (MN.comm f) ⟩
from (NO.H (cod f)) ∘ ⟦ f ⟧F (proj₁ N) ∘ from (MN.H (dom f))
≈⟨ pullˡ (NO.comm f) ⟩
(⟦ f ⟧F (proj₁ O) ∘ from (NO.H (dom f))) ∘ from (MN.H (dom f))
≈˘⟨ pushʳ (H-compose (dom f)) ⟩
⟦ f ⟧F (proj₁ O) ∘ from (MO.H (dom f))
∎
}
where
h = λ g → IsEquivalence.trans ≅-isEquivalence (homomorphism.h y g) (homomorphism.h x g)
module MO = Homomorphism h
module MN = homomorphism y
module NO = homomorphism x
H-compose : forall A -> from (MO.H A) ≈ from (NO.H A) ∘ from (MN.H A)
H-compose˘ : forall A -> to (MO.H A) ≈ to (MN.H A) ∘ to (NO.H A)
H-compose ⌊ x ⌋ = Equiv.refl
H-compose Unit = T.!-unique₂
H-compose (A * A₁) = Equiv.trans (⁂-cong₂ (H-compose A) (H-compose A₁)) (Equiv.sym ⁂∘⁂)
H-compose (A => A₁) =
begin
λg (from (MO.H A₁) ∘ eval′ ∘ (id ⁂ to (MO.H A)))
≈⟨ λ-cong (∘-resp-≈ˡ (H-compose A₁)) ⟩
λg ((from (NO.H A₁) ∘ from (MN.H A₁)) ∘ eval′ ∘ (id ⁂ to (MO.H A)))
≈⟨ λ-cong assoc ⟩
λg (from (NO.H A₁) ∘ from (MN.H A₁) ∘ eval′ ∘ (id ⁂ to (MO.H A)))
≈⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ (∘-resp-≈ʳ (⁂-cong₂ Equiv.refl (H-compose˘ A))))) ⟩
λg (from (NO.H A₁) ∘ from (MN.H A₁) ∘ eval′ ∘ (id ⁂ to (MN.H A) ∘ to (NO.H A)))
≈˘⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ (∘-resp-≈ʳ second∘second))) ⟩
λg (from (NO.H A₁) ∘ from (MN.H A₁) ∘ eval′ ∘ (id ⁂ to (MN.H A)) ∘ (id ⁂ to (NO.H A)))
≈˘⟨ λ-cong (∘-resp-≈ʳ assoc²') ⟩
λg (from (NO.H A₁) ∘ (from (MN.H A₁) ∘ eval′ ∘ (id ⁂ to (MN.H A))) ∘ (id ⁂ to (NO.H A)))
≈˘⟨ λ-cong (∘-resp-≈ʳ (pullˡ β′)) ⟩
λg (from (NO.H A₁) ∘ eval′ ∘ (λg (from (MN.H A₁) ∘ eval′ ∘ (id ⁂ to (MN.H A))) ⁂ id) ∘ (id ⁂ to (NO.H A)))
≈⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ ⁂∘⁂)) ⟩
λg (from (NO.H A₁) ∘ eval′ ∘ (λg (from (MN.H A₁) ∘ eval′ ∘ (id ⁂ to (MN.H A))) ∘ id ⁂ id ∘ to (NO.H A)))
≈⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ (⁂-cong₂ identityʳ identityˡ))) ⟩
λg (from (NO.H A₁) ∘ eval′ ∘ (λg (from (MN.H A₁) ∘ eval′ ∘ (id ⁂ to (MN.H A))) ⁂ to (NO.H A)))
≈˘⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ (⁂-cong₂ identityˡ identityʳ))) ⟩
λg (from (NO.H A₁) ∘ eval′ ∘ (id ∘ λg (from (MN.H A₁) ∘ eval′ ∘ (id ⁂ to (MN.H A))) ⁂ to (NO.H A) ∘ id))
≈˘⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ ⁂∘⁂)) ⟩
λg (from (NO.H A₁) ∘ eval′ ∘ (id ⁂ to (NO.H A)) ∘ (λg (from (MN.H A₁) ∘ eval′ ∘ (id ⁂ to (MN.H A))) ⁂ id))
≈˘⟨ λ-cong assoc²' ⟩
λg ((from (NO.H A₁) ∘ eval′ ∘ (id ⁂ to (NO.H A))) ∘ (λg (from (MN.H A₁) ∘ eval′ ∘ (id ⁂ to (MN.H A))) ⁂ id))
≈˘⟨ CartesianClosed.exp.subst cartesianClosed product product ⟩
λg (from (NO.H A₁) ∘ eval′ ∘ (id ⁂ to (NO.H A))) ∘ λg (from (MN.H A₁) ∘ eval′ ∘ (id ⁂ to (MN.H A)))
≈⟨ Equiv.refl ⟩
from (NO.H (A => A₁)) ∘ from (MN.H (A => A₁))
∎
H-compose˘ ⌊ x ⌋ = Equiv.refl
H-compose˘ Unit = T.!-unique₂
H-compose˘ (A * A₁) = Equiv.trans (⁂-cong₂ (H-compose˘ A) (H-compose˘ A₁)) (Equiv.sym ⁂∘⁂)
H-compose˘ (A => A₁) =
begin
λg (to (MO.H A₁) ∘ eval′ ∘ (id ⁂ from (MO.H A)))
≈⟨ λ-cong (∘-resp-≈ˡ (H-compose˘ A₁)) ⟩
λg ((to (MN.H A₁) ∘ to (NO.H A₁)) ∘ eval′ ∘ (id ⁂ from (MO.H A)))
≈⟨ λ-cong assoc ⟩
λg (to (MN.H A₁) ∘ to (NO.H A₁) ∘ eval′ ∘ (id ⁂ from (MO.H A)))
≈⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ (∘-resp-≈ʳ (⁂-cong₂ Equiv.refl (H-compose A))))) ⟩
λg (to (MN.H A₁) ∘ to (NO.H A₁) ∘ eval′ ∘ (id ⁂ from (NO.H A) ∘ from (MN.H A)))
≈˘⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ (∘-resp-≈ʳ second∘second))) ⟩
λg (to (MN.H A₁) ∘ to (NO.H A₁) ∘ eval′ ∘ (id ⁂ from (NO.H A)) ∘ (id ⁂ from (MN.H A)))
≈˘⟨ λ-cong (∘-resp-≈ʳ assoc²') ⟩
λg (to (MN.H A₁) ∘ (to (NO.H A₁) ∘ eval′ ∘ (id ⁂ from (NO.H A))) ∘ (id ⁂ from (MN.H A)))
≈˘⟨ λ-cong (∘-resp-≈ʳ (pullˡ β′)) ⟩
λg (to (MN.H A₁) ∘ eval′ ∘ (λg (to (NO.H A₁) ∘ eval′ ∘ (id ⁂ from (NO.H A))) ⁂ id) ∘ (id ⁂ from (MN.H A)))
≈⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ ⁂∘⁂)) ⟩
λg (to (MN.H A₁) ∘ eval′ ∘ (λg (to (NO.H A₁) ∘ eval′ ∘ (id ⁂ from (NO.H A))) ∘ id ⁂ id ∘ from (MN.H A)))
≈⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ (⁂-cong₂ identityʳ identityˡ))) ⟩
λg (to (MN.H A₁) ∘ eval′ ∘ (λg (to (NO.H A₁) ∘ eval′ ∘ (id ⁂ from (NO.H A))) ⁂ from (MN.H A)))
≈˘⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ (⁂-cong₂ identityˡ identityʳ))) ⟩
λg (to (MN.H A₁) ∘ eval′ ∘ (id ∘ λg (to (NO.H A₁) ∘ eval′ ∘ (id ⁂ from (NO.H A))) ⁂ from (MN.H A) ∘ id))
≈˘⟨ λ-cong (∘-resp-≈ʳ (∘-resp-≈ʳ ⁂∘⁂)) ⟩
λg (to (MN.H A₁) ∘ eval′ ∘ (id ⁂ from (MN.H A)) ∘ (λg (to (NO.H A₁) ∘ eval′ ∘ (id ⁂ from (NO.H A))) ⁂ id))
≈˘⟨ λ-cong assoc²' ⟩
λg ((to (MN.H A₁) ∘ eval′ ∘ (id ⁂ from (MN.H A))) ∘ (λg (to (NO.H A₁) ∘ eval′ ∘ (id ⁂ from (NO.H A))) ⁂ id))
≈˘⟨ CartesianClosed.exp.subst cartesianClosed product product ⟩
λg (to (MN.H A₁) ∘ eval′ ∘ (id ⁂ from (MN.H A))) ∘ λg (to (NO.H A₁) ∘ eval′ ∘ (id ⁂ from (NO.H A)))
≈⟨ Equiv.refl ⟩
to (MN.H (A => A₁)) ∘ to (NO.H (A => A₁))
∎
Models : Category (ℓ₁ ⊔ ℓ₂ ⊔ ℓ₃ ⊔ o ⊔ ℓ ⊔ e) (ℓ₁ ⊔ ℓ₂ ⊔ ℓ ⊔ e) (ℓ₁ ⊔ e)
Models = record
{ Obj = Model 𝒞 cartesianClosed Th
; _⇒_ = homomorphism
; _≈_ = _≗_
; id = Id.id′
; _∘_ = Compose.compose
; assoc = λ _ → assoc
; sym-assoc = λ _ → sym-assoc
; identityˡ = λ _ → identityˡ
; identityʳ = λ _ → identityʳ
; identity² = λ _ → identity²
; equiv = record { refl = λ _ → IsEquivalence.refl equiv ; sym = λ x g → IsEquivalence.sym equiv (x g) ; trans = λ x x₁ g → IsEquivalence.trans equiv (x g) (x₁ g) }
; ∘-resp-≈ = λ x x₁ g → ∘-resp-≈ (x g) (x₁ g)
}
| {
"alphanum_fraction": 0.4759036145,
"avg_line_length": 42.4503816794,
"ext": "agda",
"hexsha": "66a4425c53c4dd5895f1a908ecfe0e1d900b44e4",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "elpinal/exsub-ccc",
"max_forks_repo_path": "Categories/Category/Construction/Models.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "elpinal/exsub-ccc",
"max_issues_repo_path": "Categories/Category/Construction/Models.agda",
"max_line_length": 177,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "elpinal/exsub-ccc",
"max_stars_repo_path": "Categories/Category/Construction/Models.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T13:30:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-05T06:16:32.000Z",
"num_tokens": 5000,
"size": 11122
} |
-- It is recommended to use Cubical.Algebra.CommRing.Instances.Int
-- instead of this file.
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommRing.Instances.BiInvInt where
open import Cubical.Foundations.Prelude
open import Cubical.Algebra.CommRing
open import Cubical.Data.Int.MoreInts.BiInvInt
renaming (
_+_ to _+ℤ_;
-_ to _-ℤ_;
+-assoc to +ℤ-assoc;
+-comm to +ℤ-comm
)
BiInvℤAsCommRing : CommRing ℓ-zero
BiInvℤAsCommRing =
makeCommRing
zero (suc zero) _+ℤ_ _·_ _-ℤ_
isSetBiInvℤ
+ℤ-assoc +-zero +-invʳ +ℤ-comm
·-assoc ·-identityʳ
(λ x y z → sym (·-distribˡ x y z))
·-comm
| {
"alphanum_fraction": 0.6816,
"avg_line_length": 23.1481481481,
"ext": "agda",
"hexsha": "4db605e7a49696e44e77fee9258f806a495a14b4",
"lang": "Agda",
"max_forks_count": 134,
"max_forks_repo_forks_event_max_datetime": "2022-03-23T16:22:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-11-16T06:11:03.000Z",
"max_forks_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "marcinjangrzybowski/cubical",
"max_forks_repo_path": "Cubical/Algebra/CommRing/Instances/BiInvInt.agda",
"max_issues_count": 584,
"max_issues_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_issues_repo_issues_event_max_datetime": "2022-03-30T12:09:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-10-15T09:49:02.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "marcinjangrzybowski/cubical",
"max_issues_repo_path": "Cubical/Algebra/CommRing/Instances/BiInvInt.agda",
"max_line_length": 66,
"max_stars_count": 301,
"max_stars_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "marcinjangrzybowski/cubical",
"max_stars_repo_path": "Cubical/Algebra/CommRing/Instances/BiInvInt.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-24T02:10:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-17T18:00:24.000Z",
"num_tokens": 223,
"size": 625
} |
-- Example usage of solver
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
open import Categories.Category.Cartesian
module Experiment.Categories.Solver.Category.Cartesian.Example
{o ℓ e} {𝒞 : Category o ℓ e} (cartesian : Cartesian 𝒞) where
open import Experiment.Categories.Solver.Category.Cartesian cartesian
open Category 𝒞
open Cartesian cartesian
open HomReasoning
private
variable
A B C D E F : Obj
module _ {f : D ⇒ E} {g : C ⇒ D} {h : B ⇒ C} {i : A ⇒ B} where
_ : (f ∘ g) ∘ id ∘ h ∘ i ≈ f ∘ (g ∘ h) ∘ i
_ = solve ((∥-∥ :∘ ∥-∥) :∘ :id :∘ ∥-∥ :∘ ∥-∥) (∥-∥ :∘ (∥-∥ :∘ ∥-∥) :∘ ∥-∥) refl
swap∘swap≈id :
∀ {A B} → swap {A}{B} ∘ swap {B}{A} ≈ id
swap∘swap≈id {A} {B} =
solve (:swap {∥ A ∥} {∥ B ∥} :∘ :swap)
:id
refl
assocʳ∘assocˡ≈id : ∀ {A B C} → assocʳ {A}{B}{C} ∘ assocˡ {A}{B}{C} ≈ id
assocʳ∘assocˡ≈id = solve (:assocʳ {∥ _ ∥} {∥ _ ∥} {∥ _ ∥} :∘ :assocˡ) :id refl
module _ {f : B ⇒ C} (f′ : A ⇒ B) {g : E ⇒ F} {g′ : D ⇒ E} where
⁂-∘ : (f ⁂ g) ∘ (f′ ⁂ g′) ≈ (f ∘ f′) ⁂ (g ∘ g′)
⁂-∘ = solve lhs rhs refl where
lhs = (∥ f ∥ :⁂ ∥ g ∥) :∘ (∥ f′ ∥ :⁂ ∥ g′ ∥)
rhs = (∥ f ∥ :∘ ∥ f′ ∥) :⁂ (∥ g ∥ :∘ ∥ g′ ∥)
module _ {A B C D} where
pentagon′ : (id ⁂ assocˡ) ∘ assocˡ ∘ (assocˡ ⁂ id) ≈
assocˡ ∘ assocˡ {A × B} {C} {D}
pentagon′ = solve lhs rhs refl where
lhs = (:id :⁂ :assocˡ) :∘ :assocˡ :∘ (:assocˡ :⁂ :id)
rhs = :assocˡ :∘ :assocˡ {∥ A ∥ :× ∥ B ∥} {∥ C ∥} {∥ D ∥}
module _ {A B C} where
hexagon₁′ : (id ⁂ swap) ∘ assocˡ ∘ (swap ⁂ id) ≈
assocˡ ∘ swap ∘ assocˡ {A}{B}{C}
hexagon₁′ = solve lhs rhs refl where
lhs = (:id :⁂ :swap) :∘ :assocˡ :∘ (:swap :⁂ :id)
rhs = :assocˡ :∘ :swap :∘ :assocˡ {∥ A ∥}{∥ B ∥}{∥ C ∥}
module _ {f : A ⇒ B} where
commute : ⟨ ! , id ⟩ ∘ f ≈ ⟨ id ∘ π₁ , f ∘ π₂ ⟩ ∘ ⟨ ! , id ⟩
commute = solve (:⟨ :! , :id ⟩ :∘ ∥ f ∥)
(:⟨ :id :∘ :π₁ , ∥ f ∥ :∘ :π₂ ⟩ :∘ :⟨ :! , :id ⟩)
refl
_ : id {⊤} ≈ !
_ = solve (∥ id !∥) :! refl
_ : π₁ {⊤} {⊤} ≈ π₂
_ = solve (:π₁ {:⊤} {:⊤}) :π₂ refl
module _ {f : A ⇒ B} {g : C ⇒ D} where
first↔second′ : first f ∘ second g ≈ second g ∘ first f
first↔second′ = solve (:first ∥ f ∥ :∘ :second ∥ g ∥)
(:second ∥ g ∥ :∘ :first ∥ f ∥)
refl
| {
"alphanum_fraction": 0.454821894,
"avg_line_length": 31.5342465753,
"ext": "agda",
"hexsha": "ada976e329647f2da9e4ed4a042bc05f1b3f1e1d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rei1024/agda-misc",
"max_forks_repo_path": "Experiment/Categories/Solver/Category/Cartesian/Example.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "rei1024/agda-misc",
"max_issues_repo_path": "Experiment/Categories/Solver/Category/Cartesian/Example.agda",
"max_line_length": 81,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rei1024/agda-misc",
"max_stars_repo_path": "Experiment/Categories/Solver/Category/Cartesian/Example.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-21T00:03:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:49:42.000Z",
"num_tokens": 1128,
"size": 2302
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.KleinBottle where
open import Cubical.HITs.KleinBottle.Base public
open import Cubical.HITs.KleinBottle.Properties public
| {
"alphanum_fraction": 0.793814433,
"avg_line_length": 32.3333333333,
"ext": "agda",
"hexsha": "495c86da7001c7e689f7ece796546271d5463c02",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/HITs/KleinBottle.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/HITs/KleinBottle.agda",
"max_line_length": 54,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/HITs/KleinBottle.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 54,
"size": 194
} |
data Unit : Set where
unit : Unit
data Maybe (A : Set) : Set where
nothing : Maybe A
just : A → Maybe A
data Test : Set where
map : (Unit → Maybe Test) → Test
-- Accepted:
foo : Test → Unit
foo-aux : Maybe Test → Unit
foo (map f) = foo-aux (f unit)
foo-aux nothing = unit
foo-aux (just x) = foo x
test : Test → Unit
test (map f) with f unit
test (map f) | nothing = unit
test (map f) | just x = test x
-- WAS: Termination checker complains
-- SHOULD: succeed
| {
"alphanum_fraction": 0.6398305085,
"avg_line_length": 18.88,
"ext": "agda",
"hexsha": "ba8c120f8486d8a87d5ef7b23d349edea29300ae",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue1381.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue1381.agda",
"max_line_length": 37,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue1381.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 153,
"size": 472
} |
module nats where
open import Data.Nat
ten : ℕ
ten = 10
| {
"alphanum_fraction": 0.7068965517,
"avg_line_length": 8.2857142857,
"ext": "agda",
"hexsha": "fe9ae47fcd503b97f5bc7e413e39f4fda25b21f2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "257675afb3bd4a09b9f1672474d7048748f7d155",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "ssbothwell/plfa.github.io",
"max_forks_repo_path": "src/nats.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "257675afb3bd4a09b9f1672474d7048748f7d155",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "ssbothwell/plfa.github.io",
"max_issues_repo_path": "src/nats.agda",
"max_line_length": 20,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "257675afb3bd4a09b9f1672474d7048748f7d155",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "ssbothwell/plfa.github.io",
"max_stars_repo_path": "src/nats.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 20,
"size": 58
} |
open import Agda.Builtin.Nat
postulate P : Nat → Set
record R : Set where
field
f : P zero
foo : R → Set
foo (record { f = f0 }) with zero
foo r | x = Nat
| {
"alphanum_fraction": 0.6121212121,
"avg_line_length": 12.6923076923,
"ext": "agda",
"hexsha": "6c07748f1b3afd8c8a33b8d45157699eecc691d0",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue2998-illtyped.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue2998-illtyped.agda",
"max_line_length": 33,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue2998-illtyped.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 58,
"size": 165
} |
module Proof where
-- stdlib import
open import Data.Nat
main : ℕ
main = suc zero
| {
"alphanum_fraction": 0.7011494253,
"avg_line_length": 7.9090909091,
"ext": "agda",
"hexsha": "1fe3d3b628484113a9520b7400040052e5280f63",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "725ac3568bc2ce6abf170696f61802bfee09c039",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "sourcedennis/docker-agda-mini",
"max_forks_repo_path": "example/proofs/Proof.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "725ac3568bc2ce6abf170696f61802bfee09c039",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "sourcedennis/docker-agda-mini",
"max_issues_repo_path": "example/proofs/Proof.agda",
"max_line_length": 20,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "725ac3568bc2ce6abf170696f61802bfee09c039",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "sourcedennis/docker-agda-mini",
"max_stars_repo_path": "example/proofs/Proof.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 25,
"size": 87
} |
{-# OPTIONS --cubical #-}
module _ where
open import Agda.Builtin.Nat
open import Agda.Builtin.Cubical.Path
postulate
admit : ∀ {A : Set} → A
data Z : Set where
pos : Nat → Z
neg : Nat → Z
sameZero : pos 0 ≡ neg 0
_+Z_ : Z → Z → Z
pos x +Z pos x₁ = admit
pos x +Z neg x₁ = admit
pos x +Z sameZero x₁ = admit
neg x +Z z' = admit
sameZero x +Z z' = admit
| {
"alphanum_fraction": 0.6053333333,
"avg_line_length": 17.8571428571,
"ext": "agda",
"hexsha": "b1a6a0dfbd711db19c3d0cdbcd89b8b1a7a8cf3f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2fa8ede09451d43647f918dbfb24ff7b27c52edc",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "phadej/agda",
"max_forks_repo_path": "test/Succeed/Issue3314.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2fa8ede09451d43647f918dbfb24ff7b27c52edc",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "phadej/agda",
"max_issues_repo_path": "test/Succeed/Issue3314.agda",
"max_line_length": 37,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "2fa8ede09451d43647f918dbfb24ff7b27c52edc",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "phadej/agda",
"max_stars_repo_path": "test/Succeed/Issue3314.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 142,
"size": 375
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT renaming (pt to ⊙pt)
open import homotopy.Bouquet
open import homotopy.FinWedge
open import homotopy.SphereEndomorphism
open import homotopy.DisjointlyPointedSet
open import groups.SphereEndomorphism
open import groups.SumOfSubIndicator
open import groups.DisjointlyPointedSet
open import cw.CW
open import cw.DegreeByProjection
open import cw.FinBoundary
open import cw.FinCW
open import cw.WedgeOfCells
open import cohomology.Theory
module cw.cohomology.cochainequiv.FirstCoboundary (OT : OrdinaryTheory lzero)
(⊙fin-skel : ⊙FinSkeleton 1) where
open OrdinaryTheory OT
open import cohomology.RephraseSubFinCoboundary OT
open import cohomology.SubFinBouquet OT
private
⊙skel = ⊙FinSkeleton-realize ⊙fin-skel
fin-skel = ⊙FinSkeleton.skel ⊙fin-skel
I = AttachedFinSkeleton.numCells fin-skel
skel = ⊙Skeleton.skel ⊙skel
dec = FinSkeleton-has-cells-with-dec-eq fin-skel
ac = FinSkeleton-has-cells-with-choice 0 fin-skel lzero
fin-skel₋₁ = fcw-init fin-skel
ac₋₁ = FinSkeleton-has-cells-with-choice 0 fin-skel₋₁ lzero
endpoint = attaching-last skel
I₋₁ = AttachedFinSkeleton.skel fin-skel
⊙head = ⊙cw-head ⊙skel
pt = ⊙pt ⊙head
open DegreeAtOne skel dec
open import cw.cohomology.WedgeOfCells OT ⊙skel
open import cw.cohomology.reconstructed.TipAndAugment OT (⊙cw-init ⊙skel)
open import cw.cohomology.reconstructed.TipCoboundary OT ⊙skel
open import cw.cohomology.cochainequiv.FirstCoboundaryAbstractDefs OT ⊙fin-skel
abstract
rephrase-cw-co∂-head'-in-degree : ∀ g
→ GroupIso.f (CXₙ/Xₙ₋₁-diag-β ac) (GroupHom.f cw-co∂-head' (GroupIso.g (CX₀-diag-β ac₋₁) g))
∼ λ <I → Group.subsum-r (C2 0) ⊙head-separate
(λ b → Group.exp (C2 0) (g b) (degree <I (fst b)))
rephrase-cw-co∂-head'-in-degree g <I =
GroupIso.f (C-FinBouquet-diag 1 I)
(CEl-fmap 1 (⊙–> (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ skel))
(CEl-fmap 1 ⊙cw-∂-head'-before-Susp
(<– (CEl-Susp 0 ⊙head)
(CEl-fmap 0 (⊙<– (Bouquet-⊙equiv-X ⊙head-is-separable))
(GroupIso.g (C-SubFinBouquet-diag 0 MinusPoint-⊙head-has-choice ⊙head-separate)
g))))) <I
=⟨ ap
(λ g →
GroupIso.f (C-FinBouquet-diag 1 I)
(CEl-fmap 1 (⊙–> (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ skel))
(CEl-fmap 1 ⊙cw-∂-head'-before-Susp g)) <I) $
C-Susp-fmap' 0 (⊙<– (Bouquet-⊙equiv-X (Fin-has-dec-eq pt))) □$ᴳ
(GroupIso.g (C-SubFinBouquet-diag 0 MinusPoint-⊙head-has-choice ⊙head-separate)
g) ⟩
GroupIso.f (C-FinBouquet-diag 1 I)
(CEl-fmap 1 (⊙–> (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ skel))
(CEl-fmap 1 ⊙cw-∂-head'-before-Susp
(CEl-fmap 1 (⊙Susp-fmap (⊙<– (Bouquet-⊙equiv-X ⊙head-is-separable)))
(<– (CEl-Susp 0 (⊙Bouquet (MinusPoint ⊙head) 0))
(GroupIso.g (C-SubFinBouquet-diag 0 MinusPoint-⊙head-has-choice ⊙head-separate)
g))))) <I
=⟨ ap (λ g → GroupIso.f (C-FinBouquet-diag 1 I) g <I) $
∘-CEl-fmap 1 (⊙–> (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ skel)) ⊙cw-∂-head'-before-Susp
(CEl-fmap 1 (⊙Susp-fmap (⊙<– (Bouquet-⊙equiv-X ⊙head-is-separable)))
(<– (CEl-Susp 0 (⊙Bouquet (MinusPoint ⊙head) 0))
(GroupIso.g (C-SubFinBouquet-diag 0 MinusPoint-⊙head-has-choice ⊙head-separate)
g)))
∙ ∘-CEl-fmap 1
(⊙cw-∂-head'-before-Susp ⊙∘ ⊙–> (Bouquet-⊙equiv-Xₙ/Xₙ₋₁ skel))
(⊙Susp-fmap (⊙<– (Bouquet-⊙equiv-X ⊙head-is-separable)))
(<– (CEl-Susp 0 (⊙Bouquet (MinusPoint ⊙head) 0))
(GroupIso.g (C-SubFinBouquet-diag 0 MinusPoint-⊙head-has-choice ⊙head-separate)
g))
∙ ap (λ f → CEl-fmap 1 f
(<– (CEl-Susp 0 (⊙Bouquet (MinusPoint ⊙head) 0))
(GroupIso.g (C-SubFinBouquet-diag 0 MinusPoint-⊙head-has-choice ⊙head-separate)
g)))
(! ⊙function₀'-β) ⟩
GroupIso.f (C-FinBouquet-diag 1 I)
(CEl-fmap 1 ⊙function₀'
(<– (CEl-Susp 0 (⊙Bouquet (MinusPoint ⊙head) 0))
(GroupIso.g (C-SubFinBouquet-diag 0 MinusPoint-⊙head-has-choice ⊙head-separate)
g))) <I
=⟨ rephrase-in-degree 0 {I = I} MinusPoint-⊙head-has-choice
MinusPoint-⊙head-has-dec-eq ⊙head-separate-equiv ⊙function₀' g <I ⟩
Group.subsum-r (C2 0) ⊙head-separate
(λ b → Group.exp (C2 0) (g b)
(⊙SphereS-endo-degree 0
(⊙Susp-fmap (⊙bwproj MinusPoint-⊙head-has-dec-eq b) ⊙∘ ⊙function₀' ⊙∘ ⊙fwin <I)))
=⟨ ap (Group.subsum-r (C2 0) ⊙head-separate)
(λ= λ b → ap (Group.exp (C2 0) (g b)) $
⊙SphereS-endo-degree-base-indep 0
{f = ( ⊙Susp-fmap (⊙bwproj MinusPoint-⊙head-has-dec-eq b)
⊙∘ ⊙function₀'
⊙∘ ⊙fwin <I)}
{g = (Susp-fmap (function₁' <I b) , idp)}
(mega-reduction <I b)) ⟩
Group.subsum-r (C2 0) ⊙head-separate
(λ b → Group.exp (C2 0) (g b)
(⊙SphereS-endo-degree 0
(Susp-fmap (function₁' <I b) , idp)))
=⟨ ap (Group.subsum-r (C2 0) ⊙head-separate)
(λ= λ b → ap (Group.exp (C2 0) (g b)) $
degree-matches <I b) ⟩
Group.subsum-r (C2 0) ⊙head-separate
(λ b → Group.exp (C2 0) (g b)
(degree <I (fst b)))
=∎
abstract
private
degree-true-≠ : ∀ {<I <I₋₁} → (<I₋₁ ≠ endpoint <I true) → degree-true <I <I₋₁ == 0
degree-true-≠ {<I} {<I₋₁} neq with Fin-has-dec-eq <I₋₁ (endpoint <I true)
... | inl eq = ⊥-rec (neq eq)
... | inr _ = idp
degree-true-diag : ∀ <I → degree-true <I (endpoint <I true) == -1
degree-true-diag <I with Fin-has-dec-eq (endpoint <I true) (endpoint <I true)
... | inl _ = idp
... | inr neq = ⊥-rec (neq idp)
sum-degree-true : ∀ <I g → Group.sum (C2 0) (λ <I₋₁ → Group.exp (C2 0) g (degree-true <I <I₋₁)) == Group.inv (C2 0) g
sum-degree-true <I g =
sum-subindicator (C2 0) (λ <I₋₁ → Group.exp (C2 0) g (degree-true <I <I₋₁))
(endpoint <I true) (λ neq → ap (Group.exp (C2 0) g) (degree-true-≠ neq))
∙ ap (Group.exp (C2 0) g) (degree-true-diag <I)
degree-false-≠ : ∀ {<I <I₋₁} → (<I₋₁ ≠ endpoint <I false) → degree-false <I <I₋₁ == 0
degree-false-≠ {<I} {<I₋₁} neq with Fin-has-dec-eq <I₋₁ (endpoint <I false)
... | inl eq = ⊥-rec (neq eq)
... | inr _ = idp
degree-false-diag : ∀ <I → degree-false <I (endpoint <I false) == 1
degree-false-diag <I with Fin-has-dec-eq (endpoint <I false) (endpoint <I false)
... | inl _ = idp
... | inr neq = ⊥-rec (neq idp)
sum-degree-false : ∀ <I g → Group.sum (C2 0) (λ <I₋₁ → Group.exp (C2 0) g (degree-false <I <I₋₁)) == g
sum-degree-false <I g =
sum-subindicator (C2 0) (λ <I₋₁ → Group.exp (C2 0) g (degree-false <I <I₋₁))
(endpoint <I false) (λ neq → ap (Group.exp (C2 0) g) (degree-false-≠ neq))
∙ ap (Group.exp (C2 0) g) (degree-false-diag <I)
sum-degree : ∀ <I g → Group.sum (C2 0) (λ <I₋₁ → Group.exp (C2 0) g (degree <I <I₋₁)) == Group.ident (C2 0)
sum-degree <I g =
ap (Group.sum (C2 0)) (λ= λ <I₋₁ → Group.exp-+ (C2 0) g (degree-true <I <I₋₁) (degree-false <I <I₋₁))
∙ AbGroup.sum-comp (C2-abgroup 0)
(λ <I₋₁ → Group.exp (C2 0) g (degree-true <I <I₋₁))
(λ <I₋₁ → Group.exp (C2 0) g (degree-false <I <I₋₁))
∙ ap2 (Group.comp (C2 0))
(sum-degree-true <I g)
(sum-degree-false <I g)
∙ Group.inv-l (C2 0) g
merge-branches : ∀ (g : Fin I₋₁ → Group.El (C2 0)) (g-pt : g pt == Group.ident (C2 0)) x
→ Coprod-rec (λ _ → Group.ident (C2 0)) (λ b → g (fst b)) (⊙head-separate x)
== g x
merge-branches g g-pt x with Fin-has-dec-eq pt x
merge-branches g g-pt x | inl idp = ! g-pt
merge-branches g g-pt x | inr _ = idp
rephrase-cw-co∂-head-in-degree : ∀ g
→ GroupIso.f (CXₙ/Xₙ₋₁-diag-β ac) (GroupHom.f cw-co∂-head (GroupIso.g (C2×CX₀-diag-β ac₋₁) g))
∼ λ <I → Group.sum (C2 0) (λ <I₋₁ → Group.exp (C2 0) (g <I₋₁) (degree <I <I₋₁))
rephrase-cw-co∂-head-in-degree g <I =
GroupIso.f (CXₙ/Xₙ₋₁-diag-β ac) (GroupHom.f cw-co∂-head' (GroupIso.g (CX₀-diag-β ac₋₁) (snd (diff-and-separate (C2 0) g)))) <I
=⟨ rephrase-cw-co∂-head'-in-degree (snd (diff-and-separate (C2 0) g)) <I ⟩
Group.subsum-r (C2 0) ⊙head-separate
(λ b → Group.exp (C2 0) (Group.diff (C2 0) (g (fst b)) (g pt))
(degree <I (fst b)))
=⟨ ap (Group.sum (C2 0)) (λ= λ <I₋₁ →
merge-branches
(λ <I₋₁ → Group.exp (C2 0) (Group.diff (C2 0) (g <I₋₁) (g pt)) (degree <I <I₋₁))
( ap (λ g → Group.exp (C2 0) g (degree <I pt)) (Group.inv-r (C2 0) (g pt))
∙ Group.exp-ident (C2 0) (degree <I pt))
<I₋₁
∙ AbGroup.exp-comp (C2-abgroup 0) (g <I₋₁) (Group.inv (C2 0) (g pt)) (degree <I <I₋₁)) ⟩
Group.sum (C2 0) (λ <I₋₁ →
Group.comp (C2 0)
(Group.exp (C2 0) (g <I₋₁) (degree <I <I₋₁))
(Group.exp (C2 0) (Group.inv (C2 0) (g pt)) (degree <I <I₋₁)))
=⟨ AbGroup.sum-comp (C2-abgroup 0)
(λ <I₋₁ → Group.exp (C2 0) (g <I₋₁) (degree <I <I₋₁))
(λ <I₋₁ → Group.exp (C2 0) (Group.inv (C2 0) (g pt)) (degree <I <I₋₁)) ⟩
Group.comp (C2 0)
(Group.sum (C2 0) (λ <I₋₁ → Group.exp (C2 0) (g <I₋₁) (degree <I <I₋₁)))
(Group.sum (C2 0) (λ <I₋₁ → Group.exp (C2 0) (Group.inv (C2 0) (g pt)) (degree <I <I₋₁)))
=⟨ ap (Group.comp (C2 0) (Group.sum (C2 0) (λ <I₋₁ → Group.exp (C2 0) (g <I₋₁) (degree <I <I₋₁))))
(sum-degree <I (Group.inv (C2 0) (g pt)))
∙ Group.unit-r (C2 0) _ ⟩
Group.sum (C2 0) (λ <I₋₁ → Group.exp (C2 0) (g <I₋₁) (degree <I <I₋₁))
=∎
| {
"alphanum_fraction": 0.5601360404,
"avg_line_length": 47.3317073171,
"ext": "agda",
"hexsha": "e75026f19e1242f40c95e7ad1ff6dd3b36f43b50",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/cw/cohomology/cochainequiv/FirstCoboundary.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/cw/cohomology/cochainequiv/FirstCoboundary.agda",
"max_line_length": 130,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "theorems/cw/cohomology/cochainequiv/FirstCoboundary.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4091,
"size": 9703
} |
-- FNF, 2017-06-13, issue # 2592 reported by Manuel Bärenz
-- The .in file loads Issue2592/B.agda and Issue2592/C.agda that both
-- imports Issue2592/A.agda.
| {
"alphanum_fraction": 0.7295597484,
"avg_line_length": 31.8,
"ext": "agda",
"hexsha": "a4537c9e5650ba2b1995647b0a0473a166175d6e",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/Issue2592.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue2592.agda",
"max_line_length": 69,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue2592.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 55,
"size": 159
} |
data ⊥ : Set where
module M₁ where
postulate
∥_∥ : Set → Set
{-# POLARITY ∥_∥ ++ #-}
data D : Set where
c : ∥ D ∥ → D
module M₂ where
postulate
_⇒_ : Set → Set → Set
lambda : {A B : Set} → (A → B) → A ⇒ B
apply : {A B : Set} → A ⇒ B → A → B
{-# POLARITY _⇒_ ++ #-}
data D : Set where
c : D ⇒ ⊥ → D
not-inhabited : D → ⊥
not-inhabited (c f) = apply f (c f)
d : D
d = c (lambda not-inhabited)
bad : ⊥
bad = not-inhabited d
postulate
F₁ : Set → Set → Set₁ → Set₁ → Set₁ → Set
{-# POLARITY F₁ _ ++ + - * #-}
data D₁ : Set where
c : F₁ (D₁ → ⊥) D₁ Set Set Set → D₁
postulate
F₂ : ∀ {a} → Set a → Set a → Set a
{-# POLARITY F₂ * * ++ #-}
data D₂ (A : Set) : Set where
c : F₂ A (D₂ A) → D₂ A
module _ (A : Set₁) where
postulate
F₃ : Set → Set
{-# POLARITY F₃ ++ #-}
data D₃ : Set where
c : F₃ Set D₃ → D₃
postulate
F₄ : ∀ {a} → Set a → Set a → Set a
{-# POLARITY F₄ * ++ #-}
data D₄ (A : Set) : Set where
c : F₄ (D₄ A) A → D₄ A
postulate
F₅ : ⦃ _ : Set ⦄ → Set
{-# POLARITY F₅ ++ #-}
data D₅ : Set where
c : F₅ ⦃ D₅ ⦄ → D₅
| {
"alphanum_fraction": 0.4870651204,
"avg_line_length": 14.9466666667,
"ext": "agda",
"hexsha": "e7cd5c3c2534e9daa10da6f7ec3ec42653a3ed35",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Polarity-pragma.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Polarity-pragma.agda",
"max_line_length": 43,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Polarity-pragma.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 507,
"size": 1121
} |
module Tuples where
open import Data.Product
_² : ∀ {a} (A : Set a) → Set a
A ² = A × A
_³ : ∀ {a} (A : Set a) → Set a
A ³ = A × A ²
_⁴ : ∀ {a} (A : Set a) → Set a
A ⁴ = A × A ³
_⁵ : ∀ {a} (A : Set a) → Set a
A ⁵ = A × A ⁴
_⁶ : ∀ {a} (A : Set a) → Set a
A ⁶ = A × A ⁵
_⁷ : ∀ {a} (A : Set a) → Set a
A ⁷ = A × A ⁶
| {
"alphanum_fraction": 0.4330218069,
"avg_line_length": 13.9565217391,
"ext": "agda",
"hexsha": "8421c0f1ff85ede37fd9baad8a3ce4b4fa6dce71",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "ice1k/Theorems",
"max_forks_repo_path": "src/Tuples.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "ice1k/Theorems",
"max_issues_repo_path": "src/Tuples.agda",
"max_line_length": 30,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "ice1k/Theorems",
"max_stars_repo_path": "src/Tuples.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-15T15:28:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-15T15:28:03.000Z",
"num_tokens": 181,
"size": 321
} |
{-# OPTIONS --without-K #-}
module function.extensionality where
open import function.extensionality.core public
open import function.extensionality.proof public
open import function.extensionality.strong public
using (strong-funext; strong-funext-iso)
open import function.extensionality.computation public
open import equality.core
open import function.isomorphism
open import function.overloading
-- extensionality for functions of implicit arguments
impl-funext : ∀ {i j}{X : Set i}{Y : X → Set j}
→ {f g : {x : X} → Y x}
→ ((x : X) → f {x} ≡ g {x})
→ (λ {x} → f {x}) ≡ g
impl-funext h = ap (apply impl-iso) (funext h)
| {
"alphanum_fraction": 0.6914893617,
"avg_line_length": 32.9,
"ext": "agda",
"hexsha": "2ad60fd29f20b9cd344f92c16461458bada10e85",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-02-26T06:17:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-11T17:19:12.000Z",
"max_forks_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "HoTT/M-types",
"max_forks_repo_path": "function/extensionality.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_issues_repo_issues_event_max_datetime": "2015-02-11T15:20:34.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-11T11:14:59.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "HoTT/M-types",
"max_issues_repo_path": "function/extensionality.agda",
"max_line_length": 54,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "HoTT/M-types",
"max_stars_repo_path": "function/extensionality.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z",
"num_tokens": 178,
"size": 658
} |
module SimpleTermUnification where
open import OscarPrelude
data Term (n : Nat) : Set where
var : Fin n → Term n
leaf : Term n
_fork_ : Term n → Term n → Term n
|> : ∀ {m n} → (r : Fin m → Fin n) → Fin m → Term n
|> r = var ∘ r
_<|_ : ∀ {m n} → (f : Fin m → Term n) → Term m → Term n
f <| var x = f x
f <| leaf = leaf
f <| (t₁ fork t₂) = (f <| t₁) fork (f <| t₂)
<|-assoc : ∀ {m n o} (f : Fin n → Term o) (g : Fin m → Term n) (x : Term m) → f <| (g <| x) ≡ (λ y → f <| g y) <| x
<|-assoc f g (var x) = refl
<|-assoc f g leaf = refl
<|-assoc f g (x₁ fork x₂) rewrite <|-assoc f g x₁ | <|-assoc f g x₂ = refl
_≗_ : ∀ {m n} → (f g : Fin m → Term n) → Set
f ≗ g = ∀ x → f x ≡ g x
infixr 9 _⋄_
_⋄_ : ∀ {l m n} → (f : Fin m → Term n) → (g : Fin l → Term m) → Fin l → Term n
(f ⋄ g) = (f <|_) ∘ g
⋄-assoc : ∀ {l m n o} (f : Fin n → Term o) (g : Fin m → Term n) (h : Fin l → Term m) → (f ⋄ (g ⋄ h)) ≗ ((f ⋄ g) ⋄ h)
⋄-assoc f g h x = <|-assoc f g (h x)
⋄-assoc' : ∀ {l m n o} (f : Fin n → Term o) (g : Fin m → Term n) (h : Fin l → Term m) → (f ⋄ (g ⋄ h)) ≡ ((f ⋄ g) ⋄ h)
⋄-assoc' f g h = {!⋄-assoc f g h!}
thin : ∀ {n} → (x : Fin (suc n)) → (y : Fin n) → Fin (suc n)
thin {n} zero y = suc y
thin {zero} (suc x) ()
thin {suc n} (suc x) zero = zero
thin {suc n} (suc x) (suc y) = suc (thin x y)
thick : ∀ {n} → (x y : Fin (suc n)) → Maybe (Fin n)
thick {n} zero zero = nothing
thick {n} zero (suc y) = just y
thick {zero} (suc ()) zero
thick {suc n} (suc x) zero = just zero
thick {zero} (suc ()) (suc y)
thick {suc n} (suc x) (suc y) = suc <$> thick x y
check : ∀ {n} → (x : Fin (suc n)) (t : Term (suc n)) → Maybe (Term n)
check x (var y) = var <$> thick x y
check x leaf = just leaf
check x (t₁ fork t₂) = _fork_ <$> check x t₁ <*> check x t₂
_for_ : ∀ {n} → (t' : Term n) (x : Fin (suc n)) → Fin (suc n) → Term n
(t' for x) y with thick x y
… | just y' = var y'
… | nothing = t'
data AList (n : Nat) : Nat → Set where
anil : AList n n
_asnoc_/_ : ∀ {m} → (σ : AList n m) → (t' : Term m) → (x : Fin (suc m)) → AList n (suc m)
sub : ∀ {n m} → (σ : AList n m) → Fin m → Term n
sub anil = var
sub (σ asnoc t' / x) = sub σ ⋄ (t' for x)
flexFlex : ∀ {m} → (x y : Fin m) → ∃ (flip AList m)
flexFlex {zero} () _
flexFlex {suc m} x y with thick x y
… | just y' = m , (anil asnoc var y' / x)
… | nothing = suc m , anil
flexRigid : ∀ {m} → (x : Fin m) (t : Term m) → Maybe (∃ (flip AList m))
flexRigid {zero} () _
flexRigid {suc m} x t with check x t
… | just t' = just $ m , anil asnoc t' / x
… | nothing = nothing
amgu : ∀ {m} → (s t : Term m) (acc : ∃ (flip AList m)) → Maybe (∃ (flip AList m))
amgu {m} leaf leaf acc = just acc
amgu {m} leaf (_ fork _) _ = nothing
amgu {m} (_ fork _) leaf _ = nothing
amgu {m} (s₁ fork s₂) (t₁ fork t₂) acc = amgu s₁ t₁ acc >>= amgu s₂ t₂
amgu {m} (var x) (var y) (.m , anil) = just $ flexFlex x y
amgu {m} (var x) t (.m , anil) = flexRigid x t
amgu {m} t (var x) (.m , anil) = flexRigid x t
amgu {suc m} s t (n , (σ asnoc r / z)) = amgu ((r for z) <| s) ((r for z) <| t) (n , σ) >>= λ {(n' , σ') → just $ n' , σ' asnoc r / z}
mgu : ∀ {m} → (s t : Term m) → Maybe (∃ (flip AList m))
mgu {m} s t = amgu s t (m , anil)
f : Fin 4 → Term 5
f n = var (thin (suc n) n) fork var (thin (suc n) n)
g : Fin 4 → Term 5
g n = var (suc n)
fs : Term 5
fs = f 0 fork (f 1 fork (f 2 fork f 3))
gs : Term 5
gs = g 0 fork (g 1 fork (g 2 fork g 3))
foo : Set
foo = {!mgu fs gs!}
Property : Nat → Set₁
Property m = ∀ {n} → (Fin m → Term n) → Set
Unifies : ∀ {m} → (s t : Term m) → Property m
Unifies s t f = f <| s ≡ f <| t
_∧_ : ∀ {m} → (P Q : Property m) → Property m
(P ∧ Q) f = P f × Q f
_⇔_ : ∀ {m} → (P Q : Property m) → Property m
(P ⇔ Q) f = (P f → Q f) × (Q f → P f)
Nothing : ∀ {m} (P : Property m) → Set
Nothing {m} P = ∀ {n} → (f : Fin m → Term n) → ¬ P f
infixl 3 _[-⋄_]_
_[-⋄_]_ : ∀ {m n} (P : Property m) (f : Fin m → Term n) → Property n
(P [-⋄ f ] g) = P (g ⋄ f)
_≤ₛ_ : ∀ {m n n'} (f : Fin m → Term n) (g : Fin m → Term n') → Set
f ≤ₛ g = ∃ λ f' → f ≗ (f' ⋄ g)
Max : ∀ {m} (P : Property m) → Property m
Max {m} P f = P f × ∀ {n} → (f' : Fin m → Term n) → P f' → f' ≤ₛ f
DClosed : ∀ {m} (P : Property m) → Set
DClosed {m} P = ∀ {n n'} (f : Fin m → Term n) (g : Fin m → Term n') → f ≤ₛ g → P g → P f
Lemma1 : ∀ {l} {P Q : Property l} {m n o}
{p : Fin m → Term n}
{q : Fin n → Term o}
{a : Fin l → Term m}
→ DClosed P
→ Max (P [-⋄ a ]_) p
→ Max (Q [-⋄ (p ⋄ a)]_) q
→ Max ((P ∧ Q) [-⋄ a ]_) (q ⋄ p)
Lemma1 {P = P} {Q} {p = p} {q} {a} DCP maxP maxQ =
let Qqpa : Q (q ⋄ p ⋄ a)
Qqpa = fst maxQ
Qqpa' : Q ((q ⋄ p) ⋄ a)
Qqpa' = {!⋄-assoc q p a!}
Pqpa : P (q ⋄ p ⋄ a)
Pqpa = DCP (λ z → q <| (p <| a z)) (λ z → p <| a z) (q , (λ x → refl)) (fst maxP)
lem3 : ∀ {n} → {f : Fin _ → Term n} → P (f ⋄ a) → Q (f ⋄ a) → f ≤ₛ (q ⋄ p)
lem3 = {!!}
in ({!!} , {!maxQ!}) , {!!}
where
Ppa : P (p ⋄ a)
Ppa = fst maxP
pMax : ∀ {n} {p' : Fin _ → Term n} → P (p' ⋄ a) → p' ≤ₛ p
pMax {n} {p'} Pp'a = snd maxP p' Pp'a
data Step (n : Nat) : Set where
left : Term n → Step n
right : Term n → Step n
_+ₛ_ : ∀ {n} → (ps : List (Step n)) → (t : Term n) → Term n
[] +ₛ t = t
(left r ∷ ps) +ₛ t = (ps +ₛ t) fork r
(right l ∷ ps) +ₛ t = l fork (ps +ₛ t)
theorem-6 : ∀ m → (s t : Term m) → (r : Maybe (∃ (flip AList m))) → mgu s t ≡ r → Either (∃ λ n → ∃ λ σ → Max (Unifies s t) (sub σ) × r ≡ just (n , σ)) (Nothing (Unifies s t) × r ≡ nothing)
theorem-6 = {!!}
| {
"alphanum_fraction": 0.473359913,
"avg_line_length": 31.8959537572,
"ext": "agda",
"hexsha": "0dd0d6d058fe47ee506f719e6f71736ba7e264a0",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-1/SimpleTermUnification.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-1/SimpleTermUnification.agda",
"max_line_length": 189,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-1/SimpleTermUnification.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2572,
"size": 5518
} |
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)
| {
"alphanum_fraction": 0.46,
"avg_line_length": 29.2,
"ext": "agda",
"hexsha": "4114ee780adffa2592617cd9d6341aeaff54ddba",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "6f3df71dcd958c6a1d1bf4f175dc16c220d42124",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "bens/hwlc",
"max_forks_repo_path": "Types.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6f3df71dcd958c6a1d1bf4f175dc16c220d42124",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "bens/hwlc",
"max_issues_repo_path": "Types.agda",
"max_line_length": 67,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6f3df71dcd958c6a1d1bf4f175dc16c220d42124",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "bens/hwlc",
"max_stars_repo_path": "Types.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1852,
"size": 3650
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT.Base
open import HoTT.Identity
open import HoTT.Identity.Sigma
open import HoTT.Identity.Pi
open import HoTT.Identity.Universe
open import HoTT.Identity.Product
open import HoTT.HLevel
open import HoTT.HLevel.Truncate
open import HoTT.Equivalence
open import HoTT.Equivalence.Lift
module HoTT.Logic where
private variable i j k : Level
LiftProp : Prop𝒰 i → Prop𝒰 (i ⊔ j)
LiftProp {i} {j} P = type (Lift {j} (P ty))
⊤ : Prop𝒰 i
⊤ = type 𝟏
⊥ : Prop𝒰 i
⊥ = type 𝟎
_∧_ : Prop𝒰 i → Prop𝒰 j → Prop𝒰 (i ⊔ j)
P ∧ Q = type (P ty × Q ty) ⦃ ×-hlevel ⦄
_⇒_ : Prop𝒰 i → Prop𝒰 j → Prop𝒰 (i ⊔ j)
P ⇒ Q = type (P ty → Q ty)
infix 10 _⇒_
_⇔_ : Prop𝒰 i → Prop𝒰 i → Prop𝒰 (lsuc i)
P ⇔ Q = type (P ty == Q ty) ⦃ equiv-hlevel (=𝒰-equiv ⁻¹ₑ) ⦄
where
instance
_ = Σ-hlevel
_ = raise ⦃ hlevel𝒰.h P ⦄
_ = raise ⦃ hlevel𝒰.h Q ⦄
_∨_ : Prop𝒰 i → Prop𝒰 j → Prop𝒰 (i ⊔ j)
P ∨ Q = type ∥ P ty + Q ty ∥
∃ : (A : 𝒰 i) → (A → Prop𝒰 j) → Prop𝒰 (i ⊔ j)
∃ A P = type ∥ Σ A (_ty ∘ P) ∥
syntax ∃ A (λ x → Φ) = ∃[ x ∶ A ] Φ
∀' : (A : 𝒰 i) → (P : A → Prop𝒰 j) → Prop𝒰 (i ⊔ j)
∀' A P = type (Π A (_ty ∘ P))
where instance _ = λ {x} → hlevel𝒰.h (P x)
syntax ∀' A (λ x → Φ) = ∀[ x ∶ A ] Φ
LEM : 𝒰 (lsuc i)
LEM {i} = (A : Prop𝒰 i) → A ty + ¬ A ty
LEM∞ : 𝒰 (lsuc i)
LEM∞ {i} = (A : 𝒰 i) → A + ¬ A
LDN : 𝒰 (lsuc i)
LDN {i} = (A : Prop𝒰 i) → ¬ ¬ A ty → A ty
AC : 𝒰 (lsuc i ⊔ lsuc j ⊔ lsuc k)
AC {i} {j} {k} =
{X : 𝒰 i} {A : X → 𝒰 j} {P : (x : X) → A x → 𝒰 k} →
⦃ hlevel 2 X ⦄ → ⦃ {x : X} → hlevel 2 (A x) ⦄ →
⦃ {x : X} {a : A x} → hlevel 1 (P x a) ⦄ →
Π[ x ∶ X ] ∥ Σ[ a ∶ A x ] P x a ∥ →
∥ Σ[ g ∶ Π[ x ∶ X ] A x ] Π[ x ∶ X ] P x (g x) ∥
Lemma3/9/1 : (P : 𝒰 i) → ⦃ hlevel 1 P ⦄ → P ≃ ∥ P ∥
Lemma3/9/1 P = let open Iso in iso→eqv λ where
.f → ∣_∣ ; .g → ∥-rec id ; .η _ → refl ; .ε _ → center
-- Principle of unique choice
Corollary3/9/2 : {A : 𝒰 i} {P : A → 𝒰 i} → ⦃ {x : A} → hlevel 1 (P x) ⦄ →
((x : A) → ∥ P x ∥) → (x : A) → P x
Corollary3/9/2 {P = P} f = ∥-rec id ∘ f
| {
"alphanum_fraction": 0.5083170254,
"avg_line_length": 26.2051282051,
"ext": "agda",
"hexsha": "f7b25e9128f60c67587be2d4d6eb805cefff75a2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "michaelforney/hott",
"max_forks_repo_path": "HoTT/Logic.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "michaelforney/hott",
"max_issues_repo_path": "HoTT/Logic.agda",
"max_line_length": 73,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "michaelforney/hott",
"max_stars_repo_path": "HoTT/Logic.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1093,
"size": 2044
} |
module Agda.TypeChecking.Lock where
| {
"alphanum_fraction": 0.8611111111,
"avg_line_length": 18,
"ext": "agda",
"hexsha": "78a185793c19c6ce007ce7ff60830a0cfe1fb39d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "aa5e3a127bf17a8c80d947f3c286758a36dadc36",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "jappeace/agda",
"max_forks_repo_path": "src/full/Agda/TypeChecking/Lock.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aa5e3a127bf17a8c80d947f3c286758a36dadc36",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "jappeace/agda",
"max_issues_repo_path": "src/full/Agda/TypeChecking/Lock.agda",
"max_line_length": 35,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "aa5e3a127bf17a8c80d947f3c286758a36dadc36",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "jappeace/agda",
"max_stars_repo_path": "src/full/Agda/TypeChecking/Lock.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 8,
"size": 36
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Foundations.Pointed.FunExt where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Pointed.Base
open import Cubical.Foundations.Pointed.Properties
open import Cubical.Foundations.Pointed.Homotopy
private
variable
ℓ ℓ' : Level
module _ {A : Pointed ℓ} {B : typ A → Type ℓ'} {ptB : B (pt A)} where
-- pointed function extensionality
funExt∙P : {f g : Π∙ A B ptB} → f ∙∼P g → f ≡ g
funExt∙P (h , h∙) i .fst x = h x i
funExt∙P (h , h∙) i .snd = h∙ i
-- inverse of pointed function extensionality
funExt∙P⁻ : {f g : Π∙ A B ptB} → f ≡ g → f ∙∼P g
funExt∙P⁻ p .fst a i = p i .fst a
funExt∙P⁻ p .snd i = p i .snd
-- function extensionality is an isomorphism, PathP version
funExt∙PIso : (f g : Π∙ A B ptB) → Iso (f ∙∼P g) (f ≡ g)
Iso.fun (funExt∙PIso f g) = funExt∙P {f = f} {g = g}
Iso.inv (funExt∙PIso f g) = funExt∙P⁻ {f = f} {g = g}
Iso.rightInv (funExt∙PIso f g) p i j = p j
Iso.leftInv (funExt∙PIso f g) h _ = h
-- transformed to equivalence
funExt∙P≃ : (f g : Π∙ A B ptB) → (f ∙∼P g) ≃ (f ≡ g)
funExt∙P≃ f g = isoToEquiv (funExt∙PIso f g)
-- funExt∙≃ using the other kind of pointed homotopy
funExt∙≃ : (f g : Π∙ A B ptB) → (f ∙∼ g) ≃ (f ≡ g)
funExt∙≃ f g = compEquiv (∙∼≃∙∼P f g) (funExt∙P≃ f g)
-- standard pointed function extensionality and its inverse
funExt∙ : {f g : Π∙ A B ptB} → f ∙∼ g → f ≡ g
funExt∙ {f = f} {g = g} = equivFun (funExt∙≃ f g)
funExt∙⁻ : {f g : Π∙ A B ptB} → f ≡ g → f ∙∼ g
funExt∙⁻ {f = f} {g = g} = equivFun (invEquiv (funExt∙≃ f g))
| {
"alphanum_fraction": 0.6097704532,
"avg_line_length": 34.6734693878,
"ext": "agda",
"hexsha": "4df73cbdc3ac3eb61f8e2807e7c25789acb88366",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "60226aacd7b386aef95d43a0c29c4eec996348a8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "L-TChen/cubical",
"max_forks_repo_path": "Cubical/Foundations/Pointed/FunExt.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "60226aacd7b386aef95d43a0c29c4eec996348a8",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "L-TChen/cubical",
"max_issues_repo_path": "Cubical/Foundations/Pointed/FunExt.agda",
"max_line_length": 69,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "60226aacd7b386aef95d43a0c29c4eec996348a8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "L-TChen/cubical",
"max_stars_repo_path": "Cubical/Foundations/Pointed/FunExt.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 765,
"size": 1699
} |
{-# OPTIONS --cubical --no-exact-split --safe #-}
module Cubical.Structures.MultiSet where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.SIP renaming (SNS-PathP to SNS)
open import Cubical.Functions.FunExtEquiv
open import Cubical.Structures.Pointed
open import Cubical.Structures.Queue
open import Cubical.Data.Unit
open import Cubical.Data.Sum
open import Cubical.Data.Nat
open import Cubical.Data.Sigma
module _(A : Type ℓ)
(Aset : isSet A) where
open Queues-on A Aset
member-structure : Type ℓ → Type ℓ
member-structure X = A → X → ℕ
Member : Type (ℓ-suc ℓ)
Member = TypeWithStr ℓ member-structure
member-iso : StrIso member-structure ℓ
member-iso (X , f) (Y , g) e = ∀ a x → f a x ≡ g a (e .fst x)
Member-is-SNS : SNS {ℓ} member-structure member-iso
Member-is-SNS = SNS-≡→SNS-PathP member-iso ((λ _ _ → funExt₂Equiv))
-- a multi set structure inspired bei Okasaki
multi-set-structure : Type ℓ → Type ℓ
multi-set-structure X = X × (A → X → X) × (A → X → ℕ)
Multi-Set : Type (ℓ-suc ℓ)
Multi-Set = TypeWithStr ℓ multi-set-structure
multi-set-iso : StrIso multi-set-structure ℓ
multi-set-iso (X , emp₁ , insert₁ , memb₁) (Y , emp₂ , insert₂ , memb₂) e =
(e .fst emp₁ ≡ emp₂)
× (∀ a q → e .fst (insert₁ a q) ≡ insert₂ a (e .fst q))
× (∀ a x → memb₁ a x ≡ memb₂ a (e .fst x))
Multi-Set-is-SNS : SNS {ℓ₁ = ℓ} multi-set-structure multi-set-iso
Multi-Set-is-SNS =
join-SNS pointed-iso pointed-is-SNS
{S₂ = λ X → (left-action-structure X) × (member-structure X)}
(λ B C e → (∀ a q → e .fst (B .snd .fst a q) ≡ C .snd .fst a (e .fst q))
× (∀ a x → (B .snd .snd a x) ≡ (C .snd .snd a (e .fst x))))
(join-SNS left-action-iso Left-Action-is-SNS member-iso Member-is-SNS)
| {
"alphanum_fraction": 0.6489963973,
"avg_line_length": 32.9322033898,
"ext": "agda",
"hexsha": "74b83bb63a83a8df8e152246177f0453c7f5d734",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c67854d2e11aafa5677e25a09087e176fafd3e43",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cmester0/cubical",
"max_forks_repo_path": "Cubical/Structures/MultiSet.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c67854d2e11aafa5677e25a09087e176fafd3e43",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cmester0/cubical",
"max_issues_repo_path": "Cubical/Structures/MultiSet.agda",
"max_line_length": 85,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "c67854d2e11aafa5677e25a09087e176fafd3e43",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cmester0/cubical",
"max_stars_repo_path": "Cubical/Structures/MultiSet.agda",
"max_stars_repo_stars_event_max_datetime": "2020-03-23T23:52:11.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-03-23T23:52:11.000Z",
"num_tokens": 643,
"size": 1943
} |
{-# OPTIONS --without-K #-}
module Swaps where
-- Intermediate representation of permutations to prove soundness and
-- completeness
open import Level using (Level; _⊔_) renaming (zero to lzero; suc to lsuc)
open import Relation.Binary.PropositionalEquality
using (_≡_; refl; sym; trans; subst; subst₂; cong; cong₂; setoid;
inspect; [_]; proof-irrelevance; module ≡-Reasoning)
open import Relation.Binary.PropositionalEquality.TrustMe
using (trustMe)
open import Relation.Nullary using (Dec; yes; no; ¬_)
open import Data.Nat.Properties
using (m≢1+m+n; i+j≡0⇒i≡0; i+j≡0⇒j≡0; n≤m+n)
open import Data.Nat.Properties.Simple
using (+-right-identity; +-suc; +-assoc; +-comm;
*-assoc; *-comm; *-right-zero; distribʳ-*-+)
open import Data.Nat.DivMod using (_mod_)
open import Relation.Binary using (Rel; Decidable; Setoid)
open import Relation.Binary.Core using (Transitive)
open import Data.String using (String)
renaming (_++_ to _++S_)
open import Data.Nat.Show using (show)
open import Data.Bool using (Bool; false; true; T)
open import Data.Nat using (ℕ; suc; _+_; _∸_; _*_; _<_; _≮_; _≤_; _≰_;
z≤n; s≤s; _≟_; _≤?_; module ≤-Reasoning)
open import Data.Fin
using (Fin; zero; suc; toℕ; fromℕ; _ℕ-_; _≺_;
raise; inject+; inject₁; inject≤; _≻toℕ_)
renaming (_+_ to _F+_)
open import Data.Fin.Properties using (bounded; inject+-lemma)
open import Data.Vec.Properties
using (lookup∘tabulate; tabulate∘lookup; lookup-allFin; tabulate-∘;
tabulate-allFin; map-id; allFin-map)
open import Data.List
using (List; []; _∷_; _∷ʳ_; foldl; replicate; reverse; downFrom;
concatMap; gfilter; initLast; InitLast; _∷ʳ'_)
renaming (_++_ to _++L_; map to mapL; concat to concatL; zip to zipL)
open import Data.List.NonEmpty
using (List⁺; module List⁺; [_]; _∷⁺_; head; last; _⁺++_)
renaming (toList to nonEmptyListtoList; _∷ʳ_ to _n∷ʳ_; tail to ntail)
open List⁺ public
open import Data.List.Any using (Any; here; there; any; module Membership)
open import Data.Maybe using (Maybe; nothing; just; maybe′)
open import Data.Vec
using (Vec; tabulate; []; _∷_; tail; lookup; zip; zipWith; splitAt;
_[_]≔_; allFin; toList)
renaming (_++_ to _++V_; map to mapV; concat to concatV)
open import Function using (id; _∘_; _$_)
open import Data.Empty using (⊥; ⊥-elim)
open import Data.Unit using (⊤; tt)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Product using (Σ; _×_; _,_; proj₁; proj₂)
open import Cauchy
open import Perm
open import Proofs
open import CauchyProofs
open import CauchyProofsT
open import CauchyProofsS
open import Groupoid
open import PiLevel0
------------------------------------------------------------------------------
-- Representation of a permutation as a product of "transpositions."
-- This product is not commutative; we apply it from left to
-- right. Because we eventually want to normalize permutations to some
-- canonical representation, we insist that the first component of a
-- transposition is always ≤ than the second
infix 90 _X_
data Transposition (n : ℕ) : Set where
_X_ : (i j : Fin n) → {p : toℕ i ≤ toℕ j} → Transposition n
i≰j→j≤i : (i j : ℕ) → (i ≰ j) → (j ≤ i)
i≰j→j≤i i 0 p = z≤n
i≰j→j≤i 0 (suc j) p with p z≤n
i≰j→j≤i 0 (suc j) p | ()
i≰j→j≤i (suc i) (suc j) p with i ≤? j
i≰j→j≤i (suc i) (suc j) p | yes p' with p (s≤s p')
i≰j→j≤i (suc i) (suc j) p | yes p' | ()
i≰j→j≤i (suc i) (suc j) p | no p' = s≤s (i≰j→j≤i i j p')
mkTransposition : {n : ℕ} → (i j : Fin n) → Transposition n
mkTransposition {n} i j with toℕ i ≤? toℕ j
... | yes p = _X_ i j {p}
... | no p = _X_ j i {i≰j→j≤i (toℕ i) (toℕ j) p}
Transposition* : ℕ → Set
Transposition* n = List (Transposition n)
-- Representation of a permutation as a product of cycles where each
-- cycle is a non-empty sequence of indices
Cycle : ℕ → Set
Cycle n = List⁺ (Fin n)
Cycle* : ℕ → Set
Cycle* n = List (Cycle n)
-- Convert cycles to products of transpositions
cycle→transposition* : ∀ {n} → Cycle n → Transposition* n
cycle→transposition* c = mapL (mkTransposition (head c)) (reverse (ntail c))
cycle*→transposition* : ∀ {n} → Cycle* n → Transposition* n
cycle*→transposition* cs = concatMap cycle→transposition* cs
-- Convert from Cauchy representation to product of cycles
-- Helper that checks if there is a cycle that starts at i
-- Returns the cycle containing i and the rest of the permutation
-- without that cycle
findCycle : ∀ {n} → Fin n → Cycle* n → Maybe (Cycle n × Cycle* n)
findCycle i [] = nothing
findCycle i (c ∷ cs) with toℕ i ≟ toℕ (head c)
findCycle i (c ∷ cs) | yes _ = just (c , cs)
findCycle i (c ∷ cs) | no _ =
maybe′ (λ { (c' , cs') → just (c' , c ∷ cs') }) nothing (findCycle i cs)
-- Another helper that repeatedly tries to merge smaller cycles
{-# NO_TERMINATION_CHECK #-}
mergeCycles : ∀ {n} → Cycle* n → Cycle* n
mergeCycles [] = []
mergeCycles (c ∷ cs) with findCycle (last c) cs
mergeCycles (c ∷ cs) | nothing = c ∷ mergeCycles cs
mergeCycles (c ∷ cs) | just (c' , cs') = mergeCycles ((c ⁺++ ntail c') ∷ cs')
-- To convert a Cauchy representation to a product of cycles, just create
-- a cycle of size 2 for each entry and then merge the cycles
cauchy→cycle* : ∀ {n} → Cauchy n → Cycle* n
cauchy→cycle* {n} perm =
mergeCycles
(toList (zipWith (λ i j → i ∷⁺ Data.List.NonEmpty.[ j ]) (allFin n) perm))
-- Cauchy to product of transpostions
cauchy→transposition* : ∀ {n} → Cauchy n → Transposition* n
cauchy→transposition* = cycle*→transposition* ∘ cauchy→cycle*
------------------------------------------------------------------------------
-- Main functions
-- A permutation between t₁ and t₂ has three components in the Cauchy
-- representation: the map π of each element to a new position and a
-- proof that the sizes of the domain and range are the same and that
-- the map is injective.
TPermutation : U → U → Set
TPermutation t₁ t₂ = size t₁ ≡ size t₂ × Permutation (size t₁)
-- A view of (t : U) as normalized types.
-- Let size t be n then the normalized version of t is the type
-- (1 + (1 + (1 + (1 + ... 0)))) i.e. Fin n.
fromSize : ℕ → U
fromSize 0 = ZERO
fromSize (suc n) = PLUS ONE (fromSize n)
canonicalU : U → U
canonicalU = fromSize ∘ size
size+ : (n₁ n₂ : ℕ) → PLUS (fromSize n₁) (fromSize n₂) ⟷ fromSize (n₁ + n₂)
size+ 0 n₂ = unite₊
size+ (suc n₁) n₂ = assocr₊ ◎ (id⟷ ⊕ size+ n₁ n₂)
size* : (n₁ n₂ : ℕ) → TIMES (fromSize n₁) (fromSize n₂) ⟷ fromSize (n₁ * n₂)
size* 0 n₂ = absorbr
size* (suc n₁) n₂ = dist ◎ (unite⋆ ⊕ size* n₁ n₂) ◎ size+ n₂ (n₁ * n₂)
normalizeC : (t : U) → t ⟷ canonicalU t
normalizeC ZERO = id⟷
normalizeC ONE = uniti₊ ◎ swap₊
normalizeC (PLUS t₀ t₁) =
(normalizeC t₀ ⊕ normalizeC t₁) ◎ size+ (size t₀) (size t₁)
normalizeC (TIMES t₀ t₁) =
(normalizeC t₀ ⊗ normalizeC t₁) ◎ size* (size t₀) (size t₁)
-- Given a normalized type Fin n and two indices 'a' and 'b' generate the code
-- to swap the two indices. Ex:
-- swapFin {3} "0" "1" should produce the permutation:
-- assocl₊ ◎ (swap₊ ⊕ id⟷) ◎ assocr₊ :
-- PLUS ONE (PLUS ONE (PLUS ONE ZERO)) ⟷ PLUS ONE (PLUS ONE (PLUS ONE ZERO))
swapFin : {n : ℕ} → (a b : Fin n) → (leq : toℕ a ≤ toℕ b) → fromSize n ⟷ fromSize n
swapFin zero zero z≤n = id⟷
swapFin zero (suc zero) z≤n = assocl₊ ◎ (swap₊ ⊕ id⟷) ◎ assocr₊
swapFin zero (suc (suc b)) z≤n =
(assocl₊ ◎ (swap₊ ⊕ id⟷) ◎ assocr₊) ◎
(id⟷ ⊕ swapFin zero (suc b) z≤n) ◎
(assocl₊ ◎ (swap₊ ⊕ id⟷) ◎ assocr₊)
swapFin (suc a) zero ()
swapFin (suc a) (suc b) (s≤s leq) = id⟷ ⊕ swapFin a b leq
-- permutation to combinator
transposition*2c : (m n : ℕ) (m≡n : m ≡ n) → Transposition* m →
(fromSize m ⟷ fromSize n)
transposition*2c m n m≡n [] rewrite m≡n = id⟷
transposition*2c m n m≡n (_X_ i j {leq} ∷ π) rewrite m≡n =
swapFin i j leq ◎ transposition*2c n n refl π
perm2c : {t₁ t₂ : U} → TPermutation t₁ t₂ → (t₁ ⟷ t₂)
perm2c {t₁} {t₂} (s₁≡s₂ , (π , inj)) =
normalizeC t₁ ◎
transposition*2c (size t₁) (size t₂) s₁≡s₂ (cauchy→transposition* π) ◎
(! (normalizeC t₂))
------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.6361733563,
"avg_line_length": 36.9181818182,
"ext": "agda",
"hexsha": "9d15a57e417567b5b0bd3ee6117d6a1f247be85a",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "Univalence/Swaps.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "Univalence/Obsolete/Swaps.agda",
"max_line_length": 83,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "Univalence/Swaps.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 2917,
"size": 8122
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Example showing how the free monad construction on containers can be
-- used
------------------------------------------------------------------------
module README.Container.FreeMonad where
open import Category.Monad
open import Data.Empty
open import Data.Unit
open import Data.Bool
open import Data.Nat
open import Data.Sum using (inj₁; inj₂)
open import Data.Product renaming (_×_ to _⟨×⟩_)
open import Data.Container
open import Data.Container.Combinator
open import Data.Container.FreeMonad
open import Data.W
open import Relation.Binary.PropositionalEquality
------------------------------------------------------------------------
-- The signature of state and its (generic) operations.
State : Set → Container _
State S = ⊤ ⟶ S ⊎ S ⟶ ⊤
where
_⟶_ : Set → Set → Container _
I ⟶ O = I ▷ λ _ → O
get : ∀ {S} → State S ⋆ S
get = do (inj₁ _ , return)
where
open RawMonad rawMonad
put : ∀ {S} → S → State S ⋆ ⊤
put s = do (inj₂ s , return)
where
open RawMonad rawMonad
-- Using the above we can, for example, write a stateful program that
-- delivers a boolean.
prog : State ℕ ⋆ Bool
prog =
get >>= λ n →
put (suc n) >>
return true
where
open RawMonad rawMonad
runState : ∀ {S X} → State S ⋆ X → (S → X ⟨×⟩ S)
runState (sup (inj₁ x) _) = λ s → x , s
runState (sup (inj₂ (inj₁ _)) k) = λ s → runState (k s) s
runState (sup (inj₂ (inj₂ s)) k) = λ _ → runState (k _) s
test : runState prog 0 ≡ true , 1
test = refl
-- It should be noted that @State S ⋆ X@ is not the state monad. If we
-- could quotient @State S ⋆ X@ by the seven axioms of state (see
-- Plotkin and Power's "Notions of Computation Determine Monads", 2002)
-- then we would get the state monad.
| {
"alphanum_fraction": 0.5929592959,
"avg_line_length": 27.9692307692,
"ext": "agda",
"hexsha": "d2cbd1a35e49c8e2f144f549efeb8aa8f1f67144",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/README/Container/FreeMonad.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/README/Container/FreeMonad.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/README/Container/FreeMonad.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 520,
"size": 1818
} |
{-# OPTIONS --cubical --safe #-}
module Container.List where
open import Prelude
open import Data.Fin
open import Container
List : Type a → Type a
List = ⟦ ℕ , Fin ⟧
| {
"alphanum_fraction": 0.6923076923,
"avg_line_length": 15.3636363636,
"ext": "agda",
"hexsha": "f1f608da25ab678b5e97647cb6900fbd4558cf50",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Container/List.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Container/List.agda",
"max_line_length": 32,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Container/List.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 46,
"size": 169
} |
{-# OPTIONS --allow-unsolved-metas #-}
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
test : (x y : Nat) → x ≡ y → x ≡ 1 → y ≡ 1 → Nat
test (suc zero) (suc zero) refl refl refl = {!!}
| {
"alphanum_fraction": 0.6237623762,
"avg_line_length": 25.25,
"ext": "agda",
"hexsha": "964225079fb883e9b88b83ab2d01a099a39cc445",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue2855.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue2855.agda",
"max_line_length": 48,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue2855.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 73,
"size": 202
} |
open import Prelude
module Implicits.Syntax where
open import Implicits.Syntax.Type public
open import Implicits.Syntax.Term public
open import Implicits.Syntax.Context public
| {
"alphanum_fraction": 0.8483146067,
"avg_line_length": 22.25,
"ext": "agda",
"hexsha": "86967cef955e1415dbb2d88e214fe4088ace91ef",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Syntax.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Syntax.agda",
"max_line_length": 43,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Syntax.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 38,
"size": 178
} |
-- Enriched categories
{-# OPTIONS --safe #-}
module Cubical.Categories.Monoidal.Enriched where
open import Cubical.Categories.Monoidal.Base
open import Cubical.Foundations.Prelude
module _ {ℓV ℓV' : Level} (V : MonoidalCategory ℓV ℓV') (ℓE : Level) where
open MonoidalCategory V
renaming (ob to obV; Hom[_,_] to V[_,_]; id to idV; _⋆_ to _⋆V_)
record EnrichedCategory : Type (ℓ-max (ℓ-max ℓV ℓV') (ℓ-suc ℓE)) where
field
ob : Type ℓE
Hom[_,_] : ob → ob → obV
id : ∀ {x} → V[ unit , Hom[ x , x ] ]
seq : ∀ x y z → V[ Hom[ x , y ] ⊗ Hom[ y , z ] , Hom[ x , z ] ]
-- Axioms
⋆IdL : ∀ x y → η⟨ _ ⟩ ≡ (id {x} ⊗ₕ idV) ⋆V (seq x x y)
⋆IdR : ∀ x y → ρ⟨ _ ⟩ ≡ (idV ⊗ₕ id {y}) ⋆V (seq x y y)
⋆Assoc : ∀ x y z w →
α⟨ _ , _ , _ ⟩ ⋆V ((seq x y z) ⊗ₕ idV) ⋆V (seq x z w)
≡ (idV ⊗ₕ (seq y z w)) ⋆V (seq x y w)
-- TODO: define underlying category using Hom[ x , y ] := V[ unit , Hom[ x , y ] ]
| {
"alphanum_fraction": 0.5084915085,
"avg_line_length": 33.3666666667,
"ext": "agda",
"hexsha": "c7ea5d60ada8c5d73e9ba684849a5d5f2c1d19c2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Seanpm2001-web/cubical",
"max_forks_repo_path": "Cubical/Categories/Monoidal/Enriched.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Seanpm2001-web/cubical",
"max_issues_repo_path": "Cubical/Categories/Monoidal/Enriched.agda",
"max_line_length": 82,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9acdecfa6437ec455568be4e5ff04849cc2bc13b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "FernandoLarrain/cubical",
"max_stars_repo_path": "Cubical/Categories/Monoidal/Enriched.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-05T00:28:39.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-03-05T00:28:39.000Z",
"num_tokens": 436,
"size": 1001
} |
{-
--{-# OPTIONS --allow-unsolved-metas #-}
--{-# OPTIONS -v 100 #-}
{- Yellow highlighting should be accompanied by an error message -}
{- By default, command-line agda reports "unsolved metas" and gives a source-code location, but no information about the nature of the unsolved metas. (Emacs agda gives only yellow-highlighting.). With Without increasing verbosity (via "-v 100") -}
postulate
yellow-highlighting-but-no-error-message : Set _
{- --allow-unsolved-metas -}
{-
Running from the command-line, agda reports that there are unsolved metas but doesn't say anything about what they are. Is there a way to increase verbosity about the unsolved metas?
-}
postulate
error-message-but-no-link-to-source-code-location : _ _
-}
postulate
Σ : (A : Set) (B : A → Set) → Set
X : Set
confusing-message--not-empty-type-of-sizes : Σ _ λ x → X
confusing-message--not-empty-type-of-sizes = {!!}
| {
"alphanum_fraction": 0.7144432194,
"avg_line_length": 34.8846153846,
"ext": "agda",
"hexsha": "ac4ff476fc9dfba50f8fae3151fa841b01904d85",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-1/Bug-confusing-sizes-message.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-1/Bug-confusing-sizes-message.agda",
"max_line_length": 250,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-1/Bug-confusing-sizes-message.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 239,
"size": 907
} |
------------------------------------------------------------------------------
-- Testing the non-internal ATP equality
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module NonInternalEquality where
postulate D : Set
data _≡_ (x : D) : D → Set where
refl : x ≡ x
{-# ATP axiom refl #-}
postulate foo : ∀ x → x ≡ x
{-# ATP prove foo #-}
| {
"alphanum_fraction": 0.3941605839,
"avg_line_length": 27.4,
"ext": "agda",
"hexsha": "65fbbaf9796af78cdf7b2e02f6d245059a54dbc8",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z",
"max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/apia",
"max_forks_repo_path": "test/Succeed/fol-theorems/NonInternalEquality.agda",
"max_issues_count": 121,
"max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/apia",
"max_issues_repo_path": "test/Succeed/fol-theorems/NonInternalEquality.agda",
"max_line_length": 78,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/apia",
"max_stars_repo_path": "test/Succeed/fol-theorems/NonInternalEquality.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z",
"num_tokens": 103,
"size": 548
} |
{-# OPTIONS --without-K --safe #-}
-- A Monad in a Bicategory.
-- For the more elementary version of Monads, see 'Categories.Monad'.
module Categories.Bicategory.Monad where
open import Level
open import Data.Product using (_,_)
open import Categories.Bicategory
import Categories.Bicategory.Extras as Bicat
open import Categories.NaturalTransformation.NaturalIsomorphism using (NaturalIsomorphism)
record Monad {o ℓ e t} (𝒞 : Bicategory o ℓ e t) : Set (o ⊔ ℓ ⊔ e ⊔ t) where
open Bicat 𝒞
field
C : Obj
T : C ⇒₁ C
η : id₁ ⇒₂ T
μ : (T ⊚₀ T) ⇒₂ T
assoc : μ ∘ᵥ (T ▷ μ) ∘ᵥ associator.from ≈ (μ ∘ᵥ (μ ◁ T))
sym-assoc : μ ∘ᵥ (μ ◁ T) ∘ᵥ associator.to ≈ (μ ∘ᵥ (T ▷ μ))
identityˡ : μ ∘ᵥ (T ▷ η) ∘ᵥ unitorʳ.to ≈ id₂
identityʳ : μ ∘ᵥ (η ◁ T) ∘ᵥ unitorˡ.to ≈ id₂
| {
"alphanum_fraction": 0.6361355082,
"avg_line_length": 28.4642857143,
"ext": "agda",
"hexsha": "b78750c067cc0913374f11644c8757e3c54385e1",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Bicategory/Monad.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Bicategory/Monad.agda",
"max_line_length": 90,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Bicategory/Monad.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 322,
"size": 797
} |
{-# OPTIONS --without-K #-}
open import lib.Basics
-- open import lib.NType2
-- open import lib.PathGroupoid
open import lib.types.Bool
open import lib.types.IteratedSuspension
open import lib.types.Lift
open import lib.types.LoopSpace
open import lib.types.Nat
open import lib.types.Paths
open import lib.types.Pi
open import lib.types.Pointed
open import lib.types.Sigma
open import lib.types.Suspension
open import lib.types.TLevel
open import lib.types.Unit
module nicolai.pseudotruncations.Preliminary-definitions where
-- definition of weak constancy
wconst : ∀ {i j} {A : Type i} {B : Type j} → (A → B) → Type (lmax i j)
wconst {A = A} f = (a₁ a₂ : A) → f a₁ == f a₂
{- Pointed maps (without the 'point') -}
_→̇_ : ∀ {i j} (Â : Ptd i) (B̂ : Ptd j) → Type _
 →̇ B̂ = fst ( ⊙→ B̂)
{- It is useful to have a lemma which allows to construct equalities
between pointed types. Of course, we know that such an equality
is a pair of equalities; however, transporting a function can
make things more tedious than necessary! -}
make-=-∙ : ∀ {i j} {Â : Ptd i} {B̂ : Ptd j} (f̂ ĝ : Â →̇ B̂)
(p : fst f̂ == fst ĝ)
→ ! (app= p (snd Â)) ∙ snd f̂ == snd ĝ
→ f̂ == ĝ
make-=-∙ (f , p) (.f , q) idp t = pair= idp t
{- A lemma that allows to prove that the value of a map between
pointed maps, at some given point, is some given point.
This would otherwise be an involved nesting of transports/
PathOvers. -}
→̇-maps-to : ∀ {i} {Â B̂ Ĉ D̂ : Ptd i} (F̂ : (Â →̇ B̂) → (Ĉ →̇ D̂))
(f̂ : Â →̇ B̂) (ĝ : Ĉ →̇ D̂)
(p : fst (F̂ f̂) == (fst ĝ))
(q : (app= p (snd Ĉ)) ∙ (snd ĝ) == snd (F̂ f̂))
→ F̂ f̂ == ĝ
→̇-maps-to F̂ f̂ (.(fst (F̂ f̂)) , .(snd (F̂ f̂))) idp idp = idp
{- Also trivial: make pointed equivalences from an ordinary equality -}
coe-equiv∙ : ∀ {i} {Â B̂ : Ptd i} → (Â == B̂) → Â ⊙≃ B̂
coe-equiv∙ idp = (idf _ , idp) , idf-is-equiv _
module _ {i} where
{- Of course, spheres are defined in the library.
Unfortunately, they do not play well together with iterated suspension.
If f is an endofunction, one can define [f^Sn] either as [f^n ∘ f] or as
[f ∘ f^n]. It turns out that it is much more convenient if one chooses
different possibilites for Ω and for Σ (suspension), as the adjunction
can then be handled much more directly.
In summary: It's best to redefine spheres. -}
⊙Susp-iter' : (n : ℕ) (Â : Ptd i) → Ptd i
⊙Susp-iter' O Â = Â
⊙Susp-iter' (S n) Â = ⊙Susp-iter' n (⊙Susp Â)
{- compare: definition of iterated Ω
⊙Ω-iter : (n : ℕ) (Â : Ptd i) → Ptd i
⊙Ω-iter O Â = Â
⊙Ω-iter (S n) Â = ⊙Ω (⊙Ω-iter n Â)
-}
⊙Sphere' : (n : ℕ) → Ptd i
⊙Sphere' n = ⊙Susp-iter' n (⊙Lift ⊙Bool)
Sphere' : (n : ℕ) → Type i
Sphere' = fst ∘ ⊙Sphere'
nor' : (n : ℕ) → Sphere' n
nor' = snd ∘ ⊙Sphere'
{- Unfortunately, we will sometimes still need the "other" behaviour of the sphere.
Thus, we show at least the following: -}
⊙Susp-iter : (n : ℕ) (Â : Ptd i) → Ptd i
⊙Susp-iter O Â = Â
⊙Susp-iter (S n) Â = ⊙Susp (⊙Susp-iter n Â)
⊙Sphere* : (n : ℕ) → Ptd i
⊙Sphere* n = ⊙Susp-iter n (⊙Lift ⊙Bool)
Sphere* : (n : ℕ) → Type i
Sphere* = fst ∘ ⊙Sphere*
{- Of course, this proof could be done for all endofunctions. -}
susp-iter= : (n : ℕ) ( : Ptd i) → ⊙Susp-iter' n  == ⊙Susp-iter n Â
susp-iter= O Â = idp
susp-iter= (S O) Â = idp
susp-iter= (S (S n)) Â =
⊙Susp-iter' (S (S n)) Â
=⟨ susp-iter= (S n) (⊙Susp Â) ⟩
⊙Susp (⊙Susp-iter n (⊙Susp Â))
=⟨ ap ⊙Susp (! (susp-iter= n (⊙Susp Â))) ⟩
⊙Susp (⊙Susp-iter' (S n) Â)
=⟨ ap ⊙Susp (susp-iter= (S n) Â) ⟩
⊙Susp-iter (S (S n)) Â
∎
{- Thus, we have for the spheres: -}
⊙Spheres= : (n : ℕ) → ⊙Sphere' n == ⊙Sphere* n
⊙Spheres= n = susp-iter= n (⊙Lift ⊙Bool)
Spheres= : (n : ℕ) → Sphere' n == Sphere* n
Spheres= n = ap fst (⊙Spheres= n)
{- Also, we have this: -}
susp'-switch : (n : ℕ) → ⊙Sphere' (S n) == ⊙Susp (⊙Sphere' n)
susp'-switch n = (⊙Spheres= (S n)) ∙ (ap ⊙Susp (! (⊙Spheres= n)))
| {
"alphanum_fraction": 0.5600961538,
"avg_line_length": 31.7557251908,
"ext": "agda",
"hexsha": "99441cfcca3933fafd17c81c881278d1bb21e5d5",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "nicolai/pseudotruncations/Preliminary-definitions.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "nicolai/pseudotruncations/Preliminary-definitions.agda",
"max_line_length": 85,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nicolaikraus/HoTT-Agda",
"max_stars_repo_path": "nicolai/pseudotruncations/Preliminary-definitions.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z",
"num_tokens": 1738,
"size": 4160
} |
-- Andreas, Bentfest 2016-04-28 Marsstrand
-- Issue 1944: also resolve overloaded projections in checking position
module _ (A : Set) (a : A) where
record R B : Set where
field f : B
open R
record S B : Set where
field f : B
open S
test : ∀{A : Set} → A → A
test = f
-- Expected error:
-- Cannot resolve overloaded projection f because first visible
-- argument is not of record type
-- when checking that the expression f has type .A → .A
| {
"alphanum_fraction": 0.6941964286,
"avg_line_length": 22.4,
"ext": "agda",
"hexsha": "b15a6482290db74d96a1cbbcb4279f2a7059a6c1",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-09-15T14:36:15.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-09-15T14:36:15.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue1944-UnappliedOverloadedProjectionNotRecord.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "hborum/agda",
"max_issues_repo_path": "test/Fail/Issue1944-UnappliedOverloadedProjectionNotRecord.agda",
"max_line_length": 71,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/Fail/Issue1944-UnappliedOverloadedProjectionNotRecord.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 129,
"size": 448
} |
open import Relation.Binary using (Rel)
open import Algebra.Bundles using (CommutativeRing)
open import Algebra.Module.Normed
module Algebra.Module.Limit.Compose
{r ℓr} {CR : CommutativeRing r ℓr}
(open CommutativeRing CR using () renaming (Carrier to X))
{rel} {_≤_ : Rel X rel}
{ma ℓma} (MA : NormedModule CR _≤_ ma ℓma)
{mb ℓmb} (MB : NormedModule CR _≤_ mb ℓmb)
{mc ℓmc} (MC : NormedModule CR _≤_ mc ℓmc)
where
open import Data.Product using (_,_)
open import Function using (_∘_)
open CommutativeRing CR
open import Assume using (assume)
import Algebra.Module.Limit as Limit
open Limit MA MB using () renaming
( _DifferentiableAt_ to _DifferentiableAt₁₂_
; Differentiable to Differentiable₁₂
)
open Limit MB MC using () renaming
(_DifferentiableAt_ to _DifferentiableAt₂₃_
; Differentiable to Differentiable₂₃
)
open Limit MA MC using () renaming
(_DifferentiableAt_ to _DifferentiableAt₁₃_
; Differentiable to Differentiable₁₃
)
private
module MA = NormedModule MA
module MB = NormedModule MB
module MC = NormedModule MC
∘-differentiable-at : ∀ {g f x} → g DifferentiableAt₂₃ (f x) → f DifferentiableAt₁₂ x → (g ∘ f) DifferentiableAt₁₃ x
∘-differentiable-at {g} {f} {x} (Dg , _) (Df , _) = (Dg ∘ Df) , assume
∘-differentiable : ∀ {g f} → Differentiable₂₃ g → Differentiable₁₂ f → Differentiable₁₃ (g ∘ f)
∘-differentiable {g} {f} diff-g diff-f = λ x → ∘-differentiable-at {g} {f} {x} (diff-g (f x)) (diff-f x)
| {
"alphanum_fraction": 0.7146757679,
"avg_line_length": 30.5208333333,
"ext": "agda",
"hexsha": "be7efe01828d1329c8423eeebeceaed58fc17e6f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a193aeebf1326f960975b19d3e31b46fddbbfaa2",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "cspollard/reals",
"max_forks_repo_path": "src/Algebra/Module/Limit/Compose.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a193aeebf1326f960975b19d3e31b46fddbbfaa2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC0-1.0"
],
"max_issues_repo_name": "cspollard/reals",
"max_issues_repo_path": "src/Algebra/Module/Limit/Compose.agda",
"max_line_length": 116,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a193aeebf1326f960975b19d3e31b46fddbbfaa2",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "cspollard/reals",
"max_stars_repo_path": "src/Algebra/Module/Limit/Compose.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 497,
"size": 1465
} |
{-# OPTIONS --cubical --safe #-}
module Data.Binary.Addition.Properties where
open import Prelude
open import Data.Binary.Definition
open import Data.Binary.Addition
open import Data.Binary.Conversion
import Data.Nat as ℕ
import Data.Nat.Properties as ℕ
open import Path.Reasoning
open import Data.Binary.Isomorphism
+-cong : ∀ xs ys → ⟦ xs + ys ⇓⟧ ≡ ⟦ xs ⇓⟧ ℕ.+ ⟦ ys ⇓⟧
add₁-cong : ∀ xs ys → ⟦ add₁ xs ys ⇓⟧ ≡ 1 ℕ.+ ⟦ xs ⇓⟧ ℕ.+ ⟦ ys ⇓⟧
add₂-cong : ∀ xs ys → ⟦ add₂ xs ys ⇓⟧ ≡ 2 ℕ.+ ⟦ xs ⇓⟧ ℕ.+ ⟦ ys ⇓⟧
lemma₁ : ∀ xs ys → ⟦ add₁ xs ys ⇓⟧ ℕ.* 2 ≡ ⟦ xs ⇓⟧ ℕ.* 2 ℕ.+ (2 ℕ.+ ⟦ ys ⇓⟧ ℕ.* 2)
lemma₁ xs ys =
⟦ add₁ xs ys ⇓⟧ ℕ.* 2 ≡⟨ cong (ℕ._* 2) (add₁-cong xs ys) ⟩
2 ℕ.+ (⟦ xs ⇓⟧ ℕ.+ ⟦ ys ⇓⟧) ℕ.* 2 ≡⟨ cong (2 ℕ.+_ ) (ℕ.+-*-distrib ⟦ xs ⇓⟧ ⟦ ys ⇓⟧ 2) ⟩
2 ℕ.+ ⟦ xs ⇓⟧ ℕ.* 2 ℕ.+ ⟦ ys ⇓⟧ ℕ.* 2 ≡⟨ cong (ℕ._+ (⟦ ys ⇓⟧ ℕ.* 2)) (ℕ.+-comm 2 (⟦ xs ⇓⟧ ℕ.* 2)) ⟩
⟦ xs ⇓⟧ ℕ.* 2 ℕ.+ 2 ℕ.+ ⟦ ys ⇓⟧ ℕ.* 2 ≡⟨ ℕ.+-assoc (⟦ xs ⇓⟧ ℕ.* 2) 2 (⟦ ys ⇓⟧ ℕ.* 2) ⟩
⟦ xs ⇓⟧ ℕ.* 2 ℕ.+ (2 ℕ.+ ⟦ ys ⇓⟧ ℕ.* 2) ∎
lemma₂ : ∀ xs ys → ⟦ add₁ xs ys ⇓⟧ ℕ.* 2 ≡ (1 ℕ.+ ⟦ xs ⇓⟧ ℕ.* 2) ℕ.+ (1 ℕ.+ ⟦ ys ⇓⟧ ℕ.* 2)
lemma₂ xs ys =
⟦ add₁ xs ys ⇓⟧ ℕ.* 2 ≡⟨ cong (ℕ._* 2) (add₁-cong xs ys) ⟩
(1 ℕ.+ ⟦ xs ⇓⟧ ℕ.+ ⟦ ys ⇓⟧) ℕ.* 2 ≡⟨ ℕ.+-*-distrib (1 ℕ.+ ⟦ xs ⇓⟧) ⟦ ys ⇓⟧ 2 ⟩
2 ℕ.+ ⟦ xs ⇓⟧ ℕ.* 2 ℕ.+ ⟦ ys ⇓⟧ ℕ.* 2 ≡˘⟨ ℕ.+-suc (1 ℕ.+ ⟦ xs ⇓⟧ ℕ.* 2) (⟦ ys ⇓⟧ ℕ.* 2) ⟩
(1 ℕ.+ ⟦ xs ⇓⟧ ℕ.* 2) ℕ.+ (1 ℕ.+ ⟦ ys ⇓⟧ ℕ.* 2) ∎
lemma₃ : ∀ xs ys → ⟦ add₂ xs ys ⇓⟧ ℕ.* 2 ≡ suc (suc (⟦ xs ⇓⟧ ℕ.* 2 ℕ.+ suc (suc (⟦ ys ⇓⟧ ℕ.* 2))))
lemma₃ xs ys =
⟦ add₂ xs ys ⇓⟧ ℕ.* 2 ≡⟨ cong (ℕ._* 2) (add₂-cong xs ys) ⟩
(2 ℕ.+ ⟦ xs ⇓⟧ ℕ.+ ⟦ ys ⇓⟧) ℕ.* 2 ≡˘⟨ cong (ℕ._* 2) (ℕ.+-suc (1 ℕ.+ ⟦ xs ⇓⟧) ⟦ ys ⇓⟧) ⟩
((1 ℕ.+ ⟦ xs ⇓⟧) ℕ.+ (1 ℕ.+ ⟦ ys ⇓⟧)) ℕ.* 2 ≡⟨ ℕ.+-*-distrib (1 ℕ.+ ⟦ xs ⇓⟧) (1 ℕ.+ ⟦ ys ⇓⟧) 2 ⟩
suc (suc (⟦ xs ⇓⟧ ℕ.* 2 ℕ.+ suc (suc (⟦ ys ⇓⟧ ℕ.* 2)))) ∎
add₁-cong 0ᵇ ys = inc-suc ys
add₁-cong (1ᵇ xs) 0ᵇ = cong (2 ℕ.+_) (sym (ℕ.+-idʳ (⟦ xs ⇓⟧ ℕ.* 2)))
add₁-cong (2ᵇ xs) 0ᵇ = cong suc (cong (ℕ._* 2) (inc-suc xs) ; cong (2 ℕ.+_) (sym (ℕ.+-idʳ (⟦ xs ⇓⟧ ℕ.* 2))))
add₁-cong (1ᵇ xs) (1ᵇ ys) = cong suc (lemma₂ xs ys)
add₁-cong (1ᵇ xs) (2ᵇ ys) = cong (2 ℕ.+_) (lemma₁ xs ys)
add₁-cong (2ᵇ xs) (1ᵇ ys) = cong (2 ℕ.+_) (lemma₂ xs ys)
add₁-cong (2ᵇ xs) (2ᵇ ys) = cong (1 ℕ.+_) (lemma₃ xs ys)
add₂-cong 0ᵇ 0ᵇ = refl
add₂-cong 0ᵇ (1ᵇ ys) = cong (1 ℕ.+_) (cong (ℕ._* 2) (inc-suc ys))
add₂-cong 0ᵇ (2ᵇ ys) = cong (2 ℕ.+_) (cong (ℕ._* 2) (inc-suc ys))
add₂-cong (1ᵇ xs) 0ᵇ = cong (1 ℕ.+_) ((cong (ℕ._* 2) (inc-suc xs)) ; cong (2 ℕ.+_) (sym (ℕ.+-idʳ _)))
add₂-cong (2ᵇ xs) 0ᵇ = cong (2 ℕ.+_) ((cong (ℕ._* 2) (inc-suc xs)) ; cong (2 ℕ.+_) (sym (ℕ.+-idʳ _)))
add₂-cong (1ᵇ xs) (1ᵇ ys) = cong (2 ℕ.+_ ) (lemma₂ xs ys)
add₂-cong (1ᵇ xs) (2ᵇ ys) = cong (1 ℕ.+_) (lemma₃ xs ys)
add₂-cong (2ᵇ xs) (1ᵇ ys) = cong (1 ℕ.+_) (lemma₃ xs ys ; ℕ.+-suc (2 ℕ.+ ⟦ xs ⇓⟧ ℕ.* 2) (1 ℕ.+ ⟦ ys ⇓⟧ ℕ.* 2))
add₂-cong (2ᵇ xs) (2ᵇ ys) = cong (2 ℕ.+_) (lemma₃ xs ys)
+-cong 0ᵇ ys = refl
+-cong (1ᵇ xs) 0ᵇ = cong suc (sym (ℕ.+-idʳ (⟦ xs ⇓⟧ ℕ.* 2)))
+-cong (2ᵇ xs) 0ᵇ = cong (suc ∘ suc) (sym (ℕ.+-idʳ (⟦ xs ⇓⟧ ℕ.* 2)))
+-cong (1ᵇ xs) (1ᵇ ys) =
2 ℕ.+ ⟦ xs + ys ⇓⟧ ℕ.* 2 ≡⟨ cong (λ xy → 2 ℕ.+ xy ℕ.* 2) (+-cong xs ys) ⟩
2 ℕ.+ (⟦ xs ⇓⟧ ℕ.+ ⟦ ys ⇓⟧) ℕ.* 2 ≡⟨ cong (2 ℕ.+_) (ℕ.+-*-distrib ⟦ xs ⇓⟧ ⟦ ys ⇓⟧ 2) ⟩
2 ℕ.+ (⟦ xs ⇓⟧ ℕ.* 2 ℕ.+ ⟦ ys ⇓⟧ ℕ.* 2) ≡˘⟨ cong suc (ℕ.+-suc (⟦ xs ⇓⟧ ℕ.* 2) (⟦ ys ⇓⟧ ℕ.* 2)) ⟩
1 ℕ.+ ⟦ xs ⇓⟧ ℕ.* 2 ℕ.+ (1 ℕ.+ ⟦ ys ⇓⟧ ℕ.* 2) ∎
+-cong (1ᵇ xs) (2ᵇ ys) = cong suc (lemma₁ xs ys)
+-cong (2ᵇ xs) (1ᵇ ys) = cong suc (lemma₂ xs ys)
+-cong (2ᵇ xs) (2ᵇ ys) = cong (2 ℕ.+_) (lemma₁ xs ys)
+-cong˘ : ∀ xs ys → ⟦ xs ℕ.+ ys ⇑⟧ ≡ ⟦ xs ⇑⟧ + ⟦ ys ⇑⟧
+-cong˘ xs ys =
⟦ xs ℕ.+ ys ⇑⟧ ≡˘⟨ cong ⟦_⇑⟧ (cong₂ ℕ._+_ (𝔹-rightInv xs) (𝔹-rightInv ys)) ⟩
⟦ ⟦ ⟦ xs ⇑⟧ ⇓⟧ ℕ.+ ⟦ ⟦ ys ⇑⟧ ⇓⟧ ⇑⟧ ≡˘⟨ cong ⟦_⇑⟧ (+-cong ⟦ xs ⇑⟧ ⟦ ys ⇑⟧) ⟩
⟦ ⟦ ⟦ xs ⇑⟧ + ⟦ ys ⇑⟧ ⇓⟧ ⇑⟧ ≡⟨ 𝔹-leftInv (⟦ xs ⇑⟧ + ⟦ ys ⇑⟧) ⟩
⟦ xs ⇑⟧ + ⟦ ys ⇑⟧ ∎
| {
"alphanum_fraction": 0.4515877147,
"avg_line_length": 49.8961038961,
"ext": "agda",
"hexsha": "749daf5e4044320c2dbfb6e56fa5acf9d728c71e",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Data/Binary/Addition/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Data/Binary/Addition/Properties.agda",
"max_line_length": 110,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Data/Binary/Addition/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 2393,
"size": 3842
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of operations on the Delay type
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe --sized-types #-}
module Codata.Delay.Properties where
open import Size
import Data.Sum as Sum
open import Codata.Thunk using (Thunk; force)
open import Codata.Conat
open import Codata.Conat.Bisimilarity as Coℕ using (zero ; suc)
open import Codata.Delay
open import Codata.Delay.Bisimilarity
open import Function
open import Relation.Binary.PropositionalEquality as Eq using (_≡_)
module _ {a} {A : Set a} where
length-never : ∀ {i} → i Coℕ.⊢ length (never {A = A}) ≈ infinity
length-never = suc λ where .force → length-never
module _ {a b} {A : Set a} {B : Set b} where
length-map : ∀ (f : A → B) da {i} → i Coℕ.⊢ length (map f da) ≈ length da
length-map f (now a) = zero
length-map f (later da) = suc λ where .force → length-map f (da .force)
module _ {a b c} {A : Set a} {B : Set b} {C : Set c} where
length-zipWith : ∀ (f : A → B → C) da db {i} →
i Coℕ.⊢ length (zipWith f da db) ≈ length da ⊔ length db
length-zipWith f (now a) db = length-map (f a) db
length-zipWith f da@(later _) (now b) = length-map (λ a → f a b) da
length-zipWith f (later da) (later db) =
suc λ where .force → length-zipWith f (da .force) (db .force)
map-map-fusion : ∀ (f : A → B) (g : B → C) da {i} →
i ⊢ map g (map f da) ≈ map (g ∘′ f) da
map-map-fusion f g (now a) = now Eq.refl
map-map-fusion f g (later da) = later λ where .force → map-map-fusion f g (da .force)
map-unfold-fusion : ∀ (f : B → C) n (s : A) {i} →
i ⊢ map f (unfold n s) ≈ unfold (Sum.map id f ∘′ n) s
map-unfold-fusion f n s with n s
... | Sum.inj₁ s′ = later λ where .force → map-unfold-fusion f n s′
... | Sum.inj₂ b = now Eq.refl
| {
"alphanum_fraction": 0.5774278215,
"avg_line_length": 37.3529411765,
"ext": "agda",
"hexsha": "b7a08beb5d9e2d18a1b9d7ee9fb967671fdc1806",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Codata/Delay/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Codata/Delay/Properties.agda",
"max_line_length": 86,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Codata/Delay/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 627,
"size": 1905
} |
------------------------------------------------------------------------
-- Helpers intended to ease the development of "tactics" which use
-- proof by reflection
------------------------------------------------------------------------
open import Relation.Binary
open import Data.Nat
open import Data.Fin
open import Data.Vec as Vec
open import Data.Function
-- Think of the parameters as follows:
--
-- * Expr: A representation of code.
-- * var: The Expr type should support a notion of variables.
-- * ⟦_⟧: Computes the semantics of an expression. Takes an
-- environment mapping variables to something.
-- * ⟦_⇓⟧: Computes the semantics of the normal form of the
-- expression.
-- * correct: Normalisation preserves the semantics.
--
-- Given these parameters two "tactics" are returned, prove and solve.
--
-- For an example of the use of this module, see Algebra.RingSolver.
module Relation.Binary.Reflection
{Expr : ℕ → Set} {A}
Sem
(var : ∀ {n} → Fin n → Expr n)
(⟦_⟧ ⟦_⇓⟧ : ∀ {n} → Expr n → Vec A n → Setoid.carrier Sem)
(correct : ∀ {n} (e : Expr n) ρ →
⟦ e ⇓⟧ ρ ⟨ Setoid._≈_ Sem ⟩₁ ⟦ e ⟧ ρ)
where
open import Data.Vec.N-ary
open import Data.Product
import Relation.Binary.EqReasoning as Eq
open Setoid Sem
open Eq Sem
-- If two normalised expressions are semantically equal, then their
-- non-normalised forms are also equal.
prove : ∀ {n} (ρ : Vec A n) e₁ e₂ →
⟦ e₁ ⇓⟧ ρ ≈ ⟦ e₂ ⇓⟧ ρ →
⟦ e₁ ⟧ ρ ≈ ⟦ e₂ ⟧ ρ
prove ρ e₁ e₂ hyp = begin
⟦ e₁ ⟧ ρ ≈⟨ sym (correct e₁ ρ) ⟩
⟦ e₁ ⇓⟧ ρ ≈⟨ hyp ⟩
⟦ e₂ ⇓⟧ ρ ≈⟨ correct e₂ ρ ⟩
⟦ e₂ ⟧ ρ ∎
-- Applies the function to all possible "variables".
close : ∀ {A} n → N-ary n (Expr n) A → A
close n f = f $ⁿ Vec.map var (allFin n)
-- A variant of prove which should in many cases be easier to use,
-- because variables and environments are handled in a less explicit
-- way.
--
-- If the type signature of solve is a bit daunting, then it may be
-- helpful to instantiate n with a small natural number and normalise
-- the remainder of the type.
solve : ∀ n (f : N-ary n (Expr n) (Expr n × Expr n)) →
Eqʰ n _≈_ (curryⁿ ⟦ proj₁ (close n f) ⇓⟧) (curryⁿ ⟦ proj₂ (close n f) ⇓⟧) →
Eq n _≈_ (curryⁿ ⟦ proj₁ (close n f) ⟧) (curryⁿ ⟦ proj₂ (close n f) ⟧)
solve n f hyp =
curryⁿ-pres ⟦ proj₁ (close n f) ⟧ ⟦ proj₂ (close n f) ⟧
(λ ρ → prove ρ (proj₁ (close n f)) (proj₂ (close n f))
(curryⁿ-pres⁻¹ ⟦ proj₁ (close n f) ⇓⟧ ⟦ proj₂ (close n f) ⇓⟧
(Eqʰ-to-Eq n hyp) ρ))
-- A variant of _,_ which is intended to make uses of solve look a
-- bit nicer.
infix 4 _⊜_
_⊜_ : ∀ {A} → A → A → A × A
_⊜_ = _,_
| {
"alphanum_fraction": 0.5726308086,
"avg_line_length": 32.9277108434,
"ext": "agda",
"hexsha": "9287fb42b8f26db82184997f44aae99371d4c775",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z",
"max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "isabella232/Lemmachine",
"max_forks_repo_path": "vendor/stdlib/src/Relation/Binary/Reflection.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/Lemmachine",
"max_issues_repo_path": "vendor/stdlib/src/Relation/Binary/Reflection.agda",
"max_line_length": 77,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "vendor/stdlib/src/Relation/Binary/Reflection.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z",
"num_tokens": 915,
"size": 2733
} |
postulate
T : Set → Set
_>>=_ : ∀ {A B} → T A → (A → T B) → T B
argh : ∀ {A} → T A → T A
argh ta = do
f x ← ta
{!!}
| {
"alphanum_fraction": 0.384,
"avg_line_length": 13.8888888889,
"ext": "agda",
"hexsha": "483328e7a84a271dd172c5f93c003d720f76636c",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue5286.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue5286.agda",
"max_line_length": 41,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue5286.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 63,
"size": 125
} |
module Common.Nat where
open import Agda.Builtin.Nat public
using ( Nat; zero; suc; _+_; _*_ )
renaming ( _-_ to _∸_ )
{-# COMPILED_JS Nat function (x,v) { return (x < 1? v.zero(): v.suc(x-1)); } #-}
{-# COMPILED_JS zero 0 #-}
{-# COMPILED_JS suc function (x) { return x+1; } #-}
{-# COMPILED_JS _+_ function (x) { return function (y) { return x+y; }; } #-}
{-# COMPILED_JS _*_ function (x) { return function (y) { return x*y; }; } #-}
{-# COMPILED_JS _∸_ function (x) { return function (y) { return Math.max(0,x-y); }; } #-}
pred : Nat → Nat
pred zero = zero
pred (suc n) = n
| {
"alphanum_fraction": 0.5861486486,
"avg_line_length": 31.1578947368,
"ext": "agda",
"hexsha": "ad4cb53c8315cedde13f1f7bd51defd878ffa113",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Common/Nat.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/Common/Nat.agda",
"max_line_length": 89,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Common/Nat.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 203,
"size": 592
} |
-- You can have infix declarations in records.
module InfixRecordFields where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
infixl 50 _+_
_+_ : Nat -> Nat -> Nat
zero + m = m
suc n + m = suc (n + m)
data _==_ {A : Set}(x : A) : A -> Set where
refl : x == x
one = suc zero
two = suc (suc zero)
record A : Set where
field x : Nat
_*_ : Nat -> Nat -> Nat
h : (one + one * x) == one -- later fields make use of the fixity
infixl 60 _*_
a : A
a = record { x = zero; _*_ = \ x y -> y; h = refl }
open module X = A a
-- The projection functions also have the right fixity.
p : (one + one * zero) == one
p = refl
| {
"alphanum_fraction": 0.5628834356,
"avg_line_length": 18.1111111111,
"ext": "agda",
"hexsha": "da804f51de6e7b4911105d4ddeb269c586cd5cbd",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/InfixRecordFields.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/InfixRecordFields.agda",
"max_line_length": 76,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/InfixRecordFields.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 225,
"size": 652
} |
{-# OPTIONS --rewriting --confluence-check #-}
open import Agda.Builtin.Equality
open import Agda.Builtin.Equality.Rewrite
data Unit : Set where ∗ : Unit
postulate
A : Set
a b c : Unit → A
a→b : a ∗ ≡ b ∗
a→c : ∀ x → a x ≡ c x
b→c : b ∗ ≡ c ∗
{-# REWRITE a→b a→c b→c #-}
| {
"alphanum_fraction": 0.5789473684,
"avg_line_length": 17.8125,
"ext": "agda",
"hexsha": "b0ce0d3ac4a935a46dcca394d8d4c32618bb4501",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-06-14T11:07:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-06-14T11:07:38.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue3795.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue3795.agda",
"max_line_length": 46,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue3795.agda",
"max_stars_repo_stars_event_max_datetime": "2019-09-27T06:54:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-09-27T06:54:44.000Z",
"num_tokens": 114,
"size": 285
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Solver for commutative ring or semiring equalities
------------------------------------------------------------------------
-- Uses ideas from the Coq ring tactic. See "Proving Equalities in a
-- Commutative Ring Done Right in Coq" by Grégoire and Mahboubi. The
-- code below is not optimised like theirs, though (in particular, our
-- Horner normal forms are not sparse).
--
-- At first the `WeaklyDecidable` type may at first glance look useless
-- as there is no guarantee that it doesn't always return `nothing`.
-- However the implementation of it affects the power of the solver. The
-- more equalities it returns, the more expressions the ring solver can
-- solve.
{-# OPTIONS --without-K --safe #-}
open import Algebra
open import Algebra.Solver.Ring.AlmostCommutativeRing
open import Relation.Binary.Core using (WeaklyDecidable)
module Algebra.Solver.Ring
{r₁ r₂ r₃}
(Coeff : RawRing r₁) -- Coefficient "ring".
(R : AlmostCommutativeRing r₂ r₃) -- Main "ring".
(morphism : Coeff -Raw-AlmostCommutative⟶ R)
(_coeff≟_ : WeaklyDecidable (Induced-equivalence morphism))
where
open import Algebra.Solver.Ring.Lemmas Coeff R morphism
private module C = RawRing Coeff
open AlmostCommutativeRing R
renaming (zero to *-zero; zeroˡ to *-zeroˡ; zeroʳ to *-zeroʳ)
open import Algebra.FunctionProperties _≈_
open import Algebra.Morphism
open _-Raw-AlmostCommutative⟶_ morphism renaming (⟦_⟧ to ⟦_⟧′)
open import Algebra.Operations.Semiring semiring
open import Relation.Binary
open import Relation.Nullary using (yes; no)
open import Relation.Binary.Reasoning.Setoid setoid
import Relation.Binary.PropositionalEquality as PropEq
import Relation.Binary.Reflection as Reflection
open import Data.Nat.Base using (ℕ; suc; zero)
open import Data.Fin using (Fin; zero; suc)
open import Data.Vec using (Vec; []; _∷_; lookup)
open import Data.Maybe.Base using (just; nothing)
open import Function
open import Level using (_⊔_)
infix 9 :-_ -H_ -N_
infixr 9 _:×_ _:^_ _^N_
infix 8 _*x+_ _*x+HN_ _*x+H_
infixl 8 _:*_ _*N_ _*H_ _*NH_ _*HN_
infixl 7 _:+_ _:-_ _+H_ _+N_
infix 4 _≈H_ _≈N_
------------------------------------------------------------------------
-- Polynomials
data Op : Set where
[+] : Op
[*] : Op
-- The polynomials are indexed by the number of variables.
data Polynomial (m : ℕ) : Set r₁ where
op : (o : Op) (p₁ : Polynomial m) (p₂ : Polynomial m) → Polynomial m
con : (c : C.Carrier) → Polynomial m
var : (x : Fin m) → Polynomial m
_:^_ : (p : Polynomial m) (n : ℕ) → Polynomial m
:-_ : (p : Polynomial m) → Polynomial m
-- Short-hand notation.
_:+_ : ∀ {n} → Polynomial n → Polynomial n → Polynomial n
_:+_ = op [+]
_:*_ : ∀ {n} → Polynomial n → Polynomial n → Polynomial n
_:*_ = op [*]
_:-_ : ∀ {n} → Polynomial n → Polynomial n → Polynomial n
x :- y = x :+ :- y
_:×_ : ∀ {n} → ℕ → Polynomial n → Polynomial n
zero :× p = con C.0#
suc m :× p = p :+ m :× p
-- Semantics.
sem : Op → Op₂ Carrier
sem [+] = _+_
sem [*] = _*_
⟦_⟧ : ∀ {n} → Polynomial n → Vec Carrier n → Carrier
⟦ op o p₁ p₂ ⟧ ρ = ⟦ p₁ ⟧ ρ ⟨ sem o ⟩ ⟦ p₂ ⟧ ρ
⟦ con c ⟧ ρ = ⟦ c ⟧′
⟦ var x ⟧ ρ = lookup ρ x
⟦ p :^ n ⟧ ρ = ⟦ p ⟧ ρ ^ n
⟦ :- p ⟧ ρ = - ⟦ p ⟧ ρ
------------------------------------------------------------------------
-- Normal forms of polynomials
-- A univariate polynomial of degree d,
--
-- p = a_d x^d + a_{d-1}x^{d-1} + … + a_0,
--
-- is represented in Horner normal form by
--
-- p = ((a_d x + a_{d-1})x + …)x + a_0.
--
-- Note that Horner normal forms can be represented as lists, with the
-- empty list standing for the zero polynomial of degree "-1".
--
-- Given this representation of univariate polynomials over an
-- arbitrary ring, polynomials in any number of variables over the
-- ring C can be represented via the isomorphisms
--
-- C[] ≅ C
--
-- and
--
-- C[X_0,...X_{n+1}] ≅ C[X_0,...,X_n][X_{n+1}].
mutual
-- The polynomial representations are indexed by the polynomial's
-- degree.
data HNF : ℕ → Set r₁ where
∅ : ∀ {n} → HNF (suc n)
_*x+_ : ∀ {n} → HNF (suc n) → Normal n → HNF (suc n)
data Normal : ℕ → Set r₁ where
con : C.Carrier → Normal zero
poly : ∀ {n} → HNF (suc n) → Normal (suc n)
-- Note that the data types above do /not/ ensure uniqueness of
-- normal forms: the zero polynomial of degree one can be
-- represented using both ∅ and ∅ *x+ con C.0#.
mutual
-- Semantics.
⟦_⟧H : ∀ {n} → HNF (suc n) → Vec Carrier (suc n) → Carrier
⟦ ∅ ⟧H _ = 0#
⟦ p *x+ c ⟧H (x ∷ ρ) = ⟦ p ⟧H (x ∷ ρ) * x + ⟦ c ⟧N ρ
⟦_⟧N : ∀ {n} → Normal n → Vec Carrier n → Carrier
⟦ con c ⟧N _ = ⟦ c ⟧′
⟦ poly p ⟧N ρ = ⟦ p ⟧H ρ
------------------------------------------------------------------------
-- Equality and decidability
mutual
-- Equality.
data _≈H_ : ∀ {n} → HNF n → HNF n → Set (r₁ ⊔ r₃) where
∅ : ∀ {n} → _≈H_ {suc n} ∅ ∅
_*x+_ : ∀ {n} {p₁ p₂ : HNF (suc n)} {c₁ c₂ : Normal n} →
p₁ ≈H p₂ → c₁ ≈N c₂ → (p₁ *x+ c₁) ≈H (p₂ *x+ c₂)
data _≈N_ : ∀ {n} → Normal n → Normal n → Set (r₁ ⊔ r₃) where
con : ∀ {c₁ c₂} → ⟦ c₁ ⟧′ ≈ ⟦ c₂ ⟧′ → con c₁ ≈N con c₂
poly : ∀ {n} {p₁ p₂ : HNF (suc n)} → p₁ ≈H p₂ → poly p₁ ≈N poly p₂
mutual
-- Equality is weakly decidable.
_≟H_ : ∀ {n} → WeaklyDecidable (_≈H_ {n = n})
∅ ≟H ∅ = just ∅
∅ ≟H (_ *x+ _) = nothing
(_ *x+ _) ≟H ∅ = nothing
(p₁ *x+ c₁) ≟H (p₂ *x+ c₂) with p₁ ≟H p₂ | c₁ ≟N c₂
... | just p₁≈p₂ | just c₁≈c₂ = just (p₁≈p₂ *x+ c₁≈c₂)
... | _ | nothing = nothing
... | nothing | _ = nothing
_≟N_ : ∀ {n} → WeaklyDecidable (_≈N_ {n = n})
con c₁ ≟N con c₂ with c₁ coeff≟ c₂
... | just c₁≈c₂ = just (con c₁≈c₂)
... | nothing = nothing
poly p₁ ≟N poly p₂ with p₁ ≟H p₂
... | just p₁≈p₂ = just (poly p₁≈p₂)
... | nothing = nothing
mutual
-- The semantics respect the equality relations defined above.
⟦_⟧H-cong : ∀ {n} {p₁ p₂ : HNF (suc n)} →
p₁ ≈H p₂ → ∀ ρ → ⟦ p₁ ⟧H ρ ≈ ⟦ p₂ ⟧H ρ
⟦ ∅ ⟧H-cong _ = refl
⟦ p₁≈p₂ *x+ c₁≈c₂ ⟧H-cong (x ∷ ρ) =
(⟦ p₁≈p₂ ⟧H-cong (x ∷ ρ) ⟨ *-cong ⟩ refl)
⟨ +-cong ⟩
⟦ c₁≈c₂ ⟧N-cong ρ
⟦_⟧N-cong :
∀ {n} {p₁ p₂ : Normal n} →
p₁ ≈N p₂ → ∀ ρ → ⟦ p₁ ⟧N ρ ≈ ⟦ p₂ ⟧N ρ
⟦ con c₁≈c₂ ⟧N-cong _ = c₁≈c₂
⟦ poly p₁≈p₂ ⟧N-cong ρ = ⟦ p₁≈p₂ ⟧H-cong ρ
------------------------------------------------------------------------
-- Ring operations on Horner normal forms
-- Zero.
0H : ∀ {n} → HNF (suc n)
0H = ∅
0N : ∀ {n} → Normal n
0N {zero} = con C.0#
0N {suc n} = poly 0H
mutual
-- One.
1H : ∀ {n} → HNF (suc n)
1H {n} = ∅ *x+ 1N {n}
1N : ∀ {n} → Normal n
1N {zero} = con C.1#
1N {suc n} = poly 1H
-- A simplifying variant of _*x+_.
_*x+HN_ : ∀ {n} → HNF (suc n) → Normal n → HNF (suc n)
(p *x+ c′) *x+HN c = (p *x+ c′) *x+ c
∅ *x+HN c with c ≟N 0N
... | just c≈0 = ∅
... | nothing = ∅ *x+ c
mutual
-- Addition.
_+H_ : ∀ {n} → HNF (suc n) → HNF (suc n) → HNF (suc n)
∅ +H p = p
p +H ∅ = p
(p₁ *x+ c₁) +H (p₂ *x+ c₂) = (p₁ +H p₂) *x+HN (c₁ +N c₂)
_+N_ : ∀ {n} → Normal n → Normal n → Normal n
con c₁ +N con c₂ = con (c₁ C.+ c₂)
poly p₁ +N poly p₂ = poly (p₁ +H p₂)
-- Multiplication.
_*x+H_ : ∀ {n} → HNF (suc n) → HNF (suc n) → HNF (suc n)
p₁ *x+H (p₂ *x+ c) = (p₁ +H p₂) *x+HN c
∅ *x+H ∅ = ∅
(p₁ *x+ c) *x+H ∅ = (p₁ *x+ c) *x+ 0N
mutual
_*NH_ : ∀ {n} → Normal n → HNF (suc n) → HNF (suc n)
c *NH ∅ = ∅
c *NH (p *x+ c′) with c ≟N 0N
... | just c≈0 = ∅
... | nothing = (c *NH p) *x+ (c *N c′)
_*HN_ : ∀ {n} → HNF (suc n) → Normal n → HNF (suc n)
∅ *HN c = ∅
(p *x+ c′) *HN c with c ≟N 0N
... | just c≈0 = ∅
... | nothing = (p *HN c) *x+ (c′ *N c)
_*H_ : ∀ {n} → HNF (suc n) → HNF (suc n) → HNF (suc n)
∅ *H _ = ∅
(_ *x+ _) *H ∅ = ∅
(p₁ *x+ c₁) *H (p₂ *x+ c₂) =
((p₁ *H p₂) *x+H (p₁ *HN c₂ +H c₁ *NH p₂)) *x+HN (c₁ *N c₂)
_*N_ : ∀ {n} → Normal n → Normal n → Normal n
con c₁ *N con c₂ = con (c₁ C.* c₂)
poly p₁ *N poly p₂ = poly (p₁ *H p₂)
-- Exponentiation.
_^N_ : ∀ {n} → Normal n → ℕ → Normal n
p ^N zero = 1N
p ^N suc n = p *N (p ^N n)
mutual
-- Negation.
-H_ : ∀ {n} → HNF (suc n) → HNF (suc n)
-H p = (-N 1N) *NH p
-N_ : ∀ {n} → Normal n → Normal n
-N con c = con (C.- c)
-N poly p = poly (-H p)
------------------------------------------------------------------------
-- Normalisation
normalise-con : ∀ {n} → C.Carrier → Normal n
normalise-con {zero} c = con c
normalise-con {suc n} c = poly (∅ *x+HN normalise-con c)
normalise-var : ∀ {n} → Fin n → Normal n
normalise-var zero = poly ((∅ *x+ 1N) *x+ 0N)
normalise-var (suc i) = poly (∅ *x+HN normalise-var i)
normalise : ∀ {n} → Polynomial n → Normal n
normalise (op [+] t₁ t₂) = normalise t₁ +N normalise t₂
normalise (op [*] t₁ t₂) = normalise t₁ *N normalise t₂
normalise (con c) = normalise-con c
normalise (var i) = normalise-var i
normalise (t :^ k) = normalise t ^N k
normalise (:- t) = -N normalise t
-- Evaluation after normalisation.
⟦_⟧↓ : ∀ {n} → Polynomial n → Vec Carrier n → Carrier
⟦ p ⟧↓ ρ = ⟦ normalise p ⟧N ρ
------------------------------------------------------------------------
-- Homomorphism lemmas
0N-homo : ∀ {n} ρ → ⟦ 0N {n} ⟧N ρ ≈ 0#
0N-homo [] = 0-homo
0N-homo (x ∷ ρ) = refl
-- If c is equal to 0N, then c is semantically equal to 0#.
0≈⟦0⟧ : ∀ {n} {c : Normal n} → c ≈N 0N → ∀ ρ → 0# ≈ ⟦ c ⟧N ρ
0≈⟦0⟧ {c = c} c≈0 ρ = sym (begin
⟦ c ⟧N ρ ≈⟨ ⟦ c≈0 ⟧N-cong ρ ⟩
⟦ 0N ⟧N ρ ≈⟨ 0N-homo ρ ⟩
0# ∎)
1N-homo : ∀ {n} ρ → ⟦ 1N {n} ⟧N ρ ≈ 1#
1N-homo [] = 1-homo
1N-homo (x ∷ ρ) = begin
0# * x + ⟦ 1N ⟧N ρ ≈⟨ refl ⟨ +-cong ⟩ 1N-homo ρ ⟩
0# * x + 1# ≈⟨ lemma₆ _ _ ⟩
1# ∎
-- _*x+HN_ is equal to _*x+_.
*x+HN≈*x+ : ∀ {n} (p : HNF (suc n)) (c : Normal n) →
∀ ρ → ⟦ p *x+HN c ⟧H ρ ≈ ⟦ p *x+ c ⟧H ρ
*x+HN≈*x+ (p *x+ c′) c ρ = refl
*x+HN≈*x+ ∅ c (x ∷ ρ) with c ≟N 0N
... | just c≈0 = begin
0# ≈⟨ 0≈⟦0⟧ c≈0 ρ ⟩
⟦ c ⟧N ρ ≈⟨ sym $ lemma₆ _ _ ⟩
0# * x + ⟦ c ⟧N ρ ∎
... | nothing = refl
∅*x+HN-homo : ∀ {n} (c : Normal n) x ρ →
⟦ ∅ *x+HN c ⟧H (x ∷ ρ) ≈ ⟦ c ⟧N ρ
∅*x+HN-homo c x ρ with c ≟N 0N
... | just c≈0 = 0≈⟦0⟧ c≈0 ρ
... | nothing = lemma₆ _ _
mutual
+H-homo : ∀ {n} (p₁ p₂ : HNF (suc n)) →
∀ ρ → ⟦ p₁ +H p₂ ⟧H ρ ≈ ⟦ p₁ ⟧H ρ + ⟦ p₂ ⟧H ρ
+H-homo ∅ p₂ ρ = sym (+-identityˡ _)
+H-homo (p₁ *x+ x₁) ∅ ρ = sym (+-identityʳ _)
+H-homo (p₁ *x+ c₁) (p₂ *x+ c₂) (x ∷ ρ) = begin
⟦ (p₁ +H p₂) *x+HN (c₁ +N c₂) ⟧H (x ∷ ρ) ≈⟨ *x+HN≈*x+ (p₁ +H p₂) (c₁ +N c₂) (x ∷ ρ) ⟩
⟦ p₁ +H p₂ ⟧H (x ∷ ρ) * x + ⟦ c₁ +N c₂ ⟧N ρ ≈⟨ (+H-homo p₁ p₂ (x ∷ ρ) ⟨ *-cong ⟩ refl) ⟨ +-cong ⟩ +N-homo c₁ c₂ ρ ⟩
(⟦ p₁ ⟧H (x ∷ ρ) + ⟦ p₂ ⟧H (x ∷ ρ)) * x + (⟦ c₁ ⟧N ρ + ⟦ c₂ ⟧N ρ) ≈⟨ lemma₁ _ _ _ _ _ ⟩
(⟦ p₁ ⟧H (x ∷ ρ) * x + ⟦ c₁ ⟧N ρ) +
(⟦ p₂ ⟧H (x ∷ ρ) * x + ⟦ c₂ ⟧N ρ) ∎
+N-homo : ∀ {n} (p₁ p₂ : Normal n) →
∀ ρ → ⟦ p₁ +N p₂ ⟧N ρ ≈ ⟦ p₁ ⟧N ρ + ⟦ p₂ ⟧N ρ
+N-homo (con c₁) (con c₂) _ = +-homo _ _
+N-homo (poly p₁) (poly p₂) ρ = +H-homo p₁ p₂ ρ
*x+H-homo :
∀ {n} (p₁ p₂ : HNF (suc n)) x ρ →
⟦ p₁ *x+H p₂ ⟧H (x ∷ ρ) ≈
⟦ p₁ ⟧H (x ∷ ρ) * x + ⟦ p₂ ⟧H (x ∷ ρ)
*x+H-homo ∅ ∅ _ _ = sym $ lemma₆ _ _
*x+H-homo (p *x+ c) ∅ x ρ = begin
⟦ p *x+ c ⟧H (x ∷ ρ) * x + ⟦ 0N ⟧N ρ ≈⟨ refl ⟨ +-cong ⟩ 0N-homo ρ ⟩
⟦ p *x+ c ⟧H (x ∷ ρ) * x + 0# ∎
*x+H-homo p₁ (p₂ *x+ c₂) x ρ = begin
⟦ (p₁ +H p₂) *x+HN c₂ ⟧H (x ∷ ρ) ≈⟨ *x+HN≈*x+ (p₁ +H p₂) c₂ (x ∷ ρ) ⟩
⟦ p₁ +H p₂ ⟧H (x ∷ ρ) * x + ⟦ c₂ ⟧N ρ ≈⟨ (+H-homo p₁ p₂ (x ∷ ρ) ⟨ *-cong ⟩ refl) ⟨ +-cong ⟩ refl ⟩
(⟦ p₁ ⟧H (x ∷ ρ) + ⟦ p₂ ⟧H (x ∷ ρ)) * x + ⟦ c₂ ⟧N ρ ≈⟨ lemma₀ _ _ _ _ ⟩
⟦ p₁ ⟧H (x ∷ ρ) * x + (⟦ p₂ ⟧H (x ∷ ρ) * x + ⟦ c₂ ⟧N ρ) ∎
mutual
*NH-homo :
∀ {n} (c : Normal n) (p : HNF (suc n)) x ρ →
⟦ c *NH p ⟧H (x ∷ ρ) ≈ ⟦ c ⟧N ρ * ⟦ p ⟧H (x ∷ ρ)
*NH-homo c ∅ x ρ = sym (*-zeroʳ _)
*NH-homo c (p *x+ c′) x ρ with c ≟N 0N
... | just c≈0 = begin
0# ≈⟨ sym (*-zeroˡ _) ⟩
0# * (⟦ p ⟧H (x ∷ ρ) * x + ⟦ c′ ⟧N ρ) ≈⟨ 0≈⟦0⟧ c≈0 ρ ⟨ *-cong ⟩ refl ⟩
⟦ c ⟧N ρ * (⟦ p ⟧H (x ∷ ρ) * x + ⟦ c′ ⟧N ρ) ∎
... | nothing = begin
⟦ c *NH p ⟧H (x ∷ ρ) * x + ⟦ c *N c′ ⟧N ρ ≈⟨ (*NH-homo c p x ρ ⟨ *-cong ⟩ refl) ⟨ +-cong ⟩ *N-homo c c′ ρ ⟩
(⟦ c ⟧N ρ * ⟦ p ⟧H (x ∷ ρ)) * x + (⟦ c ⟧N ρ * ⟦ c′ ⟧N ρ) ≈⟨ lemma₃ _ _ _ _ ⟩
⟦ c ⟧N ρ * (⟦ p ⟧H (x ∷ ρ) * x + ⟦ c′ ⟧N ρ) ∎
*HN-homo :
∀ {n} (p : HNF (suc n)) (c : Normal n) x ρ →
⟦ p *HN c ⟧H (x ∷ ρ) ≈ ⟦ p ⟧H (x ∷ ρ) * ⟦ c ⟧N ρ
*HN-homo ∅ c x ρ = sym (*-zeroˡ _)
*HN-homo (p *x+ c′) c x ρ with c ≟N 0N
... | just c≈0 = begin
0# ≈⟨ sym (*-zeroʳ _) ⟩
(⟦ p ⟧H (x ∷ ρ) * x + ⟦ c′ ⟧N ρ) * 0# ≈⟨ refl ⟨ *-cong ⟩ 0≈⟦0⟧ c≈0 ρ ⟩
(⟦ p ⟧H (x ∷ ρ) * x + ⟦ c′ ⟧N ρ) * ⟦ c ⟧N ρ ∎
... | nothing = begin
⟦ p *HN c ⟧H (x ∷ ρ) * x + ⟦ c′ *N c ⟧N ρ ≈⟨ (*HN-homo p c x ρ ⟨ *-cong ⟩ refl) ⟨ +-cong ⟩ *N-homo c′ c ρ ⟩
(⟦ p ⟧H (x ∷ ρ) * ⟦ c ⟧N ρ) * x + (⟦ c′ ⟧N ρ * ⟦ c ⟧N ρ) ≈⟨ lemma₂ _ _ _ _ ⟩
(⟦ p ⟧H (x ∷ ρ) * x + ⟦ c′ ⟧N ρ) * ⟦ c ⟧N ρ ∎
*H-homo : ∀ {n} (p₁ p₂ : HNF (suc n)) →
∀ ρ → ⟦ p₁ *H p₂ ⟧H ρ ≈ ⟦ p₁ ⟧H ρ * ⟦ p₂ ⟧H ρ
*H-homo ∅ p₂ ρ = sym $ *-zeroˡ _
*H-homo (p₁ *x+ c₁) ∅ ρ = sym $ *-zeroʳ _
*H-homo (p₁ *x+ c₁) (p₂ *x+ c₂) (x ∷ ρ) = begin
⟦ ((p₁ *H p₂) *x+H ((p₁ *HN c₂) +H (c₁ *NH p₂))) *x+HN
(c₁ *N c₂) ⟧H (x ∷ ρ) ≈⟨ *x+HN≈*x+ ((p₁ *H p₂) *x+H ((p₁ *HN c₂) +H (c₁ *NH p₂)))
(c₁ *N c₂) (x ∷ ρ) ⟩
⟦ (p₁ *H p₂) *x+H
((p₁ *HN c₂) +H (c₁ *NH p₂)) ⟧H (x ∷ ρ) * x +
⟦ c₁ *N c₂ ⟧N ρ ≈⟨ (*x+H-homo (p₁ *H p₂) ((p₁ *HN c₂) +H (c₁ *NH p₂)) x ρ
⟨ *-cong ⟩
refl)
⟨ +-cong ⟩
*N-homo c₁ c₂ ρ ⟩
(⟦ p₁ *H p₂ ⟧H (x ∷ ρ) * x +
⟦ (p₁ *HN c₂) +H (c₁ *NH p₂) ⟧H (x ∷ ρ)) * x +
⟦ c₁ ⟧N ρ * ⟦ c₂ ⟧N ρ ≈⟨ (((*H-homo p₁ p₂ (x ∷ ρ) ⟨ *-cong ⟩ refl)
⟨ +-cong ⟩
(+H-homo (p₁ *HN c₂) (c₁ *NH p₂) (x ∷ ρ)))
⟨ *-cong ⟩
refl)
⟨ +-cong ⟩
refl ⟩
(⟦ p₁ ⟧H (x ∷ ρ) * ⟦ p₂ ⟧H (x ∷ ρ) * x +
(⟦ p₁ *HN c₂ ⟧H (x ∷ ρ) + ⟦ c₁ *NH p₂ ⟧H (x ∷ ρ))) * x +
⟦ c₁ ⟧N ρ * ⟦ c₂ ⟧N ρ ≈⟨ ((refl ⟨ +-cong ⟩ (*HN-homo p₁ c₂ x ρ ⟨ +-cong ⟩ *NH-homo c₁ p₂ x ρ))
⟨ *-cong ⟩
refl)
⟨ +-cong ⟩
refl ⟩
(⟦ p₁ ⟧H (x ∷ ρ) * ⟦ p₂ ⟧H (x ∷ ρ) * x +
(⟦ p₁ ⟧H (x ∷ ρ) * ⟦ c₂ ⟧N ρ + ⟦ c₁ ⟧N ρ * ⟦ p₂ ⟧H (x ∷ ρ))) * x +
(⟦ c₁ ⟧N ρ * ⟦ c₂ ⟧N ρ) ≈⟨ lemma₄ _ _ _ _ _ ⟩
(⟦ p₁ ⟧H (x ∷ ρ) * x + ⟦ c₁ ⟧N ρ) *
(⟦ p₂ ⟧H (x ∷ ρ) * x + ⟦ c₂ ⟧N ρ) ∎
*N-homo : ∀ {n} (p₁ p₂ : Normal n) →
∀ ρ → ⟦ p₁ *N p₂ ⟧N ρ ≈ ⟦ p₁ ⟧N ρ * ⟦ p₂ ⟧N ρ
*N-homo (con c₁) (con c₂) _ = *-homo _ _
*N-homo (poly p₁) (poly p₂) ρ = *H-homo p₁ p₂ ρ
^N-homo : ∀ {n} (p : Normal n) (k : ℕ) →
∀ ρ → ⟦ p ^N k ⟧N ρ ≈ ⟦ p ⟧N ρ ^ k
^N-homo p zero ρ = 1N-homo ρ
^N-homo p (suc k) ρ = begin
⟦ p *N (p ^N k) ⟧N ρ ≈⟨ *N-homo p (p ^N k) ρ ⟩
⟦ p ⟧N ρ * ⟦ p ^N k ⟧N ρ ≈⟨ refl ⟨ *-cong ⟩ ^N-homo p k ρ ⟩
⟦ p ⟧N ρ * (⟦ p ⟧N ρ ^ k) ∎
mutual
-H‿-homo : ∀ {n} (p : HNF (suc n)) →
∀ ρ → ⟦ -H p ⟧H ρ ≈ - ⟦ p ⟧H ρ
-H‿-homo p (x ∷ ρ) = begin
⟦ (-N 1N) *NH p ⟧H (x ∷ ρ) ≈⟨ *NH-homo (-N 1N) p x ρ ⟩
⟦ -N 1N ⟧N ρ * ⟦ p ⟧H (x ∷ ρ) ≈⟨ trans (-N‿-homo 1N ρ) (-‿cong (1N-homo ρ)) ⟨ *-cong ⟩ refl ⟩
- 1# * ⟦ p ⟧H (x ∷ ρ) ≈⟨ lemma₇ _ ⟩
- ⟦ p ⟧H (x ∷ ρ) ∎
-N‿-homo : ∀ {n} (p : Normal n) →
∀ ρ → ⟦ -N p ⟧N ρ ≈ - ⟦ p ⟧N ρ
-N‿-homo (con c) _ = -‿homo _
-N‿-homo (poly p) ρ = -H‿-homo p ρ
------------------------------------------------------------------------
-- Correctness
correct-con : ∀ {n} (c : C.Carrier) (ρ : Vec Carrier n) →
⟦ normalise-con c ⟧N ρ ≈ ⟦ c ⟧′
correct-con c [] = refl
correct-con c (x ∷ ρ) = begin
⟦ ∅ *x+HN normalise-con c ⟧H (x ∷ ρ) ≈⟨ ∅*x+HN-homo (normalise-con c) x ρ ⟩
⟦ normalise-con c ⟧N ρ ≈⟨ correct-con c ρ ⟩
⟦ c ⟧′ ∎
correct-var : ∀ {n} (i : Fin n) →
∀ ρ → ⟦ normalise-var i ⟧N ρ ≈ lookup ρ i
correct-var () []
correct-var (suc i) (x ∷ ρ) = begin
⟦ ∅ *x+HN normalise-var i ⟧H (x ∷ ρ) ≈⟨ ∅*x+HN-homo (normalise-var i) x ρ ⟩
⟦ normalise-var i ⟧N ρ ≈⟨ correct-var i ρ ⟩
lookup ρ i ∎
correct-var zero (x ∷ ρ) = begin
(0# * x + ⟦ 1N ⟧N ρ) * x + ⟦ 0N ⟧N ρ ≈⟨ ((refl ⟨ +-cong ⟩ 1N-homo ρ) ⟨ *-cong ⟩ refl) ⟨ +-cong ⟩ 0N-homo ρ ⟩
(0# * x + 1#) * x + 0# ≈⟨ lemma₅ _ ⟩
x ∎
correct : ∀ {n} (p : Polynomial n) → ∀ ρ → ⟦ p ⟧↓ ρ ≈ ⟦ p ⟧ ρ
correct (op [+] p₁ p₂) ρ = begin
⟦ normalise p₁ +N normalise p₂ ⟧N ρ ≈⟨ +N-homo (normalise p₁) (normalise p₂) ρ ⟩
⟦ p₁ ⟧↓ ρ + ⟦ p₂ ⟧↓ ρ ≈⟨ correct p₁ ρ ⟨ +-cong ⟩ correct p₂ ρ ⟩
⟦ p₁ ⟧ ρ + ⟦ p₂ ⟧ ρ ∎
correct (op [*] p₁ p₂) ρ = begin
⟦ normalise p₁ *N normalise p₂ ⟧N ρ ≈⟨ *N-homo (normalise p₁) (normalise p₂) ρ ⟩
⟦ p₁ ⟧↓ ρ * ⟦ p₂ ⟧↓ ρ ≈⟨ correct p₁ ρ ⟨ *-cong ⟩ correct p₂ ρ ⟩
⟦ p₁ ⟧ ρ * ⟦ p₂ ⟧ ρ ∎
correct (con c) ρ = correct-con c ρ
correct (var i) ρ = correct-var i ρ
correct (p :^ k) ρ = begin
⟦ normalise p ^N k ⟧N ρ ≈⟨ ^N-homo (normalise p) k ρ ⟩
⟦ p ⟧↓ ρ ^ k ≈⟨ correct p ρ ⟨ ^-cong ⟩ PropEq.refl {x = k} ⟩
⟦ p ⟧ ρ ^ k ∎
correct (:- p) ρ = begin
⟦ -N normalise p ⟧N ρ ≈⟨ -N‿-homo (normalise p) ρ ⟩
- ⟦ p ⟧↓ ρ ≈⟨ -‿cong (correct p ρ) ⟩
- ⟦ p ⟧ ρ ∎
------------------------------------------------------------------------
-- "Tactics"
open Reflection setoid var ⟦_⟧ ⟦_⟧↓ correct public
using (prove; solve) renaming (_⊜_ to _:=_)
-- For examples of how solve and _:=_ can be used to
-- semi-automatically prove ring equalities, see, for instance,
-- Data.Digit or Data.Nat.DivMod.
| {
"alphanum_fraction": 0.4121945074,
"avg_line_length": 35.9510869565,
"ext": "agda",
"hexsha": "47a4a1ac52ed374cbbebc2aa5372d83fa0946ff4",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Solver/Ring.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Solver/Ring.agda",
"max_line_length": 145,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Solver/Ring.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 8923,
"size": 19845
} |
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommMonoid.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.SIP
open import Cubical.Data.Sigma
open import Cubical.Algebra.Monoid
open import Cubical.Displayed.Base
open import Cubical.Displayed.Auto
open import Cubical.Displayed.Record
open import Cubical.Displayed.Universe
open import Cubical.Reflection.RecordEquiv
open Iso
private
variable
ℓ ℓ' : Level
record IsCommMonoid {M : Type ℓ}
(ε : M) (_·_ : M → M → M) : Type ℓ where
constructor iscommmonoid
field
isMonoid : IsMonoid ε _·_
·Comm : (x y : M) → x · y ≡ y · x
open IsMonoid isMonoid public
unquoteDecl IsCommMonoidIsoΣ = declareRecordIsoΣ IsCommMonoidIsoΣ (quote IsCommMonoid)
record CommMonoidStr (M : Type ℓ) : Type ℓ where
constructor commmonoidstr
field
ε : M
_·_ : M → M → M
isCommMonoid : IsCommMonoid ε _·_
infixl 7 _·_
open IsCommMonoid isCommMonoid public
CommMonoid : ∀ ℓ → Type (ℓ-suc ℓ)
CommMonoid ℓ = TypeWithStr ℓ CommMonoidStr
makeIsCommMonoid : {M : Type ℓ} {ε : M} {_·_ : M → M → M}
(is-setM : isSet M)
(·Assoc : (x y z : M) → x · (y · z) ≡ (x · y) · z)
(·IdR : (x : M) → x · ε ≡ x)
(·Comm : (x y : M) → x · y ≡ y · x)
→ IsCommMonoid ε _·_
IsCommMonoid.isMonoid (makeIsCommMonoid is-setM ·Assoc ·IdR ·Comm) =
makeIsMonoid is-setM ·Assoc ·IdR (λ x → ·Comm _ _ ∙ ·IdR x)
IsCommMonoid.·Comm (makeIsCommMonoid is-setM ·Assoc ·IdR ·Comm) = ·Comm
makeCommMonoid : {M : Type ℓ} (ε : M) (_·_ : M → M → M)
(is-setM : isSet M)
(·Assoc : (x y z : M) → x · (y · z) ≡ (x · y) · z)
(·IdR : (x : M) → x · ε ≡ x)
(·Comm : (x y : M) → x · y ≡ y · x)
→ CommMonoid ℓ
fst (makeCommMonoid ε _·_ is-setM ·Assoc ·IdR ·Comm) = _
CommMonoidStr.ε (snd (makeCommMonoid ε _·_ is-setM ·Assoc ·IdR ·Comm)) = ε
CommMonoidStr._·_ (snd (makeCommMonoid ε _·_ is-setM ·Assoc ·IdR ·Comm)) = _·_
CommMonoidStr.isCommMonoid (snd (makeCommMonoid ε _·_ is-setM ·Assoc ·IdR ·Comm)) =
makeIsCommMonoid is-setM ·Assoc ·IdR ·Comm
CommMonoidStr→MonoidStr : {A : Type ℓ} → CommMonoidStr A → MonoidStr A
CommMonoidStr→MonoidStr (commmonoidstr _ _ H) = monoidstr _ _ (IsCommMonoid.isMonoid H)
CommMonoid→Monoid : CommMonoid ℓ → Monoid ℓ
CommMonoid→Monoid (_ , commmonoidstr _ _ M) = _ , monoidstr _ _ (IsCommMonoid.isMonoid M)
isSetFromIsCommMonoid :
{M : Type ℓ} {ε : M} {_·_ : M → M → M}
(isCommMonoid : IsCommMonoid ε _·_)
→ isSet M
isSetFromIsCommMonoid isCommMonoid =
let open IsCommMonoid isCommMonoid
in is-set
isSetCommMonoid : (M : CommMonoid ℓ) → isSet ⟨ M ⟩
isSetCommMonoid M =
let open CommMonoidStr (snd M)
in isSetFromIsCommMonoid isCommMonoid
CommMonoidHom : (L : CommMonoid ℓ) (M : CommMonoid ℓ') → Type (ℓ-max ℓ ℓ')
CommMonoidHom L M = MonoidHom (CommMonoid→Monoid L) (CommMonoid→Monoid M)
IsCommMonoidEquiv : {A : Type ℓ} {B : Type ℓ'}
(M : CommMonoidStr A) (e : A ≃ B) (N : CommMonoidStr B) → Type (ℓ-max ℓ ℓ')
IsCommMonoidEquiv M e N = IsMonoidHom (CommMonoidStr→MonoidStr M) (e .fst) (CommMonoidStr→MonoidStr N)
CommMonoidEquiv : (M : CommMonoid ℓ) (N : CommMonoid ℓ') → Type (ℓ-max ℓ ℓ')
CommMonoidEquiv M N = Σ[ e ∈ (M .fst ≃ N .fst) ] IsCommMonoidEquiv (M .snd) e (N .snd)
isPropIsCommMonoid : {M : Type ℓ} (ε : M) (_·_ : M → M → M)
→ isProp (IsCommMonoid ε _·_)
isPropIsCommMonoid ε _·_ =
isOfHLevelRetractFromIso 1 IsCommMonoidIsoΣ
(isPropΣ (isPropIsMonoid ε _·_)
λ mon → isPropΠ2 (λ _ _ → mon .is-set _ _))
where
open IsMonoid
𝒮ᴰ-CommMonoid : DUARel (𝒮-Univ ℓ) CommMonoidStr ℓ
𝒮ᴰ-CommMonoid =
𝒮ᴰ-Record (𝒮-Univ _) IsCommMonoidEquiv
(fields:
data[ ε ∣ autoDUARel _ _ ∣ presε ]
data[ _·_ ∣ autoDUARel _ _ ∣ pres· ]
prop[ isCommMonoid ∣ (λ _ _ → isPropIsCommMonoid _ _) ])
where
open CommMonoidStr
open IsMonoidHom
CommMonoidPath : (M N : CommMonoid ℓ) → CommMonoidEquiv M N ≃ (M ≡ N)
CommMonoidPath = ∫ 𝒮ᴰ-CommMonoid .UARel.ua
| {
"alphanum_fraction": 0.641212406,
"avg_line_length": 32.992248062,
"ext": "agda",
"hexsha": "9eea8077460dec193ea2656042457c7fc9c3664a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Algebra/CommMonoid/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Algebra/CommMonoid/Base.agda",
"max_line_length": 102,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Algebra/CommMonoid/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1632,
"size": 4256
} |
module Limit where
-- Statement that the limit of the function f at point l exists (and its value is L)
-- This is expressed by converting the standard (ε,δ)-limit definition to Skolem normal form (TODO: ...I think? Is this correct?
record Lim (f : ℝ → ℝ) (p : ℝ) (L : ℝ) : Stmt where
field
δ : ℝ₊ → ℝ₊ -- The delta function that is able to depend on epsilon
satisfaction : ∀{ε : ℝ} → ⦃ ε > 𝟎 ⦄ → ∀{x : ℝ} → (𝟎 < ‖ x − p ‖ < δ(ε)) → (‖ f(x) − L ‖ < ε)
-- Limit value function f (if the limit exists)
lim : (f : ℝ → ℝ) → (p : ℝ) → ⦃ _ : ∃(Lim f(p)) ⦄ → ℝ
lim _ _ ⦃ l ⦄ = Lim.L(l)
module Proofs where
postulate [+]-limit : ∀{f g p} → ⦃ _ : ∃(Lim f(p)) ⦄ → ⦃ _ : ∃(Lim g(p)) ⦄ → Lim(x ↦ f(x) + g(x))(p)
postulate [−]-limit : ∀{f g p} → ⦃ _ : ∃(Lim f(p)) ⦄ → ⦃ _ : ∃(Lim g(p)) ⦄ → Lim(x ↦ f(x) − g(x))(p)
postulate [⋅]-limit : ∀{f g p} → ⦃ _ : ∃(Lim f(p)) ⦄ → ⦃ _ : ∃(Lim g(p)) ⦄ → Lim(x ↦ f(x) ⋅ g(x))(p)
postulate [/]-limit : ∀{f g p} → ⦃ _ : ∃(Lim f(p)) ⦄ → ⦃ _ : ∃(Lim g(p)) ⦄ → Lim(x ↦ f(x) / g(x))(p)
postulate [+]-lim : ∀{f g p} → ⦃ _ : ∃(Lim f(p)) ⦄ → ⦃ _ : ∃(Lim g(p)) ⦄ → (lim(x ↦ f(x) + g(x))(p) ≡ lim f(p) + lim g(p))
postulate [−]-lim : ∀{f g p} → ⦃ _ : ∃(Lim f(p)) ⦄ → ⦃ _ : ∃(Lim g(p)) ⦄ → (lim(x ↦ f(x) − g(x))(p) ≡ lim f(p) − lim g(p))
postulate [⋅]-lim : ∀{f g p} → ⦃ _ : ∃(Lim f(p)) ⦄ → ⦃ _ : ∃(Lim g(p)) ⦄ → (lim(x ↦ f(x) ⋅ g(x))(p) ≡ lim f(p) ⋅ lim g(p))
postulate [/]-lim : ∀{f g p} → ⦃ _ : ∃(Lim f(p)) ⦄ → ⦃ _ : ∃(Lim g(p)) ⦄ → (lim(x ↦ f(x) / g(x))(p) ≡ lim f(p) / lim g(p))
| {
"alphanum_fraction": 0.448767834,
"avg_line_length": 67.0434782609,
"ext": "agda",
"hexsha": "db0e86f57f68bb08da32266ac89b842390b0d6a3",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Structure/Real/Limit.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Structure/Real/Limit.agda",
"max_line_length": 130,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Structure/Real/Limit.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 769,
"size": 1542
} |
module FOLdisplay where
open import Data.String using (String)
open import Data.Empty
open import Data.Nat
open import Data.Product
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_; _≢_; refl; sym; cong; subst)
open import Relation.Nullary
open import Data.String using (String; _++_)
-- open import Data.Fin
-- open import Data.Fin.Subset
open import Data.List.Base as List using (List; []; _∷_; [_])
-- open import Data.Bool using () renaming (_∨_ to _∨B_)
Name : Set
Name = String
insert : ℕ → List ℕ → List ℕ
insert n List.[] = n ∷ []
insert n (x ∷ l) with n ≟ x
insert n (.n ∷ l) | yes refl = n ∷ l
insert n (x ∷ l) | no n≠x with n ≤? x
insert n (x ∷ l) | no n≠x | yes n<x = n ∷ x ∷ l
insert n (x ∷ l) | no n≠x | no n>x = x ∷ insert n l
sortRemDups : List ℕ → List ℕ
sortRemDups [] = []
sortRemDups (x ∷ xs) = insert x (sortRemDups xs)
union : List ℕ → List ℕ → List ℕ
union [] ys = ys
union (x ∷ xs) ys = insert x (union xs ys)
remove : ℕ → List ℕ → List ℕ
remove n [] = []
remove n (x ∷ xs) with n Data.Nat.≟ x
remove n (.n ∷ xs) | yes refl = xs
remove n (x ∷ xs) | no _ = x ∷ remove n xs
remove-rewrite : ∀ x {xs} -> remove x (x ∷ xs) ≡ xs
remove-rewrite x with x ≟ x
remove-rewrite x | yes refl = refl
remove-rewrite x | no x≠x = ⊥-elim (x≠x refl)
-- xs \\ ys
diff : List ℕ → List ℕ → List ℕ
diff xs [] = xs
diff xs (x ∷ ys) = diff (remove x xs) ys
--
-- mutual
-- data TermT : List ℕ -> Set where
-- VarT : (n : ℕ) → TermT [ n ]
-- ConstT : Name → TermT []
-- FunT : ∀ {xs} -> Name → (TermList xs) → TermT xs
-- -- [[[_]]]T_ : List (Term × ℕ) → Term → Term
-- data TermList : List ℕ -> Set where
-- []T : TermList []
-- _∷T_ : ∀ {xs ys} (t : TermT xs) (ts : TermT ys) -> TermList (union xs ys)
--
-- data SubstList : List ℕ -> Set where
-- []S : SubstList []
-- _/_∷S_ : ∀ {xs ys} (t : TermT xs) (x : ℕ) (ts : TermT ys) -> SubstList (union xs (remove x ys))
data Term : Set where
Var : ℕ → Term
Const : Name → Term
Fun : Name → List Term → Term
-- [[_/_]]_ : Term → ℕ → Term → Term
[[[_]]]_ : List (Term × ℕ) → Term → Term
mutual
data _⊢≡_ : Term → Term → Set where
atom : ∀ {n} → Var n ⊢≡ Var n
atomC : ∀ {n} → Const n ⊢≡ Const n
funEq : ∀ {n arg1 arg2} → arg1 ≡ₗ arg2 → Fun n arg1 ⊢≡ Fun n arg2
-- subMon : ∀ {substs X Y} → X ⊢≡ Y → ([[[ substs ]]] X) ⊢≡ ([[[ substs ]]] Y) -- this rule is derivable
sub[]R : ∀ {X Y} → X ⊢≡ Y → X ⊢≡ ([[[ [] ]]] Y)
sub[]L : ∀ {X Y} → X ⊢≡ Y → ([[[ [] ]]] X) ⊢≡ Y
subAtomEqR : ∀ {x t lst X} → X ⊢≡ ([[[ lst ]]] t) → X ⊢≡ ([[[ (t , x) ∷ lst ]]] (Var x))
subAtomEqL : ∀ {x t lst Y} → ([[[ lst ]]] t) ⊢≡ Y → ([[[ (t , x) ∷ lst ]]] (Var x)) ⊢≡ Y
subAtomNeqR : ∀ {x y t lst X} → X ⊢≡ ([[[ lst ]]] (Var x)) → x ≢ y → X ⊢≡ ([[[ (t , y) ∷ lst ]]] (Var x))
subAtomNeqL : ∀ {x y t lst Y} → ([[[ lst ]]] (Var x)) ⊢≡ Y → x ≢ y → ([[[ (t , y) ∷ lst ]]] (Var x)) ⊢≡ Y
subAtomCR : ∀ {n lst X} → X ⊢≡ (Const n) → X ⊢≡ ([[[ lst ]]] (Const n))
subAtomCL : ∀ {n lst Y} → (Const n) ⊢≡ Y → ([[[ lst ]]] (Const n)) ⊢≡ Y
subFunR : ∀ {n arg lst X} → X ⊢≡ (Fun n (List.map ([[[_]]]_ lst) arg)) → X ⊢≡ ([[[ lst ]]] (Fun n arg))
subFunL : ∀ {n arg lst Y} → (Fun n (List.map ([[[_]]]_ lst) arg)) ⊢≡ Y → ([[[ lst ]]] (Fun n arg)) ⊢≡ Y
subConsR : ∀ {lst lst' X Y} → X ⊢≡ ([[[ lst List.++ lst' ]]] Y) → X ⊢≡ ([[[ lst' ]]] ([[[ lst ]]] Y))
subConsL : ∀ {lst lst' X Y} → ([[[ lst List.++ lst' ]]] X) ⊢≡ Y → ([[[ lst' ]]] ([[[ lst ]]] X)) ⊢≡ Y
data _≡ₗ_ : List Term → List Term → Set where
[]≡ : [] ≡ₗ []
_∷≡_ : {xs : List Term} {ys : List Term} {t1 t2 : Term} → t1 ⊢≡ t2 → xs ≡ₗ ys → (t1 ∷ xs) ≡ₗ (t2 ∷ ys)
-- open import Data.Maybe using (Maybe; just; nothing; monad)
--
-- open import Category.Monad using (RawMonad)
-- open import Agda.Primitive as P
--
-- open RawMonad (monad {P.lzero}) using (_>>=_;return)
-- open Category.Monad.rawMonad
open import Data.String using () renaming (_≟_ to _≟S_)
data Term' : Set where
Var' : ℕ → Term'
Const' : Name → Term'
Fun' : Name → List Term' → Term'
mutual
data TTerm : List ℕ -> Set where
TVar : (n : ℕ) → TTerm [ n ]
TConst : Name → TTerm []
TFun : ∀ {xs} -> Name → TTermList xs → TTerm xs
data TTermList : List ℕ -> Set where
[]T : TTermList []
_∷T_ : ∀ {xs ys} (t : TTerm xs) (ts : TTermList ys) -> TTermList (union xs ys)
open import Relation.Nullary.Decidable
open import Relation.Binary.Core
open import Data.List.Any as LAny
open LAny.Membership-≡
∈-∷-elim : ∀ {A : Set} {x : A} (y : A) xs -> ¬(x ≡ y) -> y ∈ x ∷ xs -> y ∈ xs
∈-∷-elim x [] x≠y (here refl) = ⊥-elim (x≠y refl)
∈-∷-elim y [] _ (there ())
∈-∷-elim x (x₁ ∷ xs) x≠y (here refl) = ⊥-elim (x≠y refl)
∈-∷-elim y (x₁ ∷ xs) _ (there y∈x∷xs) = y∈x∷xs
_∈ℕ?_ : Decidable {A = ℕ} (_∈_)
x ∈ℕ? [] = no (λ ())
x ∈ℕ? (x' ∷ xs) with x ≟ x'
x ∈ℕ? (.x ∷ xs) | yes refl = yes (here refl)
x ∈ℕ? (x' ∷ xs) | no x≠x' with x ∈ℕ? xs
x ∈ℕ? (x' ∷ xs) | no x≠x' | yes x∈xs = yes (there x∈xs)
x ∈ℕ? (x' ∷ xs) | no x≠x' | no x∉xs = no (λ x∈x'∷xs → x∉xs (∈-∷-elim x xs (λ x'≡x → x≠x' (sym x'≡x)) x∈x'∷xs))
-- subTaux : List ℕ -> ℕ -> List ℕ -> List ℕ
-- subTaux xs x ys with x ∈ℕ? ys
-- subTaux xs x ys | yes _ = union xs (remove x ys)
-- subTaux xs x ys | no _ = ys
-- mutual
-- subT : ∀ {ts ys} → TTerm ts → (x : ℕ) -> TTerm ys → TTerm (subTaux ts x ys)
-- subT t x (TVar x') with x ≟ x'
-- subT t .x' (TVar x') | yes refl rewrite remove-rewrite x' {[]} = {! t' !}
-- ... | no _ = (TVar x')
-- subT _ _ (TConst n) = TConst n
-- subT t x (TFun n args) = TFun n (subTList t x args)
--
-- subTList : ∀ {ts ys} → TTerm ts → (x : ℕ) -> TTermList ys → TTermList (subTaux ts x ys)
-- subTList _ _ []T = []T
-- subTList {ts} t x (_∷T_ {xs} {ys} a args) = rec
-- where
-- a' : TTerm (subTaux ts x xs)
-- a' = subT t x a
--
-- args' : TTermList (subTaux ts x ys)
-- args' = subTList t x args
--
-- ≡-subTaux : ∀ x xs ys -> subTaux ts x (union xs ys) ≡ union (subTaux ts x xs) (subTaux ts x ys)
-- ≡-subTaux _ [] _ = refl
-- ≡-subTaux x (x' ∷ xs) ys = {! !}
--
-- rec : TTermList (subTaux ts x (union xs ys))
-- rec rewrite ≡-subTaux x xs ys = a' ∷T args'
--
-- --subT x t' t ∷T subTList x t' l
--
TTerm→Term : ∀ {xs} -> TTerm xs -> Term
TTerm→Term (TVar n) = Var n
TTerm→Term (TConst c) = Const c
TTerm→Term (TFun n args) = Fun n (TTermList→ListTerm args)
where
TTermList→ListTerm : ∀ {xs} -> TTermList xs -> List Term
TTermList→ListTerm []T = []
TTermList→ListTerm (_∷T_ {_} {ys} t ts) = (TTerm→Term t) ∷ (TTermList→ListTerm {ys} ts)
mutual
sub : ℕ → Term' → Term' → Term'
sub x t' (Var' x') with x ≟ x'
... | yes _ = t'
... | no _ = (Var' x')
sub x t' (Const' n) = Const' n
sub x t' (Fun' n args) = Fun' n (subList x t' args)
subList : ℕ → Term' → List Term' → List Term'
subList x t' [] = []
subList x t' (t ∷ l) = sub x t' t ∷ subList x t' l
mutual
Term→Term' : Term → Term'
Term→Term' (Var x) = Var' x
Term→Term' (Const c) = Const' c
Term→Term' (Fun n args) = Fun' n (LTerm→LTerm' args)
Term→Term' ([[[ lst ]]] t) = STerm lst (Term→Term' t)
LTerm→LTerm' : List Term → List Term'
LTerm→LTerm' [] = []
LTerm→LTerm' (x ∷ l) = Term→Term' x ∷ LTerm→LTerm' l
STerm : List (Term × ℕ) → Term' → Term'
STerm [] t = t
STerm ((t' , x) ∷ lst) t = STerm lst (sub x (Term→Term' t') t)
mutual
⊢≡symm : ∀ {t1 t2 : Term} → t1 ⊢≡ t2 → t2 ⊢≡ t1
⊢≡symm atom = atom
⊢≡symm atomC = atomC
⊢≡symm (funEq x) = funEq (≡ₗsymm x)
⊢≡symm (sub[]R {Y = Y} t1⊢≡t2) = sub[]L (⊢≡symm t1⊢≡t2)
⊢≡symm (sub[]L {X = X} t1⊢≡t2) = sub[]R (⊢≡symm t1⊢≡t2)
⊢≡symm (subAtomEqR {t = t} {lst} t1⊢≡t2) = subAtomEqL (⊢≡symm t1⊢≡t2)
⊢≡symm (subAtomEqL {t = t} {lst} t1⊢≡t2) = subAtomEqR (⊢≡symm t1⊢≡t2)
⊢≡symm (subAtomNeqR {x = x} t1⊢≡t2 x₁) = subAtomNeqL (⊢≡symm t1⊢≡t2) x₁
⊢≡symm (subAtomNeqL {x = x} t1⊢≡t2 x₁) = subAtomNeqR (⊢≡symm t1⊢≡t2) x₁
⊢≡symm (subAtomCR {n = n} t1⊢≡t2) = subAtomCL (⊢≡symm t1⊢≡t2)
⊢≡symm (subAtomCL t1⊢≡t2) = subAtomCR (⊢≡symm t1⊢≡t2)
⊢≡symm (subFunR t1⊢≡t2) = subFunL (⊢≡symm t1⊢≡t2)
⊢≡symm (subFunL t1⊢≡t2) = subFunR (⊢≡symm t1⊢≡t2)
⊢≡symm (subConsR t1⊢≡t2) = subConsL (⊢≡symm t1⊢≡t2)
⊢≡symm (subConsL t1⊢≡t2) = subConsR (⊢≡symm t1⊢≡t2)
≡ₗsymm : ∀ {arg1 arg2} → arg1 ≡ₗ arg2 → arg2 ≡ₗ arg1
≡ₗsymm []≡ = []≡
≡ₗsymm (x ∷≡ arg1≡ₗarg2) = (⊢≡symm x) ∷≡ (≡ₗsymm arg1≡ₗarg2)
≡-Fun-nm : ∀ {n n' args args'} → Fun' n args ≡ Fun' n' args' → n ≡ n'
≡-Fun-nm refl = refl
≡-Fun-args : ∀ {n args args'} → Fun' n args ≡ Fun' n args' → args ≡ args'
≡-Fun-args refl = refl
Fun-args-≡ : ∀ {n args args'} → args ≡ args' → Fun' n args ≡ Fun' n args'
Fun-args-≡ refl = refl
substFun≡aux : ∀ {n} lst args → STerm lst (Fun' n args) ≡ Fun' n (List.map (STerm lst) args)
substFun≡aux [] args = Fun-args-≡ (aux args)
where
aux : ∀ args → args ≡ List.map (STerm []) args
aux [] = refl
aux (a ∷ args) = cong (_∷_ a) (aux args)
substFun≡aux {n} ((t , x) ∷ lst) args = PropEq.trans (substFun≡aux {n} lst (subList x (Term→Term' t) args)) (Fun-args-≡ (aux lst x t args))
where
aux : ∀ lst x t args → List.map (STerm lst) (subList x (Term→Term' t) args) ≡ List.map (STerm ((t , x) ∷ lst)) args
aux lst x t [] = refl
aux lst x t (x' ∷ args) = cong (_∷_ (STerm lst (sub x (Term→Term' t) x'))) (aux lst x t args)
substFun≡ : ∀ {n} args lst → Term→Term' ([[[ lst ]]] Fun n args) ≡ Fun' n (LTerm→LTerm' (List.map ([[[_]]]_ lst) args))
substFun≡ [] [] = refl
substFun≡ [] (s ∷ lst) = substFun≡ [] lst
substFun≡ (a ∷ args) [] = Fun-args-≡ (cong (_∷_ (Term→Term' a)) (LTerm[]Subst args))
where
LTerm[]Subst : ∀ args → LTerm→LTerm' args ≡ LTerm→LTerm' (List.map ([[[_]]]_ []) args)
LTerm[]Subst [] = refl
LTerm[]Subst (a ∷ args) = cong (_∷_ (Term→Term' a)) (LTerm[]Subst args)
substFun≡ (a ∷ args) ((t , x) ∷ lst) = PropEq.trans
(substFun≡aux lst (subList x (Term→Term' t) (LTerm→LTerm' (a ∷ args))))
(Fun-args-≡ (aux (a ∷ args)))
where
aux : ∀ args {lst x t} → List.map (STerm lst) (subList x (Term→Term' t) (LTerm→LTerm' args)) ≡ LTerm→LTerm' (List.map ([[[_]]]_ ((t , x) ∷ lst)) args)
aux [] = refl
aux (a ∷ args) {lst} {x} {t} = cong (_∷_ (STerm lst (sub x (Term→Term' t) (Term→Term' a)))) (aux args)
++[]-id : ∀ {a} {A : Set a} (lst : List A) → lst List.++ [] ≡ lst
++[]-id [] = refl
++[]-id (x ∷ xs) = cong (_∷_ x) (++[]-id xs)
substSubst≡ : ∀ {lst lst' t} → Term→Term' ([[[ lst ]]] ([[[ lst' ]]] t)) ≡ Term→Term' ([[[ lst' List.++ lst ]]] t)
substSubst≡ {[]} {lst'} rewrite ++[]-id lst' = refl
substSubst≡ {(t , x₂) ∷ lst} {[]} = refl
substSubst≡ {(t , x) ∷ lst} {(t' , x') ∷ lst'} {t''} = substSubst≡ {(t , x) ∷ lst} {lst'} {[[[ [ (t' , x') ] ]]] t''}
subsConst≡ : ∀ {lst c} → Term→Term' ([[[ lst ]]] (Const c)) ≡ Const' c
subsConst≡ {[]} = refl
subsConst≡ {_ ∷ lst} {c} = subsConst≡ {lst} {c}
open import Data.List.Properties
substTac : (t1 : Term) → (t2 : Term) → {_ : Term→Term' t1 ≡ Term→Term' t2} → t1 ⊢≡ t2
{-# TERMINATING #-}
substTac (Var x) (Var .x) {refl} = atom
substTac (Var _) (Const _) {()}
substTac (Var _) (Fun _ _) {()}
substTac (Const _) (Var _) {()}
substTac (Const c) (Const .c) {refl} = atomC
substTac (Const _) (Fun _ _) {()}
substTac (Fun _ _) (Var _) {()}
substTac (Fun _ _) (Const _) {()}
substTac (Fun n args) (Fun n' args') with n ≟S n'
substTac (Fun n []) (Fun .n []) | yes refl = funEq []≡
substTac (Fun n []) (Fun .n (_ ∷ _)) {()} | yes refl
substTac (Fun n (x ∷ args)) (Fun .n []) {()} | yes refl
substTac (Fun n (t ∷ args)) (Fun .n (t' ∷ args')) {eq} | yes refl with
substTac t t' {proj₁ (∷-injective (≡-Fun-args eq))} |
substTac (Fun n args) (Fun n args') {Fun-args-≡ (proj₂ (∷-injective (≡-Fun-args eq)))}
substTac (Fun n (t ∷ args)) (Fun .n (t' ∷ args')) | yes refl | t⊢≡t' | funEq args≡ₗargs' = funEq (t⊢≡t' ∷≡ args≡ₗargs')
substTac (Fun n args) (Fun n' args') {eq} | no ¬p = ⊥-elim (¬p (≡-Fun-nm eq))
substTac t1 ([[[ [] ]]] t2) {eq} = sub[]R (substTac t1 t2 {eq})
substTac t1 ([[[ (t , x') ∷ lst ]]] Var x) with x ≟ x'
substTac t1 ([[[ (t , x') ∷ lst ]]] Var .x') {eq} | yes refl =
subAtomEqR (substTac t1 ([[[ lst ]]] t) {eq' {x'} {Term→Term' t1} {t} {lst} eq}) -- agda doesnt like this call because it doesnt get structurally smaller, but its fine...
where
eq' : ∀ {x t t' lst} → t ≡ Term→Term' (([[[ (t' , x) ∷ lst ]]] Var x)) → t ≡ Term→Term' ([[[ lst ]]] t')
eq' {x} refl with x ≟ x
eq' {x} refl | yes _ = refl
eq' {x} refl | no ¬p = ⊥-elim (¬p refl)
substTac t1 ([[[ (t , x') ∷ lst ]]] Var x) {eq} | no ¬p = subAtomNeqR (substTac t1 ([[[ lst ]]] (Var x)) {eq' {x} {x'} {Term→Term' t1} {t} {lst} eq ¬p}) ¬p
where
eq' : ∀ {x x' t t' lst} → t ≡ Term→Term' (([[[ (t' , x') ∷ lst ]]] Var x)) → x ≢ x' → t ≡ Term→Term' ([[[ lst ]]] Var x)
eq' {x} {x'} refl x≠x' with x' ≟ x
eq' {x} {.x} refl x≠x' | yes refl = ⊥-elim (x≠x' refl)
eq' {x} {x'} refl x≠x' | no ¬p = refl
substTac t1 ([[[ x ∷ lst ]]] Const c) {eq} = subAtomCR (substTac t1 (Const c) {PropEq.trans eq (subsConst≡ {x ∷ lst} {c})})
substTac t1 ([[[ x ∷ lst ]]] Fun n args) {eq} = subFunR (substTac t1 (Fun n (List.map ([[[_]]]_ (x ∷ lst)) args)) {PropEq.trans eq (substFun≡ args (x ∷ lst))})
substTac t1 ([[[ x ∷ lst ]]] ([[[ lst' ]]] t2)) {eq} =
subConsR (substTac t1 ([[[ lst' List.++ x ∷ lst ]]] t2) {PropEq.trans eq (substSubst≡ {x ∷ lst} {lst'} {t2})})
substTac ([[[ lst ]]] t1) t2 {eq} = ⊢≡symm (substTac t2 ([[[ lst ]]] t1) {sym eq}) -- adga doesn't like this, but it should be fine...
⊢≡-≡ : ∀ {X Y} → X ⊢≡ Y → Term→Term' X ≡ Term→Term' Y
⊢≡-≡ atom = refl
⊢≡-≡ atomC = refl
⊢≡-≡ (funEq x) = Fun-args-≡ (≡ₗ→≡ x)
where
∷-≡ : ∀ {a} {A : Set a} {x y : A} {xs ys} → x ≡ y → xs ≡ ys → x ∷ xs ≡ y ∷ ys
∷-≡ refl refl = refl
≡ₗ→≡ : ∀ {arg1 arg2} → arg1 ≡ₗ arg2 → (LTerm→LTerm' arg1) ≡ (LTerm→LTerm' arg2)
≡ₗ→≡ []≡ = refl
≡ₗ→≡ (t1⊢≡t2 ∷≡ ≡ₗ) = ∷-≡ (⊢≡-≡ t1⊢≡t2) (≡ₗ→≡ ≡ₗ)
⊢≡-≡ (sub[]R X⊢≡Y) = ⊢≡-≡ X⊢≡Y
⊢≡-≡ (sub[]L X⊢≡Y) = ⊢≡-≡ X⊢≡Y
⊢≡-≡ (subAtomEqR {x} X⊢≡Y) with x ≟ x
⊢≡-≡ (subAtomEqR {x} X⊢≡Y) | yes p = ⊢≡-≡ X⊢≡Y
⊢≡-≡ (subAtomEqR {x} X⊢≡Y) | no ¬p = ⊥-elim (¬p refl)
⊢≡-≡ (subAtomEqL {x} X⊢≡Y) with x ≟ x
⊢≡-≡ (subAtomEqL {x} X⊢≡Y) | yes p = ⊢≡-≡ X⊢≡Y
⊢≡-≡ (subAtomEqL {x} X⊢≡Y) | no ¬p = ⊥-elim (¬p refl)
⊢≡-≡ (subAtomNeqR {x} {y} X⊢≡Y x₁) with y ≟ x
⊢≡-≡ (subAtomNeqR {x} {.x} X⊢≡Y x₁) | yes refl = ⊥-elim (x₁ refl)
⊢≡-≡ (subAtomNeqR {x} {y} X⊢≡Y x₁) | no ¬p = ⊢≡-≡ X⊢≡Y
⊢≡-≡ (subAtomNeqL {x} {y} X⊢≡Y x₁) with y ≟ x
⊢≡-≡ (subAtomNeqL {x} {.x} X⊢≡Y x₁) | yes refl = ⊥-elim (x₁ refl)
⊢≡-≡ (subAtomNeqL {x} {y} X⊢≡Y x₁) | no ¬p = ⊢≡-≡ X⊢≡Y
⊢≡-≡ (subAtomCR {c} {lst} X⊢≡Y) = PropEq.trans (⊢≡-≡ X⊢≡Y) (sym (subsConst≡ {lst} {c}))
⊢≡-≡ (subAtomCL {c} {lst} X⊢≡Y) = PropEq.trans (subsConst≡ {lst} {c}) (⊢≡-≡ X⊢≡Y)
⊢≡-≡ (subFunR {n} {args} {lst} X⊢≡Y) = PropEq.trans (⊢≡-≡ X⊢≡Y) (sym (substFun≡ {n} args lst))
⊢≡-≡ (subFunL {n} {args} {lst} X⊢≡Y) = PropEq.trans (substFun≡ {n} args lst) (⊢≡-≡ X⊢≡Y)
⊢≡-≡ (subConsR {lst} {lst'} {_} {Y} X⊢≡Y) = PropEq.trans (⊢≡-≡ X⊢≡Y) (sym (substSubst≡ {lst'} {lst} {Y}))
⊢≡-≡ (subConsL {lst} {lst'} {X} X⊢≡Y) = PropEq.trans (substSubst≡ {lst'} {lst} {X}) (⊢≡-≡ X⊢≡Y)
mutual
⊢≡atom : ∀ {t} → t ⊢≡ t
⊢≡atom {Var x} = atom
⊢≡atom {Const x} = atomC
⊢≡atom {Fun x x₁} = funEq ≡ₗatom
where
≡ₗatom : ∀ {xs} → xs ≡ₗ xs
≡ₗatom {[]} = []≡
≡ₗatom {x ∷ xs} = ⊢≡atom ∷≡ ≡ₗatom
⊢≡atom {[[[ x ]]] t} = ⊢≡subMon ⊢≡atom
⊢≡subMon : ∀ {sub X Y} → X ⊢≡ Y → ([[[ sub ]]] X) ⊢≡ ([[[ sub ]]] Y)
⊢≡subMon {sub} {X} {Y} X⊢≡Y = substTac ([[[ sub ]]] X) ([[[ sub ]]] Y) {mon {sub} {Term→Term' X} {Term→Term' Y} (⊢≡-≡ X⊢≡Y)}
where
mon : ∀ {sub X Y} → X ≡ Y → STerm sub X ≡ STerm sub Y
mon refl = refl
-- data _∈_ : ℕ → List ℕ → Set where
-- here : ∀ {x xs} → x ∈ (x ∷ xs)
-- there : ∀ {x y xs} → x ∈ xs → x ∈ (y ∷ xs)
--
-- data _⊆_ : List ℕ → List ℕ → Set where
-- nil : ∀ {xs} → [] ⊆ xs
-- cons : ∀ {x xs ys} → x ∈ ys → xs ⊆ ys → (x ∷ xs) ⊆ ys
--
-- _∉_ : ℕ → List ℕ → Set
-- n ∉ ns = ¬ (n ∈ ns)
--
-- _⊈_ : List ℕ → List ℕ → Set
-- xs ⊈ ys = ¬ (xs ⊆ ys)
mutual
FV : Term' → List ℕ
FV (Var' x) = [ x ]
FV (Const' _) = []
FV (Fun' _ args) = FVs args
FVs : List Term' → List ℕ
FVs [] = []
FVs (t ∷ ts) = union (FV t) (FVs ts)
data Formula : List ℕ → Set where
_⟨_⟩ : Name → ∀ {xs} (ts : TTermList xs) → Formula xs
_∧_ : ∀ {ns} → Formula ns → Formula ns → Formula ns
_∨_ : ∀ {ns} → Formula ns → Formula ns → Formula ns
_⟶_ : ∀ {ns} → Formula ns → Formula ns → Formula ns
∘ : ∀ {ns} v → Formula ns → {v∉ : v ∉ ns} → Formula (insert v ns)
-- [_/_] : ∀ {y ns} → Term → (x : ℕ) → {x∈ : x ∈ ns} → {y⊆ : y ⊆ ns} → {x≠y : [ x ] ≢ y} → Formula ns → Formula (remove x ns)
-- [_//_] : ∀ {y ns} → Term y → (x : ℕ) → {x⊆ : x ∈ ns} → {y⊈ : y ⊈ ns} → {x≠y : [ x ] ≢ y} → Formula ns → Formula (union y (remove x ns))
All : ∀ {ns} v → Formula ns → Formula (remove v ns)
Ex : ∀ {ns} v → Formula ns → Formula (remove v ns)
data Structure : List ℕ → Set where
∣_∣ : ∀ {n} → Formula n → Structure n
_,_ : ∀ {n m} → Structure n → Structure m → {n≡m : n ≡ m} -> Structure n
_>>_ : ∀ {n m} → Structure n → Structure m → {n≡m : n ≡ m} → Structure n
_<<_ : ∀ {n m} → Structure n → Structure m → {n≡m : n ≡ m} → Structure n
I : ∀ {n} → Structure n
○ : ∀ {n} v → Structure n → {v∉ : v ∉ n} → Structure (insert v n)
Q : ∀ {n} v → Structure n → Structure (remove v n)
data _⊢_ : ∀ {n} → Structure n → Structure n → Set where
atom : ∀ {n xs} {ts us : TTermList xs} →
∣ n ⟨ ts ⟩ ∣ ⊢ ∣ n ⟨ us ⟩ ∣
allR : ∀ {x n X Y} →
Y ⊢ Q {n} x ∣ X ∣ →
-------------------
Y ⊢ ∣ All {n} x X ∣
allL : ∀ {x n X Y} →
∣ Y ∣ ⊢ ∣ X ∣ →
-------------------------------
∣ All {n} x Y ∣ ⊢ Q {n} x ∣ X ∣
open import Data.Unit as Unit using (⊤)
open import Data.Nat.Properties as Propℕ
_≤'?_ : Decidable _≤′_
x ≤'? y with x ≤? y
x ≤'? y | yes p = yes (≤⇒≤′ p)
x ≤'? y | no ¬p = no (λ x₁ → ¬p (≤′⇒≤ x₁))
-- mutual
-- data OList : Set where
-- []O : OList
-- _∷O_ : (x : ℕ) -> (xs : OList) -> {x< : isLess x xs} -> OList
--
-- isLess : ℕ -> OList -> Set
-- isLess x []O = ⊤
-- isLess x (y ∷O ol) with x ≤'? y
-- isLess x (.x ∷O ol) | yes ≤′-refl = ⊥
-- isLess x (.(suc _) ∷O ol) | yes (≤′-step _) = ⊤
-- isLess x (y ∷O ol) | no _ = ⊥
--
--
--
-- mutual
-- data IsLess : ℕ -> OList -> Set where
-- nil : ∀ {x} -> IsLess x []O
-- cons : ∀ {x x' xs} -> x < x' -> (x'<xs : IsLess x' xs) -> IsLess x ((x' ∷O xs) {IsLess→isLess x'<xs})
--
-- IsLess→isLess : ∀ {x xs} -> IsLess x xs -> isLess x xs
-- IsLess→isLess nil = ⊤.tt
-- IsLess→isLess {x} (cons {x' = x'} x<x' x<xs) with x ≤'? x'
-- IsLess→isLess {x} (cons {_} {.x} x<x' x<xs) | yes ≤′-refl = contr x<x'
-- where
-- contr : ∀ {x} -> suc x ≤ x -> ⊥
-- contr {zero} ()
-- contr {suc x} (s≤s sx≤x) = contr sx≤x
-- IsLess→isLess {x} (cons {_} {.(suc _)} x<x' x<xs) | yes (≤′-step p) = ⊤.tt
-- IsLess→isLess {x} (cons {_} {x'} x<x' x<xs) | no ¬x≤′x' = ¬x≤′x' (≤⇒≤′ (sucx≤y→x≤y x<x'))
-- where
-- sucx≤y→x≤y : ∀ {x y} -> suc x ≤ y -> x ≤ y
-- sucx≤y→x≤y {zero} sx≤y = z≤n
-- sucx≤y→x≤y {suc x} (s≤s sx≤y) = s≤s (sucx≤y→x≤y sx≤y)
--
-- open import Data.Sum
--
--
-- isLess→IsLess : ∀ {x xs} -> isLess x xs -> IsLess x xs
-- isLess→IsLess {x} {[]O} ⊤.tt = nil
-- isLess→IsLess {x} {x' ∷O xs} x< with x ≤'? x'
-- isLess→IsLess {.x'} {x' ∷O xs} () | yes ≤′-refl
-- isLess→IsLess {x} {(.(suc _) ∷O xs) {sn<}} ⊤.tt | yes (≤′-step {n = n} x≤′n) = {!sn< !}
-- where
-- aux : x < suc n
-- aux = {! sn< !}
--
-- rec : IsLess (suc n) xs
-- rec = isLess→IsLess sn<
-- --
-- aux₂ : IsLess x ((suc n ∷O xs) {sn<})
-- aux₂ = cons aux rec
--
-- isLess→IsLess {x} {x' ∷O xs} x< | no ¬p = {! !}
mutual
data OList : Set where
[]O : OList
_∷O_ : (x : ℕ) -> (xs : OList) -> {x< : IsLess x xs} -> OList
data IsLess : ℕ -> OList -> Set where
base : ∀ {x} -> IsLess x []O
step : ∀ {x x' xs} -> x < x' -> (x'<xs : IsLess x' xs) -> IsLess x ((x' ∷O xs) {x'<xs})
IsLess→< : ∀ {x x' xs x'<} -> IsLess x ((x' ∷O xs) {x'<}) -> x < x'
IsLess→< (step x<x' _) = x<x'
mutual
insertO : ℕ -> OList -> OList
insertO x []O = (x ∷O []O) {base}
insertO x (x' ∷O xs) with x ≤'? x'
insertO x ((.x ∷O xs) {x<}) | yes ≤′-refl = (x ∷O xs) {x<}
insertO x ((.(suc _) ∷O xs) {x<}) | yes (≤′-step {n = x'} p) = (x ∷O (((suc x') ∷O xs) {x<})) {step (s≤s (≤′⇒≤ p)) x<}
insertO x ((x' ∷O xs) {x'<}) | no x'<x = (x' ∷O insertO x xs) {insertO-lemma xs x'< x'<x}
insertO-lemma : ∀ {x x'} xs -> IsLess x' xs -> ¬ x ≤′ x' -> IsLess x' (insertO x xs)
insertO-lemma []O base ¬x≤′x' = step (≰⇒> (λ x≤x' → ¬x≤′x' (≤⇒≤′ x≤x'))) base
insertO-lemma {x} {x'} (x'' ∷O xs) x'<xs x'<x with x ≤'? x''
insertO-lemma {.x''} {x'} ((x'' ∷O xs) {x''<}) x'<xs _ | yes ≤′-refl = step (IsLess→< x'<xs) x''<
insertO-lemma {x} {x'} ((.(suc _) ∷O xs) {sn<xs}) x'<xs ¬x≤′x' | yes (≤′-step x≤′n) =
step (≰⇒> (λ x≤x' → ¬x≤′x' (≤⇒≤′ x≤x'))) (step (s≤s (≤′⇒≤ x≤′n)) sn<xs)
insertO-lemma {x} {x'} ((x'' ∷O xs) {x''<xs}) x'<xs _ | no x''<x = step (IsLess→< x'<xs) (insertO-lemma {x} {x''} xs x''<xs x''<x)
data _∈O_ : ℕ -> OList -> Set where
here : ∀ {x xs x<xs} -> x ∈O ((x ∷O xs) {x<xs})
there : ∀ {x y xs y<xs} -> x ∈O xs -> x ∈O ((y ∷O xs) {y<xs})
_∉O_ : ℕ -> OList -> Set
x ∉O xs = ¬ (x ∈O xs)
IsLess-remove : ∀ {x x'} xs {x'<xs} -> IsLess x ((x' ∷O xs) {x'<xs}) -> IsLess x xs
IsLess-remove []O x<x∷xs = base
IsLess-remove ((x'' ∷O xs) {x''<xs}) (step x<x' x'<x''∷xs) = step (<-trans x<x' (IsLess→< x'<x''∷xs)) x''<xs
mutual
removeO : ℕ -> OList -> OList
removeO x []O = []O
removeO x (x' ∷O xs) with x ≟ x'
removeO x (.x ∷O xs) | yes refl = xs
removeO x ((x' ∷O xs) {x'<xs}) | no ¬p = (x' ∷O removeO x xs) {removeO-lemma {x} {x'} xs x'<xs}
removeO-lemma : ∀ {x x'} xs -> IsLess x' xs -> IsLess x' (removeO x xs)
removeO-lemma []O x'<xs = base
removeO-lemma {x} {x'} (x'' ∷O xs) x'<xs with x ≟ x''
removeO-lemma {.x''} {x'} (x'' ∷O xs) x<xs | yes refl = IsLess-remove xs x<xs
removeO-lemma {x} {x'} ((x'' ∷O xs) {x''<xs}) x'<xs | no ¬p = step (IsLess→< x'<xs) (removeO-lemma {x} {x''} xs x''<xs)
-- isLess : ℕ -> OList -> Set
-- isLess x []O = ⊤
-- isLess x (y ∷O ol) with x ≤'? y
-- isLess x (.x ∷O ol) | yes ≤′-refl = ⊥
-- isLess x (.(suc _) ∷O ol) | yes (≤′-step _) = ⊤
-- isLess x (y ∷O ol) | no _ = ⊥
--
-- smart constructor for OList
_∷O'_ : (x : ℕ) -> (xs : OList) -> OList
x ∷O' xs = insertO x xs
testOList : OList
testOList = 2 ∷O' (1 ∷O' (2 ∷O' []O))
data Formula' : OList → Set where
-- _⟨_⟩ : Name → ∀ {xs} (ts : TTermList xs) → Formula xs
_∧_ : ∀ {ns} → Formula' ns → Formula' ns → Formula' ns
_∨_ : ∀ {ns} → Formula' ns → Formula' ns → Formula' ns
_⟶_ : ∀ {ns} → Formula' ns → Formula' ns → Formula' ns
∘ : ∀ {ns} v → Formula' ns → {v∉ : v ∉O ns} → Formula' (insertO v ns)
-- [_/_] : ∀ {y ns} → Term → (x : ℕ) → {x∈ : x ∈ ns} → {y⊆ : y ⊆ ns} → {x≠y : [ x ] ≢ y} → Formula ns → Formula (remove x ns)
-- [_//_] : ∀ {y ns} → Term y → (x : ℕ) → {x⊆ : x ∈ ns} → {y⊈ : y ⊈ ns} → {x≠y : [ x ] ≢ y} → Formula ns → Formula (union y (remove x ns))
All : ∀ {ns} v → Formula' ns → Formula' (removeO v ns)
Ex : ∀ {ns} v → Formula' ns → Formula' (removeO v ns)
-- insert-reomve-id : ∀ {x n m} -> n ≡ m -> n ≡ insertO x (removeO x m)
-- insert-reomve-id {x} {xs} refl = {! xs !}
rem-inj : ∀ {n m} x -> n ≡ m -> remove x n ≡ remove x m
rem-inj _ refl = refl
data _⊢⟨_⟩_ : ∀ {n m} → Structure n → n ≡ m -> Structure m → Set where
atom : ∀ {n xs n≡m} {ts us : TTermList xs} →
∣ n ⟨ ts ⟩ ∣ ⊢⟨ n≡m ⟩ ∣ n ⟨ us ⟩ ∣
allR : ∀ {x n m n≡m X} {Y : Structure m} →
Y ⊢⟨ n≡m ⟩ Q {n} x ∣ X ∣ →
-------------------
Y ⊢⟨ n≡m ⟩ ∣ All {n} x X ∣
allL : ∀ {x n m n≡m X} {Y : Formula m} →
∣ X ∣ ⊢⟨ n≡m ⟩ ∣ Y ∣ →
-------------------------------
∣ All {n} x X ∣ ⊢⟨ rem-inj x n≡m ⟩ Q {m} x ∣ Y ∣
IL : ∀ {n m n≡m} {X : Structure n} {Y : Structure m} →
X ⊢⟨ n≡m ⟩ Y →
-------------------
(I , X) {refl} ⊢⟨ n≡m ⟩ Y
IL2 : ∀ {n m n≡m} {X : Structure n} {Y : Structure m} →
(I , X) {refl} ⊢⟨ n≡m ⟩ Y →
-------------------
X ⊢⟨ n≡m ⟩ Y
IR : ∀ {n m n≡m} {X : Structure n} {Y : Structure m} →
X ⊢⟨ n≡m ⟩ Y →
-----------------
X ⊢⟨ n≡m ⟩ (Y , I) {refl}
IR2 : ∀ {n m n≡m} {X : Structure n} {Y : Structure m} →
X ⊢⟨ n≡m ⟩ (Y , I) {refl} →
-----------------
X ⊢⟨ n≡m ⟩ Y
,>>disp : ∀ {n m n≡m} {Z : Structure n} {X Y : Structure m} →
Z ⊢⟨ n≡m ⟩ (X , Y) {refl} →
-----------------
(X >> Z) {sym n≡m} ⊢⟨ refl ⟩ Y
,>>disp2 : ∀ {n m n≡m} {Z : Structure n} {X Y : Structure m} →
(X >> Z) {sym n≡m} ⊢⟨ refl ⟩ Y →
-----------------
Z ⊢⟨ n≡m ⟩ (X , Y) {refl}
○IR : ∀ {x n m n≡m x∉m} {X : Structure n} →
X ⊢⟨ n≡m ⟩ (I {insert x m}) →
-----------------
X ⊢⟨ n≡m ⟩ ○ x (I {m}) {x∉m}
○IR2 : ∀ {x n m n≡m x∉m} {X : Structure n} →
X ⊢⟨ n≡m ⟩ ○ x (I {m}) {x∉m} →
-----------------
X ⊢⟨ n≡m ⟩ (I {insert x m})
-- ,<<disp : ∀ {n m n≡m} {X : Structure n} {Y Z : Structure m} →
-- X ⊢⟨ n≡m ⟩ (Y , Z) {refl} →
-- -----------------
-- (X >> Z) {n≡m} ⊢⟨ n≡m ⟩ Y
-- ,<<disp2 : ∀ {n m n≡m} {X : Structure n} {Y Z : Structure m} →
-- (X >> Z) {n≡m} ⊢⟨ n≡m ⟩ Y →
-- -----------------
-- X ⊢⟨ n≡m ⟩ (Y , Z) {refl}
rem-union-id : ∀ x -> remove x (union [ x ] []) ≡ []
rem-union-id x rewrite remove-rewrite x {[]} = refl
test : ∀ x y {n} -> ∣ All x (n ⟨ (TVar x) ∷T []T ⟩) ∣ ⊢⟨ PropEq.trans (rem-union-id x) (sym (rem-union-id y)) ⟩ ∣ All y (n ⟨ (TVar y) ∷T []T ⟩) ∣
test x y = allR ?
data Map : List ℕ → Set where
nil : Map []
_/_:::_ : ∀ {xs} (x : ℕ) → String → Map xs → Map (x ∷ xs)
_!!_ : List (ℕ × String) → ℕ → String
[] !! _ = "not found"
((x , s) ∷ m) !! y with x ≟ y
... | yes _ = s
... | no _ = m !! y
Term→Str : List (ℕ × String) → Term → String
Term→Str m (Var x) = "\\textit{" ++ (m !! x) ++ "}"
Term→Str m (Const s) = "\\textbf{" ++ s ++ "}"
Term→Str m (Fun n args) = "" --"\\textbf{" ++ s ++ "}"
-- Term→Str m ([[_/_]]_ _ _ _) = "" --"\\textbf{" ++ s ++ "}"
Term→Str m ([[[_]]]_ _ _) = ""
Formula→Str : ∀ {xs} → List (ℕ × String) → Formula xs → String
Formula→Str m (n ⟨ args ⟩) = n ++ "(" ++ ")" --aux args ++ ")"
-- where
-- aux : List Term → String
-- aux [] = ""
-- aux (x ∷ []) = Term→Str m x
-- aux (x ∷ (y ∷ args)) = Term→Str m x ++ ", " ++ aux (y ∷ args)
Formula→Str m (f ∧ f₁) = Formula→Str m f ++ " \\land " ++ Formula→Str m f₁
Formula→Str m (f ∨ f₁) = Formula→Str m f ++ " \\lor " ++ Formula→Str m f₁
Formula→Str m (f ⟶ f₁) = Formula→Str m f ++ " \\leftarrow " ++ Formula→Str m f₁
Formula→Str m (∘ v f) = "\\circ_" ++ (m !! v) ++ Formula→Str m f
-- Formula→Str m ([ y / x ] f) = "(" ++ Term→Str m y ++ "/" ++ (m !! x) ++ ") " ++ Formula→Str m f
-- Formula→Str m ([ y // x ] f) = "(" ++ Term→Str m y ++ "//" ++ (m !! x) ++ ") " ++ Formula→Str m f
Formula→Str m (All v f) = "\\forall " ++ (m !! v) ++ Formula→Str m f
Formula→Str m (Ex v f) = "\\exists " ++ (m !! v) ++ Formula→Str m f
Structure→Str : ∀ {xs} → List (ℕ × String) → Structure xs → String
Structure→Str m ∣ x ∣ = Formula→Str m x
Structure→Str m (s , s₁) = Structure→Str m s ++ " , " ++ Structure→Str m s₁
Structure→Str m (s >> s₁) = Structure→Str m s ++ " >> " ++ Structure→Str m s₁
Structure→Str m (s << s₁) = Structure→Str m s ++ " << " ++ Structure→Str m s₁
Structure→Str m I = "I"
Structure→Str m (○ v s) = "\\bigcirc_" ++ (m !! v) ++ Structure→Str m s
Structure→Str m (Q v s) = "Q " ++ (m !! v) ++ Structure→Str m s
⊢concl : ∀ {n} {xs ys : Structure n} → xs ⊢ ys → (Structure n × Structure n)
⊢concl {_} {xs} {ys} _ = xs , ys
data ⊢List : Set where
⊢nil : ⊢List
_⊢::_ : ∀ {n} {xs ys : Structure n} → xs ⊢ ys → ⊢List → ⊢List
⊢prems : ∀ {n} {xs ys : Structure n} → xs ⊢ ys → ⊢List
⊢prems atom = ⊢nil
⊢prems (allR xs⊢ys) = xs⊢ys ⊢:: ⊢nil
⊢prems (allL xs⊢ys) = xs⊢ys ⊢:: ⊢nil
-- proof1 : ∀ {n} P (args : TList n) → ∣ P ⟨ args ⟩ ∣ ⊢ ∣ P ⟨ args ⟩ ∣
-- proof1 P args = atom
--
-- proof : ∣ "P" ⟨ Var 0 ::: nil ⟩ ∣ ⊢ ∣ "P" ⟨ Var 0 ::: nil ⟩ ∣
-- proof = let (x , y) = ⊢concl (proof1 "P" (Var 0 ::: nil)) in {!Structure→Str [ (0 , "x") ] x !}
⊢→Str' : ∀ {n} {xs ys : Structure n} → List (ℕ × String) → xs ⊢ ys → String
⊢→Str' m xs⊢ys with ⊢concl xs⊢ys | ⊢prems xs⊢ys
⊢→Str' m xs⊢ys | xs , ys | prems = Structure→Str m xs ++ " \\vdash " ++ Structure→Str m ys
where
prems→Str : ⊢List → String
prems→Str ⊢nil = ""
prems→Str (x ⊢:: lst) = {! !}
open import IO
main = run (putStrLn "Hello, world!")
| {
"alphanum_fraction": 0.4825350345,
"avg_line_length": 36.4498094028,
"ext": "agda",
"hexsha": "43e3a3f804fe974134432a12706f9df093294e92",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b4f3ce288633417ce309a0a1371ad0907a007b30",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "goodlyrottenapple/FOLdisplay",
"max_forks_repo_path": "FOLdisplay.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b4f3ce288633417ce309a0a1371ad0907a007b30",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "goodlyrottenapple/FOLdisplay",
"max_issues_repo_path": "FOLdisplay.agda",
"max_line_length": 172,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b4f3ce288633417ce309a0a1371ad0907a007b30",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "goodlyrottenapple/FOLdisplay",
"max_stars_repo_path": "FOLdisplay.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 13644,
"size": 28686
} |
import Algebra
import Algebra.Structures
import Function.Equality
import Function.Equivalence
import Function.Bijection
import Level
import Relation.Binary
import Algebra.FunctionProperties
import Relation.Binary.EqReasoning
open Level renaming (zero to ₀)
open Relation.Binary using (Setoid; module Setoid)
open Function.Bijection
module Algebra.Lifting
(S₁ S₂ : Setoid ₀ ₀)
(f : Bijection S₁ S₂) where
open Algebra.FunctionProperties using (Op₂; LeftIdentity)
open Algebra.Structures
open Setoid S₁ using () renaming (Carrier to A₁; _≈_ to _≈₁_; sym to sym₁; refl to refl₁; trans to trans₁)
open Setoid S₂ using (sym; trans) renaming (Carrier to A₂; _≈_ to _≈₂_; isEquivalence to isEquivalence₂)
open Bijection f
open Function.Equality using (_⟨$⟩_; cong)
module WithOp₂
(_+₁_ : Op₂ A₁)
(_+₂_ : Op₂ A₂)
(+-same : ∀ x y → from ⟨$⟩ (x +₂ y) ≈₁ (from ⟨$⟩ x) +₁ (from ⟨$⟩ y)) where
open Relation.Binary.EqReasoning S₁ renaming (begin_ to begin₁_; _∎ to _∎₁; _≈⟨_⟩_ to _≈₁⟨_⟩_)
open Relation.Binary.EqReasoning S₂ renaming (begin_ to begin₂_; _∎ to _∎₂; _≈⟨_⟩_ to _≈₂⟨_⟩_)
open import Function using (_⟨_⟩_)
from-inj : ∀ {x y} → from ⟨$⟩ x ≈₁ from ⟨$⟩ y → x ≈₂ y
from-inj {x} {y} eq = (sym (right-inverse-of x)) ⟨ trans ⟩ cong to eq ⟨ trans ⟩ (right-inverse-of y)
lift-comm : (∀ x y → (x +₁ y) ≈₁ (y +₁ x)) → (∀ x y → (x +₂ y) ≈₂ (y +₂ x))
lift-comm comm₁ x y = from-inj (
begin₁
from ⟨$⟩ x +₂ y
≈₁⟨ +-same x y ⟩
(from ⟨$⟩ x) +₁ (from ⟨$⟩ y)
≈₁⟨ comm₁ (from ⟨$⟩ x) (from ⟨$⟩ y) ⟩
(from ⟨$⟩ y) +₁ (from ⟨$⟩ x)
≈₁⟨ sym₁ (+-same y x) ⟩
from ⟨$⟩ y +₂ x
∎₁
)
using-+-same : ∀ {a b c d}
→ (from ⟨$⟩ a) +₁ (from ⟨$⟩ b) ≈₁ (from ⟨$⟩ c) +₁ (from ⟨$⟩ d)
→ from ⟨$⟩ a +₂ b ≈₁ from ⟨$⟩ c +₂ d
using-+-same {a} {b} {c} {d} eq =
begin₁
from ⟨$⟩ a +₂ b
≈₁⟨ +-same a b ⟩
(from ⟨$⟩ a) +₁ (from ⟨$⟩ b)
≈₁⟨ eq ⟩
(from ⟨$⟩ c) +₁ (from ⟨$⟩ d)
≈₁⟨ sym₁ (+-same c d) ⟩
from ⟨$⟩ c +₂ d
∎₁
lift-comm' : (∀ x y → (x +₁ y) ≈₁ (y +₁ x)) → (∀ x y → (x +₂ y) ≈₂ (y +₂ x))
lift-comm' comm₁ x y = from-inj (using-+-same (comm₁ (from ⟨$⟩ x) (from ⟨$⟩ y)))
lift-assoc : (∀ x y z → (x +₁ y) +₁ z ≈₁ x +₁ (y +₁ z))
→ (∀ {a b c d} → a ≈₁ b → c ≈₁ d → a +₁ c ≈₁ b +₁ d)
→ (∀ x y z → (x +₂ y) +₂ z ≈₂ x +₂ (y +₂ z))
lift-assoc assoc₁ +₁-cong x y z = from-inj (using-+-same (
begin₁
(from ⟨$⟩ x +₂ y) +₁ fz
≈₁⟨ +₁-cong (+-same x y) refl₁ ⟩
(fx +₁ fy) +₁ fz
≈₁⟨ assoc₁ fx fy fz ⟩
fx +₁ (fy +₁ fz)
≈₁⟨ +₁-cong refl₁ (sym₁ (+-same y z)) ⟩
fx +₁ (from ⟨$⟩ y +₂ z)
∎₁)) where
fx = from ⟨$⟩ x
fy = from ⟨$⟩ y
fz = from ⟨$⟩ z
+Cong₁ = (∀ {a b c d} → a ≈₁ b → c ≈₁ d → a +₁ c ≈₁ b +₁ d)
+Cong₂ = (∀ {a b c d} → a ≈₂ b → c ≈₂ d → a +₂ c ≈₂ b +₂ d)
lift-cong : +Cong₁ → +Cong₂
lift-cong cong₁ a≈₂b c≈₂d = from-inj (using-+-same (cong₁ (cong from a≈₂b) (cong from c≈₂d)))
lift-isSemigroup : IsSemigroup _≈₁_ _+₁_ → IsSemigroup _≈₂_ _+₂_
lift-isSemigroup isSemigroup = record
{ isEquivalence = isEquivalence₂
; assoc = lift-assoc assoc ∙-cong
; ∙-cong = lift-cong ∙-cong
} where
open IsSemigroup isSemigroup
lift-LeftIdentity : ∀ ε → +Cong₁ → LeftIdentity _≈₁_ ε _+₁_ → LeftIdentity _≈₂_ (to ⟨$⟩ ε) _+₂_
lift-LeftIdentity ε +-cong₁ identityˡ x = from-inj (
begin₁
from ⟨$⟩ (to ⟨$⟩ ε) +₂ x
≈₁⟨ +-same (to ⟨$⟩ ε) x ⟩
(from ⟨$⟩ (to ⟨$⟩ ε)) +₁ (from ⟨$⟩ x)
≈₁⟨ +-cong₁ (left-inverse-of ε) refl₁ ⟩
ε +₁ (from ⟨$⟩ x)
≈₁⟨ identityˡ (from ⟨$⟩ x) ⟩
from ⟨$⟩ x
∎₁)
lift-isCommutativeMonoid : ∀ ε → IsCommutativeMonoid _≈₁_ _+₁_ ε → IsCommutativeMonoid _≈₂_ _+₂_ (to ⟨$⟩ ε)
lift-isCommutativeMonoid ε isCommMonoid = record
{ isSemigroup = lift-isSemigroup isSemigroup
; identityˡ = lift-LeftIdentity ε ∙-cong identityˡ
; comm = lift-comm comm
} where
open IsCommutativeMonoid isCommMonoid
| {
"alphanum_fraction": 0.5347931873,
"avg_line_length": 34.25,
"ext": "agda",
"hexsha": "1737a72a03d1bf3c817daa3da236b79c87b742c1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "09cc5104421e88da82f9fead5a43f0028f77810d",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "Rotsor/BinDivMod",
"max_forks_repo_path": "Algebra/Lifting.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "09cc5104421e88da82f9fead5a43f0028f77810d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "Rotsor/BinDivMod",
"max_issues_repo_path": "Algebra/Lifting.agda",
"max_line_length": 110,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "09cc5104421e88da82f9fead5a43f0028f77810d",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "Rotsor/BinDivMod",
"max_stars_repo_path": "Algebra/Lifting.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-18T13:58:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-18T13:58:14.000Z",
"num_tokens": 1732,
"size": 4110
} |
{-# OPTIONS --erased-cubical #-}
module Main where
open import Data.List using (map)
open import Data.Unit using (⊤)
open import Midi using (IO; _>>=_; getArgs; putStrLn; exportTracks; track→htrack)
open import FarmCanon using (canonTracks)
open import FarmFugue using (fugueTracks)
-- TODO: Remove
open import Data.List using (List; []; _∷_)
open import Data.String using (String)
open import Function using (_∘_)
open import Midi using (readNat)
open import Pitch using (toPC; showPC)
open import Agda.Builtin.Nat using (zero; suc)
process : List String → String
process [] = ""
process (x ∷ xs) with readNat x
... | zero = ""
... | suc n = (showPC ∘ toPC) n
main : IO ⊤
main = do
args ← getArgs
(putStrLn ∘ process) args
main' : IO ⊤
main' =
let ticksPerBeat = 4 -- (1 = quarter notes; 4 = 16th notes)
file = "/Users/leo/Music/MusicTools/test.mid"
song = fugueTracks
in exportTracks file ticksPerBeat (map track→htrack song)
| {
"alphanum_fraction": 0.6724313327,
"avg_line_length": 26.5675675676,
"ext": "agda",
"hexsha": "ff33faddb84d75c9d00ad43fee0923198d81b68a",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2020-11-10T04:04:40.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-01-12T17:02:36.000Z",
"max_forks_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "halfaya/MusicTools",
"max_forks_repo_path": "agda/Main.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_issues_repo_issues_event_max_datetime": "2020-11-17T00:58:55.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-11-13T01:26:20.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "halfaya/MusicTools",
"max_issues_repo_path": "agda/Main.agda",
"max_line_length": 86,
"max_stars_count": 28,
"max_stars_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "halfaya/MusicTools",
"max_stars_repo_path": "agda/Main.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-04T18:04:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-04-21T09:08:52.000Z",
"num_tokens": 290,
"size": 983
} |
{-# OPTIONS --cubical --no-import-sorts #-}
module MoreLogic.Reasoning where -- hProp logic
open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc)
open import Cubical.Foundations.Logic renaming (inl to inlᵖ; inr to inrᵖ)
open import Cubical.Data.Sigma renaming (_×_ to infixr 4 _×_)
-- "implicational" reaoning
-- infix 3 _◼ᵖ
-- infixr 2 _⇒ᵖ⟨_⟩_
--
-- _⇒ᵖ⟨_⟩_ : ∀{ℓ ℓ' ℓ''} {Q : hProp ℓ'} {R : hProp ℓ''} → (P : hProp ℓ) → [ P ⇒ Q ] → [ Q ⇒ R ] → [ P ⇒ R ]
-- _ ⇒ᵖ⟨ pq ⟩ qr = qr ∘ pq
--
-- _◼ᵖ : ∀{ℓ} (A : hProp ℓ) → [ A ] → [ A ]
-- _ ◼ᵖ = λ x → x
infix 3 _◼
infixr 2 _⇒⟨_⟩_
infix 3 _◼ᵖ
infixr 2 ⇒ᵖ⟨⟩-syntax -- _⇒ᵖ⟨_⟩_
infix 3 _∎ᵖ
infixr 2 ⇔⟨⟩-syntax -- _⇔⟨_⟩_
⇔⟨⟩-syntax : ∀{ℓ ℓ' ℓ''} → (P : hProp ℓ'') → (((Q , R) , _) : Σ[ (Q , R) ∈ hProp ℓ' × hProp ℓ ] [ Q ⇔ R ]) → [ P ⇔ Q ] → Σ[ (P , R) ∈ hProp ℓ'' × hProp ℓ ] [ P ⇔ R ]
⇔⟨⟩-syntax P ((Q , R) , q⇔r) p⇔q .fst = P , R -- x⇔y ∙ y⇔z
⇔⟨⟩-syntax P ((Q , R) , q⇔r) p⇔q .snd .fst = fst q⇔r ∘ fst p⇔q
⇔⟨⟩-syntax P ((Q , R) , q⇔r) p⇔q .snd .snd = snd p⇔q ∘ snd q⇔r
syntax ⇔⟨⟩-syntax P QRq⇔r p⇔q = P ⇔⟨ p⇔q ⟩ QRq⇔r
_∎ᵖ : ∀{ℓ} → (P : hProp ℓ) → Σ[ (Q , R) ∈ hProp ℓ × hProp ℓ ] [ Q ⇔ R ]
_∎ᵖ P .fst = P , P
_∎ᵖ P .snd .fst x = x
_∎ᵖ P .snd .snd x = x
⇒ᵖ⟨⟩-syntax : ∀{ℓ ℓ' ℓ''} → (P : hProp ℓ'') → (((Q , R) , _) : Σ[ (Q , R) ∈ hProp ℓ' × hProp ℓ ] [ Q ⇒ R ]) → [ P ⇒ Q ] → Σ[ (P , R) ∈ hProp ℓ'' × hProp ℓ ] [ P ⇒ R ]
⇒ᵖ⟨⟩-syntax P ((Q , R) , q⇔r) p⇔q .fst = P , R -- x⇔y ∙ y⇔z
⇒ᵖ⟨⟩-syntax P ((Q , R) , q⇒r) p⇒q .snd = q⇒r ∘ p⇒q
_◼ᵖ : ∀{ℓ} → (P : hProp ℓ) → Σ[ (Q , R) ∈ hProp ℓ × hProp ℓ ] [ Q ⇒ R ]
_◼ᵖ P .fst = P , P
_◼ᵖ P .snd x = x
syntax ⇒ᵖ⟨⟩-syntax P QRq⇒r p⇒q = P ⇒ᵖ⟨ p⇒q ⟩ QRq⇒r
_⇒⟨_⟩_ : ∀{ℓ ℓ' ℓ''} {Q : Type ℓ'} {R : Type ℓ''} → (P : Type ℓ) → (P → Q) → (Q → R) → (P → R)
_ ⇒⟨ p⇒q ⟩ q⇒r = q⇒r ∘ p⇒q
_◼ : ∀{ℓ} (A : Type ℓ) → A → A
_ ◼ = λ x → x
-- ⊎⇒⊔ : ∀ {ℓ ℓ'} (P : hProp ℓ) (Q : hProp ℓ') → [ P ] ⊎ [ Q ] → [ P ⊔ Q ]
-- ⊎⇒⊔ P Q (inl x) = inlᵖ x
-- ⊎⇒⊔ P Q (inr x) = inrᵖ x
--
-- case[_⊔_]_return_of_ : ∀ {ℓ ℓ'} (P : hProp ℓ) (Q : hProp ℓ')
-- → (z : [ P ⊔ Q ])
-- → (R : [ P ⊔ Q ] → hProp ℓ'')
-- → (S : (x : [ P ] ⊎ [ Q ]) → [ R (⊎⇒⊔ P Q x) ] )
-- → [ R z ]
-- case[_⊔_]_return_of_ P Q z R S = ⊔-elim P Q R (λ p → S (inl p)) (λ q → S (inr q)) z
{- NOTE: in the CHANGELOG.md of the v1.3 non-cubical standard library, it is explained:
* Previously all equational reasoning combinators (e.g. `_≈⟨_⟩_`, `_≡⟨_⟩_`, `_≤⟨_⟩_`)
were defined in the following style:
```agda
infixr 2 _≡⟨_⟩_
_≡⟨_⟩_ : ∀ x {y z : A} → x ≡ y → y ≡ z → x ≡ z
_ ≡⟨ x≡y ⟩ y≡z = trans x≡y y≡z
```
The type checker therefore infers the RHS of the equational step from the LHS + the
type of the proof. For example for `x ≈⟨ x≈y ⟩ y ∎` it is inferred that `y ∎`
must have type `y IsRelatedTo y` from `x : A` and `x≈y : x ≈ y`.
* There are two problems with this. Firstly, it means that the reasoning combinators are
not compatible with macros (i.e. tactics) that attempt to automatically generate proofs
for `x≈y`. This is because the reflection machinary does not have access to the type of RHS
as it cannot be inferred. In practice this meant that the new reflective solvers
`Tactic.RingSolver` and `Tactic.MonoidSolver` could not be used inside the equational
reasoning. Secondly the inference procedure itself is slower as described in this
[exchange](https://lists.chalmers.se/pipermail/agda/2016/009090.html)
on the Agda mailing list.
* Therefore, as suggested on the mailing list, the order of arguments to the combinators
have been reversed so that instead the type of the proof is inferred from the LHS + RHS.
```agda
infixr -2 step-≡
step-≡ : ∀ x {y z : A} → y ≡ z → x ≡ y → x ≡ z
step-≡ y≡z x≡y = trans x≡y y≡z
syntax step-≡ x y≡z x≡y = x ≡⟨ x≡y ⟩ y≡z
```
where the `syntax` declaration is then used to recover the original order of the arguments.
This change enables the use of macros and anecdotally speeds up type checking by a
factor of 5.
-} -- TODO: that might be "correct" the way to implement these reasoning operators
| {
"alphanum_fraction": 0.5408335341,
"avg_line_length": 38.7943925234,
"ext": "agda",
"hexsha": "0375270be769013c641492cb27474c5ee3189a69",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mchristianl/synthetic-reals",
"max_forks_repo_path": "agda/MoreLogic/Reasoning.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mchristianl/synthetic-reals",
"max_issues_repo_path": "agda/MoreLogic/Reasoning.agda",
"max_line_length": 166,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mchristianl/synthetic-reals",
"max_stars_repo_path": "agda/MoreLogic/Reasoning.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-19T12:15:21.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-31T18:15:26.000Z",
"num_tokens": 2020,
"size": 4151
} |
-- Mixing CatchAll branches with varying arity can be tricky.
--
-- If the number of arguments a catch all branch expects to be already abstracted over is smaller
-- than the number of arguments present in the failing clause/branch, we need to apply
-- the catch-all branch to the surplus arguments already abstracted over.
module CatchAllVarArity where
open import Common.Nat
open import Common.IO
open import Common.Unit
f : Nat → Nat → Nat
f zero = λ y → y
f (suc zero) (suc y) = suc y
f x y = (suc y)
case_of_ : ∀{A B : Set} → A → (A → B) → B
case a of f = f a
-- case tree variant of f
g : Nat → Nat → Nat
g = λ x →
case x of
λ{ zero → λ y → y
; (suc x') →
case x' of
λ{ zero → λ y →
case y of
λ{ (suc y') → suc y'
; _ → fallback (suc x') y
}
; _ → λ y → fallback x y
}
}
where
fallback = λ x y → suc y
--expected:
-- 10
-- 21
-- 1
-- 0
-- 4
-- 1
main = printNat (f 0 10) ,,
putStrLn "" ,,
printNat (f 10 20) ,,
putStrLn "" ,,
printNat (f 10 0) ,,
putStrLn "" ,,
printNat (f 0 0) ,,
putStrLn "" ,,
printNat (f 1 4) ,,
putStrLn "" ,,
printNat (f 1 0) ,,
putStrLn ""
| {
"alphanum_fraction": 0.5464169381,
"avg_line_length": 20.813559322,
"ext": "agda",
"hexsha": "96b974ec48754afa2f17850d30986371234b2025",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Compiler/simple/CatchAllVarArity.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Compiler/simple/CatchAllVarArity.agda",
"max_line_length": 97,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Compiler/simple/CatchAllVarArity.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 410,
"size": 1228
} |
module NF.Nat where
open import NF
open import Relation.Binary.PropositionalEquality
open import Data.Nat
instance
nf0 : NF 0
Sing.unpack (NF.!! nf0) = 0
Sing.eq (NF.!! nf0) = refl
{-# INLINE nf0 #-}
nfSuc : {n : ℕ}{{nfn : NF n}} -> NF (suc n)
Sing.unpack (NF.!! (nfSuc {n})) = suc (nf n)
Sing.eq (NF.!! (nfSuc {{nfn}})) = cong suc nf≡
{-# INLINE nfSuc #-} | {
"alphanum_fraction": 0.5915119363,
"avg_line_length": 20.9444444444,
"ext": "agda",
"hexsha": "feaabaa6ea55c7f94d134a7ca26199248febf21b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "4f037dad109a5d080023557f0869418ed9fc11c1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "yanok/normalize-via-instances",
"max_forks_repo_path": "src/NF/Nat.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4f037dad109a5d080023557f0869418ed9fc11c1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "yanok/normalize-via-instances",
"max_issues_repo_path": "src/NF/Nat.agda",
"max_line_length": 49,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "4f037dad109a5d080023557f0869418ed9fc11c1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yanok/normalize-via-instances",
"max_stars_repo_path": "src/NF/Nat.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 141,
"size": 377
} |
module STLC.Coquand.Renaming where
open import STLC.Syntax public
open import Category
--------------------------------------------------------------------------------
-- Renamings
infix 4 _∋⋆_
data _∋⋆_ : 𝒞 → 𝒞 → Set
where
∅ : ∀ {Γ} → Γ ∋⋆ ∅
_,_ : ∀ {Γ Γ′ A} → (η : Γ′ ∋⋆ Γ) (i : Γ′ ∋ A)
→ Γ′ ∋⋆ Γ , A
putᵣ : ∀ {Γ Γ′} → (∀ {A} → Γ ∋ A → Γ′ ∋ A) → Γ′ ∋⋆ Γ
putᵣ {∅} f = ∅
putᵣ {Γ , A} f = putᵣ (λ i → f (suc i)) , f 0
getᵣ : ∀ {Γ Γ′ A} → Γ′ ∋⋆ Γ → Γ ∋ A → Γ′ ∋ A
getᵣ (η , i) zero = i
getᵣ (η , i) (suc j) = getᵣ η j
wkᵣ : ∀ {A Γ Γ′} → Γ′ ∋⋆ Γ → Γ′ , A ∋⋆ Γ
wkᵣ ∅ = ∅
wkᵣ (η , i) = wkᵣ η , suc i
liftᵣ : ∀ {A Γ Γ′} → Γ′ ∋⋆ Γ → Γ′ , A ∋⋆ Γ , A
liftᵣ η = wkᵣ η , 0
idᵣ : ∀ {Γ} → Γ ∋⋆ Γ
idᵣ {∅} = ∅
idᵣ {Γ , A} = liftᵣ idᵣ
ren : ∀ {Γ Γ′ A} → Γ′ ∋⋆ Γ → Γ ⊢ A → Γ′ ⊢ A
ren η (𝓋 i) = 𝓋 (getᵣ η i)
ren η (ƛ M) = ƛ (ren (liftᵣ η) M)
ren η (M ∙ N) = ren η M ∙ ren η N
wk : ∀ {B Γ A} → Γ ⊢ A → Γ , B ⊢ A
wk M = ren (wkᵣ idᵣ) M
-- NOTE: _○_ = getᵣ⋆
_○_ : ∀ {Γ Γ′ Γ″} → Γ″ ∋⋆ Γ′ → Γ′ ∋⋆ Γ → Γ″ ∋⋆ Γ
η₁ ○ ∅ = ∅
η₁ ○ (η₂ , i) = η₁ ○ η₂ , getᵣ η₁ i
--------------------------------------------------------------------------------
-- (wkgetᵣ)
natgetᵣ : ∀ {Γ Γ′ A B} → (η : Γ′ ∋⋆ Γ) (i : Γ ∋ A)
→ getᵣ (wkᵣ {B} η) i ≡ (suc ∘ getᵣ η) i
natgetᵣ (η , j) zero = refl
natgetᵣ (η , j) (suc i) = natgetᵣ η i
idgetᵣ : ∀ {Γ A} → (i : Γ ∋ A)
→ getᵣ idᵣ i ≡ i
idgetᵣ zero = refl
idgetᵣ (suc i) = natgetᵣ idᵣ i
⦙ suc & idgetᵣ i
idren : ∀ {Γ A} → (M : Γ ⊢ A)
→ ren idᵣ M ≡ M
idren (𝓋 i) = 𝓋 & idgetᵣ i
idren (ƛ M) = ƛ & idren M
idren (M ∙ N) = _∙_ & idren M
⊗ idren N
--------------------------------------------------------------------------------
zap○ : ∀ {Γ Γ′ Γ″ A} → (η₁ : Γ″ ∋⋆ Γ′) (η₂ : Γ′ ∋⋆ Γ) (i : Γ″ ∋ A)
→ (η₁ , i) ○ wkᵣ η₂ ≡ η₁ ○ η₂
zap○ η₁ ∅ i = refl
zap○ η₁ (η₂ , j) i = (_, getᵣ η₁ j) & zap○ η₁ η₂ i
lid○ : ∀ {Γ Γ′} → (η : Γ′ ∋⋆ Γ)
→ idᵣ ○ η ≡ η
lid○ ∅ = refl
lid○ (η , i) = _,_ & lid○ η
⊗ idgetᵣ i
rid○ : ∀ {Γ Γ′} → (η : Γ′ ∋⋆ Γ)
→ η ○ idᵣ ≡ η
rid○ {∅} ∅ = refl
rid○ {Γ , A} (η , i) = (_, i) & ( zap○ η idᵣ i
⦙ rid○ η
)
--------------------------------------------------------------------------------
get○ : ∀ {Γ Γ′ Γ″ A} → (η₁ : Γ″ ∋⋆ Γ′) (η₂ : Γ′ ∋⋆ Γ) (i : Γ ∋ A)
→ getᵣ (η₁ ○ η₂) i ≡ (getᵣ η₁ ∘ getᵣ η₂) i
get○ η₁ (η₂ , j) zero = refl
get○ η₁ (η₂ , j) (suc i) = get○ η₁ η₂ i
wk○ : ∀ {Γ Γ′ Γ″ A} → (η₁ : Γ″ ∋⋆ Γ′) (η₂ : Γ′ ∋⋆ Γ)
→ wkᵣ {A} (η₁ ○ η₂) ≡ wkᵣ η₁ ○ η₂
wk○ η₁ ∅ = refl
wk○ η₁ (η₂ , i) = _,_ & wk○ η₁ η₂
⊗ (natgetᵣ η₁ i ⁻¹)
lift○ : ∀ {Γ Γ′ Γ″ A} → (η₁ : Γ″ ∋⋆ Γ′) (η₂ : Γ′ ∋⋆ Γ)
→ liftᵣ {A} (η₁ ○ η₂) ≡ liftᵣ η₁ ○ liftᵣ η₂
lift○ η₁ η₂ = (_, 0) & ( wk○ η₁ η₂
⦙ (zap○ (wkᵣ η₁) η₂ 0 ⁻¹)
)
wklid○ : ∀ {Γ Γ′ A} → (η : Γ′ ∋⋆ Γ)
→ wkᵣ {A} idᵣ ○ η ≡ wkᵣ η
wklid○ η = wk○ idᵣ η ⁻¹
⦙ wkᵣ & lid○ η
wkrid○ : ∀ {Γ Γ′ A} → (η : Γ′ ∋⋆ Γ)
→ wkᵣ {A} η ○ idᵣ ≡ wkᵣ η
wkrid○ η = wk○ η idᵣ ⁻¹
⦙ wkᵣ & rid○ η
liftwkrid○ : ∀ {Γ Γ′ A} → (η : Γ′ ∋⋆ Γ)
→ liftᵣ {A} η ○ wkᵣ idᵣ ≡ wkᵣ η
liftwkrid○ η = zap○ (wkᵣ η) idᵣ 0 ⦙ wkrid○ η
mutual
ren○ : ∀ {Γ Γ′ Γ″ A} → (η₁ : Γ″ ∋⋆ Γ′) (η₂ : Γ′ ∋⋆ Γ) (M : Γ ⊢ A)
→ ren (η₁ ○ η₂) M ≡ (ren η₁ ∘ ren η₂) M
ren○ η₁ η₂ (𝓋 i) = 𝓋 & get○ η₁ η₂ i
ren○ η₁ η₂ (ƛ M) = ƛ & renlift○ η₁ η₂ M
ren○ η₁ η₂ (M ∙ N) = _∙_ & ren○ η₁ η₂ M
⊗ ren○ η₁ η₂ N
renlift○ : ∀ {Γ Γ′ Γ″ A B} → (η₁ : Γ″ ∋⋆ Γ′) (η₂ : Γ′ ∋⋆ Γ) (M : Γ , B ⊢ A)
→ ren (liftᵣ {B} (η₁ ○ η₂)) M ≡
(ren (liftᵣ η₁) ∘ ren (liftᵣ η₂)) M
renlift○ η₁ η₂ M = (λ η′ → ren η′ M) & lift○ η₁ η₂
⦙ ren○ (liftᵣ η₁) (liftᵣ η₂) M
renwk○ : ∀ {Γ Γ′ Γ″ A B} → (η₁ : Γ″ ∋⋆ Γ′) (η₂ : Γ′ ∋⋆ Γ) (M : Γ ⊢ A)
→ ren (wkᵣ {B} (η₁ ○ η₂)) M ≡
(ren (wkᵣ η₁) ∘ ren η₂) M
renwk○ η₁ η₂ M = (λ η′ → ren η′ M) & wk○ η₁ η₂
⦙ ren○ (wkᵣ η₁) η₂ M
renliftwk○ : ∀ {Γ Γ′ Γ″ A B} → (η₁ : Γ″ ∋⋆ Γ′) (η₂ : Γ′ ∋⋆ Γ) (M : Γ ⊢ A)
→ ren (wkᵣ {B} (η₁ ○ η₂)) M ≡
(ren (liftᵣ η₁) ∘ ren (wkᵣ η₂)) M
renliftwk○ η₁ η₂ M = (λ η′ → ren η′ M) & ( wk○ η₁ η₂
⦙ zap○ (wkᵣ η₁) η₂ 0 ⁻¹
)
⦙ ren○ (liftᵣ η₁) (wkᵣ η₂) M
--------------------------------------------------------------------------------
assoc○ : ∀ {Γ Γ′ Γ″ Γ‴} → (η₁ : Γ‴ ∋⋆ Γ″) (η₂ : Γ″ ∋⋆ Γ′) (η₃ : Γ′ ∋⋆ Γ)
→ η₁ ○ (η₂ ○ η₃) ≡ (η₁ ○ η₂) ○ η₃
assoc○ η₁ η₂ ∅ = refl
assoc○ η₁ η₂ (η₃ , i) = _,_ & assoc○ η₁ η₂ η₃
⊗ (get○ η₁ η₂ i ⁻¹)
--------------------------------------------------------------------------------
𝗥𝗲𝗻 : Category 𝒞 _∋⋆_
𝗥𝗲𝗻 =
record
{ idₓ = idᵣ
; _⋄_ = flip _○_
; lid⋄ = rid○
; rid⋄ = lid○
; assoc⋄ = assoc○
}
getᵣPsh : 𝒯 → Presheaf₀ 𝗥𝗲𝗻
getᵣPsh A =
record
{ Fₓ = _∋ A
; F = getᵣ
; idF = fext! idgetᵣ
; F⋄ = λ η₂ η₁ → fext! (get○ η₁ η₂)
}
renPsh : 𝒯 → Presheaf₀ 𝗥𝗲𝗻
renPsh A =
record
{ Fₓ = _⊢ A
; F = ren
; idF = fext! idren
; F⋄ = λ η₂ η₁ → fext! (ren○ η₁ η₂)
}
--------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.3119234117,
"avg_line_length": 28.0243902439,
"ext": "agda",
"hexsha": "f1fee43643be542b57497a681498654195bb1e0a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "bd626509948fbf8503ec2e31c1852e1ac6edcc79",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/coquand-kovacs",
"max_forks_repo_path": "src/STLC/Coquand/Renaming.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bd626509948fbf8503ec2e31c1852e1ac6edcc79",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/coquand-kovacs",
"max_issues_repo_path": "src/STLC/Coquand/Renaming.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bd626509948fbf8503ec2e31c1852e1ac6edcc79",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/coquand-kovacs",
"max_stars_repo_path": "src/STLC/Coquand/Renaming.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3122,
"size": 5745
} |
------------------------------------------------------------------------
-- An investigation of nested fixpoints of the form μX.νY.… in Agda
------------------------------------------------------------------------
module MuNu where
open import Codata.Musical.Notation
import Codata.Musical.Colist as Colist
open import Codata.Musical.Stream
open import Data.Digit
open import Data.Empty
open import Data.List using (List; _∷_; [])
open import Data.Product
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary using (¬_)
-- Christophe Raffalli discusses (essentially) the type μO. νZ. Z + O
-- in his thesis. If Z is read as zero and O as one, then this type
-- contains bit sequences of the form (0^⋆1)^⋆0^ω.
-- It is interesting to note that currently it is not possible to
-- encode this type directly in Agda. One might believe that the
-- following definition should work. First we define the inner
-- greatest fixpoint:
data Z (O : Set) : Set where
[0] : ∞ (Z O) → Z O
[1] : O → Z O
-- Then we define the outer least fixpoint:
data O : Set where
↓ : Z O → O
-- However, it is still possible to define values of the form (01)^ω:
01^ω : O
01^ω = ↓ ([0] (♯ [1] 01^ω))
-- The reason is the way the termination/productivity checker works:
-- it accepts definitions by guarded corecursion as long as the guard
-- contains at least one occurrence of ♯_, no matter how the types
-- involved are defined. In effect ∞ has global reach. The mistake
-- done above was believing that O is defined to be a least fixpoint.
-- The type O really corresponds to νZ. μO. Z + O, i.e. (1^⋆0)^ω:
data O′ : Set where
[0] : ∞ O′ → O′
[1] : O′ → O′
mutual
O→O′ : O → O′
O→O′ (↓ z) = ZO→O′ z
ZO→O′ : Z O → O′
ZO→O′ ([0] z) = [0] (♯ ZO→O′ (♭ z))
ZO→O′ ([1] o) = [1] (O→O′ o)
mutual
O′→O : O′ → O
O′→O o = ↓ (O′→ZO o)
O′→ZO : O′ → Z O
O′→ZO ([0] o) = [0] (♯ O′→ZO (♭ o))
O′→ZO ([1] o) = [1] (O′→O o)
-- If O had actually encoded the type μO. νZ. Z + O, then we could
-- have proved the following theorem:
mutual
⟦_⟧O : O → Stream Bit
⟦ ↓ z ⟧O = ⟦ z ⟧Z
⟦_⟧Z : Z O → Stream Bit
⟦ [0] z ⟧Z = 0b ∷ ♯ ⟦ ♭ z ⟧Z
⟦ [1] o ⟧Z = 1b ∷ ♯ ⟦ o ⟧O
Theorem : Set
Theorem = ∀ o → ¬ (head ⟦ o ⟧O ≡ 0b × head (tail ⟦ o ⟧O) ≡ 1b ×
tail (tail ⟦ o ⟧O) ≈ ⟦ o ⟧O)
-- This would have been unfortunate, though:
inconsistency : Theorem → ⊥
inconsistency theorem = theorem 01^ω (refl , refl , proof)
where
proof : tail (tail ⟦ 01^ω ⟧O) ≈ ⟦ 01^ω ⟧O
proof = refl ∷ ♯ (refl ∷ ♯ proof)
-- Using the following elimination principle we can prove the theorem:
data ⇑ {O} (P : O → Set) : Z O → Set where
[0] : ∀ {z} → ∞ (⇑ P (♭ z)) → ⇑ P ([0] z)
[1] : ∀ {o} → P o → ⇑ P ([1] o)
O-Elim : Set₁
O-Elim = (P : O → Set) → (∀ {z} → ⇑ P z → P (↓ z)) → (o : O) → P o
theorem : O-Elim → Theorem
theorem O-elim = O-elim P helper
where
P : O → Set
P o = ¬ (head ⟦ o ⟧O ≡ 0b × head (tail ⟦ o ⟧O) ≡ 1b ×
tail (tail ⟦ o ⟧O) ≈ ⟦ o ⟧O)
helper : ∀ {z} → ⇑ P z → P (↓ z)
helper ([1] p) (() , eq₂ , eq₃)
helper ([0] p) (refl , eq₂ , eq₃) =
hlp _ eq₂ (head-cong eq₃) (tail-cong eq₃) (♭ p)
where
hlp : ∀ z → head ⟦ z ⟧Z ≡ 1b →
head (tail ⟦ z ⟧Z) ≡ 0b →
tail (tail ⟦ z ⟧Z) ≈ ⟦ z ⟧Z →
⇑ P z → ⊥
hlp .([0] _) () eq₂ eq₃ ([0] p)
hlp .([1] _) eq₁ eq₂ eq₃ ([1] p) =
p (eq₂ , head-cong eq₃ , tail-cong eq₃)
-- Fortunately it appears as if we cannot prove this elimination
-- principle. The following code is not accepted by the termination
-- checker:
{-
mutual
O-elim : O-Elim
O-elim P hyp (↓ z) = hyp (Z-elim P hyp z)
Z-elim : (P : O → Set) →
(∀ {z} → ⇑ P z → P (↓ z)) →
(z : Z O) → ⇑ P z
Z-elim P hyp ([0] z) = [0] (♯ Z-elim P hyp (♭ z))
Z-elim P hyp ([1] o) = [1] (O-elim P hyp o)
-}
-- If hyp were known to be contractive, then the code above would be
-- correct (if not accepted by the termination checker). This is not
-- the case in theorem above.
| {
"alphanum_fraction": 0.5370687546,
"avg_line_length": 28.7816901408,
"ext": "agda",
"hexsha": "d043833bfd028add2f70e28671d8cf0b0f69aa85",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/codata",
"max_forks_repo_path": "MuNu.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/codata",
"max_issues_repo_path": "MuNu.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/codata",
"max_stars_repo_path": "MuNu.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z",
"num_tokens": 1562,
"size": 4087
} |
open import Preliminaries
module Preorder where
record PreorderStructure (A : Set) : Set1 where
constructor preorder-structure
field
_≤_ : A → A → Set
refl : ∀ x → x ≤ x
trans : ∀ x y z → x ≤ y → y ≤ z → x ≤ z
record Preorder A : Set1 where
constructor preorder
field
preorder-struct : PreorderStructure A
| {
"alphanum_fraction": 0.6203966006,
"avg_line_length": 22.0625,
"ext": "agda",
"hexsha": "8d4505a97a9e18f3cdf1690337ae0a9e046969ac",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "benhuds/Agda",
"max_forks_repo_path": "complexity-drafts/Preorder.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e",
"max_issues_repo_issues_event_max_datetime": "2020-05-12T00:32:45.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-03-23T08:39:04.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "benhuds/Agda",
"max_issues_repo_path": "complexity-drafts/Preorder.agda",
"max_line_length": 49,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "benhuds/Agda",
"max_stars_repo_path": "complexity-drafts/Preorder.agda",
"max_stars_repo_stars_event_max_datetime": "2019-08-08T12:27:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-04-26T20:22:22.000Z",
"num_tokens": 104,
"size": 353
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
open import Categories.Functor hiding (id)
module Categories.Diagram.Colimit.DualProperties
{o ℓ e} {o′ ℓ′ e′} {C : Category o ℓ e} {J : Category o′ ℓ′ e′} where
open import Function.Equality renaming (id to idFun)
open import Categories.Category.Instance.Setoids
open import Categories.Diagram.Duality C
open import Categories.Functor.Hom
open import Categories.Category.Construction.Cocones as Coc
open import Categories.Diagram.Limit as Lim
open import Categories.Diagram.Limit.Properties
open import Categories.Diagram.Colimit as Col
open import Categories.NaturalTransformation
open import Categories.NaturalTransformation.NaturalIsomorphism
open import Categories.Morphism C
open import Categories.Morphism.Duality C
private
module C = Category C
module J = Category J
open C
open Hom C
open HomReasoning
-- contravariant hom functor sends colimit of F to its limit.
module _ (W : Obj) {F : Functor J C} (col : Colimit F) where
private
module F = Functor F
HomF : Functor J.op (Setoids ℓ e)
HomF = Hom[-, W ] ∘F F.op
hom-colimit⇒limit : Limit HomF
hom-colimit⇒limit = ≃-resp-lim (Hom≃ ⓘʳ F.op) (hom-resp-limit W (Colimit⇒coLimit col))
where Hom≃ : Hom[ op ][ W ,-] ≃ Hom[-, W ]
Hom≃ = record
{ F⇒G = ntHelper record
{ η = λ _ → idFun
; commute = λ _ eq → C.∘-resp-≈ˡ (C.∘-resp-≈ʳ eq) ○ C.assoc
}
; F⇐G = ntHelper record
{ η = λ _ → idFun
; commute = λ _ eq → C.sym-assoc ○ C.∘-resp-≈ˡ (C.∘-resp-≈ʳ eq)
}
; iso = λ _ → record
{ isoˡ = λ eq → eq
; isoʳ = λ eq → eq
}
}
-- natural isomorphisms respects limits
module _ {F G : Functor J C} (F≃G : F ≃ G) where
private
module F = Functor F
module G = Functor G
open NaturalIsomorphism F≃G
≃-resp-colim : Colimit F → Colimit G
≃-resp-colim Cf = coLimit⇒Colimit (≃-resp-lim op′ (Colimit⇒coLimit Cf))
≃⇒Cocone⇒ : ∀ (Cf : Colimit F) (Cg : Colimit G) → Cocones G [ Colimit.colimit Cg , Colimit.colimit (≃-resp-colim Cf) ]
≃⇒Cocone⇒ Cf Cg = coCone⇒⇒Cocone⇒ (≃⇒Cone⇒ op′ (Colimit⇒coLimit Cf) (Colimit⇒coLimit Cg))
≃⇒colim≅ : ∀ {F G : Functor J C} (F≃G : F ≃ G) (Cf : Colimit F) (Cg : Colimit G) → Colimit.coapex Cf ≅ Colimit.coapex Cg
≃⇒colim≅ F≃G Cf Cg = op-≅⇒≅ (≃⇒lim≅ (NaturalIsomorphism.op′ F≃G) (Colimit⇒coLimit Cf) (Colimit⇒coLimit Cg))
| {
"alphanum_fraction": 0.6245059289,
"avg_line_length": 35.6338028169,
"ext": "agda",
"hexsha": "0c1c9c3e0ada5985ad812c8812a44e24a8b09969",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MirceaS/agda-categories",
"max_forks_repo_path": "src/Categories/Diagram/Colimit/DualProperties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "MirceaS/agda-categories",
"max_issues_repo_path": "src/Categories/Diagram/Colimit/DualProperties.agda",
"max_line_length": 120,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MirceaS/agda-categories",
"max_stars_repo_path": "src/Categories/Diagram/Colimit/DualProperties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 903,
"size": 2530
} |
{-# OPTIONS --without-K --safe #-}
module Cats.Category.Setoids.Facts.Initial where
open import Level
open import Relation.Binary using (Setoid)
open import Cats.Category
open import Cats.Category.Setoids using (Setoids ; ≈-intro)
import Data.Empty as Empty
⊥ : ∀ {l l′} → Setoid l l′
⊥ = record
{ Carrier = Lift _ Empty.⊥
; _≈_ = λ()
; isEquivalence = record
{ refl = λ{}
; sym = λ{}
; trans = λ{}
}
}
instance
hasInitial : ∀ {l l≈} → HasInitial (Setoids l l≈)
hasInitial = record
{ ⊥ = ⊥
; isInitial = λ X → record
{ arr = record { arr = λ() ; resp = λ{} }
; unique = λ _ → ≈-intro λ{}
}
}
| {
"alphanum_fraction": 0.5639097744,
"avg_line_length": 19.5588235294,
"ext": "agda",
"hexsha": "dd568c0af59362e81ff26ddc9643e2c7ca558c9c",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-18T15:35:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-18T15:35:07.000Z",
"max_forks_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JLimperg/cats",
"max_forks_repo_path": "Cats/Category/Setoids/Facts/Initial.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JLimperg/cats",
"max_issues_repo_path": "Cats/Category/Setoids/Facts/Initial.agda",
"max_line_length": 59,
"max_stars_count": 24,
"max_stars_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JLimperg/cats",
"max_stars_repo_path": "Cats/Category/Setoids/Facts/Initial.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-06T05:00:46.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-03T15:18:57.000Z",
"num_tokens": 213,
"size": 665
} |
open import Oscar.Prelude
open import Oscar.Class
open import Oscar.Class.Reflexivity
open import Oscar.Class.Symmetry
open import Oscar.Class.Transitivity
open import Oscar.Class.IsEquivalence
open import Oscar.Class.Setoid
open import Oscar.Data.Proposequality
module Oscar.Property.Setoid.Proposextensequality where
module _ {𝔬} {𝔒 : Ø 𝔬} {𝔭} {𝔓 : 𝔒 → Ø 𝔭} where
instance
𝓡eflexivityProposextensequality : Reflexivity.class Proposextensequality⟦ 𝔓 ⟧
𝓡eflexivityProposextensequality .⋆ _ = ∅
𝓢ymmetryProposextensequality : Symmetry.class Proposextensequality⟦ 𝔓 ⟧
𝓢ymmetryProposextensequality .⋆ f₁≡̇f₂ x rewrite f₁≡̇f₂ x = ∅
𝓣ransitivityProposextensequality : Transitivity.class Proposextensequality⟦ 𝔓 ⟧
𝓣ransitivityProposextensequality .⋆ f₁≡̇f₂ f₂≡̇f₃ x rewrite f₁≡̇f₂ x = f₂≡̇f₃ x
IsEquivalenceProposextensequality : IsEquivalence Proposextensequality⟦ 𝔓 ⟧
IsEquivalenceProposextensequality = ∁
module _ {𝔬} {𝔒 : Ø 𝔬} {𝔭} (𝔓 : 𝔒 → Ø 𝔭) where
SetoidProposextensequality : Setoid _ _
SetoidProposextensequality = ∁ Proposextensequality⟦ 𝔓 ⟧
| {
"alphanum_fraction": 0.768738574,
"avg_line_length": 33.1515151515,
"ext": "agda",
"hexsha": "2da1360f77a3eaf980abd87f43b2c65370d26cbb",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-3/src/Oscar/Property/Setoid/Proposextensequality.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-3/src/Oscar/Property/Setoid/Proposextensequality.agda",
"max_line_length": 83,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-3/src/Oscar/Property/Setoid/Proposextensequality.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 424,
"size": 1094
} |
{-# OPTIONS --allow-unsolved-metas #-}
latex : Set
latex = {!test!}
| {
"alphanum_fraction": 0.6086956522,
"avg_line_length": 13.8,
"ext": "agda",
"hexsha": "0f8a539f7b4f91e65ef48018707a891fbd50bbfe",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/LaTeXAndHTML/succeed/Issue5043.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/LaTeXAndHTML/succeed/Issue5043.agda",
"max_line_length": 38,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/LaTeXAndHTML/succeed/Issue5043.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 20,
"size": 69
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some algebraic structures defined over some other structure
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary using (Rel; Setoid; IsEquivalence)
module Algebra.Module.Structures where
open import Algebra.Bundles
open import Algebra.Core
import Algebra.Definitions as Defs
open import Algebra.Module.Definitions
open import Algebra.Structures
open import Data.Product using (_,_; proj₁; proj₂)
open import Level using (Level; _⊔_)
private
variable
m ℓm r ℓr s ℓs : Level
M : Set m
module _ (semiring : Semiring r ℓr) (≈ᴹ : Rel {m} M ℓm) (+ᴹ : Op₂ M) (0ᴹ : M)
where
open Semiring semiring renaming (Carrier to R)
record IsPreleftSemimodule (*ₗ : Opₗ R M) : Set (r ⊔ m ⊔ ℓr ⊔ ℓm) where
open LeftDefs R ≈ᴹ
field
*ₗ-cong : Congruent _≈_ *ₗ
*ₗ-zeroˡ : LeftZero 0# 0ᴹ *ₗ
*ₗ-distribʳ : *ₗ DistributesOverʳ _+_ ⟶ +ᴹ
*ₗ-identityˡ : LeftIdentity 1# *ₗ
*ₗ-assoc : Associative _*_ *ₗ
*ₗ-zeroʳ : RightZero 0ᴹ *ₗ
*ₗ-distribˡ : *ₗ DistributesOverˡ +ᴹ
record IsLeftSemimodule (*ₗ : Opₗ R M) : Set (r ⊔ m ⊔ ℓr ⊔ ℓm) where
open LeftDefs R ≈ᴹ
field
+ᴹ-isCommutativeMonoid : IsCommutativeMonoid ≈ᴹ +ᴹ 0ᴹ
isPreleftSemimodule : IsPreleftSemimodule *ₗ
open IsPreleftSemimodule isPreleftSemimodule public
open IsCommutativeMonoid +ᴹ-isCommutativeMonoid public
using () renaming
( assoc to +ᴹ-assoc
; comm to +ᴹ-comm
; identity to +ᴹ-identity
; identityʳ to +ᴹ-identityʳ
; identityˡ to +ᴹ-identityˡ
; isEquivalence to ≈ᴹ-isEquivalence
; isMagma to +ᴹ-isMagma
; isMonoid to +ᴹ-isMonoid
; isPartialEquivalence to ≈ᴹ-isPartialEquivalence
; isSemigroup to +ᴹ-isSemigroup
; refl to ≈ᴹ-refl
; reflexive to ≈ᴹ-reflexive
; setoid to ≈ᴹ-setoid
; sym to ≈ᴹ-sym
; trans to ≈ᴹ-trans
; ∙-cong to +ᴹ-cong
; ∙-congʳ to +ᴹ-congʳ
; ∙-congˡ to +ᴹ-congˡ
)
*ₗ-congˡ : LeftCongruent *ₗ
*ₗ-congˡ mm = *ₗ-cong refl mm
*ₗ-congʳ : RightCongruent _≈_ *ₗ
*ₗ-congʳ xx = *ₗ-cong xx ≈ᴹ-refl
record IsPrerightSemimodule (*ᵣ : Opᵣ R M) : Set (r ⊔ m ⊔ ℓr ⊔ ℓm) where
open RightDefs R ≈ᴹ
field
*ᵣ-cong : Congruent _≈_ *ᵣ
*ᵣ-zeroʳ : RightZero 0# 0ᴹ *ᵣ
*ᵣ-distribˡ : *ᵣ DistributesOverˡ _+_ ⟶ +ᴹ
*ᵣ-identityʳ : RightIdentity 1# *ᵣ
*ᵣ-assoc : Associative _*_ *ᵣ
*ᵣ-zeroˡ : LeftZero 0ᴹ *ᵣ
*ᵣ-distribʳ : *ᵣ DistributesOverʳ +ᴹ
record IsRightSemimodule (*ᵣ : Opᵣ R M) : Set (r ⊔ m ⊔ ℓr ⊔ ℓm) where
open RightDefs R ≈ᴹ
field
+ᴹ-isCommutativeMonoid : IsCommutativeMonoid ≈ᴹ +ᴹ 0ᴹ
isPrerightSemimodule : IsPrerightSemimodule *ᵣ
open IsPrerightSemimodule isPrerightSemimodule public
open IsCommutativeMonoid +ᴹ-isCommutativeMonoid public
using () renaming
( assoc to +ᴹ-assoc
; comm to +ᴹ-comm
; identity to +ᴹ-identity
; identityʳ to +ᴹ-identityʳ
; identityˡ to +ᴹ-identityˡ
; isEquivalence to ≈ᴹ-isEquivalence
; isMagma to +ᴹ-isMagma
; isMonoid to +ᴹ-isMonoid
; isPartialEquivalence to ≈ᴹ-isPartialEquivalence
; isSemigroup to +ᴹ-isSemigroup
; refl to ≈ᴹ-refl
; reflexive to ≈ᴹ-reflexive
; setoid to ≈ᴹ-setoid
; sym to ≈ᴹ-sym
; trans to ≈ᴹ-trans
; ∙-cong to +ᴹ-cong
; ∙-congʳ to +ᴹ-congʳ
; ∙-congˡ to +ᴹ-congˡ
)
*ᵣ-congˡ : LeftCongruent _≈_ *ᵣ
*ᵣ-congˡ xx = *ᵣ-cong ≈ᴹ-refl xx
*ᵣ-congʳ : RightCongruent *ᵣ
*ᵣ-congʳ mm = *ᵣ-cong mm refl
module _ (R-semiring : Semiring r ℓr) (S-semiring : Semiring s ℓs)
(≈ᴹ : Rel {m} M ℓm) (+ᴹ : Op₂ M) (0ᴹ : M)
where
open Semiring R-semiring using () renaming (Carrier to R)
open Semiring S-semiring using () renaming (Carrier to S)
record IsBisemimodule (*ₗ : Opₗ R M) (*ᵣ : Opᵣ S M)
: Set (r ⊔ s ⊔ m ⊔ ℓr ⊔ ℓs ⊔ ℓm) where
open BiDefs R S ≈ᴹ
field
+ᴹ-isCommutativeMonoid : IsCommutativeMonoid ≈ᴹ +ᴹ 0ᴹ
isPreleftSemimodule : IsPreleftSemimodule R-semiring ≈ᴹ +ᴹ 0ᴹ *ₗ
isPrerightSemimodule : IsPrerightSemimodule S-semiring ≈ᴹ +ᴹ 0ᴹ *ᵣ
*ₗ-*ᵣ-assoc : Associative *ₗ *ᵣ
isLeftSemimodule : IsLeftSemimodule R-semiring ≈ᴹ +ᴹ 0ᴹ *ₗ
isLeftSemimodule = record
{ +ᴹ-isCommutativeMonoid = +ᴹ-isCommutativeMonoid
; isPreleftSemimodule = isPreleftSemimodule
}
isRightSemimodule : IsRightSemimodule S-semiring ≈ᴹ +ᴹ 0ᴹ *ᵣ
isRightSemimodule = record
{ +ᴹ-isCommutativeMonoid = +ᴹ-isCommutativeMonoid
; isPrerightSemimodule = isPrerightSemimodule
}
open IsLeftSemimodule isLeftSemimodule public
hiding (+ᴹ-isCommutativeMonoid; isPreleftSemimodule)
open IsPrerightSemimodule isPrerightSemimodule public
open IsRightSemimodule isRightSemimodule public
using (*ᵣ-congˡ; *ᵣ-congʳ)
module _ (commutativeSemiring : CommutativeSemiring r ℓr)
(≈ᴹ : Rel {m} M ℓm) (+ᴹ : Op₂ M) (0ᴹ : M)
where
open CommutativeSemiring commutativeSemiring renaming (Carrier to R)
-- An R-semimodule is an R-R-bisemimodule where R is commutative.
-- This means that *ₗ and *ᵣ coincide up to mathematical equality, though it
-- may be that they do not coincide up to definitional equality.
record IsSemimodule (*ₗ : Opₗ R M) (*ᵣ : Opᵣ R M)
: Set (r ⊔ m ⊔ ℓr ⊔ ℓm) where
field
isBisemimodule : IsBisemimodule semiring semiring ≈ᴹ +ᴹ 0ᴹ *ₗ *ᵣ
open IsBisemimodule isBisemimodule public
module _ (ring : Ring r ℓr)
(≈ᴹ : Rel {m} M ℓm) (+ᴹ : Op₂ M) (0ᴹ : M) (-ᴹ : Op₁ M)
where
open Ring ring renaming (Carrier to R)
record IsLeftModule (*ₗ : Opₗ R M) : Set (r ⊔ m ⊔ ℓr ⊔ ℓm) where
open Defs ≈ᴹ
field
isLeftSemimodule : IsLeftSemimodule semiring ≈ᴹ +ᴹ 0ᴹ *ₗ
-ᴹ‿cong : Congruent₁ -ᴹ
-ᴹ‿inverse : Inverse 0ᴹ -ᴹ +ᴹ
open IsLeftSemimodule isLeftSemimodule public
+ᴹ-isAbelianGroup : IsAbelianGroup ≈ᴹ +ᴹ 0ᴹ -ᴹ
+ᴹ-isAbelianGroup = record
{ isGroup = record
{ isMonoid = +ᴹ-isMonoid
; inverse = -ᴹ‿inverse
; ⁻¹-cong = -ᴹ‿cong
}
; comm = +ᴹ-comm
}
open IsAbelianGroup +ᴹ-isAbelianGroup public
using () renaming
( isGroup to +ᴹ-isGroup
; inverseˡ to -ᴹ‿inverseˡ
; inverseʳ to -ᴹ‿inverseʳ
; uniqueˡ-⁻¹ to uniqueˡ‿-ᴹ
; uniqueʳ-⁻¹ to uniqueʳ‿-ᴹ
)
record IsRightModule (*ᵣ : Opᵣ R M) : Set (r ⊔ m ⊔ ℓr ⊔ ℓm) where
open Defs ≈ᴹ
field
isRightSemimodule : IsRightSemimodule semiring ≈ᴹ +ᴹ 0ᴹ *ᵣ
-ᴹ‿cong : Congruent₁ -ᴹ
-ᴹ‿inverse : Inverse 0ᴹ -ᴹ +ᴹ
open IsRightSemimodule isRightSemimodule public
+ᴹ-isAbelianGroup : IsAbelianGroup ≈ᴹ +ᴹ 0ᴹ -ᴹ
+ᴹ-isAbelianGroup = record
{ isGroup = record
{ isMonoid = +ᴹ-isMonoid
; inverse = -ᴹ‿inverse
; ⁻¹-cong = -ᴹ‿cong
}
; comm = +ᴹ-comm
}
open IsAbelianGroup +ᴹ-isAbelianGroup public
using () renaming
( isGroup to +ᴹ-isGroup
; inverseˡ to -ᴹ‿inverseˡ
; inverseʳ to -ᴹ‿inverseʳ
; uniqueˡ-⁻¹ to uniqueˡ‿-ᴹ
; uniqueʳ-⁻¹ to uniqueʳ‿-ᴹ
)
module _ (R-ring : Ring r ℓr) (S-ring : Ring s ℓs)
(≈ᴹ : Rel {m} M ℓm) (+ᴹ : Op₂ M) (0ᴹ : M) (-ᴹ : Op₁ M)
where
open Ring R-ring renaming (Carrier to R; semiring to R-semiring)
open Ring S-ring renaming (Carrier to S; semiring to S-semiring)
record IsBimodule (*ₗ : Opₗ R M) (*ᵣ : Opᵣ S M)
: Set (r ⊔ s ⊔ m ⊔ ℓr ⊔ ℓs ⊔ ℓm) where
open Defs ≈ᴹ
field
isBisemimodule : IsBisemimodule R-semiring S-semiring ≈ᴹ +ᴹ 0ᴹ *ₗ *ᵣ
-ᴹ‿cong : Congruent₁ -ᴹ
-ᴹ‿inverse : Inverse 0ᴹ -ᴹ +ᴹ
open IsBisemimodule isBisemimodule public
isLeftModule : IsLeftModule R-ring ≈ᴹ +ᴹ 0ᴹ -ᴹ *ₗ
isLeftModule = record
{ isLeftSemimodule = isLeftSemimodule
; -ᴹ‿cong = -ᴹ‿cong
; -ᴹ‿inverse = -ᴹ‿inverse
}
open IsLeftModule isLeftModule public
using ( +ᴹ-isAbelianGroup; +ᴹ-isGroup; -ᴹ‿inverseˡ; -ᴹ‿inverseʳ
; uniqueˡ‿-ᴹ; uniqueʳ‿-ᴹ)
isRightModule : IsRightModule S-ring ≈ᴹ +ᴹ 0ᴹ -ᴹ *ᵣ
isRightModule = record
{ isRightSemimodule = isRightSemimodule
; -ᴹ‿cong = -ᴹ‿cong
; -ᴹ‿inverse = -ᴹ‿inverse
}
module _ (commutativeRing : CommutativeRing r ℓr)
(≈ᴹ : Rel {m} M ℓm) (+ᴹ : Op₂ M) (0ᴹ : M) (-ᴹ : Op₁ M)
where
open CommutativeRing commutativeRing renaming (Carrier to R)
-- An R-module is an R-R-bimodule where R is commutative.
-- This means that *ₗ and *ᵣ coincide up to mathematical equality, though it
-- may be that they do not coincide up to definitional equality.
record IsModule (*ₗ : Opₗ R M) (*ᵣ : Opᵣ R M) : Set (r ⊔ m ⊔ ℓr ⊔ ℓm) where
field
isBimodule : IsBimodule ring ring ≈ᴹ +ᴹ 0ᴹ -ᴹ *ₗ *ᵣ
open IsBimodule isBimodule public
isSemimodule : IsSemimodule commutativeSemiring ≈ᴹ +ᴹ 0ᴹ *ₗ *ᵣ
isSemimodule = record { isBisemimodule = isBisemimodule }
| {
"alphanum_fraction": 0.5873559639,
"avg_line_length": 32.9897260274,
"ext": "agda",
"hexsha": "d8952798f048c4a2cc30286b4a5ff452e58e0992",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Algebra/Module/Structures.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Algebra/Module/Structures.agda",
"max_line_length": 78,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Algebra/Module/Structures.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 4008,
"size": 9633
} |
------------------------------------------------------------------------
-- Some derivable properties
------------------------------------------------------------------------
open import Algebra
module Algebra.Props.BooleanAlgebra (b : BooleanAlgebra) where
open BooleanAlgebra b
import Algebra.Props.DistributiveLattice as DL
open DL distributiveLattice public
open import Algebra.Structures
import Algebra.FunctionProperties as P; open P _≈_
import Relation.Binary.EqReasoning as EqR; open EqR setoid
open import Relation.Binary
open import Data.Function
open import Data.Product
------------------------------------------------------------------------
-- Some simple generalisations
∨-complement : Inverse ⊤ ¬_ _∨_
∨-complement = ∨-complementˡ , ∨-complementʳ
where
∨-complementˡ : LeftInverse ⊤ ¬_ _∨_
∨-complementˡ x = begin
¬ x ∨ x ≈⟨ ∨-comm _ _ ⟩
x ∨ ¬ x ≈⟨ ∨-complementʳ _ ⟩
⊤ ∎
∧-complement : Inverse ⊥ ¬_ _∧_
∧-complement = ∧-complementˡ , ∧-complementʳ
where
∧-complementˡ : LeftInverse ⊥ ¬_ _∧_
∧-complementˡ x = begin
¬ x ∧ x ≈⟨ ∧-comm _ _ ⟩
x ∧ ¬ x ≈⟨ ∧-complementʳ _ ⟩
⊥ ∎
------------------------------------------------------------------------
-- The dual construction is also a boolean algebra
∧-∨-isBooleanAlgebra : IsBooleanAlgebra _≈_ _∧_ _∨_ ¬_ ⊥ ⊤
∧-∨-isBooleanAlgebra = record
{ isDistributiveLattice = ∧-∨-isDistributiveLattice
; ∨-complementʳ = proj₂ ∧-complement
; ∧-complementʳ = proj₂ ∨-complement
; ¬-pres-≈ = ¬-pres-≈
}
∧-∨-booleanAlgebra : BooleanAlgebra
∧-∨-booleanAlgebra = record
{ _∧_ = _∨_
; _∨_ = _∧_
; ⊤ = ⊥
; ⊥ = ⊤
; isBooleanAlgebra = ∧-∨-isBooleanAlgebra
}
------------------------------------------------------------------------
-- (∨, ∧, ⊥, ⊤) is a commutative semiring
private
∧-identity : Identity ⊤ _∧_
∧-identity = (λ _ → ∧-comm _ _ ⟨ trans ⟩ x∧⊤=x _) , x∧⊤=x
where
x∧⊤=x : ∀ x → x ∧ ⊤ ≈ x
x∧⊤=x x = begin
x ∧ ⊤ ≈⟨ refl ⟨ ∧-pres-≈ ⟩ sym (proj₂ ∨-complement _) ⟩
x ∧ (x ∨ ¬ x) ≈⟨ proj₂ absorptive _ _ ⟩
x ∎
∨-identity : Identity ⊥ _∨_
∨-identity = (λ _ → ∨-comm _ _ ⟨ trans ⟩ x∨⊥=x _) , x∨⊥=x
where
x∨⊥=x : ∀ x → x ∨ ⊥ ≈ x
x∨⊥=x x = begin
x ∨ ⊥ ≈⟨ refl ⟨ ∨-pres-≈ ⟩ sym (proj₂ ∧-complement _) ⟩
x ∨ x ∧ ¬ x ≈⟨ proj₁ absorptive _ _ ⟩
x ∎
∧-zero : Zero ⊥ _∧_
∧-zero = (λ _ → ∧-comm _ _ ⟨ trans ⟩ x∧⊥=⊥ _) , x∧⊥=⊥
where
x∧⊥=⊥ : ∀ x → x ∧ ⊥ ≈ ⊥
x∧⊥=⊥ x = begin
x ∧ ⊥ ≈⟨ refl ⟨ ∧-pres-≈ ⟩ sym (proj₂ ∧-complement _) ⟩
x ∧ x ∧ ¬ x ≈⟨ sym $ ∧-assoc _ _ _ ⟩
(x ∧ x) ∧ ¬ x ≈⟨ ∧-idempotent _ ⟨ ∧-pres-≈ ⟩ refl ⟩
x ∧ ¬ x ≈⟨ proj₂ ∧-complement _ ⟩
⊥ ∎
∨-∧-isCommutativeSemiring : IsCommutativeSemiring _≈_ _∨_ _∧_ ⊥ ⊤
∨-∧-isCommutativeSemiring = record
{ isSemiring = record
{ isSemiringWithoutAnnihilatingZero = record
{ +-isCommutativeMonoid = record
{ isMonoid = record
{ isSemigroup = record
{ isEquivalence = isEquivalence
; assoc = ∨-assoc
; ∙-pres-≈ = ∨-pres-≈
}
; identity = ∨-identity
}
; comm = ∨-comm
}
; *-isMonoid = record
{ isSemigroup = record
{ isEquivalence = isEquivalence
; assoc = ∧-assoc
; ∙-pres-≈ = ∧-pres-≈
}
; identity = ∧-identity
}
; distrib = ∧-∨-distrib
}
; zero = ∧-zero
}
; *-comm = ∧-comm
}
∨-∧-commutativeSemiring : CommutativeSemiring
∨-∧-commutativeSemiring = record
{ _+_ = _∨_
; _*_ = _∧_
; 0# = ⊥
; 1# = ⊤
; isCommutativeSemiring = ∨-∧-isCommutativeSemiring
}
------------------------------------------------------------------------
-- (∧, ∨, ⊤, ⊥) is a commutative semiring
private
∨-zero : Zero ⊤ _∨_
∨-zero = (λ _ → ∨-comm _ _ ⟨ trans ⟩ x∨⊤=⊤ _) , x∨⊤=⊤
where
x∨⊤=⊤ : ∀ x → x ∨ ⊤ ≈ ⊤
x∨⊤=⊤ x = begin
x ∨ ⊤ ≈⟨ refl ⟨ ∨-pres-≈ ⟩ sym (proj₂ ∨-complement _) ⟩
x ∨ x ∨ ¬ x ≈⟨ sym $ ∨-assoc _ _ _ ⟩
(x ∨ x) ∨ ¬ x ≈⟨ ∨-idempotent _ ⟨ ∨-pres-≈ ⟩ refl ⟩
x ∨ ¬ x ≈⟨ proj₂ ∨-complement _ ⟩
⊤ ∎
∧-∨-isCommutativeSemiring : IsCommutativeSemiring _≈_ _∧_ _∨_ ⊤ ⊥
∧-∨-isCommutativeSemiring = record
{ isSemiring = record
{ isSemiringWithoutAnnihilatingZero = record
{ +-isCommutativeMonoid = record
{ isMonoid = record
{ isSemigroup = record
{ isEquivalence = isEquivalence
; assoc = ∧-assoc
; ∙-pres-≈ = ∧-pres-≈
}
; identity = ∧-identity
}
; comm = ∧-comm
}
; *-isMonoid = record
{ isSemigroup = record
{ isEquivalence = isEquivalence
; assoc = ∨-assoc
; ∙-pres-≈ = ∨-pres-≈
}
; identity = ∨-identity
}
; distrib = ∨-∧-distrib
}
; zero = ∨-zero
}
; *-comm = ∨-comm
}
∧-∨-commutativeSemiring : CommutativeSemiring
∧-∨-commutativeSemiring =
record { isCommutativeSemiring = ∧-∨-isCommutativeSemiring }
------------------------------------------------------------------------
-- Some other properties
-- I took the statement of this lemma (called Uniqueness of
-- Complements) from some course notes, "Boolean Algebra", written
-- by Gert Smolka.
private
lemma : ∀ x y → x ∧ y ≈ ⊥ → x ∨ y ≈ ⊤ → ¬ x ≈ y
lemma x y x∧y=⊥ x∨y=⊤ = begin
¬ x ≈⟨ sym $ proj₂ ∧-identity _ ⟩
¬ x ∧ ⊤ ≈⟨ refl ⟨ ∧-pres-≈ ⟩ sym x∨y=⊤ ⟩
¬ x ∧ (x ∨ y) ≈⟨ proj₁ ∧-∨-distrib _ _ _ ⟩
¬ x ∧ x ∨ ¬ x ∧ y ≈⟨ proj₁ ∧-complement _ ⟨ ∨-pres-≈ ⟩ refl ⟩
⊥ ∨ ¬ x ∧ y ≈⟨ sym x∧y=⊥ ⟨ ∨-pres-≈ ⟩ refl ⟩
x ∧ y ∨ ¬ x ∧ y ≈⟨ sym $ proj₂ ∧-∨-distrib _ _ _ ⟩
(x ∨ ¬ x) ∧ y ≈⟨ proj₂ ∨-complement _ ⟨ ∧-pres-≈ ⟩ refl ⟩
⊤ ∧ y ≈⟨ proj₁ ∧-identity _ ⟩
y ∎
¬⊥=⊤ : ¬ ⊥ ≈ ⊤
¬⊥=⊤ = lemma ⊥ ⊤ (proj₂ ∧-identity _) (proj₂ ∨-zero _)
¬⊤=⊥ : ¬ ⊤ ≈ ⊥
¬⊤=⊥ = lemma ⊤ ⊥ (proj₂ ∧-zero _) (proj₂ ∨-identity _)
¬-involutive : Involutive ¬_
¬-involutive x = lemma (¬ x) x (proj₁ ∧-complement _) (proj₁ ∨-complement _)
deMorgan₁ : ∀ x y → ¬ (x ∧ y) ≈ ¬ x ∨ ¬ y
deMorgan₁ x y = lemma (x ∧ y) (¬ x ∨ ¬ y) lem₁ lem₂
where
lem₁ = begin
(x ∧ y) ∧ (¬ x ∨ ¬ y) ≈⟨ proj₁ ∧-∨-distrib _ _ _ ⟩
(x ∧ y) ∧ ¬ x ∨ (x ∧ y) ∧ ¬ y ≈⟨ (∧-comm _ _ ⟨ ∧-pres-≈ ⟩ refl) ⟨ ∨-pres-≈ ⟩ refl ⟩
(y ∧ x) ∧ ¬ x ∨ (x ∧ y) ∧ ¬ y ≈⟨ ∧-assoc _ _ _ ⟨ ∨-pres-≈ ⟩ ∧-assoc _ _ _ ⟩
y ∧ (x ∧ ¬ x) ∨ x ∧ (y ∧ ¬ y) ≈⟨ (refl ⟨ ∧-pres-≈ ⟩ proj₂ ∧-complement _) ⟨ ∨-pres-≈ ⟩
(refl ⟨ ∧-pres-≈ ⟩ proj₂ ∧-complement _) ⟩
(y ∧ ⊥) ∨ (x ∧ ⊥) ≈⟨ proj₂ ∧-zero _ ⟨ ∨-pres-≈ ⟩ proj₂ ∧-zero _ ⟩
⊥ ∨ ⊥ ≈⟨ proj₂ ∨-identity _ ⟩
⊥ ∎
lem₃ = begin
(x ∧ y) ∨ ¬ x ≈⟨ proj₂ ∨-∧-distrib _ _ _ ⟩
(x ∨ ¬ x) ∧ (y ∨ ¬ x) ≈⟨ proj₂ ∨-complement _ ⟨ ∧-pres-≈ ⟩ refl ⟩
⊤ ∧ (y ∨ ¬ x) ≈⟨ proj₁ ∧-identity _ ⟩
y ∨ ¬ x ≈⟨ ∨-comm _ _ ⟩
¬ x ∨ y ∎
lem₂ = begin
(x ∧ y) ∨ (¬ x ∨ ¬ y) ≈⟨ sym $ ∨-assoc _ _ _ ⟩
((x ∧ y) ∨ ¬ x) ∨ ¬ y ≈⟨ lem₃ ⟨ ∨-pres-≈ ⟩ refl ⟩
(¬ x ∨ y) ∨ ¬ y ≈⟨ ∨-assoc _ _ _ ⟩
¬ x ∨ (y ∨ ¬ y) ≈⟨ refl ⟨ ∨-pres-≈ ⟩ proj₂ ∨-complement _ ⟩
¬ x ∨ ⊤ ≈⟨ proj₂ ∨-zero _ ⟩
⊤ ∎
deMorgan₂ : ∀ x y → ¬ (x ∨ y) ≈ ¬ x ∧ ¬ y
deMorgan₂ x y = begin
¬ (x ∨ y) ≈⟨ ¬-pres-≈ $ sym (¬-involutive _) ⟨ ∨-pres-≈ ⟩
sym (¬-involutive _) ⟩
¬ (¬ ¬ x ∨ ¬ ¬ y) ≈⟨ ¬-pres-≈ $ sym $ deMorgan₁ _ _ ⟩
¬ ¬ (¬ x ∧ ¬ y) ≈⟨ ¬-involutive _ ⟩
¬ x ∧ ¬ y ∎
------------------------------------------------------------------------
-- (⊕, ∧, id, ⊥, ⊤) is a commutative ring
-- This construction is parameterised over the definition of xor.
module XorRing
(xor : Op₂ carrier)
(⊕-def : ∀ x y → xor x y ≈ (x ∨ y) ∧ ¬ (x ∧ y))
where
private
infixl 6 _⊕_
_⊕_ : Op₂ carrier
_⊕_ = xor
private
helper : ∀ {x y u v} → x ≈ y → u ≈ v → x ∧ ¬ u ≈ y ∧ ¬ v
helper x≈y u≈v = x≈y ⟨ ∧-pres-≈ ⟩ ¬-pres-≈ u≈v
⊕-¬-distribˡ : ∀ x y → ¬ (x ⊕ y) ≈ ¬ x ⊕ y
⊕-¬-distribˡ x y = begin
¬ (x ⊕ y) ≈⟨ ¬-pres-≈ $ ⊕-def _ _ ⟩
¬ ((x ∨ y) ∧ (¬ (x ∧ y))) ≈⟨ ¬-pres-≈ (proj₂ ∧-∨-distrib _ _ _) ⟩
¬ ((x ∧ ¬ (x ∧ y)) ∨ (y ∧ ¬ (x ∧ y))) ≈⟨ ¬-pres-≈ $
refl ⟨ ∨-pres-≈ ⟩
(refl ⟨ ∧-pres-≈ ⟩
¬-pres-≈ (∧-comm _ _)) ⟩
¬ ((x ∧ ¬ (x ∧ y)) ∨ (y ∧ ¬ (y ∧ x))) ≈⟨ ¬-pres-≈ $ lem _ _ ⟨ ∨-pres-≈ ⟩ lem _ _ ⟩
¬ ((x ∧ ¬ y) ∨ (y ∧ ¬ x)) ≈⟨ deMorgan₂ _ _ ⟩
¬ (x ∧ ¬ y) ∧ ¬ (y ∧ ¬ x) ≈⟨ deMorgan₁ _ _ ⟨ ∧-pres-≈ ⟩ refl ⟩
(¬ x ∨ (¬ ¬ y)) ∧ ¬ (y ∧ ¬ x) ≈⟨ helper (refl ⟨ ∨-pres-≈ ⟩ ¬-involutive _)
(∧-comm _ _) ⟩
(¬ x ∨ y) ∧ ¬ (¬ x ∧ y) ≈⟨ sym $ ⊕-def _ _ ⟩
¬ x ⊕ y ∎
where
lem : ∀ x y → x ∧ ¬ (x ∧ y) ≈ x ∧ ¬ y
lem x y = begin
x ∧ ¬ (x ∧ y) ≈⟨ refl ⟨ ∧-pres-≈ ⟩ deMorgan₁ _ _ ⟩
x ∧ (¬ x ∨ ¬ y) ≈⟨ proj₁ ∧-∨-distrib _ _ _ ⟩
(x ∧ ¬ x) ∨ (x ∧ ¬ y) ≈⟨ proj₂ ∧-complement _ ⟨ ∨-pres-≈ ⟩ refl ⟩
⊥ ∨ (x ∧ ¬ y) ≈⟨ proj₁ ∨-identity _ ⟩
x ∧ ¬ y ∎
private
⊕-comm : Commutative _⊕_
⊕-comm x y = begin
x ⊕ y ≈⟨ ⊕-def _ _ ⟩
(x ∨ y) ∧ ¬ (x ∧ y) ≈⟨ helper (∨-comm _ _) (∧-comm _ _) ⟩
(y ∨ x) ∧ ¬ (y ∧ x) ≈⟨ sym $ ⊕-def _ _ ⟩
y ⊕ x ∎
⊕-¬-distribʳ : ∀ x y → ¬ (x ⊕ y) ≈ x ⊕ ¬ y
⊕-¬-distribʳ x y = begin
¬ (x ⊕ y) ≈⟨ ¬-pres-≈ $ ⊕-comm _ _ ⟩
¬ (y ⊕ x) ≈⟨ ⊕-¬-distribˡ _ _ ⟩
¬ y ⊕ x ≈⟨ ⊕-comm _ _ ⟩
x ⊕ ¬ y ∎
⊕-annihilates-¬ : ∀ x y → x ⊕ y ≈ ¬ x ⊕ ¬ y
⊕-annihilates-¬ x y = begin
x ⊕ y ≈⟨ sym $ ¬-involutive _ ⟩
¬ ¬ (x ⊕ y) ≈⟨ ¬-pres-≈ $ ⊕-¬-distribˡ _ _ ⟩
¬ (¬ x ⊕ y) ≈⟨ ⊕-¬-distribʳ _ _ ⟩
¬ x ⊕ ¬ y ∎
private
⊕-pres : _⊕_ Preserves₂ _≈_ ⟶ _≈_ ⟶ _≈_
⊕-pres {x} {y} {u} {v} x≈y u≈v = begin
x ⊕ u ≈⟨ ⊕-def _ _ ⟩
(x ∨ u) ∧ ¬ (x ∧ u) ≈⟨ helper (x≈y ⟨ ∨-pres-≈ ⟩ u≈v)
(x≈y ⟨ ∧-pres-≈ ⟩ u≈v) ⟩
(y ∨ v) ∧ ¬ (y ∧ v) ≈⟨ sym $ ⊕-def _ _ ⟩
y ⊕ v ∎
⊕-identity : Identity ⊥ _⊕_
⊕-identity = ⊥⊕x=x , (λ _ → ⊕-comm _ _ ⟨ trans ⟩ ⊥⊕x=x _)
where
⊥⊕x=x : ∀ x → ⊥ ⊕ x ≈ x
⊥⊕x=x x = begin
⊥ ⊕ x ≈⟨ ⊕-def _ _ ⟩
(⊥ ∨ x) ∧ ¬ (⊥ ∧ x) ≈⟨ helper (proj₁ ∨-identity _)
(proj₁ ∧-zero _) ⟩
x ∧ ¬ ⊥ ≈⟨ refl ⟨ ∧-pres-≈ ⟩ ¬⊥=⊤ ⟩
x ∧ ⊤ ≈⟨ proj₂ ∧-identity _ ⟩
x ∎
⊕-inverse : Inverse ⊥ id _⊕_
⊕-inverse = x⊕x=⊥ , (λ _ → ⊕-comm _ _ ⟨ trans ⟩ x⊕x=⊥ _)
where
x⊕x=⊥ : ∀ x → x ⊕ x ≈ ⊥
x⊕x=⊥ x = begin
x ⊕ x ≈⟨ ⊕-def _ _ ⟩
(x ∨ x) ∧ ¬ (x ∧ x) ≈⟨ helper (∨-idempotent _)
(∧-idempotent _) ⟩
x ∧ ¬ x ≈⟨ proj₂ ∧-complement _ ⟩
⊥ ∎
distrib-∧-⊕ : _∧_ DistributesOver _⊕_
distrib-∧-⊕ = distˡ , distʳ
where
distˡ : _∧_ DistributesOverˡ _⊕_
distˡ x y z = begin
x ∧ (y ⊕ z) ≈⟨ refl ⟨ ∧-pres-≈ ⟩ ⊕-def _ _ ⟩
x ∧ ((y ∨ z) ∧ ¬ (y ∧ z)) ≈⟨ sym $ ∧-assoc _ _ _ ⟩
(x ∧ (y ∨ z)) ∧ ¬ (y ∧ z) ≈⟨ refl ⟨ ∧-pres-≈ ⟩ deMorgan₁ _ _ ⟩
(x ∧ (y ∨ z)) ∧
(¬ y ∨ ¬ z) ≈⟨ sym $ proj₁ ∨-identity _ ⟩
⊥ ∨
((x ∧ (y ∨ z)) ∧
(¬ y ∨ ¬ z)) ≈⟨ lem₃ ⟨ ∨-pres-≈ ⟩ refl ⟩
((x ∧ (y ∨ z)) ∧ ¬ x) ∨
((x ∧ (y ∨ z)) ∧
(¬ y ∨ ¬ z)) ≈⟨ sym $ proj₁ ∧-∨-distrib _ _ _ ⟩
(x ∧ (y ∨ z)) ∧
(¬ x ∨ (¬ y ∨ ¬ z)) ≈⟨ refl ⟨ ∧-pres-≈ ⟩
(refl ⟨ ∨-pres-≈ ⟩ sym (deMorgan₁ _ _)) ⟩
(x ∧ (y ∨ z)) ∧
(¬ x ∨ ¬ (y ∧ z)) ≈⟨ refl ⟨ ∧-pres-≈ ⟩ sym (deMorgan₁ _ _) ⟩
(x ∧ (y ∨ z)) ∧
¬ (x ∧ (y ∧ z)) ≈⟨ helper refl lem₁ ⟩
(x ∧ (y ∨ z)) ∧
¬ ((x ∧ y) ∧ (x ∧ z)) ≈⟨ proj₁ ∧-∨-distrib _ _ _ ⟨ ∧-pres-≈ ⟩
refl ⟩
((x ∧ y) ∨ (x ∧ z)) ∧
¬ ((x ∧ y) ∧ (x ∧ z)) ≈⟨ sym $ ⊕-def _ _ ⟩
(x ∧ y) ⊕ (x ∧ z) ∎
where
lem₂ = begin
x ∧ (y ∧ z) ≈⟨ sym $ ∧-assoc _ _ _ ⟩
(x ∧ y) ∧ z ≈⟨ ∧-comm _ _ ⟨ ∧-pres-≈ ⟩ refl ⟩
(y ∧ x) ∧ z ≈⟨ ∧-assoc _ _ _ ⟩
y ∧ (x ∧ z) ∎
lem₁ = begin
x ∧ (y ∧ z) ≈⟨ sym (∧-idempotent _) ⟨ ∧-pres-≈ ⟩ refl ⟩
(x ∧ x) ∧ (y ∧ z) ≈⟨ ∧-assoc _ _ _ ⟩
x ∧ (x ∧ (y ∧ z)) ≈⟨ refl ⟨ ∧-pres-≈ ⟩ lem₂ ⟩
x ∧ (y ∧ (x ∧ z)) ≈⟨ sym $ ∧-assoc _ _ _ ⟩
(x ∧ y) ∧ (x ∧ z) ∎
lem₃ = begin
⊥ ≈⟨ sym $ proj₂ ∧-zero _ ⟩
(y ∨ z) ∧ ⊥ ≈⟨ refl ⟨ ∧-pres-≈ ⟩ sym (proj₂ ∧-complement _) ⟩
(y ∨ z) ∧ (x ∧ ¬ x) ≈⟨ sym $ ∧-assoc _ _ _ ⟩
((y ∨ z) ∧ x) ∧ ¬ x ≈⟨ ∧-comm _ _ ⟨ ∧-pres-≈ ⟩ refl ⟩
(x ∧ (y ∨ z)) ∧ ¬ x ∎
distʳ : _∧_ DistributesOverʳ _⊕_
distʳ x y z = begin
(y ⊕ z) ∧ x ≈⟨ ∧-comm _ _ ⟩
x ∧ (y ⊕ z) ≈⟨ distˡ _ _ _ ⟩
(x ∧ y) ⊕ (x ∧ z) ≈⟨ ∧-comm _ _ ⟨ ⊕-pres ⟩ ∧-comm _ _ ⟩
(y ∧ x) ⊕ (z ∧ x) ∎
lemma₂ : ∀ x y u v →
(x ∧ y) ∨ (u ∧ v) ≈
((x ∨ u) ∧ (y ∨ u)) ∧
((x ∨ v) ∧ (y ∨ v))
lemma₂ x y u v = begin
(x ∧ y) ∨ (u ∧ v) ≈⟨ proj₁ ∨-∧-distrib _ _ _ ⟩
((x ∧ y) ∨ u) ∧ ((x ∧ y) ∨ v) ≈⟨ proj₂ ∨-∧-distrib _ _ _
⟨ ∧-pres-≈ ⟩
proj₂ ∨-∧-distrib _ _ _ ⟩
((x ∨ u) ∧ (y ∨ u)) ∧
((x ∨ v) ∧ (y ∨ v)) ∎
⊕-assoc : Associative _⊕_
⊕-assoc x y z = sym $ begin
x ⊕ (y ⊕ z) ≈⟨ refl ⟨ ⊕-pres ⟩ ⊕-def _ _ ⟩
x ⊕ ((y ∨ z) ∧ ¬ (y ∧ z)) ≈⟨ ⊕-def _ _ ⟩
(x ∨ ((y ∨ z) ∧ ¬ (y ∧ z))) ∧
¬ (x ∧ ((y ∨ z) ∧ ¬ (y ∧ z))) ≈⟨ lem₃ ⟨ ∧-pres-≈ ⟩ lem₄ ⟩
(((x ∨ y) ∨ z) ∧ ((x ∨ ¬ y) ∨ ¬ z)) ∧
(((¬ x ∨ ¬ y) ∨ z) ∧ ((¬ x ∨ y) ∨ ¬ z)) ≈⟨ ∧-assoc _ _ _ ⟩
((x ∨ y) ∨ z) ∧
(((x ∨ ¬ y) ∨ ¬ z) ∧
(((¬ x ∨ ¬ y) ∨ z) ∧ ((¬ x ∨ y) ∨ ¬ z))) ≈⟨ refl ⟨ ∧-pres-≈ ⟩ lem₅ ⟩
((x ∨ y) ∨ z) ∧
(((¬ x ∨ ¬ y) ∨ z) ∧
(((x ∨ ¬ y) ∨ ¬ z) ∧ ((¬ x ∨ y) ∨ ¬ z))) ≈⟨ sym $ ∧-assoc _ _ _ ⟩
(((x ∨ y) ∨ z) ∧ ((¬ x ∨ ¬ y) ∨ z)) ∧
(((x ∨ ¬ y) ∨ ¬ z) ∧ ((¬ x ∨ y) ∨ ¬ z)) ≈⟨ lem₁ ⟨ ∧-pres-≈ ⟩ lem₂ ⟩
(((x ∨ y) ∧ ¬ (x ∧ y)) ∨ z) ∧
¬ (((x ∨ y) ∧ ¬ (x ∧ y)) ∧ z) ≈⟨ sym $ ⊕-def _ _ ⟩
((x ∨ y) ∧ ¬ (x ∧ y)) ⊕ z ≈⟨ sym $ ⊕-def _ _ ⟨ ⊕-pres ⟩ refl ⟩
(x ⊕ y) ⊕ z ∎
where
lem₁ = begin
((x ∨ y) ∨ z) ∧ ((¬ x ∨ ¬ y) ∨ z) ≈⟨ sym $ proj₂ ∨-∧-distrib _ _ _ ⟩
((x ∨ y) ∧ (¬ x ∨ ¬ y)) ∨ z ≈⟨ (refl ⟨ ∧-pres-≈ ⟩ sym (deMorgan₁ _ _))
⟨ ∨-pres-≈ ⟩ refl ⟩
((x ∨ y) ∧ ¬ (x ∧ y)) ∨ z ∎
lem₂' = begin
(x ∨ ¬ y) ∧ (¬ x ∨ y) ≈⟨ sym $
proj₁ ∧-identity _
⟨ ∧-pres-≈ ⟩
proj₂ ∧-identity _ ⟩
(⊤ ∧ (x ∨ ¬ y)) ∧ ((¬ x ∨ y) ∧ ⊤) ≈⟨ sym $
(proj₁ ∨-complement _ ⟨ ∧-pres-≈ ⟩ ∨-comm _ _)
⟨ ∧-pres-≈ ⟩
(refl ⟨ ∧-pres-≈ ⟩ proj₁ ∨-complement _) ⟩
((¬ x ∨ x) ∧ (¬ y ∨ x)) ∧
((¬ x ∨ y) ∧ (¬ y ∨ y)) ≈⟨ sym $ lemma₂ _ _ _ _ ⟩
(¬ x ∧ ¬ y) ∨ (x ∧ y) ≈⟨ sym $ deMorgan₂ _ _ ⟨ ∨-pres-≈ ⟩ ¬-involutive _ ⟩
¬ (x ∨ y) ∨ ¬ ¬ (x ∧ y) ≈⟨ sym (deMorgan₁ _ _) ⟩
¬ ((x ∨ y) ∧ ¬ (x ∧ y)) ∎
lem₂ = begin
((x ∨ ¬ y) ∨ ¬ z) ∧ ((¬ x ∨ y) ∨ ¬ z) ≈⟨ sym $ proj₂ ∨-∧-distrib _ _ _ ⟩
((x ∨ ¬ y) ∧ (¬ x ∨ y)) ∨ ¬ z ≈⟨ lem₂' ⟨ ∨-pres-≈ ⟩ refl ⟩
¬ ((x ∨ y) ∧ ¬ (x ∧ y)) ∨ ¬ z ≈⟨ sym $ deMorgan₁ _ _ ⟩
¬ (((x ∨ y) ∧ ¬ (x ∧ y)) ∧ z) ∎
lem₃ = begin
x ∨ ((y ∨ z) ∧ ¬ (y ∧ z)) ≈⟨ refl ⟨ ∨-pres-≈ ⟩
(refl ⟨ ∧-pres-≈ ⟩ deMorgan₁ _ _) ⟩
x ∨ ((y ∨ z) ∧ (¬ y ∨ ¬ z)) ≈⟨ proj₁ ∨-∧-distrib _ _ _ ⟩
(x ∨ (y ∨ z)) ∧ (x ∨ (¬ y ∨ ¬ z)) ≈⟨ sym (∨-assoc _ _ _) ⟨ ∧-pres-≈ ⟩
sym (∨-assoc _ _ _) ⟩
((x ∨ y) ∨ z) ∧ ((x ∨ ¬ y) ∨ ¬ z) ∎
lem₄' = begin
¬ ((y ∨ z) ∧ ¬ (y ∧ z)) ≈⟨ deMorgan₁ _ _ ⟩
¬ (y ∨ z) ∨ ¬ ¬ (y ∧ z) ≈⟨ deMorgan₂ _ _ ⟨ ∨-pres-≈ ⟩ ¬-involutive _ ⟩
(¬ y ∧ ¬ z) ∨ (y ∧ z) ≈⟨ lemma₂ _ _ _ _ ⟩
((¬ y ∨ y) ∧ (¬ z ∨ y)) ∧
((¬ y ∨ z) ∧ (¬ z ∨ z)) ≈⟨ (proj₁ ∨-complement _ ⟨ ∧-pres-≈ ⟩ ∨-comm _ _)
⟨ ∧-pres-≈ ⟩
(refl ⟨ ∧-pres-≈ ⟩ proj₁ ∨-complement _) ⟩
(⊤ ∧ (y ∨ ¬ z)) ∧
((¬ y ∨ z) ∧ ⊤) ≈⟨ proj₁ ∧-identity _ ⟨ ∧-pres-≈ ⟩
proj₂ ∧-identity _ ⟩
(y ∨ ¬ z) ∧ (¬ y ∨ z) ∎
lem₄ = begin
¬ (x ∧ ((y ∨ z) ∧ ¬ (y ∧ z))) ≈⟨ deMorgan₁ _ _ ⟩
¬ x ∨ ¬ ((y ∨ z) ∧ ¬ (y ∧ z)) ≈⟨ refl ⟨ ∨-pres-≈ ⟩ lem₄' ⟩
¬ x ∨ ((y ∨ ¬ z) ∧ (¬ y ∨ z)) ≈⟨ proj₁ ∨-∧-distrib _ _ _ ⟩
(¬ x ∨ (y ∨ ¬ z)) ∧
(¬ x ∨ (¬ y ∨ z)) ≈⟨ sym (∨-assoc _ _ _) ⟨ ∧-pres-≈ ⟩
sym (∨-assoc _ _ _) ⟩
((¬ x ∨ y) ∨ ¬ z) ∧
((¬ x ∨ ¬ y) ∨ z) ≈⟨ ∧-comm _ _ ⟩
((¬ x ∨ ¬ y) ∨ z) ∧
((¬ x ∨ y) ∨ ¬ z) ∎
lem₅ = begin
((x ∨ ¬ y) ∨ ¬ z) ∧
(((¬ x ∨ ¬ y) ∨ z) ∧ ((¬ x ∨ y) ∨ ¬ z)) ≈⟨ sym $ ∧-assoc _ _ _ ⟩
(((x ∨ ¬ y) ∨ ¬ z) ∧ ((¬ x ∨ ¬ y) ∨ z)) ∧
((¬ x ∨ y) ∨ ¬ z) ≈⟨ ∧-comm _ _ ⟨ ∧-pres-≈ ⟩ refl ⟩
(((¬ x ∨ ¬ y) ∨ z) ∧ ((x ∨ ¬ y) ∨ ¬ z)) ∧
((¬ x ∨ y) ∨ ¬ z) ≈⟨ ∧-assoc _ _ _ ⟩
((¬ x ∨ ¬ y) ∨ z) ∧
(((x ∨ ¬ y) ∨ ¬ z) ∧ ((¬ x ∨ y) ∨ ¬ z)) ∎
isCommutativeRing : IsCommutativeRing _≈_ _⊕_ _∧_ id ⊥ ⊤
isCommutativeRing = record
{ isRing = record
{ +-isAbelianGroup = record
{ isGroup = record
{ isMonoid = record
{ isSemigroup = record
{ isEquivalence = isEquivalence
; assoc = ⊕-assoc
; ∙-pres-≈ = ⊕-pres
}
; identity = ⊕-identity
}
; inverse = ⊕-inverse
; ⁻¹-pres-≈ = id
}
; comm = ⊕-comm
}
; *-isMonoid = record
{ isSemigroup = record
{ isEquivalence = isEquivalence
; assoc = ∧-assoc
; ∙-pres-≈ = ∧-pres-≈
}
; identity = ∧-identity
}
; distrib = distrib-∧-⊕
}
; *-comm = ∧-comm
}
commutativeRing : CommutativeRing
commutativeRing = record
{ _+_ = _⊕_
; _*_ = _∧_
; -_ = id
; 0# = ⊥
; 1# = ⊤
; isCommutativeRing = isCommutativeRing
}
infixl 6 _⊕_
_⊕_ : Op₂ carrier
x ⊕ y = (x ∨ y) ∧ ¬ (x ∧ y)
module DefaultXorRing = XorRing _⊕_ (λ _ _ → refl)
| {
"alphanum_fraction": 0.329659564,
"avg_line_length": 36.9168173599,
"ext": "agda",
"hexsha": "63eaddd5c8e81eab46a35782c7201e3c969413b5",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z",
"max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "isabella232/Lemmachine",
"max_forks_repo_path": "vendor/stdlib/src/Algebra/Props/BooleanAlgebra.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/Lemmachine",
"max_issues_repo_path": "vendor/stdlib/src/Algebra/Props/BooleanAlgebra.agda",
"max_line_length": 95,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "vendor/stdlib/src/Algebra/Props/BooleanAlgebra.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z",
"num_tokens": 8891,
"size": 20415
} |
{-# OPTIONS --cubical --no-import-sorts #-}
module Number.Consequences where
open import Agda.Primitive renaming (_⊔_ to ℓ-max; lsuc to ℓ-suc; lzero to ℓ-zero)
open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc)
open import Cubical.Foundations.Logic renaming (inr to inrᵖ; inl to inlᵖ)
open import Function.Base using (it; _∋_; _$_)
open import Utils
open import MoreLogic.Definitions
open import MoreLogic.Properties
open import MorePropAlgebra.Definitions
open import MorePropAlgebra.Consequences
open import MorePropAlgebra.Structures
open import MorePropAlgebra.Bundles
open import Number.Definitions
-- import Cubical.HITs.Rationals.SigmaQ as ℚ*
-- import Cubical.Data.Nat.Coprime as Coprime
open import Cubical.HITs.Rationals.QuoQ renaming
( [_] to [_]ᶠ
; [_/_] to [_/_]ᶠ
; _+_ to _+ᶠ_
; -_ to -ᶠ_
; _*_ to _*ᶠ_
; +-assoc to +-assocᶠ
; +-comm to +-commᶠ
; *-assoc to *-assocᶠ
; *-comm to *-commᶠ
)
-- open import Cubical.Data.Nat.Literals public
--
-- instance
-- fromNatℚ : HasFromNat ℚ
-- fromNatℚ = record { Constraint = λ _ → Unit ; fromNat = λ n → [ pos n / 1 ] }
--
-- instance
-- fromNegℚ : HasFromNeg ℚ
-- fromNegℚ = record { Constraint = λ _ → Unit ; fromNeg = λ n → [ neg n / 1 ] }
open import Cubical.HITs.SetQuotients renaming ([_] to [_]ˢ)
-- Define the integers as a HIT by identifying +0 and -0
import Cubical.HITs.Ints.QuoInt
import Cubical.Data.NatPlusOne
open import Cubical.Data.Sum.Base renaming (_⊎_ to infixr 4 _⊎_)
open import Cubical.Data.Sigma renaming (_×_ to infixr 4 _×_)
open import Cubical.Data.Empty renaming (elim to ⊥-elim; ⊥ to ⊥⊥) -- `⊥` and `elim`
open import Cubical.HITs.PropositionalTruncation.Base -- ∣_∣
import Cubical.HITs.PropositionalTruncation.Properties as PTrunc
-- -- Set quotients as a higher inductive type:
-- data _/_ {ℓ ℓ'} (A : Type ℓ) (R : A → A → Type ℓ') : Type (ℓ-max ℓ ℓ') where
-- [_] : (a : A) → A / R
-- eq/ : (a b : A) → (r : R a b) → [ a ] ≡ [ b ]
-- squash/ : (x y : A / R) → (p q : x ≡ y) → p ≡ q
-- {-# DISPLAY [_]' (Cubical.HITs.Ints.QuoInt.signed Agda.Builtin.Bool.Bool.false 1 / Cubical.Data.NatPlusOne.1+ 0 )= 1ᶠ #-}
{-
we have most properties in `Cubical.HITs.Rationals.QuoQ.Properties`
but we can use `Quoℚ≡Sigmaℚ : Quo.ℚ ≡ Sigma.ℚ` from `Cubical.HITs.Rationals.SigmaQ.Properties`
-}
open import Cubical.Data.NatPlusOne
open import Cubical.Data.Sigma
open import Cubical.HITs.Ints.QuoInt hiding (+-identityʳ; *-identityʳ; *-identityˡ; *-distribˡ;*-distribʳ) -- using (ℤ)
renaming (_*_ to _*ᶻ_)
-- there is `elimProp` in `Cubical.HITs.SetQuotients` to define properties
-- elimProp {A = ℤ × ℕ₊₁} {R = _∼_} {B = λ(x : ℚ) → ?} ?
-- e.g. we have
-- _∼_ : ℤ × ℕ₊₁ → ℤ × ℕ₊₁ → Type₀
-- (a , b) ∼ (c , d) = a * ℕ₊₁→ℤ d ≡ c * ℕ₊₁→ℤ b
open import Cubical.Data.Nat as ℕ using (discreteℕ; ℕ; suc; zero) renaming (_+_ to _+ⁿ_; _*_ to _*ⁿ_)
open import Cubical.Data.Nat.Order using () renaming (_<_ to _<ⁿ_; _≤_ to _≤ⁿ_; ≤-suc to ≤ⁿ-suc)
open import Cubical.Data.Nat.Properties using (isSetℕ) renaming (snotz to snotzⁿ; +-suc to +-sucⁿ; inj-+m to inj-+mⁿ; inj-m+ to inj-m+ⁿ; +-zero to +-zeroⁿ; +-comm to +-commⁿ; +-assoc to +-assocⁿ)
_<ⁿᵖ_ : (x y : ℕ) → hProp ℓ-zero
(x <ⁿᵖ y) .fst = x <ⁿ y
(x <ⁿᵖ y) .snd (k₁ , k₁+sx≡y) (k₂ , k₂+sx≡y) = φ where
abstract φ = Σ≡Prop (λ k → isSetℕ _ _) (inj-+mⁿ (k₁+sx≡y ∙ sym k₂+sx≡y))
isProp⊤ : isProp [ ⊤ ]
isProp⊤ tt tt = refl
private
abstract
lemma10 : ∀ n → (n <ⁿ 0) ≡ [ ⊥ ]
lemma10 n = isoToPath (iso (λ{ (k , p) → snotzⁿ (sym (+-sucⁿ k n) ∙ p) }) ⊥-elim (λ b → isProp⊥ _ _) (λ a → isProp[] (n <ⁿᵖ 0) _ _))
-- NOTE: we cannot prove `isProp lemma10` because it seems not even provable that `isProp ([ ⊥ ] ≡ [ ⊥ ])`
-- but we can use propositional truncation
lemma10' : ∀ n → ∥ (n <ⁿ 0) ≡ [ ⊥ ] ∥
lemma10' n = ∣ isoToPath (iso (λ{ (k , p) → snotzⁿ (sym (+-sucⁿ k n) ∙ p) }) ⊥-elim (λ b → isProp⊥ _ _) (λ a → isProp[] (n <ⁿᵖ 0) _ _)) ∣
lemma10'' : ∀ n → (n <ⁿᵖ 0) ≡ ⊥
lemma10'' n = ⇔toPath (transport (lemma10 n)) (transport (sym (lemma10 n)))
abstract
lemma12 : ∀ n → (0 <ⁿ suc n) ≡ [ ⊤ ]
lemma12 n = isoToPath (iso (λ _ → tt) (λ _ → n , +-sucⁿ n 0 ∙ (λ i → suc (+-zeroⁿ n i))) (λ b → isProp⊤ _ _) (λ a → isProp[] (0 <ⁿᵖ suc n) _ _))
lemma12'' : ∀ n → (0 <ⁿᵖ suc n) ≡ ⊤
lemma12'' n = ⇔toPath (transport (lemma12 n)) (transport (sym (lemma12 n)))
abstract
helper : ∀ n → isProp (n <ⁿ 0) ≡ isProp [ ⊥ ]
helper n = λ i → isProp (lemma10 n i)
-- -- the following states that all propositions are equal (which is obviously not the case)
-- isPropΣProp : ∀ {ℓ} → isProp (Σ[ X ∈ Type ℓ ] isProp X)
-- isPropΣProp (A , isPropA) (B , isPropB) = Σ≡Prop (λ X → isPropIsProp) {! Goal: A ≡ B !}
-- isProp' : ∀{ℓ} {A : Type ℓ} → isProp A → A ≡ (A ≡ A)
-- isProp' isPropA = pathToIso (iso ? ? ? ?)
-- https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/
-- no-unicorns :
-- isProp-≡ : ∀{ℓ} {A : Type ℓ} → isProp A → isProp (A ≡ A)
--
-- isProp-≡ : ∀{ℓ} {A : Type ℓ} → isProp A → isProp (A ≡ A)
-- -- ———— Boundary ——————————————————————————————————————————————
-- -- i = i0 ⊢ p j
-- -- i = i1 ⊢ q j
-- -- j = i0 ⊢ A
-- -- j = i1 ⊢ A
-- --
-- -- i j | |
-- -- 0 0 | pj | A
-- -- 0 1 | pj | A
-- -- 1 0 | qj | A
-- -- 1 1 | qj | A
-- -- Σ≡Prop {A = Type ℓ} {B = λ X → isProp X} (λ X → isPropIsProp) {u = (A , isPropA)} {v = (A , isPropA)}
-- -- isProp→isSet (isPropIsProp {A = A})
-- isProp-≡ {ℓ} {A} isPropA p q = isProp→isSet {! Goal : isProp (Type ℓ) !} A A p q
-- isProp-⊥≡⊥ : isProp ([ ⊥ ] ≡ [ ⊥ ])
-- isProp-⊥≡⊥ x y = {! !}
-- abstract
-- -- isProp[] (n <ⁿᵖ 0)
-- isProp-lemma10 : ∀ n → isProp ((n <ⁿ 0) ≡ [ ⊥ ])
-- -- ———— Boundary ——————————————————————————————————————————————
-- -- i = i0 ⊢ p j
-- -- i = i1 ⊢ q j
-- -- j = i0 ⊢ n <ⁿ 0
-- -- j = i1 ⊢ [ ⊥ ]
-- -- (isProp[] (n <ⁿᵖ 0))
-- isProp-lemma10 n p q =
-- let γ : isProp ((n <ⁿ 0) ≡ (n <ⁿ 0))
-- γ x y = {! isProp[] (n <ⁿᵖ 0) ? !}
-- -- transport (helper n) (isProp[] (n <ⁿᵖ 0))
-- in {! !}
_<ᶻ'_ : ℤ → ℤ → Type ℓ-zero
pos n₀ <ᶻ' pos n₁ = [ n₀ <ⁿᵖ n₁ ]
pos n₀ <ᶻ' neg n₁ = [ ⊥ ]
neg zero <ᶻ' pos zero = [ ⊥ ]
neg zero <ᶻ' pos (suc n₁) = [ ⊤ ]
neg (suc n₀) <ᶻ' pos zero = [ ⊤ ]
neg (suc n₀) <ᶻ' pos (suc n₁) = [ ⊤ ]
neg n₀ <ᶻ' neg n₁ = [ n₁ <ⁿᵖ n₀ ]
-- 1D pathes
pos n₀ <ᶻ' posneg j = lemma10 n₀ j
neg zero <ᶻ' posneg j = lemma10 0 (~ j) -- [F1]
neg (suc n₀) <ᶻ' posneg j = lemma12 n₀ (~ j) -- [G1]
posneg i <ᶻ' pos zero = lemma10 0 i -- [F2]
posneg i <ᶻ' pos (suc n₁) = lemma12 n₁ i -- [G2]
posneg i <ᶻ' neg n₁ = lemma10 n₁ (~ i)
-- 2D path
-- note, how `lemma12` does not appear in the final, 2D-case
-- this is, because we explitictly split out [F1] from [G1] and [F2] from [G2]
-- ———— Boundary ——————————————————————————————————————————————
-- i = i0 ⊢ lemma10 0 j [a]
-- i = i1 ⊢ lemma10 0 (~ j) [b]
-- j = i0 ⊢ lemma10 0 i [c]
-- j = i1 ⊢ lemma10 0 (~ i) [d]
--
-- i j | a b c d | a b c d |
-- ----|-----------|---------|---
-- 0 0 | j i | 0 0 | 0
-- 0 1 | j ~i | 1 1 | 1 ⇒ "i xor j" ≡ (i ∨ j) ∧ ~(i ∧ j)
-- 1 0 | ~j i | 1 1 | 1
-- 1 1 | ~j ~i | 0 0 | 0
posneg i <ᶻ' posneg j = lemma10 0 ((i ∨ j) ∧ ~(i ∧ j))
_<ᶻ''_ : ℤ → ℤ → hProp ℓ-zero
pos n₀ <ᶻ'' pos n₁ = n₀ <ⁿᵖ n₁ -- point 1: 1a 3a
pos n₀ <ᶻ'' neg n₁ = ⊥ -- point 2: 1b 4a
neg zero <ᶻ'' pos zero = ⊥ -- point 3: 2a 3b
neg zero <ᶻ'' pos (suc n₁) = ⊤ --
neg (suc n₀) <ᶻ'' pos zero = ⊤ --
neg (suc n₀) <ᶻ'' pos (suc n₁) = ⊤ --
neg n₀ <ᶻ'' neg n₁ = n₁ <ⁿᵖ n₀ -- point 4: 2b 4b
-- 1D pathes
pos n₀ <ᶻ'' posneg j = lemma10'' n₀ j -- face 1: point 1 to 2
neg zero <ᶻ'' posneg j = lemma10'' 0 (~ j) -- [F1] -- face 2: point 3 to 4
neg (suc n₀) <ᶻ'' posneg j = lemma12'' n₀ (~ j) -- [G1]
posneg i <ᶻ'' pos zero = lemma10'' 0 i -- [F2] -- face 3: point 1 to 3
posneg i <ᶻ'' pos (suc n₁) = lemma12'' n₁ i -- [G2]
posneg i <ᶻ'' neg n₁ = lemma10'' n₁ (~ i) -- face 4: point 2 to 4
-- 2D path
-- note, how `lemma12` does not appear in the final, 2D-case
-- this is, because we explitictly split out [F1] from [G1] and [F2] from [G2]
-- ———— Boundary ——————————————————————————————————————————————
-- i = i0 ⊢ lemma10 0 j [a]
-- i = i1 ⊢ lemma10 0 (~ j) [b]
-- j = i0 ⊢ lemma10 0 i [c]
-- j = i1 ⊢ lemma10 0 (~ i) [d]
--
-- i j | a b c d | a b c d |
-- ----|-----------|---------|---
-- 0 0 | j i | 0 0 | 0
-- 0 1 | j ~i | 1 1 | 1 ⇒ "i xor j" ≡ (i ∨ j) ∧ ~(i ∧ j)
-- 1 0 | ~j i | 1 1 | 1
-- 1 1 | ~j ~i | 0 0 | 0
posneg i <ᶻ'' posneg j = lemma10'' 0 ((i ∨ j) ∧ ~(i ∧ j)) -- square 1: face 1 to 2 to 3 to 4
_<ᶻᵖ_ : hPropRel ℤ ℤ ℓ-zero
(x <ᶻᵖ y) .fst = x <ᶻ' y
(x <ᶻᵖ y) .snd = {! !}
_<ᶠ''_ : (ℤ × ℕ₊₁) → (ℤ × ℕ₊₁) → Type₀
(aᶻ , aⁿ⁺¹) <ᶠ'' (bᶻ , bⁿ⁺¹) = {! a * ℕ₊₁→ℤ d <ᶻ' c * ℕ₊₁→ℤ b !}
_<ᶠ'_ : ℚ → ℚ → _
x <ᶠ' y = elimProp2 {A = ℤ × ℕ₊₁} {R = _∼_} {C = C} γ κ x y
where
φ : ℚ → ℚ → hProp ℓ-zero
φ x y = {! ? , ? !}
C : ℚ → ℚ → Type
C x y = [ φ x y ]
γ : (x y : ℚ) → isProp (C x y)
γ x y = {! !}
κ : (a b : ℤ × ℕ₊₁) → C [ a ]ᶠ [ b ]ᶠ
κ a b = {! !}
_<ᶠ_ : hPropRel ℚ ℚ ℓ-zero
x <ᶠ y = {! elimProp2 {A = ℤ × ℕ₊₁} {R = _∼_} {C = C} γ κ x y !}
where
φ : ℚ → ℚ → hProp ℓ-zero
φ x y = {! !}
C : ℚ → ℚ → Type
C x y = [ φ x y ]
γ : (x y : ℚ) → isProp (C x y)
γ x y = {! !}
κ : (a b : ℤ × ℕ₊₁) → C [ a ]ᶠ [ b ]ᶠ
κ a b = {! !}
-- and there is `onCommonDenom` in `Cubical.HITs.Rationals.QuoQ.Properties` to define operations
-- open import Cubical.HITs.Ints.QuoInt.Base renaming
sucⁿ-creates-<ⁿᵖ : ∀ a b → [ a <ⁿᵖ b ⇔ suc a <ⁿᵖ suc b ]
sucⁿ-creates-<ⁿᵖ a b .fst (k , p) = k , (+-sucⁿ k (suc a)) ∙ (λ i → suc (p i))
sucⁿ-creates-<ⁿᵖ a b .snd (k , p) = k , inj-m+ⁿ {1} (sym (+-sucⁿ k (suc a)) ∙ p)
<ⁿᵖ-irrefl : (a : ℕ) → [ ¬ (a <ⁿᵖ a) ]
<ⁿᵖ-trans : (a b x : ℕ) → [ a <ⁿᵖ b ] → [ b <ⁿᵖ x ] → [ a <ⁿᵖ x ]
<ⁿᵖ-cotrans : (a b : ℕ) → [ a <ⁿᵖ b ] → (x : ℕ) → [ (a <ⁿᵖ x) ⊔ (x <ⁿᵖ b) ]
·ⁿ-preserves-<ⁿᵖ : (x y z : ℕ) → [ 0 <ⁿᵖ z ] → [ x <ⁿᵖ y ] → [ (x *ⁿ z) <ⁿᵖ (y *ⁿ z) ]
-- abstract
-- <ⁿᵖ-irrefl zero (k , p) = ψ where abstract ψ = snotzⁿ (sym (+-sucⁿ k 0) ∙ p)
-- NOTE: `<-irreflᶻ'' (posneg i) p` forced this ?9 to be constrained to
-- ?9 (k = (fst x)) (p = (snd x)) = transp (λ i → [ lemma10'' 0 (((i1 ∨ i1) ∧ ~ i1 ∨ ~ i1) ∨ i) ]) i0 x : ⊥⊥
-- which demands an implementation in terms of lemma10''
-- <ⁿᵖ-irrefl zero q@(k , p) = transp (λ i → [ lemma10'' 0 (((i1 ∨ i1) ∧ ~ i1 ∨ ~ i1) ∨ i) ]) i0 q
-- <ⁿᵖ-irrefl zero q@(k , p) = transp (λ i → [ lemma10'' 0 ((i1 ∧ ~ i1) ∨ i) ]) i0 q
<ⁿᵖ-irrefl zero q@(k , p) = transp (λ i → [ lemma10'' 0 i ]) i0 q
<ⁿᵖ-irrefl (suc a) (k , p) = φ where
abstract φ = snotzⁿ (inj-m+ⁿ {a} (+-sucⁿ a k ∙ (λ i → suc (+-commⁿ a k i)) ∙ sym (+-sucⁿ k a) ∙ inj-m+ⁿ {1} (sym (+-sucⁿ k (suc a)) ∙ p) ∙ sym (+-zeroⁿ a)))
<ⁿᵖ-trans a b c = Cubical.Data.Nat.Order.<-trans
-- <ⁿᵖ-trans zero zero zero q₁@(k₁ , p₁) q₂@(k₂ , p₂) = q₁
-- <ⁿᵖ-trans zero zero (suc c) q₁@(k₁ , p₁) q₂@(k₂ , p₂) = q₂
-- <ⁿᵖ-trans zero (suc b) zero q₁@(k₁ , p₁) q₂@(k₂ , p₂) = ⊥-elim {A = λ _ → [ zero <ⁿᵖ zero ]} $ snotzⁿ (sym (+-sucⁿ k₂ (suc b)) ∙ p₂)
-- <ⁿᵖ-trans zero (suc b) (suc c) q₁@(k₁ , p₁) q₂@(k₂ , p₂) = k₂ +ⁿ (k₁ +ⁿ 1) , sym (+-assocⁿ k₂ _ 1) ∙ (λ i → k₂ +ⁿ +-sucⁿ (k₁ +ⁿ 1) 0 i) ∙ (λ i → k₂ +ⁿ suc (+-zeroⁿ (k₁ +ⁿ 1) i)) ∙ (λ i → k₂ +ⁿ suc (p₁ i)) ∙ p₂
-- <ⁿᵖ-trans (suc a) zero zero q₁@(k₁ , p₁) q₂@(k₂ , p₂) = ⊥-elim {A = λ _ → [ suc a <ⁿᵖ zero ]} $ <ⁿᵖ-irrefl zero q₂
-- <ⁿᵖ-trans (suc a) zero (suc c) q₁@(k₁ , p₁) q₂@(k₂ , p₂) = ⊥-elim {A = λ _ → [ suc a <ⁿᵖ suc c ]} $ snotzⁿ (sym (+-sucⁿ k₁ (suc a)) ∙ p₁)
-- <ⁿᵖ-trans (suc a) (suc b) zero q₁@(k₁ , p₁) q₂@(k₂ , p₂) = ⊥-elim {A = λ _ → [ suc a <ⁿᵖ zero ]} $ snotzⁿ (sym (+-sucⁿ k₂ (suc b)) ∙ p₂)
-- <ⁿᵖ-trans (suc a) (suc b) (suc c) q₁@(k₁ , p₁) q₂@(k₂ , p₂) = k₂ +ⁿ (k₁ +ⁿ 1) , (
-- (k₂ +ⁿ (k₁ +ⁿ 1)) +ⁿ suc (suc a) ≡⟨ {! !} ⟩
-- k₂ +ⁿ ((k₁ +ⁿ 1) +ⁿ suc (suc a)) ≡⟨ {! !} ⟩
-- k₂ +ⁿ suc ((k₁ +ⁿ 1) +ⁿ suc a ) ≡⟨ {! !} ⟩
-- k₂ +ⁿ suc ( k₁ +ⁿ (1 +ⁿ suc a)) ≡⟨ {! !} ⟩
-- k₂ +ⁿ suc ( k₁ +ⁿ suc (suc a)) ≡⟨ (λ i → k₂ +ⁿ suc (p₁ i)) ⟩
-- k₂ +ⁿ suc (suc b) ≡⟨ p₂ ⟩
-- suc c ∎)
<ⁿᵖ-cotrans zero zero q c = ⊥-elim {A = λ _ → [ (zero <ⁿᵖ c) ⊔ (c <ⁿᵖ zero) ]} (<ⁿᵖ-irrefl _ q)
<ⁿᵖ-cotrans zero (suc b) q zero = inrᵖ q
<ⁿᵖ-cotrans zero (suc b) q (suc c) = inlᵖ (c , +-commⁿ c 1)
<ⁿᵖ-cotrans (suc a) zero (k , p) c = ⊥-elim {A = λ _ → [ (suc a <ⁿᵖ c) ⊔ (c <ⁿᵖ zero) ]} (snotzⁿ (sym (+-sucⁿ k (suc a)) ∙ p))
<ⁿᵖ-cotrans (suc a) (suc b) q zero = inrᵖ (b , +-commⁿ b 1)
<ⁿᵖ-cotrans (suc a) (suc b) q (suc c) = transport (λ i → [ r i ⊔ s i ]) (<ⁿᵖ-cotrans a b (sucⁿ-creates-<ⁿᵖ a b .snd q) c)
where abstract r : (a <ⁿᵖ c) ≡ (suc a <ⁿᵖ suc c)
s : (c <ⁿᵖ b) ≡ (suc c <ⁿᵖ suc b)
r = ⇔toPath (sucⁿ-creates-<ⁿᵖ a c .fst) (sucⁿ-creates-<ⁿᵖ a c .snd)
s = ⇔toPath (sucⁿ-creates-<ⁿᵖ c b .fst) (sucⁿ-creates-<ⁿᵖ c b .snd)
·ⁿ-preserves-<ⁿᵖ = {! !}
<-irreflᶻ'' : (a : ℤ) → [ ¬ (a <ᶻ'' a) ]
<-transᶻ'' : (a b x : ℤ) → [ a <ᶻ'' b ] → [ b <ᶻ'' x ] → [ a <ᶻ'' x ]
<-cotransᶻ'' : (a b : ℤ) → [ a <ᶻ'' b ] → (x : ℤ) → [ (a <ᶻ'' x) ⊔ (x <ᶻ'' b) ]
-- ·ᶻ-preserves-<ᶻ'' : (x y z : ℤ) → [ 0 <ᶻ'' z ] → [ x <ᶻ'' y ] → [ (x *ᶻ z) <ᶻ'' (y *ᶻ z) ]
-- lemma10'' : ∀ n → (n <ⁿᵖ 0) ≡ ⊥
-- (i ∨ i) ∧ (~ i ∨ ~ i))
-- i0
-- lemma10'' 0 (~ i) = (⊥ ≡ (n <ⁿᵖ 0)) i
-- lemma14 :
<-irreflᶻ'' (pos zero) = <ⁿᵖ-irrefl 0
<-irreflᶻ'' (pos (suc n)) = <ⁿᵖ-irrefl (suc n)
<-irreflᶻ'' (neg zero) = <ⁿᵖ-irrefl 0
<-irreflᶻ'' (neg (suc n)) = <ⁿᵖ-irrefl (suc n)
-- <-irreflᶻ'' (posneg i) p = transport (λ j → [ lemma10'' 0 (((i ∨ i) ∧ (~ i ∨ ~ i)) ∨ j) ]) p
<-irreflᶻ'' (posneg i) p = transport (λ j → [ lemma10'' 0 ((i ∧ ~ i) ∨ j) ]) p
-- <-irreflᶻ'' (posneg i) p =
-- <-irreflᶻ'' (posneg i) p = {! transport (λ j → [ lemma10'' 0 (((i ∨ i) ∧ (~ i ∨ ~ i)) ∨ j) ]) !} where
-- κ : [ lemma10'' 0 i1 ] ≡ {! <ⁿᵖ-irrefl 0 !}
-- κ = {! !}
-- <-irreflᶻ'' (posneg i) p = transport (λ j → [ lemma10'' 0 ((i ∧ ~ i) ∨ j) ]) p
-- <-irreflᶻ'' (posneg i) p = transport (λ j → [ lemma10'' 0 (i₀ ∨ j) ]) p
-- The problem is that when we write ̀with f x | pr`, `with` decides to call `y`
-- the result `f x` and to replace *all* of the occurences of `f x` in the type
-- of `pr` with `y`. That is to say that if we were to write:
-- ...
-- then `with` would abstract `m + n` as `p` on *both* sides of the equality
-- proven by `refl` thus giving us the following goal with an extra, useless,
-- assumption:
-- ...
-- Given that `inspect` has the type `∀ f n → Reveal f · n is (f n)`, when we
-- write `with f n | inspect f n`, the only `f n` that can be abstracted in the
-- type of `inspect f n` is the third argument to `Reveal_·_is_`.
-- That is to say that the auxiliary definition generated looks like this:
--
-- plus-eq-reveal : ∀ m n → Plus-eq m n (m + n)
-- plus-eq-reveal m n = aux m n (m + n) (my-inspect (m +_) n) where
--
-- aux : ∀ m n p → MyReveal (m +_) · n is p → Plus-eq m n p
-- aux m n zero [ m+n≡0 ] = m+n≡0⇒m≡0 m m+n≡0 , m+n≡0⇒n≡0 m m+n≡0
-- aux m n (suc p) [ m+n≡1+p ] = m+n≡1+p
--
-- At the cost of having to unwrap the constructor `[_]` around the equality
-- we care about, we can keep relying on `with` and avoid having to roll out
-- handwritten auxiliary definitions.
record Reveal_·_is_ {a b} {A : Type a} {B : A → Type b}
(f : (x : A) → B x) (x : A) (y : B x) :
Type (ℓ-max a b) where
eta-equality
constructor [_]ⁱ
field eq : f x ≡ y -- lhs stays fix, rhs gets splitted
inspect : ∀{a b} {A : Type a} {B : A → Type b}
(f : (x : A) → B x) (x : A) → Reveal f · x is f x
inspect f x = [ refl ]ⁱ
record Reveal'_·_is_ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'}
(f⁻¹ : B → A)
(y : B) (x : A)
: Type ℓ where
eta-equality
constructor [_]ⁱ'
field eq' : x ≡ f⁻¹ y
inspect' : ∀{ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'}
(f⁻¹ : B → A) (f : A → B) (x : A) → f⁻¹ (f x) ≡ x → Reveal' f⁻¹ · (f x) is x
inspect' f⁻¹ f x p = [ sym p ]ⁱ'
reprℤ : ℤ → Sign × ℕ
reprℤ z = sign z , abs z
reprℤ⁻¹ : Sign × ℕ → ℤ
reprℤ⁻¹ (s , n) = signed s n
reprℤ-id : ∀ z → reprℤ⁻¹ (reprℤ z) ≡ z
reprℤ-id (pos zero ) = refl
reprℤ-id (pos (suc n)) = refl
reprℤ-id (neg zero ) = posneg
reprℤ-id (neg (suc n)) = refl
reprℤ-id (posneg i ) = λ j → posneg (i ∧ j)
inspect-reprℤ : (x : ℤ) → Reveal' reprℤ⁻¹ · (reprℤ x) is x
inspect-reprℤ a = inspect' reprℤ⁻¹ reprℤ a (reprℤ-id a)
_<ᶻ'''_ : ∀(x y : ℤ) → hProp ℓ-zero
x <ᶻ''' y with reprℤ x | reprℤ y | inspect-reprℤ x | inspect-reprℤ y
... | spos , x' | spos , y' | [ x≡ ]ⁱ' | [ y≡ ]ⁱ' = x' <ⁿᵖ y'
... | spos , x' | sneg , y' | [ x≡ ]ⁱ' | [ y≡ ]ⁱ' = ⊥
... | sneg , x' | spos , y' | [ x≡ ]ⁱ' | [ y≡ ]ⁱ' = ⊤
... | sneg , x' | sneg , y' | [ x≡ ]ⁱ' | [ y≡ ]ⁱ' = y' <ⁿᵖ x'
<ᶻ''≡<ᶻ''' : ∀ x y → x <ᶻ'' y ≡ x <ᶻ''' y
<ᶻ''≡<ᶻ''' (pos zero ) (pos zero ) = refl
<ᶻ''≡<ᶻ''' (pos zero ) (pos (suc y)) = refl
<ᶻ''≡<ᶻ''' (pos (suc x)) (pos zero ) = refl
<ᶻ''≡<ᶻ''' (pos (suc x)) (pos (suc y)) = refl
<ᶻ''≡<ᶻ''' (pos zero ) (neg zero ) = sym (lemma10'' _)
<ᶻ''≡<ᶻ''' (pos zero ) (neg (suc y)) = refl
<ᶻ''≡<ᶻ''' (pos (suc x)) (neg zero ) = sym (lemma10'' _)
<ᶻ''≡<ᶻ''' (pos (suc x)) (neg (suc y)) = refl
<ᶻ''≡<ᶻ''' (neg zero ) (pos zero ) = sym (lemma10'' _)
<ᶻ''≡<ᶻ''' (neg zero ) (pos (suc y)) = sym (lemma12'' _)
<ᶻ''≡<ᶻ''' (neg (suc x)) (pos zero ) = refl
<ᶻ''≡<ᶻ''' (neg (suc x)) (pos (suc y)) = refl
<ᶻ''≡<ᶻ''' (neg zero ) (neg zero ) = refl
<ᶻ''≡<ᶻ''' (neg zero ) (neg (suc y)) = lemma10'' _
<ᶻ''≡<ᶻ''' (neg (suc x)) (neg zero ) = lemma12'' _
<ᶻ''≡<ᶻ''' (neg (suc x)) (neg (suc y)) = refl
<ᶻ''≡<ᶻ''' (pos zero ) (posneg i) = λ j → lemma10'' 0 (~ j ∧ i)
<ᶻ''≡<ᶻ''' (pos (suc x)) (posneg i) = λ j → lemma10'' (suc x) (~ j ∧ i)
<ᶻ''≡<ᶻ''' (neg zero ) (posneg i) = λ j → lemma10'' 0 (~ j ∧ ~ i)
<ᶻ''≡<ᶻ''' (neg (suc x)) (posneg i) = λ j → lemma12'' x (j ∨ ~ i)
<ᶻ''≡<ᶻ''' (posneg i) (pos zero ) = λ j → lemma10'' 0 (~ j ∧ i)
<ᶻ''≡<ᶻ''' (posneg i) (pos (suc y)) = λ j → lemma12'' y (~ j ∧ i)
<ᶻ''≡<ᶻ''' (posneg i) (neg zero ) = λ j → lemma10'' 0 (~ j ∧ ~ i)
<ᶻ''≡<ᶻ''' (posneg i) (neg (suc y)) = λ j → lemma10'' (suc y) (j ∨ ~ i)
-- Goal lemma10'' 0 ((i ∨ j) ∧ ~ i ∨ ~ j) ≡ (posneg i <ᶻ''' posneg j)
-- Have (0 <ⁿᵖ 0) ≡ ⊥
-- ———— Boundary ——————————————————————————————————————————————
-- i = i0 ⊢ λ k → lemma10'' 0 (~ k ∧ j)
-- i = i1 ⊢ λ k → lemma10'' 0 (~ k ∧ ~ j)
-- j = i0 ⊢ λ k → lemma10'' 0 (~ k ∧ i)
-- j = i1 ⊢ λ k → lemma10'' 0 (~ k ∧ ~ i)
<ᶻ''≡<ᶻ''' (posneg i) (posneg j ) = λ k → lemma10'' 0 (((i ∨ j) ∧ ~ i ∨ ~ j) ∧ ~ k)
_<ᶻ'''ʳ_ : ∀(x y : Sign × ℕ) → hProp ℓ-zero
-- NOTE: when using this definition, we get `<ᶻ'''≡<ᶻ'''ʳ` proven definitionally
-- but we do not get term normalization as we need it
-- x <ᶻ'''ʳ y = reprℤ⁻¹ x <ᶻ''' reprℤ⁻¹ y
-- and when using this other definition, we get `<ᶻ'''≡'<ᶻ'''ʳ` proven definitionally
(spos , x) <ᶻ'''ʳ (spos , y) = x <ⁿᵖ y -- (pos x) <ᶻ''' (pos y)
(spos , x) <ᶻ'''ʳ (sneg , y) = ⊥ -- (pos x) <ᶻ''' (neg y)
(sneg , x) <ᶻ'''ʳ (spos , y) = ⊤ -- (neg x) <ᶻ''' (pos y)
(sneg , x) <ᶻ'''ʳ (sneg , y) = y <ⁿᵖ x -- (neg x) <ᶻ''' (neg y)
signʳ-≡ : ∀ z → sign z ≡ reprℤ z .fst
signʳ-≡ (signed s zero) = refl
signʳ-≡ (signed s (suc n)) = refl
signʳ-≡ (posneg i) = refl
<ᶻ'''≡<ᶻ'''ʳ : ∀ x y → reprℤ⁻¹ x <ᶻ''' reprℤ⁻¹ y ≡ x <ᶻ'''ʳ y
<ᶻ'''≡<ᶻ'''ʳ x@(sx , nx) y@(sy , ny) with sx | sy | signʳ-≡ (reprℤ⁻¹ x) | signʳ-≡ (reprℤ⁻¹ y)
... | sx' | sy' | px | py = {! !}
-- <ᶻ'''≡<ᶻ'''ʳ (spos , x) (spos , y) = {! refl !}
-- <ᶻ'''≡<ᶻ'''ʳ (spos , x) (sneg , y) = {! refl !}
-- <ᶻ'''≡<ᶻ'''ʳ (sneg , x) (spos , y) = {! refl !}
-- <ᶻ'''≡<ᶻ'''ʳ (sneg , x) (sneg , y) = {! refl !}
<ᶻ'''≡'<ᶻ'''ʳ : ∀ x y → x <ᶻ''' y ≡ reprℤ x <ᶻ'''ʳ reprℤ y
<ᶻ'''≡'<ᶻ'''ʳ x y with reprℤ x | reprℤ y {- | inspect-reprℤ x | inspect-reprℤ y -}
... | spos , x' | spos , y' {- | [ x≡ ]ⁱ' | [ y≡ ]ⁱ' -} = refl
... | spos , x' | sneg , y' {- | [ x≡ ]ⁱ' | [ y≡ ]ⁱ' -} = refl
... | sneg , x' | spos , y' {- | [ x≡ ]ⁱ' | [ y≡ ]ⁱ' -} = refl
... | sneg , x' | sneg , y' {- | [ x≡ ]ⁱ' | [ y≡ ]ⁱ' -} = refl
<ᶻ'''≡''<ᶻ'''ʳ : ∀ x y → reprℤ⁻¹ x <ᶻ''' reprℤ⁻¹ y ≡ x <ᶻ'''ʳ y
<ᶻ'''≡''<ᶻ'''ʳ x@(xs , xn) y@(ys , yn) with reprℤ (reprℤ⁻¹ x) | reprℤ (reprℤ⁻¹ y) | inspect-reprℤ (reprℤ⁻¹ x) | inspect-reprℤ (reprℤ⁻¹ y)
... | spos , x' | spos , y' | [ x≡ ]ⁱ' | [ y≡ ]ⁱ' = {! refl !}
... | spos , x' | sneg , y' | [ x≡ ]ⁱ' | [ y≡ ]ⁱ' = {! refl !}
... | sneg , x' | spos , y' | [ x≡ ]ⁱ' | [ y≡ ]ⁱ' = {! refl !}
... | sneg , x' | sneg , y' | [ x≡ ]ⁱ' | [ y≡ ]ⁱ' = {! refl !}
-- [ reprℤ⁻¹ (spos , a') <ᶻ''' reprℤ⁻¹ (spos , c') ]
-- [ reprℤ a <ᶻ'''ʳ reprℤ c ]
-- [ a <ᶻ''' c ]
-- [ a <ᶻ'' c ]
<ᶻ'''≡'''<ᶻ'''ʳ : ∀ x y → reprℤ⁻¹ x <ᶻ''' reprℤ⁻¹ y ≡ x <ᶻ'''ʳ y
<ᶻ'''≡'''<ᶻ'''ʳ x@(xs , xn) y@(ys , yn) with reprℤ (reprℤ⁻¹ x) | reprℤ (reprℤ⁻¹ y)
... | spos , x' | spos , y' = {! !}
... | spos , x' | sneg , y' = {! !}
... | sneg , x' | spos , y' = {! !}
... | sneg , x' | sneg , y' = {! !}
-- NOTE: making use of trichotomy might be in-line with the definition of QuoInt
-- because this is what we are likely to use at the end
-- -- {! pathTo⇐ (<ᶻ''≡<ᶻ''' a c ∙ (λ i → a≡ i <ᶻ''' c≡ i)) γ !}
-- where γ : [ reprℤ⁻¹ (spos , a') <ᶻ''' reprℤ⁻¹ (spos , c') ]
-- γ = pathTo⇐ (<ᶻ'''≡<ᶻ'''ʳ (spos , a') (spos , c')) {! !}
-- κ : [ reprℤ⁻¹ (spos , a') <ᶻ''' reprℤ⁻¹ (spos , c') ]
-- κ = {! <ᶻ'''≡'<ᶻ'''ʳ a c !}
-- possible cases
-- NOTE: the "trick" is to with-abstract over `reprℤ a` and `reprℤ c`
-- which turns the type of `pathTo⇐ (<ᶻ''≡<ᶻ''' a c ∙ <ᶻ'''≡'<ᶻ'''ʳ a c)`
-- from `[ (reprℤ a <ᶻ'''ʳ reprℤ c) ⇒ (a <ᶻ'' c) ]`
-- into `a' <ⁿ c' → fst (a <ᶻ'' c)`
<-transᶻ'' a b c a<b b<c
with reprℤ a | reprℤ b | reprℤ c
| pathTo⇒ (<ᶻ''≡<ᶻ''' a b ∙ <ᶻ'''≡'<ᶻ'''ʳ a b) a<b
| pathTo⇒ (<ᶻ''≡<ᶻ''' b c ∙ <ᶻ'''≡'<ᶻ'''ʳ b c) b<c
| pathTo⇐ (<ᶻ''≡<ᶻ''' a c ∙ <ᶻ'''≡'<ᶻ'''ʳ a c)
... | spos , a' | spos , b' | spos , c' | a<b' | b<c' | p = p (<ⁿᵖ-trans _ _ _ a<b' b<c')
... | spos , a' | spos , b' | sneg , c' | a<b' | b<c' | p = p b<c'
... | spos , a' | sneg , b' | spos , c' | a<b' | b<c' | p = p (⊥-elim a<b')
... | spos , a' | sneg , b' | sneg , c' | a<b' | b<c' | p = p a<b'
... | sneg , a' | spos , b' | spos , c' | a<b' | b<c' | p = p a<b'
... | sneg , a' | spos , b' | sneg , c' | a<b' | b<c' | p = p (⊥-elim b<c')
... | sneg , a' | sneg , b' | spos , c' | a<b' | b<c' | p = p b<c'
... | sneg , a' | sneg , b' | sneg , c' | a<b' | b<c' | p = p (<ⁿᵖ-trans _ _ _ b<c' a<b')
<-cotransᶻ'' a b a<b c
with reprℤ a | reprℤ b | reprℤ c
| pathTo⇒ (<ᶻ''≡<ᶻ''' a b ∙ <ᶻ'''≡'<ᶻ'''ʳ a b) a<b
| pathTo⇐ (λ i → (<ᶻ''≡<ᶻ''' a c ∙ <ᶻ'''≡'<ᶻ'''ʳ a c) i ⊔ (<ᶻ''≡<ᶻ''' c b ∙ <ᶻ'''≡'<ᶻ'''ʳ c b) i)
... | spos , a' | spos , b' | spos , c' | a<b' | p = p (<ⁿᵖ-cotrans _ _ a<b' c')
... | spos , a' | spos , b' | sneg , c' | a<b' | p = p (inrᵖ tt)
... | sneg , a' | spos , b' | spos , c' | a<b' | p = p (inlᵖ tt)
... | sneg , a' | spos , b' | sneg , c' | a<b' | p = p (inrᵖ tt)
... | sneg , a' | sneg , b' | spos , c' | a<b' | p = p (inlᵖ tt)
... | sneg , a' | sneg , b' | sneg , c' | a<b' | p = p (pathTo⇒ (⊔-comm (b' <ⁿᵖ c') (c' <ⁿᵖ a')) (<ⁿᵖ-cotrans _ _ a<b' c'))
-- [_/_] : ℤ → ℕ₊₁ → ℚ
-- [ a / b ] = [ a , b ]
lemma15 : ∀(a@(an , ad) b@(bn , bd) : ℤ × ℕ₊₁) → a ∼ b → ((sign an , abs an) , ad) ≡ ((sign bn , abs bn) , bd)
lemma15 a@(an , ad) b@(bn , bd) a~b = {! !}
reprℚ : ℚ → (Sign × ℕ) × ℕ₊₁
reprℚ [ n , d ]ᶠ = (sign n , abs n) , d
reprℚ (eq/ a@(an , ad) b@(bn , bd) r i) = lemma15 a b r i
reprℚ (squash/ a b p q i j) = {! !}
reprℚ⁻¹ : (Sign × ℕ) × ℕ₊₁ → ℚ
reprℚ⁻¹ ((s , n) , d) = [ signed s n , d ]ᶠ
lemma15' : ∀(a@(an , ad) b@(bn , bd) : ℤ × ℕ₊₁) → a ∼ b → (an , ad) ≡ (bn , bd)
lemma15' a@(an , ad) b@(bn , bd) a~b = {! !}
import Cubical.HITs.SetQuotients.Properties as SetQuotients
reprℚ' : ℚ → ℤ × ℕ₊₁
reprℚ' [ n , d ]ᶠ = n , d
reprℚ' (eq/ a@(an , ad) b@(bn , bd) r i) = lemma15' a b r i
-- ———— Boundary ——————————————————————————————————————————————
-- i = i0 ⊢ reprℚ' (p j)
-- i = i1 ⊢ reprℚ' (q j)
-- j = i0 ⊢ reprℚ' a
-- j = i1 ⊢ reprℚ' b
-- i : p j ≡ q j
-- j : a ≡ b
--
-- j
-- ∧
-- | p1 = b q1 = b
-- |
-- | p0 = a q0 = a
-- +--------------------> i
--
-- i : p ≡ q
-- reprℚ' (squash/ a b p q i j) = reprℚ' (isSetℚ a b p q i j) -- termination checker complains
-- reprℚ' (squash/ a b p q i j) = {! !} (isSetℚ a b p q i j)
reprℚ' (squash/ a b p q i j) = {! SetQuotients.rec2 !}
-- reprℚ' (squash/ a b p q i j) = {! SetQuotients.elimProp {A = ℤ × ℕ₊₁} {R = _∼_} {B = λ _ → ℤ × ℕ₊₁} !}
-- NOTE: `onCommonDenom` uses `SetQuotient.rec2 isSetℚ`
reprℚ'' : ℚ → ℤ × ℕ₊₁
reprℚ'' q = SetQuotients.elim {A = ℤ × ℕ₊₁} {R = _∼_} {B = λ _ → ℤ × ℕ₊₁} γ (λ x → x) κ q where
γ : (x : (ℤ × ℕ₊₁) // _∼_) → isSet (ℤ × ℕ₊₁)
γ x = {! !} -- this should work out
κ : (a b : ℤ × ℕ₊₁) (r : a ∼ b) → a ≡ b
κ a b a∼b = {! !} -- this is an issue
reprℚ''' : ℚ → ℤ × ℕ₊₁
reprℚ''' q = SetQuotients.rec {A = ℤ × ℕ₊₁} {R = _∼_} {B = ℤ × ℕ₊₁} γ (λ x → x) κ q where
γ : isSet (ℤ × ℕ₊₁)
γ = {! !} -- this should work out
κ : (a b : ℤ × ℕ₊₁) (r : a ∼ b) → a ≡ b
κ (an , ad) (bn , bd) a∼b = {! !} -- this is an issue
-- is seems that `∀ a b → a ∼ b → a ≡ b` is a necessity to perform this representation operation
-- there is no nominator or denominator being "the" nominator or denominator in QuoQ
-- therefore, we won't get a `reprℚ : ℚ → ℤ × ℕ₊₁` for QuoQ (only for SigmaQ where this is just `fst`)
-- but for two (or more) rationals, we can create a common denominator for them
-- we might be able to get `ℚ ≃ Sign × ℚ⁺` with an identification of +0 and -0 similar to QuoInt
-- with onCommonDenom3 we could treat three rational numbers as integers for an implementation of <-transᶠ
-- I guess that we need to show then, something like
-- κ : ∀ a₁ b₁ c₁ a₂ b₂ c₂
-- → a₁ ∼ a₂ → b₁ ∼ b₂ → c₁ ∼ c₂
-- → (a₁<b₁ : a₁ < b₁) → (b₁<c₁ : b₁ < c₁)
-- → (a₂<b₂ : a₂ < b₂) → (b₂<c₂ : b₂ < c₂)
-- → <-trans a₁ b₁ c₁ a₁<b₁ b₁<c₁ ≡ <-trans a₂ b₂ c₂ a₂<b₂ b₂<c₂
-- i.e. that transitivity respects the equivalence
-- this might be shown with "multiplication preserves transitivity" on ℕ
-- κ : ∀ a b c
-- → (n : ℕ₊₁)
-- → (a<b : a < b) → (b<c : b < c)
-- → (an<bn : a · n < b · n) → (bn<cn : b · n < c · n)
-- → <-trans a b c a<b b<c ≡ <-trans (a · n) (b · n) (c · n) an<bn bn<cn
-- in `Cubical.HITs.Rationals.SigmaQ.Base` (which uses `ℤ` for `QuoInt.ℤ`) we have
--
-- ℚ : Type₀
-- ℚ = Σ[ (a , b) ∈ ℤ × ℕ₊₁ ] areCoprime (abs a , ℕ₊₁→ℕ b)
--
-- in `Cubical.HITs.Ints.QuoInt.Base` we have
--
-- data ℤ : Type₀ where
-- signed : (s : Sign) (n : ℕ) → ℤ
-- posneg : signed spos 0 ≡ signed sneg 0
--
-- in `Cubical.Data.NatPlusOne.Base` we have
--
-- record ℕ₊₁ : Type₀ where
-- constructor 1+_
-- field
-- n : ℕ
--
-- and in `Data.Rational.Base` (which uses `ℤ` for `Builtin.Int`) we have
--
-- record ℚ : Set where
-- constructor mkℚ
-- field
-- numerator : ℤ
-- denominator-1 : ℕ
-- .isCoprime : Coprime ∣ numerator ∣ (suc denominator-1)
--
-- in `Agda.Builtin.Int` we have
--
-- data Int : Set where
-- pos : (n : Nat) → Int
-- negsuc : (n : Nat) → Int
--
-- in `Agda.Builtin.Nat` we have
--
-- data Nat : Set where
-- zero : Nat
-- suc : (n : Nat) → Nat
--
-- so the difference between the cubical "SigmaQ"-rationals and the non-cubical "Rational"-rationals is that
-- SigmaQ uses QuoInt and NatPlusOne where Rational uses Builtin.Int and Builtin.Nat
reprℚ⁻¹' : ℤ × ℕ₊₁ → ℚ
reprℚ⁻¹' (n , d) = [ n , d ]ᶠ
-- reprℚ-id : ∀ z → reprℚ⁻¹ (reprℚ z) ≡ z
-- reprℚ-id (pos zero ) = refl
-- reprℚ-id (pos (suc n)) = refl
-- reprℚ-id (neg zero ) = posneg
-- reprℚ-id (neg (suc n)) = refl
-- reprℚ-id (posneg i ) = λ j → posneg (i ∧ j)
--
-- inspect-reprℚ : (x : ℚ) → Reveal' reprℚ⁻¹ · (reprℚ x) is x
-- inspect-reprℚ a = inspect' reprℚ⁻¹ reprℚ a (reprℚ-id a)
-- _<ᶠ_ : hPropRel ℚ ℚ ℓ-zero
-- x <ᶠ y = {! elimProp2 {A = ℤ × ℕ₊₁} {R = _∼_} {C = C} γ κ x y !}
-- where
-- φ : ℚ → ℚ → hProp ℓ-zero
-- φ x y = {! !}
-- C : ℚ → ℚ → Type
-- C x y = [ φ x y ]
-- γ : (x y : ℚ) → isProp (C x y)
-- γ x y = {! !}
-- κ : (a b : ℤ × ℕ₊₁) → C [ a ]ᶠ [ b ]ᶠ
-- κ a b = {! !}
-- ... | spos , snd₁ | fst₂ , snd₂ | fst₃ , snd₃ | [ eq ]ⁱ | [ eq₁ ]ⁱ | [ eq₂ ]ⁱ = {! !}
-- ... | sneg , snd₁ | fst₂ , snd₂ | fst₃ , snd₃ | [ eq ]ⁱ | [ eq₁ ]ⁱ | [ eq₂ ]ⁱ = {! !}
-- <-transᶻ'' (pos zero) (pos zero) (pos zero) a<b b<c = {! !}
-- <-transᶻ'' (pos zero) (pos zero) (pos (suc n₂)) a<b b<c = {! !}
-- <-transᶻ'' (pos zero) (pos (suc n₁)) (pos zero) a<b b<c = {! !}
-- <-transᶻ'' (pos zero) (pos (suc n₁)) (pos (suc n₂)) a<b b<c = {! !}
--
-- <-transᶻ'' (pos (suc n₀)) (pos zero) (pos zero) a<b b<c = {! !}
-- <-transᶻ'' (pos (suc n₀)) (pos zero) (pos (suc n₂)) a<b b<c = {! !}
-- <-transᶻ'' (pos (suc n₀)) (pos (suc n₁)) (pos zero) a<b b<c = {! !}
-- <-transᶻ'' (pos (suc n₀)) (pos (suc n₁)) (pos (suc n₂)) a<b b<c = {! !}
--
-- <-transᶻ'' (neg n₀) (pos n₁) (pos n₂) a<b b<c = {! !}
-- <-transᶻ'' (neg n₀) (neg n₁) (pos n₂) a<b b<c = {! !}
-- <-transᶻ'' (neg n₀) (neg n₁) (neg n₂) a<b b<c = {! !}
--
-- <-transᶻ'' (signed s₀ n₀) (signed s₁ n₁) (posneg i) a<b b<c = {! !}
--
-- <-transᶻ'' (signed s₀ n₀) (posneg i) (signed s₁ n₁) a<b b<c = {! !}
--
-- <-transᶻ'' (signed s₀ n₀) (posneg i) (posneg i₁) a<b b<c = {! !}
--
-- <-transᶻ'' (posneg i) (signed s₁ n₁) (signed s₂ n₂) a<b b<c = {! !}
--
-- <-transᶻ'' (posneg i) (signed s₁ n₁) (posneg i₁) a<b b<c = {! !}
--
-- <-transᶻ'' (posneg i) (posneg i₁) (signed s₂ n₂) a<b b<c = {! !}
--
-- <-transᶻ'' (posneg i) (posneg i₁) (posneg i₂) a<b b<c = {! !}
{-
-- -- 8 points
-- <-transᶻ'' (pos n₀) (pos n₁) (pos zero) a<b b<c = {! <ⁿᵖ-trans !} -- point 1
-- <-transᶻ'' (pos n₀) (pos n₁) (pos (suc n₂)) a<b b<c = {! !}
-- <-transᶻ'' (neg n₀) (pos n₁) (pos zero) a<b b<c = {! !} -- point 2
-- <-transᶻ'' (neg n₀) (pos n₁) (pos (suc n₂)) a<b b<c = {! !}
-- <-transᶻ'' (neg n₀) (neg n₁) (neg zero) a<b b<c = {! !} -- point 3
-- <-transᶻ'' (neg n₀) (neg n₁) (neg (suc n₂)) a<b b<c = {! !}
-- <-transᶻ'' (neg n₀) (neg n₁) (pos zero) a<b b<c = {! !} -- point 4
-- <-transᶻ'' (neg n₀) (neg n₁) (pos (suc n₂)) a<b b<c = {! !}
--
-- -- 12 edges
-- <-transᶻ'' (neg n₀) (pos n₁) (posneg k) a<b b<c = {! !} -- 21 -- point 2
-- <-transᶻ'' (pos n₀) (pos n₁) (posneg k) a<b b<c = {! !} -- 22 -- point 1
-- <-transᶻ'' (neg n₀) (neg n₁) (posneg k) a<b b<c = {! !} -- 23 -- point 3 to 4
-- -- <-transᶻ'' (pos n₀) (neg n₁) (posneg k) a<b b<c = {! !}
-- <-transᶻ'' (pos n₀) (posneg j) (pos n₂) a<b b<c = {! !} -- 24
-- <-transᶻ'' (pos n₀) (posneg j) (neg n₂) a<b b<c = {! !} -- 25
-- <-transᶻ'' (neg n₀) (posneg j) (pos n₂) a<b b<c = {! !} -- 26
-- <-transᶻ'' (neg n₀) (posneg j) (neg n₂) a<b b<c = {! !} -- 27
-- <-transᶻ'' (posneg i) (pos n₁) (pos n₂) a<b b<c = {! !} -- 28
-- <-transᶻ'' (posneg i) (neg n₁) (pos n₂) a<b b<c = {! !} -- 29
-- <-transᶻ'' (posneg i) (neg n₁) (neg n₂) a<b b<c = {! !} -- 30
-- -- <-transᶻ'' (posneg i) (pos n₁) (neg n₂) a<b b<c = {! !}
--
-- -- 6 faces
-- <-transᶻ'' (pos n₀) (posneg j) (posneg k) a<b b<c = {! !} -- 22 24 25
-- <-transᶻ'' (neg n₀) (posneg j) (posneg k) a<b b<c = {! !} -- 21 23 26
-- <-transᶻ'' (posneg i) (pos n₁) (posneg k) a<b b<c = {! !} -- 22 21 28
-- <-transᶻ'' (posneg i) (neg n₁) (posneg k) a<b b<c = {! !} -- 23 29 30
-- <-transᶻ'' (posneg i) (posneg j) (pos n₂) a<b b<c = {! !} -- 24 26 28 29
-- <-transᶻ'' (posneg i) (posneg j) (neg n₂) a<b b<c = {! !} -- 25 27 30
-- (i ∨ k) ∧ ~ i ∨ ~ k
-- (i ∨ k) ∧ (~ i ∨ ~ k)
-- (i ∨ k) ∧ ~(i ∧ k)
-- i k | i ∨ k | i ∧ k | ~(i ∧ k) | (i ∨ k) ∧ ~(i ∧ k)
-- 0 0 | 0 | 0 | 1 | 0
-- 0 1 | 1 | 0 | 1 | 1
-- 1 0 | 1 | 0 | 1 | 1
-- 1 1 | 1 | 1 | 0 | 0
-- ———— Boundary ——————————————————————————————————————————————
-- i = i0 ⊢ ?21 (n₀ = 0) (j = j) (k = k) (a<b = a<b) (b<c = b<c) -- : fst (lemma10'' 0 k)
-- i = i1 ⊢ ?22 (n₀ = 0) (j = j) (k = k) (a<b = a<b) (b<c = b<c) -- : fst (lemma10'' 0 (~ k))
-- j = i0 ⊢ ?23 (i = i) (n₁ = 0) (k = k) (a<b = a<b) (b<c = b<c) -- : fst (lemma10'' 0 ((i ∨ k) ∧ ~ i ∨ ~ k))
-- j = i1 ⊢ ?24 (i = i) (n₁ = 0) (k = k) (a<b = a<b) (b<c = b<c) -- : fst (lemma10'' 0 ((i ∨ k) ∧ ~ i ∨ ~ k))
-- k = i0 ⊢ ?25 (i = i) (j = j) (n₂ = 0) (a<b = a<b) (b<c = b<c) -- : fst (lemma10'' 0 i)
-- k = i1 ⊢ ?26 (i = i) (j = j) (n₂ = 0) (a<b = a<b) (b<c = b<c) -- : fst (lemma10'' 0 (~ i))
-- ———— Constraints ———————————————————————————————————————————
-- ?21 (n₀ = 0) (j = j) (k = k) (a<b = a<b) (b<c = b<c) = ?27 (i = i0) : fst (lemma10'' 0 k)
-- ?22 (n₀ = 0) (j = j) (k = k) (a<b = a<b) (b<c = b<c) = ?27 (i = i1) : fst (lemma10'' 0 (~ k))
-- ?23 (i = i) (n₁ = 0) (k = k) (a<b = a<b) (b<c = b<c) = ?27 (j = i0) : fst (lemma10'' 0 ((i ∨ k) ∧ ~ i ∨ ~ k))
-- ?24 (i = i) (n₁ = 0) (k = k) (a<b = a<b) (b<c = b<c) = ?27 (j = i1) : fst (lemma10'' 0 ((i ∨ k) ∧ ~ i ∨ ~ k))
-- ?25 (i = i) (j = j) (n₂ = 0) (a<b = a<b) (b<c = b<c) = ?27 (k = i0) : fst (lemma10'' 0 i)
-- ?26 (i = i) (j = j) (n₂ = 0) (a<b = a<b) (b<c = b<c) = ?27 (k = i1) : fst (lemma10'' 0 (~ i))
-- Goal [ lemma10'' 0 ((i ∨ k) ∧ ~ i ∨ ~ k) ]
-- ———— Boundary ——————————————————————————————————————————————
-- i = i0 ⊢ ?20 (s₀ = spos) (n₀ = 0) (j = j) (k = k) (a<b = a<b) (b<c = b<c) -- : fst (lemma10'' 0 k)
-- i = i1 ⊢ ?20 (s₀ = sneg) (n₀ = 0) (j = j) (k = k) (a<b = a<b) (b<c = b<c) -- : fst (lemma10'' 0 (~ k))
-- j = i0 ⊢ ?22 (i = i) (s₁ = spos) (n₁ = 0) (k = k) (a<b = a<b) (b<c = b<c) -- : fst (lemma10'' 0 ((i ∨ k) ∧ ~ i ∨ ~ k))
-- j = i1 ⊢ ?22 (i = i) (s₁ = sneg) (n₁ = 0) (k = k) (a<b = a<b) (b<c = b<c) -- : fst (lemma10'' 0 ((i ∨ k) ∧ ~ i ∨ ~ k))
-- k = i0 ⊢ ?23 (i = i) (j = j) (s₂ = spos) (n₂ = 0) (a<b = a<b) (b<c = b<c) -- : fst (lemma10'' 0 i)
-- k = i1 ⊢ ?23 (i = i) (j = j) (s₂ = sneg) (n₂ = 0) (a<b = a<b) (b<c = b<c) -- : fst (lemma10'' 0 (~ i))
-- ———— Constraints ———————————————————————————————————————————
-- ?20 (s₀ = spos) (n₀ = 0) (j = j) (k = k) (a<b = a<b) (b<c = b<c) = ?24 (i = i0) : fst (lemma10'' 0 k)
-- ?20 (s₀ = sneg) (n₀ = 0) (j = j) (k = k) (a<b = a<b) (b<c = b<c) = ?24 (i = i1) : fst (lemma10'' 0 (~ k))
-- ?22 (i = i) (s₁ = spos) (n₁ = 0) (k = k) (a<b = a<b) (b<c = b<c) = ?24 (j = i0) : fst (lemma10'' 0 ((i ∨ k) ∧ ~ i ∨ ~ k))
-- ?22 (i = i) (s₁ = sneg) (n₁ = 0) (k = k) (a<b = a<b) (b<c = b<c) = ?24 (j = i1) : fst (lemma10'' 0 ((i ∨ k) ∧ ~ i ∨ ~ k))
-- ?23 (i = i) (j = j) (s₂ = spos) (n₂ = 0) (a<b = a<b) (b<c = b<c) = ?24 (k = i0) : fst (lemma10'' 0 i)
-- ?23 (i = i) (j = j) (s₂ = sneg) (n₂ = 0) (a<b = a<b) (b<c = b<c) = ?24 (k = i1) : fst (lemma10'' 0 (~ i))
-- 1 cube
<-transᶻ'' (posneg i ) (posneg j ) (posneg k ) a<b b<c = {! !} -- ?24
·ᶻ-preserves-<ᶻ'' = {! !}
-- _*ᶻ_ = Cubical.HITs.Ints.QuoInt._*_
-- signᶻ = Cubical.HITs.Ints.QuoInt.sign
open import Data.Nat.Base using () renaming
( _⊔_ to maxⁿ
; _⊓_ to minⁿ
)
-- NOTE: in `Cubical.HITs.Ints.QuoInt.Base` there is
-- Int→ℤ : Int → ℤ
-- ℤ→Int : ℤ → Int
-- Int≡ℤ : Int ≡ ℤ
open import Cubical.Data.Int using () renaming (pos to ℕ→Int)
ℕ→ℤ : ℕ → ℤ
ℕ→ℤ x = Int→ℤ (ℕ→Int x)
minᶻ : ℤ → ℤ → ℤ
minᶻ x y with sign x | sign y
... | spos | spos = pos (minⁿ (abs x) (abs y))
... | spos | sneg = y
... | sneg | spos = x
... | sneg | sneg = neg (maxⁿ (abs x) (abs y)) -- instead of `- ℕ→ℤ (maxⁿ ...)`
-- maxⁿ' : ℕ → ℕ → ℕ
-- maxⁿ' (zero ) (n ) = n
-- maxⁿ' (suc m) (zero ) = suc m
-- maxⁿ' (suc m) (suc n) = suc (maxⁿ' m n)
--
-- minⁿ' : ℕ → ℕ → ℕ
-- minⁿ' (zero ) (n ) = zero
-- minⁿ' (suc m) (zero ) = zero
-- minⁿ' (suc m) (suc n) = suc (minⁿ' m n)
maxⁿ≡0-right : ∀ n → maxⁿ n 0 ≡ n
maxⁿ≡0-right zero = refl
maxⁿ≡0-right (suc n) = refl
minⁿ≡0-right : ∀ n → minⁿ n 0 ≡ 0
minⁿ≡0-right zero = refl
minⁿ≡0-right (suc n) = refl
lemma : ∀ n → pos 0 ≡ neg (minⁿ n 0)
lemma n = posneg ∙ (λ j → neg (minⁿ≡0-right n (~ j)))
-- lemma n = posneg ∙ (λ j → neg (minⁿ≡0-right n (~ j)))
-- i = i0 ⊢ pos 0
-- i = i1 ⊢ lemma 0 j
-- j = i0 ⊢ pos 0
-- j = i1 ⊢ posneg i
--
-- ———— Constraints ———————————————————————————————————————————
-- posneg i = ?11 (j = i1) : ℤ
-- pos 0 = ?11 (j = i0) : ℤ
-- hcomp (doubleComp-faces (λ _ → pos 0) (λ j₁ → neg zero) j) (posneg j) = ?11 (i = i1) : ℤ
-- pos 0 = ?11 (i = i0) : ℤ
maxᶻ : ℤ → ℤ → ℤ
maxᶻ (pos n₀) (pos n₁) = pos (maxⁿ n₀ n₁)
maxᶻ (pos n₀) (neg n₁) = pos n₀
maxᶻ (neg n₀) (pos n₁) = pos n₁
maxᶻ (neg n₀) (neg n₁) = neg (minⁿ n₀ n₁)
-- pathes
maxᶻ (pos n) (posneg i) = pos (maxⁿ≡0-right n i)
maxᶻ (neg zero) (posneg i) = posneg i -- `lemma zero i` does not work here
-- NOTE: better not use `lemma (suc n) i` because it creates an unnormalizable term:
-- `hcomp (doubleComp-faces (λ _ → pos 0) (λ j₁ → neg 0) j) (posneg j)`
maxᶻ (neg (suc n)) (posneg i) = posneg i -- lemma (suc n) i -- can also use `posneg i` here
maxᶻ (posneg i) (pos n) = pos n
maxᶻ (posneg i) (neg n) = posneg i
maxᶻ (posneg i) (posneg j) = posneg (i ∧ j) -- posneg (i ∧ j)
maxᶻ' : ℤ → ℤ → ℤ
maxᶻ' x y with sign x | sign y
... | spos | spos = pos (maxⁿ (abs x) (abs y))
... | spos | sneg = x
... | sneg | spos = y
... | sneg | sneg = neg (minⁿ (abs x) (abs y))
_ = maxᶻ -1 -1 ≡ -1 ∋ refl
_ = maxᶻ -1 0 ≡ 0 ∋ refl
_ = maxᶻ -1 1 ≡ 1 ∋ refl
_ = maxᶻ 0 -1 ≡ 0 ∋ refl
_ = maxᶻ 0 0 ≡ 0 ∋ refl
_ = maxᶻ 0 1 ≡ 1 ∋ refl
_ = maxᶻ 1 -1 ≡ 1 ∋ refl
_ = maxᶻ 1 0 ≡ 1 ∋ refl
_ = maxᶻ 1 1 ≡ 1 ∋ refl
_ = maxᶻ' -1 -1 ≡ -1 ∋ refl
_ = maxᶻ' -1 0 ≡ 0 ∋ refl
_ = maxᶻ' -1 1 ≡ 1 ∋ refl
_ = maxᶻ' 0 -1 ≡ 0 ∋ refl
_ = maxᶻ' 0 0 ≡ 0 ∋ refl
_ = maxᶻ' 0 1 ≡ 1 ∋ refl
_ = maxᶻ' 1 -1 ≡ 1 ∋ refl
_ = maxᶻ' 1 0 ≡ 1 ∋ refl
_ = maxᶻ' 1 1 ≡ 1 ∋ refl
-- sign' : ℤ → Sign
-- sign' (signed _ zero) = spos
-- sign' (signed s (suc _)) = s
-- sign' (posneg i) = spos
lemma2 : ∀ x y → maxᶻ x y ≡ maxᶻ' x y
lemma2 (pos zero ) (pos zero ) = refl
lemma2 (pos zero ) (pos (suc n₁)) = refl
lemma2 (pos (suc n₀)) (pos zero ) = refl
lemma2 (pos (suc n₀)) (pos (suc n₁)) = refl
lemma2 (pos zero ) (neg zero ) = refl
lemma2 (pos zero ) (neg (suc n₁)) = refl
lemma2 (pos (suc n₀)) (neg zero ) = refl
lemma2 (pos (suc n₀)) (neg (suc n₁)) = refl
lemma2 (neg zero ) (pos zero ) = refl
lemma2 (neg zero ) (pos (suc n₁)) = refl
lemma2 (neg (suc n₀)) (pos zero ) = refl
lemma2 (neg (suc n₀)) (pos (suc n₁)) = refl
lemma2 (neg zero ) (neg zero ) = sym posneg
lemma2 (neg zero ) (neg (suc n₁)) = refl
lemma2 (neg (suc n₀)) (neg zero ) = refl
lemma2 (neg (suc n₀)) (neg (suc n₁)) = refl
lemma2 (pos zero ) (posneg j ) = refl
lemma2 (pos (suc n₀)) (posneg j ) = refl
lemma2 (neg zero ) (posneg j ) = λ i → posneg (j ∧ (~ i))
lemma2 (neg (suc n₀)) (posneg j ) = refl
lemma2 (posneg i ) (pos zero ) = refl
lemma2 (posneg i ) (pos (suc n₁)) = refl
lemma2 (posneg i ) (neg zero ) = λ j → posneg (i ∧ (~ j))
lemma2 (posneg i ) (neg (suc n₁)) = refl
lemma2 (posneg i ) (posneg j ) = λ k → posneg (i ∧ j ∧ (~ k))
lemma3 : maxᶻ ≡ maxᶻ'
lemma3 = funExt₂ᶜ lemma2
-- maxᶻ (signed s₀ n₀) (signed s₁ n₁) = {! !}
-- maxᶻ (signed s₀ n₀) (posneg j) = {! !}
-- maxᶻ (posneg i) (signed s₁ n₁) = {! !}
-- maxᶻ (posneg i) (posneg j) = {! !}
minᶠ : ℚ → ℚ → ℚ
minᶠ x y = onCommonDenom f g h x y where
f : ℤ × ℕ₊₁ → ℤ × ℕ₊₁ → ℤ
f a@(aᶻ , aⁿ) b@(bᶻ , bⁿ) = minᶻ (aᶻ *ᶻ (ℕ₊₁→ℤ bⁿ)) (bᶻ *ᶻ (ℕ₊₁→ℤ aⁿ))
g : (a@(aᶻ , aⁿ) b@(bᶻ , bⁿ) c@(cᶻ , cⁿ) : ℤ × ℕ₊₁)
→ aᶻ *ᶻ (ℕ₊₁→ℤ bⁿ) ≡ bᶻ *ᶻ (ℕ₊₁→ℤ aⁿ)
→ (ℕ₊₁→ℤ bⁿ) *ᶻ (f a c) ≡ (ℕ₊₁→ℤ aⁿ) *ᶻ (f b c)
g a@(aᶻ , aⁿ) b@(bᶻ , bⁿ) c@(cᶻ , cⁿ) aᶻ*bⁿ≡bᶻ*aⁿ = {! !}
h : (a@(aᶻ , aⁿ) b@(bᶻ , bⁿ) c@(cᶻ , cⁿ) : ℤ × ℕ₊₁)
→ bᶻ *ᶻ (ℕ₊₁→ℤ cⁿ) ≡ cᶻ *ᶻ (ℕ₊₁→ℤ bⁿ)
→ (f a b) *ᶻ (ℕ₊₁→ℤ cⁿ) ≡ (f a c) *ᶻ (ℕ₊₁→ℤ bⁿ)
h a@(aᶻ , aⁿ) b@(bᶻ , bⁿ) c@(cᶻ , cⁿ) bᶻ*cⁿ≡cᶻ*bⁿ = {! !}
maxᶠ : ℚ → ℚ → ℚ
maxᶠ x y = {! !}
0ᶠ 1ᶠ : ℚ
0ᶠ = 0
1ᶠ = 1
<-irreflᶠ : (a : ℚ) → [ ¬ (a <ᶠ a) ]
<-transᶠ : (a b x : ℚ) → [ a <ᶠ b ] → [ b <ᶠ x ] → [ a <ᶠ x ]
<-cotransᶠ : (a b : ℚ) → [ a <ᶠ b ] → (x : ℚ) → [ (a <ᶠ x) ⊔ (x <ᶠ b) ]
·ᶠ-inv'' : (x : ℚ) → (∥ Σ[ y ∈ ℚ ] x *ᶠ y ≡ 1ᶠ ∥ → [ x <ᶠ 0ᶠ ] ⊎ [ 0ᶠ <ᶠ x ]) × ([ x <ᶠ 0ᶠ ] ⊎ [ 0ᶠ <ᶠ x ] → ∥ Σ[ y ∈ ℚ ] x *ᶠ y ≡ 1ᶠ ∥)
≤-reflᶠ : (a : ℚ) → [ ¬ (a <ᶠ a) ]
≤-antisymᶠ : (a b : ℚ) → [ ¬ (b <ᶠ a) ] → [ ¬ (a <ᶠ b) ] → [ a ≡ₚ b ]
≤-transᶠ : (a b x : ℚ) → [ ¬ (b <ᶠ a) ] → [ ¬ (x <ᶠ b) ] → [ ¬ (x <ᶠ a) ]
is-minᶠ : (x y z : ℚ) → [ ¬ (minᶠ x y <ᶠ z) ⇔ ¬ (x <ᶠ z) ⊓ ¬ (y <ᶠ z) ]
is-maxᶠ : (x y z : ℚ) → [ ¬ (z <ᶠ maxᶠ x y) ⇔ ¬ (z <ᶠ x) ⊓ ¬ (z <ᶠ y) ]
+ᶠ-<ᶠ-ext : (w x y z : ℚ) → [ (w +ᶠ x) <ᶠ (y +ᶠ z) ] → [ (w <ᶠ y) ⊔ (x <ᶠ z) ]
·ᶠ-preserves-<ᶠ : (x y z : ℚ) → [ 0ᶠ <ᶠ z ] → [ x <ᶠ y ] → [ (x *ᶠ z) <ᶠ (y *ᶠ z) ]
<-irreflᶠ = {! !}
<-transᶠ = {! !}
<-cotransᶠ = {! !}
·ᶠ-inv'' = {! !}
≤-reflᶠ = {! !}
≤-antisymᶠ = {! !}
≤-transᶠ = {! !}
is-minᶠ = {! !}
is-maxᶠ = {! !}
+ᶠ-<ᶠ-ext = {! !}
·ᶠ-preserves-<ᶠ = {! !}
open PartiallyOrderedField
ℚF : PartiallyOrderedField {ℓ-zero} {ℓ-zero}
ℚF .PartiallyOrderedField.Carrier = ℚ
ℚF .PartiallyOrderedField.0f = 0 -- [ signed spos 0 , (1+ 0) ]'
ℚF .PartiallyOrderedField.1f = 1
ℚF .PartiallyOrderedField._+_ = _+ᶠ_
ℚF .PartiallyOrderedField.-_ = -ᶠ_
ℚF .PartiallyOrderedField._·_ = _*ᶠ_
ℚF .PartiallyOrderedField.min = minᶠ
ℚF .PartiallyOrderedField.max = maxᶠ
ℚF .PartiallyOrderedField._<_ = _<ᶠ_
ℚF .PartiallyOrderedField.is-PartiallyOrderedField = record
{ is-AlmostPartiallyOrderedField = record
{ is-set = isSetℚ
; is-CommRing = record
{ is-set = isSetℚ
; is-Ring = record
{ is-set = isSetℚ
; +-AbGroup = record
{ is-set = isSetℚ
; is-Group = record
{ is-set = isSetℚ
; is-Monoid = record
{ is-set = isSetℚ
; is-Semigroup = record
{ is-set = isSetℚ
; is-assoc = +-assocᶠ
}
; is-identity = λ x → +-identityʳ x , +-identityˡ x
}
; is-inverse = λ x → (+-inverseʳ x) , (+-inverseˡ x)
}
; is-comm = +-commᶠ
}
; ·-Monoid = record
{ is-set = isSetℚ
; is-Semigroup = record
{ is-set = isSetℚ
; is-assoc = *-assocᶠ
}
; is-identity = λ x → *-identityʳ x , *-identityˡ x
}
; is-dist = λ x y z → sym (*-distribˡ x y z) , sym (*-distribʳ x y z)
}
; ·-comm = *-commᶠ
}
; <-StrictPartialOrder = record
{ is-irrefl = <-irreflᶠ
; is-trans = <-transᶠ
; is-cotrans = <-cotransᶠ
}
; ·-inv'' = ·ᶠ-inv''
; ≤-isLattice = record
{ ≤-PartialOrder = record
{ is-refl = ≤-reflᶠ
; is-antisym = ≤-antisymᶠ
; is-trans = ≤-transᶠ
}
; is-min = is-minᶠ
; is-max = is-maxᶠ
}
}
; +-<-ext = +ᶠ-<ᶠ-ext
; ·-preserves-< = ·ᶠ-preserves-<ᶠ
}
where open PartiallyOrderedField ℚF renaming (Carrier to ℚ')
-- 4.3 Archimedean property
--
-- We now define the notion of Archimedean ordered fields. We phrase this in terms of a certain
-- interpolation property, that can be defined from the fact that there is a unique morphism of
-- ordered fields from the rationals to every ordered field.
-- Lemma 4.3.3. For every ordered field (F, 0 F , 1 F , + F , · F , min F , max F , < F ), there is a unique morphism
-- i of ordered fields from the rationals to F . Additionally, i preserves < in the sense that for every q, r : Q
-- q < r ⇒ i (q) < F i (r ).
-- ∃! : ∀ {ℓ ℓ'} (A : Type ℓ) (B : A → Type ℓ') → Type (ℓ-max ℓ ℓ')
-- ∃! A B = isContr (Σ A B)
-- isContr' A = Σ[ x ∈ A ] (∀ y → x ≡ y)
-- ℚ-IsInitialObject : ∀(OF : OrderedField {ℓ} {ℓ'}) → isContr (OrderedFieldMor ℚOF OF)
-- ℚ-IsInitialObject OF = {!!} , {!!}
-- Definition 4.3.5. Let (F, 0 F , 1 F , + F , · F , min F , max F , < F ) be an ordered field, so that we get a
-- canonical morphism i : Q → F of ordered fields, as in Lemma 4.3.3. We say the ordered field
-- (F, 0 F , 1 F , + F , · F , min F , max F , < F ) is Archimedean if
-- (∀x, y : F )(∃q : Q)x < i (q) < y.
-- IsArchimedian : OrderedField {ℓ} {ℓ'} → Type (ℓ-max ℓ ℓ')
-- IsArchimedian OF = let (orderedfieldmor i _) = fst (ℚ-IsInitialObject OF)
-- open OrderedField OF
-- ℚ = OrderedField.Carrier ℚOF
-- in ∀ x y → ∃[ q ∈ ℚ ] (x < i q) × (i q < y)
-- If the ordered field is clear from the context, we will identify rationals q : Q with their in-
-- clusion i (q) in the ordered field, so that we may also say that (F, 0 F , 1 F , + F , · F , min F , max F , < F )
-- is Archimedean if
-- (∀x, y : F )(∃q : Q)x < q < y.
-- Example 4.3.6. In an Archimedean ordered field, all numbers are bounded by rationals. That
-- is, for a given x : F , there exist q, r : Q with q < x < r .
-- Example-4-3-6 : (OF : OrderedField {ℓ} {ℓ'})
-- → IsArchimedian OF
-- → let open OrderedField OF renaming (Carrier to F)
-- (orderedfieldmor i _) = fst (ℚ-IsInitialObject OF)
-- ℚ = OrderedField.Carrier ℚOF
-- in ∀(x : F) → (∃[ q ∈ ℚ ] i q < x) × (∃[ r ∈ ℚ ] x < i r)
-- -- This follows from applying the Archimedean property to x − 1 < x and x < x + 1.
-- Example-4-3-6 OF isArchimedian = {!!}
-- 4.4 Cauchy completeness of real numbers
--
-- We focus on Cauchy completeness, rather than Dedekind or Dedekind-MacNeille completeness,
-- as we will focus on the computation of digit expansions, for which Cauchy completeness suffices.
-- In order to state that an ordered field is Cauchy complete, we need to define when sequences
-- are Cauchy, and when a sequence has a limit. We also take the opportunity to define
-- the set of Cauchy reals in Definition 4.4.9. Surprisingly, this ordered field cannot be shown to
-- be Cauchy complete.
-- Fix an ordered field (F, 0 F , 1 F , + F , · F , min F , max F , < F ).
module _ {ℓ ℓ'} (OF : PartiallyOrderedField {ℓ} {ℓ'}) where
open PartiallyOrderedField OF renaming (Carrier to F)
-- module ℚ = PartiallyOrderedField ℚ
{-
open PartiallyOrderedField ℚOF using () renaming (_<_ to _<ᵣ_; 0f to 0ᵣ)
ℚ = PartiallyOrderedField.Carrier ℚOF
iᵣ = PartiallyOrderedFieldMor.fun (fst (ℚ-IsInitialObject OF))
open import Data.Nat.Base using (ℕ) renaming (_≤_ to _≤ₙ_)
-- We get a notion of distance, given by the absolute value as
-- |x − y| := max F (x − y, −(x − y)).
distance : ∀(x y : F) → F
distance x y = max (x - y) (- (x - y))
-- Consider a sequence x : N → F of elements of F . Classically, we may state that x is Cauchy as
-- (∀ε : Q + )(∃N : N)(∀m, n : N)m, n ≥ N ⇒ |x m − x n | < ε,
IsCauchy : (x : ℕ → F) → Type (ℓ-max ℓ' ℚℓ)
IsCauchy x = ∀(ε : ℚ) → 0ᵣ <ᵣ ε → ∃[ N ∈ ℕ ] ∀(m n : ℕ) → N ≤ₙ m → N ≤ₙ n → distance (x m) (x n) < iᵣ ε
-- We can interpret the quantifiers as in Definition 2.4.5.
-- NOTE: this is the case, since `∃ A B = ∥ Σ A B ∥`
-- Following a propositions-as-types interpretation, we may also state that x is Cauchy as the
-- structure
-- (Πε : Q + )(ΣN : N)(Πm, n : N)m, n ≥ N → |x m − x n | < ε.
-- The dependent sum represents a choice of index N for every error ε, and so we have arrived at the following definition.
-- Definition 4.4.1.
-- For a sequence of reals x : N → F , a a modulus of Cauchy convergence is a map M : Q + → N such that
-- (∀ε : Q + )(∀m, n : N)m, n ≥ M (ε) ⇒ |x m − x n | < ε.
-- NOTE: do we already call these x "reals" ?
-- NOTE: we are using the Modulus-type `((y : ℚ) → {{0ᵣ <ᵣ y}} → ℕ)` a few times and might abbreviate it
IsModulusOfCauchyConvergence : (x : ℕ → F) → (M : ((y : ℚ) → {{0ᵣ <ᵣ y}} → ℕ)) → Type (ℓ-max ℓ' ℚℓ)
IsModulusOfCauchyConvergence x M = ∀(ε : ℚ) → (p : 0ᵣ <ᵣ ε) → ∀(m n : ℕ)
→ let instance _ = p
in M ε ≤ₙ m → M ε ≤ₙ n → distance (x m) (x n) < iᵣ ε
-- In constructive mathematics, we typically use such sequences with modulus, for example,
-- because they can sometimes be used to compute limits of Cauchy sequences, avoiding choice axioms.
-- Definition 4.4.2.
-- A number l : F is the limit of a sequence x : N → F if the sequence
-- converges to l in the usual sense:
-- (∀ε : Q + )(∃N : N)(∀n : N)n ≥ N ⇒ |x n − l | < ε.
IsLimit : (x : ℕ → F) → (l : F) → Type (ℓ-max ℓ' ℚℓ)
IsLimit x l = ∀(ε : ℚ) → (0ᵣ <ᵣ ε) → ∃[ N ∈ ℕ ] ∀(n : ℕ) → N ≤ₙ n → distance (x n) l < iᵣ ε
-- Remark 4.4.3. We do not consider the statement of convergence in propositions-as-types
--
-- (Πε : Q + )(ΣN : N)(Πn : N)n ≥ N → |x n − l | < ε,
--
-- because if the sequence has a modulus of Cauchy convergence M, then λε.M (ε/2) is a
-- modulus of convergence to the limit l, so that we get an element of the above type.
-- Definition 4.4.4.
-- The ordered field (F, 0 F , 1 F , + F , · F , min F , max F , < F ) is said to be Cauchy complete
-- if for every sequence x with modulus of Cauchy convergence M, we have a limit of x.
-- In other words, an ordered field is Cauchy complete iff from a sequence–modulus pair (x, M), we can compute a limit of x.
IsCauchyComplete : Type (ℓ-max (ℓ-max ℓ ℓ') ℚℓ)
IsCauchyComplete = (x : ℕ → F)
→ (M : ((y : ℚ) → {{0ᵣ <ᵣ y}} → ℕ))
→ IsModulusOfCauchyConvergence x M
→ Σ[ l ∈ F ] IsLimit x l
-- For the remainder of this section, additionally assume that F is Archimedean.
module _ (isArchimedian : IsArchimedian OF) where
-- Lemma 4.4.5.
-- The type of limits of a fixed sequence x : N → F is a proposition.
Lemma-4-4-5 : ∀(x : ℕ → F) → isProp (Σ[ l ∈ F ] IsLimit x l)
-- Proof. This can be shown using the usual proof that limits are unique in Archimedean ordered fields, followed by an application of Lemma 2.6.20.
Lemma-4-4-5 x = {!!}
-- Corollary 4.4.6.
-- Fix a given sequence x : N → F . Suppose that we know that there exists a
-- limit of the sequence. Then we can compute a limit of the sequence.
Corollary-4-4-6 : ∀(x : ℕ → F) → (∃[ l ∈ F ] IsLimit x l) → Σ[ l ∈ F ] IsLimit x l
-- Proof. By applying the induction principle of propositional truncations of Definition 2.4.3.
Corollary-4-4-6 x p = {!!} , {!!}
-- Corollary 4.4.7.
-- Fix a given sequence x : N → F . Suppose that, from a modulus of Cauchy
-- convergence, we can compute a limit of the sequence. Then from the existence of the modulus of
-- Cauchy convergence we can compute a limit of the sequence.
Corollary-4-4-7 : (x : ℕ → F)
→ ( (M : ((y : ℚ) → {{0ᵣ <ᵣ y}} → ℕ))
→ (isMCC : IsModulusOfCauchyConvergence x M)
→ Σ[ l ∈ F ] IsLimit x l
)
-----------------------------------------------------------------------
→ ∃[ M ∈ ((y : ℚ) → {{0ᵣ <ᵣ y}} → ℕ) ] IsModulusOfCauchyConvergence x M
→ Σ[ l ∈ F ] IsLimit x l
-- Proof. By applying the induction principle of propositional truncations of Definition 2.4.3.
Corollary-4-4-7 x f p = {!!}
-- We can thus compute the limit of x : N → F as the number lim(x, p), where p is a proof
-- that the limit of x exists. We will rather use the more traditional notation lim n→∞ x n for this
-- number.
-- Example 4.4.8 (Exponential function).
-- In a Cauchy complete Archimedean ordered field, we can define an exponential function exp : F → F by
--
-- exp(x) = Σ_{k=0}^{∞} (xᵏ) / (k!)
--
-- For a given input x, we obtain the existence of a modulus of Cauchy convergence for the output from boundedness of
-- x, that is, from the fact that (∃q, r : Q) q < x < r .
exp : F → F
exp x = {!!}
Example-4-4-8 : ∀(x : F) → ∃[ M ∈ ((y : ℚ) → {{0ᵣ <ᵣ y}} → ℕ) ] IsModulusOfCauchyConvergence {!!} M
Example-4-4-8 x with Example-4-3-6 OF isArchimedian x
... | q' , r' = let q : ∃[ q ∈ ℚ ] iᵣ q < x
q = q'
r : ∃[ r ∈ ℚ ] x < iᵣ r
r = r'
in {!!}
-- The point of this work is that, because we have a single language for properties and struc-
-- ture, we can see more precisely what is needed for certain computations. In the above example,
-- we explicitly do not require that inputs come equipped with a modulus of Cauchy convergence,
-- but rather that there exists such a modulus. On the one hand, we do need a modulus to obtain
-- the limit, but as the limit value is independent of the chosen modulus, existence of such a
-- modulus suffices.
-}
-}
| {
"alphanum_fraction": 0.4771779619,
"avg_line_length": 43.1342925659,
"ext": "agda",
"hexsha": "d6377335b961517cdee89c6951a94ec0ffcf443e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mchristianl/synthetic-reals",
"max_forks_repo_path": "agda/Number/Consequences.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mchristianl/synthetic-reals",
"max_issues_repo_path": "agda/Number/Consequences.agda",
"max_line_length": 215,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mchristianl/synthetic-reals",
"max_stars_repo_path": "agda/Number/Consequences.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-19T12:15:21.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-31T18:15:26.000Z",
"num_tokens": 25426,
"size": 53961
} |
module Prelude.Ord where
open import Agda.Primitive
open import Prelude.Equality
open import Prelude.Decidable
open import Prelude.Bool
open import Prelude.Function
open import Prelude.Empty
data Comparison {a} {A : Set a} (_<_ : A → A → Set a) (x y : A) : Set a where
less : (lt : x < y) → Comparison _<_ x y
equal : (eq : x ≡ y) → Comparison _<_ x y
greater : (gt : y < x) → Comparison _<_ x y
isLess : ∀ {a} {A : Set a} {R : A → A → Set a} {x y} → Comparison R x y → Bool
isLess (less _) = true
isLess (equal _) = false
isLess (greater _) = false
{-# INLINE isLess #-}
isGreater : ∀ {a} {A : Set a} {R : A → A → Set a} {x y} → Comparison R x y → Bool
isGreater (less _) = false
isGreater (equal _) = false
isGreater (greater _) = true
{-# INLINE isGreater #-}
data LessEq {a} {A : Set a} (_<_ : A → A → Set a) (x y : A) : Set a where
instance
less : x < y → LessEq _<_ x y
equal : x ≡ y → LessEq _<_ x y
record Ord {a} (A : Set a) : Set (lsuc a) where
infix 4 _<_ _≤_
field
_<_ : A → A → Set a
_≤_ : A → A → Set a
compare : ∀ x y → Comparison _<_ x y
eq-to-leq : ∀ {x y} → x ≡ y → x ≤ y
lt-to-leq : ∀ {x y} → x < y → x ≤ y
leq-to-lteq : ∀ {x y} → x ≤ y → LessEq _<_ x y
open Ord {{...}} public
{-# DISPLAY Ord._<_ _ a b = a < b #-}
{-# DISPLAY Ord._≤_ _ a b = a ≤ b #-}
{-# DISPLAY Ord.compare _ a b = compare a b #-}
{-# DISPLAY Ord.eq-to-leq _ eq = eq-to-leq eq #-}
{-# DISPLAY Ord.lt-to-leq _ eq = lt-to-leq eq #-}
{-# DISPLAY Ord.leq-to-lteq _ eq = leq-to-lteq eq #-}
module _ {a} {A : Set a} {{_ : Ord A}} where
_>_ : A → A → Set a
a > b = b < a
_≥_ : A → A → Set a
a ≥ b = b ≤ a
infix 4 _>_ _≥_ _<?_ _≤?_ _>?_ _≥?_
_<?_ : A → A → Bool
x <? y = isLess (compare x y)
_>?_ : A → A → Bool
_>?_ = flip _<?_
_≤?_ : A → A → Bool
x ≤? y = not (y <? x)
_≥?_ : A → A → Bool
x ≥? y = not (x <? y)
min : A → A → A
min x y = if x <? y then x else y
max : A → A → A
max x y = if x >? y then x else y
{-# INLINE _>?_ #-}
{-# INLINE _<?_ #-}
{-# INLINE _≤?_ #-}
{-# INLINE _≥?_ #-}
{-# INLINE min #-}
{-# INLINE max #-}
--- Instances ---
-- Default implementation of _≤_ --
defaultOrd : ∀ {a} {A : Set a} {_<_ : A → A → Set a} → (∀ x y → Comparison _<_ x y) → Ord A
Ord._<_ (defaultOrd compare) = _
Ord._≤_ (defaultOrd {_<_ = _<_} compare) = LessEq _<_
Ord.compare (defaultOrd compare) = compare
Ord.eq-to-leq (defaultOrd compare) = equal
Ord.lt-to-leq (defaultOrd compare) = less
Ord.leq-to-lteq (defaultOrd compare) = id
-- Generic instance by injection --
module _ {a b} {A : Set a} {B : Set b} {S : A → A → Set a} {T : B → B → Set b} where
mapComparison : {f : A → B} →
(∀ {x y} → S x y → T (f x) (f y)) →
∀ {x y} → Comparison S x y → Comparison T (f x) (f y)
mapComparison f (less lt) = less (f lt)
mapComparison f (equal refl) = equal refl
mapComparison f (greater gt) = greater (f gt)
injectComparison : {f : B → A} → (∀ {x y} → f x ≡ f y → x ≡ y) →
(∀ {x y} → S (f x) (f y) → T x y) →
∀ {x y} → Comparison S (f x) (f y) → Comparison T x y
injectComparison _ g (less p) = less (g p)
injectComparison inj g (equal p) = equal (inj p)
injectComparison _ g (greater p) = greater (g p)
flipComparison : ∀ {a} {A : Set a} {S : A → A → Set a} {x y} →
Comparison S x y → Comparison (flip S) x y
flipComparison (less lt) = greater lt
flipComparison (equal eq) = equal eq
flipComparison (greater gt) = less gt
OrdBy : ∀ {a} {A B : Set a} {{OrdA : Ord A}} {f : B → A} →
(∀ {x y} → f x ≡ f y → x ≡ y) → Ord B
OrdBy {f = f} inj = defaultOrd λ x y → injectComparison inj id (compare (f x) (f y))
{-# INLINE OrdBy #-}
{-# INLINE defaultOrd #-}
{-# INLINE injectComparison #-}
-- Bool --
data LessBool : Bool → Bool → Set where
false<true : LessBool false true
private
compareBool : ∀ x y → Comparison LessBool x y
compareBool false false = equal refl
compareBool false true = less false<true
compareBool true false = greater false<true
compareBool true true = equal refl
instance
OrdBool : Ord Bool
OrdBool = defaultOrd compareBool
--- Ord with proofs ---
record Ord/Laws {a} (A : Set a) : Set (lsuc a) where
field
overlap {{super}} : Ord A
less-antirefl : {x : A} → x < x → ⊥
less-trans : {x y z : A} → x < y → y < z → x < z
open Ord/Laws {{...}} public hiding (super)
module _ {a} {A : Set a} {{OrdA : Ord/Laws A}} where
less-antisym : {x y : A} → x < y → y < x → ⊥
less-antisym lt lt₁ = less-antirefl {A = A} (less-trans {A = A} lt lt₁)
leq-antisym : {x y : A} → x ≤ y → y ≤ x → x ≡ y
leq-antisym x≤y y≤x with leq-to-lteq {A = A} x≤y | leq-to-lteq {A = A} y≤x
... | _ | equal refl = refl
... | less x<y | less y<x = ⊥-elim (less-antisym x<y y<x)
... | equal refl | less _ = refl
leq-trans : {x y z : A} → x ≤ y → y ≤ z → x ≤ z
leq-trans x≤y y≤z with leq-to-lteq {A = A} x≤y | leq-to-lteq {A = A} y≤z
... | equal refl | _ = y≤z
... | _ | equal refl = x≤y
... | less x<y | less y<z = lt-to-leq {A = A} (less-trans {A = A} x<y y<z)
leq-less-antisym : {x y : A} → x ≤ y → y < x → ⊥
leq-less-antisym {x = x} {y} x≤y y<x =
case leq-antisym x≤y (lt-to-leq {A = A} y<x) of λ where
refl → less-antirefl {A = A} y<x
OrdLawsBy : ∀ {a} {A B : Set a} {{OrdA : Ord/Laws A}} {f : B → A} →
(∀ {x y} → f x ≡ f y → x ≡ y) → Ord/Laws B
Ord/Laws.super (OrdLawsBy inj) = OrdBy inj
less-antirefl {{OrdLawsBy {A = A} _}} = less-antirefl {A = A}
less-trans {{OrdLawsBy {A = A} _}} = less-trans {A = A}
instance
OrdLawsBool : Ord/Laws Bool
Ord/Laws.super OrdLawsBool = it
less-antirefl {{OrdLawsBool}} ()
less-trans {{OrdLawsBool}} false<true ()
| {
"alphanum_fraction": 0.5297709924,
"avg_line_length": 30.8638743455,
"ext": "agda",
"hexsha": "804006452e9246b15665679935a53149b91540de",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "lclem/agda-prelude",
"max_forks_repo_path": "src/Prelude/Ord.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "lclem/agda-prelude",
"max_issues_repo_path": "src/Prelude/Ord.agda",
"max_line_length": 91,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "lclem/agda-prelude",
"max_stars_repo_path": "src/Prelude/Ord.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2239,
"size": 5895
} |
-- Intuitionistic propositional calculus.
-- Translation between different formalisations of syntax.
module IPC.Syntax.Translation where
open import IPC.Syntax.Common public
import IPC.Syntax.ClosedHilbertSequential as CHS
import IPC.Syntax.ClosedHilbert as CH
import IPC.Syntax.HilbertSequential as HS
import IPC.Syntax.Hilbert as H
import IPC.Syntax.Gentzen as G
open HS using () renaming (_⊦⊢_ to HS⟨_⊦⊢_⟩ ; _⊢_ to HS⟨_⊢_⟩) public
open H using () renaming (_⊢_ to H⟨_⊢_⟩) public
open G using () renaming (_⊢_ to G⟨_⊢_⟩) public
-- Available translations.
--
-- ┌─────┬─────┬─────┬─────┬─────┐
-- │ CHS │ CH │ HS │ H │ G │
-- ┌─────┼─────┼─────┼─────┼─────┼─────┤
-- │ CHS │ │ d │ d │ ∘ │ ∘ │
-- ├─────┼─────┼─────┼─────┼─────┼─────┤
-- │ CH │ d │ │ ∘ │ d │ ∘ │
-- ├─────┼─────┼─────┼─────┼─────┼─────┤
-- │ HS │ d │ ∘ │ │ d │ ∘ │
-- ├─────┼─────┼─────┼─────┼─────┼─────┤
-- │ H │ ∘ │ d │ d │ │ d │
-- ├─────┼─────┼─────┼─────┼─────┼─────┤
-- │ G │ ∘ │ ∘ │ ∘ │ d │ │
-- └─────┴─────┴─────┴─────┴─────┴─────┘
--
-- d : Direct translation.
-- ∘ : Composition of translations.
-- Translation from closed Hilbert-style sequential to closed Hilbert-style.
chs→ch : ∀ {A} → CHS.⊢ A → CH.⊢ A
chs→ch (Ξ , ts) = chs⊦→ch ts top
where
chs⊦→ch : ∀ {A Ξ} → CHS.⊦⊢ Ξ → A ∈ Ξ → CH.⊢ A
chs⊦→ch (CHS.mp i j ts) top = CH.app (chs⊦→ch ts i) (chs⊦→ch ts j)
chs⊦→ch (CHS.ci ts) top = CH.ci
chs⊦→ch (CHS.ck ts) top = CH.ck
chs⊦→ch (CHS.cs ts) top = CH.cs
chs⊦→ch (CHS.cpair ts) top = CH.cpair
chs⊦→ch (CHS.cfst ts) top = CH.cfst
chs⊦→ch (CHS.csnd ts) top = CH.csnd
chs⊦→ch (CHS.unit ts) top = CH.unit
chs⊦→ch (CHS.cboom ts) top = CH.cboom
chs⊦→ch (CHS.cinl ts) top = CH.cinl
chs⊦→ch (CHS.cinr ts) top = CH.cinr
chs⊦→ch (CHS.ccase ts) top = CH.ccase
chs⊦→ch (CHS.mp i j ts) (pop k) = chs⊦→ch ts k
chs⊦→ch (CHS.ci ts) (pop k) = chs⊦→ch ts k
chs⊦→ch (CHS.ck ts) (pop k) = chs⊦→ch ts k
chs⊦→ch (CHS.cs ts) (pop k) = chs⊦→ch ts k
chs⊦→ch (CHS.cpair ts) (pop k) = chs⊦→ch ts k
chs⊦→ch (CHS.cfst ts) (pop k) = chs⊦→ch ts k
chs⊦→ch (CHS.csnd ts) (pop k) = chs⊦→ch ts k
chs⊦→ch (CHS.unit ts) (pop k) = chs⊦→ch ts k
chs⊦→ch (CHS.cboom ts) (pop k) = chs⊦→ch ts k
chs⊦→ch (CHS.cinl ts) (pop k) = chs⊦→ch ts k
chs⊦→ch (CHS.cinr ts) (pop k) = chs⊦→ch ts k
chs⊦→ch (CHS.ccase ts) (pop k) = chs⊦→ch ts k
-- Translation from closed Hilbert-style to closed Hilbert-style sequential.
ch→chs : ∀ {A} → CH.⊢ A → CHS.⊢ A
ch→chs (CH.app t u) = CHS.app (ch→chs t) (ch→chs u)
ch→chs CH.ci = ∅ , CHS.ci CHS.nil
ch→chs CH.ck = ∅ , CHS.ck CHS.nil
ch→chs CH.cs = ∅ , CHS.cs CHS.nil
ch→chs CH.cpair = ∅ , CHS.cpair CHS.nil
ch→chs CH.cfst = ∅ , CHS.cfst CHS.nil
ch→chs CH.csnd = ∅ , CHS.csnd CHS.nil
ch→chs CH.unit = ∅ , CHS.unit CHS.nil
ch→chs CH.cboom = ∅ , CHS.cboom CHS.nil
ch→chs CH.cinl = ∅ , CHS.cinl CHS.nil
ch→chs CH.cinr = ∅ , CHS.cinr CHS.nil
ch→chs CH.ccase = ∅ , CHS.ccase CHS.nil
-- Translation from Hilbert-style sequential to Hilbert-style.
hs→h : ∀ {A Γ} → HS⟨ Γ ⊢ A ⟩ → H⟨ Γ ⊢ A ⟩
hs→h (Ξ , ts) = hs⊦→h ts top
where
hs⊦→h : ∀ {A Ξ Γ} → HS⟨ Γ ⊦⊢ Ξ ⟩ → A ∈ Ξ → H⟨ Γ ⊢ A ⟩
hs⊦→h (HS.var i ts) top = H.var i
hs⊦→h (HS.mp i j ts) top = H.app (hs⊦→h ts i) (hs⊦→h ts j)
hs⊦→h (HS.ci ts) top = H.ci
hs⊦→h (HS.ck ts) top = H.ck
hs⊦→h (HS.cs ts) top = H.cs
hs⊦→h (HS.cpair ts) top = H.cpair
hs⊦→h (HS.cfst ts) top = H.cfst
hs⊦→h (HS.csnd ts) top = H.csnd
hs⊦→h (HS.unit ts) top = H.unit
hs⊦→h (HS.cboom ts) top = H.cboom
hs⊦→h (HS.cinl ts) top = H.cinl
hs⊦→h (HS.cinr ts) top = H.cinr
hs⊦→h (HS.ccase ts) top = H.ccase
hs⊦→h (HS.var i ts) (pop k) = hs⊦→h ts k
hs⊦→h (HS.mp i j ts) (pop k) = hs⊦→h ts k
hs⊦→h (HS.ci ts) (pop k) = hs⊦→h ts k
hs⊦→h (HS.ck ts) (pop k) = hs⊦→h ts k
hs⊦→h (HS.cs ts) (pop k) = hs⊦→h ts k
hs⊦→h (HS.cpair ts) (pop k) = hs⊦→h ts k
hs⊦→h (HS.cfst ts) (pop k) = hs⊦→h ts k
hs⊦→h (HS.csnd ts) (pop k) = hs⊦→h ts k
hs⊦→h (HS.unit ts) (pop k) = hs⊦→h ts k
hs⊦→h (HS.cboom ts) (pop k) = hs⊦→h ts k
hs⊦→h (HS.cinl ts) (pop k) = hs⊦→h ts k
hs⊦→h (HS.cinr ts) (pop k) = hs⊦→h ts k
hs⊦→h (HS.ccase ts) (pop k) = hs⊦→h ts k
-- Translation from Hilbert-style to Hilbert-style sequential.
h→hs : ∀ {A Γ} → H⟨ Γ ⊢ A ⟩ → HS⟨ Γ ⊢ A ⟩
h→hs (H.var i) = ∅ , HS.var i HS.nil
h→hs (H.app t u) = HS.app (h→hs t) (h→hs u)
h→hs H.ci = ∅ , HS.ci HS.nil
h→hs H.ck = ∅ , HS.ck HS.nil
h→hs H.cs = ∅ , HS.cs HS.nil
h→hs H.cpair = ∅ , HS.cpair HS.nil
h→hs H.cfst = ∅ , HS.cfst HS.nil
h→hs H.csnd = ∅ , HS.csnd HS.nil
h→hs H.unit = ∅ , HS.unit HS.nil
h→hs H.cboom = ∅ , HS.cboom HS.nil
h→hs H.cinl = ∅ , HS.cinl HS.nil
h→hs H.cinr = ∅ , HS.cinr HS.nil
h→hs H.ccase = ∅ , HS.ccase HS.nil
-- Deduction and detachment theorems for Hilbert-style sequential.
hs-lam : ∀ {A B Γ} → HS⟨ Γ , A ⊢ B ⟩ → HS⟨ Γ ⊢ A ▻ B ⟩
hs-lam = h→hs ∘ H.lam ∘ hs→h
hs-lam⋆₀ : ∀ {A Γ} → HS⟨ Γ ⊢ A ⟩ → HS⟨ ∅ ⊢ Γ ▻⋯▻ A ⟩
hs-lam⋆₀ = h→hs ∘ H.lam⋆₀ ∘ hs→h
hs-det : ∀ {A B Γ} → HS⟨ Γ ⊢ A ▻ B ⟩ → HS⟨ Γ , A ⊢ B ⟩
hs-det = h→hs ∘ H.det ∘ hs→h
hs-det⋆₀ : ∀ {A Γ} → HS⟨ ∅ ⊢ Γ ▻⋯▻ A ⟩ → HS⟨ Γ ⊢ A ⟩
hs-det⋆₀ = h→hs ∘ H.det⋆₀ ∘ hs→h
-- Translation from closed Hilbert-style sequential to Hilbert-style sequential.
chs→hs₀ : ∀ {A} → CHS.⊢ A → HS⟨ ∅ ⊢ A ⟩
chs→hs₀ (Ξ , ts) = Ξ , chs⊦→hs₀⊦ ts
where
chs⊦→hs₀⊦ : ∀ {Ξ} → CHS.⊦⊢ Ξ → HS⟨ ∅ ⊦⊢ Ξ ⟩
chs⊦→hs₀⊦ CHS.nil = HS.nil
chs⊦→hs₀⊦ (CHS.mp i j ts) = HS.mp i j (chs⊦→hs₀⊦ ts)
chs⊦→hs₀⊦ (CHS.ci ts) = HS.ci (chs⊦→hs₀⊦ ts)
chs⊦→hs₀⊦ (CHS.ck ts) = HS.ck (chs⊦→hs₀⊦ ts)
chs⊦→hs₀⊦ (CHS.cs ts) = HS.cs (chs⊦→hs₀⊦ ts)
chs⊦→hs₀⊦ (CHS.cpair ts) = HS.cpair (chs⊦→hs₀⊦ ts)
chs⊦→hs₀⊦ (CHS.cfst ts) = HS.cfst (chs⊦→hs₀⊦ ts)
chs⊦→hs₀⊦ (CHS.csnd ts) = HS.csnd (chs⊦→hs₀⊦ ts)
chs⊦→hs₀⊦ (CHS.unit ts) = HS.unit (chs⊦→hs₀⊦ ts)
chs⊦→hs₀⊦ (CHS.cboom ts) = HS.cboom (chs⊦→hs₀⊦ ts)
chs⊦→hs₀⊦ (CHS.cinl ts) = HS.cinl (chs⊦→hs₀⊦ ts)
chs⊦→hs₀⊦ (CHS.cinr ts) = HS.cinr (chs⊦→hs₀⊦ ts)
chs⊦→hs₀⊦ (CHS.ccase ts) = HS.ccase (chs⊦→hs₀⊦ ts)
chs→hs : ∀ {A Γ} → CHS.⊢ Γ ▻⋯▻ A → HS⟨ Γ ⊢ A ⟩
chs→hs t = hs-det⋆₀ (chs→hs₀ t)
-- Translation from Hilbert-style sequential to closed Hilbert-style sequential.
hs₀→chs : ∀ {A} → HS⟨ ∅ ⊢ A ⟩ → CHS.⊢ A
hs₀→chs (Ξ , ts) = Ξ , hs₀⊦→chs⊦ ts
where
hs₀⊦→chs⊦ : ∀ {Ξ} → HS⟨ ∅ ⊦⊢ Ξ ⟩ → CHS.⊦⊢ Ξ
hs₀⊦→chs⊦ HS.nil = CHS.nil
hs₀⊦→chs⊦ (HS.var () ts)
hs₀⊦→chs⊦ (HS.mp i j ts) = CHS.mp i j (hs₀⊦→chs⊦ ts)
hs₀⊦→chs⊦ (HS.ci ts) = CHS.ci (hs₀⊦→chs⊦ ts)
hs₀⊦→chs⊦ (HS.ck ts) = CHS.ck (hs₀⊦→chs⊦ ts)
hs₀⊦→chs⊦ (HS.cs ts) = CHS.cs (hs₀⊦→chs⊦ ts)
hs₀⊦→chs⊦ (HS.cpair ts) = CHS.cpair (hs₀⊦→chs⊦ ts)
hs₀⊦→chs⊦ (HS.cfst ts) = CHS.cfst (hs₀⊦→chs⊦ ts)
hs₀⊦→chs⊦ (HS.csnd ts) = CHS.csnd (hs₀⊦→chs⊦ ts)
hs₀⊦→chs⊦ (HS.unit ts) = CHS.unit (hs₀⊦→chs⊦ ts)
hs₀⊦→chs⊦ (HS.cboom ts) = CHS.cboom (hs₀⊦→chs⊦ ts)
hs₀⊦→chs⊦ (HS.cinl ts) = CHS.cinl (hs₀⊦→chs⊦ ts)
hs₀⊦→chs⊦ (HS.cinr ts) = CHS.cinr (hs₀⊦→chs⊦ ts)
hs₀⊦→chs⊦ (HS.ccase ts) = CHS.ccase (hs₀⊦→chs⊦ ts)
hs→chs : ∀ {A Γ} → HS⟨ Γ ⊢ A ⟩ → CHS.⊢ Γ ▻⋯▻ A
hs→chs t = hs₀→chs (hs-lam⋆₀ t)
-- Translation from closed Hilbert-style to Hilbert-style.
ch→h₀ : ∀ {A} → CH.⊢ A → H⟨ ∅ ⊢ A ⟩
ch→h₀ (CH.app t u) = H.app (ch→h₀ t) (ch→h₀ u)
ch→h₀ CH.ci = H.ci
ch→h₀ CH.ck = H.ck
ch→h₀ CH.cs = H.cs
ch→h₀ CH.cpair = H.cpair
ch→h₀ CH.cfst = H.cfst
ch→h₀ CH.csnd = H.csnd
ch→h₀ CH.unit = H.unit
ch→h₀ CH.cboom = H.cboom
ch→h₀ CH.cinl = H.cinl
ch→h₀ CH.cinr = H.cinr
ch→h₀ CH.ccase = H.ccase
ch→h : ∀ {A Γ} → CH.⊢ Γ ▻⋯▻ A → H⟨ Γ ⊢ A ⟩
ch→h t = H.det⋆₀ (ch→h₀ t)
-- Translation from Hilbert-style to closed Hilbert-style.
h₀→ch : ∀ {A} → H⟨ ∅ ⊢ A ⟩ → CH.⊢ A
h₀→ch (H.var ())
h₀→ch (H.app t u) = CH.app (h₀→ch t) (h₀→ch u)
h₀→ch H.ci = CH.ci
h₀→ch H.ck = CH.ck
h₀→ch H.cs = CH.cs
h₀→ch H.cpair = CH.cpair
h₀→ch H.cfst = CH.cfst
h₀→ch H.csnd = CH.csnd
h₀→ch H.unit = CH.unit
h₀→ch H.cboom = CH.cboom
h₀→ch H.cinl = CH.cinl
h₀→ch H.cinr = CH.cinr
h₀→ch H.ccase = CH.ccase
h→ch : ∀ {A Γ} → H⟨ Γ ⊢ A ⟩ → CH.⊢ Γ ▻⋯▻ A
h→ch t = h₀→ch (H.lam⋆₀ t)
-- Translation from Hilbert-style to Gentzen-style.
h→g : ∀ {A Γ} → H⟨ Γ ⊢ A ⟩ → G⟨ Γ ⊢ A ⟩
h→g (H.var i) = G.var i
h→g (H.app t u) = G.app (h→g t) (h→g u)
h→g H.ci = G.ci
h→g H.ck = G.ck
h→g H.cs = G.cs
h→g H.cpair = G.cpair
h→g H.cfst = G.cfst
h→g H.csnd = G.csnd
h→g H.unit = G.unit
h→g H.cboom = G.cboom
h→g H.cinl = G.cinl
h→g H.cinr = G.cinr
h→g H.ccase = G.ccase
-- Translation from Gentzen-style to Hilbert-style.
g→h : ∀ {A Γ} → G⟨ Γ ⊢ A ⟩ → H⟨ Γ ⊢ A ⟩
g→h (G.var i) = H.var i
g→h (G.lam t) = H.lam (g→h t)
g→h (G.app t u) = H.app (g→h t) (g→h u)
g→h (G.pair t u) = H.pair (g→h t) (g→h u)
g→h (G.fst t) = H.fst (g→h t)
g→h (G.snd t) = H.snd (g→h t)
g→h G.unit = H.unit
g→h (G.boom t) = H.boom (g→h t)
g→h (G.inl t) = H.inl (g→h t)
g→h (G.inr t) = H.inr (g→h t)
g→h (G.case t u v) = H.case (g→h t) (g→h u) (g→h v)
-- Additional translations from closed Hilbert-style sequential.
chs→h₀ : ∀ {A} → CHS.⊢ A → H⟨ ∅ ⊢ A ⟩
chs→h₀ = ch→h₀ ∘ chs→ch
chs→h : ∀ {A Γ} → CHS.⊢ Γ ▻⋯▻ A → H⟨ Γ ⊢ A ⟩
chs→h = ch→h ∘ chs→ch
chs→g₀ : ∀ {A} → CHS.⊢ A → G⟨ ∅ ⊢ A ⟩
chs→g₀ = h→g ∘ chs→h₀
chs→g : ∀ {A Γ} → CHS.⊢ Γ ▻⋯▻ A → G⟨ Γ ⊢ A ⟩
chs→g = h→g ∘ chs→h
-- Additional translations from closed Hilbert-style.
ch→hs₀ : ∀ {A} → CH.⊢ A → HS⟨ ∅ ⊢ A ⟩
ch→hs₀ = chs→hs₀ ∘ ch→chs
ch→hs : ∀ {A Γ} → CH.⊢ Γ ▻⋯▻ A → HS⟨ Γ ⊢ A ⟩
ch→hs = chs→hs ∘ ch→chs
ch→g₀ : ∀ {A} → CH.⊢ A → G⟨ ∅ ⊢ A ⟩
ch→g₀ = h→g ∘ ch→h₀
ch→g : ∀ {A Γ} → CH.⊢ Γ ▻⋯▻ A → G⟨ Γ ⊢ A ⟩
ch→g = h→g ∘ ch→h
-- Additional translations from Hilbert-style sequential.
hs₀→ch : ∀ {A} → HS⟨ ∅ ⊢ A ⟩ → CH.⊢ A
hs₀→ch = chs→ch ∘ hs₀→chs
hs→ch : ∀ {A Γ} → HS⟨ Γ ⊢ A ⟩ → CH.⊢ Γ ▻⋯▻ A
hs→ch = chs→ch ∘ hs→chs
hs→g : ∀ {A Γ} → HS⟨ Γ ⊢ A ⟩ → G⟨ Γ ⊢ A ⟩
hs→g = h→g ∘ hs→h
-- Additional translations from Hilbert-style.
h₀→chs : ∀ {A} → H⟨ ∅ ⊢ A ⟩ → CHS.⊢ A
h₀→chs = ch→chs ∘ h₀→ch
h→chs : ∀ {A Γ} → H⟨ Γ ⊢ A ⟩ → CHS.⊢ Γ ▻⋯▻ A
h→chs = ch→chs ∘ h→ch
-- Additional translations from Gentzen-style.
g₀→chs : ∀ {A} → G⟨ ∅ ⊢ A ⟩ → CHS.⊢ A
g₀→chs = h₀→chs ∘ g→h
g→chs : ∀ {A Γ} → G⟨ Γ ⊢ A ⟩ → CHS.⊢ Γ ▻⋯▻ A
g→chs = h→chs ∘ g→h
g₀→ch : ∀ {A} → G⟨ ∅ ⊢ A ⟩ → CH.⊢ A
g₀→ch = h₀→ch ∘ g→h
g→ch : ∀ {A Γ} → G⟨ Γ ⊢ A ⟩ → CH.⊢ Γ ▻⋯▻ A
g→ch = h→ch ∘ g→h
g→hs : ∀ {A Γ} → G⟨ Γ ⊢ A ⟩ → HS⟨ Γ ⊢ A ⟩
g→hs = h→hs ∘ g→h
| {
"alphanum_fraction": 0.4854395355,
"avg_line_length": 31.8583815029,
"ext": "agda",
"hexsha": "8b6c590c68d845123ec29ff3784b5bbacc6abbe7",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/hilbert-gentzen",
"max_forks_repo_path": "IPC/Syntax/Translation.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/hilbert-gentzen",
"max_issues_repo_path": "IPC/Syntax/Translation.agda",
"max_line_length": 80,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/hilbert-gentzen",
"max_stars_repo_path": "IPC/Syntax/Translation.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-01T10:29:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-03T18:51:56.000Z",
"num_tokens": 6004,
"size": 11023
} |
------------------------------------------------------------------------------
-- Properties stated in the Burstall's paper
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.SortList.PropertiesATP where
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Data.Bool.PropertiesATP
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.Inequalities.PropertiesATP
open import FOTC.Data.Nat.List.Type
open import FOTC.Data.Nat.Type
open import FOTC.Data.List
open import FOTC.Data.List.PropertiesATP
open import FOTC.Program.SortList.Properties.Totality.BoolATP
open import FOTC.Program.SortList.Properties.Totality.ListN-ATP
open import FOTC.Program.SortList.Properties.Totality.OrdList.FlattenATP
open import FOTC.Program.SortList.Properties.Totality.OrdListATP
open import FOTC.Program.SortList.Properties.Totality.OrdTreeATP
open import FOTC.Program.SortList.Properties.Totality.TreeATP
open import FOTC.Program.SortList.SortList
------------------------------------------------------------------------------
-- Burstall's lemma: If t is ordered then totree(i, t) is ordered.
toTree-OrdTree : ∀ {item t} → N item → Tree t → OrdTree t →
OrdTree (toTree · item · t)
toTree-OrdTree {item} Nitem tnil OTt = prf
where postulate prf : OrdTree (toTree · item · nil)
{-# ATP prove prf #-}
toTree-OrdTree {item} Nitem (ttip {i} Ni) OTt =
case prf₁ prf₂ (x>y∨x≤y Ni Nitem)
where
postulate prf₁ : i > item → OrdTree (toTree · item · tip i)
{-# ATP prove prf₁ x≤x x<y→x≤y x>y→x≰y #-}
postulate prf₂ : i ≤ item → OrdTree (toTree · item · tip i)
{-# ATP prove prf₂ x≤x #-}
toTree-OrdTree {item} Nitem (tnode {t₁} {i} {t₂} Tt₁ Ni Tt₂) OTtnode =
case (prf₁ (toTree-OrdTree Nitem Tt₁ (leftSubTree-OrdTree Tt₁ Ni Tt₂ OTtnode))
(rightSubTree-OrdTree Tt₁ Ni Tt₂ OTtnode))
(prf₂ (toTree-OrdTree Nitem Tt₂ (rightSubTree-OrdTree Tt₁ Ni Tt₂ OTtnode))
(leftSubTree-OrdTree Tt₁ Ni Tt₂ OTtnode))
(x>y∨x≤y Ni Nitem)
where
postulate prf₁ : ordTree (toTree · item · t₁) ≡ true →
OrdTree t₂ →
i > item →
OrdTree (toTree · item · node t₁ i t₂)
{-# ATP prove prf₁ &&-list₄-t x>y→x≰y le-ItemTree-Bool le-TreeItem-Bool ordTree-Bool toTree-OrdTree-helper₁ #-}
postulate prf₂ : ordTree (toTree · item · t₂) ≡ true →
OrdTree t₁ →
i ≤ item →
OrdTree (toTree · item · node t₁ i t₂)
{-# ATP prove prf₂ &&-list₄-t le-ItemTree-Bool le-TreeItem-Bool ordTree-Bool toTree-OrdTree-helper₂ #-}
------------------------------------------------------------------------------
-- Burstall's lemma: ord(maketree(is)).
-- makeTree-TreeOrd : ∀ {is} → ListN is → OrdTree (makeTree is)
-- makeTree-TreeOrd LNis =
-- ind-lit OrdTree toTree nil LNis ordTree-nil
-- (λ Nx y TOy → toTree-OrdTree Nx {!!} TOy)
makeTree-OrdTree : ∀ {is} → ListN is → OrdTree (makeTree is)
makeTree-OrdTree lnnil = prf
where postulate prf : OrdTree (makeTree [])
{-# ATP prove prf #-}
makeTree-OrdTree (lncons {i} {is} Ni Lis) = prf (makeTree-OrdTree Lis)
where postulate prf : OrdTree (makeTree is) → OrdTree (makeTree (i ∷ is))
{-# ATP prove prf makeTree-Tree toTree-OrdTree #-}
------------------------------------------------------------------------------
-- Burstall's lemma: If ord(is1) and ord(is2) and is1 ≤ is2 then
-- ord(concat(is1, is2)).
++-OrdList : ∀ {is js} → ListN is → ListN js → OrdList is → OrdList js →
≤-Lists is js → OrdList (is ++ js)
++-OrdList {js = js} lnnil LNjs LOis LOjs is≤js =
subst OrdList (sym (++-leftIdentity js)) LOjs
++-OrdList {js = js} (lncons {i} {is} Ni LNis) LNjs OLi∷is OLjs i∷is≤js =
subst OrdList
(sym (++-∷ i is js))
(lemma (++-OrdList LNis LNjs
(subList-OrdList Ni LNis OLi∷is)
OLjs
(&&-list₂-t₂ (le-ItemList-Bool Ni LNjs)
(le-Lists-Bool LNis LNjs)
(trans (sym (le-Lists-∷ i is js)) i∷is≤js))))
where postulate lemma : OrdList (is ++ js) → OrdList (i ∷ is ++ js)
{-# ATP prove lemma &&-list₂-t ++-OrdList-helper le-ItemList-Bool le-Lists-Bool ordList-Bool #-}
------------------------------------------------------------------------------
-- Burstall's lemma: If t is ordered then (flatten t) is ordered.
flatten-OrdList : ∀ {t} → Tree t → OrdTree t → OrdList (flatten t)
flatten-OrdList tnil OTt =
subst OrdList (sym flatten-nil) ordList-[]
flatten-OrdList (ttip {i} Ni) OTt = prf
where postulate prf : OrdList (flatten (tip i))
{-# ATP prove prf #-}
flatten-OrdList (tnode {t₁} {i} {t₂} Tt₁ Ni Tt₂) OTt
= prf (++-OrdList (flatten-ListN Tt₁)
(flatten-ListN Tt₂)
(flatten-OrdList Tt₁ (leftSubTree-OrdTree Tt₁ Ni Tt₂ OTt))
(flatten-OrdList Tt₂ (rightSubTree-OrdTree Tt₁ Ni Tt₂ OTt))
(flatten-OrdList-helper Tt₁ Ni Tt₂ OTt))
where postulate prf : OrdList (flatten t₁ ++ flatten t₂) → -- Indirect IH.
OrdList (flatten (node t₁ i t₂))
{-# ATP prove prf #-}
| {
"alphanum_fraction": 0.5670273244,
"avg_line_length": 44.6967213115,
"ext": "agda",
"hexsha": "4a2e4094ca5cf653a394d630c38c3a4ed2ffed8c",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Program/SortList/PropertiesATP.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Program/SortList/PropertiesATP.agda",
"max_line_length": 113,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Program/SortList/PropertiesATP.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 1635,
"size": 5453
} |
{-# OPTIONS --without-K #-}
module TypeEquiv where
import Level using (zero; suc)
open import Data.Empty using (⊥)
open import Data.Unit using (⊤; tt)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Product using (_×_; proj₁; proj₂; _,_)
open import Algebra using (CommutativeSemiring)
open import Algebra.Structures
using (IsSemigroup; IsCommutativeMonoid; IsCommutativeSemiring)
open import Function renaming (_∘_ to _○_)
open import Relation.Binary.PropositionalEquality using (refl)
open import Equiv
using (_∼_; refl∼; _≃_; id≃; sym≃; ≃IsEquiv; qinv; _⊎≃_; _×≃_)
------------------------------------------------------------------------------
-- Type Equivalences
-- for each type combinator, define two functions that are inverses, and
-- establish an equivalence. These are all in the 'semantic space' with
-- respect to Pi combinators.
-- swap₊
swap₊ : {A B : Set} → A ⊎ B → B ⊎ A
swap₊ (inj₁ a) = inj₂ a
swap₊ (inj₂ b) = inj₁ b
abstract
swapswap₊ : {A B : Set} → swap₊ ○ swap₊ {A} {B} ∼ id
swapswap₊ (inj₁ a) = refl
swapswap₊ (inj₂ b) = refl
swap₊equiv : {A B : Set} → (A ⊎ B) ≃ (B ⊎ A)
swap₊equiv = (swap₊ , qinv swap₊ swapswap₊ swapswap₊)
-- unite₊ and uniti₊
unite₊ : {A : Set} → ⊥ ⊎ A → A
unite₊ (inj₁ ())
unite₊ (inj₂ y) = y
uniti₊ : {A : Set} → A → ⊥ ⊎ A
uniti₊ a = inj₂ a
abstract
uniti₊∘unite₊ : {A : Set} → uniti₊ ○ unite₊ ∼ id {A = ⊥ ⊎ A}
uniti₊∘unite₊ (inj₁ ())
uniti₊∘unite₊ (inj₂ y) = refl
-- this is so easy, Agda can figure it out by itself (see below)
unite₊∘uniti₊ : {A : Set} → unite₊ ○ uniti₊ ∼ id {A = A}
unite₊∘uniti₊ _ = refl
unite₊equiv : {A : Set} → (⊥ ⊎ A) ≃ A
unite₊equiv = (unite₊ , qinv uniti₊ unite₊∘uniti₊ uniti₊∘unite₊)
uniti₊equiv : {A : Set} → A ≃ (⊥ ⊎ A)
uniti₊equiv = sym≃ unite₊equiv
-- unite₊′ and uniti₊′
unite₊′ : {A : Set} → A ⊎ ⊥ → A
unite₊′ (inj₁ x) = x
unite₊′ (inj₂ ())
uniti₊′ : {A : Set} → A → A ⊎ ⊥
uniti₊′ a = inj₁ a
abstract
uniti₊′∘unite₊′ : {A : Set} → uniti₊′ ○ unite₊′ ∼ id {A = A ⊎ ⊥}
uniti₊′∘unite₊′ (inj₁ _) = refl
uniti₊′∘unite₊′ (inj₂ ())
-- this is so easy, Agda can figure it out by itself (see below)
unite₊′∘uniti₊′ : {A : Set} → unite₊′ ○ uniti₊′ ∼ id {A = A}
unite₊′∘uniti₊′ _ = refl
unite₊′equiv : {A : Set} → (A ⊎ ⊥) ≃ A
unite₊′equiv = (unite₊′ , qinv uniti₊′ refl∼ uniti₊′∘unite₊′)
uniti₊′equiv : {A : Set} → A ≃ (A ⊎ ⊥)
uniti₊′equiv = sym≃ unite₊′equiv
-- unite⋆ and uniti⋆
unite⋆ : {A : Set} → ⊤ × A → A
unite⋆ (tt , x) = x
uniti⋆ : {A : Set} → A → ⊤ × A
uniti⋆ x = tt , x
abstract
uniti⋆∘unite⋆ : {A : Set} → uniti⋆ ○ unite⋆ ∼ id {A = ⊤ × A}
uniti⋆∘unite⋆ (tt , x) = refl
unite⋆equiv : {A : Set} → (⊤ × A) ≃ A
unite⋆equiv = unite⋆ , qinv uniti⋆ refl∼ uniti⋆∘unite⋆
uniti⋆equiv : {A : Set} → A ≃ (⊤ × A)
uniti⋆equiv = sym≃ unite⋆equiv
-- unite⋆′ and uniti⋆′
unite⋆′ : {A : Set} → A × ⊤ → A
unite⋆′ (x , tt) = x
uniti⋆′ : {A : Set} → A → A × ⊤
uniti⋆′ x = x , tt
abstract
uniti⋆′∘unite⋆′ : {A : Set} → uniti⋆′ ○ unite⋆′ ∼ id {A = A × ⊤}
uniti⋆′∘unite⋆′ (x , tt) = refl
unite⋆′equiv : {A : Set} → (A × ⊤) ≃ A
unite⋆′equiv = unite⋆′ , qinv uniti⋆′ refl∼ uniti⋆′∘unite⋆′
uniti⋆′equiv : {A : Set} → A ≃ (A × ⊤)
uniti⋆′equiv = sym≃ unite⋆′equiv
-- swap⋆
swap⋆ : {A B : Set} → A × B → B × A
swap⋆ (a , b) = (b , a)
abstract
swapswap⋆ : {A B : Set} → swap⋆ ○ swap⋆ ∼ id {A = A × B}
swapswap⋆ (a , b) = refl
swap⋆equiv : {A B : Set} → (A × B) ≃ (B × A)
swap⋆equiv = swap⋆ , qinv swap⋆ swapswap⋆ swapswap⋆
-- assocl₊ and assocr₊
assocl₊ : {A B C : Set} → (A ⊎ (B ⊎ C)) → ((A ⊎ B) ⊎ C)
assocl₊ (inj₁ a) = inj₁ (inj₁ a)
assocl₊ (inj₂ (inj₁ b)) = inj₁ (inj₂ b)
assocl₊ (inj₂ (inj₂ c)) = inj₂ c
assocr₊ : {A B C : Set} → ((A ⊎ B) ⊎ C) → (A ⊎ (B ⊎ C))
assocr₊ (inj₁ (inj₁ a)) = inj₁ a
assocr₊ (inj₁ (inj₂ b)) = inj₂ (inj₁ b)
assocr₊ (inj₂ c) = inj₂ (inj₂ c)
abstract
assocl₊∘assocr₊ : {A B C : Set} → assocl₊ ○ assocr₊ ∼ id {A = ((A ⊎ B) ⊎ C)}
assocl₊∘assocr₊ (inj₁ (inj₁ a)) = refl
assocl₊∘assocr₊ (inj₁ (inj₂ b)) = refl
assocl₊∘assocr₊ (inj₂ c) = refl
assocr₊∘assocl₊ : {A B C : Set} → assocr₊ ○ assocl₊ ∼ id {A = (A ⊎ (B ⊎ C))}
assocr₊∘assocl₊ (inj₁ a) = refl
assocr₊∘assocl₊ (inj₂ (inj₁ b)) = refl
assocr₊∘assocl₊ (inj₂ (inj₂ c)) = refl
assocr₊equiv : {A B C : Set} → ((A ⊎ B) ⊎ C) ≃ (A ⊎ (B ⊎ C))
assocr₊equiv =
assocr₊ , qinv assocl₊ assocr₊∘assocl₊ assocl₊∘assocr₊
assocl₊equiv : {A B C : Set} → (A ⊎ (B ⊎ C)) ≃ ((A ⊎ B) ⊎ C)
assocl₊equiv = sym≃ assocr₊equiv
-- assocl⋆ and assocr⋆
assocl⋆ : {A B C : Set} → (A × (B × C)) → ((A × B) × C)
assocl⋆ (a , (b , c)) = ((a , b) , c)
assocr⋆ : {A B C : Set} → ((A × B) × C) → (A × (B × C))
assocr⋆ ((a , b) , c) = (a , (b , c))
abstract
assocl⋆∘assocr⋆ : {A B C : Set} → assocl⋆ ○ assocr⋆ ∼ id {A = ((A × B) × C)}
assocl⋆∘assocr⋆ = refl∼
assocr⋆∘assocl⋆ : {A B C : Set} → assocr⋆ ○ assocl⋆ ∼ id {A = (A × (B × C))}
assocr⋆∘assocl⋆ = refl∼
assocl⋆equiv : {A B C : Set} → (A × (B × C)) ≃ ((A × B) × C)
assocl⋆equiv =
assocl⋆ , qinv assocr⋆ assocl⋆∘assocr⋆ assocr⋆∘assocl⋆
assocr⋆equiv : {A B C : Set} → ((A × B) × C) ≃ (A × (B × C))
assocr⋆equiv = sym≃ assocl⋆equiv
-- distz and factorz, on left
distz : { A : Set} → (⊥ × A) → ⊥
distz = proj₁
factorz : {A : Set} → ⊥ → (⊥ × A)
factorz ()
abstract
distz∘factorz : {A : Set} → distz ○ factorz {A} ∼ id
distz∘factorz ()
factorz∘distz : {A : Set} → factorz {A} ○ distz ∼ id
factorz∘distz (() , proj₂)
distzequiv : {A : Set} → (⊥ × A) ≃ ⊥
distzequiv {A} =
distz , qinv factorz (distz∘factorz {A}) factorz∘distz
factorzequiv : {A : Set} → ⊥ ≃ (⊥ × A)
factorzequiv {A} = sym≃ distzequiv
-- distz and factorz, on right
distzr : { A : Set} → (A × ⊥) → ⊥
distzr = proj₂
factorzr : {A : Set} → ⊥ → (A × ⊥)
factorzr ()
abstract
distzr∘factorzr : {A : Set} → distzr ○ factorzr {A} ∼ id
distzr∘factorzr ()
factorzr∘distzr : {A : Set} → factorzr {A} ○ distzr ∼ id
factorzr∘distzr (_ , ())
distzrequiv : {A : Set} → (A × ⊥) ≃ ⊥
distzrequiv {A} =
distzr , qinv factorzr (distzr∘factorzr {A}) factorzr∘distzr
factorzrequiv : {A : Set} → ⊥ ≃ (A × ⊥)
factorzrequiv {A} = sym≃ distzrequiv
-- dist and factor, on right
dist : {A B C : Set} → ((A ⊎ B) × C) → (A × C) ⊎ (B × C)
dist (inj₁ x , c) = inj₁ (x , c)
dist (inj₂ y , c) = inj₂ (y , c)
factor : {A B C : Set} → (A × C) ⊎ (B × C) → ((A ⊎ B) × C)
factor (inj₁ (a , c)) = inj₁ a , c
factor (inj₂ (b , c)) = inj₂ b , c
abstract
dist∘factor : {A B C : Set} → dist {A} {B} {C} ○ factor ∼ id
dist∘factor (inj₁ x) = refl
dist∘factor (inj₂ y) = refl
factor∘dist : {A B C : Set} → factor {A} {B} {C} ○ dist ∼ id
factor∘dist (inj₁ x , c) = refl
factor∘dist (inj₂ y , c) = refl
distequiv : {A B C : Set} → ((A ⊎ B) × C) ≃ ((A × C) ⊎ (B × C))
distequiv = dist , qinv factor dist∘factor factor∘dist
factorequiv : {A B C : Set} → ((A × C) ⊎ (B × C)) ≃ ((A ⊎ B) × C)
factorequiv = sym≃ distequiv
-- dist and factor, on left
distl : {A B C : Set} → A × (B ⊎ C) → (A × B) ⊎ (A × C)
distl (x , inj₁ x₁) = inj₁ (x , x₁)
distl (x , inj₂ y) = inj₂ (x , y)
factorl : {A B C : Set} → (A × B) ⊎ (A × C) → A × (B ⊎ C)
factorl (inj₁ (x , y)) = x , inj₁ y
factorl (inj₂ (x , y)) = x , inj₂ y
abstract
distl∘factorl : {A B C : Set} → distl {A} {B} {C} ○ factorl ∼ id
distl∘factorl (inj₁ (x , y)) = refl
distl∘factorl (inj₂ (x , y)) = refl
factorl∘distl : {A B C : Set} → factorl {A} {B} {C} ○ distl ∼ id
factorl∘distl (a , inj₁ x) = refl
factorl∘distl (a , inj₂ y) = refl
distlequiv : {A B C : Set} → (A × (B ⊎ C)) ≃ ((A × B) ⊎ (A × C))
distlequiv = distl , qinv factorl distl∘factorl factorl∘distl
factorlequiv : {A B C : Set} → ((A × B) ⊎ (A × C)) ≃ (A × (B ⊎ C))
factorlequiv = sym≃ distlequiv
------------------------------------------------------------------------------
-- Commutative semiring structure
typesPlusIsSG : IsSemigroup {Level.suc Level.zero} {Level.zero} {Set} _≃_ _⊎_
typesPlusIsSG = record {
isMagma = record {
isEquivalence = ≃IsEquiv ;
∙-cong = _⊎≃_ }
; assoc = λ t₁ t₂ t₃ → assocr₊equiv {t₁} {t₂} {t₃}
}
typesTimesIsSG : IsSemigroup {Level.suc Level.zero} {Level.zero} {Set} _≃_ _×_
typesTimesIsSG = record {
isMagma = record {
isEquivalence = ≃IsEquiv
; ∙-cong = _×≃_
}
; assoc = λ t₁ t₂ t₃ → assocr⋆equiv {t₁} {t₂} {t₃}
}
typesPlusIsCM : IsCommutativeMonoid _≃_ _⊎_ ⊥
typesPlusIsCM = record {
isSemigroup = typesPlusIsSG ;
identityˡ = λ t → unite₊equiv {t} ;
comm = λ t₁ t₂ → swap₊equiv {t₁} {t₂}
}
typesTimesIsCM : IsCommutativeMonoid _≃_ _×_ ⊤
typesTimesIsCM = record {
isSemigroup = typesTimesIsSG ;
identityˡ = λ t → unite⋆equiv {t} ;
comm = λ t₁ t₂ → swap⋆equiv {t₁} {t₂}
}
typesIsCSR : IsCommutativeSemiring _≃_ _⊎_ _×_ ⊥ ⊤
typesIsCSR = record {
+-isCommutativeMonoid = typesPlusIsCM ;
*-isCommutativeMonoid = typesTimesIsCM ;
distribʳ = λ t₁ t₂ t₃ → distequiv {t₂} {t₃} {t₁} ;
zeroˡ = λ t → distzequiv {t}
}
typesCSR : CommutativeSemiring (Level.suc Level.zero) Level.zero
typesCSR = record {
Carrier = Set ;
_≈_ = _≃_ ;
_+_ = _⊎_ ;
_*_ = _×_ ;
0# = ⊥ ;
1# = ⊤ ;
isCommutativeSemiring = typesIsCSR
}
------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.5409550745,
"avg_line_length": 26.0424929178,
"ext": "agda",
"hexsha": "3dddaeeaf88e449ee8e1032cbf8e95a39b865662",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "Univalence/TypeEquiv.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "Univalence/TypeEquiv.agda",
"max_line_length": 78,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "Univalence/TypeEquiv.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 4442,
"size": 9193
} |
{-# OPTIONS --no-universe-polymorphism #-}
open import Relation.Binary.Core
open import Function
module Equivalence where
infixr 5 _⇔_
record _⇔_ (A B : Set) : Set where
field to : A → B
from : B → A
infixr 3 _↔_
record _↔_ (A B : Set) : Set where
field to : A → B
from : B → A
from-to : ∀ a → from (to a) ≡ a
to-from : ∀ b → to (from b) ≡ b
infixr 3 _=⟨_⟩_
_=⟨_⟩_ : {A : Set} (x : A) { y z : A} → x ≡ y → y ≡ z → x ≡ z
_=⟨_⟩_ _ refl refl = refl
=sym : {A : Set} {x y : A} → x ≡ y → y ≡ x
=sym refl = refl
infixr 5 _under_
_under_ : {A B : Set} → {x y : A} → x ≡ y → (f : A → B) → f x ≡ f y
_under_ refl f = refl
infixr 4 _□=
_□= : {A : Set} → (x : A) → x ≡ x
_□= x = refl
⇔sym : {A B : Set} → A ⇔ B → B ⇔ A
⇔sym p = record {to = _⇔_.from p ;
from = _⇔_.to p }
infixr 4 _□⇔
_□⇔ : (A : Set) → A ⇔ A
_□⇔ A = record {to = λ x → x;
from = λ x → x}
infixr 3 _⇔⟨_⟩_
_⇔⟨_⟩_ : (A : Set) {B C : Set} → A ⇔ B → B ⇔ C → A ⇔ C
_⇔⟨_⟩_ A {B} {C} AisB BisC = record {to = (_⇔_.to BisC) ∘ (_⇔_.to AisB);
from = (_⇔_.from AisB) ∘ (_⇔_.from BisC) }
↔sym : {A B : Set} → A ↔ B → B ↔ A
↔sym p = record {to = _↔_.from p ;
from = _↔_.to p ;
from-to = _↔_.to-from p ;
to-from = _↔_.from-to p }
infixr 4 _□↔
_□↔ : (A : Set) → A ↔ A
_□↔ A = record {to = λ x → x;
from = λ x → x;
from-to = λ a → refl;
to-from = λ b → refl}
infixr 3 _↔⟨_⟩_
_↔⟨_⟩_ : (A : Set) {B C : Set} → A ↔ B → B ↔ C → A ↔ C
_↔⟨_⟩_ A {B} {C} AisB BisC = record {to = to₂ ∘ to₁ ;
from = from₁ ∘ from₂ ;
from-to = λ a → (from₁ ∘ from₂ ∘ to₂ ∘ to₁) a =⟨ from-to₂ (to₁ a) under from₁ ⟩
from₁ (to₁ a) =⟨ from-to₁ a ⟩
a □= ;
to-from = λ c → (to₂ ∘ to₁ ∘ from₁ ∘ from₂) c =⟨ to-from₁ (from₂ c) under to₂ ⟩
to₂ (from₂ c) =⟨ to-from₂ c ⟩
c □= } where
to₁ = _↔_.to AisB
to₂ = _↔_.to BisC
from₁ = _↔_.from AisB
from₂ = _↔_.from BisC
from-to₁ = _↔_.from-to AisB
from-to₂ = _↔_.from-to BisC
to-from₁ = _↔_.to-from AisB
to-from₂ = _↔_.to-from BisC
| {
"alphanum_fraction": 0.3425797503,
"avg_line_length": 28.5544554455,
"ext": "agda",
"hexsha": "c59c6b555d4a5193022caf272e767e5f3d03a924",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "99bd3a5e772563153d78f61c1bbca48d7809ff48",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "NAMEhzj/Divide-and-Conquer-in-Agda",
"max_forks_repo_path": "Equivalence.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "99bd3a5e772563153d78f61c1bbca48d7809ff48",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "NAMEhzj/Divide-and-Conquer-in-Agda",
"max_issues_repo_path": "Equivalence.agda",
"max_line_length": 117,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "99bd3a5e772563153d78f61c1bbca48d7809ff48",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "NAMEhzj/Divide-and-Conquer-in-Agda",
"max_stars_repo_path": "Equivalence.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1044,
"size": 2884
} |
module Data.List.Setoid where
import Lvl
open import Data.List
open import Data.List.Equiv
open import Data.List.Relation.Quantification
open import Logic.Propositional
open import Structure.Operator
open import Structure.Setoid
open import Structure.Relator.Equivalence
import Structure.Relator.Names as Names
open import Structure.Relator.Properties
open import Type
private variable ℓ ℓₑ ℓₚ : Lvl.Level
private variable T : Type{ℓ}
instance
List-equiv : ⦃ Equiv{ℓₑ}(T) ⦄ → Equiv(List(T))
List-equiv = intro (AllElements₂(_≡_)) ⦃ intro ⦃ intro refl ⦄ ⦃ intro sym ⦄ ⦃ intro trans ⦄ ⦄ where
refl : Names.Reflexivity(AllElements₂(_≡_))
refl{∅} = ∅
refl{x ⊰ l} = reflexivity(_≡_) ⊰ refl{l}
sym : Names.Symmetry(AllElements₂(_≡_))
sym ∅ = ∅
sym (p ⊰ ps) = symmetry(_≡_) p ⊰ sym ps
trans : Names.Transitivity(AllElements₂(_≡_))
trans ∅ ∅ = ∅
trans (p ⊰ ps) (q ⊰ qs) = (transitivity(_≡_) p q) ⊰ (trans ps qs)
instance
List-equiv-extensionality : ⦃ equiv : Equiv{ℓₑ}(T) ⦄ → Extensionality(List-equiv ⦃ equiv ⦄)
List-equiv-extensionality ⦃ equiv ⦄ = intro ⦃ binaryOperator = intro(_⊰_) ⦄ (\{(p ⊰ _) → p}) (\{(_ ⊰ pl) → pl}) \()
| {
"alphanum_fraction": 0.6575456053,
"avg_line_length": 33.5,
"ext": "agda",
"hexsha": "8b46bd2149b15838629b2db02b33b0f5015f9316",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Data/List/Setoid.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Data/List/Setoid.agda",
"max_line_length": 117,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Data/List/Setoid.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 420,
"size": 1206
} |
module Background where
postulate Bits : Set
module Open where
data U : Set where
postulate
El : U → Set
marshal : (u : U) → El u → Bits
module Closed where
data Desc : Set where
postulate
μ : Desc → Set
marshal : (D : Desc) → μ D → Bits
| {
"alphanum_fraction": 0.6007326007,
"avg_line_length": 13.65,
"ext": "agda",
"hexsha": "4b6c41778a872294af7045ab155277c4cf432779",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:31:22.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-02T08:56:15.000Z",
"max_forks_repo_head_hexsha": "832383d7adf37aa2364213fb0aeb67e9f61a248f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "larrytheliquid/generic-elim",
"max_forks_repo_path": "slides/Background.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "832383d7adf37aa2364213fb0aeb67e9f61a248f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/generic-elim",
"max_issues_repo_path": "slides/Background.agda",
"max_line_length": 37,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "832383d7adf37aa2364213fb0aeb67e9f61a248f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/generic-elim",
"max_stars_repo_path": "slides/Background.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-09T08:46:42.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-06-02T14:05:20.000Z",
"num_tokens": 82,
"size": 273
} |
{-# OPTIONS --rewriting #-}
module Properties where
import Properties.Contradiction
import Properties.Dec
import Properties.Equality
import Properties.Functions
import Properties.Remember
import Properties.Step
import Properties.StrictMode
import Properties.Subtyping
import Properties.TypeCheck
| {
"alphanum_fraction": 0.8523489933,
"avg_line_length": 21.2857142857,
"ext": "agda",
"hexsha": "5594812e1693c34ab149370fded1f0fa6850ca1e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "d37d0c857ba543ea47f0b8fce5678f7aadf5239e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "EtiTheSpirit/luau",
"max_forks_repo_path": "prototyping/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d37d0c857ba543ea47f0b8fce5678f7aadf5239e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "EtiTheSpirit/luau",
"max_issues_repo_path": "prototyping/Properties.agda",
"max_line_length": 31,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "d37d0c857ba543ea47f0b8fce5678f7aadf5239e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "EtiTheSpirit/luau",
"max_stars_repo_path": "prototyping/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 54,
"size": 298
} |
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
| {
"alphanum_fraction": 0.5568078531,
"avg_line_length": 38.2013888889,
"ext": "agda",
"hexsha": "4baf07da2ccc59b4c5f0b88f19e28341b689b45b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Syntax/Type/Unification/McBride.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Syntax/Type/Unification/McBride.agda",
"max_line_length": 92,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Syntax/Type/Unification/McBride.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 2166,
"size": 5501
} |
------------------------------------------------------------------------
-- A small definition of a dependently typed language, using the
-- technique from McBride's "Outrageous but Meaningful Coincidences"
------------------------------------------------------------------------
-- Inlining saves a lot of memory. Test with +RTS -M100M
-- The inlining of zero and suc in raw-category at the end is the most
-- important.
{-# OPTIONS --type-in-type #-}
module _ where
open import Agda.Builtin.Equality
open import Agda.Builtin.Unit
open import Agda.Builtin.Sigma
------------------------------------------------------------------------
-- Prelude
data ⊥ : Set where
⊥-elim : ⊥ → {A : Set} → A
⊥-elim ()
data Either (A B : Set) : Set where
left : A → Either A B
right : B → Either A B
uncurry : {A : Set} {B : A → Set} {C : Σ A B → Set} →
((x : A) (y : B x) → C (x , y)) →
((p : Σ A B) → C p)
uncurry f p = f (fst p) (snd p)
infixr 2 _×_
_×_ : Set → Set → Set
_×_ A B = Σ A (λ _ → B)
------------------------------------------------------------------------
-- A universe
data U : Set
El : U → Set
data U where
set : U
el : Set → U
sigma : (a : U) → (El a → U) → U
pi : (a : U) → (El a → U) → U
El set = Set
El (el A) = A
El (sigma a b) = Σ (El a) (λ x → El (b x))
El (pi a b) = (x : El a) → El (b x)
-- Abbreviations.
fun : U → U → U
fun a b = pi a (λ _ → b)
times : U → U → U
times a b = sigma a (λ _ → b)
-- -- Example.
------------------------------------------------------------------------
-- Contexts
-- Contexts.
data Ctxt : Set
-- Types.
Ty : Ctxt → Set
-- Environments.
Env : Ctxt → Set
data Ctxt where
empty : Ctxt
snoc : (G : Ctxt) → Ty G → Ctxt
Ty G = Env G → U
Env empty = ⊤
Env (snoc G s) = Σ (Env G) (λ g → El (s g))
-- Variables (deBruijn indices).
Var : ∀ G → Ty G → Set
Var empty t = ⊥
Var (snoc G s) t =
Either ((λ g → s (fst g)) ≡ t)
(Σ _ (λ u → (λ g → u (fst g)) ≡ t × Var G u))
zero : ∀ {G s} → Var (snoc G s) (λ g → s (fst g))
zero = left refl
suc : ∀ {G s t} → (x : Var G t) → Var (snoc G s) (λ g → t (fst g))
suc x = right (_ , refl , x)
-- A lookup function.
lookup : ∀ G (s : Ty G) → Var G s → (g : Env G) → El (s g)
lookup empty _ absurd _ = ⊥-elim absurd
lookup (snoc vs v) _ (left refl) g = snd g
lookup (snoc vs v) t (right (_ , refl , x)) g = lookup _ _ x (fst g)
------------------------------------------------------------------------
-- A language
-- Syntax for types.
data Type (G : Ctxt) (s : Ty G) : Set
-- Terms.
data Term (G : Ctxt) (s : Ty G) : Set
-- The semantics of a term.
eval : ∀ {G s} → Term G s → (g : Env G) → El (s g)
data Type G s where
set'' : s ≡ (λ _ → set) → Type G s
el'' : (x : Term G (λ _ → set)) →
(λ g → el (eval {s = λ _ → set} x g)) ≡ s →
Type G s
sigma'' : {t : _} {u : _} →
Type G t →
Type (snoc G t) u →
(λ g → sigma (t g) (λ v → u (g , v))) ≡ s →
Type G s
pi'' : {t : _} {u : _} →
Type G t →
Type (snoc G t) u →
(λ g → pi (t g) (λ v → u (g , v))) ≡ s →
Type G s
data Term G s where
var : Var G s → Term G s
lam'' : {t : _} {u : _} →
Term (snoc G t) (uncurry u) →
(λ g → pi (t g) (λ v → u g v)) ≡ s →
Term G s
app'' : {t : _} {u : (g : Env G) → El (t g) → U} →
Term G (λ g → pi (t g) (λ v → u g v)) →
(t2 : Term G t) →
(λ g → u g (eval t2 g)) ≡ s →
Term G s
eval (var x) g = lookup _ _ x g
eval (lam'' t refl) g = λ v → eval t (g , v)
eval (app'' t1 t2 refl) g = eval t1 g (eval t2 g)
-- Abbreviations.
set' : {G : Ctxt} → Type G (λ _ → set)
set' = set'' refl
el' : {G : Ctxt}
(x : Term G (λ _ → set)) →
Type G (λ g → el (eval {G} {λ _ → set} x g))
el' x = el'' x refl
sigma' : {G : Ctxt} {t : Env G → U} {u : Env (snoc G t) → U} →
Type G t →
Type (snoc G t) u →
Type G (λ g → sigma (t g) (λ v → u (g , v)))
sigma' s t = sigma'' s t refl
pi' : {G : _} {t : _} {u : _} →
Type G t →
Type (snoc G t) u →
Type G (λ g → pi (t g) (λ v → u (g , v)))
pi' s t = pi'' s t refl
lam : {G : _} {t : _} {u : _} →
Term (snoc G t) (uncurry u) →
Term G (λ g → pi (t g) (λ v → u g v))
lam t = lam'' t refl
app : {G : _} {t : _} {u : (g : Env G) → El (t g) → U} →
Term G (λ g → pi (t g) (λ v → u g v)) →
(t2 : Term G t) →
Term G (λ g → u g (eval t2 g))
app t1 t2 = app'' t1 t2 refl
-- Example.
raw-categoryU : U
raw-categoryU =
sigma set (λ obj →
sigma (fun (el obj) (fun (el obj) set)) (λ hom →
times
(pi (el obj) (λ x → el (hom x x)))
(pi (el obj) (λ x → el (hom x x)))))
raw-category : Type empty (λ _ → raw-categoryU)
raw-category =
-- Objects.
sigma' set'
-- Morphisms.
(sigma' (pi' (el' (var zero)) (pi' (el' (var (suc zero))) set'))
-- Identity.
(sigma' (pi' (el' (var (suc zero)))
(el' (app (app (var (suc zero)) (var zero)) (var zero))))
(pi' (el' (var (suc (suc zero))))
(el' (app (app (var (suc (suc zero))) (var zero)) (var zero))))))
| {
"alphanum_fraction": 0.4261417925,
"avg_line_length": 24.5680751174,
"ext": "agda",
"hexsha": "4e8766da2f5e2d58c6094f30b6b937ad89e87b8b",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/CompileTimeInlining.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/CompileTimeInlining.agda",
"max_line_length": 80,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/CompileTimeInlining.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 1924,
"size": 5233
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Structures.Semigroup where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Transport
open import Cubical.Foundations.SIP
open import Cubical.Data.Sigma
open import Cubical.Structures.Axioms
open import Cubical.Structures.Auto
open Iso
private
variable
ℓ : Level
-- Semigroups as a record, inspired by the Agda standard library:
--
-- https://github.com/agda/agda-stdlib/blob/master/src/Algebra/Bundles.agda#L48
-- https://github.com/agda/agda-stdlib/blob/master/src/Algebra/Structures.agda#L50
--
-- Note that as we are using Path for all equations the IsMagma record
-- would only contain isSet A if we had it.
record IsSemigroup {A : Type ℓ} (_·_ : A → A → A) : Type ℓ where
-- TODO: add no-eta-equality for efficiency? This breaks some proofs later
constructor issemigroup
field
is-set : isSet A
assoc : (x y z : A) → x · (y · z) ≡ (x · y) · z
record Semigroup : Type (ℓ-suc ℓ) where
constructor semigroup
field
Carrier : Type ℓ
_·_ : Carrier → Carrier → Carrier
isSemigroup : IsSemigroup _·_
infixl 7 _·_
open IsSemigroup isSemigroup public
-- Extractor for the carrier type
⟨_⟩ : Semigroup → Type ℓ
⟨_⟩ = Semigroup.Carrier
record SemigroupEquiv (M N : Semigroup {ℓ}) : Type ℓ where
constructor semigroupequiv
-- Shorter qualified names
private
module M = Semigroup M
module N = Semigroup N
field
e : ⟨ M ⟩ ≃ ⟨ N ⟩
isHom : (x y : ⟨ M ⟩) → equivFun e (x M.· y) ≡ equivFun e x N.· equivFun e y
-- Develop some theory about Semigroups using various general results
-- that are stated using Σ-types. For this we define Semigroup as a
-- nested Σ-type, prove that it's equivalent to the above record
-- definition and then transport results along this equivalence.
module SemigroupΣTheory {ℓ} where
RawSemigroupStructure : Type ℓ → Type ℓ
RawSemigroupStructure X = X → X → X
RawSemigroupEquivStr = AutoEquivStr RawSemigroupStructure
rawSemigroupUnivalentStr : UnivalentStr _ RawSemigroupEquivStr
rawSemigroupUnivalentStr = autoUnivalentStr RawSemigroupStructure
SemigroupAxioms : (A : Type ℓ) → RawSemigroupStructure A → Type ℓ
SemigroupAxioms A _·_ = isSet A
× ((x y z : A) → x · (y · z) ≡ (x · y) · z)
SemigroupStructure : Type ℓ → Type ℓ
SemigroupStructure = AxiomsStructure RawSemigroupStructure SemigroupAxioms
SemigroupΣ : Type (ℓ-suc ℓ)
SemigroupΣ = TypeWithStr ℓ SemigroupStructure
isPropSemigroupAxioms : (A : Type ℓ) (_·_ : RawSemigroupStructure A)
→ isProp (SemigroupAxioms A _·_)
isPropSemigroupAxioms _ _ = isPropΣ isPropIsSet λ isSetA → isPropΠ3 λ _ _ _ → isSetA _ _
SemigroupEquivStr : StrEquiv SemigroupStructure ℓ
SemigroupEquivStr = AxiomsEquivStr RawSemigroupEquivStr SemigroupAxioms
SemigroupAxiomsIsoIsSemigroup : {A : Type ℓ} (_·_ : RawSemigroupStructure A)
→ Iso (SemigroupAxioms A _·_) (IsSemigroup _·_)
fun (SemigroupAxiomsIsoIsSemigroup s) (x , y) = issemigroup x y
inv (SemigroupAxiomsIsoIsSemigroup s) (issemigroup x y) = (x , y)
rightInv (SemigroupAxiomsIsoIsSemigroup s) _ = refl
leftInv (SemigroupAxiomsIsoIsSemigroup s) _ = refl
SemigroupAxioms≡IsSemigroup : {A : Type ℓ} (_·_ : RawSemigroupStructure A)
→ SemigroupAxioms _ _·_ ≡ IsSemigroup _·_
SemigroupAxioms≡IsSemigroup s = isoToPath (SemigroupAxiomsIsoIsSemigroup s)
Semigroup→SemigroupΣ : Semigroup → SemigroupΣ
Semigroup→SemigroupΣ (semigroup A _·_ isSemigroup) =
A , _·_ , SemigroupAxiomsIsoIsSemigroup _ .inv isSemigroup
SemigroupΣ→Semigroup : SemigroupΣ → Semigroup
SemigroupΣ→Semigroup (A , _·_ , isSemigroupΣ) =
semigroup A _·_ (SemigroupAxiomsIsoIsSemigroup _ .fun isSemigroupΣ)
SemigroupIsoSemigroupΣ : Iso Semigroup SemigroupΣ
SemigroupIsoSemigroupΣ =
iso Semigroup→SemigroupΣ SemigroupΣ→Semigroup (λ _ → refl) (λ _ → refl)
semigroupUnivalentStr : UnivalentStr SemigroupStructure SemigroupEquivStr
semigroupUnivalentStr = axiomsUnivalentStr _ isPropSemigroupAxioms rawSemigroupUnivalentStr
SemigroupΣPath : (M N : SemigroupΣ) → (M ≃[ SemigroupEquivStr ] N) ≃ (M ≡ N)
SemigroupΣPath = SIP semigroupUnivalentStr
SemigroupEquivΣ : (M N : Semigroup) → Type ℓ
SemigroupEquivΣ M N = Semigroup→SemigroupΣ M ≃[ SemigroupEquivStr ] Semigroup→SemigroupΣ N
SemigroupIsoΣPath : {M N : Semigroup} → Iso (SemigroupEquiv M N) (SemigroupEquivΣ M N)
fun SemigroupIsoΣPath (semigroupequiv e h) = (e , h)
inv SemigroupIsoΣPath (e , h) = semigroupequiv e h
rightInv SemigroupIsoΣPath _ = refl
leftInv SemigroupIsoΣPath _ = refl
SemigroupPath : (M N : Semigroup) → (SemigroupEquiv M N) ≃ (M ≡ N)
SemigroupPath M N =
SemigroupEquiv M N ≃⟨ isoToEquiv SemigroupIsoΣPath ⟩
SemigroupEquivΣ M N ≃⟨ SemigroupΣPath _ _ ⟩
Semigroup→SemigroupΣ M ≡ Semigroup→SemigroupΣ N ≃⟨ isoToEquiv (invIso (congIso SemigroupIsoSemigroupΣ)) ⟩
M ≡ N ■
-- We now extract the important results from the above module
isPropIsSemigroup : {A : Type ℓ} (_·_ : A → A → A) → isProp (IsSemigroup _·_)
isPropIsSemigroup _·_ =
subst isProp (SemigroupΣTheory.SemigroupAxioms≡IsSemigroup _·_)
(SemigroupΣTheory.isPropSemigroupAxioms _ _·_)
SemigroupPath : (M N : Semigroup {ℓ}) → (SemigroupEquiv M N) ≃ (M ≡ N)
SemigroupPath = SemigroupΣTheory.SemigroupPath
-- To rename the fields when using a Semigroup use for example the following:
--
-- open Semigroup M renaming ( Carrier to M ; _·_ to _·M_ )
| {
"alphanum_fraction": 0.7079959514,
"avg_line_length": 36.5925925926,
"ext": "agda",
"hexsha": "146c4481cca6ed72b6c3ffccfd8f34aa9210b565",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "RobertHarper/cubical",
"max_forks_repo_path": "Cubical/Structures/Semigroup.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "RobertHarper/cubical",
"max_issues_repo_path": "Cubical/Structures/Semigroup.agda",
"max_line_length": 109,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "RobertHarper/cubical",
"max_stars_repo_path": "Cubical/Structures/Semigroup.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1924,
"size": 5928
} |
{-# OPTIONS --without-K #-}
open import Function.Related.TypeIsomorphisms.NP
open import Function.Inverse.NP
open import Data.Maybe.NP
open import Data.Nat
open import Explore.Type
open import Explore.Explorable
open import Explore.Sum
module Explore.Explorable.Maybe where
μMaybe : ∀ {A} → Explorable A → Explorable (Maybe A)
μMaybe μA = μ-iso (sym Maybe↔𝟙⊎) (μ𝟙 ⊎-μ μA)
μMaybe^ : ∀ {A} n → Explorable A → Explorable (Maybe^ n A)
μMaybe^ zero μA = μA
μMaybe^ (suc n) μA = μMaybe (μMaybe^ n μA)
| {
"alphanum_fraction": 0.719123506,
"avg_line_length": 26.4210526316,
"ext": "agda",
"hexsha": "2e309a94689a9df1dcf90d9091d70dfd503f504d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "crypto-agda/explore",
"max_forks_repo_path": "lib/Explore/Experimental/Maybe.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_issues_repo_issues_event_max_datetime": "2019-03-16T14:24:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-03-16T14:24:04.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "crypto-agda/explore",
"max_issues_repo_path": "lib/Explore/Experimental/Maybe.agda",
"max_line_length": 58,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "crypto-agda/explore",
"max_stars_repo_path": "lib/Explore/Experimental/Maybe.agda",
"max_stars_repo_stars_event_max_datetime": "2017-06-28T19:19:29.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-05T09:25:32.000Z",
"num_tokens": 169,
"size": 502
} |
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary.Core
module Loop.Definitions
{a ℓ} {A : Set a} -- The underlying set
(_≈_ : Rel A ℓ) -- The underlying equality
where
open import Algebra.Core
open import Data.Product
LeftBol : Op₂ A → Set _
LeftBol _∙_ = ∀ x y z → (x ∙ (y ∙ (x ∙ z))) ≈ ((x ∙ (y ∙ z)) ∙ z )
RightBol : Op₂ A → Set _
RightBol _∙_ = ∀ x y z → (((z ∙ x) ∙ y) ∙ x) ≈ (z ∙ ((x ∙ y) ∙ x))
MoufangIdentity₁ : Op₂ A → Set _
MoufangIdentity₁ _∙_ = ∀ x y z → (z ∙ (x ∙ (z ∙ y))) ≈ (((z ∙ x) ∙ z) ∙ y)
MoufangIdentity₂ : Op₂ A → Set _
MoufangIdentity₂ _∙_ = ∀ x y z → (x ∙ (z ∙ (y ∙ z))) ≈ (((x ∙ z) ∙ y) ∙ z)
MoufangIdentity₃ : Op₂ A → Set _
MoufangIdentity₃ _∙_ = ∀ x y z → ((z ∙ x) ∙ (y ∙ z)) ≈ ((z ∙ (x ∙ y)) ∙ z)
MoufangIdentity₄ : Op₂ A → Set _
MoufangIdentity₄ _∙_ = ∀ x y z → ((z ∙ x) ∙ (y ∙ z)) ≈ (z ∙ ((x ∙ y) ∙ z))
| {
"alphanum_fraction": 0.5172413793,
"avg_line_length": 28.064516129,
"ext": "agda",
"hexsha": "fae84ca0184d4f0e1d9a8aa9d36cf76b9208a479",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "443e831e536b756acbd1afd0d6bae7bc0d288048",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Akshobhya1234/agda-NonAssociativeAlgebra",
"max_forks_repo_path": "src/Loop/Definitions.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "443e831e536b756acbd1afd0d6bae7bc0d288048",
"max_issues_repo_issues_event_max_datetime": "2021-10-09T08:24:56.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-04T05:30:30.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Akshobhya1234/agda-NonAssociativeAlgebra",
"max_issues_repo_path": "src/Loop/Definitions.agda",
"max_line_length": 76,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "443e831e536b756acbd1afd0d6bae7bc0d288048",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Akshobhya1234/agda-NonAssociativeAlgebra",
"max_stars_repo_path": "src/Loop/Definitions.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-17T09:14:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-08-15T06:16:13.000Z",
"num_tokens": 408,
"size": 870
} |
module UninstantiatedDotPattern where
f : Set -> Set -> Set
f .X X = X
| {
"alphanum_fraction": 0.6621621622,
"avg_line_length": 10.5714285714,
"ext": "agda",
"hexsha": "943c6b5612ab8f3be8f5259ee7e6b3c2254fbbc0",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/UninstantiatedDotPattern.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/UninstantiatedDotPattern.agda",
"max_line_length": 37,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/UninstantiatedDotPattern.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 24,
"size": 74
} |
{-# OPTIONS --universe-polymorphism #-}
module Categories.Opposite where
-- some properties of the opposite category.
-- XXX these should probably go somewhere else, but everywhere i think of
-- has other problems. ☹
open import Categories.Category
open import Categories.Functor
open import Categories.FunctorCategory
open import Categories.NaturalTransformation
open import Categories.Morphisms renaming (_≅_ to _[_≅_])
opⁱ : ∀ {o ℓ e} {C : Category o ℓ e} {A B} → C [ A ≅ B ] → Category.op C [ B ≅ A ]
opⁱ {C = C} A≅B = record
{ f = A≅B.f
; g = A≅B.g
; iso = record { isoˡ = A≅B.isoʳ; isoʳ = A≅B.isoˡ }
}
where
module A≅B = Categories.Morphisms._≅_ A≅B
opF : ∀ {o₁ ℓ₁ e₁ o₂ ℓ₂ e₂} {A : Category o₁ ℓ₁ e₁} {B : Category o₂ ℓ₂ e₂} ->
(Functor (Category.op (Functors (Category.op A) (Category.op B))) (Functors A B))
opF {A = A} {B} = record {
F₀ = Functor.op;
F₁ = NaturalTransformation.op;
identity = Category.Equiv.refl B;
homomorphism = Category.Equiv.refl B;
F-resp-≡ = λ x → x }
| {
"alphanum_fraction": 0.6112115732,
"avg_line_length": 35.6774193548,
"ext": "agda",
"hexsha": "a6db0f016db992d8bdb39f41eb9014a576995f7f",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/Opposite.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Categories/Opposite.agda",
"max_line_length": 85,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Categories/Opposite.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 359,
"size": 1106
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
-- a zero object is both terminal and initial.
module Categories.Object.Zero {o ℓ e} (C : Category o ℓ e) where
open import Level using (_⊔_)
open import Categories.Object.Terminal C
open import Categories.Object.Initial C
open Category C
record Zero : Set (o ⊔ ℓ ⊔ e) where
field
zero : Obj
! : ∀ {A} → zero ⇒ A
¡ : ∀ {A} → A ⇒ zero
field
!-unique : ∀ {A} (f : zero ⇒ A) → ! ≈ f
¡-unique : ∀ {A} (f : A ⇒ zero) → ¡ ≈ f
initial : Initial
initial = record
{ ⊥ = zero
; ! = !
; !-unique = !-unique
}
terminal : Terminal
terminal = record
{ ⊤ = zero
; ! = ¡
; !-unique = ¡-unique
}
module initial = Initial initial
module terminal = Terminal terminal
| {
"alphanum_fraction": 0.5650557621,
"avg_line_length": 19.6829268293,
"ext": "agda",
"hexsha": "dd9633f1b7e6e15efc46352fd0179aa4160a18f2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MirceaS/agda-categories",
"max_forks_repo_path": "src/Categories/Object/Zero.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "MirceaS/agda-categories",
"max_issues_repo_path": "src/Categories/Object/Zero.agda",
"max_line_length": 64,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MirceaS/agda-categories",
"max_stars_repo_path": "src/Categories/Object/Zero.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 250,
"size": 807
} |
open import Data.Product using ( _×_ ; _,_ )
open import Relation.Unary using ( _∈_ )
open import Web.Semantic.DL.ABox using ( ABox )
open import Web.Semantic.DL.Signature using ( Signature )
open import Web.Semantic.DL.TBox using ( TBox )
open import Web.Semantic.Util using ( Finite )
module Web.Semantic.DL.Category.Object {Σ : Signature} where
infixr 4 _,_
{-
This Object represents a Knowledge Base (schema + facts) with constraints.
It is defined over two TBoxes on the same Signature Σ
S is the standard TBox - i.e. a schema
T is the consTraint TBox - constraints on the facts A below
It is built from
A is a set of ABox facts over a finite set of variables
see "Integrity Constraints for Linked Data"
and especially the reference from there to Definition 1 p11 of
"Bridging the Gap between OWL and Relational Databases"
by Boris Motik, Ian Horrocks and Ulrike Sattler
-}
data Object (S T : TBox Σ) : Set₁ where
_,_ : ∀ X → (X ∈ Finite × ABox Σ X) → Object S T
-- Interface Names, the nodes that can be used by other ABoxes
IN : ∀ {S T} → Object S T → Set
IN (X , X∈Fin , A) = X
-- the proof that X is finite
fin : ∀ {S T} → (A : Object S T) → (IN A ∈ Finite)
fin (X , X∈Fin , A) = X∈Fin
{- An ABox thought of as an interface
(language from "§3 Initial Interpretation" of
"Integrity Constraints for Linked Data" )
The idea is that an ABox either creates nodes
that can be used by others or it uses nodes from
other ABoxes, and so it provides an interface to others -}
iface : ∀ {S T} → (A : Object S T) → (ABox Σ (IN A))
iface (X , X∈Fin , A) = A
| {
"alphanum_fraction": 0.703680203,
"avg_line_length": 36.6511627907,
"ext": "agda",
"hexsha": "a2cdf6f860ec6b7f1695cf17a3d02660a6196847",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bblfish/agda-web-semantic",
"max_forks_repo_path": "src/Web/Semantic/DL/Category/Object.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bblfish/agda-web-semantic",
"max_issues_repo_path": "src/Web/Semantic/DL/Category/Object.agda",
"max_line_length": 74,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bblfish/agda-web-semantic",
"max_stars_repo_path": "src/Web/Semantic/DL/Category/Object.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-22T09:43:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-22T09:43:23.000Z",
"num_tokens": 480,
"size": 1576
} |
module sn-calculus-compatconf.pot where
open import can-function-preserve
using (canₖ-monotonic ; canₛ-monotonic ; canₛₕ-monotonic)
open import sn-calculus
open import utility renaming (_U̬_ to _∪_)
open import context-properties
using (->pot-view)
open import Esterel.Lang
open import Esterel.Lang.Binding
open import Esterel.Lang.CanFunction
using (Can ; Canₛ ; Canₛₕ ; Canₖ ; Canθ ; Canθₛ ; Canθₛₕ ; Canθₖ)
open import Esterel.Lang.CanFunction.Properties
open import Esterel.Environment as Env
using (Env ; Θ ; _←_ ; Dom ; module SigMap ; module ShrMap ; module VarMap)
open import Esterel.Context
using (Context ; Context1 ; _⟦_⟧c ; _≐_⟦_⟧c)
open import Esterel.Context.Properties
using (unplugc)
open import Esterel.CompletionCode as Code
using () renaming (CompletionCode to Code)
open import Esterel.Variable.Signal as Signal
using (Signal ; _ₛ)
open import Esterel.Variable.Shared as SharedVar
using (SharedVar ; _ₛₕ)
open import Esterel.Variable.Sequential as SeqVar
using (SeqVar ; _ᵥ)
open import Relation.Nullary
using (¬_ ; Dec ; yes ; no)
open import Relation.Binary.PropositionalEquality
using (_≡_ ; refl ; sym ; cong ; trans ; subst ; module ≡-Reasoning)
open import Data.Bool
using (Bool ; if_then_else_)
open import Data.Empty
using (⊥ ; ⊥-elim)
open import Data.List
using (List ; _∷_ ; [] ; _++_)
open import Data.List.Any
using (Any ; any ; here ; there)
open import Data.List.Any.Properties
using ()
renaming (++⁺ˡ to ++ˡ ; ++⁺ʳ to ++ʳ)
open import Data.Maybe
using (Maybe ; just ; nothing)
open import Data.Nat
using (ℕ ; zero ; suc ; _+_) renaming (_⊔_ to _⊔ℕ_)
open import Data.Product
using (Σ-syntax ; Σ ; _,_ ; _,′_ ; proj₁ ; proj₂ ; _×_ ; ∃)
open import Data.Sum
using (_⊎_ ; inj₁ ; inj₂)
open import Function using (_∘_ ; id ; _∋_)
open import Data.OrderedListMap Signal Signal.unwrap Signal.Status as SigM
open import Data.OrderedListMap SharedVar SharedVar.unwrap (Σ SharedVar.Status (λ _ → ℕ)) as ShrM
open import Data.OrderedListMap SeqVar SeqVar.unwrap ℕ as SeqM
open ->pot-view
open Context1
open _≐_⟦_⟧c
{-
(p)
ρθ. C⟦pin⟧ -- sn⟶₁ -> ρθ' C⟦pin⟧
(ρθ) C⟦pin⟧ -- sn⟶₁ -> (ρθ) C⟦qin⟧
-}
1-steplρ-pot-lemma : ∀{C θ p pin qin θ' BV FV A} →
{ρθpsn⟶₁ρθ'p : ρ⟨ θ , A ⟩· p sn⟶₁ ρ⟨ θ' , A ⟩· p} →
->pot-view ρθpsn⟶₁ρθ'p refl refl →
CorrectBinding pin BV FV →
p ≐ C ⟦ pin ⟧c →
pin sn⟶₁ qin →
ρ⟨ θ , A ⟩· C ⟦ qin ⟧c sn⟶₁ ρ⟨ θ' , A ⟩· C ⟦ qin ⟧c
1-steplρ-pot-lemma {C} {θ} {_} {pin} {qin}
{ρθpsn⟶₁ρθ'p = .(rabsence {S = S} S∈ θS≡unknown S∉can-p-θ)}
(vabsence S S∈ θS≡unknown S∉can-p-θ)
cb p≐C⟦pin⟧ pinsn⟶₁qin with sym (unplugc p≐C⟦pin⟧)
... | refl
= rabsence {S = S} S∈ θS≡unknown
(λ S∈can-q-θ →
S∉can-p-θ
(canθₛ-plug 0 (Env.sig θ) C pin qin
(λ θ* → canₛ-monotonic θ* _ _ cb pinsn⟶₁qin ∘ _ₛ)
(λ θ* → canₖ-monotonic θ* _ _ cb pinsn⟶₁qin)
Env.[]env (Signal.unwrap S) S∈can-q-θ))
1-steplρ-pot-lemma {C} {θ} {_} {pin} {qin}
{ρθpsn⟶₁ρθ'p = .(rreadyness {s = s} s∈ θs≡old⊎θs≡new s∉can-p-θ)}
(vreadyness {θ = .θ} s s∈ θs≡old⊎θs≡new s∉can-p-θ)
cb p≐C⟦pin⟧ pinsn⟶₁qin with sym (unplugc p≐C⟦pin⟧)
... | refl
= rreadyness {s = s} s∈ θs≡old⊎θs≡new
(λ s∈can-q-θ →
s∉can-p-θ
(canθₛₕ-plug 0 (Env.sig θ) C pin qin
(λ θ* → canₛₕ-monotonic θ* _ _ cb pinsn⟶₁qin ∘ _ₛₕ)
(λ θ* → canₖ-monotonic θ* _ _ cb pinsn⟶₁qin)
(λ θ* → canₛ-monotonic θ* _ _ cb pinsn⟶₁qin ∘ _ₛ)
Env.[]env (SharedVar.unwrap s)
s∈can-q-θ))
-- Wrapper around 1-steplρ-pot-lemma.
1-steplρ-pot : ∀{p q θ θ' BV FV A} →
{ρθpsn⟶₁ρθ'p : ρ⟨ θ , A ⟩· p sn⟶₁ ρ⟨ θ' , A ⟩· p} →
CorrectBinding (ρ⟨ θ , A ⟩· p) BV FV →
->pot-view ρθpsn⟶₁ρθ'p refl refl →
p sn⟶ q →
(ρ⟨ θ' , A ⟩· p sn⟶* ρ⟨ θ' , A ⟩· q ×
ρ⟨ θ , A ⟩· q sn⟶* ρ⟨ θ' , A ⟩· q)
1-steplρ-pot cb@(CBρ cb') pot psn⟶q@(rcontext _ p≐C⟦pin⟧ pinsn⟶₁qin) =
sn⟶*-inclusion (rcontext _ (dcenv p≐C⟦pin⟧) pinsn⟶₁qin) ,′
sn⟶*-inclusion
(sn⟶-inclusion
(1-steplρ-pot-lemma pot
(proj₂ (binding-extractc' cb' p≐C⟦pin⟧))
p≐C⟦pin⟧ pinsn⟶₁qin))
| {
"alphanum_fraction": 0.6169393648,
"avg_line_length": 32.2170542636,
"ext": "agda",
"hexsha": "7c347bbcde4ba3259ecc12ce4c6cac3ed55b24eb",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "florence/esterel-calculus",
"max_forks_repo_path": "agda/sn-calculus-compatconf/pot.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "florence/esterel-calculus",
"max_issues_repo_path": "agda/sn-calculus-compatconf/pot.agda",
"max_line_length": 97,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "florence/esterel-calculus",
"max_stars_repo_path": "agda/sn-calculus-compatconf/pot.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-01T03:59:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T10:58:53.000Z",
"num_tokens": 1856,
"size": 4156
} |
{-# OPTIONS --safe #-}
open import Cubical.Foundations.Prelude
open import Cubical.Categories.Category.Base
open import Cubical.Categories.Monoidal.Base
open import Cubical.Categories.Instances.Functors
open import Cubical.Categories.Functor.Base renaming (𝟙⟨_⟩ to idfunctor)
open import Cubical.Categories.NaturalTransformation.Base
open import Cubical.Categories.NaturalTransformation.Properties
module Cubical.Categories.Instances.Functors.Endo {ℓC ℓC'} (C : Category ℓC ℓC') where
open Category
open NatTrans
open Functor
open StrictMonStr
open TensorStr
EndofunctorCategory : Category (ℓ-max ℓC ℓC') (ℓ-max ℓC ℓC')
EndofunctorCategory = FUNCTOR C C
| {
"alphanum_fraction": 0.8005952381,
"avg_line_length": 32,
"ext": "agda",
"hexsha": "2c4180e80d2078353c84af80b7400d17afc6d0ee",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Categories/Instances/Functors/Endo.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Categories/Instances/Functors/Endo.agda",
"max_line_length": 86,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Categories/Instances/Functors/Endo.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z",
"num_tokens": 184,
"size": 672
} |
{-# OPTIONS -v impossible:10 #-}
module ImpossibleVerbose where
-- The only way to trigger an __IMPOSSIBLE__ that isn't a bug.
{-# IMPOSSIBLE This message should be debug-printed with option '-v impossible:10'. #-}
| {
"alphanum_fraction": 0.732718894,
"avg_line_length": 31,
"ext": "agda",
"hexsha": "90045df137111471e2582feb3f24abdbae75516c",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "cagix/agda",
"max_forks_repo_path": "test/Fail/ImpossibleVerbose.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "cagix/agda",
"max_issues_repo_path": "test/Fail/ImpossibleVerbose.agda",
"max_line_length": 87,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "cagix/agda",
"max_stars_repo_path": "test/Fail/ImpossibleVerbose.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 53,
"size": 217
} |
module nodcap.NF.CutND where
open import Algebra
open import Category.Monad
open import Data.Nat as ℕ using (ℕ; suc; zero)
open import Data.Pos as ℕ⁺
open import Data.List as L using (List; []; _∷_; _++_; map)
open import Data.List.Any as LA using (Any; here; there)
open import Data.List.Any.BagAndSetEquality as B
open import Data.Product as PR using (∃; _×_; _,_; proj₁; proj₂)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Function using (_$_; _∘_; flip)
open import Function.Equality using (_⟨$⟩_)
open import Function.Inverse as I using ()
open import Relation.Binary.PropositionalEquality as P using (_≡_; _≢_)
open import Data.Environment
open import nodcap.Base
open import nodcap.NF.Typing
open import nodcap.NF.Contract
open import nodcap.NF.Expand
open import nodcap.NF.Cut
open I.Inverse using (to; from)
private
open module LM {ℓ} = RawMonadPlus (L.monadPlus {ℓ})
private module ++ {a} {A : Set a} = Monoid (L.monoid A)
{-# TERMINATING #-}
-- Theorem:
-- Nondeterministic cut elimination.
mutual
cutND : {Γ Δ : Environment} {A : Type} →
⊢ⁿᶠ A ∷ Γ → ⊢ⁿᶠ A ^ ∷ Δ →
---------------------
List (⊢ⁿᶠ Γ ++ Δ)
cutND {_} {Δ} {A = 𝟏} halt (wait y)
= return y
cutND {Γ} {_} {A = ⊥} (wait x) halt
= return
$ P.subst ⊢ⁿᶠ_ (P.sym (proj₂ ++.identity Γ)) x
cutND {_} {Θ} {A = A ⊗ B} (send {Γ} {Δ} x y) (recv z)
= return
∘ P.subst ⊢ⁿᶠ_ (P.sym (++.assoc Γ Δ Θ))
∘ exch (swp [] Γ Δ)
=<< cutND y
∘ exch (fwd [] Γ)
=<< cutND x z
cutND {Θ} {_} {A = A ⅋ B} (recv x) (send {Γ} {Δ} y z)
= return
∘ P.subst ⊢ⁿᶠ_ (++.assoc Θ Γ Δ)
=<< flip cutND z
=<< cutND x y
cutND {Γ} {Δ} {A = A ⊕ B} (sel₁ x) (case y z)
= cutND x y
cutND {Γ} {Δ} {A = A ⊕ B} (sel₂ x) (case y z)
= cutND x z
cutND {Γ} {Δ} {A = A & B} (case x y) (sel₁ z)
= cutND x z
cutND {Γ} {Δ} {A = A & B} (case x y) (sel₂ z)
= cutND y z
cutND {Γ} {Δ} {A = ![ n ] A} x y
= all (replicate⁺ n (A ^)) >>= return ∘ withPerm ∘ proj₂
where
withPerm : {Θ : Environment} → replicate⁺ n (A ^) ∼[ bag ] Θ → ⊢ⁿᶠ Γ ++ Δ
withPerm {Θ} b
= cut x
$ contract
$ exch (B.++-cong (P.subst (_ ∼[ bag ]_) (all-replicate⁺ n (I.sym b)) b) I.id)
$ expand y
cutND {Γ} {Δ} {A = ?[ n ] A} x y
= all (replicate⁺ n A) >>= return ∘ withPerm ∘ proj₂
where
withPerm : {Θ : Environment} → replicate⁺ n A ∼[ bag ] Θ → ⊢ⁿᶠ Γ ++ Δ
withPerm {Θ} b
= exch (swp₂ Γ)
$ cut y
$ P.subst (λ A → ⊢ⁿᶠ ?[ n ] A ∷ Γ) (P.sym (^-inv A))
$ contract
$ exch (B.++-cong (P.subst (_ ∼[ bag ]_) (all-replicate⁺ n (I.sym b)) b) I.id)
$ expand x
cutND {Γ} {Δ} {A} (exch b x) y
= return
∘ exch (B.++-cong {ys₁ = Δ} (del-from b (here P.refl)) I.id)
=<< cutNDIn (from b ⟨$⟩ here P.refl) (here P.refl) x y
cutND {Γ} {Δ} {A} x (exch b y)
= return
∘ exch (B.++-cong {xs₁ = Γ} I.id (del-from b (here P.refl)))
=<< cutNDIn (here P.refl) (from b ⟨$⟩ here P.refl) x y
cutNDIn : {Γ Δ : Environment} {A : Type} (i : A ∈ Γ) (j : A ^ ∈ Δ) →
⊢ⁿᶠ Γ → ⊢ⁿᶠ Δ →
-----------------------
List (⊢ⁿᶠ Γ - i ++ Δ - j)
cutNDIn (here P.refl) (here P.refl) x y = cutND x y
cutNDIn {_} {Θ} (there i) j (send {Γ} {Δ} x y) z
with split Γ i
... | inj₁ (k , p) rewrite p
= return
∘ P.subst ⊢ⁿᶠ_ (P.sym (++.assoc (_ ∷ Γ - k) Δ (Θ - j)))
∘ exch (swp₃ (_ ∷ Γ - k) Δ)
∘ P.subst ⊢ⁿᶠ_ (++.assoc (_ ∷ Γ - k) (Θ - j) Δ)
∘ flip send y
=<< cutNDIn (there k) j x z
... | inj₂ (k , p) rewrite p
= return
∘ P.subst ⊢ⁿᶠ_ (P.sym (++.assoc (_ ∷ Γ) (Δ - k) (Θ - j)))
∘ send x
=<< cutNDIn (there k) j y z
cutNDIn (there i) j (recv x) y
= return
∘ recv
=<< cutNDIn (there (there i)) j x y
cutNDIn (there i) j (sel₁ x) y
= return
∘ sel₁
=<< cutNDIn (there i) j x y
cutNDIn (there i) j (sel₂ x) y
= return
∘ sel₂
=<< cutNDIn (there i) j x y
cutNDIn (there i) j (case x y) z
= cutNDIn (there i) j x z >>= λ xz
→ cutNDIn (there i) j y z >>= λ yz
→ return
$ case xz yz
cutNDIn (there ()) j halt y
cutNDIn (there i) j (wait x) y
= return
∘ wait
=<< cutNDIn i j x y
cutNDIn (there i) j loop y
= return
$ loop
cutNDIn {Γ} {Δ} (there i) j (mk?₁ x) y
= return
∘ mk?₁
=<< cutNDIn (there i) j x y
cutNDIn {Γ} {Δ} (there i) j (mk!₁ x) y
= return
∘ mk!₁
=<< cutNDIn (there i) j x y
cutNDIn {Γ} {Δ} (there i) j (cont x) y
= return
∘ cont
=<< cutNDIn (there (there i)) j x y
cutNDIn {_} {Θ} (there i) j (pool {Γ} {Δ} x y) z
with split Γ i
... | inj₁ (k , p) rewrite p
= return
∘ P.subst ⊢ⁿᶠ_ (P.sym (++.assoc (_ ∷ Γ - k) Δ (Θ - j)))
∘ exch (swp₃ (_ ∷ Γ - k) Δ)
∘ P.subst ⊢ⁿᶠ_ (++.assoc (_ ∷ Γ - k) (Θ - j) Δ)
∘ flip pool y
=<< cutNDIn (there k) j x z
... | inj₂ (k , p) rewrite p
= return
∘ P.subst ⊢ⁿᶠ_ (P.sym (++.assoc (_ ∷ Γ) (Δ - k) (Θ - j)))
∘ pool x
=<< cutNDIn (there k) j y z
cutNDIn {Θ} {_} i (there j) x (send {Γ} {Δ} y z)
with split Γ j
... | inj₁ (k , p) rewrite p
= return
∘ exch (bwd [] (Θ - i))
∘ P.subst ⊢ⁿᶠ_ (++.assoc (_ ∷ Θ - i) (Γ - k) Δ)
∘ flip send z
∘ exch (fwd [] (Θ - i))
=<< cutNDIn i (there k) x y
... | inj₂ (k , p) rewrite p
= return
∘ exch (swp [] (Θ - i) (_ ∷ Γ))
∘ send y
∘ exch (fwd [] (Θ - i))
=<< cutNDIn i (there k) x z
cutNDIn {Γ} i (there j) x (recv {Δ} y)
= return
∘ exch (bwd [] (Γ - i))
∘ recv
∘ exch (swp [] (_ ∷ _ ∷ []) (Γ - i))
=<< cutNDIn i (there (there j)) x y
cutNDIn {Γ} {Δ} i (there j) x (sel₁ y)
= return
∘ exch (bwd [] (Γ - i))
∘ sel₁
∘ exch (fwd [] (Γ - i))
=<< cutNDIn i (there j) x y
cutNDIn {Γ} {Δ} i (there j) x (sel₂ y)
= return
∘ exch (bwd [] (Γ - i))
∘ sel₂
∘ exch (fwd [] (Γ - i))
=<< cutNDIn i (there j) x y
cutNDIn {Γ} {Δ} i (there j) x (case y z)
= cutNDIn i (there j) x y >>= λ xy
→ cutNDIn i (there j) x z >>= λ xz
→ return
$ exch (bwd [] (Γ - i))
$ case
( exch (fwd [] (Γ - i)) xy )
( exch (fwd [] (Γ - i)) xz )
cutNDIn {Γ} i (there ()) x halt
cutNDIn {Γ} {Δ} i (there j) x (wait y)
= return
∘ exch (bwd [] (Γ - i))
∘ wait
=<< cutNDIn i j x y
cutNDIn {Γ} {Δ} i (there j) x loop
= return
∘ exch (bwd [] (Γ - i))
$ loop
cutNDIn {Γ} {Δ} i (there j) x (mk?₁ y)
= return
∘ exch (bwd [] (Γ - i))
∘ mk?₁
∘ exch (fwd [] (Γ - i))
=<< cutNDIn i (there j) x y
cutNDIn {Γ} {Δ} i (there j) x (mk!₁ y)
= return
∘ exch (bwd [] (Γ - i))
∘ mk!₁
∘ exch (fwd [] (Γ - i))
=<< cutNDIn i (there j) x y
cutNDIn {Γ} {Δ} i (there j) x (cont y)
= return
∘ exch (bwd [] (Γ - i))
∘ cont
∘ exch (swp [] (_ ∷ _ ∷ []) (Γ - i))
=<< cutNDIn i (there (there j)) x y
cutNDIn {Θ} {_} i (there j) x (pool {Γ} {Δ} y z)
with split Γ j
... | inj₁ (k , p) rewrite p
= return
∘ exch (bwd [] (Θ - i))
∘ P.subst ⊢ⁿᶠ_ (++.assoc (_ ∷ Θ - i) (Γ - k) Δ)
∘ flip pool z
∘ exch (fwd [] (Θ - i))
=<< cutNDIn i (there k) x y
... | inj₂ (k , p) rewrite p
= return
∘ exch (swp [] (Θ - i) (_ ∷ Γ))
∘ pool y
∘ exch (fwd [] (Θ - i))
=<< cutNDIn i (there k) x z
cutNDIn {Γ} {Δ} i j (exch b x) y
= return
∘ exch (B.++-cong {ys₁ = Δ - j} (del-from b i ) I.id)
=<< cutNDIn (from b ⟨$⟩ i) j x y
cutNDIn {Γ} {Δ} i j x (exch b y)
= return
∘ exch (B.++-cong {xs₁ = Γ - i} I.id (del-from b j))
=<< cutNDIn i (from b ⟨$⟩ j) x y
-- -}
-- -}
-- -}
-- -}
-- -}
| {
"alphanum_fraction": 0.4793206275,
"avg_line_length": 28.8876404494,
"ext": "agda",
"hexsha": "cd985bb97b34fe4f58e95454e76cd17d66e065c6",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-09-05T08:58:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-05T08:58:13.000Z",
"max_forks_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "pepijnkokke/nodcap",
"max_forks_repo_path": "src/cpnd1/nodcap/NF/CutND.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "pepijnkokke/nodcap",
"max_issues_repo_path": "src/cpnd1/nodcap/NF/CutND.agda",
"max_line_length": 86,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "wenkokke/nodcap",
"max_stars_repo_path": "src/cpnd1/nodcap/NF/CutND.agda",
"max_stars_repo_stars_event_max_datetime": "2019-09-24T20:16:35.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-09-05T08:58:11.000Z",
"num_tokens": 3511,
"size": 7713
} |
module OlderBasicILP.Indirect.Hilbert.Nested where
open import OlderBasicILP.Indirect public
-- Derivations, as Hilbert-style combinator trees.
mutual
data Tm : Set where
VAR : ℕ → Tm
APP : Tm → Tm → Tm
CI : Tm
CK : Tm
CS : Tm
BOX : Tm → Tm
CDIST : Tm
CUP : Tm
CDOWN : Tm
CPAIR : Tm
CFST : Tm
CSND : Tm
UNIT : Tm
infix 3 _⊢_
data _⊢_ (Γ : Cx (Ty Tm)) : Ty Tm → Set where
var : ∀ {A} → A ∈ Γ → Γ ⊢ A
app : ∀ {A B} → Γ ⊢ A ▻ B → Γ ⊢ A → Γ ⊢ B
ci : ∀ {A} → Γ ⊢ A ▻ A
ck : ∀ {A B} → Γ ⊢ A ▻ B ▻ A
cs : ∀ {A B C} → Γ ⊢ (A ▻ B ▻ C) ▻ (A ▻ B) ▻ A ▻ C
box : ∀ {A} → (t : ∅ ⊢ A) → Γ ⊢ [ t ] ⦂ A
cdist : ∀ {A B T U} → Γ ⊢ T ⦂ (A ▻ B) ▻ U ⦂ A ▻ APP T U ⦂ B
cup : ∀ {A T} → Γ ⊢ T ⦂ A ▻ BOX T ⦂ T ⦂ A
cdown : ∀ {A T} → Γ ⊢ T ⦂ A ▻ A
cpair : ∀ {A B} → Γ ⊢ A ▻ B ▻ A ∧ B
cfst : ∀ {A B} → Γ ⊢ A ∧ B ▻ A
csnd : ∀ {A B} → Γ ⊢ A ∧ B ▻ B
unit : Γ ⊢ ⊤
[_] : ∀ {A Γ} → Γ ⊢ A → Tm
[ var i ] = VAR [ i ]ⁱ
[ app t u ] = APP [ t ] [ u ]
[ ci ] = CI
[ ck ] = CK
[ cs ] = CS
[ box t ] = BOX [ t ]
[ cdist ] = CDIST
[ cup ] = CUP
[ cdown ] = CDOWN
[ cpair ] = CPAIR
[ cfst ] = CFST
[ csnd ] = CSND
[ unit ] = UNIT
infix 3 _⊢⋆_
_⊢⋆_ : Cx (Ty Tm) → Cx (Ty Tm) → Set
Γ ⊢⋆ ∅ = 𝟙
Γ ⊢⋆ Ξ , A = Γ ⊢⋆ Ξ × Γ ⊢ A
-- Monotonicity with respect to context inclusion.
mono⊢ : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢ A → Γ′ ⊢ A
mono⊢ η (var i) = var (mono∈ η i)
mono⊢ η (app t u) = app (mono⊢ η t) (mono⊢ η u)
mono⊢ η ci = ci
mono⊢ η ck = ck
mono⊢ η cs = cs
mono⊢ η (box t) = box t
mono⊢ η cdist = cdist
mono⊢ η cup = cup
mono⊢ η cdown = cdown
mono⊢ η cpair = cpair
mono⊢ η cfst = cfst
mono⊢ η csnd = csnd
mono⊢ η unit = unit
mono⊢⋆ : ∀ {Ξ Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢⋆ Ξ → Γ′ ⊢⋆ Ξ
mono⊢⋆ {∅} η ∙ = ∙
mono⊢⋆ {Ξ , A} η (ts , t) = mono⊢⋆ η ts , mono⊢ η t
-- Shorthand for variables.
V₀ : Tm
V₀ = VAR 0
V₁ : Tm
V₁ = VAR 1
V₂ : Tm
V₂ = VAR 2
v₀ : ∀ {A Γ} → Γ , A ⊢ A
v₀ = var i₀
v₁ : ∀ {A B Γ} → (Γ , A) , B ⊢ A
v₁ = var i₁
v₂ : ∀ {A B C Γ} → ((Γ , A) , B) , C ⊢ A
v₂ = var i₂
-- Reflexivity.
refl⊢⋆ : ∀ {Γ} → Γ ⊢⋆ Γ
refl⊢⋆ {∅} = ∙
refl⊢⋆ {Γ , A} = mono⊢⋆ weak⊆ refl⊢⋆ , v₀
-- Deduction theorem.
LAM : Tm → Tm
LAM (VAR zero) = CI
LAM (VAR (suc i)) = APP CK (VAR i)
LAM (APP T U) = APP (APP CS (LAM T)) (LAM U)
LAM CI = APP CK CI
LAM CK = APP CK CK
LAM CS = APP CK CS
LAM (BOX T) = APP CK (BOX T)
LAM CDIST = APP CK CDIST
LAM CUP = APP CK CUP
LAM CDOWN = APP CK CDOWN
LAM CPAIR = APP CK CPAIR
LAM CFST = APP CK CFST
LAM CSND = APP CK CSND
LAM UNIT = APP CK UNIT
lam : ∀ {A B Γ} → Γ , A ⊢ B → Γ ⊢ A ▻ B
lam (var top) = ci
lam (var (pop i)) = app ck (var i)
lam (app t u) = app (app cs (lam t)) (lam u)
lam ci = app ck ci
lam ck = app ck ck
lam cs = app ck cs
lam (box t) = app ck (box t)
lam cdist = app ck cdist
lam cup = app ck cup
lam cdown = app ck cdown
lam cpair = app ck cpair
lam cfst = app ck cfst
lam csnd = app ck csnd
lam unit = app ck unit
-- Detachment theorem.
DET : Tm → Tm
DET T = APP T V₀
det : ∀ {A B Γ} → Γ ⊢ A ▻ B → Γ , A ⊢ B
det t = app (mono⊢ weak⊆ t) v₀
-- Cut and multicut.
CUT : Tm → Tm → Tm
CUT T U = APP (LAM U) T
MULTICUT : Cx Tm → Tm → Tm
MULTICUT ∅ U = U
MULTICUT (TS , T) U = APP (MULTICUT TS (LAM U)) T
cut : ∀ {A B Γ} → Γ ⊢ A → Γ , A ⊢ B → Γ ⊢ B
cut t u = app (lam u) t
multicut : ∀ {Ξ A Γ} → Γ ⊢⋆ Ξ → Ξ ⊢ A → Γ ⊢ A
multicut {∅} ∙ u = mono⊢ bot⊆ u
multicut {Ξ , B} (ts , t) u = app (multicut ts (lam u)) t
-- Transitivity.
trans⊢⋆ : ∀ {Γ″ Γ′ Γ} → Γ ⊢⋆ Γ′ → Γ′ ⊢⋆ Γ″ → Γ ⊢⋆ Γ″
trans⊢⋆ {∅} ts ∙ = ∙
trans⊢⋆ {Γ″ , A} ts (us , u) = trans⊢⋆ ts us , multicut ts u
-- Contraction.
CCONT : Tm
CCONT = LAM (LAM (APP (APP V₁ V₀) V₀))
CONT : Tm → Tm
CONT T = DET (APP CCONT (LAM (LAM T)))
ccont : ∀ {A B Γ} → Γ ⊢ (A ▻ A ▻ B) ▻ A ▻ B
ccont = lam (lam (app (app v₁ v₀) v₀))
cont : ∀ {A B Γ} → Γ , A , A ⊢ B → Γ , A ⊢ B
cont t = det (app ccont (lam (lam t)))
-- Exchange, or Schönfinkel’s C combinator.
CEXCH : Tm
CEXCH = LAM (LAM (LAM (APP (APP V₂ V₀) V₁)))
EXCH : Tm → Tm
EXCH T = DET (DET (APP CEXCH (LAM (LAM T))))
cexch : ∀ {A B C Γ} → Γ ⊢ (A ▻ B ▻ C) ▻ B ▻ A ▻ C
cexch = lam (lam (lam (app (app v₂ v₀) v₁)))
exch : ∀ {A B C Γ} → Γ , A , B ⊢ C → Γ , B , A ⊢ C
exch t = det (det (app cexch (lam (lam t))))
-- Composition, or Schönfinkel’s B combinator.
CCOMP : Tm
CCOMP = LAM (LAM (LAM (APP V₂ (APP V₁ V₀))))
COMP : Tm → Tm → Tm
COMP T U = DET (APP (APP CCOMP (LAM T)) (LAM U))
ccomp : ∀ {A B C Γ} → Γ ⊢ (B ▻ C) ▻ (A ▻ B) ▻ A ▻ C
ccomp = lam (lam (lam (app v₂ (app v₁ v₀))))
comp : ∀ {A B C Γ} → Γ , B ⊢ C → Γ , A ⊢ B → Γ , A ⊢ C
comp t u = det (app (app ccomp (lam t)) (lam u))
-- Useful theorems in functional form.
DIST : Tm → Tm → Tm
DIST T U = APP (APP CDIST T) U
UP : Tm → Tm
UP T = APP CUP T
DOWN : Tm → Tm
DOWN T = APP CDOWN T
DISTUP : Tm → Tm → Tm
DISTUP T U = DIST T (UP U)
UNBOX : Tm → Tm → Tm
UNBOX T U = APP (LAM U) T
MULTIBOX : Cx Tm → Tm → Tm
MULTIBOX ∅ U = BOX U
MULTIBOX (TS , T) U = DISTUP (MULTIBOX TS (LAM U)) T
dist : ∀ {A B T U Γ} → Γ ⊢ T ⦂ (A ▻ B) → Γ ⊢ U ⦂ A → Γ ⊢ (APP T U) ⦂ B
dist t u = app (app cdist t) u
up : ∀ {A T Γ} → Γ ⊢ T ⦂ A → Γ ⊢ BOX T ⦂ T ⦂ A
up t = app cup t
down : ∀ {A T Γ} → Γ ⊢ T ⦂ A → Γ ⊢ A
down t = app cdown t
distup : ∀ {A B T U Γ} → Γ ⊢ T ⦂ (U ⦂ A ▻ B)
→ Γ ⊢ U ⦂ A → Γ ⊢ APP T (BOX U) ⦂ B
distup t u = dist t (up u)
unbox : ∀ {A C T U Γ} → Γ ⊢ T ⦂ A → Γ , T ⦂ A ⊢ U ⦂ C → Γ ⊢ U ⦂ C
unbox t u = app (lam u) t
-- FIXME ↓ FIXME ↓ FIXME -----------------------------------------------------
--
-- Do we need reduction on term representations?
--
-- Goal: Γ ⊢ [ u ] ⦂ A
-- Have: Γ ⊢ APP [ lam u ] (BOX S) ⦂ A
distup′ : ∀ {A B T U Γ} → Γ ⊢ LAM T ⦂ (U ⦂ A ▻ B) → Γ ⊢ U ⦂ A
→ Γ ⊢ APP (LAM T) (BOX U) ⦂ B
distup′ t u = dist t (up u)
-- multibox : ∀ {n A Γ} {SS : VCx Tm n} {Ξ : VCx (Ty Tm) n}
-- → Γ ⊢⋆ SS ⦂⋆ Ξ → (u : SS ⦂⋆ Ξ ⊢ A)
-- → Γ ⊢ [ u ] ⦂ A
-- multibox {SS = ∅} {∅} ∙ u = box u
-- multibox {SS = SS , S} {Ξ , B} (ts , t) u = {!distup (multibox ts (lam u)) t!}
-- FIXME ↑ FIXME ↑ FIXME -----------------------------------------------------
PAIR : Tm → Tm → Tm
PAIR T U = APP (APP CPAIR T) U
FST : Tm → Tm
FST T = APP CFST T
SND : Tm → Tm
SND T = APP CSND T
pair : ∀ {A B Γ} → Γ ⊢ A → Γ ⊢ B → Γ ⊢ A ∧ B
pair t u = app (app cpair t) u
fst : ∀ {A B Γ} → Γ ⊢ A ∧ B → Γ ⊢ A
fst t = app cfst t
snd : ∀ {A B Γ} → Γ ⊢ A ∧ B → Γ ⊢ B
snd t = app csnd t
-- Closure under context concatenation.
concat : ∀ {A B Γ} Γ′ → Γ , A ⊢ B → Γ′ ⊢ A → Γ ⧺ Γ′ ⊢ B
concat Γ′ t u = app (mono⊢ (weak⊆⧺₁ Γ′) (lam t)) (mono⊢ weak⊆⧺₂ u)
| {
"alphanum_fraction": 0.4431818182,
"avg_line_length": 23.0819672131,
"ext": "agda",
"hexsha": "a5bb9051910fbbc311c618b0de600b0f8ddb848b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/hilbert-gentzen",
"max_forks_repo_path": "OlderBasicILP/Indirect/Hilbert/Nested.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/hilbert-gentzen",
"max_issues_repo_path": "OlderBasicILP/Indirect/Hilbert/Nested.agda",
"max_line_length": 81,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/hilbert-gentzen",
"max_stars_repo_path": "OlderBasicILP/Indirect/Hilbert/Nested.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-01T10:29:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-03T18:51:56.000Z",
"num_tokens": 3401,
"size": 7040
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Support for reflection
------------------------------------------------------------------------
module Reflection where
open import Data.Bool as Bool using (Bool); open Bool.Bool
open import Data.List using (List); open Data.List.List
open import Data.Nat using (ℕ) renaming (_≟_ to _≟-ℕ_)
open import Data.Nat.Show renaming (show to showNat)
open import Data.Float using (Float) renaming (_≟_ to _≟f_; show to showFloat)
open import Data.Char using (Char) renaming (_≟_ to _≟c_; show to showChar)
open import Data.String using (String) renaming (_≟_ to _≟s_; show to showString)
open import Data.Product
open import Function
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open import Relation.Binary.PropositionalEquality.TrustMe
open import Relation.Nullary
open import Relation.Nullary.Decidable as Dec
open import Relation.Nullary.Product
------------------------------------------------------------------------
-- Names
-- Names.
postulate Name : Set
{-# BUILTIN QNAME Name #-}
private
primitive
primQNameEquality : Name → Name → Bool
-- Equality of names is decidable.
infix 4 _==_ _≟-Name_
private
_==_ : Name → Name → Bool
_==_ = primQNameEquality
_≟-Name_ : Decidable {A = Name} _≡_
s₁ ≟-Name s₂ with s₁ == s₂
... | true = yes trustMe
... | false = no whatever
where postulate whatever : _
-- Names can be shown.
private
primitive
primShowQName : Name → String
showName : Name → String
showName = primShowQName
------------------------------------------------------------------------
-- Terms
-- Is the argument visible (explicit), hidden (implicit), or an
-- instance argument?
data Visibility : Set where
visible hidden instance′ : Visibility
{-# BUILTIN HIDING Visibility #-}
{-# BUILTIN VISIBLE visible #-}
{-# BUILTIN HIDDEN hidden #-}
{-# BUILTIN INSTANCE instance′ #-}
-- Arguments can be relevant or irrelevant.
data Relevance : Set where
relevant irrelevant : Relevance
{-# BUILTIN RELEVANCE Relevance #-}
{-# BUILTIN RELEVANT relevant #-}
{-# BUILTIN IRRELEVANT irrelevant #-}
-- Arguments.
data Arg-info : Set where
arg-info : (v : Visibility) (r : Relevance) → Arg-info
visibility : Arg-info → Visibility
visibility (arg-info v _) = v
relevance : Arg-info → Relevance
relevance (arg-info _ r) = r
data Arg (A : Set) : Set where
arg : (i : Arg-info) (x : A) → Arg A
{-# BUILTIN ARGINFO Arg-info #-}
{-# BUILTIN ARGARGINFO arg-info #-}
{-# BUILTIN ARG Arg #-}
{-# BUILTIN ARGARG arg #-}
-- Literals.
data Literal : Set where
nat : ℕ → Literal
float : Float → Literal
char : Char → Literal
string : String → Literal
name : Name → Literal
{-# BUILTIN AGDALITERAL Literal #-}
{-# BUILTIN AGDALITNAT nat #-}
{-# BUILTIN AGDALITFLOAT float #-}
{-# BUILTIN AGDALITCHAR char #-}
{-# BUILTIN AGDALITSTRING string #-}
{-# BUILTIN AGDALITQNAME name #-}
-- Terms.
mutual
data Term : Set where
-- Variable applied to arguments.
var : (x : ℕ) (args : List (Arg Term)) → Term
-- Constructor applied to arguments.
con : (c : Name) (args : List (Arg Term)) → Term
-- Identifier applied to arguments.
def : (f : Name) (args : List (Arg Term)) → Term
-- Different kinds of λ-abstraction.
lam : (v : Visibility) (t : Term) → Term
-- Pattern matching λ-abstraction.
pat-lam : (cs : List Clause) (args : List (Arg Term)) → Term
-- Pi-type.
pi : (t₁ : Arg Type) (t₂ : Type) → Term
-- A sort.
sort : Sort → Term
-- A literal.
lit : Literal → Term
-- Anything else.
unknown : Term
data Type : Set where
el : (s : Sort) (t : Term) → Type
data Sort : Set where
-- A Set of a given (possibly neutral) level.
set : (t : Term) → Sort
-- A Set of a given concrete level.
lit : (n : ℕ) → Sort
-- Anything else.
unknown : Sort
data Pattern : Set where
con : Name → List (Arg Pattern) → Pattern
dot : Pattern
var : Pattern
lit : Literal → Pattern
proj : Name → Pattern
absurd : Pattern
data Clause : Set where
clause : List (Arg Pattern) → Term → Clause
absurd-clause : List (Arg Pattern) → Clause
{-# BUILTIN AGDASORT Sort #-}
{-# BUILTIN AGDATYPE Type #-}
{-# BUILTIN AGDATERM Term #-}
{-# BUILTIN AGDAPATTERN Pattern #-}
{-# BUILTIN AGDACLAUSE Clause #-}
{-# BUILTIN AGDATERMVAR var #-}
{-# BUILTIN AGDATERMCON con #-}
{-# BUILTIN AGDATERMDEF def #-}
{-# BUILTIN AGDATERMLAM lam #-}
{-# BUILTIN AGDATERMEXTLAM pat-lam #-}
{-# BUILTIN AGDATERMPI pi #-}
{-# BUILTIN AGDATERMSORT sort #-}
{-# BUILTIN AGDATERMLIT lit #-}
{-# BUILTIN AGDATERMUNSUPPORTED unknown #-}
{-# BUILTIN AGDATYPEEL el #-}
{-# BUILTIN AGDASORTSET set #-}
{-# BUILTIN AGDASORTLIT lit #-}
{-# BUILTIN AGDASORTUNSUPPORTED unknown #-}
{-# BUILTIN AGDAPATCON con #-}
{-# BUILTIN AGDAPATDOT dot #-}
{-# BUILTIN AGDAPATVAR var #-}
{-# BUILTIN AGDAPATLIT lit #-}
{-# BUILTIN AGDAPATPROJ proj #-}
{-# BUILTIN AGDAPATABSURD absurd #-}
{-# BUILTIN AGDACLAUSECLAUSE clause #-}
{-# BUILTIN AGDACLAUSEABSURD absurd-clause #-}
------------------------------------------------------------------------
-- Definitions
-- Function definition.
data FunctionDef : Set where
fun-def : Type → List Clause → FunctionDef
{-# BUILTIN AGDAFUNDEF FunctionDef #-}
{-# BUILTIN AGDAFUNDEFCON fun-def #-}
postulate
-- Data type definition.
Data-type : Set
-- Record type definition.
Record : Set
{-# BUILTIN AGDADATADEF Data-type #-}
{-# BUILTIN AGDARECORDDEF Record #-}
-- Definitions.
data Definition : Set where
function : FunctionDef → Definition
data-type : Data-type → Definition
record′ : Record → Definition
constructor′ : Definition
axiom : Definition
primitive′ : Definition
{-# BUILTIN AGDADEFINITION Definition #-}
{-# BUILTIN AGDADEFINITIONFUNDEF function #-}
{-# BUILTIN AGDADEFINITIONDATADEF data-type #-}
{-# BUILTIN AGDADEFINITIONRECORDDEF record′ #-}
{-# BUILTIN AGDADEFINITIONDATACONSTRUCTOR constructor′ #-}
{-# BUILTIN AGDADEFINITIONPOSTULATE axiom #-}
{-# BUILTIN AGDADEFINITIONPRIMITIVE primitive′ #-}
showLiteral : Literal → String
showLiteral (nat x) = showNat x
showLiteral (float x) = showFloat x
showLiteral (char x) = showChar x
showLiteral (string x) = showString x
showLiteral (name x) = showName x
private
primitive
primQNameType : Name → Type
primQNameDefinition : Name → Definition
primDataConstructors : Data-type → List Name
-- The type of the thing with the given name.
type : Name → Type
type = primQNameType
-- The definition of the thing with the given name.
definition : Name → Definition
definition = primQNameDefinition
-- The constructors of the given data type.
constructors : Data-type → List Name
constructors = primDataConstructors
------------------------------------------------------------------------
-- Term equality is decidable
-- Boring helper functions.
private
cong₂′ : ∀ {A B C : Set} (f : A → B → C) {x y u v} →
x ≡ y × u ≡ v → f x u ≡ f y v
cong₂′ f = uncurry (cong₂ f)
cong₃′ : ∀ {A B C D : Set} (f : A → B → C → D) {x y u v r s} →
x ≡ y × u ≡ v × r ≡ s → f x u r ≡ f y v s
cong₃′ f (refl , refl , refl) = refl
arg₁ : ∀ {A i i′} {x x′ : A} → arg i x ≡ arg i′ x′ → i ≡ i′
arg₁ refl = refl
arg₂ : ∀ {A i i′} {x x′ : A} → arg i x ≡ arg i′ x′ → x ≡ x′
arg₂ refl = refl
arg-info₁ : ∀ {v v′ r r′} → arg-info v r ≡ arg-info v′ r′ → v ≡ v′
arg-info₁ refl = refl
arg-info₂ : ∀ {v v′ r r′} → arg-info v r ≡ arg-info v′ r′ → r ≡ r′
arg-info₂ refl = refl
cons₁ : ∀ {A : Set} {x y} {xs ys : List A} → x ∷ xs ≡ y ∷ ys → x ≡ y
cons₁ refl = refl
cons₂ : ∀ {A : Set} {x y} {xs ys : List A} → x ∷ xs ≡ y ∷ ys → xs ≡ ys
cons₂ refl = refl
var₁ : ∀ {x x′ args args′} → Term.var x args ≡ var x′ args′ → x ≡ x′
var₁ refl = refl
var₂ : ∀ {x x′ args args′} → Term.var x args ≡ var x′ args′ → args ≡ args′
var₂ refl = refl
con₁ : ∀ {c c′ args args′} → Term.con c args ≡ con c′ args′ → c ≡ c′
con₁ refl = refl
con₂ : ∀ {c c′ args args′} → Term.con c args ≡ con c′ args′ → args ≡ args′
con₂ refl = refl
def₁ : ∀ {f f′ args args′} → def f args ≡ def f′ args′ → f ≡ f′
def₁ refl = refl
def₂ : ∀ {f f′ args args′} → def f args ≡ def f′ args′ → args ≡ args′
def₂ refl = refl
lam₁ : ∀ {v v′ t t′} → lam v t ≡ lam v′ t′ → v ≡ v′
lam₁ refl = refl
lam₂ : ∀ {v v′ t t′} → lam v t ≡ lam v′ t′ → t ≡ t′
lam₂ refl = refl
pat-lam₁ : ∀ {cs cs′ args args′} → pat-lam cs args ≡ pat-lam cs′ args′ → cs ≡ cs′
pat-lam₁ refl = refl
pat-lam₂ : ∀ {cs cs′ args args′} → pat-lam cs args ≡ pat-lam cs′ args′ → args ≡ args′
pat-lam₂ refl = refl
pi₁ : ∀ {t₁ t₁′ t₂ t₂′} → pi t₁ t₂ ≡ pi t₁′ t₂′ → t₁ ≡ t₁′
pi₁ refl = refl
pi₂ : ∀ {t₁ t₁′ t₂ t₂′} → pi t₁ t₂ ≡ pi t₁′ t₂′ → t₂ ≡ t₂′
pi₂ refl = refl
sort₁ : ∀ {x y} → sort x ≡ sort y → x ≡ y
sort₁ refl = refl
lit₁ : ∀ {x y} → Term.lit x ≡ lit y → x ≡ y
lit₁ refl = refl
pcon₁ : ∀ {c c′ args args′} → Pattern.con c args ≡ con c′ args′ → c ≡ c′
pcon₁ refl = refl
pcon₂ : ∀ {c c′ args args′} → Pattern.con c args ≡ con c′ args′ → args ≡ args′
pcon₂ refl = refl
plit₁ : ∀ {x y} → Pattern.lit x ≡ lit y → x ≡ y
plit₁ refl = refl
pproj₁ : ∀ {x y} → proj x ≡ proj y → x ≡ y
pproj₁ refl = refl
set₁ : ∀ {x y} → set x ≡ set y → x ≡ y
set₁ refl = refl
slit₁ : ∀ {x y} → Sort.lit x ≡ lit y → x ≡ y
slit₁ refl = refl
el₁ : ∀ {s s′ t t′} → el s t ≡ el s′ t′ → s ≡ s′
el₁ refl = refl
el₂ : ∀ {s s′ t t′} → el s t ≡ el s′ t′ → t ≡ t′
el₂ refl = refl
nat₁ : ∀ {x y} → nat x ≡ nat y → x ≡ y
nat₁ refl = refl
float₁ : ∀ {x y} → float x ≡ float y → x ≡ y
float₁ refl = refl
char₁ : ∀ {x y} → char x ≡ char y → x ≡ y
char₁ refl = refl
string₁ : ∀ {x y} → string x ≡ string y → x ≡ y
string₁ refl = refl
name₁ : ∀ {x y} → name x ≡ name y → x ≡ y
name₁ refl = refl
clause₁ : ∀ {ps ps′ b b′} → clause ps b ≡ clause ps′ b′ → ps ≡ ps′
clause₁ refl = refl
clause₂ : ∀ {ps ps′ b b′} → clause ps b ≡ clause ps′ b′ → b ≡ b′
clause₂ refl = refl
absurd-clause₁ : ∀ {ps ps′} → absurd-clause ps ≡ absurd-clause ps′ → ps ≡ ps′
absurd-clause₁ refl = refl
_≟-Visibility_ : Decidable (_≡_ {A = Visibility})
visible ≟-Visibility visible = yes refl
hidden ≟-Visibility hidden = yes refl
instance′ ≟-Visibility instance′ = yes refl
visible ≟-Visibility hidden = no λ()
visible ≟-Visibility instance′ = no λ()
hidden ≟-Visibility visible = no λ()
hidden ≟-Visibility instance′ = no λ()
instance′ ≟-Visibility visible = no λ()
instance′ ≟-Visibility hidden = no λ()
_≟-Relevance_ : Decidable (_≡_ {A = Relevance})
relevant ≟-Relevance relevant = yes refl
irrelevant ≟-Relevance irrelevant = yes refl
relevant ≟-Relevance irrelevant = no λ()
irrelevant ≟-Relevance relevant = no λ()
_≟-Arg-info_ : Decidable (_≡_ {A = Arg-info})
arg-info v r ≟-Arg-info arg-info v′ r′ =
Dec.map′ (cong₂′ arg-info)
< arg-info₁ , arg-info₂ >
(v ≟-Visibility v′ ×-dec r ≟-Relevance r′)
_≟-Lit_ : Decidable (_≡_ {A = Literal})
nat x ≟-Lit nat x₁ = Dec.map′ (cong nat) nat₁ (x ≟-ℕ x₁)
nat x ≟-Lit float x₁ = no (λ ())
nat x ≟-Lit char x₁ = no (λ ())
nat x ≟-Lit string x₁ = no (λ ())
nat x ≟-Lit name x₁ = no (λ ())
float x ≟-Lit nat x₁ = no (λ ())
float x ≟-Lit float x₁ = Dec.map′ (cong float) float₁ (x ≟f x₁)
float x ≟-Lit char x₁ = no (λ ())
float x ≟-Lit string x₁ = no (λ ())
float x ≟-Lit name x₁ = no (λ ())
char x ≟-Lit nat x₁ = no (λ ())
char x ≟-Lit float x₁ = no (λ ())
char x ≟-Lit char x₁ = Dec.map′ (cong char) char₁ (x ≟c x₁)
char x ≟-Lit string x₁ = no (λ ())
char x ≟-Lit name x₁ = no (λ ())
string x ≟-Lit nat x₁ = no (λ ())
string x ≟-Lit float x₁ = no (λ ())
string x ≟-Lit char x₁ = no (λ ())
string x ≟-Lit string x₁ = Dec.map′ (cong string) string₁ (x ≟s x₁)
string x ≟-Lit name x₁ = no (λ ())
name x ≟-Lit nat x₁ = no (λ ())
name x ≟-Lit float x₁ = no (λ ())
name x ≟-Lit char x₁ = no (λ ())
name x ≟-Lit string x₁ = no (λ ())
name x ≟-Lit name x₁ = Dec.map′ (cong name) name₁ (x ≟-Name x₁)
mutual
infix 4 _≟_ _≟-Args_ _≟-ArgType_
_≟-ArgTerm_ : Decidable (_≡_ {A = Arg Term})
arg i a ≟-ArgTerm arg i′ a′ =
Dec.map′ (cong₂′ arg)
< arg₁ , arg₂ >
(i ≟-Arg-info i′ ×-dec a ≟ a′)
_≟-ArgType_ : Decidable (_≡_ {A = Arg Type})
arg i a ≟-ArgType arg i′ a′ =
Dec.map′ (cong₂′ arg)
< arg₁ , arg₂ >
(i ≟-Arg-info i′ ×-dec a ≟-Type a′)
_≟-ArgPattern_ : Decidable (_≡_ {A = Arg Pattern})
arg i a ≟-ArgPattern arg i′ a′ =
Dec.map′ (cong₂′ arg)
< arg₁ , arg₂ >
(i ≟-Arg-info i′ ×-dec a ≟-Pattern a′)
_≟-Args_ : Decidable (_≡_ {A = List (Arg Term)})
[] ≟-Args [] = yes refl
(x ∷ xs) ≟-Args (y ∷ ys) = Dec.map′ (cong₂′ _∷_) < cons₁ , cons₂ > (x ≟-ArgTerm y ×-dec xs ≟-Args ys)
[] ≟-Args (_ ∷ _) = no λ()
(_ ∷ _) ≟-Args [] = no λ()
_≟-Clause_ : Decidable (_≡_ {A = Clause})
clause ps b ≟-Clause clause ps′ b′ = Dec.map′ (cong₂′ clause) < clause₁ , clause₂ > (ps ≟-ArgPatterns ps′ ×-dec b ≟ b′)
absurd-clause ps ≟-Clause absurd-clause ps′ = Dec.map′ (cong absurd-clause) absurd-clause₁ (ps ≟-ArgPatterns ps′)
clause _ _ ≟-Clause absurd-clause _ = no λ()
absurd-clause _ ≟-Clause clause _ _ = no λ()
_≟-Clauses_ : Decidable (_≡_ {A = List Clause})
[] ≟-Clauses [] = yes refl
(x ∷ xs) ≟-Clauses (y ∷ ys) = Dec.map′ (cong₂′ _∷_) < cons₁ , cons₂ > (x ≟-Clause y ×-dec xs ≟-Clauses ys)
[] ≟-Clauses (_ ∷ _) = no λ()
(_ ∷ _) ≟-Clauses [] = no λ()
_≟-Pattern_ : Decidable (_≡_ {A = Pattern})
con c ps ≟-Pattern con c′ ps′ = Dec.map′ (cong₂′ con) < pcon₁ , pcon₂ > (c ≟-Name c′ ×-dec ps ≟-ArgPatterns ps′)
con x x₁ ≟-Pattern dot = no (λ ())
con x x₁ ≟-Pattern var = no (λ ())
con x x₁ ≟-Pattern lit x₂ = no (λ ())
con x x₁ ≟-Pattern proj x₂ = no (λ ())
con x x₁ ≟-Pattern absurd = no (λ ())
dot ≟-Pattern con x x₁ = no (λ ())
dot ≟-Pattern dot = yes refl
dot ≟-Pattern var = no (λ ())
dot ≟-Pattern lit x = no (λ ())
dot ≟-Pattern proj x = no (λ ())
dot ≟-Pattern absurd = no (λ ())
var ≟-Pattern con x x₁ = no (λ ())
var ≟-Pattern dot = no (λ ())
var ≟-Pattern var = yes refl
var ≟-Pattern lit x = no (λ ())
var ≟-Pattern proj x = no (λ ())
var ≟-Pattern absurd = no (λ ())
lit x ≟-Pattern con x₁ x₂ = no (λ ())
lit x ≟-Pattern dot = no (λ ())
lit x ≟-Pattern var = no (λ ())
lit l ≟-Pattern lit l′ = Dec.map′ (cong lit) plit₁ (l ≟-Lit l′)
lit x ≟-Pattern proj x₁ = no (λ ())
lit x ≟-Pattern absurd = no (λ ())
proj x ≟-Pattern con x₁ x₂ = no (λ ())
proj x ≟-Pattern dot = no (λ ())
proj x ≟-Pattern var = no (λ ())
proj x ≟-Pattern lit x₁ = no (λ ())
proj x ≟-Pattern proj x₁ = Dec.map′ (cong proj) pproj₁ (x ≟-Name x₁)
proj x ≟-Pattern absurd = no (λ ())
absurd ≟-Pattern con x x₁ = no (λ ())
absurd ≟-Pattern dot = no (λ ())
absurd ≟-Pattern var = no (λ ())
absurd ≟-Pattern lit x = no (λ ())
absurd ≟-Pattern proj x = no (λ ())
absurd ≟-Pattern absurd = yes refl
_≟-ArgPatterns_ : Decidable (_≡_ {A = List (Arg Pattern)})
[] ≟-ArgPatterns [] = yes refl
(x ∷ xs) ≟-ArgPatterns (y ∷ ys) = Dec.map′ (cong₂′ _∷_) < cons₁ , cons₂ > (x ≟-ArgPattern y ×-dec xs ≟-ArgPatterns ys)
[] ≟-ArgPatterns (_ ∷ _) = no λ()
(_ ∷ _) ≟-ArgPatterns [] = no λ()
_≟_ : Decidable (_≡_ {A = Term})
var x args ≟ var x′ args′ = Dec.map′ (cong₂′ var) < var₁ , var₂ > (x ≟-ℕ x′ ×-dec args ≟-Args args′)
con c args ≟ con c′ args′ = Dec.map′ (cong₂′ con) < con₁ , con₂ > (c ≟-Name c′ ×-dec args ≟-Args args′)
def f args ≟ def f′ args′ = Dec.map′ (cong₂′ def) < def₁ , def₂ > (f ≟-Name f′ ×-dec args ≟-Args args′)
lam v t ≟ lam v′ t′ = Dec.map′ (cong₂′ lam) < lam₁ , lam₂ > (v ≟-Visibility v′ ×-dec t ≟ t′)
pat-lam cs args ≟ pat-lam cs′ args′ =
Dec.map′ (cong₂′ pat-lam) < pat-lam₁ , pat-lam₂ > (cs ≟-Clauses cs′ ×-dec args ≟-Args args′)
pi t₁ t₂ ≟ pi t₁′ t₂′ = Dec.map′ (cong₂′ pi) < pi₁ , pi₂ > (t₁ ≟-ArgType t₁′ ×-dec t₂ ≟-Type t₂′)
sort s ≟ sort s′ = Dec.map′ (cong sort) sort₁ (s ≟-Sort s′)
lit l ≟ lit l′ = Dec.map′ (cong lit) lit₁ (l ≟-Lit l′)
unknown ≟ unknown = yes refl
var x args ≟ con c args′ = no λ()
var x args ≟ def f args′ = no λ()
var x args ≟ lam v t = no λ()
var x args ≟ pi t₁ t₂ = no λ()
var x args ≟ sort _ = no λ()
var x args ≟ lit _ = no λ()
var x args ≟ unknown = no λ()
con c args ≟ var x args′ = no λ()
con c args ≟ def f args′ = no λ()
con c args ≟ lam v t = no λ()
con c args ≟ pi t₁ t₂ = no λ()
con c args ≟ sort _ = no λ()
con c args ≟ lit _ = no λ()
con c args ≟ unknown = no λ()
def f args ≟ var x args′ = no λ()
def f args ≟ con c args′ = no λ()
def f args ≟ lam v t = no λ()
def f args ≟ pi t₁ t₂ = no λ()
def f args ≟ sort _ = no λ()
def f args ≟ lit _ = no λ()
def f args ≟ unknown = no λ()
lam v t ≟ var x args = no λ()
lam v t ≟ con c args = no λ()
lam v t ≟ def f args = no λ()
lam v t ≟ pi t₁ t₂ = no λ()
lam v t ≟ sort _ = no λ()
lam v t ≟ lit _ = no λ()
lam v t ≟ unknown = no λ()
pi t₁ t₂ ≟ var x args = no λ()
pi t₁ t₂ ≟ con c args = no λ()
pi t₁ t₂ ≟ def f args = no λ()
pi t₁ t₂ ≟ lam v t = no λ()
pi t₁ t₂ ≟ sort _ = no λ()
pi t₁ t₂ ≟ lit _ = no λ()
pi t₁ t₂ ≟ unknown = no λ()
sort _ ≟ var x args = no λ()
sort _ ≟ con c args = no λ()
sort _ ≟ def f args = no λ()
sort _ ≟ lam v t = no λ()
sort _ ≟ pi t₁ t₂ = no λ()
sort _ ≟ lit _ = no λ()
sort _ ≟ unknown = no λ()
lit _ ≟ var x args = no λ()
lit _ ≟ con c args = no λ()
lit _ ≟ def f args = no λ()
lit _ ≟ lam v t = no λ()
lit _ ≟ pi t₁ t₂ = no λ()
lit _ ≟ sort _ = no λ()
lit _ ≟ unknown = no λ()
unknown ≟ var x args = no λ()
unknown ≟ con c args = no λ()
unknown ≟ def f args = no λ()
unknown ≟ lam v t = no λ()
unknown ≟ pi t₁ t₂ = no λ()
unknown ≟ sort _ = no λ()
unknown ≟ lit _ = no λ()
pat-lam _ _ ≟ var x args = no λ()
pat-lam _ _ ≟ con c args = no λ()
pat-lam _ _ ≟ def f args = no λ()
pat-lam _ _ ≟ lam v t = no λ()
pat-lam _ _ ≟ pi t₁ t₂ = no λ()
pat-lam _ _ ≟ sort _ = no λ()
pat-lam _ _ ≟ lit _ = no λ()
pat-lam _ _ ≟ unknown = no λ()
var x args ≟ pat-lam _ _ = no λ()
con c args ≟ pat-lam _ _ = no λ()
def f args ≟ pat-lam _ _ = no λ()
lam v t ≟ pat-lam _ _ = no λ()
pi t₁ t₂ ≟ pat-lam _ _ = no λ()
sort _ ≟ pat-lam _ _ = no λ()
lit _ ≟ pat-lam _ _ = no λ()
unknown ≟ pat-lam _ _ = no λ()
_≟-Type_ : Decidable (_≡_ {A = Type})
el s t ≟-Type el s′ t′ = Dec.map′ (cong₂′ el) < el₁ , el₂ > (s ≟-Sort s′ ×-dec t ≟ t′)
_≟-Sort_ : Decidable (_≡_ {A = Sort})
set t ≟-Sort set t′ = Dec.map′ (cong set) set₁ (t ≟ t′)
lit n ≟-Sort lit n′ = Dec.map′ (cong lit) slit₁ (n ≟-ℕ n′)
unknown ≟-Sort unknown = yes refl
set _ ≟-Sort lit _ = no λ()
set _ ≟-Sort unknown = no λ()
lit _ ≟-Sort set _ = no λ()
lit _ ≟-Sort unknown = no λ()
unknown ≟-Sort set _ = no λ()
unknown ≟-Sort lit _ = no λ()
| {
"alphanum_fraction": 0.543684948,
"avg_line_length": 32.4943089431,
"ext": "agda",
"hexsha": "4f6f6e4dae3325453d5e878ee829f89cb7651a5a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Reflection.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Reflection.agda",
"max_line_length": 122,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Reflection.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 7168,
"size": 19984
} |
module Issue313 where
postulate
QName : Set
{-# BUILTIN QNAME QName #-}
postulate
X : Set
_+_ : QName → QName → Set
foo : Set
foo = quote X + quote X
| {
"alphanum_fraction": 0.6257668712,
"avg_line_length": 10.8666666667,
"ext": "agda",
"hexsha": "0cec7405a5eb88aeb4a6cb4831eac0b1d96161bf",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue313.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue313.agda",
"max_line_length": 27,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue313.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 52,
"size": 163
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Simple combinators working solely on and with functions
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Function where
open import Level
open import Strict
infixr 9 _∘_ _∘′_
infixl 8 _ˢ_
infixl 1 _on_
infixl 1 _⟨_⟩_
infixr -1 _$_ _$′_ _$!_ _$!′_
infixr 0 _-[_]-_
infixl 0 _|>_ _|>′_ _∋_
------------------------------------------------------------------------
-- Types
-- Unary functions on a given set.
Fun₁ : ∀ {i} → Set i → Set i
Fun₁ A = A → A
-- Binary functions on a given set.
Fun₂ : ∀ {i} → Set i → Set i
Fun₂ A = A → A → A
------------------------------------------------------------------------
-- Functions
_∘_ : ∀ {a b c}
{A : Set a} {B : A → Set b} {C : {x : A} → B x → Set c} →
(∀ {x} (y : B x) → C y) → (g : (x : A) → B x) →
((x : A) → C (g x))
f ∘ g = λ x → f (g x)
_∘′_ : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} →
(B → C) → (A → B) → (A → C)
f ∘′ g = _∘_ f g
id : ∀ {a} {A : Set a} → A → A
id x = x
const : ∀ {a b} {A : Set a} {B : Set b} → A → B → A
const x = λ _ → x
-- The S combinator. (Written infix as in Conor McBride's paper
-- "Outrageous but Meaningful Coincidences: Dependent type-safe syntax
-- and evaluation".)
_ˢ_ : ∀ {a b c}
{A : Set a} {B : A → Set b} {C : (x : A) → B x → Set c} →
((x : A) (y : B x) → C x y) →
(g : (x : A) → B x) →
((x : A) → C x (g x))
f ˢ g = λ x → f x (g x)
flip : ∀ {a b c} {A : Set a} {B : Set b} {C : A → B → Set c} →
((x : A) (y : B) → C x y) → ((y : B) (x : A) → C x y)
flip f = λ y x → f x y
-- Note that _$_ is right associative, like in Haskell. If you want a
-- left associative infix application operator, use
-- Category.Functor._<$>_, available from
-- Category.Monad.Identity.IdentityMonad.
_$_ : ∀ {a b} {A : Set a} {B : A → Set b} →
((x : A) → B x) → ((x : A) → B x)
f $ x = f x
_$′_ : ∀ {a b} {A : Set a} {B : Set b} →
(A → B) → (A → B)
_$′_ = _$_
-- Strict (call-by-value) application
_$!_ : ∀ {a b} {A : Set a} {B : A → Set b} →
((x : A) → B x) → ((x : A) → B x)
_$!_ = flip force
_$!′_ : ∀ {a b} {A : Set a} {B : Set b} →
(A → B) → (A → B)
_$!′_ = _$!_
-- flipped application aka pipe-forward
_|>_ : ∀ {a b} {A : Set a} {B : A → Set b} →
(a : A) → (∀ a → B a) → B a
_|>_ = flip _$_
_|>′_ : ∀ {a b} {A : Set a} {B : Set b} →
A → (A → B) → B
_|>′_ = _|>_
_⟨_⟩_ : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} →
A → (A → B → C) → B → C
x ⟨ f ⟩ y = f x y
_on_ : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} →
(B → B → C) → (A → B) → (A → A → C)
_*_ on f = λ x y → f x * f y
_-[_]-_ : ∀ {a b c d e} {A : Set a} {B : Set b} {C : Set c}
{D : Set d} {E : Set e} →
(A → B → C) → (C → D → E) → (A → B → D) → (A → B → E)
f -[ _*_ ]- g = λ x y → f x y * g x y
-- In Agda you cannot annotate every subexpression with a type
-- signature. This function can be used instead.
_∋_ : ∀ {a} (A : Set a) → A → A
A ∋ x = x
-- Conversely it is sometimes useful to be able to extract the
-- type of a given expression:
typeOf : ∀ {a} {A : Set a} → A → Set a
typeOf {A = A} _ = A
-- Case expressions (to be used with pattern-matching lambdas, see
-- README.Case).
infix 0 case_return_of_ case_of_
case_return_of_ :
∀ {a b} {A : Set a}
(x : A) (B : A → Set b) → ((x : A) → B x) → B x
case x return B of f = f x
case_of_ : ∀ {a b} {A : Set a} {B : Set b} → A → (A → B) → B
case x of f = case x return _ of f
| {
"alphanum_fraction": 0.4316427784,
"avg_line_length": 25.7304964539,
"ext": "agda",
"hexsha": "f3cb7f9788fede6582648acae79ff7f45c7827eb",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Function.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Function.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Function.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1435,
"size": 3628
} |
{-# OPTIONS --universe-polymorphism #-}
open import Common.Prelude
renaming (Nat to ℕ; module Nat to ℕ)
using (zero; suc; _+_; _∸_; List; []; _∷_; Bool; true; false)
open import Common.Level
open import Common.Reflection
module TermSplicing where
module Library where
data Box {a} (A : Set a) : Set a where
box : A → Box A
record ⊤ : Set where
constructor tt
infixr 5 _×_
record _×_ (A B : Set) : Set where
constructor _,_
field
proj₁ : A
proj₂ : B
[_] : ∀ {A : Set} → A → List A
[ x ] = x ∷ []
replicate : ∀ {A : Set} → ℕ → A → List A
replicate zero x = []
replicate (suc n) x = x ∷ replicate n x
foldr : ∀ {A B : Set} → (A → B → B) → B → List A → B
foldr c n [] = n
foldr c n (x ∷ xs) = c x (foldr c n xs)
foldl : ∀ {A B : Set} → (A → B → A) → A → List B → A
foldl c n [] = n
foldl c n (x ∷ xs) = foldl c (c n x) xs
reverse : ∀ {A : Set} → List A → List A
reverse = foldl (λ rev x → x ∷ rev) []
length : ∀ {A : Set} → List A → ℕ
length = foldr (λ _ → suc) 0
data Maybe (A : Set) : Set where
nothing : Maybe A
just : A → Maybe A
mapMaybe : ∀ {A B : Set} → (A → B) → Maybe A → Maybe B
mapMaybe f (just x) = just (f x)
mapMaybe f nothing = nothing
when : ∀ {A} → Bool → Maybe A → Maybe A
when true x = x
when false _ = nothing
infix 6 _≡_
data _≡_ {a} {A : Set a} (x : A) : A -> Set where
refl : x ≡ x
_→⟨_⟩_ : ∀ (A : Set) (n : ℕ) (B : Set) → Set
A →⟨ zero ⟩ B = B
A →⟨ suc n ⟩ B = A → A →⟨ n ⟩ B
open Library
module ReflectLibrary where
lamᵛ : Term → Term
lamᵛ t = lam visible (abs "_" t)
lamʰ : Term → Term
lamʰ t = lam hidden (abs "_" t)
argᵛʳ : ∀{a} {A : Set a} → A → Arg A
argᵛʳ = arg (argInfo visible relevant)
argʰʳ : ∀{a} {A : Set a} → A → Arg A
argʰʳ = arg (argInfo hidden relevant)
app` : (Args → Term) → (hrs : List ArgInfo) → Term →⟨ length hrs ⟩ Term
app` f = go [] where
go : List (Arg Term) → (hrs : List ArgInfo) → Term →⟨ length hrs ⟩ Term
go args [] = f (reverse args)
go args (i ∷ hs) = λ t → go (arg i t ∷ args) hs
con` : QName → (hrs : List ArgInfo) → Term →⟨ length hrs ⟩ Term
con` x = app` (con x)
def` : QName → (hrs : List ArgInfo) → Term →⟨ length hrs ⟩ Term
def` x = app` (def x)
var` : ℕ → (hrs : List ArgInfo) → Term →⟨ length hrs ⟩ Term
var` x = app` (var x)
coe : ∀ {A : Set} {z : A} n → (Term →⟨ length (replicate n z) ⟩ Term) → Term →⟨ n ⟩ Term
coe zero t = t
coe (suc n) f = λ t → coe n (f t)
con`ⁿʳ : QName → (n : ℕ) → Term →⟨ n ⟩ Term
con`ⁿʳ x n = coe n (app` (con x) (replicate n (argInfo visible relevant)))
def`ⁿʳ : QName → (n : ℕ) → Term →⟨ n ⟩ Term
def`ⁿʳ x n = coe n (app` (def x) (replicate n (argInfo visible relevant)))
var`ⁿʳ : ℕ → (n : ℕ) → Term →⟨ n ⟩ Term
var`ⁿʳ x n = coe n (app` (var x) (replicate n (argInfo visible relevant)))
sort₀ : Sort
sort₀ = lit 0
sort₁ : Sort
sort₁ = lit 1
`Set₀ : Term
`Set₀ = sort sort₀
unArg : ∀ {a} {A : Set a} → Arg A → A
unArg (arg _ a) = a
`Level : Term
`Level = def (quote Level) []
ℕ→Level : ℕ → Level
ℕ→Level zero = lzero
ℕ→Level (suc n) = lsuc (ℕ→Level n)
-- Can't match on Levels anymore
-- Level→ℕ : Level → ℕ
-- Level→ℕ zero = zero
-- Level→ℕ (suc n) = suc (Level→ℕ n)
setLevel : Level → Sort
setLevel ℓ = lit 0 -- (Level→ℕ ℓ)
_==_ : QName → QName → Bool
_==_ = primQNameEquality
decodeSort : Sort → Maybe Level
decodeSort (set (con c [])) = when (quote lzero == c) (just lzero)
decodeSort (set (con c (arg (argInfo visible relevant) s ∷ [])))
= when (quote lsuc == c) (mapMaybe lsuc (decodeSort (set s)))
decodeSort (set (sort s)) = decodeSort s
decodeSort (set _) = nothing
decodeSort (lit n) = just (ℕ→Level n)
decodeSort (prop _) = nothing
decodeSort (propLit _) = nothing
decodeSort (inf _) = nothing
decodeSort unknown = nothing
_`⊔`_ : Sort → Sort → Sort
s₁ `⊔` s₂ with decodeSort s₁ | decodeSort s₂
... | just n₁ | just n₂ = setLevel (n₁ ⊔ n₂)
... | _ | _ = set (def (quote _⊔_) (argᵛʳ (sort s₁) ∷ argᵛʳ (sort s₂) ∷ []))
Π : Arg Type → Type → Type
Π t u = pi t (abs "_" u)
Πᵛʳ : Type → Type → Type
Πᵛʳ t u = Π (vArg t) u
Πʰʳ : Type → Type → Type
Πʰʳ t u = Π (hArg t) u
open ReflectLibrary
`ℕ : Term
`ℕ = def (quote ℕ) []
`ℕOk : (unquote (give `ℕ)) ≡ ℕ
`ℕOk = refl
idℕ : ℕ → ℕ
idℕ = unquote (give (lamᵛ (var 0 [])))
id : (A : Set) → A → A
id = unquote (give (lamᵛ (lamᵛ (var 0 []))))
idBox : Box ({A : Set} → A → A)
idBox = box (unquote (give (lamᵛ (var 0 []))))
-- builds a pair
_`,_ : Term → Term → Term
_`,_ = con`ⁿʳ (quote _,_) 2
`tt : Term
`tt = con (quote tt) []
tuple : List Term → Term
tuple = foldr _`,_ `tt
`refl : Term
`refl = con (quote refl) []
`zero : Term
`zero = con (quote ℕ.zero) []
`[] : Term
`[] = con (quote []) []
_`∷_ : (`x `xs : Term) → Term
_`∷_ = con`ⁿʳ (quote _∷_) 2
`abs : (`s `body : Term) → Term
`abs = con`ⁿʳ (quote abs) 2
`var : (`n `args : Term) → Term
`var = con`ⁿʳ (quote Term.var) 2
`lam : (`hiding `body : Term) → Term
`lam = con`ⁿʳ (quote lam) 2
`lit : Term → Term
`lit = con`ⁿʳ (quote Term.lit) 1
`string : Term → Term
`string = con`ⁿʳ (quote string) 1
`visible : Term
`visible = con (quote visible) []
`hidden : Term
`hidden = con (quote hidden) []
`[_`] : Term → Term
`[ x `] = x `∷ `[]
quotedTwice : Term
quotedTwice = `lam `visible (`abs (lit (string "_")) (`var `zero `[]))
unquoteTwice₂ : ℕ → ℕ
unquoteTwice₂ = unquote (give (unquote (give quotedTwice)))
unquoteTwice : ℕ → ℕ
unquoteTwice x = unquote (give (unquote (give (`var `zero `[]))))
id₂ : {A : Set} → A → A
id₂ = unquote (give (lamᵛ (var 0 [])))
id₃ : {A : Set} → A → A
id₃ x = unquote (give (var 0 []))
module Id {A : Set} (x : A) where
x′ : A
x′ = unquote (give (var 0 []))
k`ℕ : ℕ → Term
k`ℕ zero = `ℕ
k`ℕ (suc n) = unquote (give (def (quote k`ℕ) [ argᵛʳ (var 0 []) ])) -- k`ℕ n
test : id ≡ (λ A (x : A) → x)
× unquote (give `Set₀) ≡ Set
× unquote (give `ℕ) ≡ ℕ
× unquote (give (lamᵛ (var 0 []))) ≡ (λ (x : Set) → x)
× id ≡ (λ A (x : A) → x)
× unquote (give `tt) ≡ tt
× (λ {A} → Id.x′ {A}) ≡ (λ {A : Set} (x : A) → x)
× unquote (give (pi (vArg `Set₀) (abs "_" `Set₀))) ≡ (Set → Set)
× unquoteTwice ≡ (λ (x : ℕ) → x)
× unquote (give (k`ℕ 42)) ≡ ℕ
× unquote (give (lit (nat 15))) ≡ 15
× unquote (give (lit (float 3.1415))) ≡ 3.1415
× unquote (give (lit (string "foo"))) ≡ "foo"
× unquote (give (lit (char 'X'))) ≡ 'X'
× unquote (give (lit (qname (quote ℕ)))) ≡ quote ℕ
× ⊤
test = unquote (give (tuple (replicate n `refl))) where n = 15
Πⁿ : ℕ → Type → Type
Πⁿ zero t = t
Πⁿ (suc n) t = Π (argʰʳ `Set₀) (Πⁿ n t)
ƛⁿ : Hiding → ℕ → Term → Term
ƛⁿ h zero t = t
ƛⁿ h (suc n) t = lam h (abs "_" (ƛⁿ h n t))
-- projᵢ : Proj i n
-- projᵢ = proj i n
-- Projᵢ = {A₁ ... Ai ... An : Set} → A₁ → ... → Aᵢ → ... → An → Aᵢ
-- projᵢ = λ {A₁ ... Ai ... An} x₁ ... xᵢ ... xn → xᵢ
Proj : (i n : ℕ) → Term
Proj i n = Πⁿ n (go n) where
n∸1 = n ∸ 1
go : ℕ → Type
go zero = var ((n + n) ∸ i) []
go (suc m) = Π (argᵛʳ (var n∸1 [])) (go m)
proj : (i n : ℕ) → Term
proj i n = ƛⁿ visible n (var (n ∸ i) [])
projFull : (i n : ℕ) → Term
projFull i n = ƛⁿ hidden n (proj i n)
ℕ→ℕ : Set
ℕ→ℕ = unquote (give (Π (argᵛʳ `ℕ) `ℕ))
ℕ→ℕOk : ℕ→ℕ ≡ (ℕ → ℕ)
ℕ→ℕOk = refl
``∀A→A : Type
``∀A→A = Πᵛʳ `Set₀ (var 0 [])
∀A→A : Set₁
∀A→A = unquote (give ``∀A→A)
Proj₁¹ : Set₁
Proj₁¹ = unquote (give (Proj 1 1))
Proj₁² : Set₁
Proj₁² = unquote (give (Proj 1 2))
Proj₂² : Set₁
Proj₂² = unquote (give (Proj 2 2))
proj₃⁵ : unquote (give (Proj 3 5))
proj₃⁵ _ _ x _ _ = x
proj₃⁵′ : Box (unquote (give (Proj 3 5)))
proj₃⁵′ = box (unquote (give (proj 3 5)))
proj₂⁷ : unquote (give (Proj 2 7))
proj₂⁷ = unquote (give (proj 2 7))
test-proj : proj₃⁵′ ≡ box (λ _ _ x _ _ → x)
× Proj₁¹ ≡ ({A : Set} → A → A)
× Proj₁² ≡ ({A₁ A₂ : Set} → A₁ → A₂ → A₁)
× Proj₂² ≡ ({A₁ A₂ : Set} → A₁ → A₂ → A₂)
× unquote (give (Proj 3 5)) ≡ ({A₁ A₂ A₃ A₄ A₅ : Set} → A₁ → A₂ → A₃ → A₄ → A₅ → A₃)
× unquote (give (projFull 1 1)) ≡ (λ {A : Set} (x : A) → x)
× unquote (give (projFull 1 2)) ≡ (λ {A₁ A₂ : Set} (x₁ : A₁) (x₂ : A₂) → x₁)
× unquote (give (projFull 2 2)) ≡ (λ {A₁ A₂ : Set} (x₁ : A₁) (x₂ : A₂) → x₂)
× ∀A→A ≡ (∀ (A : Set) → A)
× ⊤
test-proj = unquote (give (tuple (replicate n `refl))) where n = 9
module Test where
data Squash (A : Set) : Set where
squash : unquote (give (Π (arg (argInfo visible irrelevant) (var 0 []))
(def (quote Squash) (argᵛʳ (var 1 []) ∷ []))))
data Squash (A : Set) : Set where
squash : .A → Squash A
`Squash : Term → Term
`Squash = def`ⁿʳ (quote Squash) 1
squash-type : Type
squash-type = Π (arg (argInfo visible irrelevant) (var 0 [])) (`Squash (var 1 []))
test-squash : ∀ {A} → (.A → Squash A) ≡ unquote (give squash-type)
test-squash = refl
`∀ℓ→Setℓ : Type
`∀ℓ→Setℓ = Πᵛʳ `Level (sort (set (var 0 [])))
| {
"alphanum_fraction": 0.5103835558,
"avg_line_length": 26.5112359551,
"ext": "agda",
"hexsha": "b3643531a9c39dc33d217f17a62ace600e4666a6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "aea2c53340f509c2c67157caeac360400ea6afbc",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "googleson78/agda",
"max_forks_repo_path": "test/Succeed/TermSplicing.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aea2c53340f509c2c67157caeac360400ea6afbc",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "googleson78/agda",
"max_issues_repo_path": "test/Succeed/TermSplicing.agda",
"max_line_length": 112,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "aea2c53340f509c2c67157caeac360400ea6afbc",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "googleson78/agda",
"max_stars_repo_path": "test/Succeed/TermSplicing.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3978,
"size": 9438
} |
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.NType
open import lib.types.Cospan
open import lib.types.Pointed
open import lib.types.Sigma
module lib.types.Pullback where
module _ {i j k} (D : Cospan {i} {j} {k}) where
open Cospan D
record Pullback : Type (lmax i (lmax j k)) where
constructor pullback
field
a : A
b : B
h : f a == g b
pullback= : {a a' : A} (p : a == a') {b b' : B} (q : b == b')
{h : f a == g b} {h' : f a' == g b'} (r : h ∙ ap g q == ap f p ∙ h')
→ pullback a b h == pullback a' b' h'
pullback= idp idp r =
ap (pullback _ _) (! (∙-unit-r _) ∙ r)
pullback-aβ : {a a' : A} (p : a == a') {b b' : B} (q : b == b')
{h : f a == g b} {h' : f a' == g b'} (r : h ∙ ap g q == ap f p ∙ h')
→ ap Pullback.a (pullback= p q {h = h} {h' = h'} r) == p
pullback-aβ idp idp r =
ap Pullback.a (ap (pullback _ _) (! (∙-unit-r _) ∙ r))
=⟨ ∘-ap Pullback.a (pullback _ _) _ ⟩
ap (λ _ → _) (! (∙-unit-r _) ∙ r)
=⟨ ap-cst _ _ ⟩
idp =∎
pullback-bβ : {a a' : A} (p : a == a') {b b' : B} (q : b == b')
{h : f a == g b} {h' : f a' == g b'} (r : h ∙ ap g q == ap f p ∙ h')
→ ap Pullback.b (pullback= p q {h = h} {h' = h'} r) == q
pullback-bβ idp idp r =
ap Pullback.b (ap (pullback _ _) (! (∙-unit-r _) ∙ r))
=⟨ ∘-ap Pullback.b (pullback _ _) _ ⟩
ap (λ _ → _) (! (∙-unit-r _) ∙ r)
=⟨ ap-cst _ _ ⟩
idp =∎
module _ {i j k} (D : ⊙Cospan {i} {j} {k}) where
⊙Pullback : Ptd (lmax i (lmax j k))
⊙Pullback =
⊙[ Pullback (⊙cospan-out D) ,
pullback (pt X) (pt Y) (snd f ∙ ! (snd g)) ]
where open ⊙Cospan D
module _ {i j k} (D : Cospan {i} {j} {k}) where
open Cospan D
pullback-decomp-equiv : Pullback D ≃ Σ (A × B) (λ {(a , b) → f a == g b})
pullback-decomp-equiv = equiv
(λ {(pullback a b h) → ((a , b) , h)})
(λ {((a , b) , h) → pullback a b h})
(λ _ → idp)
(λ _ → idp)
module _ {i j k} (n : ℕ₋₂) {D : Cospan {i} {j} {k}} where
open Cospan D
pullback-level : has-level n A → has-level n B → has-level n C
→ has-level n (Pullback D)
pullback-level pA pB pC =
equiv-preserves-level ((pullback-decomp-equiv D)⁻¹) $
Σ-level (×-level pA pB) (λ _ → =-preserves-level pC)
| {
"alphanum_fraction": 0.4938434477,
"avg_line_length": 30.7297297297,
"ext": "agda",
"hexsha": "a797ca3272d87493df8eda7abaebf0716afda57f",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mikeshulman/HoTT-Agda",
"max_forks_repo_path": "core/lib/types/Pullback.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mikeshulman/HoTT-Agda",
"max_issues_repo_path": "core/lib/types/Pullback.agda",
"max_line_length": 75,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mikeshulman/HoTT-Agda",
"max_stars_repo_path": "core/lib/types/Pullback.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 962,
"size": 2274
} |
{-# OPTIONS --without-K --safe #-}
module Data.Empty where
open import Data.Empty.Base public
| {
"alphanum_fraction": 0.7083333333,
"avg_line_length": 16,
"ext": "agda",
"hexsha": "4130d0f360e7429edbbc3359c69beccd8e743f8b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Data/Empty.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Data/Empty.agda",
"max_line_length": 34,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Data/Empty.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 20,
"size": 96
} |
{-# OPTIONS --without-K #-}
module tactic where
open import Type
open import Search.Type
open import Search.Searchable
open import Search.Searchable.Product
open import Data.One
open import Data.Product
open import Function
open import Relation.Binary.PropositionalEquality.NP
module _ {R S} (sum-R : Sum R)(sum-R-ext : SumExt sum-R)(sum-S : Sum S) where
su-× : ∀ {f : R → R}{g : S → S} → SumStableUnder sum-R f → SumStableUnder sum-S g
→ SumStableUnder (sum-R ×-sum sum-S) (map f g)
su-× {f}{g} su-f su-g F
= (sum-R ×-sum sum-S) F
≡⟨ sum-R-ext (λ x → su-g (λ y → F ( x , y))) ⟩
(sum-R ×-sum sum-S) (F ∘ map id g)
≡⟨ su-f (λ x → sum-S (λ y → F (map id g (x , y)))) ⟩
(sum-R ×-sum sum-S) (F ∘ map f g)
∎ where open ≡-Reasoning
module _ {R}(sum-R : Sum R) where
su-id : SumStableUnder sum-R id
su-id f = refl
su-∘ : ∀ {f g} → SumStableUnder sum-R f → SumStableUnder sum-R g → SumStableUnder sum-R (f ∘ g)
su-∘ {f} su-f su-g F = trans (su-f F) (su-g (F ∘ f))
module with-sum {R R' S'}(sum-R : Sum R)(sum-R' : Sum R')(sum-S' : Sum S')(sum-R'-ext : SumExt sum-R')
(h : R' → R')(su-h : SumStableUnder sum-R' h)
(to : R' → S' → R)(sum-same : ∀ f → sum-R f ≡ sum-R' (λ r' → sum-S' (f ∘ to r'))) where
principle : ∀ {f g} → (∀ r' → sum-S' (f ∘ to r') ≡ sum-S' (g ∘ to (h r'))) → sum-R f ≡ sum-R g
principle {f}{g} prf
= sum-R f
≡⟨ sum-same f ⟩
sum-R' (λ r' → sum-S' (λ s' → f (to r' s')))
≡⟨ sum-R'-ext (λ r' → prf r') ⟩
sum-R' (λ r' → sum-S' (λ s' → g (to (h r') s')))
≡⟨ sym (su-h (λ r' → sum-S' (λ s' → g (to r' s')))) ⟩
sum-R' (λ r' → sum-S' (λ s' → g (to r' s')))
≡⟨ sym (sum-same g) ⟩
sum-R g
∎
where open ≡-Reasoning
import Function.Inverse.NP as Inv
open Inv using (_↔_) renaming (_$₁_ to to ; _$₂_ to from)
module with-iso {R R' S' : Set}(iso : R ↔ (R' × S'))(h : R' ↔ R') where
open import Function.Related
open import Data.Fin using (Fin)
open import Function.Related.TypeIsomorphisms.NP
principle : ∀ {f g} → (∀ r' → Σ S' (Fin ∘ f ∘ curry (from iso) r')
↔ Σ S' (Fin ∘ g ∘ curry (from iso) (to h r')))
→ Σ R (Fin ∘ f) ↔ Σ R (Fin ∘ g)
principle {f} {g} prf
= Σ R (Fin ∘ f)
↔⟨ first-iso iso ⟩
Σ (R' × S') (Fin ∘ f ∘ from iso)
↔⟨ Σ-assoc ⟩
Σ R' (λ r' → Σ S' (λ s' → Fin (f (from iso (r' , s')))))
↔⟨ second-iso prf ⟩
Σ R' (λ r' → Σ S' (λ s' → Fin (g (from iso (to h r' , s')))))
↔⟨ Inv.sym (first-iso (Inv.sym h)) ⟩
Σ R' (λ r' → Σ S' (λ s' → Fin (g (from iso (r' , s')))))
↔⟨ Inv.sym Σ-assoc ⟩
Σ (R' × S') (Fin ∘ g ∘ from iso)
↔⟨ Inv.sym (first-iso iso) ⟩
Σ R (Fin ∘ g)
∎ where open EquationalReasoning
module _ (sum-R : Sum R)(sum-S' : Sum S')(sum-R-adq : AdequateSum sum-R)(sum-S'-adq : AdequateSum sum-S') where
cool : ∀ {f g} → (∀ r' → sum-S' (f ∘ curry (from iso) r')
≡ sum-S' (g ∘ curry (from iso) (to h r')))
→ sum-R f ≡ sum-R g
cool {f} {g} prf = Fin-injective (Inv.sym (sum-R-adq g)
Inv.∘ principle lemma
Inv.∘ sum-R-adq f)
where
open EquationalReasoning
lemma : (_ : _) → _
lemma r' = Σ S' (Fin ∘ f ∘ curry (from iso) r')
↔⟨ Inv.sym (sum-S'-adq (f ∘ curry (from iso) r')) ⟩
Fin (sum-S' (f ∘ curry (from iso) r'))
↔⟨ Fin-cong (prf r') ⟩
Fin (sum-S' (g ∘ curry (from iso) (to h r')))
↔⟨ sum-S'-adq (g ∘ curry (from iso) (to h r')) ⟩
Σ S' (Fin ∘ g ∘ curry (from iso) (to h r'))
∎
| {
"alphanum_fraction": 0.4777568078,
"avg_line_length": 37.4646464646,
"ext": "agda",
"hexsha": "9957b62f9f4c6777d2e3b4a21075700598624038",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "crypto-agda/explore",
"max_forks_repo_path": "lib/Explore/Experimental/IsoRandomnessSplit.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_issues_repo_issues_event_max_datetime": "2019-03-16T14:24:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-03-16T14:24:04.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "crypto-agda/explore",
"max_issues_repo_path": "lib/Explore/Experimental/IsoRandomnessSplit.agda",
"max_line_length": 113,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "crypto-agda/explore",
"max_stars_repo_path": "lib/Explore/Experimental/IsoRandomnessSplit.agda",
"max_stars_repo_stars_event_max_datetime": "2017-06-28T19:19:29.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-05T09:25:32.000Z",
"num_tokens": 1461,
"size": 3709
} |
-- ByteStrings where we track statically if they're lazy or strict
-- Note that lazy and strict bytestrings have the same semantics
-- in Agda, as all computation is guaranteed to terminate.
-- They may, however, have quite different performance characteristics.
open import Data.Bool using ( Bool )
open import Data.Nat using ( ℕ )
open import Data.Natural using ( Natural ; % )
open import Data.Product using ( _×_ ; _,_ )
open import Data.Word using ( Byte )
open import Data.String using ( String )
open import Data.ByteString.Primitive
module Data.ByteString where
open Data.ByteString.Primitive public using ( mkStrict ; mkLazy )
data Style : Set where
lazy strict : Style
ByteString : Style → Set
ByteString strict = ByteStringStrict
ByteString lazy = ByteStringLazy
ε : {s : Style} → (ByteString s)
ε {lazy} = emptyLazy
ε {strict} = emptyStrict
_∙_ : {s : Style} → (ByteString s) → (ByteString s) → (ByteString s)
_∙_ {lazy} = appendLazy
_∙_ {strict} = appendStrict
_◁_ : {s : Style} → Byte → (ByteString s) → (ByteString s)
_◁_ {lazy} = consLazy
_◁_ {strict} = consStrict
_▷_ : {s : Style} → (ByteString s) → Byte → (ByteString s)
_▷_ {lazy} = snocLazy
_▷_ {strict} = snocStrict
length : {s : Style} → (ByteString s) → Natural
length {lazy} = lengthLazy
length {strict} = lengthStrict
size : {s : Style} → (ByteString s) → ℕ
size bs = %(length bs)
null : {s : Style} → (ByteString s) → Bool
null {lazy} = nullLazy
null {strict} = nullStrict
span : {s : Style} → (Byte → Bool) → (ByteString s) → (ByteString s × ByteString s)
span {lazy} φ bs with spanLazy φ bs
span {lazy} φ bs | bs² = (lazy₁ bs² , lazy₂ bs²)
span {strict} φ bs with spanStrict φ bs
span {strict} φ bs | bs² = (strict₁ bs² , strict₂ bs²)
break : {s : Style} → (Byte → Bool) → (ByteString s) → (ByteString s × ByteString s)
break {lazy} φ bs with breakLazy φ bs
break {lazy} φ bs | bs² = (lazy₁ bs² , lazy₂ bs²)
break {strict} φ bs with breakStrict φ bs
break {strict} φ bs | bs² = (strict₁ bs² , strict₂ bs²)
| {
"alphanum_fraction": 0.6828063241,
"avg_line_length": 32.126984127,
"ext": "agda",
"hexsha": "c40e4770833190d1c7b2b9b84f21d99d366984df",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:23.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-08-10T06:12:54.000Z",
"max_forks_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ilya-fiveisky/agda-system-io",
"max_forks_repo_path": "src/Data/ByteString.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "ilya-fiveisky/agda-system-io",
"max_issues_repo_path": "src/Data/ByteString.agda",
"max_line_length": 84,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ilya-fiveisky/agda-system-io",
"max_stars_repo_path": "src/Data/ByteString.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-15T04:35:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-04T13:45:16.000Z",
"num_tokens": 629,
"size": 2024
} |
module BasicConcreteImplementations where
open import AbstractInterfaces public
-- Process identifiers.
instance
⟨P⟩ : IsProc
⟨P⟩ = record
{ Proc = ℕ
; _≡ₚ?_ = _≡?_
; _<ₚ_ = _<_
; trans<ₚ = trans<
; tri<ₚ = tri<
}
-- Process clocks, message timestamps, and event timestamps.
instance
⟨T⟩ : IsTime
⟨T⟩ = record
{ Time = ℕ
; _≡ₜ?_ = _≡?_
; _<ₜ_ = _<_
; trans<ₜ = trans<
; tri<ₜ = tri<
; irrefl<ₜ = irrefl<
; sucₜ = suc
; _⊔ₜ_ = _⊔_
; n<s[n⊔m]ₜ = n<s[n⊔m]
}
-- Messages.
data BasicMsg : (Pᵢ Pⱼ : Proc) (Tₘ : Time) → Set where
instance
⟨M⟩ : IsMsg
⟨M⟩ = record
{ Msg = BasicMsg
}
-- Events within one process.
data BasicEvent : Proc → Time → Set where
send : ∀ {Cᵢ Pᵢ Pⱼ Tₘ} {{_ : Tₘ ≡ sucₜ Cᵢ}} →
Msg Pᵢ Pⱼ Tₘ → BasicEvent Pᵢ Tₘ
recv : ∀ {Cⱼ Pᵢ Pⱼ Tₘ Tⱼ} {{_ : Tⱼ ≡ sucₜ (Tₘ ⊔ₜ Cⱼ)}} →
Msg Pᵢ Pⱼ Tₘ → BasicEvent Pⱼ Tⱼ
instance
⟨E⟩ : IsEvent
⟨E⟩ = record
{ Event = BasicEvent
; isSendₑ = λ {Cᵢ} m a → a ≡ send {Cᵢ} m
; isRecvₑ = λ {Cⱼ} m a → a ≡ recv {Cⱼ} m
; absurdₑ = λ { {{refl}} (refl , ()) }
}
| {
"alphanum_fraction": 0.4508320726,
"avg_line_length": 20.65625,
"ext": "agda",
"hexsha": "d71b8777962bb461e594ef8e34e25af23d414335",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b685baa99230c3d5fd1e41c66d325575b70308c4",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/lamport-timestamps",
"max_forks_repo_path": "BasicConcreteImplementations.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b685baa99230c3d5fd1e41c66d325575b70308c4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/lamport-timestamps",
"max_issues_repo_path": "BasicConcreteImplementations.agda",
"max_line_length": 60,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b685baa99230c3d5fd1e41c66d325575b70308c4",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/lamport-timestamps",
"max_stars_repo_path": "BasicConcreteImplementations.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 551,
"size": 1322
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.