Search is not available for this dataset
text string | meta dict |
|---|---|
------------------------------------------------------------------------
-- Properties satisfied by posets
------------------------------------------------------------------------
open import Relation.Binary
module Relation.Binary.Props.Poset (p : Poset) where
open Relation.Binary.Poset p hiding (trans)
import Relation.Binary.NonStrictToStrict as Conv
open Conv _≈_ _≤_
------------------------------------------------------------------------
-- Posets can be turned into strict partial orders
strictPartialOrder : StrictPartialOrder
strictPartialOrder = record
{ isStrictPartialOrder = record
{ isEquivalence = isEquivalence
; irrefl = irrefl
; trans = trans isPartialOrder
; <-resp-≈ = <-resp-≈ isEquivalence ≤-resp-≈
}
}
open StrictPartialOrder strictPartialOrder
| {
"alphanum_fraction": 0.5311355311,
"avg_line_length": 30.3333333333,
"ext": "agda",
"hexsha": "20964c5fb7770914a10bde3fe49ca1af56b190b8",
"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/Props/Poset.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/Props/Poset.agda",
"max_line_length": 72,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "vendor/stdlib/src/Relation/Binary/Props/Poset.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": 164,
"size": 819
} |
{-# OPTIONS --without-K #-}
module container.fixpoint where
open import sum
open import level
open import container.core
open import function.core
open import function.isomorphism
open import function.overloading
record Fixpoint {li la lb}
(c : Container li la lb)
(lx : Level) : Set (li ⊔ la ⊔ lb ⊔ lsuc lx) where
constructor fix
open Container c
field
X : I → Set lx
fixpoint : ∀ i → X i ≅ F X i
head : ∀ {i} → X i → A i
head {i} = proj₁ ∘ apply (fixpoint i)
tail : ∀ {i}(u : X i)(b : B (head u)) → X (r b)
tail {i} = proj₂ ∘' apply (fixpoint i)
| {
"alphanum_fraction": 0.6019736842,
"avg_line_length": 22.5185185185,
"ext": "agda",
"hexsha": "bd8550d4b2f2b703c2a15d419825360feda9cf70",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-02-26T06:17:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-11T17:19:12.000Z",
"max_forks_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "HoTT/M-types",
"max_forks_repo_path": "container/fixpoint.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/container/fixpoint.agda",
"max_line_length": 65,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "HoTT/M-types",
"max_stars_repo_path": "container/fixpoint.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": 191,
"size": 608
} |
module plfa.part2.Properties-peer where
open import Relation.Binary.PropositionalEquality
using (_≡_; _≢_; refl; sym; cong; cong₂)
open import Data.String using (String; _≟_)
open import Data.Nat using (ℕ; zero; suc)
open import Data.Empty using (⊥; ⊥-elim)
open import Data.Product
using (_×_; proj₁; proj₂; ∃; ∃-syntax)
renaming (_,_ to ⟨_,_⟩)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Relation.Nullary using (¬_; Dec; yes; no)
open import Function using (_∘_)
open import plfa.part1.Isomorphism
open import plfa.part2.Lambda
V¬—→ : ∀ {M N}
→ Value M
----------
→ ¬ (M —→ N)
V¬—→ V-ƛ ()
V¬—→ V-zero ()
V¬—→ (V-suc VM) (ξ-suc M—→N) = V¬—→ VM M—→N
—→¬V : ∀ {M N}
→ M —→ N
---------
→ ¬ Value M
—→¬V M—→N VM = V¬—→ VM M—→N
infix 4 Canonical_⦂_
data Canonical_⦂_ : Term → Type → Set where
C-ƛ : ∀ {x A N B}
→ ∅ , x ⦂ A ⊢ N ⦂ B
-----------------------------
→ Canonical (ƛ x ⇒ N) ⦂ (A ⇒ B)
C-zero :
--------------------
Canonical `zero ⦂ `ℕ
C-suc : ∀ {V}
→ Canonical V ⦂ `ℕ
---------------------
→ Canonical `suc V ⦂ `ℕ
canonical : ∀ {V A}
→ ∅ ⊢ V ⦂ A
→ Value V
-----------
→ Canonical V ⦂ A
canonical (⊢` ()) ()
canonical (⊢ƛ ⊢N) V-ƛ = C-ƛ ⊢N
canonical (⊢L · ⊢M) ()
canonical ⊢zero V-zero = C-zero
canonical (⊢suc ⊢V) (V-suc VV) = C-suc (canonical ⊢V VV)
canonical (⊢case ⊢L ⊢M ⊢N) ()
canonical (⊢μ ⊢M) ()
value : ∀ {M A}
→ Canonical M ⦂ A
----------------
→ Value M
value (C-ƛ ⊢N) = V-ƛ
value C-zero = V-zero
value (C-suc CM) = V-suc (value CM)
typed : ∀ {M A}
→ Canonical M ⦂ A
---------------
→ ∅ ⊢ M ⦂ A
typed (C-ƛ ⊢N) = ⊢ƛ ⊢N
typed C-zero = ⊢zero
typed (C-suc CM) = ⊢suc (typed CM)
data Progress (M : Term) : Set where
step : ∀ {N}
→ M —→ N
----------
→ Progress M
done :
Value M
----------
→ Progress M
progress : ∀ {M A}
→ ∅ ⊢ M ⦂ A
----------
→ Progress M
progress (⊢` ())
progress (⊢ƛ ⊢N) = done V-ƛ
progress (⊢L · ⊢M) with progress ⊢L
... | step L—→L′ = step (ξ-·₁ L—→L′)
... | done VL with progress ⊢M
... | step M—→M′ = step (ξ-·₂ VL M—→M′)
... | done VM with canonical ⊢L VL
... | C-ƛ _ = step (β-ƛ VM)
progress ⊢zero = done V-zero
progress (⊢suc ⊢M) with progress ⊢M
... | step M—→M′ = step (ξ-suc M—→M′)
... | done VM = done (V-suc VM)
progress (⊢case ⊢L ⊢M ⊢N) with progress ⊢L
... | step L—→L′ = step (ξ-case L—→L′)
... | done VL with canonical ⊢L VL
... | C-zero = step β-zero
... | C-suc CL = step (β-suc (value CL))
progress (⊢μ ⊢M) = step β-μ
postulate
progress′ : ∀ M {A} → ∅ ⊢ M ⦂ A → Value M ⊎ ∃[ N ](M —→ N)
ext : ∀ {Γ Δ}
→ (∀ {x A} → Γ ∋ x ⦂ A → Δ ∋ x ⦂ A)
-----------------------------------------------------
→ (∀ {x y A B} → Γ , y ⦂ B ∋ x ⦂ A → Δ , y ⦂ B ∋ x ⦂ A)
ext ρ Z = Z
ext ρ (S x≢y ∋x) = S x≢y (ρ ∋x)
rename : ∀ {Γ Δ}
→ (∀ {x A} → Γ ∋ x ⦂ A → Δ ∋ x ⦂ A)
----------------------------------
→ (∀ {M A} → Γ ⊢ M ⦂ A → Δ ⊢ M ⦂ A)
rename ρ (⊢` ∋w) = ⊢` (ρ ∋w)
rename ρ (⊢ƛ ⊢N) = ⊢ƛ (rename (ext ρ) ⊢N)
rename ρ (⊢L · ⊢M) = (rename ρ ⊢L) · (rename ρ ⊢M)
rename ρ ⊢zero = ⊢zero
rename ρ (⊢suc ⊢M) = ⊢suc (rename ρ ⊢M)
rename ρ (⊢case ⊢L ⊢M ⊢N) = ⊢case (rename ρ ⊢L) (rename ρ ⊢M) (rename (ext ρ) ⊢N)
rename ρ (⊢μ ⊢M) = ⊢μ (rename (ext ρ) ⊢M)
weaken : ∀ {Γ M A}
→ ∅ ⊢ M ⦂ A
----------
→ Γ ⊢ M ⦂ A
weaken {Γ} ⊢M = rename ρ ⊢M
where
ρ : ∀ {z C}
→ ∅ ∋ z ⦂ C
---------
→ Γ ∋ z ⦂ C
ρ ()
drop : ∀ {Γ x M A B C}
→ Γ , x ⦂ A , x ⦂ B ⊢ M ⦂ C
--------------------------
→ Γ , x ⦂ B ⊢ M ⦂ C
drop {Γ} {x} {M} {A} {B} {C} ⊢M = rename ρ ⊢M
where
ρ : ∀ {z C}
→ Γ , x ⦂ A , x ⦂ B ∋ z ⦂ C
-------------------------
→ Γ , x ⦂ B ∋ z ⦂ C
ρ Z = Z
ρ (S x≢x Z) = ⊥-elim (x≢x refl)
ρ (S z≢x (S _ ∋z)) = S z≢x ∋z
swap : ∀ {Γ x y M A B C}
→ x ≢ y
→ Γ , y ⦂ B , x ⦂ A ⊢ M ⦂ C
--------------------------
→ Γ , x ⦂ A , y ⦂ B ⊢ M ⦂ C
swap {Γ} {x} {y} {M} {A} {B} {C} x≢y ⊢M = rename ρ ⊢M
where
ρ : ∀ {z C}
→ Γ , y ⦂ B , x ⦂ A ∋ z ⦂ C
--------------------------
→ Γ , x ⦂ A , y ⦂ B ∋ z ⦂ C
ρ Z = S x≢y Z
ρ (S z≢x Z) = Z
ρ (S z≢x (S z≢y ∋z)) = S z≢y (S z≢x ∋z)
subst : ∀ {Γ x N V A B}
→ ∅ ⊢ V ⦂ A
→ Γ , x ⦂ A ⊢ N ⦂ B
--------------------
→ Γ ⊢ N [ x := V ] ⦂ B
subst {x = y} ⊢V (⊢` {x = x} Z) with x ≟ y
... | yes _ = weaken ⊢V
... | no x≢y = ⊥-elim (x≢y refl)
subst {x = y} ⊢V (⊢` {x = x} (S x≢y ∋x)) with x ≟ y
... | yes refl = ⊥-elim (x≢y refl)
... | no _ = ⊢` ∋x
subst {x = y} ⊢V (⊢ƛ {x = x} ⊢N) with x ≟ y
... | yes refl = ⊢ƛ (drop ⊢N)
... | no x≢y = ⊢ƛ (subst ⊢V (swap x≢y ⊢N))
subst ⊢V (⊢L · ⊢M) = (subst ⊢V ⊢L) · (subst ⊢V ⊢M)
subst ⊢V ⊢zero = ⊢zero
subst ⊢V (⊢suc ⊢M) = ⊢suc (subst ⊢V ⊢M)
subst {x = y} ⊢V (⊢case {x = x} ⊢L ⊢M ⊢N) with x ≟ y
... | yes refl = ⊢case (subst ⊢V ⊢L) (subst ⊢V ⊢M) (drop ⊢N)
... | no x≢y = ⊢case (subst ⊢V ⊢L) (subst ⊢V ⊢M) (subst ⊢V (swap x≢y ⊢N))
subst {x = y} ⊢V (⊢μ {x = x} ⊢M) with x ≟ y
... | yes refl = ⊢μ (drop ⊢M)
... | no x≢y = ⊢μ (subst ⊢V (swap x≢y ⊢M))
preserve : ∀ {M N A}
→ ∅ ⊢ M ⦂ A
→ M —→ N
----------
→ ∅ ⊢ N ⦂ A
preserve (⊢` ())
preserve (⊢ƛ ⊢N) ()
preserve (⊢L · ⊢M) (ξ-·₁ L—→L′) = (preserve ⊢L L—→L′) · ⊢M
preserve (⊢L · ⊢M) (ξ-·₂ VL M—→M′) = ⊢L · (preserve ⊢M M—→M′)
preserve ((⊢ƛ ⊢N) · ⊢V) (β-ƛ VV) = subst ⊢V ⊢N
preserve ⊢zero ()
preserve (⊢suc ⊢M) (ξ-suc M—→M′) = ⊢suc (preserve ⊢M M—→M′)
preserve (⊢case ⊢L ⊢M ⊢N) (ξ-case L—→L′) = ⊢case (preserve ⊢L L—→L′) ⊢M ⊢N
preserve (⊢case ⊢zero ⊢M ⊢N) (β-zero) = ⊢M
preserve (⊢case (⊢suc ⊢V) ⊢M ⊢N) (β-suc VV) = subst ⊢V ⊢N
preserve (⊢μ ⊢M) (β-μ) = subst (⊢μ ⊢M) ⊢M
sucμ = μ "x" ⇒ `suc (` "x")
data Gas : Set where
gas : ℕ → Gas
data Finished (N : Term) : Set where
done :
Value N
----------
→ Finished N
out-of-gas :
----------
Finished N
data Steps (L : Term) : Set where
steps : ∀ {N}
→ L —↠ N
→ Finished N
----------
→ Steps L
{-# TERMINATING #-}
eval : ∀ {L A}
→ Gas
→ ∅ ⊢ L ⦂ A
---------
→ Steps L
eval {L} (gas zero) ⊢L = steps (L ∎) out-of-gas
eval {L} (gas (suc m)) ⊢L with progress ⊢L
... | done VL = steps (L ∎) (done VL)
... | step L—→M with eval (gas m) (preserve ⊢L L—→M)
... | steps M—↠N fin = steps (L —→⟨ L—→M ⟩ M—↠N) fin
⊢sucμ : ∅ ⊢ μ "x" ⇒ `suc ` "x" ⦂ `ℕ
⊢sucμ = ⊢μ (⊢suc (⊢` ∋x))
where
∋x = Z
_ : eval (gas 3) ⊢sucμ ≡
steps
(μ "x" ⇒ `suc ` "x"
—→⟨ β-μ ⟩
`suc (μ "x" ⇒ `suc ` "x")
—→⟨ ξ-suc β-μ ⟩
`suc (`suc (μ "x" ⇒ `suc ` "x"))
—→⟨ ξ-suc (ξ-suc β-μ) ⟩
`suc (`suc (`suc (μ "x" ⇒ `suc ` "x")))
∎)
out-of-gas
_ = refl
_ : eval (gas 100) (⊢twoᶜ · ⊢sucᶜ · ⊢zero) ≡
steps
((ƛ "s" ⇒ (ƛ "z" ⇒ ` "s" · (` "s" · ` "z"))) · (ƛ "n" ⇒ `suc ` "n")
· `zero
—→⟨ ξ-·₁ (β-ƛ V-ƛ) ⟩
(ƛ "z" ⇒ (ƛ "n" ⇒ `suc ` "n") · ((ƛ "n" ⇒ `suc ` "n") · ` "z")) ·
`zero
—→⟨ β-ƛ V-zero ⟩
(ƛ "n" ⇒ `suc ` "n") · ((ƛ "n" ⇒ `suc ` "n") · `zero)
—→⟨ ξ-·₂ V-ƛ (β-ƛ V-zero) ⟩
(ƛ "n" ⇒ `suc ` "n") · `suc `zero
—→⟨ β-ƛ (V-suc V-zero) ⟩
`suc (`suc `zero)
∎)
(done (V-suc (V-suc V-zero)))
_ = refl
_ : eval (gas 100) ⊢2+2 ≡
steps
((μ "+" ⇒
(ƛ "m" ⇒
(ƛ "n" ⇒
case ` "m" [zero⇒ ` "n" |suc "m" ⇒ `suc (` "+" · ` "m" · ` "n")
])))
· `suc (`suc `zero)
· `suc (`suc `zero)
—→⟨ ξ-·₁ (ξ-·₁ β-μ) ⟩
(ƛ "m" ⇒
(ƛ "n" ⇒
case ` "m" [zero⇒ ` "n" |suc "m" ⇒
`suc
((μ "+" ⇒
(ƛ "m" ⇒
(ƛ "n" ⇒
case ` "m" [zero⇒ ` "n" |suc "m" ⇒ `suc (` "+" · ` "m" · ` "n")
])))
· ` "m"
· ` "n")
]))
· `suc (`suc `zero)
· `suc (`suc `zero)
—→⟨ ξ-·₁ (β-ƛ (V-suc (V-suc V-zero))) ⟩
(ƛ "n" ⇒
case `suc (`suc `zero) [zero⇒ ` "n" |suc "m" ⇒
`suc
((μ "+" ⇒
(ƛ "m" ⇒
(ƛ "n" ⇒
case ` "m" [zero⇒ ` "n" |suc "m" ⇒ `suc (` "+" · ` "m" · ` "n")
])))
· ` "m"
· ` "n")
])
· `suc (`suc `zero)
—→⟨ β-ƛ (V-suc (V-suc V-zero)) ⟩
case `suc (`suc `zero) [zero⇒ `suc (`suc `zero) |suc "m" ⇒
`suc
((μ "+" ⇒
(ƛ "m" ⇒
(ƛ "n" ⇒
case ` "m" [zero⇒ ` "n" |suc "m" ⇒ `suc (` "+" · ` "m" · ` "n")
])))
· ` "m"
· `suc (`suc `zero))
]
—→⟨ β-suc (V-suc V-zero) ⟩
`suc
((μ "+" ⇒
(ƛ "m" ⇒
(ƛ "n" ⇒
case ` "m" [zero⇒ ` "n" |suc "m" ⇒ `suc (` "+" · ` "m" · ` "n")
])))
· `suc `zero
· `suc (`suc `zero))
—→⟨ ξ-suc (ξ-·₁ (ξ-·₁ β-μ)) ⟩
`suc
((ƛ "m" ⇒
(ƛ "n" ⇒
case ` "m" [zero⇒ ` "n" |suc "m" ⇒
`suc
((μ "+" ⇒
(ƛ "m" ⇒
(ƛ "n" ⇒
case ` "m" [zero⇒ ` "n" |suc "m" ⇒ `suc (` "+" · ` "m" · ` "n")
])))
· ` "m"
· ` "n")
]))
· `suc `zero
· `suc (`suc `zero))
—→⟨ ξ-suc (ξ-·₁ (β-ƛ (V-suc V-zero))) ⟩
`suc
((ƛ "n" ⇒
case `suc `zero [zero⇒ ` "n" |suc "m" ⇒
`suc
((μ "+" ⇒
(ƛ "m" ⇒
(ƛ "n" ⇒
case ` "m" [zero⇒ ` "n" |suc "m" ⇒ `suc (` "+" · ` "m" · ` "n")
])))
· ` "m"
· ` "n")
])
· `suc (`suc `zero))
—→⟨ ξ-suc (β-ƛ (V-suc (V-suc V-zero))) ⟩
`suc
case `suc `zero [zero⇒ `suc (`suc `zero) |suc "m" ⇒
`suc
((μ "+" ⇒
(ƛ "m" ⇒
(ƛ "n" ⇒
case ` "m" [zero⇒ ` "n" |suc "m" ⇒ `suc (` "+" · ` "m" · ` "n")
])))
· ` "m"
· `suc (`suc `zero))
]
—→⟨ ξ-suc (β-suc V-zero) ⟩
`suc
(`suc
((μ "+" ⇒
(ƛ "m" ⇒
(ƛ "n" ⇒
case ` "m" [zero⇒ ` "n" |suc "m" ⇒ `suc (` "+" · ` "m" · ` "n")
])))
· `zero
· `suc (`suc `zero)))
—→⟨ ξ-suc (ξ-suc (ξ-·₁ (ξ-·₁ β-μ))) ⟩
`suc
(`suc
((ƛ "m" ⇒
(ƛ "n" ⇒
case ` "m" [zero⇒ ` "n" |suc "m" ⇒
`suc
((μ "+" ⇒
(ƛ "m" ⇒
(ƛ "n" ⇒
case ` "m" [zero⇒ ` "n" |suc "m" ⇒ `suc (` "+" · ` "m" · ` "n")
])))
· ` "m"
· ` "n")
]))
· `zero
· `suc (`suc `zero)))
—→⟨ ξ-suc (ξ-suc (ξ-·₁ (β-ƛ V-zero))) ⟩
`suc
(`suc
((ƛ "n" ⇒
case `zero [zero⇒ ` "n" |suc "m" ⇒
`suc
((μ "+" ⇒
(ƛ "m" ⇒
(ƛ "n" ⇒
case ` "m" [zero⇒ ` "n" |suc "m" ⇒ `suc (` "+" · ` "m" · ` "n")
])))
· ` "m"
· ` "n")
])
· `suc (`suc `zero)))
—→⟨ ξ-suc (ξ-suc (β-ƛ (V-suc (V-suc V-zero)))) ⟩
`suc
(`suc
case `zero [zero⇒ `suc (`suc `zero) |suc "m" ⇒
`suc
((μ "+" ⇒
(ƛ "m" ⇒
(ƛ "n" ⇒
case ` "m" [zero⇒ ` "n" |suc "m" ⇒ `suc (` "+" · ` "m" · ` "n")
])))
· ` "m"
· `suc (`suc `zero))
])
—→⟨ ξ-suc (ξ-suc β-zero) ⟩
`suc (`suc (`suc (`suc `zero)))
∎)
(done (V-suc (V-suc (V-suc (V-suc V-zero)))))
_ = refl
Normal : Term → Set
Normal M = ∀ {N} → ¬ (M —→ N)
Stuck : Term → Set
Stuck M = Normal M × ¬ Value M
-- Exercise Progress-≃ (practice)
Progress-≃ : ∀ {M} → Progress M ≃ Value M ⊎ ∃[ N ](M —→ N)
Progress-≃ {M} = record
{ to = to
; from = from
; from∘to = from∘to
; to∘from = to∘from }
where
to : ∀ { M } → Progress M → Value M ⊎ ∃[ N ](M —→ N)
to (done m) = inj₁ m
to (step {N} M→N) = inj₂ ⟨ N , M→N ⟩
from : ∀ { M } → Value M ⊎ ∃[ N ](M —→ N) → Progress M
from (inj₁ m) = done m
from (inj₂ ⟨ N , M→N ⟩) = step M→N
from∘to : ∀ { M } → (m : Progress M) → from (to m) ≡ m
from∘to (done m) = refl
from∘to (step M→N) = refl
to∘from : ∀ { M } ( s : Value M ⊎ ∃[ N ](M —→ N)) → to (from s) ≡ s
to∘from (inj₁ m) = refl
to∘from (inj₂ ⟨ N , M→N ⟩) = refl
-- Exercise value? (practice)
value? : ∀ {A M} → ∅ ⊢ M ⦂ A → Dec (Value M)
value? ⊢M with progress ⊢M
... | done m = yes m
... | step M→N = no (—→¬V M→N)
-- Exercise mul-eval (recommended)
mulᶜ : Term
mulᶜ = ƛ "m" ⇒ ƛ "n" ⇒ ƛ "s" ⇒ ƛ "z" ⇒
` "m" · (` "n" · ` "s" ) · ` "z"
⊢mulᶜ : ∀ {Γ A} → Γ ⊢ mulᶜ ⦂ Ch A ⇒ Ch A ⇒ Ch A
⊢mulᶜ = ⊢ƛ (⊢ƛ (⊢ƛ (⊢ƛ (⊢m · ⊢z))))
where
⊢m = (⊢` (S (λ()) (S (λ()) (S (λ()) Z))))
· (⊢` (S (λ()) (S (λ()) Z))
· (⊢` (S (λ()) Z)))
⊢z = ⊢` Z
⊢2*2ᶜ : ∅ ⊢ mulᶜ · twoᶜ · twoᶜ · sucᶜ · `zero ⦂ `ℕ
⊢2*2ᶜ = ⊢mulᶜ · ⊢twoᶜ · ⊢twoᶜ · ⊢sucᶜ · ⊢zero
_ : eval (gas 100) (⊢2*2ᶜ) ≡
steps
((ƛ "m" ⇒
(ƛ "n" ⇒ (
ƛ "s" ⇒ (ƛ "z" ⇒ ` "m" · (` "n" · ` "s") · ` "z"))))
· (ƛ "s" ⇒ (ƛ "z" ⇒ ` "s" · (` "s" · ` "z")))
· (ƛ "s" ⇒ (ƛ "z" ⇒ ` "s" · (` "s" · ` "z")))
· (ƛ "n" ⇒ `suc ` "n")
· `zero
—→⟨ ξ-·₁ (ξ-·₁ (ξ-·₁ (β-ƛ V-ƛ))) ⟩
(ƛ "n" ⇒
(ƛ "s" ⇒
(ƛ "z" ⇒
(ƛ "s" ⇒ (ƛ "z" ⇒ ` "s" · (` "s" · ` "z"))) · (` "n" · ` "s") · ` "z")))
· (ƛ "s" ⇒ (ƛ "z" ⇒ ` "s" · (` "s" · ` "z")))
· (ƛ "n" ⇒ `suc ` "n")
· `zero
—→⟨ ξ-·₁ (ξ-·₁ (β-ƛ V-ƛ)) ⟩
(ƛ "s" ⇒
(ƛ "z" ⇒
(ƛ "s" ⇒ (ƛ "z" ⇒ ` "s" · (` "s" · ` "z"))) ·
((ƛ "s" ⇒ (ƛ "z" ⇒ ` "s" · (` "s" · ` "z"))) · ` "s") · ` "z"))
· (ƛ "n" ⇒ `suc ` "n")
· `zero
—→⟨ ξ-·₁ (β-ƛ V-ƛ) ⟩
(ƛ "z" ⇒
(ƛ "s" ⇒ (ƛ "z" ⇒ ` "s" · (` "s" · ` "z"))) ·
((ƛ "s" ⇒ (ƛ "z" ⇒ ` "s" · (` "s" · ` "z"))) ·
(ƛ "n" ⇒ `suc ` "n"))
· ` "z")
· `zero
—→⟨ β-ƛ V-zero ⟩
(ƛ "s" ⇒ (ƛ "z" ⇒ ` "s" · (` "s" · ` "z"))) ·
((ƛ "s" ⇒ (ƛ "z" ⇒ ` "s" · (` "s" · ` "z"))) ·
(ƛ "n" ⇒ `suc ` "n"))
· `zero
—→⟨ ξ-·₁ (ξ-·₂ V-ƛ (β-ƛ V-ƛ)) ⟩
(ƛ "s" ⇒ (ƛ "z" ⇒ ` "s" · (` "s" · ` "z"))) ·
(ƛ "z" ⇒ (ƛ "n" ⇒ `suc ` "n") · ((ƛ "n" ⇒ `suc ` "n") · ` "z"))
· `zero
—→⟨ ξ-·₁ (β-ƛ V-ƛ) ⟩
(ƛ "z" ⇒
(ƛ "z" ⇒ (ƛ "n" ⇒ `suc ` "n") · ((ƛ "n" ⇒ `suc ` "n") · ` "z")) ·
((ƛ "z" ⇒ (ƛ "n" ⇒ `suc ` "n") · ((ƛ "n" ⇒ `suc ` "n") · ` "z")) · ` "z"))
· `zero
—→⟨ β-ƛ V-zero ⟩
(ƛ "z" ⇒ (ƛ "n" ⇒ `suc ` "n") · ((ƛ "n" ⇒ `suc ` "n") · ` "z")) ·
((ƛ "z" ⇒ (ƛ "n" ⇒ `suc ` "n") · ((ƛ "n" ⇒ `suc ` "n") · ` "z")) ·
`zero)
—→⟨ ξ-·₂ V-ƛ (β-ƛ V-zero) ⟩
(ƛ "z" ⇒ (ƛ "n" ⇒ `suc ` "n") · ((ƛ "n" ⇒ `suc ` "n") · ` "z")) ·
((ƛ "n" ⇒ `suc ` "n") · ((ƛ "n" ⇒ `suc ` "n") · `zero))
—→⟨ ξ-·₂ V-ƛ (ξ-·₂ V-ƛ (β-ƛ V-zero)) ⟩
(ƛ "z" ⇒ (ƛ "n" ⇒ `suc ` "n") · ((ƛ "n" ⇒ `suc ` "n") · ` "z")) ·
((ƛ "n" ⇒ `suc ` "n") · `suc `zero)
—→⟨ ξ-·₂ V-ƛ (β-ƛ (V-suc V-zero)) ⟩
(ƛ "z" ⇒ (ƛ "n" ⇒ `suc ` "n") · ((ƛ "n" ⇒ `suc ` "n") · ` "z")) ·
`suc (`suc `zero)
—→⟨ β-ƛ (V-suc (V-suc V-zero)) ⟩
(ƛ "n" ⇒ `suc ` "n") · ((ƛ "n" ⇒ `suc ` "n") · `suc (`suc `zero))
—→⟨ ξ-·₂ V-ƛ (β-ƛ (V-suc (V-suc V-zero))) ⟩
(ƛ "n" ⇒ `suc ` "n") · `suc (`suc (`suc `zero)) —→⟨
β-ƛ (V-suc (V-suc (V-suc V-zero))) ⟩
`suc (`suc (`suc (`suc `zero))) ∎)
(done (V-suc (V-suc (V-suc (V-suc V-zero)))))
_ = refl
-- Exercise: progress-preservation (practice)
-- progress: If there exists a term M ⦂ A, then M must either be a value, or there exists an N such that M —→ N
-- preservation: If term M ⦂ A and N can be reduced from M, then N ⦂ A.
-- Exercise subject_expansion (practice)
-- counter example with case expression
-- M = case `suc V [zero ⇒ N |suc x ⇒ T ], ∅ ⊢ N ⦂ A, ∅ ⊢ T ⦂ B
-- In this example, M does not have a type, but M —→ A or M —→ B.
-- counter example without case expression
-- M —→ N, ∅ ⊢ N ⦂ A → B → A and N = λ a b. a
-- Exercise stuck (practice)
-- example: `zero · `suc `zero
-- The example above is an ill-typed term.
-- Exercise unstuck (recommended)
unstuck : ∀ {M A}
→ ∅ ⊢ M ⦂ A
-----------
→ ¬ (Stuck M)
unstuck m ⟨ fst , snd ⟩ with progress m
... | done m₁ = ⊥-elim (snd m₁)
... | step m₁ = ⊥-elim (fst m₁)
preserves : ∀ {M N A}
→ ∅ ⊢ M ⦂ A
→ M —↠ N
---------
→ ∅ ⊢ N ⦂ A
preserves m (M _—↠_.∎) = m
preserves m (L —→⟨ LM ⟩ MN) = preserves (preserve m LM) MN
wttdgs : ∀ {M N A}
→ ∅ ⊢ M ⦂ A
→ M —↠ N
-----------
→ ¬ (Stuck N)
wttdgs a n = unstuck (preserves a n)
| {
"alphanum_fraction": 0.3448939112,
"avg_line_length": 26.3660855784,
"ext": "agda",
"hexsha": "ea4274258cead4c1b43f69fbd68a7b516e43875b",
"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": "1961af3a34b519106824bf13f4a9d9b7d63a0a9b",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "billyang98/plfa.github.io",
"max_forks_repo_path": "src/plfa/part2/Properties-peer.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1961af3a34b519106824bf13f4a9d9b7d63a0a9b",
"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": "billyang98/plfa.github.io",
"max_issues_repo_path": "src/plfa/part2/Properties-peer.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1961af3a34b519106824bf13f4a9d9b7d63a0a9b",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "billyang98/plfa.github.io",
"max_stars_repo_path": "src/plfa/part2/Properties-peer.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 8237,
"size": 16637
} |
{-# OPTIONS --without-K --rewriting #-}
module lib.two-semi-categories.TwoSemiCategories where
open import lib.two-semi-categories.FunCategory public
open import lib.two-semi-categories.Functor public
open import lib.two-semi-categories.FunctorInverse public
open import lib.two-semi-categories.FundamentalCategory public
open import lib.two-semi-categories.FunextFunctors public
open import lib.two-semi-categories.GroupToCategory public
| {
"alphanum_fraction": 0.8344671202,
"avg_line_length": 40.0909090909,
"ext": "agda",
"hexsha": "f3f1407b7f14468f1f0b313fa6147f1210b3b299",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "AntoineAllioux/HoTT-Agda",
"max_forks_repo_path": "core/lib/two-semi-categories/TwoSemiCategories.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "AntoineAllioux/HoTT-Agda",
"max_issues_repo_path": "core/lib/two-semi-categories/TwoSemiCategories.agda",
"max_line_length": 62,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "AntoineAllioux/HoTT-Agda",
"max_stars_repo_path": "core/lib/two-semi-categories/TwoSemiCategories.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z",
"num_tokens": 98,
"size": 441
} |
open import Function using (_∘_)
open import Category.Monad using (module RawMonad)
open import Data.Fin using (Fin; suc; zero)
open import Data.Fin.Properties renaming (_≟_ to _≟-Fin_)
open import Data.List as List using (List; _∷_; [])
open import Data.List.Properties renaming (∷-injective to ∷-inj)
open import Data.Maybe as Maybe using (Maybe; just; nothing)
open import Data.Nat using (ℕ; suc; zero)
open import Data.Product as Prod using (∃; _×_; _,_; proj₁; proj₂)
open import Relation.Nullary using (Dec; yes; no)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong; cong₂)
module Unification
(Name : Set) (_≟-Name_ : (x y : Name) → Dec (x ≡ y))
(Literal : Set) (_≟-Literal_ : (x y : Literal) → Dec (x ≡ y))
where
open RawMonad {{...}} using (_<$>_; _>>=_; return)
private
instance
MaybeMonad = Maybe.monad
data Term (n : ℕ) : Set where
var : (x : Fin n) → Term n
con : (s : Name) (ts : List (Term n)) → Term n
lit : (l : Literal) → Term n
-- ext : (x : Fin (suc n)) (t : Term (suc n)) → Term n
var-inj : ∀ {n x₁ x₂} → var {n} x₁ ≡ var {n} x₂ → x₁ ≡ x₂
var-inj refl = refl
con-inj : ∀ {n s₁ s₂ ts₁ ts₂} → con {n} s₁ ts₁ ≡ con {n} s₂ ts₂ → s₁ ≡ s₂ × ts₁ ≡ ts₂
con-inj refl = (refl , refl)
lit-inj : ∀ {n x₁ x₂} → lit {n} x₁ ≡ lit {n} x₂ → x₁ ≡ x₂
lit-inj refl = refl
mutual
_≟-Term_ : ∀ {n} → (t₁ t₂ : Term n) → Dec (t₁ ≡ t₂)
_≟-Term_ (var _) (lit _) = no (λ ())
_≟-Term_ (var _) (con _ _) = no (λ ())
_≟-Term_ (var x₁) (var x₂) with x₁ ≟-Fin x₂
... | yes x₁=x₂ = yes (cong var x₁=x₂)
... | no x₁≠x₂ = no (x₁≠x₂ ∘ var-inj)
_≟-Term_ (con _ _) (var _) = no (λ ())
_≟-Term_ (con _ _) (lit _) = no (λ ())
_≟-Term_ (con s₁ ts₁) (con s₂ ts₂) with s₁ ≟-Name s₂
... | no s₁≠s₂ = no (s₁≠s₂ ∘ proj₁ ∘ con-inj)
... | yes s₁=s₂ rewrite s₁=s₂ with ts₁ ≟-Terms ts₂
... | no ts₁≠ts₂ = no (ts₁≠ts₂ ∘ proj₂ ∘ con-inj)
... | yes ts₁=ts₂ = yes (cong (con s₂) ts₁=ts₂)
_≟-Term_ (lit _) (var _) = no (λ ())
_≟-Term_ (lit _) (con _ _) = no (λ ())
_≟-Term_ (lit x₁) (lit x₂) with x₁ ≟-Literal x₂
... | yes x₁=x₂ = yes (cong lit x₁=x₂)
... | no x₁≠x₂ = no (x₁≠x₂ ∘ lit-inj)
_≟-Terms_ : ∀ {n} (xs ys : List (Term n)) → Dec (xs ≡ ys)
_≟-Terms_ [] [] = yes refl
_≟-Terms_ [] (_ ∷ _) = no (λ ())
_≟-Terms_ (_ ∷ _) [] = no (λ ())
_≟-Terms_ (x ∷ xs) (y ∷ ys) with x ≟-Term y
... | no x≠y = no (x≠y ∘ proj₁ ∘ ∷-inj)
... | yes x=y with xs ≟-Terms ys
... | no xs≠ys = no (xs≠ys ∘ proj₂ ∘ ∷-inj)
... | yes xs=ys = yes (cong₂ _∷_ x=y xs=ys)
-- defining thick and thin
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 ()) _
thick {suc n} (suc x) zero = just zero
thick {suc n} (suc x) (suc y) = suc <$> thick x y
-- defining replacement function (written _◂ in McBride, 2003)
replace : ∀ {n m} → (Fin n → Term m) → Term n → Term m
replace _ (lit l) = lit l
replace f (var i) = f i
replace f (con s ts) = con s (replaceChildren f ts)
where
replaceChildren : ∀ {n m} → (Fin n → Term m) → (List (Term n) → List (Term m))
replaceChildren f [] = []
replaceChildren f (x ∷ xs) = replace f x ∷ (replaceChildren f xs)
-- defining replacement composition
_◇_ : ∀ {m n l} (f : Fin m → Term n) (g : Fin l → Term m) → Fin l → Term n
_◇_ f g = replace f ∘ g
-- defining an occurs check (**check** in McBride, 2003)
check : ∀ {n} (x : Fin (suc n)) (t : Term (suc n)) → Maybe (Term n)
check _ (lit l) = just (lit l)
check x₁ (var x₂) = var <$> thick x₁ x₂
check x₁ (con s ts) = con s <$> checkChildren x₁ ts
where
checkChildren : ∀ {n} (x : Fin (suc n)) (ts : List (Term (suc n))) → Maybe (List (Term n))
checkChildren x₁ [] = just []
checkChildren x₁ (t ∷ ts) = check x₁ t >>= λ t' →
checkChildren x₁ ts >>= λ ts' → return (t' ∷ ts')
-- datatype for substitutions (AList in McBride, 2003)
data Subst : ℕ → ℕ → Set where
nil : ∀ {n} → Subst n n
snoc : ∀ {m n} → (s : Subst m n) → (t : Term m) → (x : Fin (suc m)) → Subst (suc m) n
-- substitutes t for x (**for** in McBride, 2003)
_for_ : ∀ {n} (t : Term n) (x : Fin (suc n)) → Fin (suc n) → Term n
_for_ t x y with thick x y
_for_ t x y | just y' = var y'
_for_ t x y | nothing = t
-- substitution application (**sub** in McBride, 2003)
sub : ∀ {m n} → Subst m n → Fin m → Term n
sub nil = var
sub (snoc s t x) = (sub s) ◇ (t for x)
-- composes two substitutions
_++_ : ∀ {l m n} → Subst m n → Subst l m → Subst l n
s₁ ++ nil = s₁
s₁ ++ (snoc s₂ t x) = snoc (s₁ ++ s₂) t x
flexRigid : ∀ {n} → Fin n → Term n → Maybe (∃ (Subst n))
flexRigid {zero} () t
flexRigid {suc n} x t with check x t
flexRigid {suc n} x t | nothing = nothing
flexRigid {suc n} x t | just t' = just (n , snoc nil t' x)
flexFlex : ∀ {n} → (x y : Fin n) → ∃ (Subst n)
flexFlex {zero} () j
flexFlex {suc n} x y with thick x y
flexFlex {suc n} x y | nothing = (suc n , nil)
flexFlex {suc n} x y | just z = (n , snoc nil (var z) x)
mutual
unifyAcc : ∀ {m} → (t₁ t₂ : Term m) → ∃ (Subst m) → Maybe (∃ (Subst m))
unifyAcc (lit x₁) (lit x₂) (n , nil) with x₁ ≟-Literal x₂
... | yes x₁=x₂ rewrite x₁=x₂ = just (n , nil)
... | no x₁≠x₂ = nothing
unifyAcc (con s ts) (lit x) (n , nil) = nothing
unifyAcc (lit x) (con s ts) (n , nil) = nothing
unifyAcc (con s₁ ts₁) (con s₂ ts₂) acc with s₁ ≟-Name s₂
... | yes s₁=s₂ rewrite s₁=s₂ = unifyAccChildren ts₁ ts₂ acc
... | no s₁≠s₂ = nothing
unifyAcc (var x₁) (var x₂) (n , nil) = just (flexFlex x₁ x₂)
unifyAcc t (var x) (n , nil) = flexRigid x t
unifyAcc (var x) t (n , nil) = flexRigid x t
unifyAcc t₁ t₂ (n , snoc s t′ x) =
( λ s → proj₁ s , snoc (proj₂ s) t′ x )
<$> unifyAcc (replace (t′ for x) t₁) (replace (t′ for x) t₂) (n , s)
unifyAccChildren : ∀ {n} → (ts₁ ts₂ : List (Term n)) → ∃ (Subst n) → Maybe (∃ (Subst n))
unifyAccChildren [] [] acc = just acc
unifyAccChildren [] _ _ = nothing
unifyAccChildren _ [] _ = nothing
unifyAccChildren (t₁ ∷ ts₁) (t₂ ∷ ts₂) acc = unifyAcc t₁ t₂ acc >>= unifyAccChildren ts₁ ts₂
unify : ∀ {m} → (t₁ t₂ : Term m) → Maybe (∃ (Subst m))
unify {m} t₁ t₂ = unifyAcc t₁ t₂ (m , nil)
| {
"alphanum_fraction": 0.5212068212,
"avg_line_length": 41.3313253012,
"ext": "agda",
"hexsha": "0487c1383326e10304ab8051155937a05aff8d94",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2019-07-07T07:37:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-07-10T10:47:30.000Z",
"max_forks_repo_head_hexsha": "f384b5c236645fcf8ab93179723a7355383a8716",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "wenkokke/AutoInAgda",
"max_forks_repo_path": "src/Unification.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "f384b5c236645fcf8ab93179723a7355383a8716",
"max_issues_repo_issues_event_max_datetime": "2017-11-06T16:49:27.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-11-03T09:46:19.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "wenkokke/AutoInAgda",
"max_issues_repo_path": "src/Unification.agda",
"max_line_length": 96,
"max_stars_count": 22,
"max_stars_repo_head_hexsha": "f384b5c236645fcf8ab93179723a7355383a8716",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "wenkokke/AutoInAgda",
"max_stars_repo_path": "src/Unification.agda",
"max_stars_repo_stars_event_max_datetime": "2021-03-20T15:04:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-07-18T18:14:09.000Z",
"num_tokens": 2715,
"size": 6861
} |
module Oscar.Data.Term.internal.SubstituteAndSubstitution1 {𝔣} (FunctionName : Set 𝔣) where
open import Oscar.Data.Equality
open import Oscar.Data.Equality.properties
open import Oscar.Data.Fin
open import Oscar.Data.Nat
open import Oscar.Data.Term FunctionName
open import Oscar.Data.Vec
open import Oscar.Function
infix 19 _◃_ _◃s_
mutual
_◃_ : ∀ {m n} → (f : m ⊸ n) → Term m → Term n
σ̇ ◃ i 𝑥 = σ̇ 𝑥
_ ◃ leaf = leaf
σ̇ ◃ (τl fork τr) = (σ̇ ◃ τl) fork (σ̇ ◃ τr)
σ̇ ◃ (function fn τs) = function fn (σ̇ ◃s τs) where
_◃s_ : ∀ {m n} → m ⊸ n → ∀ {N} → Vec (Term m) N → Vec (Term n) N
f ◃s [] = []
f ◃s (t ∷ ts) = f ◃ t ∷ f ◃s ts
_◇_ : ∀ {m n} → m ⊸ n → ∀ {l} → l ⊸ m → l ⊸ n
_◇_ f g = (f ◃_) ∘ g
mutual
◃-extensionality : ∀ {m n} {f g : m ⊸ n} → f ≡̇ g → f ◃_ ≡̇ g ◃_
◃-extensionality p (i x) = p x
◃-extensionality p leaf = refl
◃-extensionality p (s fork t) = cong₂ _fork_ (◃-extensionality p s) (◃-extensionality p t)
◃-extensionality p (function fn ts) = cong (function fn) (◃s-extensionality p ts)
◃s-extensionality : ∀ {m n} {f g : m ⊸ n} → f ≡̇ g → ∀ {N} → _◃s_ f {N} ≡̇ _◃s_ g
◃s-extensionality p [] = refl
◃s-extensionality p (t ∷ ts) = cong₂ _∷_ (◃-extensionality p t) (◃s-extensionality p ts)
mutual
◃-associativity : ∀ {l m} (f : l ⊸ m) {n} (g : m ⊸ n) → (g ◇ f) ◃_ ≡̇ (g ◃_) ∘ (f ◃_)
◃-associativity _ _ (i _) = refl
◃-associativity _ _ leaf = refl
◃-associativity _ _ (τ₁ fork τ₂) = cong₂ _fork_ (◃-associativity _ _ τ₁) (◃-associativity _ _ τ₂)
◃-associativity f g (function fn ts) = cong (function fn) (◃s-associativity f g ts)
◃s-associativity : ∀ {l m n} (f : l ⊸ m) (g : m ⊸ n) → ∀ {N} → (_◃s_ (g ◇ f) {N}) ≡̇ (g ◃s_) ∘ (f ◃s_)
◃s-associativity _ _ [] = refl
◃s-associativity _ _ (τ ∷ τs) = cong₂ _∷_ (◃-associativity _ _ τ) (◃s-associativity _ _ τs)
◇-associativity : ∀ {k l} (f : k ⊸ l) {m} (g : l ⊸ m) {n} (h : m ⊸ n) → (h ◇ g) ◇ f ≡̇ h ◇ (g ◇ f)
◇-associativity f g h x rewrite ◃-associativity g h (f x) = refl
◇-extensionality : ∀ {l m} {f₁ f₂ : l ⊸ m} → f₁ ≡̇ f₂ → ∀ {n} {g₁ g₂ : m ⊸ n} → g₁ ≡̇ g₂ → g₁ ◇ f₁ ≡̇ g₂ ◇ f₂
◇-extensionality {f₂ = f₂} f₁≡̇f₂ g₁≡̇g₂ x rewrite f₁≡̇f₂ x = ◃-extensionality g₁≡̇g₂ (f₂ x)
open import Oscar.Category.Semigroupoid
SemigroupoidSubstitution : Semigroupoid _ _ _
Semigroupoid.⋆ SemigroupoidSubstitution = _
Semigroupoid._⇒_ SemigroupoidSubstitution m n = Fin m ⇒ Term n
Semigroupoid._∙_ SemigroupoidSubstitution = _◇_
Semigroupoid.associativity SemigroupoidSubstitution = ◇-associativity
Semigroupoid.extensionality SemigroupoidSubstitution = ◇-extensionality
open import Oscar.Category.Semifunctor
SemifunctorSubstitution : Semifunctor _ _ _ _ _ _
Semifunctor.semigroupoid₁ SemifunctorSubstitution = SemigroupoidSubstitution
Semifunctor.semigroupoid₂ SemifunctorSubstitution = SemigroupoidFunction Term
Semifunctor.μ SemifunctorSubstitution = id
Semifunctor.𝔣 SemifunctorSubstitution = _◃_
Semifunctor.extensionality SemifunctorSubstitution = ◃-extensionality
Semifunctor.preservativity SemifunctorSubstitution = ◃-associativity
ε : ∀ {m} → m ⊸ m
ε = i
mutual
◃-identity : ∀ {m} (t : Term m) → ε ◃ t ≡ t
◃-identity (i x) = refl
◃-identity leaf = refl
◃-identity (s fork t) = cong₂ _fork_ (◃-identity s) (◃-identity t)
◃-identity (function fn ts) = cong (function fn) (◃s-identity ts)
◃s-identity : ∀ {N m} (t : Vec (Term m) N) → ε ◃s t ≡ t
◃s-identity [] = refl
◃s-identity (t ∷ ts) = cong₂ _∷_ (◃-identity t) (◃s-identity ts)
◇-left-identity : ∀ {m n} (f : m ⊸ n) → ε ◇ f ≡̇ f
◇-left-identity f = ◃-identity ∘ f
◇-right-identity : ∀ {m n} (f : m ⊸ n) → f ◇ ε ≡̇ f
◇-right-identity _ _ = refl
open import Oscar.Category.Category
CategorySubstitution : Category _ _ _
Category.semigroupoid CategorySubstitution = SemigroupoidSubstitution
Category.ε CategorySubstitution = ε
Category.left-identity CategorySubstitution = {!!}
Category.right-identity CategorySubstitution {x} {y} {f} x₁ = ◇-right-identity f x₁
test-right-id = {!Category.right-identity CategorySubstitution!}
-- open import Oscar.Property.Associativity
-- open import Oscar.Property.Equivalence
-- open import Oscar.Property.Extensionality₂
-- instance
-- AssociativitySubstitutionComposition : Associativity _◇_ _≡̇_
-- Associativity.associativity AssociativitySubstitutionComposition = ◇-associativity
-- ExtensionalityS◇ : ExtensionalitySemigroupoid _◇_ _≡̇_
-- ExtensionalitySemigroupoid.extensionalitySemigroupoid ExtensionalityS◇ g₁≡̇g₂ {_} {_} {f₂} f₁≡̇f₂ x rewrite f₁≡̇f₂ x = ◃-extensionality g₁≡̇g₂ (f₂ x)
-- -- instance
-- -- Extensionality₂≡̇◇⋆ : ∀ {x y z} → Extensionality₂⋆ _≡̇_ _≡̇_ (λ ‵ → _≡̇_ ‵) ((y ⊸ z → x ⊸ y → x ⊸ z) ∋ λ ` → _◇_ `) (λ ` → _◇_ `)
-- -- Extensionality₂⋆.extensionality* Extensionality₂≡̇◇⋆ g₁≡̇g₂ {_} {f₂} f₁≡̇f₂ x rewrite f₁≡̇f₂ x = ◃-extensionality g₁≡̇g₂ (f₂ x)
-- -- -- Extensionality₂≡̇◇ : ∀ {x y z} → Extensionality₂ _≡̇_ _≡̇_ (λ ‵ → _≡̇_ ‵) (λ {yz} → _◇_ {y} {z} yz {x}) (λ {_} {yz} → yz ◇_)
-- -- -- Extensionality₂.extensionality₂ Extensionality₂≡̇◇ {g₁} {g₂} g₁≡̇g₂ {f₁} {f₂} f₁≡̇f₂ x rewrite f₁≡̇f₂ x = ◃-extensionality g₁≡̇g₂ (f₂ x)
-- instance
-- SemigroupoidSubstitution : Semigroupoid _ _ _
-- Semigroupoid.⋆ SemigroupoidSubstitution = _
-- Semigroupoid._⇒_ SemigroupoidSubstitution = _⊸_
-- Semigroupoid._≋_ SemigroupoidSubstitution = _≡̇_
-- Semigroupoid._∙_ SemigroupoidSubstitution = _◇_
-- instance
-- Associativity-∘ : ∀ {𝔬} {⋆ : Set 𝔬} {f} {F : ⋆ → Set f} →
-- Associativity (λ {y} {z} g {x} f₁ x₁ → g (f₁ x₁))
-- (λ {x} {y} f₁ g → (x₁ : F x) → f₁ x₁ ≡ g x₁)
-- Associativity.associativity Associativity-∘ _ _ _ _ = refl
-- ExtensionalityS∘ : ∀ {𝔬} {⋆ : Set 𝔬} {f} {F : ⋆ → Set f} → ExtensionalitySemigroupoid (λ g f → {!(λ {_} → g) ∘ f!}) (_≡̇_ {B = F})
-- ExtensionalityS∘ = {!!}
-- -- Extensionality₂-≡̇ : ∀ {𝔬} {⋆ : Set 𝔬} {f} {F : ⋆ → Set f} {x y z : ⋆} →
-- -- Extensionality₂ {_} {F _ → _} {_} {λ _ → F _ → _}
-- -- (λ f₁ g → (x₁ : F y) → _≡_ (f₁ x₁) (g x₁)) {_}
-- -- {λ {w} _ → F _ → _} {_} {λ {w} {x₁} _ → F x → F y} {f}
-- -- (λ {w} {x₁} f₁ g → (x₂ : F x) → _≡_ {f} {F y} (f₁ x₂) (g x₂)) {f}
-- -- {λ {w} {y₁} _ → F x → F z} {f} {λ {w} {x₁} {y₁} _ → F x → F z} {f}
-- -- (λ {w} {x₁} {y₁} ′ {z₁} g →
-- -- (x₂ : F x) → _≡_ (′ x₂) (g x₂))
-- -- (λ {yz} f₁ x₂ → yz (f₁ x₂))
-- -- (λ {_} {yz} f₁ x₁ → yz (f₁ x₁))
-- -- Extensionality₂.extensionality₂ Extensionality₂-≡̇ w≡̇x y≡̇z f rewrite y≡̇z f = w≡̇x _
-- SemigroupoidIndexedFunction : ∀ {𝔬} {⋆ : Set 𝔬} {f} (F : ⋆ → Set f) → Semigroupoid _ _ _
-- Semigroupoid.⋆ (SemigroupoidIndexedFunction F) = _
-- Semigroupoid._⇒_ (SemigroupoidIndexedFunction F) m n = F m → F n
-- Semigroupoid._≋_ (SemigroupoidIndexedFunction F) = _≡̇_
-- Semigroupoid._∙_ (SemigroupoidIndexedFunction F) g f = g ∘ f
-- Semigroupoid.′associativity (SemigroupoidIndexedFunction F) = it
-- Semigroupoid.′extensionality₂ (SemigroupoidIndexedFunction F) = {!!} -- Extensionality₂-≡̇ {F = F}
-- open import Oscar.Property.Extensionality
-- instance
-- ex : ∀ {x y} →
-- Extensionality (λ f g →
-- (x₁ : Fin x) →
-- _≡_ (f x₁) (g x₁))
-- (λ {x₁} ‵ {y₁} g →
-- (x₂ : Term x) →
-- _≡_ {𝔣} {Term y} (‵ x₂) (g x₂))
-- _◃_ _◃_
-- Extensionality.extensionality ex = ◃-extensionality
-- open import Oscar.Property.Preservativity
-- instance
-- pres : ∀ {x y z} →
-- Preservativity {𝔣}
-- {Fin y → Term z} {𝔣}
-- {λ _ → Fin x → Term y} {𝔣}
-- {λ x₁ _ → Fin x → Term z}
-- (λ ‵ g x₁ → _◃_ {y} {z} ‵ (g x₁)) {𝔣}
-- {Term y →
-- Term z}
-- {𝔣}
-- {λ _ →
-- Term x →
-- Term y}
-- {𝔣}
-- {λ x₁ _ →
-- Term x →
-- Term z}
-- (λ ‵ f x₁ → ‵ (f x₁)) {𝔣}
-- (λ {x₁} {y₁} f g →
-- (x₂ : Term x) →
-- _≡_ {𝔣} {Term z} (f x₂) (g x₂))
-- (_◃_ {y} {z}) (λ {x₁} → _◃_ {x} {y}) (λ {x₁} {y₁} → _◃_ {x} {z})
-- Preservativity.preservativity pres ρ₂ ρ₁ t = ◃-associativity' t ρ₁ ρ₂
-- semifunctor : Semifunctor _ _ _ _ _ _
-- Semifunctor.semigroupoid₁ semifunctor = SemigroupoidSubstitution
-- Semifunctor.semigroupoid₂ semifunctor = SemigroupoidIndexedFunction Term
-- Semifunctor.μ semifunctor = id
-- Semifunctor.𝔣 semifunctor = _◃_
| {
"alphanum_fraction": 0.581384361,
"avg_line_length": 39.5607476636,
"ext": "agda",
"hexsha": "5e420a29792ec0331859067a10e9a087f5ff6055",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-2/Oscar/Data/Term/internal/SubstituteAndSubstitution1.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-2/Oscar/Data/Term/internal/SubstituteAndSubstitution1.agda",
"max_line_length": 154,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-2/Oscar/Data/Term/internal/SubstituteAndSubstitution1.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3610,
"size": 8466
} |
------------------------------------------------------------------------
-- A parser for PBM images; illustrates essential use of bind
------------------------------------------------------------------------
-- Note that I am using the simple "Plain PBM" format, and I try to
-- adhere to the following statement from the pbm man page:
--
-- "Programs that read this format should be as lenient as possible,
-- accepting anything that looks remotely like a bitmap."
-- The idea to write this particular parser was taken from "The Power
-- of Pi" by Oury and Swierstra.
module RecursiveDescent.Hybrid.PBM where
import Data.Vec as Vec
open Vec using (Vec; _++_; [_])
import Data.List as List
open import Data.Nat
import Data.String as String
open String using (String) renaming (_++_ to _<+>_)
import Data.Char as Char
open Char using (Char; _==_)
open import Data.Product.Record
open import Data.Function
open import Data.Bool
open import Data.Unit
open import Data.Maybe
import Data.Nat.Show as N
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
open import RecursiveDescent.Index
open import RecursiveDescent.Hybrid
open import RecursiveDescent.Hybrid.Lib
open Token Char.decSetoid
open import RecursiveDescent.Hybrid.Simple
------------------------------------------------------------------------
-- The PBM type
data Colour : Set where
white : Colour
black : Colour
Matrix : Set -> ℕ -> ℕ -> Set
Matrix a rows cols = Vec (Vec a cols) rows
record PBM : Set where
field
rows : ℕ
cols : ℕ
matrix : Matrix Colour rows cols
open PBM
makePBM : forall {rows cols} -> Matrix Colour rows cols -> PBM
makePBM m = record { rows = _; cols = _; matrix = m }
------------------------------------------------------------------------
-- Showing PBM images
showColour : Colour -> Char
showColour white = '0'
showColour black = '1'
show : PBM -> String
show i = "P1 # Generated using Agda.\n" <+>
N.show (cols i) <+> " " <+> N.show (rows i) <+> "\n" <+>
showMatrix (matrix i)
where
showMatrix = String.fromList ∘
Vec.toList ∘
Vec.concat ∘
Vec.map ((\xs -> xs ++ [ '\n' ]) ∘ Vec.map showColour)
------------------------------------------------------------------------
-- Parsing PBM images
data NT : ParserType where
comment : NT _ ⊤
colour : NT _ Colour
pbm : NT _ PBM
grammar : Grammar Char NT
grammar comment = tt <$ sym '#' <⊛ sat' (not ∘ _==_ '\n') ⋆ <⊛ sym '\n'
grammar colour = white <$ sym '0'
∣ black <$ sym '1'
grammar pbm =
w∣c ⋆ ⊛>
string (String.toVec "P1") ⊛>
w∣c ⋆ ⊛>
number !>>= \cols -> -- _>>=_ works just as well.
w∣c + ⊛>
number >>= \rows -> -- _!>>=_ works just as well.
w∣c ⊛>
(makePBM <$> exactly rows (exactly cols (w∣c ⋆ ⊛> ! colour))) <⊛
any ⋆
where w∣c = whitespace ∣ ! comment
module Example where
open Vec
image = makePBM ((white ∷ black ∷ []) ∷
(black ∷ white ∷ []) ∷
(black ∷ black ∷ []) ∷ [])
ex₁ : parse-complete (! pbm) grammar (String.toList (show image)) ≡
List.[_] image
ex₁ = refl
| {
"alphanum_fraction": 0.5597860289,
"avg_line_length": 28.375,
"ext": "agda",
"hexsha": "ab28cba32d5effaf85242e1cb219eeb12ff3abc6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "misc/RecursiveDescent/Hybrid/PBM.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_issues_repo_issues_event_max_datetime": "2018-01-24T16:39:37.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-01-22T22:21:41.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/parser-combinators",
"max_issues_repo_path": "misc/RecursiveDescent/Hybrid/PBM.agda",
"max_line_length": 72,
"max_stars_count": 7,
"max_stars_repo_head_hexsha": "b396d35cc2cb7e8aea50b982429ee385f001aa88",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yurrriq/parser-combinators",
"max_stars_repo_path": "misc/RecursiveDescent/Hybrid/PBM.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-22T05:35:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-12-13T05:23:14.000Z",
"num_tokens": 854,
"size": 3178
} |
{-# OPTIONS --no-qualified-instances #-}
module CF.Compile where
open import Data.Product
open import Data.List hiding (null; [_])
open import Relation.Binary.PropositionalEquality hiding ([_])
open import Relation.Unary
open import Relation.Unary.PredicateTransformer using (Pt)
open import Relation.Ternary.Core
open import Relation.Ternary.Structures
open import Relation.Ternary.Structures.Syntax
open import Relation.Ternary.Monad.Possibly
open import Relation.Ternary.Monad.Weakening
open import Relation.Ternary.Data.ReflexiveTransitive
open import CF.Syntax as Src
open import CF.Contexts.Lexical
open import CF.Transform.Hoist
open import CF.Transform.UnCo
open import CF.Transform.Compile.Expressions
open import CF.Transform.Compile.Statements
open import CF.Transform.Compile.ToJVM
open import JVM.Builtins
open import JVM.Types
open import JVM.Contexts
open import JVM.Syntax.Values
open import JVM.Syntax.Instructions
open import JVM.Transform.Noooops
open import JVM.Compiler
module _ {T : Set} where
open import JVM.Model T public
compile : ∀ {r} → Src.Block r [] → ∃ λ Γ → ε[ ⟪ Γ ∣ [] ↝ [] ⟫ ]
compile bl₁ with hoist bl₁
... | _ , Possibly.possibly (intros r refl) bl₂ -- The grading of the possibility modality
-- proves that only the lexical context has been extended
with unco bl₂
... | bl₃ with execCompiler (compiler [] bl₃)
... | bl₄ with noooop bl₄
... | bl₅ = -, bl₅
| {
"alphanum_fraction": 0.7334682861,
"avg_line_length": 33.6818181818,
"ext": "agda",
"hexsha": "84b1810014ea9047b643e842fa9c65f6aa6525f9",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:37:15.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:37:15.000Z",
"max_forks_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "ajrouvoet/jvm.agda",
"max_forks_repo_path": "src/CF/Compile.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"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": "ajrouvoet/jvm.agda",
"max_issues_repo_path": "src/CF/Compile.agda",
"max_line_length": 106,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "ajrouvoet/jvm.agda",
"max_stars_repo_path": "src/CF/Compile.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-28T21:49:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T14:07:17.000Z",
"num_tokens": 359,
"size": 1482
} |
open import Agda.Primitive
open import Agda.Builtin.Sigma
open import Agda.Builtin.Equality
record R {A : Set} {B : A → Set} (p) : Set where
field
prf : p ≡ p
| {
"alphanum_fraction": 0.6807228916,
"avg_line_length": 20.75,
"ext": "agda",
"hexsha": "f5f46b2eb2291449b5af1390931a230fe422575d",
"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": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "shlevy/agda",
"max_forks_repo_path": "test/Fail/NoLetInRecordTele2.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/NoLetInRecordTele2.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/Fail/NoLetInRecordTele2.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": 166
} |
{-# OPTIONS --without-K #-}
module level where
open import Agda.Primitive public
using (Level; _⊔_; lzero; lsuc)
record ↑ {a} ℓ (A : Set a) : Set (a ⊔ ℓ) where
constructor lift
field lower : A
open ↑ public
| {
"alphanum_fraction": 0.6392694064,
"avg_line_length": 18.25,
"ext": "agda",
"hexsha": "a318727f1e7fe3f2cc95bf14ba90cb3046088751",
"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": "level.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/level.agda",
"max_line_length": 46,
"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": "level.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": 73,
"size": 219
} |
{-
Type quotients:
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.TypeQuotients.Properties where
open import Cubical.HITs.TypeQuotients.Base
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.HITs.PropositionalTruncation as PropTrunc using (∥_∥ ; ∣_∣ ; squash)
open import Cubical.HITs.SetTruncation as SetTrunc using (∥_∥₂ ; ∣_∣₂ ; squash₂
; setTruncIsSet)
private
variable
ℓ ℓ' ℓ'' : Level
A : Type ℓ
R : A → A → Type ℓ'
B : A /ₜ R → Type ℓ''
C : A /ₜ R → A /ₜ R → Type ℓ''
elim : (f : (a : A) → (B [ a ]))
→ ((a b : A) (r : R a b) → PathP (λ i → B (eq/ a b r i)) (f a) (f b))
------------------------------------------------------------------------
→ (x : A /ₜ R) → B x
elim f feq [ a ] = f a
elim f feq (eq/ a b r i) = feq a b r i
rec : {X : Type ℓ''}
→ (f : A → X)
→ (∀ (a b : A) → R a b → f a ≡ f b)
-------------------------------------
→ A /ₜ R → X
rec f feq [ a ] = f a
rec f feq (eq/ a b r i) = feq a b r i
elimProp : ((x : A /ₜ R ) → isProp (B x))
→ ((a : A) → B ( [ a ]))
---------------------------------
→ (x : A /ₜ R) → B x
elimProp Bprop f [ a ] = f a
elimProp Bprop f (eq/ a b r i) = isOfHLevel→isOfHLevelDep 1 Bprop (f a) (f b) (eq/ a b r) i
elimProp2 : ((x y : A /ₜ R ) → isProp (C x y))
→ ((a b : A) → C [ a ] [ b ])
--------------------------------------
→ (x y : A /ₜ R) → C x y
elimProp2 Cprop f = elimProp (λ x → isPropΠ (λ y → Cprop x y))
(λ x → elimProp (λ y → Cprop [ x ] y) (f x))
| {
"alphanum_fraction": 0.4681769148,
"avg_line_length": 30.393442623,
"ext": "agda",
"hexsha": "c5c2f015237a55ed44ef244f3f7567f21d91fc0f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Edlyr/cubical",
"max_forks_repo_path": "Cubical/HITs/TypeQuotients/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Edlyr/cubical",
"max_issues_repo_path": "Cubical/HITs/TypeQuotients/Properties.agda",
"max_line_length": 91,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Edlyr/cubical",
"max_stars_repo_path": "Cubical/HITs/TypeQuotients/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 651,
"size": 1854
} |
module OldBasicILP.UntypedSyntax.Translation where
open import OldBasicILP.UntypedSyntax.Common public
import OldBasicILP.UntypedSyntax.ClosedHilbertSequential as CHS
import OldBasicILP.UntypedSyntax.ClosedHilbert as CH
-- Translation of types parametrised by a closed, untyped representation of syntax.
_↦ᵀ_ : ∀ {Rep Rep′} → (Rep → Rep′) → ClosedSyntax.Ty Rep → ClosedSyntax.Ty Rep′
f ↦ᵀ (ClosedSyntax.α P) = ClosedSyntax.α P
f ↦ᵀ (A ClosedSyntax.▻ B) = f ↦ᵀ A ClosedSyntax.▻ f ↦ᵀ B
f ↦ᵀ (p ClosedSyntax.⦂ A) = f p ClosedSyntax.⦂ f ↦ᵀ A
f ↦ᵀ (A ClosedSyntax.∧ B) = f ↦ᵀ A ClosedSyntax.∧ f ↦ᵀ B
f ↦ᵀ ClosedSyntax.⊤ = ClosedSyntax.⊤
-- Translation from closed Hilbert-style sequential to closed Hilbert-style.
chsᴿ→chᴿ : ∀ {n} → CHS.Rep n → Fin n → CH.Rep
chsᴿ→chᴿ (CHS.MP i j r) zero = CH.APP (chsᴿ→chᴿ r i) (chsᴿ→chᴿ r j)
chsᴿ→chᴿ (CHS.CI r) zero = CH.CI
chsᴿ→chᴿ (CHS.CK r) zero = CH.CK
chsᴿ→chᴿ (CHS.CS r) zero = CH.CS
chsᴿ→chᴿ (CHS.NEC `r r) zero = CH.BOX (chsᴿ→chᴿ `r zero)
chsᴿ→chᴿ (CHS.CDIST r) zero = CH.CDIST
chsᴿ→chᴿ (CHS.CUP r) zero = CH.CUP
chsᴿ→chᴿ (CHS.CDOWN r) zero = CH.CDOWN
chsᴿ→chᴿ (CHS.CPAIR r) zero = CH.CPAIR
chsᴿ→chᴿ (CHS.CFST r) zero = CH.CFST
chsᴿ→chᴿ (CHS.CSND r) zero = CH.CSND
chsᴿ→chᴿ (CHS.UNIT r) zero = CH.UNIT
chsᴿ→chᴿ (CHS.MP i j r) (suc k) = chsᴿ→chᴿ r k
chsᴿ→chᴿ (CHS.CI r) (suc k) = chsᴿ→chᴿ r k
chsᴿ→chᴿ (CHS.CK r) (suc k) = chsᴿ→chᴿ r k
chsᴿ→chᴿ (CHS.CS r) (suc k) = chsᴿ→chᴿ r k
chsᴿ→chᴿ (CHS.NEC `r r) (suc k) = chsᴿ→chᴿ r k
chsᴿ→chᴿ (CHS.CDIST r) (suc k) = chsᴿ→chᴿ r k
chsᴿ→chᴿ (CHS.CUP r) (suc k) = chsᴿ→chᴿ r k
chsᴿ→chᴿ (CHS.CDOWN r) (suc k) = chsᴿ→chᴿ r k
chsᴿ→chᴿ (CHS.CPAIR r) (suc k) = chsᴿ→chᴿ r k
chsᴿ→chᴿ (CHS.CFST r) (suc k) = chsᴿ→chᴿ r k
chsᴿ→chᴿ (CHS.CSND r) (suc k) = chsᴿ→chᴿ r k
chsᴿ→chᴿ (CHS.UNIT r) (suc k) = chsᴿ→chᴿ r k
chsᴾ→chᴾ : CHS.Proof → CH.Proof
chsᴾ→chᴾ CHS.[ r ] = CH.[ chsᴿ→chᴿ r zero ]
chsᵀ→chᵀ : CHS.Ty → CH.Ty
chsᵀ→chᵀ = chsᴾ→chᴾ ↦ᵀ_
-- FIXME: What is going on here?
postulate
ᴬlem₁ : ∀ {n₁ n₂} → (r₁ : CHS.Rep (suc n₁)) → (r₂ : CHS.Rep (suc n₂))
→ chsᴿ→chᴿ (CHS.APP r₁ r₂) zero ≡ CH.APP (chsᴿ→chᴿ r₁ zero) (chsᴿ→chᴿ r₂ zero)
mutual
chsᴰ→ch : ∀ {Ξ A} → CHS.⊢ᴰ Ξ → A ∈ Ξ → CH.⊢ chsᵀ→chᵀ A
chsᴰ→ch (CHS.mp i j d) top = CH.app (chsᴰ→ch d i) (chsᴰ→ch d j)
chsᴰ→ch (CHS.ci d) top = CH.ci
chsᴰ→ch (CHS.ck d) top = CH.ck
chsᴰ→ch (CHS.cs d) top = CH.cs
chsᴰ→ch (CHS.nec `d d) top rewrite ᴬlem₂ `d top = CH.box (chsᴰ→ch `d top)
chsᴰ→ch (CHS.cdist {r₁ = r₁} {r₂} d) top rewrite ᴬlem₁ r₁ r₂ = CH.cdist
chsᴰ→ch (CHS.cup d) top = CH.cup
chsᴰ→ch (CHS.cdown d) top = CH.cdown
chsᴰ→ch (CHS.cpair d) top = CH.cpair
chsᴰ→ch (CHS.cfst d) top = CH.cfst
chsᴰ→ch (CHS.csnd d) top = CH.csnd
chsᴰ→ch (CHS.unit d) top = CH.unit
chsᴰ→ch (CHS.mp i j d) (pop k) = chsᴰ→ch d k
chsᴰ→ch (CHS.ci d) (pop k) = chsᴰ→ch d k
chsᴰ→ch (CHS.ck d) (pop k) = chsᴰ→ch d k
chsᴰ→ch (CHS.cs d) (pop k) = chsᴰ→ch d k
chsᴰ→ch (CHS.nec `d d) (pop k) = chsᴰ→ch d k
chsᴰ→ch (CHS.cdist d) (pop k) = chsᴰ→ch d k
chsᴰ→ch (CHS.cup d) (pop k) = chsᴰ→ch d k
chsᴰ→ch (CHS.cdown d) (pop k) = chsᴰ→ch d k
chsᴰ→ch (CHS.cpair d) (pop k) = chsᴰ→ch d k
chsᴰ→ch (CHS.cfst d) (pop k) = chsᴰ→ch d k
chsᴰ→ch (CHS.csnd d) (pop k) = chsᴰ→ch d k
chsᴰ→ch (CHS.unit d) (pop k) = chsᴰ→ch d k
ᴬlem₂ : ∀ {Ξ A} → (d : CHS.⊢ᴰ Ξ) → (k : A ∈ Ξ)
→ chsᴿ→chᴿ CHS.ᴿ⌊ d ⌋ ⁱ⌊ k ⌋ ≡ CH.ᴿ⌊ chsᴰ→ch d k ⌋
ᴬlem₂ CHS.nil ()
ᴬlem₂ (CHS.mp i j d) top = cong² CH.APP (ᴬlem₂ d i) (ᴬlem₂ d j)
ᴬlem₂ (CHS.ci d) top = refl
ᴬlem₂ (CHS.ck d) top = refl
ᴬlem₂ (CHS.cs d) top = refl
ᴬlem₂ (CHS.nec `d d) top rewrite ᴬlem₂ `d top = cong CH.BOX refl
ᴬlem₂ (CHS.cdist {r₁ = r₁} {r₂} d) top rewrite ᴬlem₁ r₁ r₂ = refl
ᴬlem₂ (CHS.cup d) top = refl
ᴬlem₂ (CHS.cdown d) top = refl
ᴬlem₂ (CHS.cpair d) top = refl
ᴬlem₂ (CHS.cfst d) top = refl
ᴬlem₂ (CHS.csnd d) top = refl
ᴬlem₂ (CHS.unit d) top = refl
ᴬlem₂ (CHS.mp i j d) (pop k) = ᴬlem₂ d k
ᴬlem₂ (CHS.ci d) (pop k) = ᴬlem₂ d k
ᴬlem₂ (CHS.ck d) (pop k) = ᴬlem₂ d k
ᴬlem₂ (CHS.cs d) (pop k) = ᴬlem₂ d k
ᴬlem₂ (CHS.nec `d d) (pop k) = ᴬlem₂ d k
ᴬlem₂ (CHS.cdist d) (pop k) = ᴬlem₂ d k
ᴬlem₂ (CHS.cup d) (pop k) = ᴬlem₂ d k
ᴬlem₂ (CHS.cdown d) (pop k) = ᴬlem₂ d k
ᴬlem₂ (CHS.cpair d) (pop k) = ᴬlem₂ d k
ᴬlem₂ (CHS.cfst d) (pop k) = ᴬlem₂ d k
ᴬlem₂ (CHS.csnd d) (pop k) = ᴬlem₂ d k
ᴬlem₂ (CHS.unit d) (pop k) = ᴬlem₂ d k
chs→ch : ∀ {A} → CHS.⊢ A → CH.⊢ chsᵀ→chᵀ A
chs→ch (Ξ , d) = chsᴰ→ch d top
-- Translation from closed Hilbert-style to closed Hilbert-style sequential.
chᴿ→chsᴿ : CH.Rep → ∃ (λ n → CHS.Rep (suc n))
chᴿ→chsᴿ (CH.APP r₁ r₂) with chᴿ→chsᴿ r₁ | chᴿ→chsᴿ r₂
chᴿ→chsᴿ (CH.APP r₁ r₂) | (n₁ , r₁′) | (n₂ , r₂′) = suc n₂ + suc n₁ , CHS.APP r₁′ r₂′
chᴿ→chsᴿ CH.CI = zero , CHS.CI CHS.NIL
chᴿ→chsᴿ CH.CK = zero , CHS.CK CHS.NIL
chᴿ→chsᴿ CH.CS = zero , CHS.CS CHS.NIL
chᴿ→chsᴿ (CH.BOX r) with chᴿ→chsᴿ r
chᴿ→chsᴿ (CH.BOX r) | (n , r′) = zero , CHS.BOX r′
chᴿ→chsᴿ CH.CDIST = zero , CHS.CDIST CHS.NIL
chᴿ→chsᴿ CH.CUP = zero , CHS.CUP CHS.NIL
chᴿ→chsᴿ CH.CDOWN = zero , CHS.CDOWN CHS.NIL
chᴿ→chsᴿ CH.CPAIR = zero , CHS.CPAIR CHS.NIL
chᴿ→chsᴿ CH.CFST = zero , CHS.CFST CHS.NIL
chᴿ→chsᴿ CH.CSND = zero , CHS.CSND CHS.NIL
chᴿ→chsᴿ CH.UNIT = zero , CHS.UNIT CHS.NIL
chᴾ→chsᴾ : CH.Proof → CHS.Proof
chᴾ→chsᴾ CH.[ r ] with chᴿ→chsᴿ r
chᴾ→chsᴾ CH.[ r ] | (n , r′) = CHS.[ r′ ]
chᵀ→chsᵀ : CH.Ty → CHS.Ty
chᵀ→chsᵀ = chᴾ→chsᴾ ↦ᵀ_
distᴺ⌊⌋+ : ∀ {U} → (Γ Γ′ : Cx U) → ᴺ⌊ Γ ⧺ Γ′ ⌋ ≡ ᴺ⌊ Γ ⌋ + ᴺ⌊ Γ′ ⌋
distᴺ⌊⌋+ Γ ∅ = refl
distᴺ⌊⌋+ Γ (Γ′ , A) = cong suc (distᴺ⌊⌋+ Γ Γ′)
mutual
ch→chs : ∀ {A} → CH.⊢ A → CHS.⊢ chᵀ→chsᵀ A
ch→chs (CH.app d₁ d₂) = CHS.app (ch→chs d₁) (ch→chs d₂)
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.box d) rewrite ᴮlem₁ d = CHS.box (ch→chs d)
ch→chs CH.cdist = ∅ , CHS.cdist CHS.nil
ch→chs CH.cup = ∅ , CHS.cup CHS.nil
ch→chs CH.cdown = ∅ , CHS.cdown 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
-- FIXME: This should hold by ᴮlem₂.
postulate
ᴮlem₁ : ∀ {A} → (d : CH.⊢ A)
→ chᴿ→chsᴿ CH.ᴿ⌊ d ⌋ ≡ ᴺ⌊ π₁ (ch→chs d) ⌋ , CHS.ᴿ⌊ π₂ (ch→chs d) ⌋
ᴮlem₂ : ∀ {A} → (d : CH.⊢ A)
→ ᴺ⌊ π₁ (ch→chs d) ⌋ ≡ π₁ (chᴿ→chsᴿ CH.ᴿ⌊ d ⌋)
ᴮlem₂ (CH.app d₁ d₂) rewrite ᴮlem₂ d₂ | ᴮlem₃ d₁ d₂ = cong suc refl
ᴮlem₂ CH.ci = refl
ᴮlem₂ CH.ck = refl
ᴮlem₂ CH.cs = refl
ᴮlem₂ (CH.box d) rewrite ᴮlem₂ d | ᴮlem₁ d = refl
ᴮlem₂ CH.cdist = refl
ᴮlem₂ CH.cup = refl
ᴮlem₂ CH.cdown = refl
ᴮlem₂ CH.cpair = refl
ᴮlem₂ CH.cfst = refl
ᴮlem₂ CH.csnd = refl
ᴮlem₂ CH.unit = refl
ᴮlem₃ : ∀ {A B} → (d₁ : CH.⊢ A CH.▻ B) → (d₂ : CH.⊢ A)
→ ᴺ⌊ (π₁ (ch→chs d₂) , chᵀ→chsᵀ A) ⧺ π₁ (ch→chs d₁) ⌋ ≡
suc (π₁ (chᴿ→chsᴿ CH.ᴿ⌊ d₂ ⌋)) + π₁ (chᴿ→chsᴿ CH.ᴿ⌊ d₁ ⌋)
ᴮlem₃ {A} d₁ d₂ rewrite distᴺ⌊⌋+ (π₁ (ch→chs d₂) , chᵀ→chsᵀ A) (π₁ (ch→chs d₁)) =
cong² _+_ (cong suc (ᴮlem₂ d₂)) (ᴮlem₂ d₁)
| {
"alphanum_fraction": 0.5148671704,
"avg_line_length": 44.1182795699,
"ext": "agda",
"hexsha": "a7c5d47dbef600cdb47c79de01906a440f59df5e",
"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": "OldBasicILP/UntypedSyntax/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": "OldBasicILP/UntypedSyntax/Translation.agda",
"max_line_length": 93,
"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": "OldBasicILP/UntypedSyntax/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": 4369,
"size": 8206
} |
open import Nat
open import Prelude
open import dynamics-core
open import contexts
open import typed-elaboration
open import lemmas-gcomplete
open import lemmas-complete
open import progress-checks
open import finality
module cast-inert where
-- if a term is compelete and well typed, then the casts inside are all
-- identity casts and there are no failed casts
cast-inert : ∀{Δ Γ d τ} →
d dcomplete →
Δ , Γ ⊢ d :: τ →
cast-id d
cast-inert dc TANum = CINum
cast-inert (DCPlus dc dc₁) (TAPlus wt wt₁) = CIPlus (cast-inert dc wt) (cast-inert dc₁ wt₁)
cast-inert dc (TAVar x₁) = CIVar
cast-inert (DCLam dc x₁) (TALam x₂ wt) = CILam (cast-inert dc wt)
cast-inert (DCAp dc dc₁) (TAAp wt wt₁) = CIAp (cast-inert dc wt) (cast-inert dc₁ wt₁)
cast-inert (DCInl x dc) (TAInl wt) = CIInl (cast-inert dc wt)
cast-inert (DCInr x dc) (TAInr wt) = CIInr (cast-inert dc wt)
cast-inert (DCCase dc dc₁ dc₂) (TACase wt x wt₁ x₁ wt₂) =
CICase (cast-inert dc wt) (cast-inert dc₁ wt₁) (cast-inert dc₂ wt₂)
cast-inert (DCPair dc dc₁) (TAPair wt wt₁) = CIPair (cast-inert dc wt) (cast-inert dc₁ wt₁)
cast-inert (DCFst dc) (TAFst wt) = CIFst (cast-inert dc wt)
cast-inert (DCSnd dc) (TASnd wt) = CISnd (cast-inert dc wt)
cast-inert () (TAEHole x x₁)
cast-inert () (TANEHole x wt x₁)
cast-inert (DCCast dc x x₁) (TACast wt x₂)
with complete-consistency x₂ x x₁
... | refl = CICast (cast-inert dc wt)
cast-inert () (TAFailedCast wt x x₁ x₂)
-- in a well typed complete internal expression, every cast is the
-- identity cast.
complete-casts : ∀{Γ Δ d τ1 τ2} →
Γ , Δ ⊢ d ⟨ τ1 ⇒ τ2 ⟩ :: τ2 →
d ⟨ τ1 ⇒ τ2 ⟩ dcomplete →
τ1 == τ2
complete-casts wt comp with cast-inert comp wt
complete-casts wt comp | CICast qq = refl
-- relates expressions to the same thing with all identity casts
-- removed. note that this is a syntactic rewrite and it goes under
-- binders.
data no-id-casts : ihexp → ihexp → Set where
NICNum : ∀{n} →
no-id-casts (N n) (N n)
NICPlus : ∀{d1 d2 d1' d2'} →
no-id-casts d1 d1' →
no-id-casts d2 d2' →
no-id-casts (d1 ·+ d2) (d1' ·+ d2')
NICVar : ∀{x} →
no-id-casts (X x) (X x)
NICLam : ∀{x τ d d'} →
no-id-casts d d' →
no-id-casts (·λ x ·[ τ ] d) (·λ x ·[ τ ] d')
NICAp : ∀{d1 d2 d1' d2'} →
no-id-casts d1 d1' →
no-id-casts d2 d2' →
no-id-casts (d1 ∘ d2) (d1' ∘ d2')
NICInl : ∀{d τ d'} →
no-id-casts d d' →
no-id-casts (inl τ d) (inl τ d')
NICInr : ∀{d τ d'} →
no-id-casts d d' →
no-id-casts (inr τ d) (inr τ d')
NICCase : ∀{d x d1 y d2 d' d1' d2'} →
no-id-casts d d' →
no-id-casts d1 d1' →
no-id-casts d2 d2' →
no-id-casts (case d x d1 y d2) (case d' x d1' y d2')
NICPair : ∀{d1 d2 d1' d2'} →
no-id-casts d1 d1' →
no-id-casts d2 d2' →
no-id-casts ⟨ d1 , d2 ⟩ ⟨ d1' , d2' ⟩
NICFst : ∀{d d'} →
no-id-casts d d' →
no-id-casts (fst d) (fst d')
NICSnd : ∀{d d'} →
no-id-casts d d' →
no-id-casts (snd d) (snd d')
NICHole : ∀{u} →
no-id-casts (⦇-⦈⟨ u ⟩) (⦇-⦈⟨ u ⟩)
NICNEHole : ∀{d d' u} →
no-id-casts d d' →
no-id-casts (⦇⌜ d ⌟⦈⟨ u ⟩) (⦇⌜ d' ⌟⦈⟨ u ⟩)
NICCast : ∀{d d' τ} →
no-id-casts d d' →
no-id-casts (d ⟨ τ ⇒ τ ⟩) d'
NICFailed : ∀{d d' τ1 τ2} →
no-id-casts d d' →
no-id-casts (d ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩) (d' ⟨ τ1 ⇒⦇-⦈⇏ τ2 ⟩)
-- removing identity casts doesn't change the type
no-id-casts-type : ∀{Γ Δ d τ d' } → Δ , Γ ⊢ d :: τ →
no-id-casts d d' →
Δ , Γ ⊢ d' :: τ
no-id-casts-type TANum NICNum = TANum
no-id-casts-type (TAPlus wt wt₁) (NICPlus nic nic₁) = TAPlus (no-id-casts-type wt nic) (no-id-casts-type wt₁ nic₁)
no-id-casts-type (TAVar x₁) NICVar = TAVar x₁
no-id-casts-type (TALam x₁ wt) (NICLam nic) = TALam x₁ (no-id-casts-type wt nic)
no-id-casts-type (TAAp wt wt₁) (NICAp nic nic₁) = TAAp (no-id-casts-type wt nic) (no-id-casts-type wt₁ nic₁)
no-id-casts-type (TAInl wt) (NICInl nic) = TAInl (no-id-casts-type wt nic)
no-id-casts-type (TAInr wt) (NICInr nic) = TAInr (no-id-casts-type wt nic)
no-id-casts-type (TACase wt x wt₁ x₁ wt₂) (NICCase nic nic₁ nic₂) = TACase (no-id-casts-type wt nic) x (no-id-casts-type wt₁ nic₁) x₁ (no-id-casts-type wt₂ nic₂)
no-id-casts-type (TAPair wt wt₁) (NICPair nic nic₁) = TAPair (no-id-casts-type wt nic) (no-id-casts-type wt₁ nic₁)
no-id-casts-type (TAFst wt) (NICFst nic) = TAFst (no-id-casts-type wt nic)
no-id-casts-type (TASnd wt) (NICSnd nic) = TASnd (no-id-casts-type wt nic)
no-id-casts-type (TAEHole x x₁) NICHole = TAEHole x x₁
no-id-casts-type (TANEHole x wt x₁) (NICNEHole nic) = TANEHole x (no-id-casts-type wt nic) x₁
no-id-casts-type (TACast wt x) (NICCast nic) = no-id-casts-type wt nic
no-id-casts-type (TAFailedCast wt x x₁ x₂) (NICFailed nic) = TAFailedCast (no-id-casts-type wt nic) x x₁ x₂
| {
"alphanum_fraction": 0.543946932,
"avg_line_length": 46.3846153846,
"ext": "agda",
"hexsha": "856f88c3244608d0753ed3f994d15d72421d80eb",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-agda",
"max_forks_repo_path": "cast-inert.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazelnut-agda",
"max_issues_repo_path": "cast-inert.agda",
"max_line_length": 163,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnut-agda",
"max_stars_repo_path": "cast-inert.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2071,
"size": 5427
} |
module PatternMatchingLambda where
data Bool : Set where
true false : Bool
data Void : Set where
data _≡_ {A : Set}(x : A) : A -> Set where
refl : x ≡ x
and : Bool -> Bool -> Bool
and = λ { true x → x ; false _ → false }
or : Bool -> Bool -> Bool
or x y = not (and (not x) (not y))
where not : Bool -> Bool
not = \ { true -> false ; false -> true }
iff : Bool -> Bool -> Bool -> Bool
iff = λ { true x -> λ { true → true ; false → false } ;
false x -> λ { true -> false ; false -> true }
}
pattern-matching-lambdas-compute : (x : Bool) -> or true x ≡ true
pattern-matching-lambdas-compute x = refl
isTrue : Bool -> Set
isTrue = \ { true -> Bool ; false -> Void }
absurd : (x : Bool) -> isTrue x -> Bool
absurd = \ { true x -> x ; false () }
--carefully chosen without eta, so that pattern matching is needed
data Unit : Set where
unit : Unit
isNotUnit : Unit -> Set
isNotUnit = \ { tt -> Void }
absurd-one-clause : (x : Unit) -> isNotUnit x -> Bool
absurd-one-clause = λ { tt ()}
data indexed-by-xor : (Bool -> Bool -> Bool) -> Set where
c : (b : Bool) -> indexed-by-xor \ { true true -> false ;
false false -> false ;
_ _ -> true }
-- won't work if the underscore is replaced with the actual value at the moment
f : (r : Bool -> Bool -> Bool) -> indexed-by-xor r -> Bool
f ._ (c b) = b
record Σ (A : Set)(B : A -> Set) : Set where
constructor _,_
field
proj₁ : A
proj₂ : B proj₁
fst : {A : Set}{B : A -> Set} -> (x : Σ A B) -> A
fst = \ { (a , b) -> a }
snd : {A : Set}{B : A -> Set} -> (x : Σ A B) -> B (fst x)
snd = \ { (a , b) -> b }
record FamSet : Set1 where
constructor _,_
field
A : Set
B : A -> Set
ΣFAM : (A : Set)(B : A -> Set)(P : A -> Set)(Q : (x : A) -> B x -> P x -> Set) -> FamSet
ΣFAM A B P Q = (Σ A P , \ { (a , p) -> Σ (B a) (λ b → Q a b p) } )
--The syntax doesn't interfere with hidden lambdas etc:
postulate
P : ({x : Bool} -> Bool) -> Set
p : P (λ {x} → x)
--Issue 446: Absurd clauses can appear inside more complex expressions
data Box (A : Set) : Set where
box : A → Box A
foo : {A : Set} → Box Void → A
foo = λ { (box ()) }
| {
"alphanum_fraction": 0.5253022839,
"avg_line_length": 26.2705882353,
"ext": "agda",
"hexsha": "0f08939e1cd0c95debeb4aa0e1986a6dbc2258db",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/agda-kanso",
"max_forks_repo_path": "test/succeed/PatternMatchingLambda.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/agda-kanso",
"max_issues_repo_path": "test/succeed/PatternMatchingLambda.agda",
"max_line_length": 88,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/succeed/PatternMatchingLambda.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 741,
"size": 2233
} |
{-# OPTIONS --safe #-}
open import Generics.Prelude
open import Generics.Telescope
open import Generics.Desc
open import Generics.Mu
open import Generics.Mu.All
module Generics.Mu.Elim
{P I n} {D : DataDesc P I n}
{p c} (Pr : ∀ {i} → μ D (p , i) → Set c)
(f : ∀ {i} (x : μ D (p , i)) → All D Pr x → Pr x) where
private
variable
V : ExTele P
i : ⟦ I ⟧tel p
v : ⟦ V ⟧tel p
private
Pr′ : ∀{i} → μ D (p , i) → Setω
Pr′ x = Liftω (Pr x)
all : (x : μ D (p , i)) → All D Pr x
allIndArg : (C : ConDesc P V I)
(x : ⟦ C ⟧IndArgω (μ D) (p , v))
→ AllIndArgωω Pr′ C x
allIndArg (var _) x = liftω (f x (all x))
allIndArg (A ⊗ B) (xa , xb) = allIndArg A xa , allIndArg B xb
allIndArg (π _ _ C) x s = allIndArg C (x s)
allCon : (C : ConDesc P V I)
(x : ⟦ C ⟧Conω (μ D) (p , v , i))
→ AllConωω Pr′ C x
allCon (var _) x = tt
allCon (A ⊗ B) (xa , xb) = allIndArg A xa , allCon B xb
allCon (π _ _ C) (_ , x) = allCon C x
all ⟨ k , x ⟩ = allCon (lookupCon D k) x
elim : (x : μ D (p , i)) → Pr x
elim x = f x (all x)
| {
"alphanum_fraction": 0.5323336457,
"avg_line_length": 24.25,
"ext": "agda",
"hexsha": "8e58defd9b2c9121564329bd60a02c36cee181c7",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-01-14T10:35:16.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-08T08:32:42.000Z",
"max_forks_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "flupe/generics",
"max_forks_repo_path": "src/Generics/Mu/Elim.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T10:48:30.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-09-13T07:33:50.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "flupe/generics",
"max_issues_repo_path": "src/Generics/Mu/Elim.agda",
"max_line_length": 61,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "flupe/generics",
"max_stars_repo_path": "src/Generics/Mu/Elim.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T09:35:17.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-04-08T15:10:20.000Z",
"num_tokens": 451,
"size": 1067
} |
------------------------------------------------------------------------
-- The two big-step semantics given by Leroy and Grall in "Coinductive
-- big-step operational semantics"
------------------------------------------------------------------------
module Lambda.Substitution.TwoSemantics where
open import Codata.Musical.Notation
open import Lambda.Syntax
open WHNF
open import Lambda.Substitution
-- Big-step semantics for terminating computations.
infix 4 _⇓_
data _⇓_ {n} : Tm n → Value n → Set where
val : ∀ {v} → ⌜ v ⌝ ⇓ v
app : ∀ {t₁ t₂ t v v′}
(t₁⇓ : t₁ ⇓ ƛ t)
(t₂⇓ : t₂ ⇓ v)
(t₁t₂⇓ : t / sub ⌜ v ⌝ ⇓ v′) →
t₁ · t₂ ⇓ v′
-- Big-step semantics for non-terminating computations.
infix 4 _⇑
data _⇑ {n} : Tm n → Set where
·ˡ : ∀ {t₁ t₂}
(t₁⇑ : ∞ (t₁ ⇑)) →
t₁ · t₂ ⇑
·ʳ : ∀ {t₁ t₂ v}
(t₁⇓ : t₁ ⇓ v)
(t₂⇑ : ∞ (t₂ ⇑)) →
t₁ · t₂ ⇑
app : ∀ {t₁ t₂ t v}
(t₁⇓ : t₁ ⇓ ƛ t)
(t₂⇓ : t₂ ⇓ v)
(t₁t₂⇓ : ∞ (t / sub ⌜ v ⌝ ⇑)) →
t₁ · t₂ ⇑
| {
"alphanum_fraction": 0.4354382658,
"avg_line_length": 24.6744186047,
"ext": "agda",
"hexsha": "0b0308d0906ac54dbf147665b7b7ebcd73a28867",
"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": "Lambda/Substitution/TwoSemantics.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": "Lambda/Substitution/TwoSemantics.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": "Lambda/Substitution/TwoSemantics.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": 418,
"size": 1061
} |
------------------------------------------------------------------------
-- Inversion of canonical subtyping in Fω with interval kinds
------------------------------------------------------------------------
{-# OPTIONS --safe --without-K #-}
module FOmegaInt.Kinding.Canonical.Inversion where
open import Data.Product using (_,_; _×_; proj₁; proj₂)
open import Data.Vec using ([]; _∷_; foldl)
open import Function using (_∘_)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong₂)
open import Relation.Nullary using (¬_)
open import FOmegaInt.Syntax
open import FOmegaInt.Kinding.Canonical
open import FOmegaInt.Kinding.Canonical.Validity
open Syntax
open ElimCtx
open Kinding
open ContextNarrowing
------------------------------------------------------------------------
-- Inversion of canonical subtyping (in the empty context).
-- NOTE. The lemmas in this module only hold in the empty context
-- because we can not invert instances of the interval projection
-- rules (<:-⟨| and (<:-|⟩) in arbitrary contexts. This is because
-- instances of these rules can reflect arbitrary subtyping
-- assumptions into the subtyping relation. Consider, e.g.
--
-- Γ, X :: ⊤..⊥ ctx Γ(X) = ⊥..⊤
-- ------------------------------- (∈-var)
-- Γ, X :: ⊤..⊥ ⊢ X :: ⊤..⊥
-- -------------------------- (<:-⟨|, <:-|⟩)
-- Γ, X :: ⊤..⊥ ⊢ ⊤ <: X <: ⊥
--
-- Which allows us to prove that ⊤ <: ⊥ using (<:-trans) under the
-- assumption (X : ⊤..⊥). On the other hand, it is impossible to give
-- a transitivity-free proof of ⊤ <: ⊥. In general, it is therefore
-- impossible to invert subtyping statements in non-empty contexts,
-- i.e. one cannot prove lemmas like (<:-→-inv) or (<:-∀-inv) below
-- for arbitrary contexts.
infix 4 ⊢_<!_
-- Top-level transitivity-free canonical subtyping in the empty
-- context.
data ⊢_<!_ : Elim 0 → Elim 0 → Set where
<!-⊥ : ∀ {a} → [] ⊢Nf a ⇉ a ⋯ a → ⊢ ⊥∙ <! a
<!-⊤ : ∀ {a} → [] ⊢Nf a ⇉ a ⋯ a → ⊢ a <! ⊤∙
<!-∀ : ∀ {k₁ k₂ a₁ a₂} → [] ⊢ k₂ <∷ k₁ → kd k₂ ∷ [] ⊢ a₁ <: a₂ →
[] ⊢Nf ∀∙ k₁ a₁ ⇉ ∀∙ k₁ a₁ ⋯ ∀∙ k₁ a₁ → ⊢ ∀∙ k₁ a₁ <! ∀∙ k₂ a₂
<!-→ : ∀ {a₁ a₂ b₁ b₂} → [] ⊢ a₂ <: a₁ → [] ⊢ b₁ <: b₂ →
⊢ a₁ ⇒∙ b₁ <! a₂ ⇒∙ b₂
-- Soundness of <! with respect to <: in the empty context.
sound-<! : ∀ {a b : Elim 0} → ⊢ a <! b → [] ⊢ a <: b
sound-<! (<!-⊥ a⇉a⋯a) = <:-⊥ a⇉a⋯a
sound-<! (<!-⊤ a⇉a⋯a) = <:-⊤ a⇉a⋯a
sound-<! (<!-∀ k₂<∷k₁ a₁<:a₂ Πk₁a₁⇉Πk₁a₁⋯Πk₁a₁) =
<:-∀ k₂<∷k₁ a₁<:a₂ Πk₁a₁⇉Πk₁a₁⋯Πk₁a₁
sound-<! (<!-→ a₂<:a₁ b₁<:b₂) = <:-→ a₂<:a₁ b₁<:b₂
-- The only proper (top-level) subtype of ⊥ is ⊥ itself.
⊥-<!-min : ∀ {a : Elim 0} → ⊢ a <! ⊥∙ → a ≡ ⊥∙
⊥-<!-min (<!-⊥ _) = refl
-- The only proper (top-level) supertype of ⊤ is ⊤ itself.
⊤-<!-max : ∀ {a : Elim 0} → ⊢ ⊤∙ <! a → a ≡ ⊤∙
⊤-<!-max (<!-⊤ _) = refl
-- Arrows are not (top-level) subtypes of universals and vice-versa.
⇒-≮!-Π : ∀ {a : Elim 0} {k b₁ b₂} → ¬ ⊢ a ⇒∙ b₁ <! ∀∙ k b₂
⇒-≮!-Π ()
Π-≮!-⇒ : ∀ {a : Elim 0} {k b₁ b₂} → ¬ ⊢ ∀∙ k b₁ <! a ⇒∙ b₂
Π-≮!-⇒ ()
-- Validity of <!
<!-valid : ∀ {a b} → ⊢ a <! b → [] ⊢Nf a ⇉ a ⋯ a × [] ⊢Nf b ⇉ b ⋯ b
<!-valid a<!b = <:-valid (sound-<! a<!b)
-- Top-level transitivity of canonical subtyping is admissible.
<!-trans : ∀ {a b c} → [] ⊢ a <: b → ⊢ b <! c → ⊢ a <! c
<!-trans (<:-trans a<:b b<:c) c<!d = <!-trans a<:b (<!-trans b<:c c<!d)
<!-trans (<:-⊥ a⇉a⋯a) a<!d = <!-⊥ (proj₂ (<!-valid a<!d))
<!-trans (<:-⊤ a⇉a⋯a) (<!-⊤ _) = <!-⊤ a⇉a⋯a
<!-trans (<:-∀ k₂<∷k₁ a₁<:a₂ Πk₁a₁⇉Πk₁a₁⋯Πk₁a₁) (<!-⊤ _) =
<!-⊤ (proj₁ (<:-valid (<:-∀ k₂<∷k₁ a₁<:a₂ Πk₁a₁⇉Πk₁a₁⋯Πk₁a₁)))
<!-trans (<:-∀ k₂<∷k₁ a₁<:a₂ Πk₁a₁⇉Πk₁a₁⋯Πk₁a₁) (<!-∀ k₃<∷k₂ a₂<:a₃ _) =
<!-∀ (<∷-trans k₃<∷k₂ k₂<∷k₁)
(<:-trans (⇓-<: k₃-kd k₃<∷k₂ a₁<:a₂) a₂<:a₃) Πk₁a₁⇉Πk₁a₁⋯Πk₁a₁
where k₃-kd = wf-kd-inv (wf-∷₁ (<:-ctx a₂<:a₃))
<!-trans (<:-→ a₂<:a₁ b₁<:b₂) (<!-⊤ a₂⇒b₂⇉a₂⇒b₂⋯a₂⇒b₂) =
<!-⊤ (proj₁ (<:-valid (<:-→ a₂<:a₁ b₁<:b₂)))
<!-trans (<:-→ a₂<:a₁ b₁<:b₂) (<!-→ a₃<:a₂ b₂<:b₃) =
<!-→ (<:-trans a₃<:a₂ a₂<:a₁) (<:-trans b₁<:b₂ b₂<:b₃)
<!-trans (<:-∙ {()} _ _) b<!c
<!-trans (<:-⟨| (∈-∙ {()} _ _)) b<!c
<!-trans (<:-|⟩ (∈-∙ {()} _ _)) b<!c
-- Completeness of <! with respect to <: in the empty context.
complete-<! : ∀ {a b : Elim 0} → [] ⊢ a <: b → ⊢ a <! b
complete-<! (<:-trans a<:b b<:c) = <!-trans a<:b (complete-<! b<:c)
complete-<! (<:-⊥ a⇉a⋯a) = <!-⊥ a⇉a⋯a
complete-<! (<:-⊤ a⇉a⋯a) = <!-⊤ a⇉a⋯a
complete-<! (<:-∀ k₂<∷k₁ a₁<:a₂ Πk₁a₁⇉Πk₁a₁⋯Πk₁a₁) =
<!-∀ k₂<∷k₁ a₁<:a₂ Πk₁a₁⇉Πk₁a₁⋯Πk₁a₁
complete-<! (<:-→ a₂<:a₁ b₁<:b₂) = <!-→ a₂<:a₁ b₁<:b₂
complete-<! (<:-∙ {()} _ _)
complete-<! (<:-⟨| (∈-∙ {()} _ _))
complete-<! (<:-|⟩ (∈-∙ {()} _ _))
-- The only proper (top-level) subtype of ⊥ is ⊥ itself.
⊥-<:-min : ∀ {a : Elim 0} → [] ⊢ a <: ⊥∙ → a ≡ ⊥∙
⊥-<:-min a<:⊥ = ⊥-<!-min (complete-<! a<:⊥)
-- The only proper (top-level) supertype of ⊤ is ⊤ itself.
⊤-<:-max : ∀ {a : Elim 0} → [] ⊢ ⊤∙ <: a → a ≡ ⊤∙
⊤-<:-max ⊤<:a = ⊤-<!-max (complete-<! ⊤<:a)
-- Inversion of canonical subtyping for universals and arrow types.
<:-∀-inv : ∀ {k₁ k₂ : Kind Elim 0} {a₁ a₂} → [] ⊢ ∀∙ k₁ a₁ <: ∀∙ k₂ a₂ →
[] ⊢ k₂ <∷ k₁ × kd k₂ ∷ [] ⊢ a₁ <: a₂
<:-∀-inv Πk₁a₁<:Πk₂a₂ with complete-<! Πk₁a₁<:Πk₂a₂
<:-∀-inv Πk₁a₁<:Πk₂a₂ | <!-∀ k₂<∷k₁ a₁<:a₂ _ = k₂<∷k₁ , a₁<:a₂
<:-→-inv : ∀ {a₁ a₂ : Elim 0} {b₁ b₂} → [] ⊢ a₁ ⇒∙ b₁ <: a₂ ⇒∙ b₂ →
[] ⊢ a₂ <: a₁ × [] ⊢ b₁ <: b₂
<:-→-inv a₁⇒b₁<:a₂⇒b₂ with complete-<! a₁⇒b₁<:a₂⇒b₂
<:-→-inv a₁⇒b₁<:a₂⇒b₂ | <!-→ a₂<∷a₁ b₁<:b₂ = a₂<∷a₁ , b₁<:b₂
-- Arrows are not canonical subtypes of universals and vice-versa.
⇒-≮:-Π : ∀ {a : Elim 0} {k b₁ b₂} → ¬ [] ⊢ a ⇒∙ b₁ <: ∀∙ k b₂
⇒-≮:-Π = ⇒-≮!-Π ∘ complete-<!
Π-≮:-⇒ : ∀ {a : Elim 0} {k b₁ b₂} → ¬ [] ⊢ ∀∙ k b₁ <: a ⇒∙ b₂
Π-≮:-⇒ = Π-≮!-⇒ ∘ complete-<!
| {
"alphanum_fraction": 0.4743165593,
"avg_line_length": 39.6068965517,
"ext": "agda",
"hexsha": "94da9059b3f3f569efa76560691c9bdc25a856b4",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-05-14T10:25:05.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-05-13T22:29:48.000Z",
"max_forks_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Blaisorblade/f-omega-int-agda",
"max_forks_repo_path": "src/FOmegaInt/Kinding/Canonical/Inversion.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_issues_repo_issues_event_max_datetime": "2021-05-14T08:54:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-05-14T08:09:40.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Blaisorblade/f-omega-int-agda",
"max_issues_repo_path": "src/FOmegaInt/Kinding/Canonical/Inversion.agda",
"max_line_length": 74,
"max_stars_count": 12,
"max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Blaisorblade/f-omega-int-agda",
"max_stars_repo_path": "src/FOmegaInt/Kinding/Canonical/Inversion.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-27T05:53:06.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-06-13T16:05:35.000Z",
"num_tokens": 2930,
"size": 5743
} |
------------------------------------------------------------------------------
-- Properties of the alter list
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.FOTC.UnguardedCorecursion.Alter.PropertiesATP where
open import FOT.FOTC.UnguardedCorecursion.Alter.Alter
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Data.Stream.Type
open import FOTC.Relation.Binary.Bisimilarity.Type
------------------------------------------------------------------------------
-- TODO (23 December 2013).
-- alter-Stream : Stream alter
-- alter-Stream = Stream-coind A h refl
-- where
-- A : D → Set
-- A xs = xs ≡ xs
-- {-# ATP definition A #-}
-- postulate h : A alter → ∃[ x' ] ∃[ xs' ] alter ≡ x' ∷ xs' ∧ A xs'
-- {-# ATP prove h #-}
-- TODO (23 December 2013).
-- alter'-Stream : Stream alter'
-- alter'-Stream = Stream-coind A h refl
-- where
-- A : D → Set
-- A xs = xs ≡ xs
-- {-# ATP definition A #-}
-- postulate h : A alter' → ∃[ x' ] ∃[ xs' ] alter' ≡ x' ∷ xs' ∧ A xs'
-- {-# ATP prove h #-}
-- TODO (23 December 2013).
-- alter≈alter' : alter ≈ alter'
-- alter≈alter' = ≈-coind B h₁ h₂
-- where
-- B : D → D → Set
-- B xs ys = xs ≡ xs
-- {-# ATP definition B #-}
-- postulate h₁ : B alter alter' → ∃[ x' ] ∃[ xs' ] ∃[ ys' ]
-- alter ≡ x' ∷ xs' ∧ alter' ≡ x' ∷ ys' ∧ B xs' ys'
-- {-# ATP prove h₁ #-}
-- postulate h₂ : B alter alter'
-- {-# ATP prove h₂ #-}
| {
"alphanum_fraction": 0.4694864048,
"avg_line_length": 29.5535714286,
"ext": "agda",
"hexsha": "fa987bc1b8031c011466d09dd17b0db29d4f4258",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/FOT/FOTC/UnguardedCorecursion/Alter/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": "notes/FOT/FOTC/UnguardedCorecursion/Alter/PropertiesATP.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "notes/FOT/FOTC/UnguardedCorecursion/Alter/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": 482,
"size": 1655
} |
{-# OPTIONS --without-K #-}
module sets.nat.ordering.properties where
open import function.isomorphism
open import sets.nat.core
open import sets.nat.ordering.lt
open import sets.nat.ordering.leq
open import hott.level.core
<-≤-iso : ∀ {n m} → (n < m) ≅ (suc n ≤ m)
<-≤-iso = record
{ to = f
; from = g
; iso₁ = λ _ → h1⇒prop <-level _ _
; iso₂ = λ _ → h1⇒prop ≤-level _ _ }
where
f : ∀ {n m} → n < m → suc n ≤ m
f suc< = refl-≤
f (n<s p) = s≤s (trans-≤ suc≤ (f p))
g : ∀ {n m} → suc n ≤ m → n < m
g {zero} (s≤s p) = z<n
g {suc n} (s≤s p) = ap<-suc (g p)
| {
"alphanum_fraction": 0.5405405405,
"avg_line_length": 24.6666666667,
"ext": "agda",
"hexsha": "634de4c86b8cdc3f00fd22745d9a682a6c186302",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z",
"max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pcapriotti/agda-base",
"max_forks_repo_path": "src/sets/nat/ordering/properties.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/sets/nat/ordering/properties.agda",
"max_line_length": 41,
"max_stars_count": 20,
"max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pcapriotti/agda-base",
"max_stars_repo_path": "src/sets/nat/ordering/properties.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z",
"num_tokens": 250,
"size": 592
} |
open import Prelude hiding (lift; Fin′; subst; id)
module Implicits.Substitutions.LNMetaType where
open import Implicits.Syntax.LNMetaType
open import Data.Fin.Substitution
open import Data.Star as Star hiding (map)
open import Data.Star.Properties
module MetaTypeApp {T} (l : Lift T MetaType) where
open Lift l hiding (var)
infixl 8 _/_
mutual
_simple/_ : ∀ {m n} → MetaSType m → Sub T m n → MetaType n
tc c simple/ σ = simpl (tc c)
tvar x simple/ σ = simpl (tvar x)
mvar x simple/ σ = lift $ lookup x σ
(a →' b) simple/ σ = simpl ((a / σ) →' (b / σ))
_/_ : ∀ {m n} → MetaType m → Sub T m n → MetaType n
(simpl c) / σ = (c simple/ σ)
(a ⇒ b) / σ = (a / σ) ⇒ (b / σ)
(∀' a) / σ = ∀' (a / σ)
open Application (record { _/_ = _/_ }) using (_/✶_)
→'-/✶-↑✶ : ∀ k {m n a b} (ρs : Subs T m n) →
(simpl (a →' b)) /✶ ρs ↑✶ k ≡ simpl ((a /✶ ρs ↑✶ k) →' (b /✶ ρs ↑✶ k))
→'-/✶-↑✶ k ε = refl
→'-/✶-↑✶ k (r ◅ ρs) = cong₂ _/_ (→'-/✶-↑✶ k ρs) refl
⇒-/✶-↑✶ : ∀ k {m n a b} (ρs : Subs T m n) →
(a ⇒ b) /✶ ρs ↑✶ k ≡ (a /✶ ρs ↑✶ k) ⇒ (b /✶ ρs ↑✶ k)
⇒-/✶-↑✶ k ε = refl
⇒-/✶-↑✶ k (r ◅ ρs) = cong₂ _/_ (⇒-/✶-↑✶ k ρs) refl
tc-/✶-↑✶ : ∀ k {c m n} (ρs : Subs T m n) →
(simpl (tc c)) /✶ ρs ↑✶ k ≡ simpl (tc c)
tc-/✶-↑✶ k ε = refl
tc-/✶-↑✶ k (r ◅ ρs) = cong₂ _/_ (tc-/✶-↑✶ k ρs) refl
tvar-/✶-↑✶ : ∀ k {c m n} (ρs : Subs T m n) →
(simpl (tvar c)) /✶ ρs ↑✶ k ≡ simpl (tvar c)
tvar-/✶-↑✶ k ε = refl
tvar-/✶-↑✶ k (r ◅ ρs) = cong₂ _/_ (tvar-/✶-↑✶ k ρs) refl
∀'-/✶-↑✶ : ∀ k {m n a} (ρs : Subs T m n) →
(∀' a) /✶ ρs ↑✶ k ≡ ∀' (a /✶ ρs ↑✶ k)
∀'-/✶-↑✶ k ε = refl
∀'-/✶-↑✶ k (x ◅ ρs) = cong₂ _/_ (∀'-/✶-↑✶ k ρs) refl
typeSubst : TermSubst MetaType
typeSubst = record { var = (λ n → simpl (mvar n)); app = MetaTypeApp._/_ }
open TermSubst typeSubst public hiding (var)
open MetaTypeApp termLift public using (_simple/_)
open MetaTypeApp varLift public using () renaming (_simple/_ to _simple/Var_)
infix 8 _[/_]
-- Shorthand for single-variable type substitutions
_[/_] : ∀ {n} → MetaType (suc n) → MetaType n → MetaType n
a [/ b ] = a / sub b
_◁m₁ : ∀ {m} (r : MetaType m) → ℕ
_◁m₁ (a ⇒ b) = b ◁m₁
_◁m₁ (∀' r) = 1 N+ r ◁m₁
_◁m₁ (simpl x) = zero
-- heads of metatypes
_◁m : ∀ {m} (r : MetaType m) → (MetaType ((r ◁m₁) N+ m))
(a ⇒ b) ◁m = b ◁m
∀' r ◁m = open-meta zero (r ◁m)
simpl x ◁m = simpl x
| {
"alphanum_fraction": 0.4895960832,
"avg_line_length": 31.8311688312,
"ext": "agda",
"hexsha": "3bf83f02ba5150bdc1644a35a0f71440a5fd7e83",
"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/Substitutions/LNMetaType.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/Substitutions/LNMetaType.agda",
"max_line_length": 83,
"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/Substitutions/LNMetaType.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": 1176,
"size": 2451
} |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.CommRing.Instances.MultivariatePoly-notationZ where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat
open import Cubical.Data.FinData
open import Cubical.Relation.Nullary
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.FGIdeal
open import Cubical.Algebra.CommRing.QuotientRing
open import Cubical.Algebra.CommRing.Instances.Int
open import Cubical.Algebra.Polynomials.Multivariate.Base
open import Cubical.Algebra.CommRing.Instances.MultivariatePoly
open import Cubical.Algebra.CommRing.Instances.MultivariatePoly-Quotient
-- Notations for ℤ polynomial rings
ℤ[X] : CommRing ℓ-zero
ℤ[X] = PolyCommRing ℤCommRing 1
ℤ[x] : Type ℓ-zero
ℤ[x] = fst ℤ[X]
ℤ[X,Y] : CommRing ℓ-zero
ℤ[X,Y] = PolyCommRing ℤCommRing 2
ℤ[x,y] : Type ℓ-zero
ℤ[x,y] = fst ℤ[X,Y]
ℤ[X,Y,Z] : CommRing ℓ-zero
ℤ[X,Y,Z] = PolyCommRing ℤCommRing 3
ℤ[x,y,z] : Type ℓ-zero
ℤ[x,y,z] = fst ℤ[X,Y,Z]
ℤ[X1,···,Xn] : (n : ℕ) → CommRing ℓ-zero
ℤ[X1,···,Xn] n = A[X1,···,Xn] ℤCommRing n
ℤ[x1,···,xn] : (n : ℕ) → Type ℓ-zero
ℤ[x1,···,xn] n = fst (ℤ[X1,···,Xn] n)
-- Notation for quotiented ℤ polynomial ring
<X> : FinVec ℤ[x] 1
<X> = <Xkʲ> ℤCommRing 1 0 1
<X²> : FinVec ℤ[x] 1
<X²> = <Xkʲ> ℤCommRing 1 0 2
<X³> : FinVec ℤ[x] 1
<X³> = <Xkʲ> ℤCommRing 1 0 3
<Xᵏ> : (k : ℕ) → FinVec ℤ[x] 1
<Xᵏ> k = <Xkʲ> ℤCommRing 1 0 k
ℤ[X]/X : CommRing ℓ-zero
ℤ[X]/X = A[X1,···,Xn]/<Xkʲ> ℤCommRing 1 0 1
ℤ[x]/x : Type ℓ-zero
ℤ[x]/x = fst ℤ[X]/X
ℤ[X]/X² : CommRing ℓ-zero
ℤ[X]/X² = A[X1,···,Xn]/<Xkʲ> ℤCommRing 1 0 2
ℤ[x]/x² : Type ℓ-zero
ℤ[x]/x² = fst ℤ[X]/X²
ℤ[X]/X³ : CommRing ℓ-zero
ℤ[X]/X³ = A[X1,···,Xn]/<Xkʲ> ℤCommRing 1 0 3
ℤ[x]/x³ : Type ℓ-zero
ℤ[x]/x³ = fst ℤ[X]/X³
ℤ[X1,···,Xn]/<X1,···,Xn> : (n : ℕ) → CommRing ℓ-zero
ℤ[X1,···,Xn]/<X1,···,Xn> n = A[X1,···,Xn]/<X1,···,Xn> ℤCommRing n
ℤ[x1,···,xn]/<x1,···,xn> : (n : ℕ) → Type ℓ-zero
ℤ[x1,···,xn]/<x1,···,xn> n = fst (ℤ[X1,···,Xn]/<X1,···,Xn> n)
-- Warning there is two possible definitions of ℤ[X]
-- they only holds up to a path
ℤ'[X]/X : CommRing ℓ-zero
ℤ'[X]/X = A[X1,···,Xn]/<X1,···,Xn> ℤCommRing 1
equivℤ[X] : ℤ'[X]/X ≡ ℤ[X]/X
equivℤ[X] = cong (λ X → (A[X1,···,Xn] ℤCommRing 1) / (genIdeal ((A[X1,···,Xn] ℤCommRing 1)) X))
(funExt (λ {zero → refl }))
| {
"alphanum_fraction": 0.6280642434,
"avg_line_length": 23.898989899,
"ext": "agda",
"hexsha": "17040f67ba73ef45b4170ce9c3385a87fcf8dfcb",
"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": "ce3120d3f8d692847b2744162bcd7a01f0b687eb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "guilhermehas/cubical",
"max_forks_repo_path": "Cubical/Algebra/CommRing/Instances/MultivariatePoly-notationZ.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ce3120d3f8d692847b2744162bcd7a01f0b687eb",
"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": "guilhermehas/cubical",
"max_issues_repo_path": "Cubical/Algebra/CommRing/Instances/MultivariatePoly-notationZ.agda",
"max_line_length": 95,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ce3120d3f8d692847b2744162bcd7a01f0b687eb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "guilhermehas/cubical",
"max_stars_repo_path": "Cubical/Algebra/CommRing/Instances/MultivariatePoly-notationZ.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": 1113,
"size": 2366
} |
-- Andreas, 2015-03-12
-- Sizes should be irrelevant in terms, while they are relevant in types!
{-# OPTIONS --experimental-irrelevance #-}
open import Common.Size
open import Common.Equality
module IrrelevantSizes where
-- Nat i is shape-irrelevant in i.
data Nat ..(i : Size) : Set where
zero : .(j : Size< i) → Nat i
suc : .(j : Size< i) → Nat j → Nat i
add : .(i : Size) → Nat i → Nat ∞ → Nat ∞
add i (zero j) y = y
add i (suc j x) y = suc ∞ (add j x y)
-- Proving this lemma is much easier with irrelevant sizes
-- in constructors zero and suc
plus0 : .(i : Size) (x : Nat i) → add ∞ x (zero ∞) ≡ x
plus0 i (zero j) = refl -- Goal: zero ∞ = zero j
plus0 i (suc j x) = cong (suc ∞) (plus0 j x) -- Goal: suc ∞ (add j x (zero ∞)) ≡ suc j x
| {
"alphanum_fraction": 0.5778331258,
"avg_line_length": 28.6785714286,
"ext": "agda",
"hexsha": "269b469ac0636ee35029e18cc7c0a04f49ce42e1",
"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/Succeed/IrrelevantSizes.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/IrrelevantSizes.agda",
"max_line_length": 91,
"max_stars_count": 3,
"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/IrrelevantSizes.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": 281,
"size": 803
} |
{-# OPTIONS --cubical --safe #-}
module Cardinality.Finite.ManifestBishop.Isomorphism where
open import Prelude
open import Data.Fin
open import Data.Fin.Properties
open import Container.List.Isomorphism
import Cardinality.Finite.ManifestBishop.Inductive as 𝕃
import Cardinality.Finite.ManifestBishop.Container as ℒ
open import Cardinality.Finite.SplitEnumerable.Isomorphism
open import Data.Nat.Properties
∈!ℒ⇒∈!𝕃 : ∀ (x : A) l (xs : Fin l → A) → x ℒ.∈! (l , xs) → x 𝕃.∈! ℒ→𝕃 (l , xs)
∈!ℒ⇒∈!𝕃 x (suc l) xs ((f0 , p) , u) = (f0 , p) , lemma
where
lemma : (y : x 𝕃.∈ ℒ→𝕃 (suc l , xs)) → (f0 , p) ≡ y
lemma (f0 , q) = cong (∈ℒ⇒∈𝕃 x (suc l , xs)) (u (f0 , q))
lemma (fs m , q) =
let o , r = subst (x ℒ.∈_) (ℒ→𝕃→ℒ l (xs ∘ fs)) (m , q)
in ⊥-elim (znots (cong (FinToℕ ∘ fst) (u (fs o , r))))
∈!ℒ⇒∈!𝕃 x (suc l) xs ((fs n , p) , u) = 𝕃.push! xs0≢x (∈!ℒ⇒∈!𝕃 x l (xs ∘ fs) ((n , p) , uxss))
where
xs0≢x : xs f0 ≢ x
xs0≢x xs0≡x = snotz (cong (FinToℕ ∘ fst) (u (f0 , xs0≡x)))
uxss : (y : x ℒ.∈ (l , xs ∘ fs)) → (n , p) ≡ y
uxss (m , q) = cong (λ { (f0 , q) → ⊥-elim (xs0≢x q) ; (fs m , q) → m , q}) (u (fs m , q))
𝕃⇔ℒ⟨ℬ⟩ : 𝕃.ℬ A ⇔ ℒ.ℬ A
𝕃⇔ℒ⟨ℬ⟩ .fun (sup , cov) = 𝕃→ℒ sup , cov
𝕃⇔ℒ⟨ℬ⟩ .inv ((l , xs) , cov) = ℒ→𝕃 (l , xs) , λ x → ∈!ℒ⇒∈!𝕃 x l xs (cov x)
𝕃⇔ℒ⟨ℬ⟩ .rightInv (sup , cov) i .fst = 𝕃⇔ℒ .rightInv sup i
𝕃⇔ℒ⟨ℬ⟩ .rightInv ((l , xs) , cov) i .snd x =
J
(λ ys ys≡ → (zs : x ℒ.∈! ys) → PathP (λ i → x ℒ.∈! sym ys≡ i) zs (cov x))
(λ _ → isPropIsContr _ _)
(sym (ℒ→𝕃→ℒ l xs))
(∈!ℒ⇒∈!𝕃 x l xs (cov x))
i
𝕃⇔ℒ⟨ℬ⟩ .leftInv (sup , cov) i .fst = 𝕃⇔ℒ .leftInv sup i
𝕃⇔ℒ⟨ℬ⟩ .leftInv (sup , cov) i .snd x =
J
(λ ys ys≡ → (zs : x 𝕃.∈! ys) → PathP (λ i → x 𝕃.∈! sym ys≡ i) zs (cov x))
(λ zs → isPropIsContr _ _)
(sym (𝕃→ℒ→𝕃 sup))
(∈!ℒ⇒∈!𝕃 x (𝕃.length sup) (sup 𝕃.!_) (cov x))
i
| {
"alphanum_fraction": 0.5190217391,
"avg_line_length": 34.7169811321,
"ext": "agda",
"hexsha": "1ffda6cd4e72d922ad53385cd758b1c75fd0648c",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Cardinality/Finite/ManifestBishop/Isomorphism.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/combinatorics-paper",
"max_issues_repo_path": "agda/Cardinality/Finite/ManifestBishop/Isomorphism.agda",
"max_line_length": 94,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Cardinality/Finite/ManifestBishop/Isomorphism.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-05T15:32:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-01-05T14:07:44.000Z",
"num_tokens": 1036,
"size": 1840
} |
-- Andreas, 2013-02-26
module Issue799a where
data D (A : Set1) : Set where
d : D A
x : D Set
x = d {A = _} -- correct parameter name
y : D Set
y = d {B = _} -- wrong parameter name, should give error
| {
"alphanum_fraction": 0.6165048544,
"avg_line_length": 17.1666666667,
"ext": "agda",
"hexsha": "3dd93087ff10e4006a29e66e76ab29434131b090",
"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/Issue799a.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/Issue799a.agda",
"max_line_length": 56,
"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/Issue799a.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": 75,
"size": 206
} |
module Acc where
data Acc ( A : Set ) ( Lt : A -> A -> Set) : A -> Set where
acc : ( b : A )
-> ( ( a : A ) -> Lt a b -> Acc A Lt a )
-> ( Acc A Lt b )
data Nat : Set where
zero : Nat
succ : Nat -> Nat
data Lt : Nat -> Nat -> Set where
ltzero : ( x : Nat ) -> Lt zero (succ x)
ltsucc : ( x : Nat ) -> (y : Nat) -> Lt x y -> Lt (succ x) (succ y)
ltcase : ( x : Nat ) -> ( y : Nat ) -> Lt x (succ y) ->
( P : Nat -> Set ) -> ( (x' : Nat ) -> Lt x' y -> P x') -> P y -> P x
ltcase zero zero _ P hx' hy = hy
ltcase zero (succ y') _ P hx' hy = hx' zero (ltzero y')
ltcase (succ x') zero (ltsucc .x' .zero ()) _ _ _
ltcase (succ x') (succ y') (ltsucc ._ ._ p) P hx' hy =
ltcase x' y' p (\ n -> P (succ n))
(\ x'' p' -> hx' (succ x'') (ltsucc _ _ p')) hy
accSucc : (x : Nat) -> Acc Nat Lt x -> Acc Nat Lt (succ x)
accSucc x a@(acc .x h) = acc (succ x) (\ y p -> ltcase y x p (Acc Nat Lt) h a)
| {
"alphanum_fraction": 0.4625922023,
"avg_line_length": 33.8928571429,
"ext": "agda",
"hexsha": "8e80eef676da69858f57c178d3c35b47b0151819",
"lang": "Agda",
"max_forks_count": 5,
"max_forks_repo_forks_event_max_datetime": "2021-08-16T07:47:36.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-30T00:17:04.000Z",
"max_forks_repo_head_hexsha": "4a674eddcc8950f37fcc723b26f81d5164b05f08",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andreasabel/miniagda",
"max_forks_repo_path": "examples/BUG-THINGOUTOFCXT.agda",
"max_issues_count": 7,
"max_issues_repo_head_hexsha": "4a674eddcc8950f37fcc723b26f81d5164b05f08",
"max_issues_repo_issues_event_max_datetime": "2020-03-17T08:09:01.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-12-16T15:48:25.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "andreasabel/miniagda",
"max_issues_repo_path": "examples/BUG-THINGOUTOFCXT.agda",
"max_line_length": 78,
"max_stars_count": 85,
"max_stars_repo_head_hexsha": "4a674eddcc8950f37fcc723b26f81d5164b05f08",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "andreasabel/miniagda",
"max_stars_repo_path": "examples/BUG-THINGOUTOFCXT.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-12T16:54:56.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-12-16T15:53:24.000Z",
"num_tokens": 368,
"size": 949
} |
{-# OPTIONS --without-K --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Properties.Symmetry {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped
open import Definition.Typed
open import Definition.Typed.Properties
import Definition.Typed.Weakening as Wk
open import Definition.LogicalRelation
open import Definition.LogicalRelation.ShapeView
open import Definition.LogicalRelation.Irrelevance
open import Definition.LogicalRelation.Properties.Conversion
open import Tools.Product
import Tools.PropositionalEquality as PE
mutual
-- Helper function for symmetry of type equality using shape views.
symEqT : ∀ {Γ A B l l′} {[A] : Γ ⊩⟨ l ⟩ A} {[B] : Γ ⊩⟨ l′ ⟩ B}
→ ShapeView Γ l l′ A B [A] [B]
→ Γ ⊩⟨ l ⟩ A ≡ B / [A]
→ Γ ⊩⟨ l′ ⟩ B ≡ A / [B]
symEqT (ℕᵥ D D′) A≡B = red D
symEqT (Emptyᵥ D D′) A≡B = red D
symEqT (Unitᵥ D D′) A≡B = red D
symEqT (ne (ne K D neK K≡K) (ne K₁ D₁ neK₁ K≡K₁)) (ne₌ M D′ neM K≡M)
rewrite whrDet* (red D′ , ne neM) (red D₁ , ne neK₁) =
ne₌ _ D neK
(~-sym K≡M)
symEqT {Γ = Γ} (Bᵥ W (Bᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Bᵣ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁))
(B₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) =
let ΠF₁G₁≡ΠF′G′ = whrDet* (red D₁ , ⟦ W ⟧ₙ) (D′ , ⟦ W ⟧ₙ)
F₁≡F′ , G₁≡G′ = B-PE-injectivity W ΠF₁G₁≡ΠF′G′
[F₁≡F] : ∀ {Δ} {ρ} [ρ] ⊢Δ → _
[F₁≡F] {Δ} {ρ} [ρ] ⊢Δ =
let ρF′≡ρF₁ ρ = PE.cong (wk ρ) (PE.sym F₁≡F′)
[ρF′] {ρ} [ρ] ⊢Δ = PE.subst (λ x → Δ ⊩⟨ _ ⟩ wk ρ x) F₁≡F′ ([F]₁ [ρ] ⊢Δ)
in irrelevanceEq′ {Δ} (ρF′≡ρF₁ ρ)
([ρF′] [ρ] ⊢Δ) ([F]₁ [ρ] ⊢Δ)
(symEq ([F] [ρ] ⊢Δ) ([ρF′] [ρ] ⊢Δ)
([F≡F′] [ρ] ⊢Δ))
in B₌ _ _ (red D) (≅-sym (PE.subst (λ x → Γ ⊢ ⟦ W ⟧ F ▹ G ≅ x) (PE.sym ΠF₁G₁≡ΠF′G′) A≡B))
[F₁≡F]
(λ {ρ} [ρ] ⊢Δ [a] →
let ρG′a≡ρG₁′a = PE.cong (λ x → wk (lift ρ) x [ _ ]) (PE.sym G₁≡G′)
[ρG′a] = PE.subst (λ x → _ ⊩⟨ _ ⟩ wk (lift ρ) x [ _ ]) G₁≡G′
([G]₁ [ρ] ⊢Δ [a])
[a]₁ = convTerm₁ ([F]₁ [ρ] ⊢Δ) ([F] [ρ] ⊢Δ) ([F₁≡F] [ρ] ⊢Δ) [a]
in irrelevanceEq′ ρG′a≡ρG₁′a
[ρG′a]
([G]₁ [ρ] ⊢Δ [a])
(symEq ([G] [ρ] ⊢Δ [a]₁) [ρG′a]
([G≡G′] [ρ] ⊢Δ [a]₁)))
symEqT (Uᵥ (Uᵣ _ _ _) (Uᵣ _ _ _)) A≡B = PE.refl
symEqT (emb⁰¹ x) A≡B = symEqT x A≡B
symEqT (emb¹⁰ x) A≡B = symEqT x A≡B
-- Symmetry of type equality.
symEq : ∀ {Γ A B l l′} ([A] : Γ ⊩⟨ l ⟩ A) ([B] : Γ ⊩⟨ l′ ⟩ B)
→ Γ ⊩⟨ l ⟩ A ≡ B / [A]
→ Γ ⊩⟨ l′ ⟩ B ≡ A / [B]
symEq [A] [B] A≡B = symEqT (goodCases [A] [B] A≡B) A≡B
symNeutralTerm : ∀ {t u A Γ}
→ Γ ⊩neNf t ≡ u ∷ A
→ Γ ⊩neNf u ≡ t ∷ A
symNeutralTerm (neNfₜ₌ neK neM k≡m) = neNfₜ₌ neM neK (~-sym k≡m)
symNatural-prop : ∀ {Γ k k′}
→ [Natural]-prop Γ k k′
→ [Natural]-prop Γ k′ k
symNatural-prop (sucᵣ (ℕₜ₌ k k′ d d′ t≡u prop)) =
sucᵣ (ℕₜ₌ k′ k d′ d (≅ₜ-sym t≡u) (symNatural-prop prop))
symNatural-prop zeroᵣ = zeroᵣ
symNatural-prop (ne prop) = ne (symNeutralTerm prop)
symEmpty-prop : ∀ {Γ k k′}
→ [Empty]-prop Γ k k′
→ [Empty]-prop Γ k′ k
symEmpty-prop (ne prop) = ne (symNeutralTerm prop)
-- Symmetry of term equality.
symEqTerm : ∀ {l Γ A t u} ([A] : Γ ⊩⟨ l ⟩ A)
→ Γ ⊩⟨ l ⟩ t ≡ u ∷ A / [A]
→ Γ ⊩⟨ l ⟩ u ≡ t ∷ A / [A]
symEqTerm (Uᵣ′ .⁰ 0<1 ⊢Γ) (Uₜ₌ A B d d′ typeA typeB A≡B [A] [B] [A≡B]) =
Uₜ₌ B A d′ d typeB typeA (≅ₜ-sym A≡B) [B] [A] (symEq [A] [B] [A≡B])
symEqTerm (ℕᵣ D) (ℕₜ₌ k k′ d d′ t≡u prop) =
ℕₜ₌ k′ k d′ d (≅ₜ-sym t≡u) (symNatural-prop prop)
symEqTerm (Emptyᵣ D) (Emptyₜ₌ k k′ d d′ t≡u prop) =
Emptyₜ₌ k′ k d′ d (≅ₜ-sym t≡u) (symEmpty-prop prop)
symEqTerm (Unitᵣ D) (Unitₜ₌ ⊢t ⊢u) =
Unitₜ₌ ⊢u ⊢t
symEqTerm (ne′ K D neK K≡K) (neₜ₌ k m d d′ nf) =
neₜ₌ m k d′ d (symNeutralTerm nf)
symEqTerm (Bᵣ′ BΠ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Πₜ₌ f g d d′ funcF funcG f≡g [f] [g] [f≡g]) =
Πₜ₌ g f d′ d funcG funcF (≅ₜ-sym f≡g) [g] [f]
(λ ρ ⊢Δ [a] → symEqTerm ([G] ρ ⊢Δ [a]) ([f≡g] ρ ⊢Δ [a]))
symEqTerm (Bᵣ′ BΣ F G D ⊢F ⊢G A≡A [F] [G] G-ext)
(Σₜ₌ p r d d′ pProd rProd p≅r [t] [u] [fstp] [fstr] [fst≡] [snd≡]) =
let ⊢Γ = wf ⊢F
[Gfstp≡Gfstr] = G-ext Wk.id ⊢Γ [fstp] [fstr] [fst≡]
in Σₜ₌ r p d′ d rProd pProd (≅ₜ-sym p≅r) [u] [t] [fstr] [fstp]
(symEqTerm ([F] Wk.id ⊢Γ) [fst≡])
(convEqTerm₁
([G] Wk.id ⊢Γ [fstp]) ([G] Wk.id ⊢Γ [fstr])
[Gfstp≡Gfstr]
(symEqTerm ([G] Wk.id ⊢Γ [fstp]) [snd≡]))
symEqTerm (emb 0<1 x) t≡u = symEqTerm x t≡u
| {
"alphanum_fraction": 0.4705520213,
"avg_line_length": 42.0086206897,
"ext": "agda",
"hexsha": "60b0293db52848e59b4b733788830782765a7a51",
"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": "4746894adb5b8edbddc8463904ee45c2e9b29b69",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Vtec234/logrel-mltt",
"max_forks_repo_path": "Definition/LogicalRelation/Properties/Symmetry.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69",
"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": "Vtec234/logrel-mltt",
"max_issues_repo_path": "Definition/LogicalRelation/Properties/Symmetry.agda",
"max_line_length": 94,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Vtec234/logrel-mltt",
"max_stars_repo_path": "Definition/LogicalRelation/Properties/Symmetry.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2414,
"size": 4873
} |
module Lib where
open import Data.Nat public hiding (_<_)
open import Function public using (_∘_)
open import Data.List public
open import Data.Product public using (_×_ ; _,_ ; proj₁ ; proj₂ ; Σ ; ∃)
open import Data.Sum public using (_⊎_ ; [_,_]′ ; inj₁ ; inj₂)
open import Relation.Nullary public
open import Relation.Binary.PropositionalEquality public hiding ([_])
open import Category.Functor public
-- Pointer into a list. It is similar to list membership as defined in
-- Data.List.AnyMembership, rather than going through propositional
-- equality, it asserts the existence of the referenced element
-- directly.
infix 4 _∈_
data _∈_ {A : Set} : A → List A → Set where
hd : ∀ {x xs} → x ∈ (x ∷ xs)
tl : ∀ {x y xs} → x ∈ xs → x ∈ (y ∷ xs)
mapIdx : {A B : Set} → (f : A → B) →
{x : A} {xs : List A} → x ∈ xs → f x ∈ map f xs
mapIdx f hd = hd
mapIdx f (tl x₁) = tl (mapIdx f x₁)
| {
"alphanum_fraction": 0.6596685083,
"avg_line_length": 33.5185185185,
"ext": "agda",
"hexsha": "acd8c6c37435562f3e0ceb60723e0becf5cb5b1d",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-10-15T09:01:37.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-10-15T09:01:37.000Z",
"max_forks_repo_head_hexsha": "ef878f7fa5afa51fb7a14cd8f7f75da0af1b9deb",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "luminousfennell/polybta",
"max_forks_repo_path": "icfp2014/Lib.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ef878f7fa5afa51fb7a14cd8f7f75da0af1b9deb",
"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": "luminousfennell/polybta",
"max_issues_repo_path": "icfp2014/Lib.agda",
"max_line_length": 73,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ef878f7fa5afa51fb7a14cd8f7f75da0af1b9deb",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "luminousfennell/polybta",
"max_stars_repo_path": "icfp2014/Lib.agda",
"max_stars_repo_stars_event_max_datetime": "2019-10-15T04:35:29.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-15T04:35:29.000Z",
"num_tokens": 283,
"size": 905
} |
module Debug where
open import Data.String using (String) public
open import Level public
{-# FOREIGN GHC import qualified Data.Text #-}
{-# FOREIGN GHC import qualified Debug.Trace as Trace #-}
{-# FOREIGN GHC
debug' :: Data.Text.Text -> c -> c
debug' txt c = Trace.trace (Data.Text.unpack txt) c
#-}
postulate debug : {a : Level} {A : Set a} → String → A → A
{-# COMPILE GHC debug = (\x -> (\y -> debug')) #-}
| {
"alphanum_fraction": 0.6506024096,
"avg_line_length": 27.6666666667,
"ext": "agda",
"hexsha": "417a03ff6f157e5c75ee1074c38d2a30e945a741",
"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": "ae541df13d069df4eb1464f29fbaa9804aad439f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Zalastax/singly-typed-actors",
"max_forks_repo_path": "src/Debug.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f",
"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": "Zalastax/singly-typed-actors",
"max_issues_repo_path": "src/Debug.agda",
"max_line_length": 58,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Zalastax/thesis",
"max_stars_repo_path": "src/Debug.agda",
"max_stars_repo_stars_event_max_datetime": "2018-02-02T16:44:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-02-02T16:44:43.000Z",
"num_tokens": 107,
"size": 415
} |
{-
This second-order term syntax was created from the following second-order syntax description:
syntax Lens | L
type
S : 0-ary
A : 0-ary
term
get : S -> A
put : S A -> S
theory
(PG) s : S a : A |> get (put (s, a)) = a
(GP) s : S |> put (s, get(s)) = s
(PP) s : S a b : A |> put (put(s, a), b) = put (s, a)
-}
module Lens.Syntax where
open import SOAS.Common
open import SOAS.Context
open import SOAS.Variable
open import SOAS.Families.Core
open import SOAS.Construction.Structure
open import SOAS.ContextMaps.Inductive
open import SOAS.Metatheory.Syntax
open import Lens.Signature
private
variable
Γ Δ Π : Ctx
α : LT
𝔛 : Familyₛ
-- Inductive term declaration
module L:Terms (𝔛 : Familyₛ) where
data L : Familyₛ where
var : ℐ ⇾̣ L
mvar : 𝔛 α Π → Sub L Π Γ → L α Γ
get : L S Γ → L A Γ
put : L S Γ → L A Γ → L S Γ
open import SOAS.Metatheory.MetaAlgebra ⅀F 𝔛
Lᵃ : MetaAlg L
Lᵃ = record
{ 𝑎𝑙𝑔 = λ where
(getₒ ⋮ a) → get a
(putₒ ⋮ a , b) → put a b
; 𝑣𝑎𝑟 = var ; 𝑚𝑣𝑎𝑟 = λ 𝔪 mε → mvar 𝔪 (tabulate mε) }
module Lᵃ = MetaAlg Lᵃ
module _ {𝒜 : Familyₛ}(𝒜ᵃ : MetaAlg 𝒜) where
open MetaAlg 𝒜ᵃ
𝕤𝕖𝕞 : L ⇾̣ 𝒜
𝕊 : Sub L Π Γ → Π ~[ 𝒜 ]↝ Γ
𝕊 (t ◂ σ) new = 𝕤𝕖𝕞 t
𝕊 (t ◂ σ) (old v) = 𝕊 σ v
𝕤𝕖𝕞 (mvar 𝔪 mε) = 𝑚𝑣𝑎𝑟 𝔪 (𝕊 mε)
𝕤𝕖𝕞 (var v) = 𝑣𝑎𝑟 v
𝕤𝕖𝕞 (get a) = 𝑎𝑙𝑔 (getₒ ⋮ 𝕤𝕖𝕞 a)
𝕤𝕖𝕞 (put a b) = 𝑎𝑙𝑔 (putₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b)
𝕤𝕖𝕞ᵃ⇒ : MetaAlg⇒ Lᵃ 𝒜ᵃ 𝕤𝕖𝕞
𝕤𝕖𝕞ᵃ⇒ = record
{ ⟨𝑎𝑙𝑔⟩ = λ{ {t = t} → ⟨𝑎𝑙𝑔⟩ t }
; ⟨𝑣𝑎𝑟⟩ = refl
; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪 = 𝔪}{mε} → cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-tab mε)) } }
where
open ≡-Reasoning
⟨𝑎𝑙𝑔⟩ : (t : ⅀ L α Γ) → 𝕤𝕖𝕞 (Lᵃ.𝑎𝑙𝑔 t) ≡ 𝑎𝑙𝑔 (⅀₁ 𝕤𝕖𝕞 t)
⟨𝑎𝑙𝑔⟩ (getₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (putₒ ⋮ _) = refl
𝕊-tab : (mε : Π ~[ L ]↝ Γ)(v : ℐ α Π) → 𝕊 (tabulate mε) v ≡ 𝕤𝕖𝕞 (mε v)
𝕊-tab mε new = refl
𝕊-tab mε (old v) = 𝕊-tab (mε ∘ old) v
module _ (g : L ⇾̣ 𝒜)(gᵃ⇒ : MetaAlg⇒ Lᵃ 𝒜ᵃ g) where
open MetaAlg⇒ gᵃ⇒
𝕤𝕖𝕞! : (t : L α Γ) → 𝕤𝕖𝕞 t ≡ g t
𝕊-ix : (mε : Sub L Π Γ)(v : ℐ α Π) → 𝕊 mε v ≡ g (index mε v)
𝕊-ix (x ◂ mε) new = 𝕤𝕖𝕞! x
𝕊-ix (x ◂ mε) (old v) = 𝕊-ix mε v
𝕤𝕖𝕞! (mvar 𝔪 mε) rewrite cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-ix mε))
= trans (sym ⟨𝑚𝑣𝑎𝑟⟩) (cong (g ∘ mvar 𝔪) (tab∘ix≈id mε))
𝕤𝕖𝕞! (var v) = sym ⟨𝑣𝑎𝑟⟩
𝕤𝕖𝕞! (get a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! (put a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩
-- Syntax instance for the signature
L:Syn : Syntax
L:Syn = record
{ ⅀F = ⅀F
; ⅀:CS = ⅀:CompatStr
; mvarᵢ = L:Terms.mvar
; 𝕋:Init = λ 𝔛 → let open L:Terms 𝔛 in record
{ ⊥ = L ⋉ Lᵃ
; ⊥-is-initial = record { ! = λ{ {𝒜 ⋉ 𝒜ᵃ} → 𝕤𝕖𝕞 𝒜ᵃ ⋉ 𝕤𝕖𝕞ᵃ⇒ 𝒜ᵃ }
; !-unique = λ{ {𝒜 ⋉ 𝒜ᵃ} (f ⋉ fᵃ⇒) {x = t} → 𝕤𝕖𝕞! 𝒜ᵃ f fᵃ⇒ t } } } }
-- Instantiation of the syntax and metatheory
open Syntax L:Syn public
open L:Terms public
open import SOAS.Families.Build public
open import SOAS.Syntax.Shorthands Lᵃ public
open import SOAS.Metatheory L:Syn public
| {
"alphanum_fraction": 0.5330687831,
"avg_line_length": 24.192,
"ext": "agda",
"hexsha": "6faee41a4765e06df8b4df853a07cae7d01733ea",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z",
"max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JoeyEremondi/agda-soas",
"max_forks_repo_path": "out/Lens/Syntax.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JoeyEremondi/agda-soas",
"max_issues_repo_path": "out/Lens/Syntax.agda",
"max_line_length": 93,
"max_stars_count": 39,
"max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JoeyEremondi/agda-soas",
"max_stars_repo_path": "out/Lens/Syntax.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z",
"num_tokens": 1861,
"size": 3024
} |
open import Oscar.Prelude
open import Oscar.Class.IsCategory
open import Oscar.Class.IsPrefunctor
open import Oscar.Class.Reflexivity
open import Oscar.Class.Smap
open import Oscar.Class.Surjection
open import Oscar.Class.Surjidentity
open import Oscar.Class.Transitivity
module Oscar.Class.IsFunctor where
module _
{𝔬₁} {𝔒₁ : Ø 𝔬₁}
{𝔯₁} (_∼₁_ : 𝔒₁ → 𝔒₁ → Ø 𝔯₁)
{ℓ₁} (_∼̇₁_ : ∀ {x y} → x ∼₁ y → x ∼₁ y → Ø ℓ₁)
(ε₁ : Reflexivity.type _∼₁_)
(_↦₁_ : Transitivity.type _∼₁_)
{𝔬₂} {𝔒₂ : Ø 𝔬₂}
{𝔯₂} (_∼₂_ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂)
{ℓ₂} (_∼̇₂_ : ∀ {x y} → x ∼₂ y → x ∼₂ y → Ø ℓ₂)
(ε₂ : Reflexivity.type _∼₂_)
(_↦₂_ : Transitivity.type _∼₂_)
{surjection : Surjection.type 𝔒₁ 𝔒₂}
(smap : Smap.type _∼₁_ _∼₂_ surjection surjection)
where
record IsFunctor : Ø 𝔬₁ ∙̂ 𝔯₁ ∙̂ ℓ₁ ∙̂ 𝔬₂ ∙̂ 𝔯₂ ∙̂ ℓ₂ where
constructor ∁
field
⦃ `IsPrefunctor ⦄ : IsPrefunctor _∼₁_ _∼̇₁_ _↦₁_ _∼₂_ _∼̇₂_ _↦₂_ smap
overlap ⦃ `IsCategory₁ ⦄ : IsCategory _∼₁_ _∼̇₁_ ε₁ _↦₁_
overlap ⦃ `IsCategory₂ ⦄ : IsCategory _∼₂_ _∼̇₂_ ε₂ _↦₂_
overlap ⦃ `𝒮urjidentity ⦄ : Surjidentity.class _∼₁_ _∼₂_ _∼̇₂_ smap ε₁ ε₂
| {
"alphanum_fraction": 0.643175736,
"avg_line_length": 32.9705882353,
"ext": "agda",
"hexsha": "b0135d27b39ab0abfa37dd3e339be2da659dd8db",
"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/Class/IsFunctor.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/Class/IsFunctor.agda",
"max_line_length": 79,
"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/Class/IsFunctor.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 566,
"size": 1121
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Groups.Definition
open import Rings.Definition
open import Rings.Orders.Partial.Definition
open import Rings.Orders.Total.Definition
open import Rings.Orders.Total.Lemmas
open import Rings.IntegralDomains.Definition
open import Functions.Definition
open import Setoids.Setoids
open import Setoids.Orders.Partial.Definition
open import Setoids.Orders.Total.Definition
open import Sets.EquivalenceRelations
module Fields.FieldOfFractions.Order {a b c : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} {_*_ : A → A → A} {R : Ring S _+_ _*_} {_<_ : Rel {_} {c} A} {pOrder : SetoidPartialOrder S _<_} {pRing : PartiallyOrderedRing R pOrder} (I : IntegralDomain R) (order : TotallyOrderedRing pRing) where
open import Fields.FieldOfFractions.Setoid I
open import Fields.FieldOfFractions.Ring I
open import Fields.FieldOfFractions.Addition I
open import Fields.FieldOfFractions.Multiplication I
open import Fields.FieldOfFractions.Lemmas I
open Ring R
open Setoid S
open Equivalence eq
open SetoidTotalOrder (TotallyOrderedRing.total order)
open import Rings.Orders.Partial.Lemmas
open PartiallyOrderedRing pRing
fieldOfFractionsComparison : Rel fieldOfFractionsSet
fieldOfFractionsComparison (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) with (totality (Ring.0R R) denomA ,, totality (Ring.0R R) denomB)
fieldOfFractionsComparison (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inl 0<denomA) ,, inl (inl 0<denomB) = (numA * denomB) < (numB * denomA)
fieldOfFractionsComparison (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inl 0<denomA) ,, inl (inr denomB<0) = (numB * denomA) < (numA * denomB)
fieldOfFractionsComparison (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inl 0<denomA) ,, inr 0=denomB = exFalso (denomB!=0 (symmetric 0=denomB))
fieldOfFractionsComparison (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inr denomA<0) ,, inl (inl 0<denomB) = (numB * denomA) < (numA * denomB)
fieldOfFractionsComparison (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inr denomA<0) ,, inl (inr denomB<0) = (numA * denomB) < (numB * denomA)
fieldOfFractionsComparison (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inr denomA<0) ,, inr 0=denomB = exFalso (denomB!=0 (symmetric 0=denomB))
fieldOfFractionsComparison (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inr 0=denomA ,, _ = exFalso (denomA!=0 (symmetric 0=denomA))
private
abstract
fieldOfFractionsOrderWellDefinedLeft : {x y z : fieldOfFractionsSet} → fieldOfFractionsComparison x y → Setoid._∼_ fieldOfFractionsSetoid x z → fieldOfFractionsComparison z y
fieldOfFractionsOrderWellDefinedLeft {(record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 })} {(record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 })} {(record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 })} x<y x=z with totality (Ring.0R R) denomZ
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inl 0<denomZ) with totality (Ring.0R R) denomY
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inl 0<denomZ) | inl (inl 0<denomY) with totality (Ring.0R R) denomX
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inl 0<denomZ) | inl (inl 0<denomY) | inl (inl 0<denomX) with totality (Ring.0R R) denomY
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inl 0<denomZ) | inl (inl 0<denomY) | inl (inl 0<denomX) | inl (inl _) = s
where
have : ((numX * denomY) * denomZ) < ((numY * denomX) * denomZ)
have = ringCanMultiplyByPositive pRing 0<denomZ x<y
p : ((numX * denomZ) * denomY) < ((numY * denomX) * denomZ)
p = SetoidPartialOrder.<WellDefined pOrder (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) reflexive have
q : ((denomX * numZ) * denomY) < ((numY * denomX) * denomZ)
q = SetoidPartialOrder.<WellDefined pOrder (*WellDefined x=z reflexive) reflexive p
r : ((numZ * denomY) * denomX) < ((numY * denomZ) * denomX)
r = SetoidPartialOrder.<WellDefined pOrder (transitive (symmetric *Associative) *Commutative) (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) q
s : (numZ * denomY) < (numY * denomZ)
s = ringCanCancelPositive order 0<denomX r
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inl 0<denomZ) | inl (inl 0<denomY) | inl (inl 0<denomX) | inl (inr x) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<denomY x))
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inl 0<denomZ) | inl (inl 0<denomY) | inl (inl 0<denomX) | inr x = exFalso (denomY!=0 (symmetric x))
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inl 0<denomZ) | inl (inl 0<denomY) | inl (inr denomX<0) with totality (Ring.0R R) denomY
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inl 0<denomZ) | inl (inl 0<denomY) | inl (inr denomX<0) | inl (inl _) = ringCanCancelNegative order denomX<0 r
where
p : ((numY * denomX) * denomZ) < ((numX * denomZ) * denomY)
p = SetoidPartialOrder.<WellDefined pOrder reflexive (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) (ringCanMultiplyByPositive pRing 0<denomZ x<y)
q : ((numY * denomX) * denomZ) < ((denomX * numZ) * denomY)
q = SetoidPartialOrder.<WellDefined pOrder reflexive (*WellDefined x=z reflexive) p
r : ((numY * denomZ) * denomX) < ((numZ * denomY) * denomX)
r = SetoidPartialOrder.<WellDefined pOrder (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) (transitive (symmetric *Associative) *Commutative) q
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inl 0<denomZ) | inl (inl 0<denomY) | inl (inr denomX<0) | inl (inr x) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<denomY x))
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inl 0<denomZ) | inl (inl 0<denomY) | inl (inr denomX<0) | inr x = exFalso (denomY!=0 (Equivalence.symmetric (Setoid.eq S) x))
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inl 0<denomZ) | inl (inl 0<denomY) | inr 0=denomX = exFalso (denomX!=0 (Equivalence.symmetric (Setoid.eq S) 0=denomX))
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inl 0<denomZ) | inl (inr denomY<0) with totality (Ring.0R R) denomX
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inl 0<denomZ) | inl (inr denomY<0) | inl (inl 0<denomX) with totality (Ring.0R R) denomY
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inl 0<denomZ) | inl (inr denomY<0) | inl (inl 0<denomX) | inl (inl 0<denomY) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<denomY denomY<0))
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inl 0<denomZ) | inl (inr denomY<0) | inl (inl 0<denomX) | inl (inr _) = ringCanCancelPositive order 0<denomX r
where
p : ((numY * denomX) * denomZ) < ((numX * denomY) * denomZ)
p = ringCanMultiplyByPositive pRing 0<denomZ x<y
q : ((numY * denomX) * denomZ) < ((denomX * numZ) * denomY)
q = SetoidPartialOrder.<WellDefined pOrder reflexive (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) (transitive *Associative (*WellDefined x=z reflexive)))) p
r : ((numY * denomZ) * denomX) < ((numZ * denomY) * denomX)
r = SetoidPartialOrder.<WellDefined pOrder (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) (transitive (symmetric *Associative) *Commutative) q
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inl 0<denomZ) | inl (inr denomY<0) | inl (inl 0<denomX) | inr x = exFalso (denomY!=0 (Equivalence.symmetric (Setoid.eq S) x))
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inl 0<denomZ) | inl (inr denomY<0) | inl (inr denomX<0) with totality (Ring.0R R) denomY
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inl 0<denomZ) | inl (inr denomY<0) | inl (inr denomX<0) | inl (inl 0<denomY) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<denomY denomY<0))
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inl 0<denomZ) | inl (inr denomY<0) | inl (inr denomX<0) | inl (inr _) = ringCanCancelNegative order denomX<0 q
where
p : ((numX * denomY) * denomZ) < ((numY * denomX) * denomZ)
p = ringCanMultiplyByPositive pRing 0<denomZ x<y
q : ((numZ * denomY) * denomX) < ((numY * denomZ) * denomX)
q = SetoidPartialOrder.<WellDefined pOrder (transitive (*WellDefined *Commutative reflexive) (transitive (symmetric *Associative) (transitive (*WellDefined reflexive x=z) (transitive *Commutative (transitive (symmetric *Associative) *Commutative))))) (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) p
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inl 0<denomZ) | inl (inr denomY<0) | inl (inr denomX<0) | inr x = exFalso (denomY!=0 (Equivalence.symmetric (Setoid.eq S) x))
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inl 0<denomZ) | inl (inr denomY<0) | inr 0=denomX = exFalso (denomX!=0 (Equivalence.symmetric (Setoid.eq S) 0=denomX))
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inl 0<denomZ) | inr 0=denomY = exFalso (denomY!=0 (Equivalence.symmetric (Setoid.eq S) 0=denomY))
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inr denomZ<0) with totality (Ring.0R R) denomY
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inr denomZ<0) | inl (inl 0<denomY) with totality (Ring.0R R) denomX
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inr denomZ<0) | inl (inl 0<denomY) | inl (inl 0<denomX) with totality (Ring.0R R) denomY
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inr denomZ<0) | inl (inl 0<denomY) | inl (inl 0<denomX) | inl (inl _) = ringCanCancelPositive order 0<denomX (SetoidPartialOrder.<WellDefined pOrder (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) (transitive (symmetric *Associative) (transitive (*WellDefined reflexive x=z) (transitive (*WellDefined reflexive (*Commutative)) (transitive *Associative (*WellDefined *Commutative reflexive))))) p)
where
p : ((numY * denomX) * denomZ) < ((denomY * numX) * denomZ)
p = ringCanMultiplyByNegative pRing denomZ<0 (SetoidPartialOrder.<WellDefined pOrder *Commutative reflexive x<y)
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inr denomZ<0) | inl (inl 0<denomY) | inl (inl 0<denomX) | inl (inr denomY<0) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<denomY denomY<0))
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inr denomZ<0) | inl (inl 0<denomY) | inl (inl 0<denomX) | inr x = exFalso (denomY!=0 (Equivalence.symmetric (Setoid.eq S) x))
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inr denomZ<0) | inl (inl 0<denomY) | inl (inr denomX<0) with totality (Ring.0R R) denomY
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inr denomZ<0) | inl (inl 0<denomY) | inl (inr denomX<0) | inl (inl _) = ringCanCancelNegative order denomX<0 (SetoidPartialOrder.<WellDefined pOrder (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) (transitive *Associative (transitive (*WellDefined x=z reflexive) (transitive (symmetric *Associative) *Commutative))))) (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) p)
where
p : ((numX * denomY) * denomZ) < ((numY * denomX) * denomZ)
p = ringCanMultiplyByNegative pRing denomZ<0 x<y
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inr denomZ<0) | inl (inl 0<denomY) | inl (inr denomX<0) | inl (inr denomY<0) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder denomY<0 0<denomY))
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inr denomZ<0) | inl (inl 0<denomY) | inl (inr denomX<0) | inr 0=denomY = exFalso (denomY!=0 (Equivalence.symmetric (Setoid.eq S) 0=denomY))
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inr denomZ<0) | inl (inl 0<denomY) | inr x = exFalso (denomX!=0 (symmetric x))
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inr denomZ<0) | inl (inr denomY<0) with totality (Ring.0R R) denomX
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inr denomZ<0) | inl (inr denomY<0) | inl (inl 0<denomX) with totality (Ring.0R R) denomY
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inr denomZ<0) | inl (inr denomY<0) | inl (inl 0<denomX) | inl (inl 0<denomY) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<denomY denomY<0))
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inr denomZ<0) | inl (inr denomY<0) | inl (inl 0<denomX) | inl (inr _) = ringCanCancelPositive order 0<denomX (SetoidPartialOrder.<WellDefined pOrder (transitive (*WellDefined *Commutative reflexive) (transitive (symmetric *Associative) (transitive (*WellDefined reflexive x=z) (transitive *Associative (transitive *Commutative *Associative))))) (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) (ringCanMultiplyByNegative pRing denomZ<0 x<y))
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inr denomZ<0) | inl (inr denomY<0) | inl (inl 0<denomX) | inr x = exFalso (denomY!=0 (Equivalence.symmetric (Setoid.eq S) x))
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inr denomZ<0) | inl (inr denomY<0) | inl (inr denomX<0) with totality (Ring.0R R) denomY
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inr denomZ<0) | inl (inr denomY<0) | inl (inr denomX<0) | inl (inl 0<denomY) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<denomY denomY<0))
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inr denomZ<0) | inl (inr denomY<0) | inl (inr denomX<0) | inl (inr _) = ringCanCancelNegative order denomX<0 (SetoidPartialOrder.<WellDefined pOrder (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) (transitive (*WellDefined *Commutative reflexive) (transitive (symmetric *Associative) (transitive (*WellDefined reflexive x=z) (transitive (*WellDefined reflexive *Commutative) (transitive *Associative (*WellDefined *Commutative reflexive)))))) (ringCanMultiplyByNegative pRing denomZ<0 x<y))
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inr denomZ<0) | inl (inr denomY<0) | inl (inr denomX<0) | inr x = exFalso (denomY!=0 (Equivalence.symmetric (Setoid.eq S) x))
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inr denomZ<0) | inl (inr denomY<0) | inr x = exFalso (denomX!=0 (Equivalence.symmetric (Setoid.eq S) x))
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inl (inr denomZ<0) | inr x = exFalso (denomY!=0 (Equivalence.symmetric (Setoid.eq S) x))
fieldOfFractionsOrderWellDefinedLeft {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y x=z | inr 0=denomZ = exFalso (denomZ!=0 (Equivalence.symmetric (Setoid.eq S) 0=denomZ))
fieldOfFractionsOrderWellDefinedRight : {x y z : fieldOfFractionsSet} → fieldOfFractionsComparison x y → Setoid._∼_ (fieldOfFractionsSetoid) y z → fieldOfFractionsComparison x z
fieldOfFractionsOrderWellDefinedRight {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y y=z with totality (Ring.0R R) denomX
fieldOfFractionsOrderWellDefinedRight {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y y=z | inl (inl 0<denomX) with totality (Ring.0R R) denomZ
fieldOfFractionsOrderWellDefinedRight {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y y=z | inl (inl 0<denomX) | inl (inl 0<denomZ) with totality (Ring.0R R) denomY
fieldOfFractionsOrderWellDefinedRight {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y y=z | inl (inl 0<denomX) | inl (inl 0<denomZ) | inl (inl 0<denomY) = ringCanCancelPositive order 0<denomY (SetoidPartialOrder.<WellDefined pOrder (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) (transitive *Associative (transitive (*WellDefined y=z reflexive) (transitive (symmetric *Associative) *Commutative))))) (ringCanMultiplyByPositive pRing 0<denomZ x<y))
fieldOfFractionsOrderWellDefinedRight {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y y=z | inl (inl 0<denomX) | inl (inl 0<denomZ) | inl (inr denomY<0) = ringCanCancelNegative order denomY<0 (SetoidPartialOrder.<WellDefined pOrder (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) (transitive *Associative (transitive (*WellDefined y=z reflexive) (transitive (symmetric *Associative) *Commutative))))) (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) (ringCanMultiplyByPositive pRing 0<denomZ x<y))
fieldOfFractionsOrderWellDefinedRight {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y y=z | inl (inl 0<denomX) | inl (inl 0<denomZ) | inr x = exFalso (denomY!=0 (Equivalence.symmetric (Setoid.eq S) x))
fieldOfFractionsOrderWellDefinedRight {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y y=z | inl (inl 0<denomX) | inl (inr denomZ<0) with totality (Ring.0R R) denomY
fieldOfFractionsOrderWellDefinedRight {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y y=z | inl (inl 0<denomX) | inl (inr denomZ<0) | inl (inl 0<denomY) = ringCanCancelPositive order 0<denomY (SetoidPartialOrder.<WellDefined pOrder (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) (transitive *Associative (transitive (*WellDefined y=z reflexive) (transitive (symmetric *Associative) *Commutative))))) (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) (ringCanMultiplyByNegative pRing denomZ<0 x<y))
fieldOfFractionsOrderWellDefinedRight {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y y=z | inl (inl 0<denomX) | inl (inr denomZ<0) | inl (inr denomY<0) = ringCanCancelNegative order denomY<0 (SetoidPartialOrder.<WellDefined pOrder (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) (transitive (*Associative) (transitive (*WellDefined y=z reflexive) (transitive (symmetric *Associative) *Commutative))))) (ringCanMultiplyByNegative pRing denomZ<0 x<y))
fieldOfFractionsOrderWellDefinedRight {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y y=z | inl (inl 0<denomX) | inl (inr denomZ<0) | inr x = exFalso (denomY!=0 (Equivalence.symmetric (Setoid.eq S) x))
fieldOfFractionsOrderWellDefinedRight {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y y=z | inl (inl 0<denomX) | inr x = exFalso (denomZ!=0 (Equivalence.symmetric (Setoid.eq S) x))
fieldOfFractionsOrderWellDefinedRight {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y y=z | inl (inr denomX<0) with totality (Ring.0R R) denomZ
fieldOfFractionsOrderWellDefinedRight {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y y=z | inl (inr denomX<0) | inl (inl 0<denomZ) with totality (Ring.0R R) denomY
fieldOfFractionsOrderWellDefinedRight {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y y=z | inl (inr denomX<0) | inl (inl 0<denomZ) | inl (inl 0<denomY) = ringCanCancelPositive order 0<denomY (SetoidPartialOrder.<WellDefined pOrder (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) (transitive *Associative (transitive (*WellDefined y=z reflexive) (transitive (symmetric *Associative) *Commutative))))) (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) (ringCanMultiplyByPositive pRing 0<denomZ x<y))
fieldOfFractionsOrderWellDefinedRight {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y y=z | inl (inr denomX<0) | inl (inl 0<denomZ) | inl (inr denomY<0) = ringCanCancelNegative order denomY<0 (SetoidPartialOrder.<WellDefined pOrder (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) (transitive *Associative (transitive (*WellDefined y=z reflexive) (transitive (symmetric *Associative) *Commutative))))) (ringCanMultiplyByPositive pRing 0<denomZ x<y))
fieldOfFractionsOrderWellDefinedRight {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y y=z | inl (inr denomX<0) | inl (inl 0<denomZ) | inr x = exFalso (denomY!=0 (Equivalence.symmetric (Setoid.eq S) x))
fieldOfFractionsOrderWellDefinedRight {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y y=z | inl (inr denomX<0) | inl (inr denomZ<0) with totality (Ring.0R R) denomY
fieldOfFractionsOrderWellDefinedRight {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y y=z | inl (inr denomX<0) | inl (inr denomZ<0) | inl (inl 0<denomY) = ringCanCancelPositive order 0<denomY (SetoidPartialOrder.<WellDefined pOrder (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) (transitive *Associative (transitive (*WellDefined y=z reflexive) (transitive (symmetric *Associative) *Commutative))))) (ringCanMultiplyByNegative pRing denomZ<0 x<y))
fieldOfFractionsOrderWellDefinedRight {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y y=z | inl (inr denomX<0) | inl (inr denomZ<0) | inl (inr denomY<0) = ringCanCancelNegative order denomY<0 (SetoidPartialOrder.<WellDefined pOrder (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) (transitive *Associative (transitive (*WellDefined y=z reflexive) (transitive (symmetric *Associative) *Commutative))))) (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) (ringCanMultiplyByNegative pRing denomZ<0 x<y))
fieldOfFractionsOrderWellDefinedRight {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y y=z | inl (inr denomX<0) | inl (inr denomZ<0) | inr x = exFalso (denomY!=0 (Equivalence.symmetric (Setoid.eq S) x))
fieldOfFractionsOrderWellDefinedRight {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y y=z | inl (inr denomX<0) | inr x = exFalso (denomZ!=0 (Equivalence.symmetric (Setoid.eq S) x))
fieldOfFractionsOrderWellDefinedRight {record { num = numX ; denom = denomX ; denomNonzero = denomX!=0 }} {record { num = numY ; denom = denomY ; denomNonzero = denomY!=0 }} {record { num = numZ ; denom = denomZ ; denomNonzero = denomZ!=0 }} x<y y=z | inr x = exFalso (denomX!=0 (Equivalence.symmetric (Setoid.eq S) x))
swapLemma : {x y z : A} → Setoid._∼_ S ((x * y) * z) ((x * z) * y)
swapLemma = transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)
private
abstract
irreflexive : (a : fieldOfFractionsSet) (pr : fieldOfFractionsComparison a a) → False
irreflexive record { num = aNum ; denom = aDenom ; denomNonzero = aDenom!=0 } pr with totality (Ring.0R R) aDenom
irreflexive record { num = aNum ; denom = aDenom ; denomNonzero = aDenom!=0 } pr | inl (inl 0<aDenom) with totality (Ring.0R R) aDenom
irreflexive record { num = aNum ; denom = aDenom ; denomNonzero = aDenom!=0 } pr | inl (inl 0<aDenom) | inl (inl _) = SetoidPartialOrder.irreflexive pOrder pr
irreflexive record { num = aNum ; denom = aDenom ; denomNonzero = aDenom!=0 } pr | inl (inl 0<aDenom) | inl (inr aDenom<0) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<aDenom aDenom<0))
irreflexive record { num = aNum ; denom = aDenom ; denomNonzero = aDenom!=0 } pr | inl (inl 0<aDenom) | inr x = exFalso (aDenom!=0 (Equivalence.symmetric (Setoid.eq S) x))
irreflexive record { num = aNum ; denom = aDenom ; denomNonzero = aDenom!=0 } pr | inl (inr aDenom<0) with totality (Ring.0R R) aDenom
irreflexive record { num = aNum ; denom = aDenom ; denomNonzero = aDenom!=0 } pr | inl (inr aDenom<0) | inl (inl 0<aDenom) = SetoidPartialOrder.irreflexive pOrder pr
irreflexive record { num = aNum ; denom = aDenom ; denomNonzero = aDenom!=0 } pr | inl (inr aDenom<0) | inl (inr _) = SetoidPartialOrder.irreflexive pOrder pr
irreflexive record { num = aNum ; denom = aDenom ; denomNonzero = aDenom!=0 } pr | inl (inr aDenom<0) | inr x = exFalso (aDenom!=0 (Equivalence.symmetric (Setoid.eq S) x))
irreflexive record { num = aNum ; denom = aDenom ; denomNonzero = aDenom!=0 } pr | inr x = exFalso (aDenom!=0 (Equivalence.symmetric (Setoid.eq S) x))
<transitive : (a b c : fieldOfFractionsSet) (a<b : fieldOfFractionsComparison a b) (b<c : fieldOfFractionsComparison b c) → fieldOfFractionsComparison a c
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c with totality (Ring.0R R) denomA
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inl 0<denomA) with totality (Ring.0R R) denomC
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inl 0<denomA) | inl (inl 0<denomC) with totality (Ring.0R R) denomB
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inl 0<denomA) | inl (inl 0<denomC) | inl (inl x) with totality (Ring.0R R) denomC
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inl 0<denomA) | inl (inl 0<denomC) | inl (inl 0<denomB) | inl (inl _) = ringCanCancelPositive order 0<denomB (SetoidPartialOrder.<Transitive pOrder (SetoidPartialOrder.<WellDefined pOrder (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) reflexive (ringCanMultiplyByPositive pRing 0<denomC a<b)) (SetoidPartialOrder.<WellDefined pOrder (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) (ringCanMultiplyByPositive pRing 0<denomA b<c)))
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inl 0<denomA) | inl (inl 0<denomC) | inl (inl 0<denomB) | inl (inr denomC<0) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<denomC denomC<0))
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inl 0<denomA) | inl (inl 0<denomC) | inl (inl 0<denomB) | inr x = exFalso (denomC!=0 (Equivalence.symmetric (Setoid.eq S) x))
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inl 0<denomA) | inl (inl 0<denomC) | inl (inr denomB<0) with totality (Ring.0R R) denomC
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inl 0<denomA) | inl (inl 0<denomC) | inl (inr denomB<0) | inl (inl _) = ringCanCancelNegative order denomB<0 (SetoidPartialOrder.<Transitive pOrder (SetoidPartialOrder.<WellDefined pOrder (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) reflexive (ringCanMultiplyByPositive pRing 0<denomA b<c)) (SetoidPartialOrder.<WellDefined pOrder (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) (ringCanMultiplyByPositive pRing 0<denomC a<b)))
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inl 0<denomA) | inl (inl 0<denomC) | inl (inr denomB<0) | inl (inr denomC<0) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<denomC denomC<0))
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inl 0<denomA) | inl (inl 0<denomC) | inl (inr denomB<0) | inr x = exFalso (denomC!=0 (Equivalence.symmetric (Setoid.eq S) x))
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inl 0<denomA) | inl (inl 0<denomC) | inr x = exFalso (denomB!=0 (Equivalence.symmetric (Setoid.eq S) x))
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inl 0<denomA) | inl (inr denomC<0) with totality (Ring.0R R) denomB
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inl 0<denomA) | inl (inr denomC<0) | inl (inl 0<denomB) with totality (Ring.0R R) denomC
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inl 0<denomA) | inl (inr denomC<0) | inl (inl 0<denomB) | inl (inl 0<denomC) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<denomC denomC<0))
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inl 0<denomA) | inl (inr denomC<0) | inl (inl 0<denomB) | inl (inr _) = ringCanCancelPositive order 0<denomB (SetoidPartialOrder.<Transitive pOrder have (SetoidPartialOrder.<WellDefined pOrder swapLemma swapLemma (ringCanMultiplyByNegative pRing denomC<0 a<b)))
where
have : ((numC * denomA) * denomB) < ((numB * denomC) * denomA)
have = SetoidPartialOrder.<WellDefined pOrder swapLemma reflexive (ringCanMultiplyByPositive pRing 0<denomA b<c)
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inl 0<denomA) | inl (inr denomC<0) | inl (inl 0<denomB) | inr x = exFalso (denomC!=0 (Equivalence.symmetric (Setoid.eq S) x))
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inl 0<denomA) | inl (inr denomC<0) | inl (inr denomB<0) with totality (Ring.0R R) denomC
... | (inl (inl 0<denomC)) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<denomC denomC<0))
... | (inl (inr _)) = ringCanCancelNegative order denomB<0 (SetoidPartialOrder.<Transitive pOrder have (SetoidPartialOrder.<WellDefined pOrder (swapLemma) (swapLemma) (ringCanMultiplyByPositive pRing 0<denomA b<c)))
where
have : ((numA * denomC) * denomB) < ((numB * denomA) * denomC)
have = SetoidPartialOrder.<WellDefined pOrder (swapLemma) reflexive (ringCanMultiplyByNegative pRing denomC<0 a<b)
... | inr x = exFalso (denomC!=0 (Equivalence.symmetric (Setoid.eq S) x))
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inl 0<denomA) | inl (inr denomC<0) | inr x = exFalso (denomB!=0 (Equivalence.symmetric (Setoid.eq S) x))
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inl 0<denomA) | inr x = exFalso (denomC!=0 (Equivalence.symmetric (Setoid.eq S) x))
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inr denomA<0) with totality (Ring.0R R) denomC
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inr denomA<0) | inl (inl 0<denomC) with totality (Ring.0R R) denomB
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inr denomA<0) | inl (inl 0<denomC) | inl (inl 0<denomB) with totality (Ring.0R R) denomC
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inr denomA<0) | inl (inl 0<denomC) | inl (inl 0<denomB) | inl (inl _) = ringCanCancelPositive order 0<denomB (SetoidPartialOrder.<Transitive pOrder (SetoidPartialOrder.<WellDefined pOrder (swapLemma) (swapLemma) (ringCanMultiplyByNegative pRing denomA<0 b<c)) have)
where
have : ((numB * denomA) * denomC) < ((numA * denomC) * denomB)
have = SetoidPartialOrder.<WellDefined pOrder reflexive (swapLemma) (ringCanMultiplyByPositive pRing 0<denomC a<b)
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inr denomA<0) | inl (inl 0<denomC) | inl (inl 0<denomB) | inl (inr denomC<0) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<denomC denomC<0))
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inr denomA<0) | inl (inl 0<denomC) | inl (inl 0<denomB) | inr x = exFalso (denomC!=0 (Equivalence.symmetric (Setoid.eq S) x))
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inr denomA<0) | inl (inl 0<denomC) | inl (inr denomB<0) with totality (Ring.0R R) denomC
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inr denomA<0) | inl (inl 0<denomC) | inl (inr denomB<0) | inl (inl _) = ringCanCancelNegative order denomB<0 (SetoidPartialOrder.<Transitive pOrder have (SetoidPartialOrder.<WellDefined pOrder (swapLemma) (swapLemma) (ringCanMultiplyByNegative pRing denomA<0 b<c)))
where
have : ((numA * denomC) * denomB) < ((numB * denomA) * denomC)
have = SetoidPartialOrder.<WellDefined pOrder (swapLemma) reflexive (ringCanMultiplyByPositive pRing 0<denomC a<b)
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inr denomA<0) | inl (inl 0<denomC) | inl (inr denomB<0) | inl (inr denomC<0) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<denomC denomC<0))
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inr denomA<0) | inl (inl 0<denomC) | inl (inr denomB<0) | inr x = exFalso (denomC!=0 (Equivalence.symmetric (Setoid.eq S) x))
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inr denomA<0) | inl (inl 0<denomC) | inr x = exFalso (denomB!=0 (Equivalence.symmetric (Setoid.eq S) x))
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inr denomA<0) | inl (inr denomC<0) with totality (Ring.0R R) denomB
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inr denomA<0) | inl (inr denomC<0) | inl (inl 0<denomB) with totality (Ring.0R R) denomC
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inr denomA<0) | inl (inr denomC<0) | inl (inl 0<denomB) | inl (inl 0<denomC) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<denomC denomC<0))
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inr denomA<0) | inl (inr denomC<0) | inl (inl 0<denomB) | inl (inr _) = ringCanCancelPositive order 0<denomB (SetoidPartialOrder.<Transitive pOrder (SetoidPartialOrder.<WellDefined pOrder swapLemma reflexive (ringCanMultiplyByNegative pRing denomC<0 a<b)) (SetoidPartialOrder.<WellDefined pOrder (swapLemma) (swapLemma) (ringCanMultiplyByNegative pRing denomA<0 b<c)))
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inr denomA<0) | inl (inr denomC<0) | inl (inl 0<denomB) | inr x = exFalso (denomC!=0 (Equivalence.symmetric (Setoid.eq S) x))
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inr denomA<0) | inl (inr denomC<0) | inl (inr denomB<0) with totality (Ring.0R R) denomC
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inr denomA<0) | inl (inr denomC<0) | inl (inr denomB<0) | inl (inl 0<denomC) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<denomC denomC<0))
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inr denomA<0) | inl (inr denomC<0) | inl (inr denomB<0) | inl (inr _) = ringCanCancelNegative order denomB<0 (SetoidPartialOrder.<Transitive pOrder (SetoidPartialOrder.<WellDefined pOrder (swapLemma) (swapLemma) (ringCanMultiplyByNegative pRing denomA<0 b<c)) (SetoidPartialOrder.<WellDefined pOrder reflexive (swapLemma) (ringCanMultiplyByNegative pRing denomC<0 a<b)))
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inr denomA<0) | inl (inr denomC<0) | inl (inr denomB<0) | inr x = exFalso (denomC!=0 (Equivalence.symmetric (Setoid.eq S) x))
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inr denomA<0) | inl (inr denomC<0) | inr x = exFalso (denomB!=0 (Equivalence.symmetric (Setoid.eq S) x))
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inl (inr denomA<0) | inr x = exFalso (denomC!=0 (Equivalence.symmetric (Setoid.eq S) x))
<transitive (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) a<b b<c | inr x = exFalso (denomA!=0 (Equivalence.symmetric (Setoid.eq S) x))
fieldOfFractionsOrder : SetoidPartialOrder fieldOfFractionsSetoid fieldOfFractionsComparison
SetoidPartialOrder.<WellDefined (fieldOfFractionsOrder) {a} {b} {c} {d} a=b c=d a<c = fieldOfFractionsOrderWellDefinedRight {b} {c} {d} (fieldOfFractionsOrderWellDefinedLeft {a} {c} {b} a<c a=b) c=d
SetoidPartialOrder.irreflexive (fieldOfFractionsOrder) {a} pr = irreflexive a pr
SetoidPartialOrder.<Transitive (fieldOfFractionsOrder) {a} {b} {c} a<b b<c = <transitive a b c a<b b<c
private
<totality : (a b : fieldOfFractionsSet) → ((fieldOfFractionsComparison a b) || (fieldOfFractionsComparison b a)) || (Setoid._∼_ fieldOfFractionsSetoid a b)
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) with totality (Ring.0R R) denomA
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inl 0<denomA) with totality (Ring.0R R) denomB
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inl 0<denomA) | inl (inl 0<denomB) with totality (Ring.0R R) denomA
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inl 0<denomA) | inl (inl 0<denomB) | inl (inl _) with totality (numA * denomB) (numB * denomA)
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inl 0<denomA) | inl (inl 0<denomB) | inl (inl _) | inl (inl x) = inl (inl x)
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inl 0<denomA) | inl (inl 0<denomB) | inl (inl _) | inl (inr x) = inl (inr x)
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inl 0<denomA) | inl (inl 0<denomB) | inl (inl _) | inr x = inr (Equivalence.transitive (Setoid.eq S) x (Ring.*Commutative R))
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inl 0<denomA) | inl (inl 0<denomB) | inl (inr denomA<0) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<denomA denomA<0))
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inl 0<denomA) | inl (inl 0<denomB) | inr x = exFalso (denomA!=0 (Equivalence.symmetric (Setoid.eq S) x))
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inl 0<denomA) | inl (inr denomB<0) with totality (Ring.0R R) denomA
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inl 0<denomA) | inl (inr denomB<0) | inl (inl _) with totality (numB * denomA) (numA * denomB)
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inl 0<denomA) | inl (inr denomB<0) | inl (inl _) | inl (inl x) = inl (inl x)
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inl 0<denomA) | inl (inr denomB<0) | inl (inl _) | inl (inr x) = inl (inr x)
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inl 0<denomA) | inl (inr denomB<0) | inl (inl _) | inr x = inr (Equivalence.symmetric (Setoid.eq S) (Equivalence.transitive (Setoid.eq S) (Ring.*Commutative R) x))
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inl 0<denomA) | inl (inr denomB<0) | inl (inr denomA<0) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<denomA denomA<0))
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inl 0<denomA) | inl (inr denomB<0) | inr x = exFalso (denomA!=0 (Equivalence.symmetric (Setoid.eq S) x))
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inl 0<denomA) | inr x = exFalso (denomB!=0 (Equivalence.symmetric (Setoid.eq S) x))
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inr denomA<0) with totality (Ring.0R R) denomB
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inr denomA<0) | inl (inl 0<denomB) with totality (Ring.0R R) denomA
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inr denomA<0) | inl (inl 0<denomB) | inl (inl 0<denomA) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<denomA denomA<0))
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inr denomA<0) | inl (inl 0<denomB) | inl (inr _) with totality (numB * denomA) (numA * denomB)
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inr denomA<0) | inl (inl 0<denomB) | inl (inr _) | inl (inl x) = inl (inl x)
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inr denomA<0) | inl (inl 0<denomB) | inl (inr _) | inl (inr x) = inl (inr x)
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inr denomA<0) | inl (inl 0<denomB) | inl (inr _) | inr x = inr (Equivalence.transitive (Setoid.eq S) (Equivalence.symmetric (Setoid.eq S) x) (Ring.*Commutative R))
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inr denomA<0) | inl (inl 0<denomB) | inr x = exFalso (denomA!=0 (Equivalence.symmetric (Setoid.eq S) x))
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inr denomA<0) | inl (inr denomB<0) with totality (Ring.0R R) denomA
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inr denomA<0) | inl (inr denomB<0) | inl (inl 0<denomA) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<denomA denomA<0))
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inr denomA<0) | inl (inr denomB<0) | inl (inr _) with totality (numA * denomB) (numB * denomA)
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inr denomA<0) | inl (inr denomB<0) | inl (inr _) | inl (inl x) = inl (inl x)
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inr denomA<0) | inl (inr denomB<0) | inl (inr _) | inl (inr x) = inl (inr x)
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inr denomA<0) | inl (inr denomB<0) | inl (inr _) | inr x = inr (Equivalence.transitive (Setoid.eq S) x (Ring.*Commutative R))
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inr denomA<0) | inl (inr denomB<0) | inr x = exFalso (denomA!=0 (Equivalence.symmetric (Setoid.eq S) x))
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inl (inr denomA<0) | inr x = exFalso (denomB!=0 (Equivalence.symmetric (Setoid.eq S) x))
<totality (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) | inr x = exFalso (denomA!=0 (Equivalence.symmetric (Setoid.eq S) x))
fieldOfFractionsTotalOrder : SetoidTotalOrder fieldOfFractionsOrder
SetoidTotalOrder.totality (fieldOfFractionsTotalOrder) x y = <totality x y
private
abstract
ineqLemma : {x y : A} → (Ring.0R R) < (x * y) → (Ring.0R R) < x → (Ring.0R R) < y
ineqLemma {x} {y} 0<xy 0<x with totality (Ring.0R R) y
ineqLemma {x} {y} 0<xy 0<x | inl (inl 0<y) = 0<y
ineqLemma {x} {y} 0<xy 0<x | inl (inr y<0) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<xy (SetoidPartialOrder.<WellDefined pOrder reflexive (transitive *Commutative (Ring.timesZero R)) (ringCanMultiplyByNegative pRing y<0 0<x))))
ineqLemma {x} {y} 0<xy 0<x | inr 0=y = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<WellDefined pOrder reflexive (transitive (*WellDefined reflexive (symmetric 0=y)) (Ring.timesZero R)) 0<xy))
ineqLemma' : {x y : A} → (Ring.0R R) < (x * y) → x < (Ring.0R R) → y < (Ring.0R R)
ineqLemma' {x} {y} 0<xy x<0 with totality (Ring.0R R) y
... | inl (inl 0<y) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<xy (SetoidPartialOrder.<WellDefined pOrder *Commutative (transitive *Commutative (Ring.timesZero R)) (ringCanMultiplyByNegative pRing x<0 0<y))))
... | inl (inr y<0) = y<0
... | (inr 0=y) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<WellDefined pOrder reflexive (transitive (*WellDefined reflexive (symmetric 0=y)) (Ring.timesZero R)) 0<xy))
ineqLemma'' : {x y : A} → (x * y) < (Ring.0R R) → (Ring.0R R) < x → y < (Ring.0R R)
ineqLemma'' {x} {y} xy<0 0<x with totality (Ring.0R R) y
... | inl (inl 0<y) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder xy<0 (orderRespectsMultiplication 0<x 0<y)))
... | inl (inr y<0) = y<0
... | (inr 0=y) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<WellDefined pOrder (transitive (*WellDefined reflexive (symmetric 0=y)) (Ring.timesZero R)) reflexive xy<0))
ineqLemma''' : {x y : A} → (x * y) < (Ring.0R R) → x < (Ring.0R R) → (Ring.0R R) < y
ineqLemma''' {x} {y} xy<0 x<0 with totality (Ring.0R R) y
... | inl (inl 0<y) = 0<y
... | inl (inr y<0) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder xy<0 (SetoidPartialOrder.<WellDefined pOrder (transitive *Commutative (Ring.timesZero R)) reflexive (ringCanMultiplyByNegative pRing y<0 x<0))))
... | inr 0=y = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<WellDefined pOrder (transitive (*WellDefined reflexive (symmetric 0=y)) (Ring.timesZero R)) reflexive xy<0))
private
<orderRespectsAddition : (a b : fieldOfFractionsSet) (a<b : fieldOfFractionsComparison a b) (c : fieldOfFractionsSet) → fieldOfFractionsComparison (fieldOfFractionsPlus a c) (fieldOfFractionsPlus b c)
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) with totality (Ring.0R R) (denomA * denomC)
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inl 0<dAdC) with totality (Ring.0R R) (denomB * denomC)
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inl 0<dAdC) | inl (inl 0<dBdC) with totality (Ring.0R R) denomA
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inl 0<dAdC) | inl (inl 0<dBdC) | inl (inl 0<dA) with totality (Ring.0R R) denomB
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inl 0<dAdC) | inl (inl 0<dBdC) | inl (inl 0<dA) | inl (inl 0<dB) = SetoidPartialOrder.<WellDefined pOrder (symmetric *Associative) (symmetric *Associative) (ringCanMultiplyByPositive pRing 0<dC (SetoidPartialOrder.<WellDefined pOrder (transitive (Group.+WellDefined additiveGroup *Commutative *Commutative) (transitive (symmetric *DistributesOver+) *Commutative)) (transitive (Group.+WellDefined additiveGroup *Commutative *Commutative) (transitive (symmetric *DistributesOver+) *Commutative)) (SetoidPartialOrder.<WellDefined pOrder reflexive (Group.+WellDefined additiveGroup reflexive (transitive (*WellDefined *Commutative reflexive) (transitive (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) (*WellDefined *Commutative reflexive)))) (PartiallyOrderedRing.orderRespectsAddition pRing (SetoidPartialOrder.<WellDefined pOrder (swapLemma) (swapLemma) (ringCanMultiplyByPositive pRing 0<dC a<b)) ((denomA * numC) * denomB)))))
where
0<dC : 0R < denomC
0<dC with totality 0R denomC
0<dC | inl (inl x) = x
0<dC | inl (inr dC<0) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<dBdC (SetoidPartialOrder.<WellDefined pOrder reflexive (transitive *Commutative (Ring.timesZero R)) (ringCanMultiplyByNegative pRing dC<0 0<dB))))
0<dC | inr x = exFalso (denomC!=0 (Equivalence.symmetric (Setoid.eq S) x))
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inl 0<dAdC) | inl (inl 0<dBdC) | inl (inl 0<dA) | inl (inr dB<0) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<dAdC (SetoidPartialOrder.<WellDefined pOrder reflexive (transitive *Commutative (Ring.timesZero R)) (ringCanMultiplyByNegative pRing dC<0 0<dA))))
where
dC<0 : denomC < 0R
dC<0 with totality 0R denomC
... | inl (inl x) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<dBdC (SetoidPartialOrder.<WellDefined pOrder reflexive (transitive *Commutative (Ring.timesZero R)) (ringCanMultiplyByPositive pRing x dB<0))))
... | inl (inr x) = x
... | inr x = exFalso (denomC!=0 (Equivalence.symmetric (Setoid.eq S) x))
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inl 0<dAdC) | inl (inl 0<dBdC) | inl (inl 0<dA) | inr x = exFalso (denomB!=0 (Equivalence.symmetric (Setoid.eq S) x))
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inl 0<dAdC) | inl (inl 0<dBdC) | inl (inr dA<0) with totality (Ring.0R R) denomB
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inl 0<dAdC) | inl (inl 0<dBdC) | inl (inr dA<0) | inl (inl 0<dB) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<dC dC<0))
where
0<dC : 0R < denomC
0<dC with totality 0R denomC
0<dC | inl (inl x) = x
0<dC | inl (inr dC<0) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<dBdC (SetoidPartialOrder.<WellDefined pOrder reflexive (transitive *Commutative (Ring.timesZero R)) (ringCanMultiplyByNegative pRing dC<0 0<dB))))
0<dC | inr x = exFalso (denomC!=0 (Equivalence.symmetric (Setoid.eq S) x))
dC<0 : denomC < 0R
dC<0 with totality 0R denomC
dC<0 | inl (inl 0<dC) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<dAdC (SetoidPartialOrder.<WellDefined pOrder *Commutative (transitive *Commutative (Ring.timesZero R)) (ringCanMultiplyByNegative pRing dA<0 0<dC))))
dC<0 | inl (inr x) = x
dC<0 | inr x = exFalso (denomC!=0 (Equivalence.symmetric (Setoid.eq S) x))
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inl 0<dAdC) | inl (inl 0<dBdC) | inl (inr dA<0) | inl (inr dB<0) = SetoidPartialOrder.<WellDefined pOrder (symmetric *Associative) (symmetric *Associative) (ringCanMultiplyByNegative pRing dC<0 (SetoidPartialOrder.<WellDefined pOrder (transitive (symmetric *DistributesOver+) *Commutative) (transitive (symmetric *DistributesOver+) *Commutative) have''))
where
dC<0 : denomC < 0R
dC<0 = ineqLemma' 0<dAdC dA<0
have : ((numB * denomA) * denomC) < ((numA * denomB) * denomC)
have = ringCanMultiplyByNegative pRing dC<0 a<b
have' : (denomA * (numB * denomC)) < (denomB * (numA * denomC))
have' = SetoidPartialOrder.<WellDefined pOrder (transitive (*WellDefined *Commutative reflexive) (symmetric *Associative)) (transitive (*WellDefined *Commutative reflexive) (symmetric *Associative)) have
have'' : ((denomA * (numB * denomC)) + (denomA * (denomB * numC))) < ((denomB * (numA * denomC)) + (denomB * (denomA * numC)))
have'' = SetoidPartialOrder.<WellDefined pOrder reflexive (Group.+WellDefined additiveGroup reflexive (transitive *Associative (transitive (*WellDefined *Commutative reflexive) (symmetric *Associative)))) (PartiallyOrderedRing.orderRespectsAddition pRing have' (denomA * (denomB * numC)))
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inl 0<dAdC) | inl (inl 0<dBdC) | inl (inr dA<0) | inr x = exFalso (denomB!=0 (Equivalence.symmetric (Setoid.eq S) x))
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inl 0<dAdC) | inl (inl 0<dBdC) | inr x = exFalso (denomA!=0 (Equivalence.symmetric (Setoid.eq S) x))
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inl 0<dAdC) | inl (inr dBdC<0) with totality (Ring.0R R) denomA
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inl 0<dAdC) | inl (inr dBdC<0) | inl (inl 0<dA) with totality (Ring.0R R) denomB
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inl 0<dAdC) | inl (inr dBdC<0) | inl (inl 0<dA) | inl (inl 0<dB) = exFalso bad
where
0<dC : 0R < denomC
0<dC = ineqLemma 0<dAdC 0<dA
dC<0 : denomC < 0R
dC<0 = ineqLemma'' dBdC<0 0<dB
bad : False
bad = SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<dC dC<0)
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inl 0<dAdC) | inl (inr dBdC<0) | inl (inl 0<dA) | inl (inr dB<0) = SetoidPartialOrder.<WellDefined pOrder (symmetric *Associative) (symmetric *Associative) (ringCanMultiplyByPositive pRing 0<dC ans)
where
0<dC : 0R < denomC
0<dC = ineqLemma 0<dAdC 0<dA
have : ((numB * denomA) * denomC) < ((numA * denomB) * denomC)
have = ringCanMultiplyByPositive pRing 0<dC a<b
have' : (((numB * denomC) * denomA) + ((denomB * numC) * denomA)) < (((numA * denomC) * denomB) + ((denomB * numC) * denomA))
have' = PartiallyOrderedRing.orderRespectsAddition pRing (SetoidPartialOrder.<WellDefined pOrder (swapLemma) (swapLemma) have) _
ans : (((numB * denomC) + (denomB * numC)) * denomA) < (((numA * denomC) + (denomA * numC)) * denomB)
ans = SetoidPartialOrder.<WellDefined pOrder (transitive (Group.+WellDefined additiveGroup *Commutative *Commutative) (transitive (symmetric *DistributesOver+) *Commutative)) (transitive (Group.+WellDefined additiveGroup *Commutative (transitive (symmetric *Associative) (*WellDefined reflexive *Commutative))) (transitive (symmetric *DistributesOver+) *Commutative)) have'
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inl 0<dAdC) | inl (inr dBdC<0) | inl (inl 0<dA) | inr x = exFalso (denomB!=0 (Equivalence.symmetric (Setoid.eq S) x))
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inl 0<dAdC) | inl (inr dBdC<0) | inl (inr dA<0) with totality (Ring.0R R) denomB
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inl 0<dAdC) | inl (inr dBdC<0) | inl (inr dA<0) | inl (inl 0<dB) = SetoidPartialOrder.<WellDefined pOrder (symmetric *Associative) (symmetric *Associative) (ringCanMultiplyByNegative pRing dC<0 (SetoidPartialOrder.<WellDefined pOrder (transitive (Group.+WellDefined additiveGroup *Commutative *Commutative) (transitive (transitive (Group.+WellDefined additiveGroup reflexive (transitive *Associative (transitive (*WellDefined *Commutative reflexive) (symmetric *Associative)))) (symmetric *DistributesOver+)) *Commutative)) (transitive (Group.+WellDefined additiveGroup *Commutative *Commutative) (transitive (symmetric *DistributesOver+) *Commutative)) have))
where
dC<0 : denomC < 0R
dC<0 = ineqLemma'' dBdC<0 0<dB
have : (((numA * denomC) * denomB) + ((denomB * numC) * denomA)) < (((numB * denomC) * denomA) + ((denomB * numC) * denomA))
have = PartiallyOrderedRing.orderRespectsAddition pRing (SetoidPartialOrder.<WellDefined pOrder (swapLemma) (swapLemma) (ringCanMultiplyByNegative pRing dC<0 a<b)) _
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inl 0<dAdC) | inl (inr dBdC<0) | inl (inr dA<0) | inl (inr dB<0) = exFalso bad
where
dC<0 : denomC < 0R
dC<0 = ineqLemma' 0<dAdC dA<0
0<dC : 0R < denomC
0<dC = ineqLemma''' dBdC<0 dB<0
bad : False
bad = SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<dC dC<0)
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inl 0<dAdC) | inl (inr dBdC<0) | inl (inr dA<0) | inr x = exFalso (denomB!=0 (Equivalence.symmetric (Setoid.eq S) x))
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inl 0<dAdC) | inl (inr dBdC<0) | inr x = exFalso (denomA!=0 (Equivalence.symmetric (Setoid.eq S) x))
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inl 0<dAdC) | inr 0=dBdC with IntegralDomain.intDom I (Equivalence.symmetric (Setoid.eq S) 0=dBdC)
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inl 0<dAdC) | inr 0=dBdC | f = exFalso (denomC!=0 (f denomB!=0))
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inr dAdC<0) with totality (Ring.0R R) (denomB * denomC)
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inr dAdC<0) | inl (inl 0<dBdC) with totality (Ring.0R R) denomA
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inr dAdC<0) | inl (inl 0<dBdC) | inl (inl 0<dA) with totality (Ring.0R R) denomB
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inr dAdC<0) | inl (inl 0<dBdC) | inl (inl 0<dA) | inl (inl 0<dB) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<dC dC<0))
where
0<dC : 0R < denomC
0<dC = ineqLemma 0<dBdC 0<dB
dC<0 : denomC < 0R
dC<0 = ineqLemma'' dAdC<0 0<dA
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inr dAdC<0) | inl (inl 0<dBdC) | inl (inl 0<dA) | inl (inr dB<0) = SetoidPartialOrder.<WellDefined pOrder (symmetric *Associative) (symmetric *Associative) (ringCanMultiplyByNegative pRing dC<0 (SetoidPartialOrder.<WellDefined pOrder (transitive (Group.+WellDefined additiveGroup (transitive (*WellDefined *Commutative reflexive) (symmetric *Associative)) *Commutative) (transitive (symmetric *DistributesOver+) *Commutative)) (transitive (Group.+WellDefined additiveGroup (transitive (*WellDefined *Commutative reflexive) (symmetric *Associative)) (transitive (symmetric *Associative) (*WellDefined reflexive *Commutative))) (transitive (symmetric *DistributesOver+) *Commutative)) have))
where
dC<0 : denomC < 0R
dC<0 = ineqLemma'' dAdC<0 0<dA
have : (((numA * denomB) * denomC) + ((denomA * numC) * denomB)) < (((numB * denomA) * denomC) + ((denomA * numC) * denomB))
have = PartiallyOrderedRing.orderRespectsAddition pRing (ringCanMultiplyByNegative pRing dC<0 a<b) _
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inr dAdC<0) | inl (inl 0<dBdC) | inl (inl 0<dA) | inr 0=dB = exFalso (denomB!=0 (Equivalence.symmetric (Setoid.eq S) 0=dB))
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inr dAdC<0) | inl (inl 0<dBdC) | inl (inr dA<0) with totality (Ring.0R R) denomB
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inr dAdC<0) | inl (inl 0<dBdC) | inl (inr dA<0) | inl (inl 0<dB) = SetoidPartialOrder.<WellDefined pOrder (symmetric *Associative) (symmetric *Associative) (ringCanMultiplyByPositive pRing 0<dC (SetoidPartialOrder.<WellDefined pOrder (transitive (Group.+WellDefined additiveGroup *Commutative *Commutative) (transitive (transitive (Group.+WellDefined additiveGroup (transitive *Commutative (transitive (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) *Commutative)) (transitive *Associative (transitive (*WellDefined *Commutative reflexive) (symmetric *Associative)))) (symmetric *DistributesOver+)) *Commutative)) (transitive (Group.+WellDefined additiveGroup *Commutative *Commutative) (transitive (transitive (Group.+WellDefined additiveGroup (transitive *Commutative (transitive (*WellDefined *Commutative reflexive) (symmetric *Associative))) reflexive) (symmetric *DistributesOver+)) *Commutative)) have))
where
0<dC : 0R < denomC
0<dC = ineqLemma 0<dBdC 0<dB
have : (((numB * denomA) * denomC) + ((denomA * numC) * denomB)) < (((numA * denomB) * denomC) + ((denomA * numC) * denomB))
have = PartiallyOrderedRing.orderRespectsAddition pRing (ringCanMultiplyByPositive pRing 0<dC a<b) _
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inr dAdC<0) | inl (inl 0<dBdC) | inl (inr dA<0) | inl (inr dB<0) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<dC dC<0))
where
dC<0 : denomC < 0R
dC<0 = ineqLemma' 0<dBdC dB<0
0<dC : 0R < denomC
0<dC = ineqLemma''' dAdC<0 dA<0
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inr dAdC<0) | inl (inl 0<dBdC) | inl (inr dA<0) | inr 0=dB = exFalso (denomB!=0 (Equivalence.symmetric (Setoid.eq S) 0=dB))
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inr dAdC<0) | inl (inl 0<dBdC) | inr 0=dA = exFalso (denomA!=0 (Equivalence.symmetric (Setoid.eq S) 0=dA))
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inr dAdC<0) | inl (inr dBdC<0) with totality (Ring.0R R) denomA
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inr dAdC<0) | inl (inr dBdC<0) | inl (inl 0<dA) with totality (Ring.0R R) denomB
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inr dAdC<0) | inl (inr dBdC<0) | inl (inl 0<dA) | inl (inl 0<dB) = SetoidPartialOrder.<WellDefined pOrder (symmetric *Associative) (symmetric *Associative) (ringCanMultiplyByNegative pRing dC<0 (SetoidPartialOrder.<WellDefined pOrder (transitive (transitive (Group.+WellDefined additiveGroup *Commutative *Commutative) (Group.+WellDefined additiveGroup (transitive *Commutative (transitive (*WellDefined *Commutative reflexive) (symmetric *Associative))) reflexive)) (transitive (symmetric *DistributesOver+) *Commutative)) (transitive (transitive (Group.+WellDefined additiveGroup *Commutative *Commutative) (Group.+WellDefined additiveGroup (transitive (transitive *Associative (*WellDefined *Commutative reflexive)) *Commutative) (transitive *Associative (transitive (*WellDefined *Commutative reflexive) (symmetric *Associative))))) (transitive (symmetric *DistributesOver+) *Commutative)) have))
where
dC<0 : denomC < 0R
dC<0 = ineqLemma'' dAdC<0 0<dA
have : (((numB * denomA) * denomC) + ((denomB * numC) * denomA)) < (((numA * denomB) * denomC) + ((denomB * numC) * denomA))
have = PartiallyOrderedRing.orderRespectsAddition pRing (ringCanMultiplyByNegative pRing dC<0 a<b) _
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inr dAdC<0) | inl (inr dBdC<0) | inl (inl 0<dA) | inl (inr dB<0) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder dC<0 0<dC))
where
dC<0 : denomC < 0R
dC<0 = ineqLemma'' dAdC<0 0<dA
0<dC : 0R < denomC
0<dC = ineqLemma''' dBdC<0 dB<0
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inr dAdC<0) | inl (inr dBdC<0) | inl (inl 0<dA) | inr x = exFalso (denomB!=0 (Equivalence.symmetric (Setoid.eq S) x))
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inr dAdC<0) | inl (inr dBdC<0) | inl (inr dA<0) with totality (Ring.0R R) denomB
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inr dAdC<0) | inl (inr dBdC<0) | inl (inr dA<0) | inl (inl 0<dB) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<dC dC<0))
where
0<dC : 0R < denomC
0<dC = ineqLemma''' dAdC<0 dA<0
dC<0 : denomC < 0R
dC<0 = ineqLemma'' dBdC<0 0<dB
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inr dAdC<0) | inl (inr dBdC<0) | inl (inr dA<0) | inl (inr dB<0) = SetoidPartialOrder.<WellDefined pOrder (symmetric *Associative) (symmetric *Associative) (ringCanMultiplyByPositive pRing 0<dC (SetoidPartialOrder.<WellDefined pOrder (transitive (Group.+WellDefined additiveGroup *Commutative *Commutative) (transitive (Group.+WellDefined additiveGroup (transitive *Commutative (transitive (*WellDefined *Commutative reflexive) (symmetric *Associative))) reflexive) (transitive (symmetric *DistributesOver+) *Commutative))) (transitive (Group.+WellDefined additiveGroup *Commutative *Commutative) (transitive (transitive (Group.+WellDefined additiveGroup (transitive *Commutative (transitive (*WellDefined *Commutative reflexive) (symmetric *Associative))) (transitive *Commutative (transitive (symmetric *Associative) (*WellDefined reflexive *Commutative)))) (symmetric *DistributesOver+)) *Commutative)) have))
where
0<dC : 0R < denomC
0<dC = ineqLemma''' dAdC<0 dA<0
have : (((numA * denomB) * denomC) + ((denomA * numC) * denomB)) < (((numB * denomA) * denomC) + ((denomA * numC) * denomB))
have = PartiallyOrderedRing.orderRespectsAddition pRing (ringCanMultiplyByPositive pRing 0<dC a<b) _
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inr dAdC<0) | inl (inr dBdC<0) | inl (inr dA<0) | inr x = exFalso (denomB!=0 (Equivalence.symmetric (Setoid.eq S) x))
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inr dAdC<0) | inl (inr dBdC<0) | inr x = exFalso (denomA!=0 (Equivalence.symmetric (Setoid.eq S) x))
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inl (inr dAdC<0) | inr 0=dBdC with IntegralDomain.intDom I (Equivalence.symmetric (Setoid.eq S) 0=dBdC)
... | f = exFalso (denomC!=0 (f denomB!=0))
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inr (0=dAdC) with IntegralDomain.intDom I (Equivalence.symmetric (Setoid.eq S) 0=dAdC)
<orderRespectsAddition (record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }) (record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }) a<b (record { num = numC ; denom = denomC ; denomNonzero = denomC!=0 }) | inr 0=dAdC | f = exFalso (denomC!=0 (f denomA!=0))
private
<RespectsMultiplication : {a b : fieldOfFractionsSet} → fieldOfFractionsComparison (Ring.0R fieldOfFractionsRing) a → fieldOfFractionsComparison (Ring.0R fieldOfFractionsRing) b → fieldOfFractionsComparison (Ring.0R fieldOfFractionsRing) (fieldOfFractionsTimes a b)
<RespectsMultiplication {record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }} {record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }} t u with totality (Ring.0R R) (Ring.1R R)
<RespectsMultiplication {record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }} {record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }} 0<a 0<b | inl (inl 0<1) with totality (Ring.0R R) (denomA * denomB)
<RespectsMultiplication {record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }} {record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }} 0<a 0<b | inl (inl 0<1) | inl (inl 0<dAdB) with totality (Ring.0R R) denomB
<RespectsMultiplication {record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }} {record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }} 0<a 0<b | inl (inl 0<1) | inl (inl 0<dAdB) | inl (inl 0<dB) with totality (Ring.0R R) denomA
<RespectsMultiplication {record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }} {record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }} 0<a 0<b | inl (inl 0<1) | inl (inl 0<dAdB) | inl (inl 0<dB) | inl (inl 0<dA) = SetoidPartialOrder.<WellDefined pOrder (symmetric (transitive *Commutative (Ring.timesZero R))) (symmetric (transitive *Commutative identIsIdent)) (SetoidPartialOrder.<WellDefined pOrder (transitive *Commutative (Ring.timesZero R)) reflexive (ringCanMultiplyByPositive pRing (SetoidPartialOrder.<WellDefined pOrder (transitive *Commutative (Ring.timesZero R)) (transitive *Commutative identIsIdent) 0<b) (SetoidPartialOrder.<WellDefined pOrder (transitive *Commutative (Ring.timesZero R)) (transitive *Commutative identIsIdent) 0<a)))
<RespectsMultiplication {record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }} {record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }} 0<a 0<b | inl (inl 0<1) | inl (inl 0<dAdB) | inl (inl 0<dB) | inl (inr dA<0) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<dAdB (SetoidPartialOrder.<WellDefined pOrder *Commutative (transitive *Commutative (Ring.timesZero R)) (ringCanMultiplyByNegative pRing dA<0 0<dB))))
<RespectsMultiplication {record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }} {record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }} 0<a 0<b | inl (inl 0<1) | inl (inl 0<dAdB) | inl (inl 0<dB) | inr x = exFalso (denomA!=0 (Equivalence.symmetric (Setoid.eq S) x))
<RespectsMultiplication {record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }} {record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }} 0<a 0<b | inl (inl 0<1) | inl (inl 0<dAdB) | inl (inr dB<0) with totality (Ring.0R R) denomA
<RespectsMultiplication {record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }} {record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }} 0<a 0<b | inl (inl 0<1) | inl (inl 0<dAdB) | inl (inr dB<0) | inl (inl 0<dA) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<dAdB (SetoidPartialOrder.<WellDefined pOrder reflexive (transitive *Commutative (Ring.timesZero R)) (ringCanMultiplyByNegative pRing dB<0 0<dA))))
<RespectsMultiplication {record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }} {record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }} 0<a 0<b | inl (inl 0<1) | inl (inl 0<dAdB) | inl (inr dB<0) | inl (inr dA<0) = SetoidPartialOrder.<WellDefined pOrder (symmetric (transitive *Commutative (Ring.timesZero R))) (symmetric (transitive *Commutative identIsIdent)) (SetoidPartialOrder.<WellDefined pOrder (transitive *Commutative (Ring.timesZero R)) *Commutative (ringCanMultiplyByNegative pRing (SetoidPartialOrder.<WellDefined pOrder (transitive *Commutative identIsIdent) (transitive *Commutative (Ring.timesZero R)) 0<a) (SetoidPartialOrder.<WellDefined pOrder (transitive *Commutative identIsIdent) (transitive *Commutative (Ring.timesZero R)) 0<b)))
<RespectsMultiplication {record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }} {record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }} 0<a 0<b | inl (inl 0<1) | inl (inl 0<dAdB) | inl (inr dB<0) | inr x = exFalso (denomA!=0 (Equivalence.symmetric (Setoid.eq S) x))
<RespectsMultiplication {record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }} {record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }} 0<a 0<b | inl (inl 0<1) | inl (inl 0<dAdB) | inr x = exFalso (denomB!=0 (Equivalence.symmetric (Setoid.eq S) x))
<RespectsMultiplication {record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }} {record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }} 0<a 0<b | inl (inl 0<1) | inl (inr dAdB<0) with totality (Ring.0R R) denomB
<RespectsMultiplication {record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }} {record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }} 0<a 0<b | inl (inl 0<1) | inl (inr dAdB<0) | inl (inl 0<denomB) with totality (Ring.0R R) denomA
<RespectsMultiplication {record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }} {record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }} 0<a 0<b | inl (inl 0<1) | inl (inr dAdB<0) | inl (inl 0<denomB) | inl (inl 0<denomA) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder (PartiallyOrderedRing.orderRespectsMultiplication pRing 0<denomA 0<denomB) dAdB<0))
<RespectsMultiplication {record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }} {record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }} 0<a 0<b | inl (inl 0<1) | inl (inr dAdB<0) | inl (inl 0<denomB) | inl (inr denomA<0) = SetoidPartialOrder.<WellDefined pOrder (symmetric (transitive *Commutative identIsIdent)) (symmetric (transitive *Commutative (Ring.timesZero R))) (SetoidPartialOrder.<WellDefined pOrder *Commutative (transitive *Commutative (Ring.timesZero R)) (ringCanMultiplyByNegative pRing (SetoidPartialOrder.<WellDefined pOrder (transitive *Commutative identIsIdent) (transitive *Commutative (Ring.timesZero R)) 0<a) (SetoidPartialOrder.<WellDefined pOrder (transitive *Commutative (Ring.timesZero R)) (transitive *Commutative identIsIdent) 0<b)))
<RespectsMultiplication {record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }} {record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }} 0<a 0<b | inl (inl 0<1) | inl (inr dAdB<0) | inl (inl 0<denomB) | inr x = exFalso (denomA!=0 (Equivalence.symmetric (Setoid.eq S) x))
<RespectsMultiplication {record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }} {record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }} 0<a 0<b | inl (inl 0<1) | inl (inr dAdB<0) | inl (inr denomB<0) with totality (Ring.0R R) denomA
<RespectsMultiplication {record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }} {record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }} 0<a 0<b | inl (inl 0<1) | inl (inr dAdB<0) | inl (inr denomB<0) | inl (inl 0<denomA) = SetoidPartialOrder.<WellDefined pOrder (symmetric (transitive *Commutative identIsIdent)) (symmetric (transitive *Commutative (Ring.timesZero R))) (SetoidPartialOrder.<WellDefined pOrder reflexive (transitive *Commutative (Ring.timesZero R)) (ringCanMultiplyByNegative pRing (SetoidPartialOrder.<WellDefined pOrder (transitive *Commutative identIsIdent) (transitive *Commutative (Ring.timesZero R)) 0<b) (SetoidPartialOrder.<WellDefined pOrder (transitive *Commutative (Ring.timesZero R)) (transitive *Commutative identIsIdent) 0<a)))
<RespectsMultiplication {record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }} {record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }} 0<a 0<b | inl (inl 0<1) | inl (inr dAdB<0) | inl (inr denomB<0) | inl (inr denomA<0) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder dAdB<0 (SetoidPartialOrder.<WellDefined pOrder (transitive *Commutative (Ring.timesZero R)) reflexive (ringCanMultiplyByNegative pRing denomB<0 denomA<0))))
<RespectsMultiplication {record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }} {record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }} 0<a 0<b | inl (inl 0<1) | inl (inr dAdB<0) | inl (inr denomB<0) | inr x = exFalso (denomA!=0 (Equivalence.symmetric (Setoid.eq S) x))
<RespectsMultiplication {record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }} {record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }} 0<a 0<b | inl (inl 0<1) | inl (inr dAdB<0) | inr x = exFalso (denomB!=0 (Equivalence.symmetric (Setoid.eq S) x))
<RespectsMultiplication {record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }} {record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }} 0<a 0<b | inl (inl 0<1) | inr 0=dAdB = exFalso (denomB!=0 (IntegralDomain.intDom I (Equivalence.symmetric (Setoid.eq S) 0=dAdB) denomA!=0))
<RespectsMultiplication {record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }} {record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }} 0<a 0<b | inl (inr 1<0) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 1<0 (SetoidPartialOrder.<WellDefined pOrder (transitive *Commutative (Ring.timesZero R)) identIsIdent (ringCanMultiplyByNegative pRing 1<0 1<0))))
<RespectsMultiplication {record { num = numA ; denom = denomA ; denomNonzero = denomA!=0 }} {record { num = numB ; denom = denomB ; denomNonzero = denomB!=0 }} 0<a 0<b | inr x = exFalso (IntegralDomain.nontrivial I (Equivalence.symmetric (Setoid.eq S) x))
fieldOfFractionsPOrderedRing : PartiallyOrderedRing fieldOfFractionsRing (SetoidTotalOrder.partial fieldOfFractionsTotalOrder)
PartiallyOrderedRing.orderRespectsAddition fieldOfFractionsPOrderedRing {a} {b} a<b c = <orderRespectsAddition a b a<b c
PartiallyOrderedRing.orderRespectsMultiplication fieldOfFractionsPOrderedRing {a} {b} 0<a 0<b = <RespectsMultiplication {a} {b} 0<a 0<b
fieldOfFractionsOrderedRing : TotallyOrderedRing fieldOfFractionsPOrderedRing
TotallyOrderedRing.total fieldOfFractionsOrderedRing = fieldOfFractionsTotalOrder
private
fieldOfFractionsOrderInherited' : {x y : A} → x < y → fieldOfFractionsComparison (embedIntoFieldOfFractions x) (embedIntoFieldOfFractions y)
fieldOfFractionsOrderInherited' {x} {y} x<y with totality 0R 1R
fieldOfFractionsOrderInherited' {x} {y} x<y | inl (inl 0<1) with totality 0R 1R
fieldOfFractionsOrderInherited' {x} {y} x<y | inl (inl 0<1) | inl (inl _) = SetoidPartialOrder.<WellDefined pOrder (symmetric (transitive *Commutative identIsIdent)) (symmetric (transitive *Commutative identIsIdent)) x<y
fieldOfFractionsOrderInherited' {x} {y} x<y | inl (inl 0<1) | inl (inr 1<0) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder 0<1 1<0))
fieldOfFractionsOrderInherited' {x} {y} x<y | inl (inl 0<1) | inr 0=1 = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<WellDefined pOrder 0=1 reflexive 0<1))
fieldOfFractionsOrderInherited' {x} {y} x<y | inl (inr 1<0) = exFalso (1<0False order 1<0)
fieldOfFractionsOrderInherited' {x} {y} x<y | inr 0=1 = exFalso (anyComparisonImpliesNontrivial pRing x<y 0=1)
fieldOfFractionsOrderInherited : {x y : A} → x < y → fieldOfFractionsComparison (embedIntoFieldOfFractions x) (embedIntoFieldOfFractions y)
fieldOfFractionsOrderInherited {x} {y} x<y = fieldOfFractionsOrderInherited' {x} {y} x<y
| {
"alphanum_fraction": 0.6861608011,
"avg_line_length": 215.4630738523,
"ext": "agda",
"hexsha": "f830c86e2bd5980bcc2cf77919e62a8df1d92d3b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Fields/FieldOfFractions/Order.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Fields/FieldOfFractions/Order.agda",
"max_line_length": 1221,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Fields/FieldOfFractions/Order.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 38002,
"size": 107947
} |
-- 2010-10-02, see issue 334
module TerminationInfiniteRecord where
record Empty : Set where
inductive
constructor empty
field
fromEmpty : Empty
elimEmpty : Empty -> Set
elimEmpty (empty e) = elimEmpty e
-- this no longer termination checks
-- and it should not, since it is translated to
-- elimEmpty e' = elimEmpty (fromEmpty e')
| {
"alphanum_fraction": 0.7312138728,
"avg_line_length": 20.3529411765,
"ext": "agda",
"hexsha": "2287ab5653500353be0cebfeb8c85251e4713d2a",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "hborum/agda",
"max_forks_repo_path": "test/Fail/TerminationInfiniteRecord.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "hborum/agda",
"max_issues_repo_path": "test/Fail/TerminationInfiniteRecord.agda",
"max_line_length": 47,
"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/TerminationInfiniteRecord.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": 95,
"size": 346
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Implications of nullary relations
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Nullary.Implication where
open import Relation.Nullary
open import Data.Empty
-- Some properties which are preserved by _→_.
infixr 2 _→-dec_
_→-dec_ : ∀ {p q} {P : Set p} {Q : Set q} →
Dec P → Dec Q → Dec (P → Q)
yes p →-dec no ¬q = no (λ f → ¬q (f p))
yes p →-dec yes q = yes (λ _ → q)
no ¬p →-dec _ = yes (λ p → ⊥-elim (¬p p))
| {
"alphanum_fraction": 0.4554294976,
"avg_line_length": 26.8260869565,
"ext": "agda",
"hexsha": "c51f085ccd9a85d570391448ad8b05dfbbb740ea",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Relation/Nullary/Implication.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Relation/Nullary/Implication.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/Relation/Nullary/Implication.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 165,
"size": 617
} |
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module LogicalFramework.UniversalQuantifier where
postulate D : Set
-- The universal quantifier type on D.
data ForAll (A : D → Set) : Set where
dfun : ((t : D) → A t) → ForAll A
dapp : {A : D → Set}(t : D) → ForAll A → A t
dapp t (dfun f) = f t
| {
"alphanum_fraction": 0.5613207547,
"avg_line_length": 26.5,
"ext": "agda",
"hexsha": "0884a22b6bebf20f19b5d7fc1edddc55417a65e5",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/thesis/report/LogicalFramework/UniversalQuantifier.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "notes/thesis/report/LogicalFramework/UniversalQuantifier.agda",
"max_line_length": 49,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "notes/thesis/report/LogicalFramework/UniversalQuantifier.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": 122,
"size": 424
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- An alternative definition of mutually-defined lists and non-empty
-- lists, using the Kleene star and plus.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Kleene where
------------------------------------------------------------------------
-- Types and basic operations
open import Data.List.Kleene.Base public
| {
"alphanum_fraction": 0.4163346614,
"avg_line_length": 31.375,
"ext": "agda",
"hexsha": "571f29542df1a855b804784faf8afe3cffbd5bbb",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/List/Kleene.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/List/Kleene.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/List/Kleene.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": 69,
"size": 502
} |
{-# OPTIONS --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Substitution.Introductions.IdRefl {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped
open import Definition.Untyped.Properties
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.LogicalRelation
open import Definition.LogicalRelation.Irrelevance
open import Definition.LogicalRelation.Properties
open import Definition.LogicalRelation.Substitution
open import Definition.LogicalRelation.Substitution.Properties
open import Definition.LogicalRelation.Substitution.Conversion
open import Definition.LogicalRelation.Substitution.Reduction
open import Definition.LogicalRelation.Substitution.Reflexivity
open import Definition.LogicalRelation.Substitution.ProofIrrelevance
open import Definition.LogicalRelation.Substitution.MaybeEmbed
open import Definition.LogicalRelation.Substitution.Introductions.Nat
open import Definition.LogicalRelation.Substitution.Introductions.Natrec
open import Definition.LogicalRelation.Substitution.Introductions.Empty
open import Definition.LogicalRelation.Substitution.Introductions.Emptyrec
open import Definition.LogicalRelation.Substitution.Introductions.Universe
open import Definition.LogicalRelation.Substitution.Introductions.Pi
open import Definition.LogicalRelation.Substitution.Introductions.Sigma
open import Definition.LogicalRelation.Substitution.Introductions.Id
open import Definition.LogicalRelation.Substitution.Introductions.IdUPiPi
open import Definition.LogicalRelation.Substitution.Introductions.Cast
open import Definition.LogicalRelation.Substitution.Introductions.CastPi
open import Definition.LogicalRelation.Substitution.Introductions.Lambda
open import Definition.LogicalRelation.Substitution.Introductions.Application
open import Definition.LogicalRelation.Substitution.Introductions.Pair
open import Definition.LogicalRelation.Substitution.Introductions.Fst
open import Definition.LogicalRelation.Substitution.Introductions.Snd
open import Definition.LogicalRelation.Substitution.Introductions.SingleSubst
open import Definition.LogicalRelation.Substitution.Introductions.Transp
open import Definition.LogicalRelation.Fundamental.Variable
import Definition.LogicalRelation.Substitution.ProofIrrelevance as PI
import Definition.LogicalRelation.Substitution.Irrelevance as S
open import Definition.LogicalRelation.Substitution.Weakening
open import Tools.Product
open import Tools.Unit
open import Tools.Nat
import Tools.PropositionalEquality as PE
Idreflᵛ : ∀{Γ A l t}
→ ([Γ] : ⊩ᵛ Γ)
→ ([A] : Γ ⊩ᵛ⟨ ∞ ⟩ A ^ [ ! , ι l ] / [Γ])
→ ([t] : Γ ⊩ᵛ⟨ ∞ ⟩ t ∷ A ^ [ ! , ι l ] / [Γ] / [A])
→ let [Id] = Idᵛ {A = A} {t = t} {u = t } [Γ] [A] [t] [t]
in Γ ⊩ᵛ⟨ ∞ ⟩ Idrefl A t ∷ Id A t t ^ [ % , ι l ] / [Γ] / [Id]
Idreflᵛ {Γ} {A} {l} {t} [Γ] [A] [t] =
let [Id] = Idᵛ {A = A} {t = t} {u = t } [Γ] [A] [t] [t]
in validityIrr {A = Id A t t} {t = Idrefl A t} [Γ] [Id] λ ⊢Δ [σ] → Idreflⱼ (escapeTerm (proj₁ ([A] ⊢Δ [σ])) (proj₁ ([t] ⊢Δ [σ])))
castreflᵛ : ∀{Γ A t}
→ ([Γ] : ⊩ᵛ Γ)
→ ([UA] : Γ ⊩ᵛ⟨ ∞ ⟩ U ⁰ ^ [ ! , next ⁰ ] / [Γ])
→ ([A]ₜ : Γ ⊩ᵛ⟨ ∞ ⟩ A ∷ U ⁰ ^ [ ! , next ⁰ ] / [Γ] / [UA] )
→ ([A] : Γ ⊩ᵛ⟨ ∞ ⟩ A ^ [ ! , ι ⁰ ] / [Γ])
→ ([t]ₜ : Γ ⊩ᵛ⟨ ∞ ⟩ t ∷ A ^ [ ! , ι ⁰ ] / [Γ] / [A])
→ let [Id] : Γ ⊩ᵛ⟨ ∞ ⟩ Id A t (cast ⁰ A A (Idrefl (U ⁰) A) t) ^ [ % , ι ⁰ ] / [Γ]
[Id] = Idᵛ {A = A} {t = t} {u = cast ⁰ A A (Idrefl (U ⁰) A) t} [Γ] [A] [t]ₜ
(castᵗᵛ {A = A} {B = A} {t = t} {e = Idrefl (U ⁰) A} [Γ] [UA] [A]ₜ [A]ₜ [A] [A] [t]ₜ
(Idᵛ {A = U _} {t = A} {u = A} [Γ] [UA] [A]ₜ [A]ₜ)
(Idreflᵛ {A = U _} {t = A} [Γ] [UA] [A]ₜ))
in Γ ⊩ᵛ⟨ ∞ ⟩ castrefl A t ∷ Id A t (cast ⁰ A A (Idrefl (U ⁰) A) t) ^ [ % , ι ⁰ ] / [Γ] / [Id]
castreflᵛ {Γ} {A} {t} [Γ] [UA] [A]ₜ [A] [t]ₜ =
let [Id] : Γ ⊩ᵛ⟨ ∞ ⟩ Id A t (cast ⁰ A A (Idrefl (U ⁰) A) t) ^ [ % , ι ⁰ ] / [Γ]
[Id] = Idᵛ {A = A} {t = t} {u = cast ⁰ A A (Idrefl (U ⁰) A) t} [Γ] [A] [t]ₜ
(castᵗᵛ {A = A} {B = A} {t = t} {e = Idrefl (U ⁰) A} [Γ] [UA] [A]ₜ [A]ₜ [A] [A] [t]ₜ
(Idᵛ {A = U _} {t = A} {u = A} [Γ] [UA] [A]ₜ [A]ₜ)
(Idreflᵛ {A = U _} {t = A} [Γ] [UA] [A]ₜ))
in validityIrr {A = Id A t (cast ⁰ A A (Idrefl (U ⁰) A) t)} {t = castrefl A t}
[Γ] [Id] λ ⊢Δ [σ] → castreflⱼ (escapeTerm (proj₁ ([UA] ⊢Δ [σ])) (proj₁ ([A]ₜ ⊢Δ [σ]))) (escapeTerm (proj₁ ([A] ⊢Δ [σ])) (proj₁ ([t]ₜ ⊢Δ [σ])))
| {
"alphanum_fraction": 0.6523946149,
"avg_line_length": 53.9404761905,
"ext": "agda",
"hexsha": "bc9c851ce5f10f63825abc425339e9a695b1a256",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-02-15T19:42:19.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-01-26T14:55:51.000Z",
"max_forks_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CoqHott/logrel-mltt",
"max_forks_repo_path": "Definition/LogicalRelation/Substitution/Introductions/IdRefl.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"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": "CoqHott/logrel-mltt",
"max_issues_repo_path": "Definition/LogicalRelation/Substitution/Introductions/IdRefl.agda",
"max_line_length": 160,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CoqHott/logrel-mltt",
"max_stars_repo_path": "Definition/LogicalRelation/Substitution/Introductions/IdRefl.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T16:13:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-06-21T08:39:01.000Z",
"num_tokens": 1744,
"size": 4531
} |
{-
This file contains:
- the coequalizer of sets as a HIT as performed in https://1lab.dev/Data.Set.Coequaliser.html
-}
{-# OPTIONS --safe #-}
module Cubical.HITs.SetCoequalizer.Properties where
open import Cubical.HITs.SetCoequalizer.Base
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Data.Sigma
private
variable
ℓ ℓ' ℓ'' : Level
A : Type ℓ
B : Type ℓ'
-- Some helpful lemmas, similar to those in Cubical/HITs/SetQuotients/Properties.agda
elimProp : {f g : A → B} {C : SetCoequalizer f g → Type ℓ}
→ (Cprop : (x : SetCoequalizer f g) → isProp (C x))
→ (Cinc : (b : B) → C (inc b))
→ (x : SetCoequalizer f g) → C x
elimProp Cprop Cinc (inc x) = Cinc x
elimProp {f = f} {g = g} Cprop Cinc (coeq a i) =
isProp→PathP (λ i → Cprop (coeq a i)) (Cinc (f a)) (Cinc (g a)) i
elimProp Cprop Cinc (squash x y p q i j) =
isOfHLevel→isOfHLevelDep
2 (λ x → isProp→isSet (Cprop x)) (g x) (g y) (cong g p) (cong g q) (squash x y p q) i j
where
g = elimProp Cprop Cinc
elimProp2 : {A' : Type ℓ} {B' : Type ℓ'} {f g : A → B} {f' g' : A' → B'}
{C : SetCoequalizer f g → SetCoequalizer f' g' → Type (ℓ-max ℓ ℓ')}
→ (Cprop : (x : SetCoequalizer f g) → (y : SetCoequalizer f' g') → isProp (C x y))
→ (Cinc : (b : B) → (b' : B') → C (inc b) (inc b'))
→ (x : SetCoequalizer f g) → (y : SetCoequalizer f' g') → C x y
elimProp2 Cprop Cinc = elimProp (λ x → isPropΠ (λ y → Cprop x y))
(λ x → elimProp (λ y → Cprop (inc x) y) (Cinc x))
elimProp3 : {A' A'' : Type ℓ} {B' B'' : Type ℓ'} {f g : A → B} {f' g' : A' → B'}
{f'' g'' : A'' → B''}
{C : SetCoequalizer f g → SetCoequalizer f' g' → SetCoequalizer f'' g''
→ Type (ℓ-max ℓ ℓ')}
→ (Cprop : (x : SetCoequalizer f g)
→ (y : SetCoequalizer f' g')
→ (z : SetCoequalizer f'' g'')
→ isProp (C x y z))
→ (Cinc : (b : B) → (b' : B') → (b'' : B'') → C (inc b) (inc b') (inc b''))
→ (x : SetCoequalizer f g) → (y : SetCoequalizer f' g') → (z : SetCoequalizer f'' g'')
→ C x y z
elimProp3 Cprop Cinc = elimProp (λ x → isPropΠ2 (λ y z → Cprop x y z))
(λ x → elimProp2 (λ y z → Cprop (inc x) y z) (Cinc x))
rec : {C : Type ℓ''} {f g : A → B}
→ (Cset : (x y : C) → (p q : x ≡ y) → p ≡ q)
→ (h : B → C)
→ (hcoeqs : (a : A) → h (f a) ≡ h (g a))
→ SetCoequalizer f g → C
rec Cset h hcoeqs (inc x) = h x
rec Cset h hcoeqs (coeq a i) = hcoeqs a i
rec Cset h hcoeqs (squash x y p q i j) =
Cset (g x) (g y) (λ i → g (p i)) (λ i → g (q i)) i j
where g = rec Cset h hcoeqs
rec2 : {A' : Type ℓ} {B' : Type ℓ'} {C : Type ℓ''} {f g : A → B} {f' g' : A' → B'}
→ (Cset : (x y : C) → (p q : x ≡ y) → p ≡ q)
→ (h : B → B' → C)
→ (hcoeqsl : (a : A) (b' : B') → h (f a) b' ≡ h (g a) b')
→ (hcoeqsr : (a' : A') (b : B) → h b (f' a') ≡ h b (g' a'))
→ SetCoequalizer f g → SetCoequalizer f' g' → C
rec2 Cset h hcoeqsl hcoeqsr =
rec
(isSetΠ (λ _ → Cset))
(λ b → rec Cset (λ b' → h b b') (λ a' → hcoeqsr a' b))
(λ a → funExt (elimProp (λ _ → Cset _ _) (λ b' → hcoeqsl a b')))
module UniversalProperty where
{- The proof of the universal property of the coequalizer of sets.
A ==f=g==> B --inc--> SetCoequalizer f g
\ .
\ .
h ∃! inducedHom
\ .
\ .
C
commuting diagram
-}
inducedHom : {C : Type ℓ''} {f g : A → B}
→ (Cset : (x y : C) → (p q : x ≡ y) → p ≡ q)
→ (h : B → C)
→ (hcoeq : (a : A) → h (f a) ≡ h (g a))
→ SetCoequalizer f g → C
inducedHom Cset h hcoeq = rec Cset h hcoeq
commutativity : {C : Type ℓ''} {f g : A → B}
→ (Cset : (x y : C) → (p q : x ≡ y) → p ≡ q)
→ (h : B → C)
→ (hcoeq : (a : A) → h (f a) ≡ h (g a))
→ ((b : B) → h b ≡ inducedHom Cset h hcoeq (inc b))
commutativity Cset h hcoeq = λ b → refl
uniqueness : {C : Type ℓ''}
→ (f g : A → B)
→ (Cset : (x y : C) → (p q : x ≡ y) → p ≡ q)
→ (h : B → C)
→ (hcoeq : (a : A) → h (f a) ≡ h (g a))
→ (i : SetCoequalizer f g → C)
→ (icommutativity : (b : B) → h b ≡ i (inc b))
→ (i ≡ inducedHom Cset h hcoeq)
uniqueness f g Cset h hcoeq i icommutativity = λ j x → q x j
where q : (x : SetCoequalizer f g) → i x ≡ inducedHom Cset h hcoeq x
q = elimProp
(λ _ → Cset _ _)
(λ b → i (inc b) ≡⟨ sym (icommutativity b) ⟩
h b ≡⟨ refl ⟩
inducedHom Cset h hcoeq (inc b) ∎)
| {
"alphanum_fraction": 0.4607522486,
"avg_line_length": 39.4516129032,
"ext": "agda",
"hexsha": "af395f3cd8c032448036496abfc2c1b9b37ae363",
"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/HITs/SetCoequalizer/Properties.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/HITs/SetCoequalizer/Properties.agda",
"max_line_length": 96,
"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/HITs/SetCoequalizer/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1946,
"size": 4892
} |
-- Qualified imported constructors
module Issue262 where
open import Common.Prelude
z = Nat.zero
| {
"alphanum_fraction": 0.797979798,
"avg_line_length": 14.1428571429,
"ext": "agda",
"hexsha": "0f78279029d1b455ef4d6f50be65c8b45ace0d30",
"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/Issue262.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/Issue262.agda",
"max_line_length": 34,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue262.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": 21,
"size": 99
} |
-- Andreas, 2016-10-09, issue #2223
-- The level constraint solver needs to combine constraints
-- from different contexts and modules.
-- The parameter refinement broke this test case.
-- {-# OPTIONS -v tc.with.top:25 #-}
-- {-# OPTIONS -v tc.conv.nat:40 #-}
-- {-# OPTIONS -v tc.constr.add:45 #-}
open import Common.Level
module _ (a ℓ : Level) where
module Function where
mutual
X : Level
X = _ -- Agda 2.5.1.1 solves this level meta
X<=a : Set (X ⊔ a) → Set a
X<=a A = A
test : Set₁
test with (lsuc ℓ)
... | _ = Set
where
a<=X : Set (X ⊔ a) → Set X
a<=X A = A
-- Should solve all metas.
| {
"alphanum_fraction": 0.5825688073,
"avg_line_length": 19.8181818182,
"ext": "agda",
"hexsha": "e67c748ffb61dc789e8147beb3ae41f4cd1a3a6d",
"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/Issue2223-function.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/Issue2223-function.agda",
"max_line_length": 59,
"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/Issue2223-function.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": 209,
"size": 654
} |
{-# OPTIONS --without-K #-}
module PiLevel0 where
-- We refine the trivial relation used in level-(-2). We do not
-- identify all types: only those of the same "size". So between any
-- two types, there could be zero, one, or many identifications. If
-- there is more than one idenfication we force them to be the same;
-- so 'id' and 'not' at BOOL ⟷ BOOL are the same and U effectively
-- collapses to the set of natural numbers
open import Data.Unit using (⊤; tt)
open import Data.Nat using (ℕ)
open import Relation.Binary.Core using (IsEquivalence)
open import Relation.Binary.PropositionalEquality
using (_≡_; refl; cong₂; module ≡-Reasoning)
open import PiU using (U; ZERO; ONE; PLUS; TIMES; toℕ)
infix 30 _⟷_
infixr 50 _◎_
------------------------------------------------------------------------------
-- Level 0 of Pi
-- Abbreviation
size : U → ℕ
size = toℕ
-- Combinators
data _⟷_ : U → U → Set where
unite₊l : {t : U} → PLUS ZERO t ⟷ t
uniti₊l : {t : U} → t ⟷ PLUS ZERO t
unite₊r : {t : U} → PLUS t ZERO ⟷ t
uniti₊r : {t : U} → t ⟷ PLUS t ZERO
swap₊ : {t₁ t₂ : U} → PLUS t₁ t₂ ⟷ PLUS t₂ t₁
assocl₊ : {t₁ t₂ t₃ : U} → PLUS t₁ (PLUS t₂ t₃) ⟷ PLUS (PLUS t₁ t₂) t₃
assocr₊ : {t₁ t₂ t₃ : U} → PLUS (PLUS t₁ t₂) t₃ ⟷ PLUS t₁ (PLUS t₂ t₃)
unite⋆l : {t : U} → TIMES ONE t ⟷ t
uniti⋆l : {t : U} → t ⟷ TIMES ONE t
unite⋆r : {t : U} → TIMES t ONE ⟷ t
uniti⋆r : {t : U} → t ⟷ TIMES t ONE
swap⋆ : {t₁ t₂ : U} → TIMES t₁ t₂ ⟷ TIMES t₂ t₁
assocl⋆ : {t₁ t₂ t₃ : U} → TIMES t₁ (TIMES t₂ t₃) ⟷ TIMES (TIMES t₁ t₂) t₃
assocr⋆ : {t₁ t₂ t₃ : U} → TIMES (TIMES t₁ t₂) t₃ ⟷ TIMES t₁ (TIMES t₂ t₃)
absorbr : {t : U} → TIMES ZERO t ⟷ ZERO
absorbl : {t : U} → TIMES t ZERO ⟷ ZERO
factorzr : {t : U} → ZERO ⟷ TIMES t ZERO
factorzl : {t : U} → ZERO ⟷ TIMES ZERO t
dist : {t₁ t₂ t₃ : U} →
TIMES (PLUS t₁ t₂) t₃ ⟷ PLUS (TIMES t₁ t₃) (TIMES t₂ t₃)
factor : {t₁ t₂ t₃ : U} →
PLUS (TIMES t₁ t₃) (TIMES t₂ t₃) ⟷ TIMES (PLUS t₁ t₂) t₃
distl : {t₁ t₂ t₃ : U } →
TIMES t₁ (PLUS t₂ t₃) ⟷ PLUS (TIMES t₁ t₂) (TIMES t₁ t₃)
factorl : {t₁ t₂ t₃ : U } →
PLUS (TIMES t₁ t₂) (TIMES t₁ t₃) ⟷ TIMES t₁ (PLUS t₂ t₃)
id⟷ : {t : U} → t ⟷ t
_◎_ : {t₁ t₂ t₃ : U} → (t₁ ⟷ t₂) → (t₂ ⟷ t₃) → (t₁ ⟷ t₃)
_⊕_ : {t₁ t₂ t₃ t₄ : U} →
(t₁ ⟷ t₃) → (t₂ ⟷ t₄) → (PLUS t₁ t₂ ⟷ PLUS t₃ t₄)
_⊗_ : {t₁ t₂ t₃ t₄ : U} →
(t₁ ⟷ t₃) → (t₂ ⟷ t₄) → (TIMES t₁ t₂ ⟷ TIMES t₃ t₄)
-- At the next level we have a trivial equivalence that equates all
-- morphisms of the same type so for example id and not : BOOL ⟷ BOOL
-- are equated
triv≡ : {t₁ t₂ : U} → (f g : t₁ ⟷ t₂) → Set
triv≡ _ _ = ⊤
triv≡Equiv : {t₁ t₂ : U} → IsEquivalence (triv≡ {t₁} {t₂})
triv≡Equiv = record
{ refl = tt
; sym = λ _ → tt
; trans = λ _ _ → tt
}
------------------------------------------------------------------------------
-- Every combinator has an inverse. There are actually many
-- syntactically different inverses but they are all equivalent.
! : {t₁ t₂ : U} → (t₁ ⟷ t₂) → (t₂ ⟷ t₁)
! unite₊l = uniti₊l
! uniti₊l = unite₊l
! unite₊r = uniti₊r
! uniti₊r = unite₊r
! swap₊ = swap₊
! assocl₊ = assocr₊
! assocr₊ = assocl₊
! unite⋆l = uniti⋆l
! uniti⋆l = unite⋆l
! unite⋆r = uniti⋆r
! uniti⋆r = unite⋆r
! swap⋆ = swap⋆
! assocl⋆ = assocr⋆
! assocr⋆ = assocl⋆
! absorbl = factorzr
! absorbr = factorzl
! factorzl = absorbr
! factorzr = absorbl
! dist = factor
! factor = dist
! distl = factorl
! factorl = distl
! id⟷ = id⟷
! (c₁ ◎ c₂) = ! c₂ ◎ ! c₁
! (c₁ ⊕ c₂) = (! c₁) ⊕ (! c₂)
! (c₁ ⊗ c₂) = (! c₁) ⊗ (! c₂)
!! : {t₁ t₂ : U} {c : t₁ ⟷ t₂} → triv≡ (! (! c)) c
!! = tt
------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.5234087322,
"avg_line_length": 32.4957264957,
"ext": "agda",
"hexsha": "565ac0a7258fc6b0824789beae5298a819da8762",
"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/PiLevel0.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/PiLevel0.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/PiLevel0.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": 1661,
"size": 3802
} |
module BabyAgda where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
stuff : Nat
nonDependent : Nat -> Nat -> Nat
nonDependent a b = a
dependent : {A : Set} -> A -> A
dependent a = a
asdf : {A : Set} -> {B : Nat} -> {renameMe0 : Nat} -> Nat
asdf {_} {_} {zero} = zero
asdf {_} {_} {suc c} = dependent c
| {
"alphanum_fraction": 0.565625,
"avg_line_length": 20,
"ext": "agda",
"hexsha": "95158902ae05cf6e945712deeb1c0e8fe0b316b3",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-01-31T08:40:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-01-31T08:40:41.000Z",
"max_forks_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "omega12345/RefactorAgda",
"max_forks_repo_path": "RefactorAgdaEngine/Test/Tests/ManualTestFiles/BabyAgda.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_issues_repo_issues_event_max_datetime": "2019-02-05T12:53:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-31T08:03:07.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "omega12345/RefactorAgda",
"max_issues_repo_path": "RefactorAgdaEngine/Test/Tests/ManualTestFiles/BabyAgda.agda",
"max_line_length": 57,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "omega12345/RefactorAgda",
"max_stars_repo_path": "RefactorAgdaEngine/Test/Tests/ManualTestFiles/BabyAgda.agda",
"max_stars_repo_stars_event_max_datetime": "2019-05-03T10:03:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-01-31T14:10:18.000Z",
"num_tokens": 113,
"size": 320
} |
-- Andreas, 2016-06-01, issue 1999
-- Bug in TypeChecking.Signature.applySection
-- If that function was not such horrible spaghetti code,
-- there would be less bugs like this.
-- Bug was: code for applying projection used ts instead of ts'
-- {-# OPTIONS -v tc.mod.apply:80 #-}
module Issue1999 where
import Common.Product as P using (_×_ ; proj₂)
module One (A : Set) where
open P public
module Two (A : Set) where
module M = One A
myproj : A M.× A → A
myproj p = M.proj₂ p
-- WAS: Internal error in Substitute (projection applied to lambda)
-- Should work.
| {
"alphanum_fraction": 0.6967071057,
"avg_line_length": 23.08,
"ext": "agda",
"hexsha": "2b49cd521633f3167b07b8e50e703a3727db7ff9",
"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/Issue1999.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/Issue1999.agda",
"max_line_length": 67,
"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/Issue1999.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": 160,
"size": 577
} |
module DTGP.Rand where
open import Data.Nat
open import Relation.Nullary.Decidable
open import Data.Nat.DivMod renaming (_mod_ to _nmod_)
open import Data.Fin
open import Data.Product
open import DTGP.State public
postulate Int : Set
{-# BUILTIN INTEGER Int #-}
primitive
primIntegerPlus : Int → Int → Int
primIntegerMinus : Int → Int → Int
primIntegerTimes : Int → Int → Int
primIntegerDiv : Int → Int → Int -- partial
primIntegerMod : Int → Int → Int -- partial
primIntegerAbs : Int → ℕ
primNatToInteger : ℕ → Int
multiplier : Int
multiplier = primNatToInteger 25173
incrementer : Int
incrementer = primNatToInteger 13849
modulus : Int
modulus = primNatToInteger 65536
nextRand : ℕ → ℕ
nextRand nat =
let n = primNatToInteger nat
product = primIntegerTimes n multiplier
sum = primIntegerPlus product incrementer
remainder = primIntegerMod sum modulus
in primIntegerAbs remainder
calcRand : ℕ → ℕ × ℕ
calcRand n with nextRand n
... | next = next , next
rand : State ℕ ℕ
rand = state calcRand
Rand : Set → Set
Rand A = State ℕ A
runRand : ∀ {A} → Rand A → ℕ → A
runRand st seed = proj₁ (runState st seed)
primNatMod : (dividend divisor : ℕ) → ℕ
primNatMod dividend zero = zero
primNatMod dividend (suc n) =
let x = primNatToInteger dividend
y = primNatToInteger (suc n)
z = primIntegerMod x y
nat = primIntegerAbs z
in nat
_mod_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} → Fin divisor
_mod_ m n {p} = _nmod_ (primNatMod m n) n {p}
| {
"alphanum_fraction": 0.6932555123,
"avg_line_length": 24.8709677419,
"ext": "agda",
"hexsha": "5f97ea3898d9f820f3fce93aecc1a88785a97951",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:53:14.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-04-17T02:02:58.000Z",
"max_forks_repo_head_hexsha": "31d79242908f2d80ea8e0c02931f4fdc5a3e5d1f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "larrytheliquid/dtgp",
"max_forks_repo_path": "src/DTGP/Rand.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "31d79242908f2d80ea8e0c02931f4fdc5a3e5d1f",
"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/dtgp",
"max_issues_repo_path": "src/DTGP/Rand.agda",
"max_line_length": 71,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "31d79242908f2d80ea8e0c02931f4fdc5a3e5d1f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/dtgp",
"max_stars_repo_path": "src/DTGP/Rand.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-19T21:39:58.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-20T16:46:00.000Z",
"num_tokens": 465,
"size": 1542
} |
open import Agda.Builtin.Equality
postulate
A : Set
Phantom : A → Set
Phantom _ = A
postulate
rigid : A → A
mutual
X : A → A → A → A
X = _
Y : (x y : A) → Phantom x
Y = _
-- This constraint triggers pruning of X in an attempt to remove the non-linearity.
-- It doesn't get rid of the non-linearity but prunes x setting X x y z := Z y z,
-- for a fresh meta Z.
c₁ : (x y : A) → X x y y ≡ rigid y
c₁ x y = refl
-- Here we end up with Z y z == rigid (Y x y) which requires pruning x from Y. This
-- fails due to the phantom dependency on x in the type of Y and the constraint is
-- left unsolved. If we hadn't pruned x from X we could have solved this with
-- X x y z := rigid (Y x y), turning the first constraint into rigid (Y x y) == rigid y,
-- which is solved by Y x y := y.
c₂ : (x y z : A) → X x y z ≡ rigid (Y x y)
c₂ x y z = refl
| {
"alphanum_fraction": 0.6133786848,
"avg_line_length": 26.7272727273,
"ext": "agda",
"hexsha": "1bb46e4993d7191ad0e3bca165cc068d5253c9e6",
"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/Issue3177.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/Issue3177.agda",
"max_line_length": 90,
"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/Issue3177.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": 298,
"size": 882
} |
{-# OPTIONS --cubical --safe #-}
module Data.Empty where
open import Data.Empty.Base public
| {
"alphanum_fraction": 0.7127659574,
"avg_line_length": 15.6666666667,
"ext": "agda",
"hexsha": "7d432f2603f140b889146e885b9211243060f889",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Data/Empty.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/combinatorics-paper",
"max_issues_repo_path": "agda/Data/Empty.agda",
"max_line_length": 34,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Data/Empty.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-05T15:32:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-01-05T14:07:44.000Z",
"num_tokens": 21,
"size": 94
} |
-- Andreas, 2021-04-14, #1154
-- Andreas, 2021-04-10, BNFC/bnfc#354
-- Make sure we do not "resurrect" superseded layout columns.
private private private
A : Set -- OK, stacking
B : Set -- Bad, should fail
-- Expected: Parse error after B
| {
"alphanum_fraction": 0.6109090909,
"avg_line_length": 27.5,
"ext": "agda",
"hexsha": "8190fafe931a1e806d140d4d8b159d608692a0e5",
"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/Issue1145b.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/Issue1145b.agda",
"max_line_length": 61,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue1145b.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": 82,
"size": 275
} |
------------------------------------------------------------------------
-- Lemmas related to expansion and CCS
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
open import Prelude hiding (module W; step-→)
module Expansion.CCS {ℓ} {Name : Type ℓ} where
open import Equality.Propositional
open import Prelude.Size
open import Function-universe equality-with-J hiding (id; _∘_)
import Bisimilarity.CCS as SL
import Bisimilarity.Equational-reasoning-instances
import Bisimilarity.Weak.Equational-reasoning-instances
open import Equational-reasoning
import Expansion.Equational-reasoning-instances
open import Labelled-transition-system.CCS Name
open import Relation
open import Bisimilarity CCS as S using (_∼_)
open import Bisimilarity.Weak CCS as W using (_≈_; force)
open import Expansion CCS
import Labelled-transition-system.Equational-reasoning-instances CCS
as Dummy
-- Some lemmas used to prove the congruence lemmas below as well as
-- similar results in Bisimilarity.Weak.CCS.
module Cong-lemmas
({R} R′ : Proc ∞ → Proc ∞ → Type ℓ)
⦃ _ : Reflexive R′ ⦄
⦃ _ : Convertible R R′ ⦄
⦃ _ : Convertible R′ R′ ⦄
⦃ _ : Transitive′ R′ _∼_ ⦄
⦃ _ : Transitive _∼_ R′ ⦄
{_[_]↝_ : Proc ∞ → Label → Proc ∞ → Type ℓ}
(right-to-left :
∀ {P Q} → R P Q →
∀ {Q′ μ} → Q [ μ ]⟶ Q′ → ∃ λ P′ → P [ μ ]↝ P′ × R′ P′ Q′)
⦃ _ : ∀ {μ} → Convertible _[ μ ]↝_ _[ μ ]↝_ ⦄
⦃ _ : ∀ {μ} → Convertible _[ μ ]⟶_ _[ μ ]↝_ ⦄
(↝→[]⇒ : ∀ {P Q a} → P [ name a ]↝ Q → P [ name a ]⇒ Q)
([]⇒→↝ : ∀ {P Q} → P [ τ ]⇒ Q → P [ τ ]↝ Q)
(map-↝ :
{F : Proc ∞ → Proc ∞} →
(∀ {P P′ μ} → P [ μ ]⟶ P′ → F P [ μ ]⟶ F P′) →
∀ {P P′ μ} → P [ μ ]↝ P′ → F P [ μ ]↝ F P′)
(map-↝′ :
∀ {μ} {F : Proc ∞ → Proc ∞} →
(∀ {P P′ μ} → Silent μ → P [ μ ]⟶ P′ → F P [ μ ]⟶ F P′) →
(∀ {P P′} → P [ μ ]⟶ P′ → F P [ μ ]⟶ F P′) →
∀ {P P′} → P [ μ ]↝ P′ → F P [ μ ]↝ F P′)
(zip-↝ :
{F : Proc ∞ → Proc ∞ → Proc ∞} →
(∀ {P P′ Q μ} → P [ μ ]⟶ P′ → F P Q [ μ ]⟶ F P′ Q) →
(∀ {P Q Q′ μ} → Q [ μ ]⟶ Q′ → F P Q [ μ ]⟶ F P Q′) →
∀ {μ₁ μ₂ μ₃} →
(Silent μ₁ → Silent μ₂ → Silent μ₃) →
(∀ {P P′ Q} → P [ μ₁ ]⟶ P′ → Silent μ₂ → F P Q [ μ₃ ]⟶ F P′ Q) →
(∀ {P Q Q′} → Silent μ₁ → Q [ μ₂ ]⟶ Q′ → F P Q [ μ₃ ]⟶ F P Q′) →
(∀ {P P′ Q Q′} →
P [ μ₁ ]⟶ P′ → Q [ μ₂ ]⟶ Q′ → F P Q [ μ₃ ]⟶ F P′ Q′) →
∀ {P P′ Q Q′} →
P [ μ₁ ]↝ P′ → Q [ μ₂ ]↝ Q′ → F P Q [ μ₃ ]↝ F P′ Q′)
(!-lemma :
(∀ {P Q μ} → P [ μ ]⇒ Q → ! P [ μ ]⇒ ! P ∣ Q) →
∀ {P Q μ} → P [ μ ]↝ Q →
∃ λ P′ → ((! P) [ μ ]↝ P′) × P′ ∼ ! P ∣ Q)
where
private
infix -3 rl-result-↝
rl-result-↝ : ∀ {P P′ Q′} μ → P [ μ ]↝ P′ → R′ P′ Q′ →
∃ λ P′ → (P [ μ ]↝ P′) × R′ P′ Q′
rl-result-↝ _ P↝P′ P′≳′Q′ = _ , P↝P′ , P′≳′Q′
syntax rl-result-↝ μ P↝P′ P′≳′Q′ = P↝P′ ↝[ μ ] P′≳′Q′
∣-cong :
(∀ {P P′ Q Q′} → R′ P P′ → R′ Q Q′ → R′ (P ∣ Q) (P′ ∣ Q′)) →
∀ {P₁ P₂ Q₁ Q₂ R₂ μ} →
R P₁ P₂ → R Q₁ Q₂ → P₂ ∣ Q₂ [ μ ]⟶ R₂ →
∃ λ R₁ → ((P₁ ∣ Q₁) [ μ ]↝ R₁) × R′ R₁ R₂
∣-cong _∣-cong′_ P₁≳P₂ Q₁≳Q₂ = λ where
(par-left tr) → Σ-map (_∣ _)
(Σ-map (map-↝ par-left)
(_∣-cong′ convert Q₁≳Q₂))
(right-to-left P₁≳P₂ tr)
(par-right tr) → Σ-map (_ ∣_)
(Σ-map (map-↝ par-right)
(convert P₁≳P₂ ∣-cong′_))
(right-to-left Q₁≳Q₂ tr)
(par-τ tr₁ tr₂) → Σ-zip _∣_
(Σ-zip (zip-↝ par-left par-right
(λ ()) (λ _ ()) (λ ())
par-τ)
_∣-cong′_)
(right-to-left P₁≳P₂ tr₁)
(right-to-left Q₁≳Q₂ tr₂)
·-cong :
∀ {P₁ P₂ Q₂ μ μ′} →
R′ (force P₁) (force P₂) → μ · P₂ [ μ′ ]⟶ Q₂ →
∃ λ Q₁ → ((μ · P₁) [ μ′ ]↝ Q₁) × R′ Q₁ Q₂
·-cong P₁≳P₂ action = _ , convert (⟶: action) , P₁≳P₂
⟨ν⟩-cong :
(∀ {a P P′} → R′ P P′ → R′ (⟨ν a ⟩ P) (⟨ν a ⟩ P′)) →
∀ {a μ P P′ Q′} →
R P P′ → ⟨ν a ⟩ P′ [ μ ]⟶ Q′ →
∃ λ Q → (⟨ν a ⟩ P [ μ ]↝ Q) × R′ Q Q′
⟨ν⟩-cong ⟨ν⟩-cong′ {a} {μ} {P} P≳P′
(restriction {P′ = Q′} a∉μ P′⟶Q′) =
case right-to-left P≳P′ P′⟶Q′ of λ where
(Q , P↝Q , Q≳′Q′) →
⟨ν a ⟩ P →⟨ map-↝′ (restriction ∘ ∉τ) (restriction a∉μ) P↝Q ⟩■
↝[ μ ]
⟨ν a ⟩ Q ∼⟨ ⟨ν⟩-cong′ Q≳′Q′ ⟩■
⟨ν a ⟩ Q′
!-cong-lemma₁ : ∀ {P Q μ} → P [ μ ]⇒ Q → ! P [ μ ]⇒ ! P ∣ Q
!-cong-lemma₁ {P} {Q} {μ} = λ where
(steps {q′ = Q′} done P⟶Q′ Q′⇒Q) →
! P [ μ ]⇒⟨ replication (par-right P⟶Q′) ⟩
! P ∣ Q′ →⟨ map-⇒ par-right Q′⇒Q ⟩■
! P ∣ Q
(steps {p′ = P″} {q′ = Q′}
(step {q = P′} {μ = μ′} μ′s P⟶P′ P′⇒P″)
P″⟶Q′ Q′⇒Q) →
! P →⟨ ⟶→⇒ μ′s (replication (par-right P⟶P′)) ⟩
! P ∣ P′ →⟨ map-⇒ par-right P′⇒P″ ⟩
! P ∣ P″ [ μ ]⇒⟨ par-right P″⟶Q′ ⟩
! P ∣ Q′ →⟨ map-⇒ par-right Q′⇒Q ⟩■
! P ∣ Q
!-cong-lemma₂ :
∀ {P Q₁ Q₂ a} →
P [ name a ]⇒ Q₁ → P [ name (co a) ]⇒ Q₂ →
∃ λ R → ! P [ τ ]⇒ R × R ∼ (! P ∣ Q₁) ∣ Q₂
!-cong-lemma₂ {P} {Q₁} {Q₂} {a} = λ where
(steps {q′ = Q₁′} done P⟶Q₁′ Q₁′⇒Q₁)
(steps {q′ = Q₂′} done P⟶Q₂′ Q₂′⇒Q₂) →
_
, (! P [ τ ]⇒⟨ replication (par-τ (replication (par-right P⟶Q₁′)) P⟶Q₂′) ⟩
(! P ∣ Q₁′) ∣ Q₂′ →⟨ zip-⇒ par-left par-right (map-⇒ par-right Q₁′⇒Q₁) Q₂′⇒Q₂ ⟩■
(! P ∣ Q₁) ∣ Q₂)
, reflexive
(steps {q′ = Q₁′} done P⟶Q₁′ Q₁′⇒Q₁)
(steps {p′ = P₂″} {q′ = Q₂′}
(step {q = P₂′} {μ = μ} μs P⟶P₂′ P₂′⇒P₂″)
P₂″⟶Q₂′ Q₂′⇒Q₂) →
_
, (! P →⟨ ⟶→⇒ μs (replication (par-right P⟶P₂′)) ⟩
! P ∣ P₂′ →⟨ map-⇒ par-right P₂′⇒P₂″ ⟩
! P ∣ P₂″ [ τ ]⇒⟨ par-τ (replication (par-right P⟶Q₁′)) P₂″⟶Q₂′ ⟩
(! P ∣ Q₁′) ∣ Q₂′ →⟨ zip-⇒ par-left par-right (map-⇒ par-right Q₁′⇒Q₁) Q₂′⇒Q₂ ⟩■
(! P ∣ Q₁) ∣ Q₂)
, reflexive
(steps {p′ = P₁″} {q′ = Q₁′}
(step {q = P₁′} {μ = μ} μs P⟶P₁′ P₁′⇒P₁″)
P₁″⟶Q₁′ Q₁′⇒Q₁)
(steps {q′ = Q₂′} done P⟶Q₂′ Q₂′⇒Q₂) →
_
, (! P →⟨ ⟶→⇒ μs (replication (par-right P⟶P₁′)) ⟩
! P ∣ P₁′ →⟨ map-⇒ par-right P₁′⇒P₁″ ⟩
! P ∣ P₁″ [ τ ]⇒⟨ par-τ′ (sym $ co-involutive a) (replication (par-right P⟶Q₂′)) P₁″⟶Q₁′ ⟩
(! P ∣ Q₂′) ∣ Q₁′ →⟨ zip-⇒ par-left par-right (map-⇒ par-right Q₂′⇒Q₂) Q₁′⇒Q₁ ⟩■
(! P ∣ Q₂) ∣ Q₁)
, ((! P ∣ Q₂) ∣ Q₁ ∼⟨ SL.swap-rightmost ⟩■
(! P ∣ Q₁) ∣ Q₂)
(steps {p′ = P₁″} {q′ = Q₁′}
(step {q = P₁′} {μ = μ₁} μ₁s P⟶P₁′ P₁′⇒P₁″)
P₁″⟶Q₁′ Q₁′⇒Q₁)
(steps {p′ = P₂″} {q′ = Q₂′}
(step {q = P₂′} {μ = μ₂} μ₂s P⟶P₂′ P₂′⇒P₂″)
P₂″⟶Q₂′ Q₂′⇒Q₂) →
_
, (! P →⟨ ⟶→⇒ μ₂s (replication (par-right P⟶P₂′)) ⟩
! P ∣ P₂′ →⟨ ⟶→⇒ μ₁s (par-left (replication (par-right P⟶P₁′))) ⟩
(! P ∣ P₁′) ∣ P₂′ →⟨ zip-⇒ par-left par-right (map-⇒ par-right P₁′⇒P₁″) P₂′⇒P₂″ ⟩
(! P ∣ P₁″) ∣ P₂″ [ τ ]⇒⟨ par-τ (par-right P₁″⟶Q₁′) P₂″⟶Q₂′ ⟩
(! P ∣ Q₁′) ∣ Q₂′ →⟨ zip-⇒ par-left par-right (map-⇒ par-right Q₁′⇒Q₁) Q₂′⇒Q₂ ⟩■
(! P ∣ Q₁) ∣ Q₂)
, reflexive
!-cong :
(∀ {P P′ Q Q′} → R′ P P′ → R′ Q Q′ → R′ (P ∣ Q) (P′ ∣ Q′)) →
(∀ {P P′} → R′ P P′ → R′ (! P) (! P′)) →
∀ {P P′ Q′ μ} →
R P P′ → ! P′ [ μ ]⟶ Q′ →
∃ λ Q → ((! P) [ μ ]↝ Q) × R′ Q Q′
!-cong _∣-cong′_ !-cong′_ {P} {P′} {Q′} {μ} P≳P′ !P′⟶Q′ =
case SL.6-1-3-2 !P′⟶Q′ of λ where
(inj₁ (P″ , P′⟶P″ , Q′∼!P′∣P″)) →
let Q , P↝Q , Q≳′P″ = right-to-left P≳P′ P′⟶P″
R , !P↝R , R∼!P∣Q = !-lemma !-cong-lemma₁ P↝Q
in
! P →⟨ !P↝R ⟩■
↝[ μ ]
R ∼⟨ R∼!P∣Q ⟩
! P ∣ Q ∼′⟨ (!-cong′ (convert P≳P′)) ∣-cong′ Q≳′P″ ⟩
! P′ ∣ P″ ∼⟨ symmetric Q′∼!P′∣P″ ⟩■
Q′
(inj₂ (refl , P″ , P‴ , a , P′⟶P″ , P′⟶P‴ , Q′∼!P′∣P″∣P‴)) →
let Q₁ , P↝Q₁ , Q₁≳′P″ = right-to-left P≳P′ P′⟶P″
Q₂ , P↝Q₂ , Q₂≳′P‴ = right-to-left P≳P′ P′⟶P‴
R , !P⇒R , R∼[!P∣Q₁]∣Q₂ =
!-cong-lemma₂ (↝→[]⇒ P↝Q₁) (↝→[]⇒ P↝Q₂)
in
! P →⟨ []⇒→↝ !P⇒R ⟩■
↝[ τ ]
R ∼⟨ R∼[!P∣Q₁]∣Q₂ ⟩
(! P ∣ Q₁) ∣ Q₂ ∼′⟨ ((!-cong′ (convert P≳P′)) ∣-cong′ Q₁≳′P″) ∣-cong′ Q₂≳′P‴ ⟩
(! P′ ∣ P″) ∣ P‴ ∼⟨ symmetric Q′∼!P′∣P″∣P‴ ⟩■
Q′
⊕·-cong :
∀ {P Q Q′ S′ μ μ′} →
R′ (force Q) (force Q′) → P ⊕ μ · Q′ [ μ′ ]⟶ S′ →
∃ λ S → ((P ⊕ μ · Q) [ μ′ ]↝ S) × R′ S S′
⊕·-cong {P} {Q} {Q′} {S′} {μ} {μ′} Q≳Q′ = λ where
(sum-left P⟶S′) →
P ⊕ μ · Q →⟨ ⟶: sum-left P⟶S′ ⟩■
↝[ μ′ ]
S′ ■
(sum-right action) →
P ⊕ μ · Q →⟨ ⟶: sum-right action ⟩■
↝[ μ ]
force Q ∼⟨ Q≳Q′ ⟩■
force Q′
·⊕·-cong :
∀ {μ₁ μ₂ P₁ P₁′ P₂ P₂′ S′ μ} →
R′ (force P₁) (force P₁′) → R′ (force P₂) (force P₂′) →
μ₁ · P₁′ ⊕ μ₂ · P₂′ [ μ ]⟶ S′ →
∃ λ S → ((μ₁ · P₁ ⊕ μ₂ · P₂) [ μ ]↝ S) × R′ S S′
·⊕·-cong {μ₁} {μ₂} {P₁} {P₁′} {P₂} {P₂′} P₁≳P₁′ P₂≳P₂′ = λ where
(sum-left action) →
μ₁ · P₁ ⊕ μ₂ · P₂ →⟨ ⟶: sum-left action ⟩■
↝[ μ₁ ]
force P₁ ∼⟨ P₁≳P₁′ ⟩■
force P₁′
(sum-right action) →
μ₁ · P₁ ⊕ μ₂ · P₂ →⟨ ⟶: sum-right action ⟩■
↝[ μ₂ ]
force P₂ ∼⟨ P₂≳P₂′ ⟩■
force P₂′
private
module CL {i} =
Cong-lemmas
[ i ]_≳′_ right-to-left id id
map-[]⇒ map-[]⇒′ (λ f g _ _ _ → zip-[]⇒ f g)
(λ hyp P⇒Q → _ , hyp P⇒Q , reflexive)
mutual
-- _∣_ preserves the expansion relation.
infix 6 _∣-cong_ _∣-cong′_
_∣-cong_ : ∀ {i P P′ Q Q′} →
[ i ] P ≳ P′ → [ i ] Q ≳ Q′ → [ i ] P ∣ Q ≳ P′ ∣ Q′
_∣-cong_ {i} P≳P′ Q≳Q′ =
⟨ lr P≳P′ Q≳Q′
, CL.∣-cong _∣-cong′_ P≳P′ Q≳Q′
⟩
where
lr : ∀ {P P′ Q Q′ R μ} →
[ i ] P ≳ P′ → [ i ] Q ≳ Q′ → P ∣ Q [ μ ]⟶ R →
∃ λ R′ → P′ ∣ Q′ [ μ ]⟶̂ R′ × [ i ] R ≳′ R′
lr P≳P′ Q≳Q′ (par-left tr) = Σ-map (_∣ _)
(Σ-map (map-⟶̂ par-left)
(_∣-cong′ convert {a = ℓ} Q≳Q′))
(left-to-right P≳P′ tr)
lr P≳P′ Q≳Q′ (par-right tr) = Σ-map (_ ∣_)
(Σ-map (map-⟶̂ par-right)
(convert {a = ℓ} P≳P′ ∣-cong′_))
(left-to-right Q≳Q′ tr)
lr P≳P′ Q≳Q′ (par-τ tr₁ tr₂) = Σ-zip _∣_
(Σ-zip (zip-⟶̂ (λ ()) (λ _ ())
(λ ()) par-τ)
_∣-cong′_)
(left-to-right P≳P′ tr₁)
(left-to-right Q≳Q′ tr₂)
_∣-cong′_ : ∀ {i P P′ Q Q′} →
[ i ] P ≳′ P′ → [ i ] Q ≳′ Q′ → [ i ] P ∣ Q ≳′ P′ ∣ Q′
force (P≳P′ ∣-cong′ Q≳Q′) = force P≳P′ ∣-cong force Q≳Q′
-- _·_ preserves the expansion relation.
infix 12 _·-cong_ _·-cong′_
_·-cong_ :
∀ {i μ μ′ P P′} →
μ ≡ μ′ → [ i ] force P ≳′ force P′ → [ i ] μ · P ≳ μ′ · P′
_·-cong_ {i} {μ} {P = P} {P′} refl P≳P′ = ⟨ lr , CL.·-cong P≳P′ ⟩
where
lr : ∀ {Q μ″} →
μ · P [ μ″ ]⟶ Q →
∃ λ Q′ → μ · P′ [ μ″ ]⟶̂ Q′ × [ i ] Q ≳′ Q′
lr action = _ , ⟶→⟶̂ action , P≳P′
_·-cong′_ :
∀ {i μ μ′ P P′} →
μ ≡ μ′ → [ i ] force P ≳′ force P′ → [ i ] μ · P ≳′ μ′ · P′
force (μ≡μ′ ·-cong′ P≳P′) = μ≡μ′ ·-cong P≳P′
-- _∙_ preserves the expansion relation.
infix 12 _∙-cong_ _∙-cong′_
_∙-cong_ : ∀ {i μ μ′ P P′} →
μ ≡ μ′ → [ i ] P ≳ P′ → [ i ] μ ∙ P ≳ μ′ ∙ P′
refl ∙-cong P≳P′ = refl ·-cong convert {a = ℓ} P≳P′
_∙-cong′_ : ∀ {i μ μ′ P P′} →
μ ≡ μ′ → [ i ] P ≳′ P′ → [ i ] μ ∙ P ≳′ μ′ ∙ P′
force (μ≡μ′ ∙-cong′ P≳P′) = μ≡μ′ ∙-cong force P≳P′
-- _∙ turns equal actions into processes related by the expansion
-- relation.
infix 12 _∙-cong _∙-cong′
_∙-cong : ∀ {μ μ′} → μ ≡ μ′ → μ ∙ ≳ μ′ ∙
refl ∙-cong = reflexive
_∙-cong′ : ∀ {μ μ′} → μ ≡ μ′ → μ ∙ ≳′ μ′ ∙
refl ∙-cong′ = reflexive
mutual
-- ⟨ν_⟩ preserves the expansion relation.
⟨ν_⟩-cong : ∀ {i a a′ P P′} →
a ≡ a′ → [ i ] P ≳ P′ → [ i ] ⟨ν a ⟩ P ≳ ⟨ν a′ ⟩ P′
⟨ν_⟩-cong {i} {a} {P = P} {P′} refl P≳P′ =
⟨ lr
, CL.⟨ν⟩-cong ⟨ν refl ⟩-cong′ P≳P′
⟩
where
lr : ∀ {Q μ} →
⟨ν a ⟩ P [ μ ]⟶ Q →
∃ λ Q′ → ⟨ν a ⟩ P′ [ μ ]⟶̂ Q′ × [ i ] Q ≳′ Q′
lr {μ = μ} (restriction {P′ = Q} a∉μ P⟶Q)
with left-to-right P≳P′ P⟶Q
... | Q′ , step P′⟶Q′ , Q≳′Q′ =
⟨ν a ⟩ Q ∼⟨ ⟨ν refl ⟩-cong′ Q≳′Q′ ⟩■
⟨ν a ⟩ Q′
⟵̂[ μ ] ←⟨ ⟶: restriction a∉μ P′⟶Q′ ⟩■
⟨ν a ⟩ P′
... | _ , done μs , Q≳′P′ =
⟨ν a ⟩ Q ∼⟨ ⟨ν refl ⟩-cong′ Q≳′P′ ⟩■
⟨ν a ⟩ P′
⟵̂[ μ ] ←⟨ ⟶̂: done μs ⟩■
⟨ν a ⟩ P′
⟨ν_⟩-cong′ : ∀ {i a a′ P P′} →
a ≡ a′ → [ i ] P ≳′ P′ → [ i ] ⟨ν a ⟩ P ≳′ ⟨ν a′ ⟩ P′
force (⟨ν a≡a′ ⟩-cong′ P≳P′) = ⟨ν a≡a′ ⟩-cong (force P≳P′)
mutual
-- !_ preserves the expansion relation.
infix 10 !-cong_ !-cong′_
!-cong_ : ∀ {i P P′} →
[ i ] P ≳ P′ → [ i ] ! P ≳ ! P′
!-cong_ {i} {P} {P′} P≳P′ =
⟨ lr
, CL.!-cong _∣-cong′_ !-cong′_ P≳P′
⟩
where
lr : ∀ {Q μ} →
! P [ μ ]⟶ Q →
∃ λ Q′ → ! P′ [ μ ]⟶̂ Q′ × [ i ] Q ≳′ Q′
lr {Q} {μ} !P⟶Q = case SL.6-1-3-2 !P⟶Q of λ where
(inj₁ (P″ , P⟶P″ , Q∼!P∣P″)) → case left-to-right P≳P′ P⟶P″ of λ where
(_ , done s , P″≳′P′) → case silent≡τ s of λ where
refl →
_
, (! P′ ■)
, (Q ∼⟨ Q∼!P∣P″ ⟩
! P ∣ P″ ∼′⟨ !-cong′ (convert {a = ℓ} P≳P′) ∣-cong′ P″≳′P′ ⟩ S.∼:
! P′ ∣ P′ ∼⟨ SL.6-1-2 ⟩■
! P′)
(Q′ , step P′⟶Q′ , P″≳′Q′) →
_
, (! P′ ∣ Q′ ←⟨ ⟶: replication (par-right P′⟶Q′) ⟩■
! P′)
, (Q ∼⟨ Q∼!P∣P″ ⟩
! P ∣ P″ ∼⟨ !-cong′ (convert {a = ℓ} P≳P′) ∣-cong′ P″≳′Q′ ⟩■
! P′ ∣ Q′)
(inj₂ (refl , P″ , P‴ , a , P⟶P″ , P⟶P‴ , Q≳!P∣P″∣P‴)) →
case left-to-right P≳P′ P⟶P″ ,′
left-to-right P≳P′ P⟶P‴ of λ where
((Q′ , step P′⟶Q′ , P″≳′Q′) ,
(Q″ , step P′⟶Q″ , P‴≳′Q″)) →
_
, ((! P′ ∣ Q′) ∣ Q″ ←⟨ ⟶: replication (par-τ (replication (par-right P′⟶Q′)) P′⟶Q″) ⟩■
! P′)
, (Q ∼⟨ Q≳!P∣P″∣P‴ ⟩
(! P ∣ P″) ∣ P‴ ∼⟨ (!-cong′ (convert {a = ℓ} P≳P′) ∣-cong′ P″≳′Q′) ∣-cong′ P‴≳′Q″ ⟩■
(! P′ ∣ Q′) ∣ Q″)
((_ , done () , _) , _)
(_ , (_ , done () , _))
!-cong′_ : ∀ {i P P′} → [ i ] P ≳′ P′ → [ i ] ! P ≳′ ! P′
force (!-cong′ P≳P′) = !-cong (force P≳P′)
-- It is not necessarily the case that, if P expands P′, then P ⊕ Q is
-- weakly bisimilar to P′ ⊕ Q (assuming that Name is inhabited).
--
-- I based the counterexample on one in "Enhancements of the
-- bisimulation proof method" by Pous and Sangiorgi.
¬⊕-congˡ-≳≈ : Name → ¬ (∀ {P P′ Q} → P ≳ P′ → P ⊕ Q ≈ P′ ⊕ Q)
¬⊕-congˡ-≳≈ x =
(∀ {P P′ Q} → P ≳ P′ → P ⊕ Q ≈ P′ ⊕ Q) ↝⟨ _$ τa≳a ⟩
τ ∙ (a ∙) ⊕ b ∙ ≈ a ∙ ⊕ b ∙ ↝⟨ τa⊕b≉a⊕b ⟩□
⊥ □
where
a = x , true
b = x , false
τa≳a : ∀ {a} → τ ∙ (a ∙) ≳ a ∙
τa≳a {a} =
⟨ (λ where
action →
a ∙ ■
⟵̂[ τ ]
a ∙ ■)
, (λ where
action →
τ ∙ (a ∙) →⟨ ⟶: action ⟩
a ∙ →⟨ ⟶: action ⟩■
⇒[ name a ]
∅ ■)
⟩
τa⊕b≉a⊕b : ¬ τ ∙ (a ∙) ⊕ b ∙ ≈ a ∙ ⊕ b ∙
τa⊕b≉a⊕b τa⊕b≈a⊕b
with W.left-to-right τa⊕b≈a⊕b (sum-left action)
... | _ , non-silent ¬s _ , _ = ⊥-elim (¬s _)
... | _ , silent _ (step () (sum-left action) _) , _
... | _ , silent _ (step () (sum-right action) _) , _
... | _ , silent _ done , a≈′a⊕b
with W.right-to-left (force a≈′a⊕b) (sum-right action)
... | _ , silent () _ , _
... | _ , non-silent _ (steps done () _) , _
... | _ , non-silent _ (steps (step () action _) _ _) , _
-- It is not necessarily the case that, if Q expands Q′, then P ⊕ Q is
-- weakly bisimilar to P ⊕ Q′ (assuming that Name is inhabited).
¬⊕-congʳ-≳≈ : Name → ¬ (∀ {P Q Q′} → Q ≳ Q′ → P ⊕ Q ≈ P ⊕ Q′)
¬⊕-congʳ-≳≈ x ⊕-congʳ-≳≈ = ¬⊕-congˡ-≳≈ x ⊕-congˡ-≳≈
where
⊕-congˡ-≳≈ : ∀ {P P′ Q} → P ≳ P′ → P ⊕ Q ≈ P′ ⊕ Q
⊕-congˡ-≳≈ {P} {P′} {Q} P≳P′ =
P ⊕ Q ∼⟨ SL.⊕-comm ⟩
Q ⊕ P ∼′⟨ ⊕-congʳ-≳≈ P≳P′ ⟩ S.∼:
Q ⊕ P′ ∼⟨ SL.⊕-comm ⟩■
P′ ⊕ Q
-- _⊕_ does not, in general, preserve the expansion relation in its
-- first argument (assuming that Name is inhabited).
¬⊕-congˡ : Name → ¬ (∀ {P P′ Q} → P ≳ P′ → P ⊕ Q ≳ P′ ⊕ Q)
¬⊕-congˡ x =
(∀ {P P′ Q} → P ≳ P′ → P ⊕ Q ≳ P′ ⊕ Q) ↝⟨ W.≳⇒≈ ∘_ ⟩
(∀ {P P′ Q} → P ≳ P′ → P ⊕ Q ≈ P′ ⊕ Q) ↝⟨ ¬⊕-congˡ-≳≈ x ⟩□
⊥ □
-- _⊕_ does not, in general, preserve the expansion relation in its
-- second argument (assuming that Name is inhabited).
¬⊕-congʳ : Name → ¬ (∀ {P Q Q′} → Q ≳ Q′ → P ⊕ Q ≳ P ⊕ Q′)
¬⊕-congʳ x =
(∀ {P Q Q′} → Q ≳ Q′ → P ⊕ Q ≳ P ⊕ Q′) ↝⟨ W.≳⇒≈ ∘_ ⟩
(∀ {P Q Q′} → Q ≳ Q′ → P ⊕ Q ≈ P ⊕ Q′) ↝⟨ ¬⊕-congʳ-≳≈ x ⟩□
⊥ □
-- Some congruence lemmas for combinations of _⊕_ and _·_.
⊕·-cong : ∀ {i P μ Q Q′} →
[ i ] force Q ≳′ force Q′ → [ i ] P ⊕ μ · Q ≳ P ⊕ μ · Q′
⊕·-cong {i} {P} {μ} {Q} {Q′} Q≳Q′ =
⟨ lr , CL.⊕·-cong Q≳Q′ ⟩
where
lr : ∀ {R μ′} →
P ⊕ μ · Q [ μ′ ]⟶ R →
∃ λ R′ → P ⊕ μ · Q′ [ μ′ ]⟶̂ R′ × [ i ] R ≳′ R′
lr {R} {μ′} = λ where
(sum-left P⟶R) →
R ■
⟵̂[ μ′ ] ←⟨ ⟶: sum-left P⟶R ⟩■
P ⊕ μ · Q′
(sum-right action) →
force Q ∼⟨ Q≳Q′ ⟩■
force Q′
⟵̂[ μ ] ←⟨ ⟶: sum-right action ⟩■
P ⊕ μ · Q′
⊕·-cong′ : ∀ {i P μ Q Q′} →
[ i ] force Q ≳′ force Q′ → [ i ] P ⊕ μ · Q ≳′ P ⊕ μ · Q′
force (⊕·-cong′ Q≳Q′) = ⊕·-cong Q≳Q′
·⊕-cong : ∀ {i P P′ μ Q} →
[ i ] force P ≳′ force P′ → [ i ] μ · P ⊕ Q ≳ μ · P′ ⊕ Q
·⊕-cong {P = P} {P′} {μ} {Q} P≳P′ =
μ · P ⊕ Q ∼⟨ SL.⊕-comm ⟩
Q ⊕ μ · P ∼′⟨ ⊕·-cong P≳P′ ⟩ S.∼:
Q ⊕ μ · P′ ∼⟨ SL.⊕-comm ⟩■
μ · P′ ⊕ Q
·⊕-cong′ : ∀ {i P P′ μ Q} →
[ i ] force P ≳′ force P′ → [ i ] μ · P ⊕ Q ≳′ μ · P′ ⊕ Q
force (·⊕-cong′ P≳P′) = ·⊕-cong P≳P′
infix 8 _·⊕·-cong_ _·⊕·-cong′_
_·⊕·-cong_ :
∀ {i μ₁ μ₂ P₁ P₁′ P₂ P₂′} →
[ i ] force P₁ ≳′ force P₁′ → [ i ] force P₂ ≳′ force P₂′ →
[ i ] μ₁ · P₁ ⊕ μ₂ · P₂ ≳ μ₁ · P₁′ ⊕ μ₂ · P₂′
_·⊕·-cong_ {i} {μ₁} {μ₂} {P₁} {P₁′} {P₂} {P₂′} P₁≳P₁′ P₂≳P₂′ =
⟨ lr , CL.·⊕·-cong P₁≳P₁′ P₂≳P₂′ ⟩
where
lr : ∀ {R μ} → μ₁ · P₁ ⊕ μ₂ · P₂ [ μ ]⟶ R →
∃ λ R′ → μ₁ · P₁′ ⊕ μ₂ · P₂′ [ μ ]⟶̂ R′ × [ i ] R ≳′ R′
lr = λ where
(sum-left action) →
force P₁ ∼⟨ P₁≳P₁′ ⟩■
force P₁′
⟵̂[ μ₁ ] ←⟨ ⟶: sum-left action ⟩■
μ₁ · P₁′ ⊕ μ₂ · P₂′
(sum-right action) →
force P₂ ∼⟨ P₂≳P₂′ ⟩■
force P₂′
⟵̂[ μ₂ ] ←⟨ ⟶: sum-right action ⟩■
μ₁ · P₁′ ⊕ μ₂ · P₂′
_·⊕·-cong′_ :
∀ {i μ₁ μ₂ P₁ P₁′ P₂ P₂′} →
[ i ] force P₁ ≳′ force P₁′ → [ i ] force P₂ ≳′ force P₂′ →
[ i ] μ₁ · P₁ ⊕ μ₂ · P₂ ≳′ μ₁ · P₁′ ⊕ μ₂ · P₂′
force (P₁≳′P₁′ ·⊕·-cong′ P₂≳′P₂′) = P₁≳′P₁′ ·⊕·-cong P₂≳′P₂′
-- _[_] preserves the expansion relation for non-degenerate contexts.
-- (This result is related to Theorem 6.5.25 in "Enhancements of the
-- bisimulation proof method" by Pous and Sangiorgi.)
infix 5 _[_]-cong _[_]-cong′
_[_]-cong :
∀ {i n Ps Qs} {C : Context ∞ n} →
Non-degenerate ∞ C → (∀ x → [ i ] Ps x ≳ Qs x) →
[ i ] C [ Ps ] ≳ C [ Qs ]
hole [ Ps≳Qs ]-cong = Ps≳Qs _
∅ [ Ps≳Qs ]-cong = reflexive
D₁ ∣ D₂ [ Ps≳Qs ]-cong = (D₁ [ Ps≳Qs ]-cong) ∣-cong (D₂ [ Ps≳Qs ]-cong)
action D [ Ps≳Qs ]-cong = refl ·-cong λ { .force → force D [ Ps≳Qs ]-cong }
⟨ν⟩ D [ Ps≳Qs ]-cong = ⟨ν refl ⟩-cong (D [ Ps≳Qs ]-cong)
! D [ Ps≳Qs ]-cong = !-cong (D [ Ps≳Qs ]-cong)
D₁ ⊕ D₂ [ Ps≳Qs ]-cong = ⊕-cong Ps≳Qs D₁ D₂
where
_[_]-cong′ :
∀ {i n Ps Qs} {C : Context ∞ n} →
Non-degenerate′ ∞ C → (∀ x → [ i ] Ps x ≳ Qs x) →
[ i ] C [ Ps ] ≳′ C [ Qs ]
force (D [ Ps≳Qs ]-cong′) = force D [ Ps≳Qs ]-cong
⊕-cong :
∀ {i n Ps Qs} {C₁ C₂ : Context ∞ n} →
(∀ x → [ i ] Ps x ≳ Qs x) →
Non-degenerate-summand ∞ C₁ →
Non-degenerate-summand ∞ C₂ →
[ i ] (C₁ [ Ps ]) ⊕ (C₂ [ Ps ]) ≳ (C₁ [ Qs ]) ⊕ (C₂ [ Qs ])
⊕-cong {Ps = Ps} {Qs} Ps≳Qs = λ where
(process P₁) (process P₂) →
(context P₁ [ Ps ]) ⊕ (context P₂ [ Ps ]) ∼⟨ symmetric (SL.≡→∼ (context-[] P₁) SL.⊕-cong SL.≡→∼ (context-[] P₂)) ⟩
P₁ ⊕ P₂ ∼⟨ SL.≡→∼ (context-[] P₁) SL.⊕-cong SL.≡→∼ (context-[] P₂) ⟩■
(context P₁ [ Qs ]) ⊕ (context P₂ [ Qs ])
(process P₁) (action {μ = μ₂} {C = C₂} D₂) →
(context P₁ [ Ps ]) ⊕ μ₂ · (C₂ [ Ps ]′) ∼⟨ symmetric (SL.≡→∼ (context-[] P₁)) SL.⊕-cong (_ ■) ⟩
P₁ ⊕ μ₂ · (C₂ [ Ps ]′) ∼′⟨ ⊕·-cong (D₂ [ Ps≳Qs ]-cong′) ⟩ S.∼:
P₁ ⊕ μ₂ · (C₂ [ Qs ]′) ∼⟨ SL.≡→∼ (context-[] P₁) SL.⊕-cong (_ ■) ⟩■
(context P₁ [ Qs ]) ⊕ μ₂ · (C₂ [ Qs ]′)
(action {μ = μ₁} {C = C₁} D₁) (process P₂) →
μ₁ · (C₁ [ Ps ]′) ⊕ (context P₂ [ Ps ]) ∼⟨ (_ ■) SL.⊕-cong symmetric (SL.≡→∼ (context-[] P₂)) ⟩
μ₁ · (C₁ [ Ps ]′) ⊕ P₂ ∼′⟨ ·⊕-cong (D₁ [ Ps≳Qs ]-cong′) ⟩ S.∼:
μ₁ · (C₁ [ Qs ]′) ⊕ P₂ ∼⟨ (_ ■) SL.⊕-cong SL.≡→∼ (context-[] P₂) ⟩■
μ₁ · (C₁ [ Qs ]′) ⊕ (context P₂ [ Qs ])
(action {μ = μ₁} {C = C₁} D₁) (action {μ = μ₂} {C = C₂} D₂) →
μ₁ · (C₁ [ Ps ]′) ⊕ μ₂ · (C₂ [ Ps ]′) ∼⟨ (D₁ [ Ps≳Qs ]-cong′) ·⊕·-cong (D₂ [ Ps≳Qs ]-cong′) ⟩■
μ₁ · (C₁ [ Qs ]′) ⊕ μ₂ · (C₂ [ Qs ]′)
_[_]-cong′ :
∀ {i n Ps Qs} {C : Context ∞ n} →
Non-degenerate ∞ C → (∀ x → [ i ] Ps x ≳′ Qs x) →
[ i ] C [ Ps ] ≳′ C [ Qs ]
force (C [ Ps≳Qs ]-cong′) = C [ (λ x → force (Ps≳Qs x)) ]-cong
| {
"alphanum_fraction": 0.372216474,
"avg_line_length": 35.1724683544,
"ext": "agda",
"hexsha": "88d71a8f5be2c69021455c0d4b7a8c716f5142e8",
"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": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/up-to",
"max_forks_repo_path": "src/Expansion/CCS.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"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/up-to",
"max_issues_repo_path": "src/Expansion/CCS.agda",
"max_line_length": 121,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/up-to",
"max_stars_repo_path": "src/Expansion/CCS.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 11591,
"size": 22229
} |
module BTree.Complete.Base {A : Set} where
open import BTree {A}
open import BTree.Equality {A}
data Perfect : BTree → Set where
plf : Perfect leaf
p≃ : {l r : BTree}
(x : A)
→ l ≃ r
→ Perfect (node x l r)
data _⋗_ : BTree → BTree → Set where
⋗lf : (x : A)
→ node x leaf leaf ⋗ leaf
⋗nd : {l r' : BTree}
(x x' : A)
→ (r l' : BTree)
→ l ⋗ r'
→ node x l r ⋗ node x' l' r'
data NearlyPerfect : BTree → Set where
npr : {r : BTree}
(x : A)
(l : BTree)
→ NearlyPerfect r
→ NearlyPerfect (node x l r)
np⋗ : {l r : BTree}
(x : A)
→ l ⋗ r
→ NearlyPerfect (node x l r)
data _⋘_ : BTree → BTree → Set where
eq⋘ : {l r : BTree}
→ l ≃ r
→ l ⋘ r
gt⋘ : {l r : BTree}
→ NearlyPerfect l
→ Perfect r
→ l ⋗ r
→ l ⋘ r
data _⋙_ : BTree → BTree → Set where
⋙gt : {l r : BTree}
→ l ⋗ r
→ l ⋙ r
data Complete : BTree → Set where
leaf : Complete leaf
left : {l r : BTree}
(x : A)
→ Complete l
→ Complete r
→ l ⋘ r
→ Complete (node x l r)
right : {l r : BTree}
(x : A)
→ Complete l
→ Complete r
→ l ⋙ r
→ Complete (node x l r)
| {
"alphanum_fraction": 0.3442720764,
"avg_line_length": 27.0322580645,
"ext": "agda",
"hexsha": "ba90bd5c0216e2974245057f215ba2655659c986",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bgbianchi/sorting",
"max_forks_repo_path": "agda/BTree/Complete/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bgbianchi/sorting",
"max_issues_repo_path": "agda/BTree/Complete/Base.agda",
"max_line_length": 48,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bgbianchi/sorting",
"max_stars_repo_path": "agda/BTree/Complete/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z",
"num_tokens": 497,
"size": 1676
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Relation.Binary.Construct.Always where
open import Cubical.Core.Everything
open import Cubical.Relation.Binary
open import Cubical.Relation.Binary.Construct.Constant using (Const)
open import Cubical.Data.Unit.Polymorphic
------------------------------------------------------------------------
-- Definition
Always : ∀ {a b ℓ} {A : Type a} {B : Type b} → REL A B ℓ
Always = Const (⊤ , isProp⊤)
------------------------------------------------------------------------
-- Properties
module _ {a} (A : Type a) ℓ where
reflexive : Reflexive {A = A} {ℓ = ℓ} Always
reflexive = _
symmetric : Symmetric {A = A} {ℓ = ℓ} Always
symmetric _ = _
transitive : Transitive {A = A} {ℓ = ℓ} Always
transitive _ _ = _
isEquivalence : IsEquivalence {ℓ = ℓ} {A} Always
isEquivalence = record {}
equivalence : Equivalence A ℓ
equivalence = record
{ isEquivalence = isEquivalence
}
| {
"alphanum_fraction": 0.5780765253,
"avg_line_length": 26.1351351351,
"ext": "agda",
"hexsha": "75fa39d85d16fe6c4e469839a7d8f8af2e9311c2",
"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": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bijan2005/univalent-foundations",
"max_forks_repo_path": "Cubical/Relation/Binary/Construct/Always.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"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": "bijan2005/univalent-foundations",
"max_issues_repo_path": "Cubical/Relation/Binary/Construct/Always.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bijan2005/univalent-foundations",
"max_stars_repo_path": "Cubical/Relation/Binary/Construct/Always.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 264,
"size": 967
} |
module Prelude where
open import Data.Nat
open import Data.Unit
open import Data.Product
_^_ : Set → ℕ → Set
A ^ zero = ⊤
-- A ^ 1 = A
A ^ suc n = A × (A ^ n)
ℜⁿ : {A B : Set} → (A → B → Set) → (n : ℕ) → (A ^ n → B ^ n → Set)
ℜⁿ r zero = λ tt tt → ⊤
ℜⁿ r (suc n) = λ { (a , aⁿ) (b , bⁿ) → r a b × (ℜⁿ r n) aⁿ bⁿ }
𝔉ⁿ : {A B : Set} → (A → B) → (n : ℕ) → (A ^ n → B ^ n)
𝔉ⁿ f zero = λ tt → tt
𝔉ⁿ f (suc n) = λ { (a , aⁿ) → f a , 𝔉ⁿ f n aⁿ }
| {
"alphanum_fraction": 0.4582392777,
"avg_line_length": 23.3157894737,
"ext": "agda",
"hexsha": "e7f983871dab18c5d99fe0fae0c709c158ab4bfc",
"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": "6cd093011923758a21663bc32b5a63ce7893e049",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "vikraman/agda-structures",
"max_forks_repo_path": "Prelude.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6cd093011923758a21663bc32b5a63ce7893e049",
"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": "vikraman/agda-structures",
"max_issues_repo_path": "Prelude.agda",
"max_line_length": 66,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6cd093011923758a21663bc32b5a63ce7893e049",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "vikraman/agda-structures",
"max_stars_repo_path": "Prelude.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 237,
"size": 443
} |
data _≡_ {ℓ} {A : Set ℓ} (x : A) : A → Set ℓ where
refl : x ≡ x
data ℕ : Set where
zero : ℕ
succ : ℕ → ℕ
record Stream (A : Set) : Set where
constructor stream
field
start : A
next : A → A
open Stream
ℕ-stream : Stream ℕ
start ℕ-stream = zero
next ℕ-stream n = succ n
0th : {A : Set} → Stream A → A
0th s = start s
3rd : {A : Set} → Stream A → A
3rd s = next s (next s (next s (start s)))
_ : 0th ℕ-stream ≡ zero
_ = refl
_ : 3rd ℕ-stream ≡ succ (succ (succ zero))
_ = refl
| {
"alphanum_fraction": 0.572,
"avg_line_length": 16.1290322581,
"ext": "agda",
"hexsha": "095a76751c32a4690458a4cd5757a5ea9a306342",
"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": "9576d5b76e6a868992dbe52930712ac67697bed2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "anqurvanillapy/fpl",
"max_forks_repo_path": "agda/Stream.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9576d5b76e6a868992dbe52930712ac67697bed2",
"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": "anqurvanillapy/fpl",
"max_issues_repo_path": "agda/Stream.agda",
"max_line_length": 50,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9576d5b76e6a868992dbe52930712ac67697bed2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "anqurvanillapy/fpl",
"max_stars_repo_path": "agda/Stream.agda",
"max_stars_repo_stars_event_max_datetime": "2019-08-24T22:47:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-24T22:47:47.000Z",
"num_tokens": 195,
"size": 500
} |
-- Andreas, 2017-12-04, Re: issue #2862, reported by m0davis,
-- Make sure there is similar problem with functions.
open import Agda.Builtin.Equality
data Bool : Set where
true false : Bool
val : Bool
module M where
val = true -- Should fail
val≡true : val ≡ true
val≡true = refl
val = false
data ⊥ : Set where
¬val≡true : val ≡ true → ⊥
¬val≡true ()
boom : ⊥
boom = ¬val≡true Z.val≡true
| {
"alphanum_fraction": 0.6600985222,
"avg_line_length": 15.6153846154,
"ext": "agda",
"hexsha": "cc234faa45b5739dffa8e0f63ebf5476e6bf33f9",
"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/Issue2862fun.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/Issue2862fun.agda",
"max_line_length": 61,
"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/Issue2862fun.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": 141,
"size": 406
} |
------------------------------------------------------------------------------
-- Testing the η-expansion
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module Eta2 where
postulate
D : Set
∃ : (A : D → Set) → Set
_≡_ : D → D → Set
-- Due to η-contraction the Agda internal representation of foo and
-- bar are the same. We η-expand the internal types before the
-- translation to FOL.
postulate
foo : ∀ d → ∃ (λ e → d ≡ e)
bar : ∀ d → ∃ (_≡_ d)
{-# ATP prove foo #-}
{-# ATP prove bar #-}
| {
"alphanum_fraction": 0.4297752809,
"avg_line_length": 27.3846153846,
"ext": "agda",
"hexsha": "1d4f5ddf199bd80368cd82960d0308dfa51ee718",
"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/Eta2.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/Eta2.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/Eta2.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": 169,
"size": 712
} |
module Day1 where
open import Data.String as String
open import Data.Maybe
open import Foreign.Haskell using (Unit)
open import Data.List as List
open import Data.Nat
import Data.Nat.Show as ℕs
open import Data.Char
open import Data.Vec as Vec renaming (_>>=_ to _VV=_ ; toList to VecToList)
open import Data.Product
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
open import Data.Nat.Properties
open import Data.Bool.Base
open import AocIO
open import AocUtil
open import AocVec
makePairs : {A : Set} → {N : ℕ } → Vec A (suc N) → Vec (A × A) N
makePairs (x ∷ y ∷ vs) = ( ( x , y )) ∷ makePairs (y ∷ vs)
makePairs (x ∷ []) = []
makeNPairs : {A : Set} → {M : ℕ} → (N : ℕ) → Vec A (N + M) → Vec (A × A) M
makeNPairs {M = M} N vs with (Vec.drop N vs)
... | ends rewrite (+-comm N M) with (Vec.take M vs)
... | starts = Vec.zip starts ends
neighbours : {A : Set} → {N : ℕ} → Vec A N → Vec (A × A) N
neighbours [] = []
neighbours (x ∷ vs) with (dupFrontToBack (x ∷ vs))
... | dvs = makePairs dvs
halfwayNeighbours : {A : Set} → (N : ℕ) → Vec A (N + N) → Vec (A × A) (N + N)
halfwayNeighbours 0 [] = []
halfwayNeighbours (suc N) v with (dupFirstNToBack (suc N) v)
... | dupped with (makeNPairs (suc N) dupped)
... | pairs = pairs
parseDigits : List Char → Maybe (List ℕ)
parseDigits [] = Maybe.just []
parseDigits (c ∷ cs) with (toDigit c) | (parseDigits cs)
... | (just n) | (just ns) = just (n ∷ ns)
... | _ | _ = nothing
onlyKeepPairs : List (ℕ × ℕ) → List (ℕ × ℕ)
onlyKeepPairs [] = []
onlyKeepPairs ((a , b) ∷ xs) with (a Data.Nat.≟ b)
... | yes p = (a , b) ∷ onlyKeepPairs xs
... | no ¬p = onlyKeepPairs xs
main2 : IO Unit
main2 = mainBuilder (readFileMain processFile)
where
processDigits : {M : ℕ} → Vec ℕ M → IO Unit
processDigits vs with (neighbours vs)
... | neigh with (onlyKeepPairs (VecToList neigh))
... | pairs with (List.map Σ.proj₁ pairs)
... | nums = putStrLn (toCostring (ℕs.show (List.sum nums)))
processLine : List Char → IO Unit
processLine ls with (parseDigits ls)
... | nothing = putStrLn (toCostring ("Failed to parse this line: " String.++ (String.fromList ls)))
... | just digs = processDigits (Vec.fromList digs)
processFile : String → IO Unit
processFile file-content with (lines (String.toList file-content))
... | file-lines with (List.map processLine file-lines)
... | ops = void (sequence-io-prim ops)
checkEvenVec : ∀ {a} {A : Set a} → {N : ℕ} → Vec A N → Maybe (Σ[ M ∈ ℕ ] M + M ≡ N)
checkEvenVec [] = just (0 , refl)
checkEvenVec (x ∷ []) = nothing
checkEvenVec { N = N} (x ∷ y ∷ vs) with (checkEvenVec vs)
... | nothing = nothing
... | just (M , p) with (cong suc (+-suc M M))
... | t rewrite p = just ((suc M) , t)
main : IO Unit
main = mainBuilder (readFileMain processFile)
where
processDigits : {N : ℕ} → Vec ℕ N → IO Unit
processDigits vs with (checkEvenVec vs)
... | nothing = printString "Input has to have even length"
... | just (M , p) with (halfwayNeighbours M v)
where
v : Vec ℕ (M + M)
v rewrite p = vs
... | half-neigh with (onlyKeepPairs (VecToList half-neigh))
... | pairs with (List.map Σ.proj₁ pairs)
... | nums = printString (ℕs.show (List.sum nums))
processLine : List Char → IO Unit
processLine ls with (parseDigits ls)
... | nothing = putStrLn (toCostring ("Failed to parse this line: " String.++ (String.fromList ls)))
... | just digs = processDigits (Vec.fromList digs)
processFile : String → IO Unit
processFile file-content with (lines (String.toList file-content))
... | file-lines with (List.map processLine file-lines)
... | ops = void (sequence-io-prim ops)
| {
"alphanum_fraction": 0.5861376193,
"avg_line_length": 39.4257425743,
"ext": "agda",
"hexsha": "470c6e07362ca8914f0f0c8e5767822109ea3642",
"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": "37956e581dc51bf78008d7dd902bb18d2ee481f6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Zalastax/adventofcode2017",
"max_forks_repo_path": "day-1/Day1.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "37956e581dc51bf78008d7dd902bb18d2ee481f6",
"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": "Zalastax/adventofcode2017",
"max_issues_repo_path": "day-1/Day1.agda",
"max_line_length": 108,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "37956e581dc51bf78008d7dd902bb18d2ee481f6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Zalastax/adventofcode2017",
"max_stars_repo_path": "day-1/Day1.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1173,
"size": 3982
} |
module UnifyFin where
open import Data.Fin using (Fin; suc; zero)
open import Data.Nat using (ℕ; suc; zero)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong₂; cong; sym; trans)
open import Function using (_∘_)
open import Relation.Nullary using (¬_; Dec; yes; no)
open import Data.Product using (∃; _,_; _×_)
open import Data.Empty using (⊥-elim)
thin : ∀ {n} -> (x : Fin (suc n)) (y : Fin n) -> Fin (suc n)
thin zero y = suc y
thin (suc x) zero = zero
thin (suc x) (suc y) = suc (thin x y)
p : ∀ {n} -> Fin (suc (suc n)) -> Fin (suc n)
p (suc x) = x
p zero = zero
module Thin where
fact1 : ∀ {n} x y z -> thin {n} x y ≡ thin x z -> y ≡ z
fact1 zero y .y refl = refl
fact1 (suc x) zero zero r = refl
fact1 (suc x) zero (suc z) ()
fact1 (suc x) (suc y) zero ()
fact1 (suc x) (suc y) (suc z) r = cong suc (fact1 x y z (cong p r))
fact2 : ∀ {n} x y -> ¬ thin {n} x y ≡ x
fact2 zero y ()
fact2 (suc x) zero ()
fact2 (suc x) (suc y) r = fact2 x y (cong p r)
fact3 : ∀{n} x y -> ¬ x ≡ y -> ∃ λ y' -> thin {n} x y' ≡ y
fact3 zero zero ne = ⊥-elim (ne refl)
fact3 zero (suc y) _ = y , refl
fact3 {zero} (suc ()) _ _
fact3 {suc n} (suc x) zero ne = zero , refl
fact3 {suc n} (suc x) (suc y) ne with y | fact3 x y (ne ∘ cong suc)
... | .(thin x y') | y' , refl = suc y' , refl
open import Data.Maybe
open import Category.Functor
open import Category.Monad
import Level
open RawMonad (Data.Maybe.monad {Level.zero})
thick : ∀ {n} -> (x y : Fin (suc n)) -> Maybe (Fin n)
thick zero zero = nothing
thick zero (suc y) = just y
thick {zero} (suc ()) _
thick {suc _} (suc x) zero = just zero
thick {suc _} (suc x) (suc y) = suc <$> (thick x y)
open import Data.Sum
_≡Fin_ : ∀ {n} -> (x y : Fin n) -> Dec (x ≡ y)
zero ≡Fin zero = yes refl
zero ≡Fin suc y = no λ ()
suc x ≡Fin zero = no λ ()
suc {suc _} x ≡Fin suc y with x ≡Fin y
... | yes r = yes (cong suc r)
... | no r = no λ e -> r (cong p e)
suc {zero} () ≡Fin _
module Thick where
half1 : ∀ {n} (x : Fin (suc n)) -> thick x x ≡ nothing
half1 zero = refl
half1 {suc _} (suc x) = cong (_<$>_ suc) (half1 x)
half1 {zero} (suc ())
half2 : ∀ {n} (x : Fin (suc n)) y -> ∀ y' -> thin x y' ≡ y -> thick x y ≡ just y'
half2 zero zero y' ()
half2 zero (suc y) .y refl = refl
half2 {suc n} (suc x) zero zero refl = refl
half2 {suc _} (suc _) zero (suc _) ()
half2 {suc n} (suc x) (suc y) zero ()
half2 {suc n} (suc x) (suc .(thin x y')) (suc y') refl with thick x (thin x y') | half2 x (thin x y') y' refl
... | .(just y') | refl = refl
half2 {zero} (suc ()) _ _ _
fact1 : ∀ {n} (x : Fin (suc n)) y r
-> thick x y ≡ r
-> x ≡ y × r ≡ nothing ⊎ ∃ λ y' -> thin x y' ≡ y × r ≡ just y'
fact1 x y .(thick x y) refl with x ≡Fin y
fact1 x .x ._ refl | yes refl = inj₁ (refl , half1 x)
... | no el with Thin.fact3 x y el
... | y' , thinxy'=y = inj₂ (y' , ( thinxy'=y , half2 x y y' thinxy'=y ))
| {
"alphanum_fraction": 0.5435643564,
"avg_line_length": 34.0449438202,
"ext": "agda",
"hexsha": "54ff792af70e23ec5c508143fd6cfce3bbb41acc",
"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/UnifyFin.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/UnifyFin.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-1/UnifyFin.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1212,
"size": 3030
} |
module SET where
----------------------------------------------------------------------------
-- Auxiliary.
----------------------------------------------------------------------------
data Fun (X Y : Set) : Set where
fun : (X -> Y) -> Fun X Y
{-
Unop : Set -> Set
Unop X = Fun X X
Binop : Set -> Set
Binop X = Fun X (Fun X X)
-}
-- We need to replace Pred X by its RHS (less readable!)
-- Pred : Set -> Set1
-- Pred X = X -> Set
-- Pow = Pred
-- Rel : Set -> Set1
-- Rel X = X -> X -> Set
data Reflexive {X : Set} (R : X -> X -> Set) : Set where
reflexive : ((x : X) -> R x x) -> Reflexive R
data Symmetrical {X : Set} (R : X -> X -> Set) : Set where
symmetrical : ( {x1 x2 : X} -> R x1 x2 -> R x2 x1) -> Symmetrical R
{-
Transitive {X : Set}(R : X -> X -> Set) : Set
= (x1 x2 x3 : X) |-> R x1 x2 -> R x2 x3 -> R x1 x3
Compositional {X : Set}(R : X -> X -> Set) : Set
= (x1 : X) |-> (x2 : X) |-> (x3 : X) |-> R x2 x3 -> R x1 x2 -> R x1 x3
-}
data Substitutive {X : Set} (R : X -> X -> Set) : Set1 where
substitutive : ( (P : X -> Set) -> {x1 x2 : X} -> R x1 x2 -> P x1 -> P x2)
-> Substitutive R
{-
Collapsed (X : Set) : Set1
= (P : X -> Set) -> (x1 x2 : X) |-> P x1 -> P x2
id {X : Set} : X -> X
= \x -> x
cmp (|X |Y |Z : Set) : (Y -> Z) -> (X -> Y) -> X -> Z
= \f -> \g -> \x -> f (g x)
seq (|X |Y |Z : Set)(f : X -> Y)(g : Y -> Z) : X -> Z
= cmp g f
const (|X |Y : Set)(x : X)(y : Y) : X
= x
proj {X : Set}(Y : X -> Set)(x : X)(f : (x : X) -> Y x) : Y x
= f x
flip {X : Set}{Y : Set}{Z : Set}(f : X -> Y -> Z)(y : Y)(x : X) : Z
= f x y
FlipRel {X : Set}(R : X -> X -> Set)(x1 : X)(x2 : X) : Set
= R x2 x1
----------------------------------------------------------------------------
-- Product sets.
----------------------------------------------------------------------------
Prod (X : Set)(Y : X -> Set) : Set
= (x : X) -> Y x
mapProd {X : Set}
{Y1 : X -> Set}
{Y2 : X -> Set}
(f : (x : X) -> Y1 x -> Y2 x)
: Prod X Y1 -> Prod X Y2
= \g -> \x -> f x (g x)
-- Fun(X : Set)(Y : Set) = X -> Y
mapFun (|X1 |X2 |Y1 |Y2 : Set)
: (X2 -> X1) -> (Y1 -> Y2) -> (X1 -> Y1) -> X2 -> Y2
= \f -> \g -> \h -> \x ->
g (h (f x))
----------------------------------------------------------------------------
-- Identity proof sets.
----------------------------------------------------------------------------
Id {X : Set} : X -> X -> Set
= idata ref (x : X) : _ x x
refId {X : Set} : Reflexive Id
= \(x : X) -> ref@_ x
elimId (|X : Set)
(C : (x1 x2 : X) |-> Id x1 x2 -> Set)
(refC : (x : X) -> C (refId x))
(|x1 |x2 : X)
(u : Id x1 x2) :
C u
= case u of { (ref x) -> refC x;}
abstract whenId {X : Set}(C : X -> X -> Set)(c : (x : X) -> C x x)
: (x1 x2 : X) |-> Id x1 x2 -> C x1 x2
= elimId (\x1 x2 |-> \(u : Id x1 x2) -> C x1 x2) c
abstract substId {X : Set} : Substitutive Id
= \(C : X -> Set) ->
whenId (\x1 x2 -> C x1 -> C x2) (\x -> id)
abstract mapId {X : Set}{Y : Set}(f : X -> Y)
: (x1 x2 : X) |-> Id x1 x2 -> Id (f x1) (f x2)
= whenId (\x1 x2 -> Id (f x1) (f x2)) (\(x : X) -> refId (f x))
abstract symId {X : Set} : Symmetrical Id
= whenId (\(x1 x2 : X) -> Id x2 x1) refId
abstract cmpId {X : Set} : Compositional Id
= let lem : (x y : X) |-> Id x y -> (z : X) |-> Id z x -> Id z y
= whenId ( \(x y : _) -> (z : X) |-> Id z x -> Id z y)
( \x -> \z |-> id)
in \(x1 x2 x3 : _) |->
\(u : Id x2 x3) ->
\(v : Id x1 x2) ->
lem u v
abstract tranId {X : Set} : Transitive Id
= \(x1 x2 x3 : X) |->
\(u : Id x1 x2) ->
\(v : Id x2 x3) ->
cmpId v u
----------------------------------------------------------------------------
-- The empty set.
----------------------------------------------------------------------------
-}
data Zero : Set where
{-
abstract whenZero (X : Set)(z : Zero) : X
= case z of { }
elimZero (C : Zero -> Set)(z : Zero) : C z
= case z of { }
abstract collZero : Collapsed Zero
= \(C : Zero -> Set) ->
\(z1 z2 : Zero) |->
\(c : C z1) ->
case z1 of { }
----------------------------------------------------------------------------
-- The singleton set.
----------------------------------------------------------------------------
-}
data Unit : Set where
unit : Unit
{-
elUnit = tt
elimUnit (C : Unit -> Set)(c_tt : C tt@_)(u : Unit) : C u
= case u of { (tt) -> c_tt;}
abstract collUnit : Collapsed Unit
= \(C : Unit -> Set) ->
\(u1 u2 : Unit) |->
\(c : C u1) ->
case u1 of { (tt) -> case u2 of { (tt) -> c;};}
----------------------------------------------------------------------------
-- The successor set adds a new element.
----------------------------------------------------------------------------
Succ (X : Set) : Set
= data zer | suc (x : X)
zerSucc {X : Set} : Succ X
= zer@_
sucSucc {X : Set}(x : X) : Succ X
= suc@_ x
elimSucc {X : Set}
(C : Succ X -> Set)
(c_z : C zer@_)
(c_s : (x : X) -> C (suc@_ x))
(x' : Succ X)
: C x'
= case x' of {
(zer) -> c_z;
(suc x) -> c_s x;}
whenSucc (|X |Y : Set)(y_z : Y)(y_s : X -> Y)(x' : Succ X) : Y
= case x' of {
(zer) -> y_z;
(suc x) -> y_s x;}
mapSucc (|X |Y : Set)(f : X -> Y) : Succ X -> Succ Y
= whenSucc zer@(Succ Y) (\(x : X) -> suc@_ (f x)) -- (Succ Y)
----------------------------------------------------------------------------
-- The (binary) disjoint union.
----------------------------------------------------------------------------
data Plus (X Y : Set) = inl (x : X) | inr (y : Y)
elimPlus (|X |Y : Set)
(C : Plus X Y -> Set)
(c_lft : (x : X) -> C (inl@_ x))
(c_rgt : (y : Y) -> C (inr@_ y))
(xy : Plus X Y)
: C xy
= case xy of {
(inl x) -> c_lft x;
(inr y) -> c_rgt y;}
when (|X |Y |Z : Set)(f : X -> Z)(g : Y -> Z) : Plus X Y -> Z
= \xy -> case xy of {
(inl x) -> f x;
(inr y) -> g y;}
whenPlus = when
mapPlus (|X1 |X2 |Y1 |Y2 : Set)(f : X1 -> X2)(g : Y1 -> Y2)
: Plus X1 Y1 -> Plus X2 Y2
= when (\x1 -> inl (f x1)) (\y1 -> inr (g y1))
swapPlus (|X |Y : Set) : Plus X Y -> Plus Y X
= when inr inl
----------------------------------------------------------------------------
-- Dependent pairs.
----------------------------------------------------------------------------
Sum (X : Set)(Y : X -> Set) : Set
= sig{fst : X;
snd : Y fst;}
dep_pair {X : Set}{Y : X -> Set}(x : X)(y : Y x) : Sum X Y
= struct {fst = x; snd = y;}
dep_fst {X : Set}{Y : X -> Set}(xy : Sum X Y) : X
= xy.fst
dep_snd {X : Set}{Y : X -> Set}(xy : Sum X Y) : Y (dep_fst xy)
= xy.snd
dep_cur {X : Set}{Y : X -> Set}{Z : Set}(f : Sum X Y -> Z)
: (x : X) |-> Y x -> Z
= \x |-> \y -> f (dep_pair x y)
dep_uncur {X : Set}{Y : X -> Set}{Z : Set}
: ((x : X) -> Y x -> Z) -> Sum X Y -> Z
= \(f : (x : X) -> (x' : Y x) -> Z) -> \(xy : Sum X Y) -> f xy.fst xy.snd
dep_curry {X : Set}
{Y : X -> Set}
(Z : Sum X Y -> Set)
(f : (xy : Sum X Y) -> Z xy)
: (x : X) -> (y : Y x) -> Z (dep_pair x y)
= \(x : X) -> \(y : Y x) -> f (dep_pair x y)
dep_uncurry {X : Set}
{Y : X -> Set}
(Z : Sum X Y -> Set)
(f : (x : X) ->
(y : Y x) ->
Z (dep_pair x y))
(xy : Sum X Y)
: Z xy
= f xy.fst xy.snd
mapSum {X : Set}{Y1 : X -> Set}{Y2 : X -> Set}(f : (x : X) -> Y1 x -> Y2 x)
: Sum X Y1 -> Sum X Y2
= \(p : Sum X Y1) -> dep_pair p.fst (f p.fst p.snd)
elimSum = dep_uncurry
----------------------------------------------------------------------------
-- Nondependent pairs (binary) cartesian product.
----------------------------------------------------------------------------
Times (X : Set)(Y : Set) : Set
= Sum X (\(x : X) -> Y)
pair {X : Set}{Y : Set} : X -> Y -> Times X Y
= \(x : X) ->
\(y : Y) ->
struct {
fst = x;
snd = y;}
fst {X : Set}{Y : Set} : Times X Y -> X
= \(xy : Times X Y) -> xy.fst
snd {X : Set}{Y : Set} : Times X Y -> Y
= \(xy : Times X Y) -> xy.snd
pairfun {X : Set}{Y : Set}{Z : Set}(f : X -> Y)(g : X -> Z)(x : X)
: Times Y Z
= pair (f x) (g x)
mapTimes {X1 : Set}{X2 : Set}{Y1 : Set}{Y2 : Set}
: (f : X1 -> X2) -> (g : Y1 -> Y2) -> Times X1 Y1 -> Times X2 Y2
= \(f : (x : X1) -> X2) ->
\(g : (x : Y1) -> Y2) ->
\(xy : Times X1 Y1) ->
pair (f xy.fst) (g xy.snd)
swapTimes {X : Set}{Y : Set} : Times X Y -> Times Y X
= pairfun snd fst
cur {X : Set}{Y : Set}{Z : Set}(f : Times X Y -> Z) : X -> Y -> Z
= \(x : X) -> \(y : Y) -> f (pair |_ |_ x y)
uncur {X : Set}{Y : Set}{Z : Set}(f : X -> Y -> Z) : Times X Y -> Z
= \(xy : Times X Y) -> f xy.fst xy.snd
curry {X : Set}
{Y : Set}
{Z : Times X Y -> Set}
(f : (xy : Times X Y) -> Z xy)
: (x : X) ->
(y : Y) ->
Z (pair |_ |_ x y)
= \(x : X) ->
\(y : Y) ->
f (pair |_ |_ x y)
uncurry {X : Set}
{Y : Set}
{Z : Times X Y -> Set}
(f : (x : X) ->
(y : Y) ->
Z (pair |_ |_ x y))
: (xy : Times X Y) -> Z xy
= \(xy : Times X Y) -> f xy.fst xy.snd
elimTimes = uncurry
----------------------------------------------------------------------------
-- Natural numbers.
----------------------------------------------------------------------------
Nat : Set
= data zer | suc (m : Nat)
zero : Nat
= zer@_
succ (x : Nat) : Nat
= suc@_ x
elimNat (C : Nat -> Set)
: (c_z : C zer@_) ->
(c_s : (x : Nat) -> C x -> C (suc@_ x)) ->
(m : Nat) ->
C m
= \(c_z : C zer@_) ->
\(c_s : (x : Nat) -> (x' : C x) -> C (suc@_ x)) ->
\(m : Nat) ->
case m of {
(zer) -> c_z;
(suc m') -> c_s m' (elimNat C c_z c_s m');}
----------------------------------------------------------------------------
-- Linear universe of finite sets.
----------------------------------------------------------------------------
Fin (m : Nat) : Set
= case m of {
(zer) -> Zero;
(suc m') -> Succ (Fin m');}
valFin (m : Nat) : Fin m -> Nat
= \(n : Fin m) ->
case m of {
(zer) -> case n of { };
(suc m') ->
case n of {
(zer) -> zer@_;
(suc n') -> suc@_ (valFin m' n');};}
zeroFin (m : Nat) : Fin (succ m)
= zer@_
succFin (m : Nat)(n : Fin m) : Fin (succ m)
= suc@_ n
----------------------------------------------------------------------------
-- Do these really belong here?
----------------------------------------------------------------------------
HEAD (X : Set1)(m : Nat)(f : Fin (succ m) -> X) : X
= f (zeroFin m)
TAIL (X : Set1)(m : Nat)(f : Fin (succ m) -> X) : Fin m -> X
= \(n : Fin m) -> f (succFin m n)
----------------------------------------------------------------------------
-- Lists.
----------------------------------------------------------------------------
List (X : Set) : Set
= data nil | con (x : X) (xs : List X)
nil {X : Set} : List X
= nil@_
con {X : Set}(x : X)(xs : List X) : List X
= con@_ x xs
elimList {X : Set}
(C : List X -> Set)
(c_nil : C (nil |_))
(c_con : (x : X) -> (xs : List X) -> C xs -> C (con@_ x xs))
(xs : List X)
: C xs
= case xs of {
(nil) -> c_nil;
(con x xs') -> c_con x xs' (elimList |_ C c_nil c_con xs');}
----------------------------------------------------------------------------
-- Tuples are "dependently typed vectors".
----------------------------------------------------------------------------
Nil : Set
= data nil
Con (X0 : Set)(X' : Set) : Set
= data con (x : X0) (xs : X')
Tuple (m : Nat)(X : Fin m -> Set) : Set
= case m of {
(zer) -> Nil;
(suc m') -> Con (X zer@_) (Tuple m' (\(n : Fin m') -> X (suc@_ n)));}
----------------------------------------------------------------------------
-- Vectors homogeneously typed tuples.
----------------------------------------------------------------------------
Vec (X : Set)(m : Nat) : Set
= Tuple m (\(n : Fin m) -> X)
----------------------------------------------------------------------------
-- Monoidal expressions.
----------------------------------------------------------------------------
Mon (X : Set) : Set
= data unit | at (x : X) | mul (xs1 : Mon X) (xs2 : Mon X)
----------------------------------------------------------------------------
-- Propositions.
----------------------------------------------------------------------------
Imply (X : Set)(Y : Set) : Set
= X -> Y
-}
Absurd : Set
Absurd = Zero
Taut : Set
Taut = Unit
{-
Not (X : Set) : Set
= X -> Absurd
Exist {X : Set}(P : X -> Set) : Set
= Sum X P
Forall (X : Set)(P : X -> Set) : Set
= (x : X) -> P x
And (X : Set)(Y : Set) : Set
= Times X Y
Iff (X : Set)(Y : Set) : Set
= And (Imply X Y) (Imply Y X)
Or (X : Set)(Y : Set) : Set
= Plus X Y
Decidable (X : Set) : Set
= Or X (Imply X Absurd)
DecidablePred {X : Set}(P : X -> Set) : Set
= (x : X) -> Decidable (P x)
DecidableRel {X : Set}(R : X -> X -> Set) : Set
= (x1 : X) -> (x2 : X) -> Decidable (R x1 x2)
Least {X : Set}((<=) : X -> X -> Set)(P : X -> Set) : X -> Set
= \(x : X) -> And (P x) ((x' : X) -> P x' -> (x <= x'))
Greatest {X : Set}((<=) : X -> X -> Set)(P : X -> Set) : X -> Set
= \(x : X) -> And (P x) ((x' : X) -> P x' -> (x' <= x))
----------------------------------------------------------------------------
-- Booleans.
----------------------------------------------------------------------------
-}
data Bool : Set where
true : Bool
false : Bool
{-
elimBool (C : Bool -> Set)(c_t : C true@_)(c_f : C false@_)(p : Bool)
: C p
= case p of {
(true) -> c_t;
(false) -> c_f;}
whenBool (C : Set)(c_t : C)(c_f : C) : Bool -> C
= elimBool (\(x : Bool) -> C) c_t c_f
pred (X : Set) : Set
= X -> Bool
-}
-- rel (X : Set) : Set
-- = X -> X -> Bool
True : Bool -> Set
True (true) = Taut
True (false) = Absurd
{-
bool2set = True
pred2Pred {X : Set} : pred X -> X -> Set
= \(p : pred X) -> \(x : X) -> True (p x)
rel2Rel {X : Set} : (X -> X -> Bool) -> X -> X -> Set
= \(r : (X -> X -> Bool)) -> \(x : X) -> \(y : X) -> True (r x y)
decTrue (p : Bool) : Decidable (True p)
= case p of {
(true) -> inl@_ tt;
(false) -> inr@_ (id |_);}
abstract dec_lem {P : Set}(decP : Decidable P)
: Exist |_ (\(b : Bool) -> Iff (True b) P)
= case decP of {
(inl trueP) ->
struct {
fst = true@_;
snd =
struct {
fst = const |_ |_ trueP; -- (True true@_)
snd = const |_ |_ tt;};};
(inr notP) ->
struct {
fst = false@_;
snd =
struct {
fst = whenZero P;
snd = notP;};};}
dec2bool : (P : Set) |-> (decP : Decidable P) -> Bool
= \(P : Set) |-> \(decP : Decidable P) -> (dec_lem |_ decP).fst
dec2bool_spec {P : Set}(decP : Decidable P)
: Iff (True (dec2bool |_ decP)) P
= (dec_lem |_ decP).snd
abstract collTrue : (b : Bool) -> Collapsed (True b)
= let aux (X : Set)(C : X -> Set)
: (b : Bool) ->
(f : True b -> X) ->
(t1 : True b) |->
(t2 : True b) |->
C (f t1) -> C (f t2)
= \(b : Bool) ->
case b of {
(true) ->
\(f : (x : True true@_) -> X) ->
\(t1 t2 : True true@_) |->
\(c : C (f t1)) ->
case t1 of { (tt) -> case t2 of { (tt) -> c;};};
(false) ->
\(f : (x : True false@_) -> X) ->
\(t1 t2 : True false@_) |->
\(c : C (f t1)) ->
case t1 of { };}
in \(b : Bool) -> \(P : True b -> Set) -> aux (True b) P b id
bool2nat (p : Bool) : Nat
= case p of {
(true) -> succ zero;
(false) -> zero;}
----------------------------------------------------------------------------
-- Decidable subsets.
----------------------------------------------------------------------------
Filter {X : Set}(p : pred X) : Set
= Sum X (pred2Pred |_ p)
----------------------------------------------------------------------------
-- Equality.
----------------------------------------------------------------------------
-- "Deq" stands for "datoid equality" and represents exactly the data
-- that has to be added to turn a set into a datoid.
Deq (X : Set) : Set1
= sig{eq : X -> X -> Bool;
ref : (x : X) -> True (eq x x);
subst :
(C : X -> Set) -> (x1 x2 : X)|-> True (eq x1 x2) -> C x1 -> C x2;}
-- The "Equality" type represents the data that has to be added to turna
-- set into a setoid.
Equality (X : Set) : Set1
= sig{Equal : X -> X -> Set;
ref : Reflexive |_ Equal;
sym : Symmetrical |_ Equal;
tran : Transitive |_ Equal;}
-}
data Datoid : Set1 where
datoid : (Elem : Set) ->
(eq : Elem -> Elem -> Bool) ->
(ref : (x : Elem) -> True (eq x x)) ->
(subst : Substitutive (\x1 -> \x2 -> True (eq x1 x2))) ->
Datoid
pElem : Datoid -> Set
pElem (datoid Elem _ _ _) = Elem
{-
ElD (X : Datoid) : Set
= X.Elem
eqD {X : Datoid} : ElD X -> ElD X -> Bool
= X.eq
EqD {X : Datoid}(x1 x2 : ElD X) : Set
= True (X.eq x1 x2)
Setoid : Set1
= sig{Elem : Set;
Equal : Elem -> Elem -> Set;
ref : (x : Elem) -> Equal x x;
sym : (x1 : Elem) |-> (x2 : Elem) |-> Equal x1 x2 -> Equal x2 x1;
tran :
(x1 : Elem) |->
(x2 : Elem) |->
(x3 : Elem) |->
Equal x1 x2 -> Equal x2 x3 -> Equal x1 x3;}
El (X : Setoid) : Set
= X.Elem
Eq {X : Setoid} : Rel (El X)
= X.Equal
NotEq {X : Setoid} : Rel (El X)
= \x1-> \x2-> Not (Eq |X x1 x2)
Respectable {X : Setoid}(P : El X -> Set) : Set
= (x1 x2 : El X) |-> Eq |X x1 x2 -> P x1 -> P x2
RspEq {X Y : Setoid}(f : El X -> El Y) : Set
= (x1 x2 : El X) |-> Eq |X x1 x2 -> Eq |Y (f x1) (f x2)
RspEq2 (|X |Y |Z : Setoid)(f : El X -> El Y -> El Z)
: Set
= (x1 x2 : X.Elem) |-> (y1 y2 : Y.Elem) ->
Eq |X x1 x2 ->
Eq |Y y1 y2 ->
Eq |Z (f x1 y1) (f x2 y2)
D2S (Y : Datoid) : Setoid
= struct {
Elem = Y.Elem;
Equal = \(x1 x2 : Elem) -> True (Y.eq x1 x2);
ref = Y.ref;
sym =
\(x1 x2 : Elem) |->
\(u : Equal x1 x2) ->
Y.subst (\(x : Y.Elem) -> Equal x x1) |_ |_ u (ref x1);
tran =
\(x1 x2 x3 : Elem) |->
\(u : Equal x1 x2) ->
\(v : Equal x2 x3) ->
Y.subst (Equal x1) |_ |_ v u;}
{-# Alfa unfoldgoals off
brief on
hidetypeannots off
wide
nd
hiding on
con "nil" as "[]" with symbolfont
con "con" infix as " : " with symbolfont
var "Forall" as "\"" with symbolfont
var "Exist" as "$" with symbolfont
var "And" infix as "&" with symbolfont
var "Or" infix as "Ú" with symbolfont
var "Iff" infix as "«" with symbolfont
var "Not" as "Ø" with symbolfont
var "Imply" infix as "É" with symbolfont
var "Taut" as "T" with symbolfont
var "Absurd" as "^" with symbolfont
var "El" mixfix as "|_|" with symbolfont
var "Eq" distfix3 as "==" with symbolfont
var "NotEq" distfix3 as "=|=" with symbolfont
var "True" mixfix as "|_|" with symbolfont
var "ElD" mixfix as "|_|" with symbolfont
var "EqD" distfix3 as "==" with symbolfont
var "Id" distfix3 as "=" with symbolfont
#-}
-}
| {
"alphanum_fraction": 0.3539744412,
"avg_line_length": 33.6661129568,
"ext": "agda",
"hexsha": "2b5a95d3879921883e4bd90d0486ec3b2c606f9e",
"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": "examples/AIM5/Hedberg/SET.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": "examples/AIM5/Hedberg/SET.agda",
"max_line_length": 78,
"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": "examples/AIM5/Hedberg/SET.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": 6792,
"size": 20267
} |
module Membership where
open import OscarPrelude
open import Successor
record Membership {ℓ} (m : Set ℓ) (M : Set ℓ) : Set (⊹ ℓ)
where
field
_∈_ : m → M → Set ℓ
_∉_ : m → M → Set ℓ
xor-membership : ∀ {x : m} {X : M} → x ∈ X ←⊗→ x ∉ X
open Membership ⦃ … ⦄ public
data _∈List_ {ℓ} {A : Set ℓ} (a : A) : List A → Set ℓ
where
zero : {as : List A} → a ∈List (a ∷ as)
suc : {x : A} {as : List A} → a ∈List as → a ∈List (x ∷ as)
instance MembershipList : ∀ {ℓ} {A : Set ℓ} → Membership A $ List A
Membership._∈_ MembershipList = _∈List_
Membership._∉_ MembershipList x X = ¬ x ∈ X
Membership.xor-membership MembershipList = (λ x x₁ → x₁ x) , (λ x x₁ → x x₁)
instance SuccessorMembershipList : ∀ {ℓ} {A : Set ℓ} {a : A} {x : A} {as : List A} → Successor (a ∈ as) $ a ∈ (x List.∷ as)
Successor.⊹ SuccessorMembershipList = suc
_⊆_ : ∀ {ℓ} {m M : Set ℓ} ⦃ _ : Membership m M ⦄ → M → M → Set ℓ
_⊆_ {m = m} M₁ M₂ = ∀ {x : m} → x ∈ M₁ → x ∈ M₂
| {
"alphanum_fraction": 0.5651720542,
"avg_line_length": 30.935483871,
"ext": "agda",
"hexsha": "199a9bf8d66d8e653ad68937a51f2eeb93ed04f2",
"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/Membership.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/Membership.agda",
"max_line_length": 123,
"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/Membership.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 416,
"size": 959
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Intersection of two binary relations
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Binary.Construct.Intersection where
open import Data.Product
open import Data.Sum using (_⊎_; inj₁; inj₂; [_,_])
open import Function using (_∘_)
open import Level using (_⊔_)
open import Relation.Binary
open import Relation.Nullary using (yes; no)
------------------------------------------------------------------------
-- Definition
_∩_ : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b} →
REL A B ℓ₁ → REL A B ℓ₂ → REL A B (ℓ₁ ⊔ ℓ₂)
L ∩ R = λ i j → L i j × R i j
------------------------------------------------------------------------
-- Properties
module _ {a ℓ₁ ℓ₂} {A : Set a} (L : Rel A ℓ₁) (R : Rel A ℓ₂) where
reflexive : Reflexive L → Reflexive R → Reflexive (L ∩ R)
reflexive L-refl R-refl = L-refl , R-refl
symmetric : Symmetric L → Symmetric R → Symmetric (L ∩ R)
symmetric L-sym R-sym = map L-sym R-sym
transitive : Transitive L → Transitive R → Transitive (L ∩ R)
transitive L-trans R-trans = zip L-trans R-trans
respects : ∀ {p} (P : A → Set p) →
P Respects L ⊎ P Respects R → P Respects (L ∩ R)
respects P resp (Lxy , Rxy) = [ (λ x → x Lxy) , (λ x → x Rxy) ] resp
min : ∀ {⊤} → Minimum L ⊤ → Minimum R ⊤ → Minimum (L ∩ R) ⊤
min L-min R-min = < L-min , R-min >
max : ∀ {⊥} → Maximum L ⊥ → Maximum R ⊥ → Maximum (L ∩ R) ⊥
max L-max R-max = < L-max , R-max >
module _ {a b ℓ₁ ℓ₂ ℓ₃} {A : Set a} {B : Set b}
(≈ : REL A B ℓ₁) {L : REL A B ℓ₂} {R : REL A B ℓ₃} where
implies : (≈ ⇒ L) → (≈ ⇒ R) → ≈ ⇒ (L ∩ R)
implies ≈⇒L ≈⇒R = < ≈⇒L , ≈⇒R >
module _ {a b ℓ₁ ℓ₂ ℓ₃} {A : Set a} {B : Set b}
(≈ : REL A B ℓ₁) (L : REL A B ℓ₂) (R : REL A B ℓ₃) where
irreflexive : Irreflexive ≈ L ⊎ Irreflexive ≈ R → Irreflexive ≈ (L ∩ R)
irreflexive irrefl x≈y (Lxy , Rxy) = [ (λ x → x x≈y Lxy) , (λ x → x x≈y Rxy) ] irrefl
module _ {a ℓ₁ ℓ₂ ℓ₃} {A : Set a}
(≈ : Rel A ℓ₁) (L : Rel A ℓ₂) (R : Rel A ℓ₃) where
respectsˡ : L Respectsˡ ≈ → R Respectsˡ ≈ → (L ∩ R) Respectsˡ ≈
respectsˡ L-resp R-resp x≈y = map (L-resp x≈y) (R-resp x≈y)
respectsʳ : L Respectsʳ ≈ → R Respectsʳ ≈ → (L ∩ R) Respectsʳ ≈
respectsʳ L-resp R-resp x≈y = map (L-resp x≈y) (R-resp x≈y)
respects₂ : L Respects₂ ≈ → R Respects₂ ≈ → (L ∩ R) Respects₂ ≈
respects₂ (Lʳ , Lˡ) (Rʳ , Rˡ) = respectsʳ Lʳ Rʳ , respectsˡ Lˡ Rˡ
antisymmetric : Antisymmetric ≈ L ⊎ Antisymmetric ≈ R → Antisymmetric ≈ (L ∩ R)
antisymmetric (inj₁ L-antisym) (Lxy , _) (Lyx , _) = L-antisym Lxy Lyx
antisymmetric (inj₂ R-antisym) (_ , Rxy) (_ , Ryx) = R-antisym Rxy Ryx
module _ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b} {L : REL A B ℓ₁} {R : REL A B ℓ₂} where
decidable : Decidable L → Decidable R → Decidable (L ∩ R)
decidable L? R? x y with L? x y | R? x y
... | no ¬Lxy | _ = no (¬Lxy ∘ proj₁)
... | yes _ | no ¬Rxy = no (¬Rxy ∘ proj₂)
... | yes Lxy | yes Rxy = yes (Lxy , Rxy)
------------------------------------------------------------------------
-- Structures
module _ {a ℓ₁ ℓ₂} {A : Set a} {L : Rel A ℓ₁} {R : Rel A ℓ₂} where
isEquivalence : IsEquivalence L → IsEquivalence R → IsEquivalence (L ∩ R)
isEquivalence eqₗ eqᵣ = record
{ refl = reflexive L R Eqₗ.refl Eqᵣ.refl
; sym = symmetric L R Eqₗ.sym Eqᵣ.sym
; trans = transitive L R Eqₗ.trans Eqᵣ.trans
}
where module Eqₗ = IsEquivalence eqₗ; module Eqᵣ = IsEquivalence eqᵣ
isDecEquivalence : IsDecEquivalence L → IsDecEquivalence R → IsDecEquivalence (L ∩ R)
isDecEquivalence eqₗ eqᵣ = record
{ isEquivalence = isEquivalence Eqₗ.isEquivalence Eqᵣ.isEquivalence
; _≟_ = decidable Eqₗ._≟_ Eqᵣ._≟_
}
where module Eqₗ = IsDecEquivalence eqₗ; module Eqᵣ = IsDecEquivalence eqᵣ
module _ {a ℓ₁ ℓ₂ ℓ₃} {A : Set a} {≈ : Rel A ℓ₁} {L : Rel A ℓ₂} {R : Rel A ℓ₃} where
isPreorder : IsPreorder ≈ L → IsPreorder ≈ R → IsPreorder ≈ (L ∩ R)
isPreorder Oₗ Oᵣ = record
{ isEquivalence = Oₗ.isEquivalence
; reflexive = implies ≈ Oₗ.reflexive Oᵣ.reflexive
; trans = transitive L R Oₗ.trans Oᵣ.trans
}
where module Oₗ = IsPreorder Oₗ; module Oᵣ = IsPreorder Oᵣ
isPartialOrderˡ : IsPartialOrder ≈ L → IsPreorder ≈ R → IsPartialOrder ≈ (L ∩ R)
isPartialOrderˡ Oₗ Oᵣ = record
{ isPreorder = isPreorder Oₗ.isPreorder Oᵣ
; antisym = antisymmetric ≈ L R (inj₁ Oₗ.antisym)
}
where module Oₗ = IsPartialOrder Oₗ; module Oᵣ = IsPreorder Oᵣ
isPartialOrderʳ : IsPreorder ≈ L → IsPartialOrder ≈ R → IsPartialOrder ≈ (L ∩ R)
isPartialOrderʳ Oₗ Oᵣ = record
{ isPreorder = isPreorder Oₗ Oᵣ.isPreorder
; antisym = antisymmetric ≈ L R (inj₂ Oᵣ.antisym)
}
where module Oₗ = IsPreorder Oₗ; module Oᵣ = IsPartialOrder Oᵣ
isStrictPartialOrderˡ : IsStrictPartialOrder ≈ L →
Transitive R → R Respects₂ ≈ →
IsStrictPartialOrder ≈ (L ∩ R)
isStrictPartialOrderˡ Oₗ transᵣ respᵣ = record
{ isEquivalence = Oₗ.isEquivalence
; irrefl = irreflexive ≈ L R (inj₁ Oₗ.irrefl)
; trans = transitive L R Oₗ.trans transᵣ
; <-resp-≈ = respects₂ ≈ L R Oₗ.<-resp-≈ respᵣ
}
where module Oₗ = IsStrictPartialOrder Oₗ
isStrictPartialOrderʳ : Transitive L → L Respects₂ ≈ →
IsStrictPartialOrder ≈ R →
IsStrictPartialOrder ≈ (L ∩ R)
isStrictPartialOrderʳ transₗ respₗ Oᵣ = record
{ isEquivalence = Oᵣ.isEquivalence
; irrefl = irreflexive ≈ L R (inj₂ Oᵣ.irrefl)
; trans = transitive L R transₗ Oᵣ.trans
; <-resp-≈ = respects₂ ≈ L R respₗ Oᵣ.<-resp-≈
}
where module Oᵣ = IsStrictPartialOrder Oᵣ
| {
"alphanum_fraction": 0.5636828645,
"avg_line_length": 39.1,
"ext": "agda",
"hexsha": "bb4823e82991ad8cebfe0711a8f2eca586817fc1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Construct/Intersection.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Construct/Intersection.agda",
"max_line_length": 87,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/Construct/Intersection.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2309,
"size": 5865
} |
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.NType2
open import lib.types.Pi
open import lib.types.Group
{-
The definition of G-sets. Thanks to Daniel Grayson.
-}
module lib.types.GroupSet {i} where
-- The right group action with respect to the group [grp].
record GroupSetStructure (grp : Group i) {j} (El : Type j)
(_ : is-set El) : Type (lmax i j) where
constructor groupset-structure
private
module G = Group grp
module GS = GroupStructure G.group-struct
field
act : El → G.El → El
unit-r : ∀ x → act x GS.ident == x
assoc : ∀ x g₁ g₂ → act (act x g₁) g₂ == act x (GS.comp g₁ g₂)
-- The definition of a G-set. A set [El] equipped with
-- a right group action with respect to [grp].
record GroupSet (grp : Group i) j : Type (lsucc (lmax i j)) where
constructor groupset
field
El : Type j
El-level : is-set El
grpset-struct : GroupSetStructure grp El El-level
open GroupSetStructure grpset-struct public
El-is-set = El-level
-- A helper function to establish equivalence between two G-sets.
-- Many data are just props and this function do the coversion for them
-- for you. You only need to show the non-trivial parts.
module _ {grp : Group i} {j} {El : Type j} {El-level : is-set El} where
private
module G = Group grp
module GS = GroupStructure G.group-struct
open GroupSetStructure
private
groupset-structure=' : ∀ {gss₁ gss₂ : GroupSetStructure grp El El-level}
→ (act= : act gss₁ == act gss₂)
→ unit-r gss₁ == unit-r gss₂
[ (λ act → ∀ x → act x GS.ident == x) ↓ act= ]
→ assoc gss₁ == assoc gss₂
[ (λ act → ∀ x g₁ g₂ →
act (act x g₁) g₂ == act x (GS.comp g₁ g₂)) ↓ act= ]
→ gss₁ == gss₂
groupset-structure=' {groupset-structure _ _ _} {groupset-structure ._ ._ ._}
idp idp idp = idp
groupset-structure= : ∀ {gss₁ gss₂ : GroupSetStructure grp El El-level}
→ (∀ x g → act gss₁ x g == act gss₂ x g)
→ gss₁ == gss₂
groupset-structure= act= = groupset-structure='
(λ= λ x → λ= λ g → act= x g)
(prop-has-all-paths-↓ (Π-level λ _ → El-level _ _))
(prop-has-all-paths-↓
(Π-level λ _ → Π-level λ _ → Π-level λ _ → El-level _ _))
module _ {grp : Group i} {j : ULevel} where
private
module G = Group grp
module GS = GroupStructure G.group-struct
open GroupSet {grp} {j}
private
groupset='' : ∀ {gs₁ gs₂ : GroupSet grp j}
→ (El= : El gs₁ == El gs₂)
→ (El-level : El-level gs₁ == El-level gs₂ [ is-set ↓ El= ])
→ grpset-struct gs₁ == grpset-struct gs₂
[ uncurry (GroupSetStructure grp) ↓ pair= El= El-level ]
→ gs₁ == gs₂
groupset='' {groupset _ _ _} {groupset ._ ._ ._} idp idp idp = idp
groupset=' : ∀ {gs₁ gs₂ : GroupSet grp j}
→ (El= : El gs₁ == El gs₂)
→ (El-level : El-level gs₁ == El-level gs₂ [ is-set ↓ El= ])
→ (∀ {x₁} {x₂} (p : x₁ == x₂ [ idf _ ↓ El= ]) g
→ act gs₁ x₁ g == act gs₂ x₂ g [ idf _ ↓ El= ])
→ gs₁ == gs₂
groupset=' {groupset _ _ _} {groupset ._ ._ _} idp idp act= =
groupset='' idp idp (groupset-structure= λ x g → act= idp g)
groupset= : ∀ {gs₁ gs₂ : GroupSet grp j}
→ (El≃ : El gs₁ ≃ El gs₂)
→ (∀ {x₁} {x₂}
→ –> El≃ x₁ == x₂
→ ∀ g → –> El≃ (act gs₁ x₁ g) == act gs₂ x₂ g)
→ gs₁ == gs₂
groupset= El≃ act= =
groupset='
(ua El≃)
(prop-has-all-paths-↓ is-set-is-prop)
(λ x= g → ↓-idf-ua-in El≃ $ act= (↓-idf-ua-out El≃ x=) g)
-- The GroupSet homomorphism.
record GroupSetHom {grp : Group i} {j}
(gset₁ gset₂ : GroupSet grp j) : Type (lmax i j) where
constructor groupset-hom
open GroupSet
field
f : El gset₁ → El gset₂
pres-act : ∀ g x → f (act gset₁ x g) == act gset₂ (f x) g
private
groupset-hom=' : ∀ {grp : Group i} {j} {gset₁ gset₂ : GroupSet grp j}
{gsh₁ gsh₂ : GroupSetHom gset₁ gset₂}
→ (f= : GroupSetHom.f gsh₁ == GroupSetHom.f gsh₂)
→ (GroupSetHom.pres-act gsh₁ == GroupSetHom.pres-act gsh₂
[ (λ f → ∀ g x → f (GroupSet.act gset₁ x g) == GroupSet.act gset₂ (f x) g) ↓ f= ] )
→ gsh₁ == gsh₂
groupset-hom=' idp idp = idp
groupset-hom= : ∀ {grp : Group i} {j} {gset₁ gset₂ : GroupSet grp j}
{gsh₁ gsh₂ : GroupSetHom gset₁ gset₂}
→ (∀ x → GroupSetHom.f gsh₁ x == GroupSetHom.f gsh₂ x)
→ gsh₁ == gsh₂
groupset-hom= {gset₂ = gset₂} f= =
groupset-hom='
(λ= f=)
(prop-has-all-paths-↓ $
Π-level λ _ → Π-level λ _ → GroupSet.El-level gset₂ _ _)
group-to-group-set : ∀ (grp : Group i) → GroupSet grp i
group-to-group-set grp = record {
El = G.El;
El-level = G.El-level;
grpset-struct = record {
act = G.comp;
unit-r = G.unit-r;
assoc = G.assoc}}
where module G = Group grp
| {
"alphanum_fraction": 0.5655935614,
"avg_line_length": 36.0144927536,
"ext": "agda",
"hexsha": "dd93a6379b8149400be1e98fa047ff50f70292bc",
"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/GroupSet.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/GroupSet.agda",
"max_line_length": 91,
"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/GroupSet.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1719,
"size": 4970
} |
module Sets.BoolSet.Proofs{ℓ₁} where
open import Data.Boolean
open import Data.Boolean.Proofs
open import Functional
open import Logic.Propositional
open import Sets.BoolSet{ℓ₁}
open import Type
module _ {ℓ₂}{T : Type{ℓ₂}} where
[∈]-in-[∪] : ∀{a : T}{S₁ S₂ : BoolSet(T)} → (a ∈ S₁) → (a ∈ (S₁ ∪ S₂))
[∈]-in-[∪] proof-a = [∨]-introₗ-[𝑇] proof-a
[∈]-in-[∩] : ∀{a : T}{S₁ S₂ : BoolSet(T)} → (a ∈ S₁) → (a ∈ S₂) → (a ∈ (S₁ ∩ S₂))
[∈]-in-[∩] proof-a₁ proof-a₂ = [∧]-intro-[𝑇] proof-a₁ proof-a₂
[∈]-in-[∖] : ∀{a : T}{S₁ S₂ : BoolSet(T)} → (a ∈ S₁) → (a ∉ S₂) → (a ∈ (S₁ ∖ S₂))
[∈]-in-[∖] proof-a₁ proof-a₂ = [∧]-intro-[𝑇] proof-a₁ proof-a₂
[∈]-in-[∁] : ∀{a : T}{S : BoolSet(T)} → (a ∉ S) → (a ∈ (∁ S))
[∈]-in-[∁] = id
| {
"alphanum_fraction": 0.5129604366,
"avg_line_length": 33.3181818182,
"ext": "agda",
"hexsha": "12d4a8b4fb3fb2172921abbc077b8fe513f52b17",
"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": "old/Sets/BoolSet/Proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "old/Sets/BoolSet/Proofs.agda",
"max_line_length": 83,
"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": "old/Sets/BoolSet/Proofs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 364,
"size": 733
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Pointwise lifting of relations to lists
------------------------------------------------------------------------
module Relation.Binary.List.Pointwise where
open import Function
open import Function.Inverse using (Inverse)
open import Data.Product hiding (map)
open import Data.List hiding (map)
open import Level
open import Relation.Nullary
import Relation.Nullary.Decidable as Dec using (map′)
open import Relation.Binary renaming (Rel to Rel₂)
open import Relation.Binary.PropositionalEquality as P using (_≡_)
infixr 5 _∷_
data Rel {a b ℓ} {A : Set a} {B : Set b}
(_∼_ : REL A B ℓ) : List A → List B → Set (a ⊔ b ⊔ ℓ) where
[] : Rel _∼_ [] []
_∷_ : ∀ {x xs y ys} (x∼y : x ∼ y) (xs∼ys : Rel _∼_ xs ys) →
Rel _∼_ (x ∷ xs) (y ∷ ys)
head : ∀ {a b ℓ} {A : Set a} {B : Set b} {_∼_ : REL A B ℓ} {x y xs ys} →
Rel _∼_ (x ∷ xs) (y ∷ ys) → x ∼ y
head (x∼y ∷ xs∼ys) = x∼y
tail : ∀ {a b ℓ} {A : Set a} {B : Set b} {_∼_ : REL A B ℓ} {x y xs ys} →
Rel _∼_ (x ∷ xs) (y ∷ ys) → Rel _∼_ xs ys
tail (x∼y ∷ xs∼ys) = xs∼ys
rec : ∀ {a b c ℓ} {A : Set a} {B : Set b} {_∼_ : REL A B ℓ}
(P : ∀ {xs ys} → Rel _∼_ xs ys → Set c) →
(∀ {x y xs ys} {xs∼ys : Rel _∼_ xs ys} →
(x∼y : x ∼ y) → P xs∼ys → P (x∼y ∷ xs∼ys)) →
P [] →
∀ {xs ys} (xs∼ys : Rel _∼_ xs ys) → P xs∼ys
rec P c n [] = n
rec P c n (x∼y ∷ xs∼ys) = c x∼y (rec P c n xs∼ys)
map : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b}
{_≈_ : REL A B ℓ₁} {_∼_ : REL A B ℓ₂} →
_≈_ ⇒ _∼_ → Rel _≈_ ⇒ Rel _∼_
map ≈⇒∼ [] = []
map ≈⇒∼ (x≈y ∷ xs≈ys) = ≈⇒∼ x≈y ∷ map ≈⇒∼ xs≈ys
reflexive : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b}
{_≈_ : REL A B ℓ₁} {_∼_ : REL A B ℓ₂} →
_≈_ ⇒ _∼_ → Rel _≈_ ⇒ Rel _∼_
reflexive ≈⇒∼ [] = []
reflexive ≈⇒∼ (x≈y ∷ xs≈ys) = ≈⇒∼ x≈y ∷ reflexive ≈⇒∼ xs≈ys
refl : ∀ {a ℓ} {A : Set a} {_∼_ : Rel₂ A ℓ} →
Reflexive _∼_ → Reflexive (Rel _∼_)
refl rfl {[]} = []
refl rfl {x ∷ xs} = rfl ∷ refl rfl
symmetric : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b}
{_≈_ : REL A B ℓ₁} {_∼_ : REL B A ℓ₂} →
Sym _≈_ _∼_ → Sym (Rel _≈_) (Rel _∼_)
symmetric sym [] = []
symmetric sym (x∼y ∷ xs∼ys) = sym x∼y ∷ symmetric sym xs∼ys
transitive :
∀ {a b c ℓ₁ ℓ₂ ℓ₃} {A : Set a} {B : Set b} {C : Set c}
{_≋_ : REL A B ℓ₁} {_≈_ : REL B C ℓ₂} {_∼_ : REL A C ℓ₃} →
Trans _≋_ _≈_ _∼_ → Trans (Rel _≋_) (Rel _≈_) (Rel _∼_)
transitive trans [] [] = []
transitive trans (x∼y ∷ xs∼ys) (y∼z ∷ ys∼zs) =
trans x∼y y∼z ∷ transitive trans xs∼ys ys∼zs
antisymmetric : ∀ {a ℓ₁ ℓ₂} {A : Set a}
{_≈_ : Rel₂ A ℓ₁} {_≤_ : Rel₂ A ℓ₂} →
Antisymmetric _≈_ _≤_ →
Antisymmetric (Rel _≈_) (Rel _≤_)
antisymmetric antisym [] [] = []
antisymmetric antisym (x∼y ∷ xs∼ys) (y∼x ∷ ys∼xs) =
antisym x∼y y∼x ∷ antisymmetric antisym xs∼ys ys∼xs
respects₂ : ∀ {a ℓ₁ ℓ₂} {A : Set a}
{_≈_ : Rel₂ A ℓ₁} {_∼_ : Rel₂ A ℓ₂} →
_∼_ Respects₂ _≈_ → (Rel _∼_) Respects₂ (Rel _≈_)
respects₂ {_≈_ = _≈_} {_∼_} resp =
(λ {xs} {ys} {zs} → resp¹ {xs} {ys} {zs}) ,
(λ {xs} {ys} {zs} → resp² {xs} {ys} {zs})
where
resp¹ : ∀ {xs} → (Rel _∼_ xs) Respects (Rel _≈_)
resp¹ [] [] = []
resp¹ (x≈y ∷ xs≈ys) (z∼x ∷ zs∼xs) =
proj₁ resp x≈y z∼x ∷ resp¹ xs≈ys zs∼xs
resp² : ∀ {ys} → (flip (Rel _∼_) ys) Respects (Rel _≈_)
resp² [] [] = []
resp² (x≈y ∷ xs≈ys) (x∼z ∷ xs∼zs) =
proj₂ resp x≈y x∼z ∷ resp² xs≈ys xs∼zs
decidable : ∀ {a b ℓ} {A : Set a} {B : Set b} {_∼_ : REL A B ℓ} →
Decidable _∼_ → Decidable (Rel _∼_)
decidable dec [] [] = yes []
decidable dec [] (y ∷ ys) = no (λ ())
decidable dec (x ∷ xs) [] = no (λ ())
decidable dec (x ∷ xs) (y ∷ ys) with dec x y
... | no ¬x∼y = no (¬x∼y ∘ head)
... | yes x∼y with decidable dec xs ys
... | no ¬xs∼ys = no (¬xs∼ys ∘ tail)
... | yes xs∼ys = yes (x∼y ∷ xs∼ys)
isEquivalence : ∀ {a ℓ} {A : Set a} {_≈_ : Rel₂ A ℓ} →
IsEquivalence _≈_ → IsEquivalence (Rel _≈_)
isEquivalence eq = record
{ refl = refl Eq.refl
; sym = symmetric Eq.sym
; trans = transitive Eq.trans
} where module Eq = IsEquivalence eq
isPreorder : ∀ {a ℓ₁ ℓ₂} {A : Set a}
{_≈_ : Rel₂ A ℓ₁} {_∼_ : Rel₂ A ℓ₂} →
IsPreorder _≈_ _∼_ → IsPreorder (Rel _≈_) (Rel _∼_)
isPreorder pre = record
{ isEquivalence = isEquivalence Pre.isEquivalence
; reflexive = reflexive Pre.reflexive
; trans = transitive Pre.trans
} where module Pre = IsPreorder pre
isDecEquivalence : ∀ {a ℓ} {A : Set a}
{_≈_ : Rel₂ A ℓ} → IsDecEquivalence _≈_ →
IsDecEquivalence (Rel _≈_)
isDecEquivalence eq = record
{ isEquivalence = isEquivalence DE.isEquivalence
; _≟_ = decidable DE._≟_
} where module DE = IsDecEquivalence eq
isPartialOrder : ∀ {a ℓ₁ ℓ₂} {A : Set a}
{_≈_ : Rel₂ A ℓ₁} {_≤_ : Rel₂ A ℓ₂} →
IsPartialOrder _≈_ _≤_ →
IsPartialOrder (Rel _≈_) (Rel _≤_)
isPartialOrder po = record
{ isPreorder = isPreorder PO.isPreorder
; antisym = antisymmetric PO.antisym
} where module PO = IsPartialOrder po
preorder : ∀ {p₁ p₂ p₃} → Preorder p₁ p₂ p₃ → Preorder _ _ _
preorder p = record
{ isPreorder = isPreorder (Preorder.isPreorder p)
}
setoid : ∀ {c ℓ} → Setoid c ℓ → Setoid _ _
setoid s = record
{ isEquivalence = isEquivalence (Setoid.isEquivalence s)
}
decSetoid : ∀ {c ℓ} → DecSetoid c ℓ → DecSetoid _ _
decSetoid d = record
{ isDecEquivalence = isDecEquivalence (DecSetoid.isDecEquivalence d)
}
poset : ∀ {c ℓ₁ ℓ₂} → Poset c ℓ₁ ℓ₂ → Poset _ _ _
poset p = record
{ isPartialOrder = isPartialOrder (Poset.isPartialOrder p)
}
-- Rel _≡_ coincides with _≡_.
Rel≡⇒≡ : ∀ {a} {A : Set a} → Rel {A = A} _≡_ ⇒ _≡_
Rel≡⇒≡ [] = P.refl
Rel≡⇒≡ (P.refl ∷ xs∼ys) with Rel≡⇒≡ xs∼ys
Rel≡⇒≡ (P.refl ∷ xs∼ys) | P.refl = P.refl
≡⇒Rel≡ : ∀ {a} {A : Set a} → _≡_ ⇒ Rel {A = A} _≡_
≡⇒Rel≡ P.refl = refl P.refl
Rel↔≡ : ∀ {a} {A : Set a} →
Inverse (setoid (P.setoid A)) (P.setoid (List A))
Rel↔≡ = record
{ to = record { _⟨$⟩_ = id; cong = Rel≡⇒≡ }
; from = record { _⟨$⟩_ = id; cong = ≡⇒Rel≡ }
; inverse-of = record
{ left-inverse-of = λ _ → refl P.refl
; right-inverse-of = λ _ → P.refl
}
}
decidable-≡ : ∀ {a} {A : Set a} →
Decidable {A = A} _≡_ → Decidable {A = List A} _≡_
decidable-≡ dec xs ys = Dec.map′ Rel≡⇒≡ ≡⇒Rel≡ (xs ≟ ys)
where
open DecSetoid (decSetoid (P.decSetoid dec))
| {
"alphanum_fraction": 0.5059708094,
"avg_line_length": 35.5130890052,
"ext": "agda",
"hexsha": "d6f0fc1762bbb67602feee09a2e0f051b8e8ed91",
"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/Relation/Binary/List/Pointwise.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/Relation/Binary/List/Pointwise.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/src/Relation/Binary/List/Pointwise.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": 2946,
"size": 6783
} |
data ℕ : Set where
ze : ℕ
su : ℕ → ℕ
f : (ℕ → ℕ) → ℕ → ℕ
f g n = g n
syntax f g n = n , g
h : ℕ
h = ?
| {
"alphanum_fraction": 0.3963963964,
"avg_line_length": 7.9285714286,
"ext": "agda",
"hexsha": "fc7171ac12a3ee21913dc63ce9edd0a8d04137ff",
"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/Issue488.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/Issue488.agda",
"max_line_length": 20,
"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/Issue488.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": 111
} |
-- if curious: https://agda.readthedocs.io/en/v2.6.0.1/language/without-k.html
{-# OPTIONS --without-K --allow-unsolved-metas #-}
{-
CS 598 TLR
Artifact 1: Proof Objects
Student Copy
READ ME FIRST: You will absolutely not be graded on your ability to finish
these proofs. It's OK to be confused and find this hard. It's also
OK to come into this class as an Agda wizard and breeze through this,
perhaps even using a bunch of features of Agda that aren't mentioned
in this file at all (if you do that, though, please help your partner
understand what you are doing, and please discuss what you did at the end).
The point is to pay attention to what is hard and where you wish you
had better automation, and to learn about proof objects.
At the end of this class (or, if you're not attending in person,
sometime before 1230 PM the day of class) you'll post on the forum
about what you found challenging, what you enjoyed, and─most importantly
for this class─what kind of automation you wish you had.
If you or someone you're working with is an Agda wizard already,
and you know about automation or syntax that already exists that makes the
job easy, definitely take note of that and mention it as well.
If you have a lot of trouble with a proof, it's OK to ask me for help
(or post in the forum if you're not here in person). It's also OK to
ask people in other groups.
But please, please don't stress about finishing these proofs.
The theorems will still be here after class if you feel tempted by them.
I'm also happy to distribute my own answer key, or to let you share
proofs with other students later─the point is to think about the proof
objects you construct throughout, and the experience you have constructing
them. It's about the journey, not the destination.
-}
module proof-objects where
{-
Some built-in datatypes we'll use in this exercise:
-}
open import Agda.Builtin.Nat -- natural numbers
open import Agda.Builtin.List -- polymorphic lists
open import Agda.Builtin.Char -- characters
open import Agda.Builtin.Equality -- equality
{-
You can see these definitions by clicking them and then pressing the Alt
key along with the period. Or you can use the middle button of your mouse,
if you have one.
For example, if we click on Agda.Builtin.List and press the Alt key
along with the period, it will open up the file that defines the
list datatype. A polymorphic list in Agda is defined a lot like the
list datatype in Coq that we saw in the slides for the first class.
It is an inductive datatype with two cases:
data List (A : Set) : Set where
[] : List A
_∷_ : A → List A → List A
In other words, as in Coq, a list is either empty ([]) or the result
of consing (∷) an element of type A in front of some other list of
elements of type A.
For example, let's define some empty lists of numbers and characters.
In Agda, a definition has its type on the first line, and then the
term with that type on the next line:
-}
-- The empty list of natural numbers
empty-nat : List Nat -- the type
empty-nat = [] -- the term
-- The empty list of characters
empty-char : List Char -- the type
empty-char = [] -- the term
{-
Cool. Now let's define some non-empty lists.
NOTE: The Agda community has an unfortunate obsession with Unicode.
The syntax for the cons constructor in Coq is two colons, written ::.
Confusingly, the Agda cons constructor is actually denoted with a
single special unicode character, written ∷. You can write this
special character by typing \:: (with two colons), and it will
magically turn into ∷.
OK, with that in mind:
-}
-- A list [1; 2; 3; 4]
1-2-3-4 : List Nat -- type
1-2-3-4 = 1 ∷ 2 ∷ 3 ∷ 4 ∷ [] -- term
-- A list [x; y; z]
x-y-z : List Char -- type
x-y-z = 'x' ∷ 'y' ∷ 'z' ∷ [] -- term
{-
As in Coq, we can write functions about lists, like our length function,
which we define by pattern matching. The syntax for pattern matching in
Agda is defining each case on a different line:
-}
-- list length
length : ∀ {A : Set} → List A → Nat -- type
length [] = 0 -- term in the empty case
length (h ∷ tl) = suc (length tl) -- term in the cons case
{-
That is, the length of the empty list ([]) is zero (0), and the
length any other list (h ∷ tl) is one plus (suc, for "successor")
the length of the tail of the list (length tl).
NOTE: Thanks to the Agda community's unicode obsession, you can write
the above ∀ by typing \forall, and you can write the above → by typing
\r or \->. But it's OK to spell them out as forall and ->.
EXERCISE 1: Write a function that reverses a list.
You may use the function app I've written for you below,
which appends two lists.
NOTE: The {! !} syntax I've written inside of the sketch of rev is a
hole─you will want to replace this with your implementation of rev for
each case. These holes change color when you compile files, and numbers
appear next to them; I explain this a bit more later on.
NOTE: You can compile this file by running C-c C-l, to just
invoke the type checker. To produce an executable file,
you can run C-c C-x C-c and specify the GHC backend, but this isn't necessary
to just check the proofs you'll write in this file. The first time
you compile this file, you'll see a bunch of numbered constrants;
these correspond to the holes I've left in the file for you to fill.
-}
-- list append
app : ∀ {A : Set} → List A → List A → List A -- type
app [] l = l -- term in the empty case
app (h ∷ tl) l = h ∷ app tl l -- term in the cons case
-- list rev
rev : ∀ {A : Set} → List A → List A -- type
rev [] = {! !} -- your term in the empty case goes here
rev (h ∷ tl) = {! !} -- your term in the cons case goes here
{-
Let's test your rev function.
We're going to check that, on the lists we've defined at the top
of this file, the result of calling rev gives us the reverse lists.
To do that, we need a way to state what it means for two things to be
equal. Equality in Agda is written ≡, which is typed as \== using the same
magic as before, because of the community's unicode obsession:
data _≡_ {a} {A : Set a} (x : A) : A → Set a where
refl : x ≡ x
Equality is an inductive datatype, just like lists. But one thing that's
cool about the equality type is that it's something called a dependent type.
A dependent type is a lot like a polymorphic type, but instead of taking
a type argument (like the A in List A), it takes a _term_ argument
(like the x in x ≡ x). Dependent types can refer to values!
So we can define the type of all terms that prove our lists
behave the way we want them to. And then we can write terms that
have those types─our proofs.
There is exactly one constructor for the equality type in Agda:
refl, for reflexivity. Two things are equal by reflexivity when they
compute to the same result. So if your rev function is correct,
these test cases should compile:
-}
-- empty-nat doesn't change
rev-empty-nat-empty-nat : rev empty-nat ≡ empty-nat
rev-empty-nat-empty-nat = refl
-- empty-char doesn't change
rev-empty-char-empty-char : rev empty-char ≡ empty-char
rev-empty-char-empty-char = refl
-- [1; 2; 3; 4] becomes [4; 3; 2; 1]
rev-1-2-3-4-4-3-2-1 : rev 1-2-3-4 ≡ 4 ∷ 3 ∷ 2 ∷ 1 ∷ []
rev-1-2-3-4-4-3-2-1 = refl
-- [x; y; z] becomes [z; y; x]
rev-x-y-z-z-y-x : rev x-y-z ≡ 'z' ∷ 'y' ∷ 'x' ∷ []
rev-x-y-z-z-y-x = refl
{-
These test cases are actually proofs! Even though they all hold
by computation (reflexivity), they are terms, just like the lists
we refer to inside of them. Their types are the theorems that they prove.
That's the beauty of Curry-Howard; our terms here are proof objects
that prove the theorems stated by the types they inhabit.
These programs are proofs!
So now it's your turn to test my length function and, in the process,
write some proofs yourself.
EXERCISE 2: Prove that 1-2-3-4 and x-y-z have the right lengths.
As before, you'll want to replace each hole {! !} with your own code.
This time, I want you to define both the types and the terms.
-}
-- 1-2-3-4 has the right length
length-1-2-3-4-OK : {! !}
length-1-2-3-4-OK = {! !}
-- x-y-z has the right length
length-x-y-z-OK : {! !}
length-x-y-z-OK = {! !}
{-
Those proofs are very small proofs that hold by computation.
There are also some cooler proofs we can prove by computation,
like that appending the empty list to the left of any list
gives us back that list:
-}
-- left identity of nil for append
app-nil-l : ∀ {A : Set} → (l : List A) → app [] l ≡ l -- type or theorem
app-nil-l l = refl -- term or proof
{-
But sometimes we need to get fancier! For example, if we simply swap
the [] and l in the type definition above above, to define app-nil-r,
this will no longer hold by reflexivity, since app is defined by
matching over the first list, not the second. Because of this,
when you put the empty list as the first argument, Agda can reduce it;
when you put it as the second argument instead, Agda cannot reduce it.
If we try to prove app-nil-r by reflexivity, we'll get a scary looking
type error, like this:
app l [] != l of type List A
when checking that the expression refl has type app l [] ≡ l
But here's the thing─the equality is still true!
It's just not true by computation. We have to prove it differently.
Agda needs our help figuring this out.
So let's help Agda. We're going to need to write some fancier proofs
about equality. But how do we do that if there's just one constructor
for equality─refl? Well, there are two things we can do with inductive
datatypes: we can construct them, and we can pattern match over their cases
(the latter is also called destructing them or, for reasons you'll see later,
in specific contexts, inducting over them).
Since equality is defined as an inductive type, we can pattern match
over it just like we do over lists. When we do, there will be just one
case─refl. But that actually turns out to give us a lot of power to
prove some cool things about equality. So let's do that.
Our first lemma is congruence, which comes from the standard library,
and states that function application preserves equality:
-}
-- congruence
cong : ∀ {A B : Set} (f : A → B) {x y : A} → x ≡ y → f x ≡ f y -- the lemma
cong f refl = refl -- the proof
{-
In other words, this matches over the input argument of type x ≡ y.
Since equality has just one case, pattern matching breaks this into
just one case, which is when that equality is refl.
When that equality is refl, then we have x ≡ x.
Thus, we are trying to show f x ≡ f x, which also holds by refl,
since these terms are the same.
One thing to note here is that it can be super hard to track this information
in your head. In Agda, you can create holes in your functions
by typing {! !}, much like I've done for you throughout. So you could write:
cong f refl = {! !}
If you compile that with C-c C-l, it'll change colors and there
will be a 0 next to it, indicating that it's the 0th goal. In the AgdaInfo
buffer, you'll see the goal that you need to satisfy for that hole:
?0 : f x ≡ f x
This goal is the type you're trying to inhabit. From there,
you can figure out that refl has that type, without having to track
so much information in your head about what Agda is doing.
With this, we should be able to prove app-nil-r:
-}
-- right identity of nil for append
app-nil-r : ∀ {A : Set} → (l : List A) → app l [] ≡ l
app-nil-r [] = refl
app-nil-r (h ∷ tl) = cong (λ l′ → h ∷ l′) (app-nil-r tl)
{-
EXERCISE 3: Prove the lemma sym, which states that equality is symmetric.
I have inserted a hole into this lemma, denoted {! !}, which may
already look green if you've compiled this file. You can use the
workflow described above to figure out the type you're trying to inhabit.
-}
-- symmetry of equality
sym : ∀ {A : Set} {x y : A} → x ≡ y → y ≡ x
sym refl = {! !}
{-
EXERCISE 4: Prove that l ≡ app l [], using symmetry. I have inserted
a hole into this lemma where you will need to figure out a term.
-}
-- symmetric right identity of nil for append
app-nil-r-sym : ∀ {A : Set} → (l : List A) → l ≡ app l []
app-nil-r-sym l = sym {! !}
{-
EXERCISE 5: Prove the lemma trans, which states that equality
is transitive. I have inserted a hole into this lemma as well.
-}
-- transitivity of equality
trans : ∀ {A : Set} {x y z : A} → x ≡ y → y ≡ z → x ≡ z
trans refl refl = {! !}
{-
Equalities like this that we have to prove by pattern matching over
the equality type are what we called propositional equalities
in QED at Large. This is in contrast with definitional equalities,
which hold by computation.
For example, app [] l and l are definitionally equal, since Agda
reduces both of them to the same term. But app l [] and l are not
definitionally equal, as we saw earlier, since app is defined by
pattern matching over the first term rather than the second.
They are only propositionally─provably, that is─equal.
In Agda, Coq, and Lean, two things that are definitionally equal are
necessarily propositionally equal, but the reverse is not necessarily true.
This is why we can't prove app-nil-r by reflexivity.
This is important to pay attention to─in many of these languages, it is
really standard for your proofs to mirror the structure of
the programs they are about. There is a deep type theoretical
reason that this is true.
ASIDE: Definitional equality is─for many proof assistants we care about in
this class─a decidable judgment that follows from a few reduction rules,
like unfolding some constants (δ-expansion), applying functions to
arguments (Β-reduction, which is sometimes called ι-reduction for
inductive datatypes), renaming (α-conversion), and more.
These may sound familiar if you're familiar with the λ-calculus,
a simple functional programming language that is often used as an example
in programming languages courses. The proof assistants Agda, Coq, and Lean
all build on extensions of the λ-calculus with not just simple types,
but also polymorphism (like how list takes a type argument A), dependent
types (like how ≡ takes a term argument x), and inductive types (like
how both the list and ≡ datatypes are defined by defining all ways to
construct them).
But if you haven't heard of these, that's OK. I super recommend reading this
chapter of Certified Programming with Dependent Types by Adam Chlipala:
http://adam.chlipala.net/cpdt/html/Equality.html. If you'd like more
information, that will really help─though it's in Coq. I hope to
show you some automation that steps through equalities like this next week.
BACK TO BUSINESS: It can be kind of annoying to keep pattern matching
over equality, which is why the lemmas above─also defined in the standard
library─can be really useful.
An especially useful lemma about equality is substitution,
which is also found inside of the standard library:
-}
-- substitution
subst : ∀ {A : Set} {x y : A} (P : A → Set) → x ≡ y → P x → P y
subst P refl px = px
{-
This states that for any property P, if x ≡ y, and we have a proof
that P x holds, we can substitute y for x inside of that to show
that P y holds. This is really powerful, but a little hard to use,
because you have to figure out what P is. For example, here is a proof
of app-nil-r using subst instead of cong:
-}
-- right identity of nil for append, proven by substitution instead
app-nil-r′ : ∀ {A : Set} → (l : List A) → app l [] ≡ l
app-nil-r′ [] = refl
app-nil-r′ (h ∷ tl) = subst (λ l′ → h ∷ l′ ≡ h ∷ tl) (sym (app-nil-r′ tl)) refl
{-
Your turn to try. You can use cong or subst here─whatever you find
more convenient.
EXERCISE 6: Finish the proof of length-succ-r.
-}
length-succ-r :
∀ {A} → (l : List A) → (a : A) → length (app l (a ∷ [])) ≡ suc (length l)
length-succ-r [] a = refl -- base case
length-succ-r {A} (h ∷ tl) a = -- inductive case
{! !}
{-
EXERCISE 7: Show that the reverse function that you wrote preserves
the length of the input list. You may use length-succ-r, and any of the
equality lemmas we've defined so far like trans, subst, sym, and
cong. (You probably won't need all of them.)
-}
rev-pres-length : ∀ {A} → (l : List A) → length (rev l) ≡ length l
rev-pres-length [] = {! !}
rev-pres-length (h ∷ tl) = {! !}
{-
That's it for now! You can keep playing with other proofs if you have
extra time. If you have a lot of extra time, I recommend looking at the
Agda source code on Github to get a sense for how it's implemented:
https://github.com/agda/agda. In any case, when we have 25 minutes
left of class, please do this:
1. Turn to your group and discuss the question below.
2. Post your answer─just one answer for your group, clearly indicating
all members of the group. (If you are not here, and are working alone,
you can post your answer alone.)
3. With 10 minutes left, finish posting your answer, so we can discuss
a bit as a class.
You'll be graded based on whether you post an answer, not based on
what it is, so don't worry too much about saying something silly.
DISCUSSION QUESTION: What was it like constructing these proofs directly,
as terms in a programming language? What did you find challenging about
this experience, if anything? What did you find helpful, if anything? Did
you get stuck at any point, and if so, where and why? Where do you wish
you'd had more automation to help you out?
-}
| {
"alphanum_fraction": 0.705116595,
"avg_line_length": 40.3378995434,
"ext": "agda",
"hexsha": "aaed83254a7630c29d6711353f7bd5659c4b7593",
"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": "5b3afde25381d7aff75a6a231b90cf60dca5b826",
"max_forks_repo_licenses": [
"CC-BY-3.0"
],
"max_forks_repo_name": "tlringer/tlringer.github.io",
"max_forks_repo_path": "classes/artifacts/1/proof-objects.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5b3afde25381d7aff75a6a231b90cf60dca5b826",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC-BY-3.0"
],
"max_issues_repo_name": "tlringer/tlringer.github.io",
"max_issues_repo_path": "classes/artifacts/1/proof-objects.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5b3afde25381d7aff75a6a231b90cf60dca5b826",
"max_stars_repo_licenses": [
"CC-BY-3.0"
],
"max_stars_repo_name": "tlringer/tlringer.github.io",
"max_stars_repo_path": "classes/artifacts/1/proof-objects.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4876,
"size": 17668
} |
------------------------------------------------------------------------
-- The semantics given in OneSemantics and TwoSemantics are equivalent
------------------------------------------------------------------------
module Lambda.Substitution.Equivalence where
open import Codata.Musical.Notation
open import Lambda.Syntax
open WHNF
open import Lambda.Substitution.OneSemantics
open import Lambda.Substitution.TwoSemantics
⇒⟶⇓ : ∀ {n t} {v : Value n} → t ⇒ val v → t ⇓ v
⇒⟶⇓ val = val
⇒⟶⇓ (app t₁⇓ t₂⇓ t₁t₂⇒) = app (⇒⟶⇓ t₁⇓) (⇒⟶⇓ t₂⇓) (⇒⟶⇓ t₁t₂⇒)
⇒⊥⟶⇑ : ∀ {n} {t : Tm n} → t ⇒ ⊥ → t ⇑
⇒⊥⟶⇑ (·ˡ t₁⇑) = ·ˡ (♯ (⇒⊥⟶⇑ (♭ t₁⇑)))
⇒⊥⟶⇑ (·ʳ t₁⇓ t₂⇑) = ·ʳ (⇒⟶⇓ t₁⇓) (♯ (⇒⊥⟶⇑ (♭ t₂⇑)))
⇒⊥⟶⇑ (app t₁⇓ t₂⇓ t₁t₂⇒) = app (⇒⟶⇓ t₁⇓) (⇒⟶⇓ t₂⇓) (♯ (⇒⊥⟶⇑ (♭ t₁t₂⇒)))
⇓⟶⇒ : ∀ {n t} {v : Value n} → t ⇓ v → t ⇒ val v
⇓⟶⇒ val = val
⇓⟶⇒ (app t₁⇓ t₂⇓ t₁t₂⇓) = app (⇓⟶⇒ t₁⇓) (⇓⟶⇒ t₂⇓) (⇓⟶⇒ t₁t₂⇓)
⇑⟶⇒⊥ : ∀ {n} {t : Tm n} → t ⇑ → t ⇒ ⊥
⇑⟶⇒⊥ (·ˡ t₁⇑) = ·ˡ (♯ (⇑⟶⇒⊥ (♭ t₁⇑)))
⇑⟶⇒⊥ (·ʳ t₁⇓ t₂⇑) = ·ʳ (⇓⟶⇒ t₁⇓) (♯ (⇑⟶⇒⊥ (♭ t₂⇑)))
⇑⟶⇒⊥ (app t₁⇓ t₂⇓ t₁t₂⇓) = app (⇓⟶⇒ t₁⇓) (⇓⟶⇒ t₂⇓) (♯ (⇑⟶⇒⊥ (♭ t₁t₂⇓)))
| {
"alphanum_fraction": 0.3644289451,
"avg_line_length": 37,
"ext": "agda",
"hexsha": "d58d3f161e522e840c9bd5b0830970ad4298cb1b",
"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": "Lambda/Substitution/Equivalence.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": "Lambda/Substitution/Equivalence.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": "Lambda/Substitution/Equivalence.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": 792,
"size": 1147
} |
open import Coinduction using ( ∞ ; ♯_ ; ♭ )
open import Data.Product using ( ∃ ; _×_ ; _,_ ; proj₂ )
open import Data.Nat using ( ℕ ; zero ; suc )
open import Data.Empty using ( ⊥ )
open import FRP.LTL.ISet.Core using ( ISet ; M⟦_⟧ ; ⟦_⟧ ; ⌈_⌉ ; _,_ ; splitM⟦_⟧ ) renaming ( [_] to ⟪_⟫ )
open import FRP.LTL.ISet.Globally using ( □ ; [_] )
open import FRP.LTL.ISet.Stateless using ( _⇒_ ; _$_ )
open import FRP.LTL.RSet.Core using ( RSet )
open import FRP.LTL.Time.Bound using
( Time∞ ; fin ; +∞ ; _≺_ ; _≼_ ; _⋠_ ; ≺-Indn ; _,_
; ≺-impl-≼ ; ≼-refl ; _≼-trans_ ; ≡-impl-≽ ; ≺-impl-≢ ; ≺-impl-⋡ ; t≺+∞ ; ∞≼-impl-≡∞ ; ≺-indn )
open import FRP.LTL.Time.Interval using ( [_⟩ ; Int ; ↑ )
open import FRP.LTL.Util using ( ⊥-elim )
open import Relation.Binary.PropositionalEquality using ( _≡_ ; refl )
open import Relation.Unary using ( _∈_ )
module FRP.LTL.ISet.Causal where
infixr 2 _⊵_
infixr 3 _⋙_ _≫_ _⊨_≫_
-- A ⊵ B is the causal function space from A to B
data _∙_⊸_∙_ (A : ISet) (s : Time∞) (B : ISet) (u : Time∞) : Set where
inp : .(s ≼ u) → .(u ≺ +∞) →
(∀ {t} .(s≺t : s ≺ t) → M⟦ A ⟧ [ s≺t ⟩ → ∞ (A ∙ t ⊸ B ∙ u)) →
(A ∙ s ⊸ B ∙ u)
out : ∀ {v} .(u≺v : u ≺ v) →
M⟦ B ⟧ [ u≺v ⟩ → ∞ (A ∙ s ⊸ B ∙ v) →
(A ∙ s ⊸ B ∙ u)
done : .(u ≡ +∞) →
(A ∙ s ⊸ B ∙ u)
_⊵_ : ISet → ISet → ISet
A ⊵ B = ⌈ (λ t → A ∙ fin t ⊸ B ∙ fin t) ⌉
-- Categorical structure
ar : ∀ {A B} t → M⟦ A ⇒ B ⟧ (↑ t) → (A ∙ fin t ⊸ B ∙ fin t)
ar {A} {B} t f = inp ≼-refl t≺+∞ P where
P : ∀ {u} .(t≺u : fin t ≺ u) → M⟦ A ⟧ [ t≺u ⟩ → ∞ (A ∙ u ⊸ B ∙ fin t)
P {+∞} t≺u σ = ♯ out t≺u (f $ σ) (♯ done refl)
P {fin u} t≺u σ with splitM⟦ A ⇒ B ⟧ [ t≺u ⟩ (↑ u) refl f
P {fin u} t≺u σ | (f₁ , f₂) = ♯ out t≺u (f₁ $ σ) (♯ ar u f₂)
arr : ∀ {A B} → ⟦ □ (A ⇒ B) ⇒ (A ⊵ B) ⟧
arr ⟪ ⟪ f ⟫ ⟫ = ⟪ (λ t t∈i → ar t (f t t∈i) ) ⟫
-- We could define id in terms of arr, but we define it explictly for efficiency.
id : ∀ {A} t → (A ∙ t ⊸ A ∙ t)
id +∞ = done refl
id (fin t) = inp ≼-refl t≺+∞ (λ {u} t≺u σ → ♯ out t≺u σ (♯ id u))
identity : ∀ {A} → ⟦ A ⊵ A ⟧
identity = ⟪ (λ t t∈i → id (fin t)) ⟫
-- The following typechecks but does not pass the termination checker,
-- due to the possibility of infinite left-to-right chatter:
-- _≫_ : ∀ {A B C s t u} → (A ∙ s ⊸ B ∙ t) → (B ∙ t ⊸ C ∙ u) → (A ∙ s ⊸ C ∙ u)
-- P ≫ out u≺w τ Q = out u≺w τ (♯ (P ≫ ♭ Q))
-- P ≫ done u≡∞ = done u≡∞
-- inp s≼t t≺∞ P ≫ inp t≼u u≺∞ Q = inp (s≼t ≼-trans t≼u) u≺∞ (λ s≺v σ → ♯ (♭ (P s≺v σ) ≫ inp t≼u u≺∞ Q))
-- done t≡∞ ≫ inp t≼u u≺∞ Q = ⊥-elim (≺-impl-≢ u≺∞ (∞≼-impl-≡∞ (≡-impl-≽ t≡∞ ≼-trans t≼u)))
-- out t≺v σ P ≫ inp t≼u u≺∞ Q = out t≺v σ P ≫ inp t≼u u≺∞ Q
-- We have to be explicit about the induction scheme in the case of left-to-right
-- communication, which is because, for any t and u ≺ ∞, there is a bound
-- on the length of any ≺-chain between t and u.
mutual
_⊨_≫_ : ∀ {A B C s t u} → (≺-Indn t u) → (A ∙ s ⊸ B ∙ t) → (B ∙ t ⊸ C ∙ u) → (A ∙ s ⊸ C ∙ u)
n , t+n≻u ⊨ P ≫ out u≺w τ Q = out u≺w τ (♯ (P ≫ ♭ Q))
n , t+n≻u ⊨ P ≫ done u≡∞ = done u≡∞
n , t+n≻u ⊨ inp s≼t t≺∞ P ≫ inp t≼u u≺∞ Q = inp (s≼t ≼-trans t≼u) u≺∞ (λ s≺v σ → ♯ (♭ (P s≺v σ) ≫ inp t≼u u≺∞ Q))
n , t+n≻u ⊨ done t≡∞ ≫ inp t≼u u≺∞ Q = ⊥-elim (≺-impl-≢ u≺∞ (∞≼-impl-≡∞ (≡-impl-≽ t≡∞ ≼-trans t≼u)))
zero , u≺t ⊨ out t≺v σ P ≫ inp t≼u u≺∞ Q = ⊥-elim (≺-impl-⋡ u≺t t≼u)
suc n , t+1+n≻u ⊨ out t≺v σ P ≫ inp t≼u u≺∞ Q = n , t+1+n≻u t≺v ⊨ ♭ P ≫ ♭ (Q t≺v σ)
_≫_ : ∀ {A B C s t u} → (A ∙ s ⊸ B ∙ t) → (B ∙ t ⊸ C ∙ u) → (A ∙ s ⊸ C ∙ u)
P ≫ out u≺w τ Q = out u≺w τ (♯ (P ≫ ♭ Q))
P ≫ done u≡∞ = done u≡∞
inp s≼t t≺∞ P ≫ inp t≼u u≺∞ Q = inp (s≼t ≼-trans t≼u) u≺∞ (λ s≺v σ → ♯ (♭ (P s≺v σ) ≫ inp t≼u u≺∞ Q))
done t≡∞ ≫ inp t≼u u≺∞ Q = ⊥-elim (≺-impl-≢ u≺∞ (∞≼-impl-≡∞ (≡-impl-≽ t≡∞ ≼-trans t≼u)))
out t≺v σ P ≫ inp t≼u u≺∞ Q = ≺-indn u≺∞ ⊨ out t≺v σ P ≫ inp t≼u u≺∞ Q
_⋙_ : ∀ {A B C} → ⟦ (A ⊵ B) ⇒ (B ⊵ C) ⇒ (A ⊵ C) ⟧
(⟪ ⟪ f ⟫ ⟫ ⋙ ⟪ ⟪ g ⟫ ⟫) = ⟪ (λ t t∈i → f t t∈i ≫ g t t∈i) ⟫
-- Apply a process to some of its output
_/_/_ : ∀ {A B s t u} → (A ∙ s ⊸ B ∙ u) → .(s≺t : s ≺ t) → M⟦ A ⟧ [ s≺t ⟩ → (A ∙ t ⊸ B ∙ u)
inp s≼u u≺∞ P / s≺t / σ = ♭ (P s≺t σ)
out u≺v τ P / s≺t / σ = out u≺v τ (♯ (♭ P / s≺t / σ))
done u≡∞ / s≺t / σ = done u≡∞
| {
"alphanum_fraction": 0.4441136051,
"avg_line_length": 44.101010101,
"ext": "agda",
"hexsha": "2392d9c28bfb7ad8830e7a1fde1c1631686193aa",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:04.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-01T07:33:00.000Z",
"max_forks_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/agda-frp-ltl",
"max_forks_repo_path": "src/FRP/LTL/ISet/Causal.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5",
"max_issues_repo_issues_event_max_datetime": "2015-03-02T15:23:53.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-01T07:01:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/agda-frp-ltl",
"max_issues_repo_path": "src/FRP/LTL/ISet/Causal.agda",
"max_line_length": 121,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-frp-ltl",
"max_stars_repo_path": "src/FRP/LTL/ISet/Causal.agda",
"max_stars_repo_stars_event_max_datetime": "2020-06-15T02:51:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-02T20:25:05.000Z",
"num_tokens": 2476,
"size": 4366
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Helper reflection functions
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Tactic.RingSolver.Core.ReflectionHelp where
open import Agda.Builtin.Reflection
open import Data.List as List using (List; []; _∷_)
open import Data.Nat.Base as ℕ using (ℕ; suc; zero)
open import Data.Nat.GeneralisedArithmetic using (fold)
open import Data.Fin.Base as Fin using (Fin)
open import Data.Vec.Base as Vec using (Vec; []; _∷_)
open import Data.String using (String)
open import Data.Maybe.Base as Maybe using (Maybe; just; nothing)
open import Data.Product
open import Function
open import Level using (Level)
open import Reflection.Term
open import Reflection.Argument
open import Tactic.RingSolver.Core.NatSet as NatSet
private
variable
a : Level
A : Set a
-- TO-DO - once `Reflection` is --safe after v1.3 a lot of this can be simplified
hlams : ∀ {n} → Vec String n → Term → Term
hlams vs xs = Vec.foldr (const Term) (λ v vs → lam hidden (abs v vs)) xs vs
vlams : ∀ {n} → Vec String n → Term → Term
vlams vs xs = Vec.foldr (const Term) (λ v vs → lam visible (abs v vs)) xs vs
getVisible : Arg Term → Maybe Term
getVisible (arg (arg-info visible relevant) x) = just x
getVisible _ = nothing
getArgs : ∀ n → Term → Maybe (Vec Term n)
getArgs n (def _ xs) = Maybe.map Vec.reverse (List.foldl f c (List.mapMaybe getVisible xs) n)
where
f : (∀ n → Maybe (Vec Term n)) → Term → ∀ n → Maybe (Vec Term n)
f xs x zero = just []
f xs x (suc n) = Maybe.map (x ∷_) (xs n)
c : ∀ n → Maybe (Vec Term n)
c zero = just []
c (suc _ ) = nothing
getArgs _ _ = nothing
underPi : Term → ∃[ n ] (Vec String n × Term)
underPi = go (λ xs y → _ , xs , y)
where
go : (∀ {n} → Vec String n → Term → A) → Term → A
go k (pi a (abs s x)) = go (k ∘ (s ∷_)) x
go k t = k [] t
curriedTerm : NatSet → Term
curriedTerm = List.foldr go (quote Vec.[] ⟨ con ⟩ 2 ⋯⟅∷⟆ []) ∘ NatSet.toList
where
go : ℕ → Term → Term
go x xs = quote Vec._∷_ ⟨ con ⟩ 3 ⋯⟅∷⟆ var x [] ⟨∷⟩ xs ⟨∷⟩ []
| {
"alphanum_fraction": 0.5904159132,
"avg_line_length": 32.5294117647,
"ext": "agda",
"hexsha": "81c5cb13805f971ea821796da27ab116cef125bf",
"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/Tactic/RingSolver/Core/ReflectionHelp.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/Tactic/RingSolver/Core/ReflectionHelp.agda",
"max_line_length": 93,
"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/Tactic/RingSolver/Core/ReflectionHelp.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": 665,
"size": 2212
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties related to All
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Maybe.Relation.Unary.All.Properties where
open import Data.Maybe.Base
open import Data.Maybe.Relation.Unary.All as All
using (All; nothing; just)
open import Data.Product using (_×_; _,_)
open import Function
open import Relation.Unary
------------------------------------------------------------------------
-- Introduction (⁺) and elimination (⁻) rules for maybe operations
------------------------------------------------------------------------
-- map
module _ {a b p} {A : Set a} {B : Set b} {P : Pred B p} {f : A → B} where
map⁺ : ∀ {mx} → All (P ∘ f) mx → All P (map f mx)
map⁺ (just p) = just p
map⁺ nothing = nothing
map⁻ : ∀ {mx} → All P (map f mx) → All (P ∘ f) mx
map⁻ {just x} (just px) = just px
map⁻ {nothing} nothing = nothing
-- A variant of All.map.
module _ {a b p q} {A : Set a} {B : Set b} {f : A → B}
{P : Pred A p} {Q : Pred B q} where
gmap : P ⊆ Q ∘ f → All P ⊆ All Q ∘ map f
gmap g = map⁺ ∘ All.map g
------------------------------------------------------------------------
-- _<∣>_
module _ {a p} {A : Set a} {P : A → Set p} where
<∣>⁺ : ∀ {mx my} → All P mx → All P my → All P (mx <∣> my)
<∣>⁺ (just px) pmy = just px
<∣>⁺ nothing pmy = pmy
<∣>⁻ : ∀ mx {my} → All P (mx <∣> my) → All P mx
<∣>⁻ (just x) pmxy = pmxy
<∣>⁻ nothing pmxy = nothing
| {
"alphanum_fraction": 0.4343434343,
"avg_line_length": 29.8867924528,
"ext": "agda",
"hexsha": "7270d8932bfe4b7c9d7dda21f890f465e96ce411",
"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/Maybe/Relation/Unary/All/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/Maybe/Relation/Unary/All/Properties.agda",
"max_line_length": 73,
"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/Maybe/Relation/Unary/All/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 489,
"size": 1584
} |
open import Prelude
open import RW.Language.RTerm
open import RW.Language.RTermUtils
open import RW.Language.RTermIdx
open import RW.Data.RTrie
open import RW.Strategy using (Trs; Symmetry; UData; u-data)
module RW.Language.RTermTrie where
open import RW.Utils.Monads
open Monad {{...}}
add-action : Name → ℕ × RTrie → ℕ × RTrie
add-action act bt
= let
ty = lift-ivar $ typeResult $ Ag2RType $ type act
in insertTerm act ty bt
replicateM : {A : Set} → List (Maybe A) → Maybe (List A)
replicateM [] = just []
replicateM (nothing ∷ _) = nothing
replicateM (just x ∷ xs) with replicateM xs
...| just xs' = just (x ∷ xs')
...| nothing = nothing
postulate
not-found : Name × UData
ul-is-nothing : Name × UData
search-action : RTermName → RBinApp ⊥ → RTrie → List (Name × UData)
search-action hd (_ , g₁ , g₂) trie
= let g□ = g₁ ∩↑ g₂
u₁ = g□ -↓ g₁
u₂ = g□ -↓ g₂
ul = replicateM (u₁ ∷ u₂ ∷ [])
in maybe (mkSearch g□) (ul-is-nothing ∷ []) ul
where
convert : RTerm (Maybe ⊥) → List (ℕ × RTerm ⊥) × Name → Name × UData
convert g□ (ns , act) = act , u-data (⊥2UnitCast g□) ns []
convert-sym : RTerm (Maybe ⊥) → List (ℕ × RTerm ⊥) × Name → Name × UData
convert-sym g□ (ns , act) = act , u-data (⊥2UnitCast g□) ns (Symmetry ∷ [])
mkLkup : List (RTerm ⊥) → Maybe (List (List (ℕ × RTerm ⊥) × Name))
mkLkup ul with lookupTerm (rapp hd ul) trie
...| [] = nothing
...| l = just l
mkSearch : RTerm (Maybe ⊥) → List (RTerm ⊥) → List (Name × UData)
mkSearch g□ ul with mkLkup ul
...| just l = map (convert g□) l
...| nothing with mkLkup (reverse ul)
...| nothing = not-found ∷ []
...| just l = map (convert-sym g□) l
| {
"alphanum_fraction": 0.5721448468,
"avg_line_length": 32.0535714286,
"ext": "agda",
"hexsha": "3b5a9baff8c281cbc6f8ede0eaf2792524a8e202",
"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": "2856afd12b7dbbcc908482975638d99220f38bf2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "VictorCMiraldo/agda-rw",
"max_forks_repo_path": "RW/Language/RTermTrie.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "2856afd12b7dbbcc908482975638d99220f38bf2",
"max_issues_repo_issues_event_max_datetime": "2015-05-28T14:48:03.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-06T15:03:33.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "VictorCMiraldo/agda-rw",
"max_issues_repo_path": "RW/Language/RTermTrie.agda",
"max_line_length": 81,
"max_stars_count": 16,
"max_stars_repo_head_hexsha": "2856afd12b7dbbcc908482975638d99220f38bf2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "VictorCMiraldo/agda-rw",
"max_stars_repo_path": "RW/Language/RTermTrie.agda",
"max_stars_repo_stars_event_max_datetime": "2019-10-24T17:38:20.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-02-09T15:43:38.000Z",
"num_tokens": 632,
"size": 1795
} |
module _ where
open import Agda.Builtin.Reflection renaming (bindTC to _>>=_)
open import Agda.Builtin.Equality
open import Agda.Builtin.String
macro
m : Name → Term → TC _
m f hole = do
ty ← getType f
ty ← normalise ty
quoteTC ty >>= unify hole
open import Agda.Builtin.Nat
import Agda.Builtin.Nat as Nat₁ renaming (Nat to Hombre)
import Agda.Builtin.Nat as Nat₂ renaming (Nat to ℕumber)
import Agda.Builtin.Nat as Nat₃ renaming (Nat to n)
import Agda.Builtin.Nat as Nat₄ renaming (Nat to N)
infix 0 _∋_
_∋_ : (A : Set) → A → A
A ∋ x = x
binderName : Term → String
binderName (pi _ (abs x _)) = x
binderName _ = "(no binder)"
f₁ : Nat₁.Hombre → Nat
f₁ x = x
f₂ : Nat₂.ℕumber → Nat
f₂ x = x
f₃ : Nat₃.n → Nat
f₃ x = x
f₄ : Nat₄.N → Nat
f₄ x = x
_ = binderName (m f₁) ≡ "h" ∋ refl
_ = binderName (m f₂) ≡ "z" ∋ refl -- Can't toLower ℕ
_ = binderName (m f₃) ≡ "z" ∋ refl -- Single lower case type name, don't pick same name for binder
_ = binderName (m f₄) ≡ "n" ∋ refl
| {
"alphanum_fraction": 0.6456692913,
"avg_line_length": 22.0869565217,
"ext": "agda",
"hexsha": "8303738c175a613b7f1c1584a47595d4f3646763",
"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/Issue5048.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/Issue5048.agda",
"max_line_length": 99,
"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/Issue5048.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": 382,
"size": 1016
} |
module Base.Free.Properties where
open import Relation.Binary.PropositionalEquality using (_≢_)
open import Base.Free using (Free; pure; impure)
discriminate : ∀ {S P A} {s : S} {pf : P s → Free S P A} {a : A} → impure s pf ≢ pure a
discriminate = λ ()
| {
"alphanum_fraction": 0.6161971831,
"avg_line_length": 31.5555555556,
"ext": "agda",
"hexsha": "90e938fc3fd0b028e916a17396d8f3ac92cf4a50",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-05-14T07:48:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-04-08T11:23:46.000Z",
"max_forks_repo_head_hexsha": "6931b9ca652a185a92dd824373f092823aea4ea9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "FreeProving/free-compiler",
"max_forks_repo_path": "base/agda/Base/Free/Properties.agda",
"max_issues_count": 120,
"max_issues_repo_head_hexsha": "6931b9ca652a185a92dd824373f092823aea4ea9",
"max_issues_repo_issues_event_max_datetime": "2020-12-08T07:46:01.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-04-09T09:40:39.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "FreeProving/free-compiler",
"max_issues_repo_path": "base/agda/Base/Free/Properties.agda",
"max_line_length": 87,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "6931b9ca652a185a92dd824373f092823aea4ea9",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "FreeProving/free-compiler",
"max_stars_repo_path": "base/agda/Base/Free/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-21T13:38:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-02-06T11:03:34.000Z",
"num_tokens": 81,
"size": 284
} |
{-# OPTIONS --cubical --safe #-}
module Algebra where
open import Prelude
module _ {a} {A : Type a} (_∙_ : A → A → A) where
Associative : Type a
Associative = ∀ x y z → (x ∙ y) ∙ z ≡ x ∙ (y ∙ z)
Commutative : Type _
Commutative = ∀ x y → x ∙ y ≡ y ∙ x
Idempotent : Type _
Idempotent = ∀ x → x ∙ x ≡ x
Identityˡ : (A → B → B) → A → Type _
Identityˡ _∙_ x = ∀ y → x ∙ y ≡ y
Zeroˡ : (A → B → A) → A → Type _
Zeroˡ _∙_ x = ∀ y → x ∙ y ≡ x
Zeroʳ : (A → B → B) → B → Type _
Zeroʳ _∙_ x = ∀ y → y ∙ x ≡ x
Identityʳ : (A → B → A) → B → Type _
Identityʳ _∙_ x = ∀ y → y ∙ x ≡ y
_Distributesʳ_ : (A → B → B) → (B → B → B) → Type _
_⊗_ Distributesʳ _⊕_ = ∀ x y z → x ⊗ (y ⊕ z) ≡ (x ⊗ y) ⊕ (x ⊗ z)
_Distributesˡ_ : (B → A → B) → (B → B → B) → Type _
_⊗_ Distributesˡ _⊕_ = ∀ x y z → (x ⊕ y) ⊗ z ≡ (x ⊗ z) ⊕ (y ⊗ z)
Cancellableˡ : (A → B → C) → A → Type _
Cancellableˡ _⊗_ c = ∀ x y → c ⊗ x ≡ c ⊗ y → x ≡ y
Cancellableʳ : (A → B → C) → B → Type _
Cancellableʳ _⊗_ c = ∀ x y → x ⊗ c ≡ y ⊗ c → x ≡ y
Cancellativeˡ : (A → B → C) → Type _
Cancellativeˡ _⊗_ = ∀ c → Cancellableˡ _⊗_ c
Cancellativeʳ : (A → B → C) → Type _
Cancellativeʳ _⊗_ = ∀ c → Cancellableʳ _⊗_ c
record Semigroup ℓ : Type (ℓsuc ℓ) where
infixl 6 _∙_
field
𝑆 : Type ℓ
_∙_ : 𝑆 → 𝑆 → 𝑆
assoc : ∀ x y z → (x ∙ y) ∙ z ≡ x ∙ (y ∙ z)
record Monoid ℓ : Type (ℓsuc ℓ) where
infixl 6 _∙_
field
𝑆 : Type ℓ
_∙_ : 𝑆 → 𝑆 → 𝑆
ε : 𝑆
assoc : ∀ x y z → (x ∙ y) ∙ z ≡ x ∙ (y ∙ z)
ε∙ : ∀ x → ε ∙ x ≡ x
∙ε : ∀ x → x ∙ ε ≡ x
semigroup : Semigroup ℓ
semigroup = record
{ 𝑆 = 𝑆; _∙_ = _∙_; assoc = assoc }
record MonoidHomomorphism_⟶_
{ℓ₁ ℓ₂}
(from : Monoid ℓ₁)
(to : Monoid ℓ₂)
: Type (ℓsuc (ℓ₁ ℓ⊔ ℓ₂)) where
open Monoid from
open Monoid to
renaming ( 𝑆 to 𝑅
; _∙_ to _⊙_
; ε to ⓔ
)
field
f : 𝑆 → 𝑅
∙-homo : ∀ x y → f (x ∙ y) ≡ f x ⊙ f y
ε-homo : f ε ≡ ⓔ
record Group ℓ : Type (ℓsuc ℓ) where
field
monoid : Monoid ℓ
open Monoid monoid public
field
-_ : 𝑆 → 𝑆
∙⁻ : ∀ x → x ∙ - x ≡ ε
⁻∙ : ∀ x → - x ∙ x ≡ ε
open import Path.Reasoning
cancelˡ : Cancellativeˡ _∙_
cancelˡ x y z p =
y ≡˘⟨ ε∙ y ⟩
ε ∙ y ≡˘⟨ cong (_∙ y) (⁻∙ x) ⟩
(- x ∙ x) ∙ y ≡⟨ assoc (- x) x y ⟩
- x ∙ (x ∙ y) ≡⟨ cong (- x ∙_) p ⟩
- x ∙ (x ∙ z) ≡˘⟨ assoc (- x) x z ⟩
(- x ∙ x) ∙ z ≡⟨ cong (_∙ z) (⁻∙ x) ⟩
ε ∙ z ≡⟨ ε∙ z ⟩
z ∎
cancelʳ : Cancellativeʳ _∙_
cancelʳ x y z p =
y ≡˘⟨ ∙ε y ⟩
y ∙ ε ≡˘⟨ cong (y ∙_) (∙⁻ x) ⟩
y ∙ (x ∙ - x) ≡˘⟨ assoc y x (- x) ⟩
(y ∙ x) ∙ - x ≡⟨ cong (_∙ - x) p ⟩
(z ∙ x) ∙ - x ≡⟨ assoc z x (- x) ⟩
z ∙ (x ∙ - x) ≡⟨ cong (z ∙_) (∙⁻ x) ⟩
z ∙ ε ≡⟨ ∙ε z ⟩
z ∎
record CommutativeMonoid ℓ : Type (ℓsuc ℓ) where
field
monoid : Monoid ℓ
open Monoid monoid public
field
comm : Commutative _∙_
record Semilattice ℓ : Type (ℓsuc ℓ) where
field
commutativeMonoid : CommutativeMonoid ℓ
open CommutativeMonoid commutativeMonoid public
field
idem : Idempotent _∙_
record NearSemiring ℓ : Type (ℓsuc ℓ) where
infixl 6 _+_
infixl 7 _*_
field
𝑅 : Type ℓ
_+_ : 𝑅 → 𝑅 → 𝑅
_*_ : 𝑅 → 𝑅 → 𝑅
1# : 𝑅
0# : 𝑅
+-assoc : Associative _+_
*-assoc : Associative _*_
0+ : Identityˡ _+_ 0#
+0 : Identityʳ _+_ 0#
1* : Identityˡ _*_ 1#
*1 : Identityʳ _*_ 1#
0* : Zeroˡ _*_ 0#
⟨+⟩* : _*_ Distributesˡ _+_
record Semiring ℓ : Type (ℓsuc ℓ) where
field
nearSemiring : NearSemiring ℓ
open NearSemiring nearSemiring public
field
+-comm : Commutative _+_
*0 : Zeroʳ _*_ 0#
*⟨+⟩ : _*_ Distributesʳ _+_
record IdempotentSemiring ℓ : Type (ℓsuc ℓ) where
field
semiring : Semiring ℓ
open Semiring semiring public
field
+-idem : Idempotent _+_
record CommutativeSemiring ℓ : Type (ℓsuc ℓ) where
field
semiring : Semiring ℓ
open Semiring semiring public
field
*-comm : Commutative _*_
record LeftSemimodule {ℓ₁} (semiring : Semiring ℓ₁) ℓ₂ : Type (ℓ₁ ℓ⊔ ℓsuc ℓ₂) where
open Semiring semiring public
field
semimodule : CommutativeMonoid ℓ₂
open CommutativeMonoid semimodule renaming (_∙_ to _∪_) public
renaming (𝑆 to 𝑉
; assoc to ∪-assoc
; ε∙ to ∅∪
; ∙ε to ∪∅
; ε to ∅
)
infixr 7 _⋊_
field
_⋊_ : 𝑅 → 𝑉 → 𝑉
⟨*⟩⋊ : ∀ x y z → (x * y) ⋊ z ≡ x ⋊ (y ⋊ z)
⟨+⟩⋊ : ∀ x y z → (x + y) ⋊ z ≡ (x ⋊ z) ∪ (y ⋊ z)
⋊⟨∪⟩ : _⋊_ Distributesʳ _∪_
1⋊ : Identityˡ _⋊_ 1#
0⋊ : ∀ x → 0# ⋊ x ≡ ∅
⋊∅ : ∀ x → x ⋊ ∅ ≡ ∅
record SemimoduleHomomorphism[_]_⟶_
{ℓ₁ ℓ₂ ℓ₃}
(rng : Semiring ℓ₁)
(from : LeftSemimodule rng ℓ₂)
(to : LeftSemimodule rng ℓ₃) : Type (ℓ₁ ℓ⊔ ℓsuc (ℓ₂ ℓ⊔ ℓ₃)) where
open Semiring rng
open LeftSemimodule from using (_⋊_; monoid)
open LeftSemimodule to using () renaming (_⋊_ to _⋊′_; monoid to monoid′)
field mon-homo : MonoidHomomorphism monoid ⟶ monoid′
open MonoidHomomorphism_⟶_ mon-homo public
field ⋊-homo : ∀ r x → f (r ⋊ x) ≡ r ⋊′ f x
record StarSemiring ℓ : Type (ℓsuc ℓ) where
field
semiring : Semiring ℓ
open Semiring semiring public
field
_⋆ : 𝑅 → 𝑅
star-iterʳ : ∀ x → x ⋆ ≡ 1# + x * x ⋆
star-iterˡ : ∀ x → x ⋆ ≡ 1# + x ⋆ * x
_⁺ : 𝑅 → 𝑅
x ⁺ = x * x ⋆
record Functor ℓ₁ ℓ₂ : Type (ℓsuc (ℓ₁ ℓ⊔ ℓ₂)) where
field
𝐹 : Type ℓ₁ → Type ℓ₂
map : (A → B) → 𝐹 A → 𝐹 B
map-id : map (id {ℓ₁} {A}) ≡ id
map-comp : (f : B → C) → (g : A → B) → map (f ∘ g) ≡ map f ∘ map g
record Applicative ℓ₁ ℓ₂ : Type (ℓsuc (ℓ₁ ℓ⊔ ℓ₂)) where
field
functor : Functor ℓ₁ ℓ₂
open Functor functor public
infixl 5 _<*>_
field
pure : A → 𝐹 A
_<*>_ : 𝐹 (A → B) → 𝐹 A → 𝐹 B
map-ap : (f : A → B) → map f ≡ pure f <*>_
pure-homo : (f : A → B) → (x : A) → map f (pure x) ≡ pure (f x)
<*>-interchange : (u : 𝐹 (A → B)) → (y : A) → u <*> pure y ≡ map (_$ y) u
<*>-comp : (u : 𝐹 (B → C)) → (v : 𝐹 (A → B)) → (w : 𝐹 A) → pure _∘′_ <*> u <*> v <*> w ≡ u <*> (v <*> w)
record IsMonad {ℓ₁} {ℓ₂} (𝐹 : Type ℓ₁ → Type ℓ₂) : Type (ℓsuc ℓ₁ ℓ⊔ ℓ₂) where
infixl 1 _>>=_
field
_>>=_ : 𝐹 A → (A → 𝐹 B) → 𝐹 B
return : A → 𝐹 A
>>=-idˡ : (f : A → 𝐹 B) → (x : A) → (return x >>= f) ≡ f x
>>=-idʳ : (x : 𝐹 A) → (x >>= return) ≡ x
>>=-assoc : (xs : 𝐹 A) (f : A → 𝐹 B) (g : B → 𝐹 C) → ((xs >>= f) >>= g) ≡ (xs >>= (λ x → f x >>= g))
record Monad ℓ₁ ℓ₂ : Type (ℓsuc (ℓ₁ ℓ⊔ ℓ₂)) where
field
𝐹 : Type ℓ₁ → Type ℓ₂
isMonad : IsMonad 𝐹
open IsMonad isMonad public
record MonadHomomorphism_⟶_
{ℓ₁ ℓ₂ ℓ₃}
(from : Monad ℓ₁ ℓ₂)
(to : Monad ℓ₁ ℓ₃) : Type (ℓsuc ℓ₁ ℓ⊔ ℓ₂ ℓ⊔ ℓ₃) where
module F = Monad from
module T = Monad to
field
f : F.𝐹 A → T.𝐹 A
>>=-homo : (xs : F.𝐹 A) (k : A → F.𝐹 B) → (f xs T.>>= (f ∘ k)) ≡ f (xs F.>>= k)
return-homo : (x : A) → f (F.return x) ≡ T.return x
record IsSetMonad {ℓ₁} {ℓ₂} (𝐹 : Type ℓ₁ → Type ℓ₂) : Type (ℓsuc ℓ₁ ℓ⊔ ℓ₂) where
infixl 1 _>>=_
field
_>>=_ : 𝐹 A → (A → 𝐹 B) → 𝐹 B
return : A → 𝐹 A
trunc : isSet A → isSet (𝐹 A)
>>=-idˡ : isSet B → (f : A → 𝐹 B) → (x : A) → (return x >>= f) ≡ f x
>>=-idʳ : isSet A → (x : 𝐹 A) → (x >>= return) ≡ x
>>=-assoc : isSet C → (xs : 𝐹 A) (f : A → 𝐹 B) (g : B → 𝐹 C) → ((xs >>= f) >>= g) ≡ (xs >>= (λ x → f x >>= g))
record SetMonad ℓ₁ ℓ₂ : Type (ℓsuc (ℓ₁ ℓ⊔ ℓ₂)) where
field
𝐹 : Type ℓ₁ → Type ℓ₂
isSetMonad : IsSetMonad 𝐹
open IsSetMonad isSetMonad public
record SetMonadHomomorphism_⟶_
{ℓ₁ ℓ₂ ℓ₃}
(from : SetMonad ℓ₁ ℓ₂)
(to : SetMonad ℓ₁ ℓ₃) : Type (ℓsuc ℓ₁ ℓ⊔ ℓ₂ ℓ⊔ ℓ₃) where
module F = SetMonad from
module T = SetMonad to
field
f : F.𝐹 A → T.𝐹 A
>>=-homo : (xs : F.𝐹 A) (k : A → F.𝐹 B) → (f xs T.>>= (f ∘ k)) ≡ f (xs F.>>= k)
return-homo : (x : A) → f (F.return x) ≡ T.return x
record Alternative ℓ₁ ℓ₂ : Type (ℓsuc (ℓ₁ ℓ⊔ ℓ₂)) where
field
applicative : Applicative ℓ₁ ℓ₂
open Applicative applicative public
field
0# : 𝐹 A
_<|>_ : 𝐹 A → 𝐹 A → 𝐹 A
<|>-idˡ : (x : 𝐹 A) → 0# <|> x ≡ x
<|>-idʳ : (x : 𝐹 A) → x <|> 0# ≡ x
0-annˡ : (x : 𝐹 A) → 0# <*> x ≡ 0# {B}
<|>-distrib : (x y : 𝐹 (A → B)) → (z : 𝐹 A) → (x <|> y) <*> z ≡ (x <*> z) <|> (y <*> z)
record MonadPlus ℓ₁ ℓ₂ : Type (ℓsuc (ℓ₁ ℓ⊔ ℓ₂)) where
field
monad : Monad ℓ₁ ℓ₂
open Monad monad public
field
0# : 𝐹 A
_<|>_ : 𝐹 A → 𝐹 A → 𝐹 A
<|>-idˡ : (x : 𝐹 A) → 0# <|> x ≡ x
<|>-idʳ : (x : 𝐹 A) → x <|> 0# ≡ x
0-annˡ : (x : A → 𝐹 B) → (0# >>= x) ≡ 0#
<|>-distrib : (x y : 𝐹 A) → (z : A → 𝐹 B) → ((x <|> y) >>= z) ≡ (x >>= z) <|> (y >>= z)
Endo : Type a → Type a
Endo A = A → A
endoMonoid : ∀ {a} → Type a → Monoid a
endoMonoid A .Monoid.𝑆 = Endo A
endoMonoid A .Monoid.ε x = x
endoMonoid A .Monoid._∙_ f g x = f (g x)
endoMonoid A .Monoid.assoc _ _ _ = refl
endoMonoid A .Monoid.ε∙ _ = refl
endoMonoid A .Monoid.∙ε _ = refl
record Foldable ℓ₁ ℓ₂ : Type (ℓsuc (ℓ₁ ℓ⊔ ℓ₂)) where
field
𝐹 : Type ℓ₁ → Type ℓ₂
open Monoid ⦃ ... ⦄
field
foldMap : {A : Type ℓ₁} ⦃ _ : Monoid ℓ₁ ⦄ → (A → 𝑆) → 𝐹 A → 𝑆
foldr : {A B : Type ℓ₁} → (A → B → B) → B → 𝐹 A → B
foldr f b xs = foldMap ⦃ endoMonoid _ ⦄ f xs b
record GradedMonad {ℓ₁} (monoid : Monoid ℓ₁) ℓ₂ ℓ₃ : Type (ℓ₁ ℓ⊔ ℓsuc (ℓ₂ ℓ⊔ ℓ₃)) where
open Monoid monoid
field
𝐹 : 𝑆 → Type ℓ₂ → Type ℓ₃
pure : A → 𝐹 ε A
_>>=_ : ∀ {x y} → 𝐹 x A → (A → 𝐹 y B) → 𝐹 (x ∙ y) B
>>=-idˡ : ∀ {s} (f : A → 𝐹 s B) → (x : A) → (pure x >>= f) ≡[ i ≔ 𝐹 (ε∙ s i) B ]≡ (f x)
>>=-idʳ : ∀ {s} (x : 𝐹 s A) → (x >>= pure) ≡[ i ≔ 𝐹 (∙ε s i) A ]≡ x
>>=-assoc : ∀ {x y z} (xs : 𝐹 x A) (f : A → 𝐹 y B) (g : B → 𝐹 z C) → ((xs >>= f) >>= g) ≡[ i ≔ 𝐹 (assoc x y z i) C ]≡ (xs >>= (λ x → f x >>= g))
infixr 0 proven-bind
proven-bind : ∀ {x y z} → 𝐹 x A → (A → 𝐹 y B) → (x ∙ y) ≡ z → 𝐹 z B
proven-bind xs f proof = subst (flip 𝐹 _) proof (xs >>= f)
syntax proven-bind xs f proof = xs >>=[ proof ] f
infixr 0 proven-do
proven-do : ∀ {x y z} → 𝐹 x A → (A → 𝐹 y B) → (x ∙ y) ≡ z → 𝐹 z B
proven-do = proven-bind
syntax proven-do xs (λ x → e) proof = x ← xs [ proof ] e
map : ∀ {x} → (A → B) → 𝐹 x A → 𝐹 x B
map f xs = xs >>=[ ∙ε _ ] (pure ∘ f)
_<*>_ : ∀ {x y} → 𝐹 x (A → B) → 𝐹 y A → 𝐹 (x ∙ y) B
fs <*> xs = fs >>= flip map xs
_>>=ε_ : ∀ {x} → 𝐹 x A → (A → 𝐹 ε B) → 𝐹 x B
xs >>=ε f = xs >>=[ ∙ε _ ] f
| {
"alphanum_fraction": 0.4828904607,
"avg_line_length": 27.8244680851,
"ext": "agda",
"hexsha": "d18072d5e13904ade06c3ee413d8a32acfb05f51",
"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": "Algebra.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": "Algebra.agda",
"max_line_length": 148,
"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": "Algebra.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": 5361,
"size": 10462
} |
module Monads where
open import Library
open import Categories
record Monad {a}{b}(C : Cat {a}{b}) : Set (a ⊔ b) where
constructor monad
open Cat C
field T : Obj → Obj
η : ∀ {X} → Hom X (T X)
bind : ∀{X Y} → Hom X (T Y) → Hom (T X) (T Y)
law1 : ∀{X} → bind (η {X}) ≅ iden {T X}
law2 : ∀{X Y}{f : Hom X (T Y)} → comp (bind f) η ≅ f
law3 : ∀{X Y Z}{f : Hom X (T Y)}{g : Hom Y (T Z)} →
bind (comp (bind g) f) ≅ comp (bind g) (bind f)
open import Functors
TFun : ∀{a b}{C : Cat {a}{b}} → Monad C → Fun C C
TFun {C = C} M = let open Monad M; open Cat C in record {
OMap = T;
HMap = bind ∘ comp η;
fid =
proof
bind (comp η iden)
≅⟨ cong bind idr ⟩
bind η
≅⟨ law1 ⟩
iden ∎;
fcomp = λ {_}{_}{_}{f}{g} →
proof
bind (comp η (comp f g))
≅⟨ cong bind (sym ass) ⟩
bind (comp (comp η f) g)
≅⟨ cong (λ f → bind (comp f g)) (sym law2) ⟩
bind (comp (comp (bind (comp η f)) η) g)
≅⟨ cong bind ass ⟩
bind (comp (bind (comp η f)) (comp η g))
≅⟨ law3 ⟩
comp (bind (comp η f)) (bind (comp η g))
∎}
| {
"alphanum_fraction": 0.4802110818,
"avg_line_length": 27.0714285714,
"ext": "agda",
"hexsha": "511ebf1c6f7a8be4d0e464e8e4f8104134167935",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jmchapman/Relative-Monads",
"max_forks_repo_path": "Monads.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jmchapman/Relative-Monads",
"max_issues_repo_path": "Monads.agda",
"max_line_length": 63,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jmchapman/Relative-Monads",
"max_stars_repo_path": "Monads.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z",
"num_tokens": 484,
"size": 1137
} |
module CS410-Prelude where
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Standard Equipment for use in Exercises
------------------------------------------------------------------------------
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- functional equipment (types may be generalized later)
------------------------------------------------------------------------------
-- the polymorphic identity function
id : {X : Set} -> X -> X
id x = x
-- standard composition: f << g is "f after g"
_<<_ : {X Y Z : Set} -> (Y -> Z) -> (X -> Y) -> (X -> Z)
(f << g) x = f (g x)
-- diagrammatic composition: f >> g is "f then g"
_>>_ : {X Y Z : Set} -> (X -> Y) -> (Y -> Z) -> (X -> Z)
-- ^^^^^^^^ dominoes!
(f >> g) x = g (f x)
infixr 5 _>>_
-- infix application
_$_ : {S : Set}{T : S -> Set}(f : (x : S) -> T x)(s : S) -> T s
f $ s = f s
infixl 2 _$_
------------------------------------------------------------------------------
-- some basic "logical" types
------------------------------------------------------------------------------
data Zero : Set where
-- to give a value in a data, choose one constructor
-- there are no constructors
-- so that's impossible
record One : Set where
-- to give a value in a record type, fill all its fields
-- there are no fields
-- so that's trivial
-- (can we have a constructor, for convenience?)
constructor <>
data _+_ (S : Set)(T : Set) : Set where -- "where" wants an indented block
-- to offer a choice of constructors, list them with their types
inl : S -> S + T -- constructors can pack up stuff
inr : T -> S + T
-- in Haskell, this was called "Either S T"
record Sg (S : Set)(T : S -> Set) : Set where -- Sg is short for "Sigma"
constructor _,_
field -- introduces a bunch of fields, listed with their types
fst : S
snd : T fst
-- make _*_ from Sg ?
open Sg public
_*_ : Set -> Set -> Set
S * T = Sg S \ _ -> T
infixr 4 _,_ _*_
------------------------------------------------------------------------------
-- natural numbers and addition
------------------------------------------------------------------------------
data Nat : Set where
zero : Nat
suc : Nat -> Nat -- recursive data type
{-# BUILTIN NATURAL Nat #-}
-- ^^^^^^^^^^^^^^^^^^^ this pragma lets us use decimal notation
_+N_ : Nat -> Nat -> Nat
zero +N y = y
suc x +N y = suc (x +N y) -- there are other choices
------------------------------------------------------------------------------
-- equality
------------------------------------------------------------------------------
data _==_ {X : Set} : X -> X -> Set where
refl : (x : X) -> x == x -- the relation that's "only reflexive"
{-# BUILTIN EQUALITY _==_ #-} -- we'll see what that's for, later
_=$=_ : {X Y : Set}{f f' : X -> Y}{x x' : X} ->
f == f' -> x == x' -> f x == f' x'
refl f =$= refl x = refl (f x)
_=$_ : {S : Set}{T : S -> Set}{f g : (x : S) -> T x} -> (f == g) -> (x : S) -> f x == g x
refl f =$ x = refl (f x)
infixl 2 _=$=_ _=$_
sym : {X : Set}{x y : X} -> x == y -> y == x
sym (refl x) = refl x
_[QED] : {X : Set}(x : X) -> x == x
x [QED] = refl x
_=[_>=_ : {X : Set}(x : X){y z : X} -> x == y -> y == z -> x == z
x =[ refl .x >= q = q
_=<_]=_ : {X : Set}(x : X){y z : X} -> y == x -> y == z -> x == z
x =< refl .x ]= q = q
infixr 1 _=[_>=_ _=<_]=_
infixr 2 _[QED]
------------------------------------------------------------------------------
-- greater-than-or-equals
------------------------------------------------------------------------------
_>=_ : Nat -> Nat -> Set
x >= zero = One
zero >= suc y = Zero
suc x >= suc y = x >= y
refl->= : (n : Nat) -> n >= n
refl->= zero = record {}
refl->= (suc n) = refl->= n
trans->= : (x y z : Nat) -> x >= y -> y >= z -> x >= z
trans->= x y zero x>=y y>=z = record {}
trans->= x zero (suc z) x>=y ()
trans->= zero (suc y) (suc z) () y>=z
trans->= (suc x) (suc y) (suc z) x>=y y>=z = trans->= x y z x>=y y>=z
suc->= : (x : Nat) -> suc x >= x
suc->= zero = <>
suc->= (suc x) = suc->= x
----------------------------------------------------------------------------
-- Two -- the type of Boolean values
----------------------------------------------------------------------------
data Two : Set where tt ff : Two
{-# BUILTIN BOOL Two #-}
{-# BUILTIN TRUE tt #-}
{-# BUILTIN FALSE ff #-}
-- nondependent conditional with traditional syntax
if_then_else_ : forall {l}{X : Set l} -> Two -> X -> X -> X
if tt then t else e = t
if ff then t else e = e
-- dependent conditional cooked for partial application
caseTwo : forall {l}{P : Two -> Set l} -> P tt -> P ff -> (b : Two) -> P b
caseTwo t f tt = t
caseTwo t f ff = f
----------------------------------------------------------------------------
-- lists
----------------------------------------------------------------------------
data List (X : Set) : Set where
[] : List X
_,-_ : (x : X)(xs : List X) -> List X
infixr 4 _,-_
{-# COMPILE GHC List = data [] ([] | (:)) #-}
{-# BUILTIN LIST List #-}
----------------------------------------------------------------------------
-- chars and strings
----------------------------------------------------------------------------
postulate -- this means that we just suppose the following things exist...
Char : Set
String : Set
{-# BUILTIN CHAR Char #-}
{-# BUILTIN STRING String #-}
primitive -- these are baked in; they even work!
primCharEquality : Char -> Char -> Two
primStringAppend : String -> String -> String
primStringToList : String -> List Char
primStringFromList : List Char -> String
| {
"alphanum_fraction": 0.3876271186,
"avg_line_length": 30.890052356,
"ext": "agda",
"hexsha": "d85d9c84f525250cfe9d8d6969f9d0e5e735e612",
"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": "5b20aeffeaf714769e121bc9f7aa7c25106d0a1b",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "poscat0x04/CS410",
"max_forks_repo_path": "CS410-Prelude.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5b20aeffeaf714769e121bc9f7aa7c25106d0a1b",
"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": "poscat0x04/CS410",
"max_issues_repo_path": "CS410-Prelude.agda",
"max_line_length": 89,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5b20aeffeaf714769e121bc9f7aa7c25106d0a1b",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "poscat0x04/CS410",
"max_stars_repo_path": "CS410-Prelude.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1548,
"size": 5900
} |
------------------------------------------------------------------------
-- Traditional non-dependent lenses
------------------------------------------------------------------------
{-# OPTIONS --cubical #-}
import Equality.Path as P
module Lens.Non-dependent.Traditional
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq
open import Logical-equivalence using (_⇔_)
open import Prelude
open import Bijection equality-with-J as Bij using (_↔_)
open import Circle eq as Circle using (𝕊¹)
open import Equality.Path.Isomorphisms eq
open import Equivalence equality-with-J as Eq
using (_≃_; Is-equivalence)
open import Function-universe equality-with-J as F hiding (id; _∘_)
open import H-level equality-with-J as H-level
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional eq as Trunc
using (∥_∥; ∣_∣)
open import Preimage equality-with-J using (_⁻¹_)
open import Surjection equality-with-J using (_↠_)
open import Univalence-axiom equality-with-J
open import Lens.Non-dependent eq as Non-dependent
hiding (no-first-projection-lens; no-singleton-projection-lens)
private
variable
a b c p : Level
A A₁ A₂ B B₁ B₂ : Type a
u v x₁ x₂ y₁ y₂ : A
------------------------------------------------------------------------
-- Traditional lenses
-- Lenses.
record Lens (A : Type a) (B : Type b) : Type (a ⊔ b) where
field
-- Getter and setter.
get : A → B
set : A → B → A
-- Lens laws.
get-set : ∀ a b → get (set a b) ≡ b
set-get : ∀ a → set a (get a) ≡ a
set-set : ∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂
-- A combination of get and set.
modify : (B → B) → A → A
modify f x = set x (f (get x))
instance
-- Traditional lenses have getters and setters.
has-getter-and-setter :
Has-getter-and-setter (Lens {a = a} {b = b})
has-getter-and-setter = record
{ get = Lens.get
; set = Lens.set
}
-- Lens A B is isomorphic to a nested Σ-type.
Lens-as-Σ :
Lens A B ↔
∃ λ (get : A → B) →
∃ λ (set : A → B → A) →
(∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)
Lens-as-Σ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ l → get l , set l , get-set l , set-get l , set-set l
; from = λ { (get , set , get-set , set-get , set-set) →
record
{ get = get
; set = set
; get-set = get-set
; set-get = set-get
; set-set = set-set
}
}
}
; right-inverse-of = refl
}
; left-inverse-of = refl
}
where
open Lens
private
variable
l₁ l₂ : Lens A B
-- An example: A lens corresponding to the value of a function for a
-- certain input.
function-at : Decidable-equality A → A → Lens (A → B) B
function-at _≟_ a = record
{ get = λ f → f a
; set = λ f b a′ → if a ≟ a′ then b else f a′
; get-set = λ f b → lemma₁ (a ≟ a)
; set-get = λ f → ⟨ext⟩ λ a′ → lemma₂ f (a ≟ a′)
; set-set = λ f b₁ b₂ → ⟨ext⟩ λ a′ → lemma₃ (a ≟ a′)
}
where
lemma₁ :
∀ {b₁ b₂} (d : Dec (a ≡ a)) →
if d then b₁ else b₂ ≡ b₁
lemma₁ (yes _) = refl _
lemma₁ (no a≢a) = ⊥-elim $ a≢a (refl _)
lemma₂ :
∀ f {a′} (d : Dec (a ≡ a′)) →
if d then f a else f a′ ≡ f a′
lemma₂ f (yes a≡a′) = cong f a≡a′
lemma₂ _ (no _) = refl _
lemma₃ :
∀ {a′ b₁ b₂ b₃} (d : Dec (a ≡ a′)) →
if d then b₂ else (if d then b₁ else b₃) ≡
if d then b₂ else b₃
lemma₃ (yes _) = refl _
lemma₃ (no _) = refl _
------------------------------------------------------------------------
-- Somewhat coherent lenses
-- Traditional lenses that satisfy some extra coherence properties.
record Coherent-lens (A : Type a) (B : Type b) : Type (a ⊔ b) where
field
lens : Lens A B
open Lens lens public
field
get-set-get : ∀ a → cong get (set-get a) ≡ get-set a (get a)
get-set-set :
∀ a b₁ b₂ →
cong get (set-set a b₁ b₂) ≡
trans (get-set (set a b₁) b₂) (sym (get-set a b₂))
instance
-- Somewhat coherent lenses have getters and setters.
coherent-has-getter-and-setter :
Has-getter-and-setter (Coherent-lens {a = a} {b = b})
coherent-has-getter-and-setter = record
{ get = Coherent-lens.get
; set = Coherent-lens.set
}
-- Coherent-lens A B is equivalent to a nested Σ-type.
Coherent-lens-as-Σ :
Coherent-lens A B ≃
∃ λ (l : Lens A B) →
let open Lens l in
(∀ a → cong get (set-get a) ≡ get-set a (get a)) ×
(∀ a b₁ b₂ →
cong get (set-set a b₁ b₂) ≡
trans (get-set (set a b₁) b₂) (sym (get-set a b₂)))
Coherent-lens-as-Σ = Eq.↔→≃
(λ l → lens l , get-set-get l , get-set-set l)
(λ (l , get-set-get , get-set-set) → record
{ lens = l
; get-set-get = get-set-get
; get-set-set = get-set-set
})
refl
refl
where
open Coherent-lens
------------------------------------------------------------------------
-- Some lemmas
-- If two lenses have equal setters, then they also have equal
-- getters.
getters-equal-if-setters-equal :
let open Lens in
(l₁ l₂ : Lens A B) →
set l₁ ≡ set l₂ →
get l₁ ≡ get l₂
getters-equal-if-setters-equal l₁ l₂ setters-equal = ⟨ext⟩ λ a →
get l₁ a ≡⟨ cong (get l₁) $ sym $ set-get l₂ _ ⟩
get l₁ (set l₂ a (get l₂ a)) ≡⟨ cong (λ f → get l₁ (f _ _)) $ sym setters-equal ⟩
get l₁ (set l₁ a (get l₂ a)) ≡⟨ get-set l₁ _ _ ⟩∎
get l₂ a ∎
where
open Lens
-- If the forward direction of an equivalence is Lens.get l, then the
-- setter of l can be expressed using the other direction of the
-- equivalence.
from≡set :
∀ (l : Lens A B) is-equiv →
let open Lens
A≃B = Eq.⟨ get l , is-equiv ⟩
in
∀ a b → _≃_.from A≃B b ≡ set l a b
from≡set l is-equiv a b =
_≃_.to-from Eq.⟨ get , is-equiv ⟩ (
get (set a b) ≡⟨ get-set _ _ ⟩∎
b ∎)
where
open Lens l
------------------------------------------------------------------------
-- Some lens isomorphisms
-- Lens preserves equivalences.
Lens-cong : A₁ ≃ A₂ → B₁ ≃ B₂ → Lens A₁ B₁ ≃ Lens A₂ B₂
Lens-cong {A₁ = A₁} {A₂ = A₂} {B₁ = B₁} {B₂ = B₂} A₁≃A₂ B₁≃B₂ =
Lens A₁ B₁ ↔⟨ Lens-as-Σ ⟩
(∃ λ (get : A₁ → B₁) →
∃ λ (set : A₁ → B₁ → A₁) →
(∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)) ↝⟨ (Σ-cong (→-cong ext A₁≃A₂ B₁≃B₂) λ get →
Σ-cong (→-cong ext A₁≃A₂ $ →-cong ext B₁≃B₂ A₁≃A₂) λ set →
(Π-cong ext A₁≃A₂ λ a → Π-cong ext B₁≃B₂ λ b →
inverse (Eq.≃-≡ B₁≃B₂) F.∘
(≡⇒≃ $ cong (_≡ _)
(get (set a b) ≡⟨ sym $ cong₂ (λ a b → get (set a b))
(_≃_.left-inverse-of A₁≃A₂ _)
(_≃_.left-inverse-of B₁≃B₂ _) ⟩
get (set (_≃_.from A₁≃A₂ (_≃_.to A₁≃A₂ a))
(_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ b))) ≡⟨ cong get $ sym $ _≃_.left-inverse-of A₁≃A₂ _ ⟩∎
get (_≃_.from A₁≃A₂ (_≃_.to A₁≃A₂
(set (_≃_.from A₁≃A₂ (_≃_.to A₁≃A₂ a))
(_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ b))))) ∎)))
×-cong
(Π-cong ext A₁≃A₂ λ a →
inverse (Eq.≃-≡ A₁≃A₂) F.∘
(≡⇒≃ $ cong (_≡ _)
(set a (get a) ≡⟨ cong (set a) $ sym $ _≃_.left-inverse-of B₁≃B₂ _ ⟩
set a (_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ (get a))) ≡⟨ cong (λ a → set a (_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ (get a)))) $ sym $
_≃_.left-inverse-of A₁≃A₂ _ ⟩∎
set (_≃_.from A₁≃A₂ (_≃_.to A₁≃A₂ a))
(_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂
(get (_≃_.from A₁≃A₂ (_≃_.to A₁≃A₂ a))))) ∎)))
×-cong
(inverse $ Π-cong ext (inverse A₁≃A₂) λ a →
inverse $ Π-cong ext B₁≃B₂ λ b₁ →
inverse $ Π-cong ext (inverse B₁≃B₂) λ b₂ →
(≡⇒≃ $ cong (λ a′ → set a′ (_≃_.from B₁≃B₂ b₂) ≡
set (_≃_.from A₁≃A₂ a) (_≃_.from B₁≃B₂ b₂))
(_≃_.from A₁≃A₂ (_≃_.to A₁≃A₂
(set (_≃_.from A₁≃A₂ a)
(_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ b₁)))) ≡⟨ _≃_.left-inverse-of A₁≃A₂ _ ⟩
set (_≃_.from A₁≃A₂ a)
(_≃_.from B₁≃B₂ (_≃_.to B₁≃B₂ b₁)) ≡⟨ cong (set (_≃_.from A₁≃A₂ a)) $
_≃_.left-inverse-of B₁≃B₂ _ ⟩∎
set (_≃_.from A₁≃A₂ a) b₁ ∎)) F.∘
Eq.≃-≡ A₁≃A₂)) ⟩
(∃ λ (get : A₂ → B₂) →
∃ λ (set : A₂ → B₂ → A₂) →
(∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)) ↔⟨ inverse Lens-as-Σ ⟩□
Lens A₂ B₂ □
-- If B is a proposition, then Lens A B is isomorphic to
-- (A → B) × ((a : A) → a ≡ a).
lens-to-proposition↔ :
Is-proposition B →
Lens A B ↔ (A → B) × ((a : A) → a ≡ a)
lens-to-proposition↔ {B = B} {A = A} B-prop =
Lens A B ↝⟨ Lens-as-Σ ⟩
(∃ λ (get : A → B) →
∃ λ (set : A → B → A) →
(∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)) ↝⟨ (∃-cong λ _ → ∃-cong λ _ →
drop-⊤-left-× λ _ →
_⇔_.to contractible⇔↔⊤ $
Π-closure ext 0 λ _ →
Π-closure ext 0 λ _ →
+⇒≡ B-prop) ⟩
(∃ λ (get : A → B) →
∃ λ (set : A → B → A) →
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)) ↝⟨ (∃-cong λ get → ∃-cong λ set → ∃-cong λ _ →
∀-cong ext λ a → ∀-cong ext λ b₁ → ∀-cong ext λ b₂ →
≡⇒↝ _ (
(set (set a b₁) b₂ ≡ set a b₂) ≡⟨ cong (λ b → set (set a b) b₂ ≡ _) (B-prop _ _) ⟩
(set (set a (get a)) b₂ ≡ set a b₂) ≡⟨ cong (λ b → set (set a (get a)) b ≡ _) (B-prop _ _) ⟩
(set (set a (get a)) (get (set a (get a))) ≡ set a b₂) ≡⟨ cong (λ b → _ ≡ set a b) (B-prop _ _) ⟩∎
(set (set a (get a)) (get (set a (get a))) ≡ set a (get a)) ∎)) ⟩
(∃ λ (get : A → B) →
∃ λ (set : A → B → A) →
(∀ a → set a (get a) ≡ a) ×
(∀ a → B → B →
set (set a (get a)) (get (set a (get a))) ≡
set a (get a))) ↝⟨ (∃-cong λ get → Σ-cong (A→B→A↔A→A get) λ _ → F.id) ⟩
((A → B) ×
∃ λ (f : A → A) →
(∀ a → f a ≡ a) ×
(∀ a → B → B → f (f a) ≡ f a)) ↝⟨ (∃-cong λ get → ∃-cong λ _ → ∃-cong λ _ →
∀-cong ext λ a →
drop-⊤-left-Π ext (B↔⊤ (get a)) F.∘
drop-⊤-left-Π ext (B↔⊤ (get a))) ⟩
((A → B) × ∃ λ (f : A → A) → (∀ a → f a ≡ a) × (∀ a → f (f a) ≡ f a)) ↝⟨ (∃-cong λ _ → ∃-cong λ f → ∃-cong λ f≡id →
∀-cong ext λ a →
≡⇒↝ _ (cong₂ _≡_ (trans (f≡id (f a)) (f≡id a)) (f≡id a))) ⟩
((A → B) × ∃ λ (f : A → A) → (∀ a → f a ≡ a) × (∀ a → a ≡ a)) ↝⟨ (∃-cong λ _ →
Σ-assoc F.∘
(∃-cong λ _ →
Σ-cong (Eq.extensionality-isomorphism ext) λ _ → F.id)) ⟩
(A → B) × (∃ λ (f : A → A) → f ≡ id) × (∀ a → a ≡ a) ↝⟨ (∃-cong λ _ → drop-⊤-left-× λ _ →
_⇔_.to contractible⇔↔⊤ $
singleton-contractible _) ⟩□
(A → B) × (∀ a → a ≡ a) □
where
B↔⊤ : B → B ↔ ⊤
B↔⊤ b =
_⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible B-prop b
A→B→A↔A→A : (A → B) → (A → B → A) ↔ (A → A)
A→B→A↔A→A get =
(A → B → A) ↝⟨ ∀-cong ext (λ a → drop-⊤-left-Π ext $ B↔⊤ (get a)) ⟩□
(A → A) □
-- Lens A ⊤ is isomorphic to (a : A) → a ≡ a.
lens-to-⊤↔ : Lens A ⊤ ↔ ((a : A) → a ≡ a)
lens-to-⊤↔ {A = A} =
Lens A ⊤ ↝⟨ lens-to-proposition↔ (mono₁ 0 ⊤-contractible) ⟩
(A → ⊤) × ((a : A) → a ≡ a) ↝⟨ drop-⊤-left-× (λ _ → →-right-zero) ⟩□
((a : A) → a ≡ a) □
-- Lens A ⊥ is isomorphic to ¬ A.
lens-to-⊥↔ : Lens A (⊥ {ℓ = b}) ↔ ¬ A
lens-to-⊥↔ {A = A} =
Lens A ⊥ ↝⟨ lens-to-proposition↔ ⊥-propositional ⟩
(A → ⊥) × ((a : A) → a ≡ a) ↝⟨ →-cong ext F.id (Bij.⊥↔uninhabited ⊥-elim)
×-cong
F.id ⟩
¬ A × ((a : A) → a ≡ a) ↝⟨ drop-⊤-right lemma ⟩□
¬ A □
where
lemma : ¬ A → ((a : A) → a ≡ a) ↔ ⊤
lemma ¬a = record
{ surjection = record
{ logical-equivalence = record
{ to = _
; from = λ _ _ → refl _
}
; right-inverse-of = λ _ → refl _
}
; left-inverse-of = λ eq → ⟨ext⟩ λ a →
⊥-elim (¬a a)
}
-- See also lens-from-⊥≃⊤ and lens-from-⊤≃codomain-contractible below.
------------------------------------------------------------------------
-- Some lens results related to h-levels
-- If the domain of a lens is inhabited and has h-level n,
-- then the codomain also has h-level n.
h-level-respects-lens-from-inhabited :
∀ n → Lens A B → A → H-level n A → H-level n B
h-level-respects-lens-from-inhabited {A = A} {B = B} n l a =
H-level n A ↝⟨ H-level.respects-surjection surj n ⟩□
H-level n B □
where
open Lens l
surj : A ↠ B
surj = record
{ logical-equivalence = record
{ to = get
; from = set a
}
; right-inverse-of = λ b →
get (set a b) ≡⟨ get-set a b ⟩∎
b ∎
}
-- Lenses with contractible domains have contractible codomains.
contractible-to-contractible :
Lens A B → Contractible A → Contractible B
contractible-to-contractible l c =
h-level-respects-lens-from-inhabited _ l (proj₁ c) c
-- If A and B have h-level n given the assumption that A is inhabited,
-- then Lens A B also has h-level n.
lens-preserves-h-level :
∀ n → (A → H-level n A) → (A → H-level n B) →
H-level n (Lens A B)
lens-preserves-h-level n hA hB =
H-level.respects-surjection (_↔_.surjection (inverse Lens-as-Σ)) n $
Σ-closure n (Π-closure ext n λ a →
hB a) λ _ →
Σ-closure n (Π-closure ext n λ a →
Π-closure ext n λ _ →
hA a) λ _ →
×-closure n (Π-closure ext n λ a →
Π-closure ext n λ _ →
+⇒≡ $ mono₁ n (hB a)) $
×-closure n (Π-closure ext n λ a →
+⇒≡ $ mono₁ n (hA a))
(Π-closure ext n λ a →
Π-closure ext n λ _ →
Π-closure ext n λ _ →
+⇒≡ $ mono₁ n (hA a))
-- If A has positive h-level n, then Lens A B also has h-level n.
lens-preserves-h-level-of-domain :
∀ n → H-level (1 + n) A → H-level (1 + n) (Lens A B)
lens-preserves-h-level-of-domain n hA =
[inhabited⇒+]⇒+ n λ l →
lens-preserves-h-level (1 + n) (λ _ → hA) λ a →
h-level-respects-lens-from-inhabited _ l a hA
-- Lens 𝕊¹ ⊤ is not propositional (assuming univalence).
--
-- (The lemma does not actually use the univalence argument, but
-- univalence is used by Circle.¬-type-of-refl-propositional.)
¬-lens-to-⊤-propositional :
Univalence (# 0) →
¬ Is-proposition (Lens 𝕊¹ ⊤)
¬-lens-to-⊤-propositional _ =
Is-proposition (Lens 𝕊¹ ⊤) ↝⟨ H-level.respects-surjection (_↔_.surjection lens-to-⊤↔) 1 ⟩
Is-proposition ((x : 𝕊¹) → x ≡ x) ↝⟨ H-level-cong _ 1 (Π-cong ext (inverse Bij.↑↔) λ _ → Eq.≃-≡ $ Eq.↔⇒≃ Bij.↑↔) ⟩
Is-proposition ((x : ↑ lzero 𝕊¹) → x ≡ x) ↝⟨ proj₂ $ Circle.¬-type-of-refl-propositional ⟩□
⊥ □
------------------------------------------------------------------------
-- Some equality characterisation lemmas
abstract
-- An equality characterisation lemma.
equality-characterisation₁ :
let open Lens in
l₁ ≡ l₂
↔
∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
(∀ a b → subst (λ get → get (set l₂ a b) ≡ b) g
(subst (λ set → get l₁ (set a b) ≡ b) s
(get-set l₁ a b)) ≡
get-set l₂ a b)
×
(∀ a → subst (λ get → set l₂ a (get a) ≡ a) g
(subst (λ set → set a (get l₁ a) ≡ a) s
(set-get l₁ a)) ≡
set-get l₂ a)
×
(∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂)
equality-characterisation₁ {l₁ = l₁} {l₂ = l₂} =
let l₁′ = _↔_.to Lens-as-Σ l₁
l₂′ = _↔_.to Lens-as-Σ l₂
in
l₁ ≡ l₂ ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ (inverse Lens-as-Σ)) ⟩
l₁′ ≡ l₂′ ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ (inverse Σ-assoc)) ⟩
((get l₁ , set l₁) , proj₂ (proj₂ l₁′))
≡
((get l₂ , set l₂) , proj₂ (proj₂ l₂′)) ↝⟨ inverse Bij.Σ-≡,≡↔≡ ⟩
(∃ λ (gs : (get l₁ , set l₁) ≡ (get l₂ , set l₂)) →
subst (λ { (get , set) →
(∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂) })
gs (proj₂ (proj₂ l₁′)) ≡
proj₂ (proj₂ l₂′)) ↝⟨ Σ-cong (inverse ≡×≡↔≡) (λ gs → ≡⇒↝ _ $
cong (λ (gs : (get l₁ , set l₁) ≡ (get l₂ , set l₂)) →
subst (λ { (get , set) →
(∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂) })
gs (proj₂ (proj₂ l₁′))
≡
proj₂ (proj₂ l₂′))
(sym $ _↔_.right-inverse-of ≡×≡↔≡ gs)) ⟩
(∃ λ (gs : get l₁ ≡ get l₂ × set l₁ ≡ set l₂) →
subst (λ { (get , set) →
(∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂) })
(_↔_.to ≡×≡↔≡ gs) (proj₂ (proj₂ l₁′)) ≡
proj₂ (proj₂ l₂′)) ↝⟨ inverse Σ-assoc ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
subst (λ { (get , set) →
(∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂) })
(_↔_.to ≡×≡↔≡ (g , s)) (proj₂ (proj₂ l₁′)) ≡
proj₂ (proj₂ l₂′)) ↝⟨ (∃-cong λ g → ∃-cong λ s → ≡⇒↝ _ $
cong (λ x → x ≡ proj₂ (proj₂ l₂′))
(push-subst-, {y≡z = _↔_.to ≡×≡↔≡ (g , s)} _ _)) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
( subst (λ { (get , set) → ∀ a b → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁)
, subst (λ { (get , set) →
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂) })
(_↔_.to ≡×≡↔≡ (g , s)) (proj₂ (proj₂ (proj₂ l₁′)))
) ≡
proj₂ (proj₂ l₂′)) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → inverse ≡×≡↔≡) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
subst (λ { (get , set) → ∀ a b → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁) ≡
get-set l₂
×
subst (λ { (get , set) →
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂) })
(_↔_.to ≡×≡↔≡ (g , s)) (proj₂ (proj₂ (proj₂ l₁′))) ≡
proj₂ (proj₂ (proj₂ l₂′))) ↝⟨ (∃-cong λ g → ∃-cong λ s → ∃-cong λ _ → ≡⇒↝ _ $
cong (λ x → x ≡ proj₂ (proj₂ (proj₂ l₂′)))
(push-subst-, {y≡z = _↔_.to ≡×≡↔≡ (g , s)} _ _)) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
subst (λ { (get , set) → ∀ a b → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁) ≡
get-set l₂
×
( subst (λ { (get , set) → ∀ a → set a (get a) ≡ a })
(_↔_.to ≡×≡↔≡ (g , s)) (set-get l₁)
, subst (λ { (get , set) →
∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂ })
(_↔_.to ≡×≡↔≡ (g , s)) (set-set l₁)
) ≡
proj₂ (proj₂ (proj₂ l₂′))) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → inverse ≡×≡↔≡) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
subst (λ { (get , set) → ∀ a b → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁) ≡
get-set l₂
×
subst (λ { (get , set) → ∀ a → set a (get a) ≡ a })
(_↔_.to ≡×≡↔≡ (g , s)) (set-get l₁) ≡
set-get l₂
×
subst (λ { (get , set) →
∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂ })
(_↔_.to ≡×≡↔≡ (g , s)) (set-set l₁) ≡
set-set l₂) ↝⟨ (∃-cong λ g → ∃-cong λ s →
lemma₁ (λ { (get , set) a → ∀ b → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s))
×-cong
lemma₁ (λ { (get , set) a → set a (get a) ≡ a })
(_↔_.to ≡×≡↔≡ (g , s))
×-cong
lemma₁ (λ { (get , set) a → ∀ b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂ })
(_↔_.to ≡×≡↔≡ (g , s))) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
(∀ a → subst (λ { (get , set) → ∀ b → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁ a) ≡
get-set l₂ a)
×
(∀ a → subst (λ { (get , set) → set a (get a) ≡ a })
(_↔_.to ≡×≡↔≡ (g , s)) (set-get l₁ a) ≡
set-get l₂ a)
×
(∀ a → subst (λ { (get , set) →
∀ b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂ })
(_↔_.to ≡×≡↔≡ (g , s)) (set-set l₁ a) ≡
set-set l₂ a)) ↝⟨ (∃-cong λ g → ∃-cong λ s →
(∀-cong ext λ a →
lemma₁ (λ { (get , set) b → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s)))
×-cong
F.id
×-cong
(∀-cong ext λ a →
lemma₁ (λ { (get , set) b₁ → ∀ b₂ → set (set a b₁) b₂ ≡ set a b₂ })
(_↔_.to ≡×≡↔≡ (g , s)))) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
(∀ a b → subst (λ { (get , set) → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁ a b) ≡
get-set l₂ a b)
×
(∀ a → subst (λ { (get , set) → set a (get a) ≡ a })
(_↔_.to ≡×≡↔≡ (g , s)) (set-get l₁ a) ≡
set-get l₂ a)
×
(∀ a b₁ → subst (λ { (get , set) →
∀ b₂ → set (set a b₁) b₂ ≡ set a b₂ })
(_↔_.to ≡×≡↔≡ (g , s)) (set-set l₁ a b₁) ≡
set-set l₂ a b₁)) ↝⟨ (∃-cong λ g → ∃-cong λ s → ∃-cong λ _ → ∃-cong λ _ →
∀-cong ext λ a → ∀-cong ext λ b₁ →
lemma₁ (λ { (get , set) b₂ → set (set a b₁) b₂ ≡ set a b₂ })
(_↔_.to ≡×≡↔≡ (g , s))) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
(∀ a b → subst (λ { (get , set) → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁ a b) ≡
get-set l₂ a b)
×
(∀ a → subst (λ { (get , set) → set a (get a) ≡ a })
(_↔_.to ≡×≡↔≡ (g , s)) (set-get l₁ a) ≡
set-get l₂ a)
×
(∀ a b₁ b₂ → subst (λ { (get , set) →
set (set a b₁) b₂ ≡ set a b₂ })
(_↔_.to ≡×≡↔≡ (g , s)) (set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂)) ↝⟨ (∃-cong λ g → ∃-cong λ s →
(∀-cong ext λ a → ∀-cong ext λ b →
lemma₂ (λ { (get , set) → get (set a b) ≡ b }) g s)
×-cong
(∀-cong ext λ a →
lemma₂ (λ { (get , set) → set a (get a) ≡ a }) g s)
×-cong
(∀-cong ext λ a → ∀-cong ext λ b₁ → ∀-cong ext λ b₂ →
lemma₂ (λ { (get , set) → set (set a b₁) b₂ ≡ set a b₂ }) g s)) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
(∀ a b → subst (λ get → get (set l₂ a b) ≡ b) g
(subst (λ set → get l₁ (set a b) ≡ b) s
(get-set l₁ a b)) ≡
get-set l₂ a b)
×
(∀ a → subst (λ get → set l₂ a (get a) ≡ a) g
(subst (λ set → set a (get l₁ a) ≡ a) s
(set-get l₁ a)) ≡
set-get l₂ a)
×
(∀ a b₁ b₂ →
subst (λ get → set l₂ (set l₂ a b₁) b₂ ≡ set l₂ a b₂) g
(subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂)) ≡
set-set l₂ a b₁ b₂)) ↝⟨ (∃-cong λ g → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ →
∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ →
≡⇒↝ _ $ cong (λ x → x ≡ _) $ subst-const g) ⟩□
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
(∀ a b → subst (λ get → get (set l₂ a b) ≡ b) g
(subst (λ set → get l₁ (set a b) ≡ b) s
(get-set l₁ a b)) ≡
get-set l₂ a b)
×
(∀ a → subst (λ get → set l₂ a (get a) ≡ a) g
(subst (λ set → set a (get l₁ a) ≡ a) s
(set-get l₁ a)) ≡
set-get l₂ a)
×
(∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂)) □
where
open Lens
abstract
lemma₁ :
∀ (C : A → B → Type c) (eq : u ≡ v) {f g} →
(subst (λ x → ∀ y → C x y) eq f ≡ g)
↔
(∀ y → subst (λ x → C x y) eq (f y) ≡ g y)
lemma₁ C eq {f} {g} =
subst (λ x → ∀ y → C x y) eq f ≡ g ↔⟨ inverse $ Eq.extensionality-isomorphism ext ⟩
(∀ y → subst (λ x → ∀ y → C x y) eq f y ≡ g y) ↝⟨ (∀-cong ext λ y → ≡⇒↝ _ $
cong (λ x → x ≡ _) (sym $ push-subst-application eq _)) ⟩□
(∀ y → subst (λ x → C x y) eq (f y) ≡ g y) □
lemma₂ :
(P : A × B → Type p) (x₁≡x₂ : x₁ ≡ x₂) (y₁≡y₂ : y₁ ≡ y₂) →
∀ {p p′} →
(subst P (_↔_.to ≡×≡↔≡ (x₁≡x₂ , y₁≡y₂)) p ≡ p′)
↔
(subst (λ x → P (x , y₂)) x₁≡x₂ (subst (λ y → P (x₁ , y)) y₁≡y₂ p)
≡
p′)
lemma₂ P x₁≡x₂ y₁≡y₂ {p = p} = ≡⇒↝ _ $ cong (_≡ _) $ elim¹
(λ y₁≡y₂ →
subst P (_↔_.to ≡×≡↔≡ (x₁≡x₂ , y₁≡y₂)) p ≡
subst (λ x → P (x , _)) x₁≡x₂
(subst (λ y → P (_ , y)) y₁≡y₂ p))
(subst P (_↔_.to ≡×≡↔≡ (x₁≡x₂ , refl _)) p ≡⟨⟩
subst P (cong₂ _,_ x₁≡x₂ (refl _)) p ≡⟨⟩
subst P (trans (cong (_, _) x₁≡x₂) (cong (_ ,_) (refl _))) p ≡⟨ cong (λ eq → subst P (trans (cong (_, _) x₁≡x₂) eq) p) $ cong-refl _ ⟩
subst P (trans (cong (_, _) x₁≡x₂) (refl _)) p ≡⟨ cong (λ eq → subst P eq p) $ trans-reflʳ _ ⟩
subst P (cong (_, _) x₁≡x₂) p ≡⟨ sym $ subst-∘ _ _ _ ⟩
subst (λ x → P (x , _)) x₁≡x₂ p ≡⟨ cong (subst (λ x → P (x , _)) x₁≡x₂) $ sym $ subst-refl _ _ ⟩∎
subst (λ x → P (x , _)) x₁≡x₂
(subst (λ y → P (_ , y)) (refl _) p) ∎)
_
-- Another equality characterisation lemma.
equality-characterisation₂ :
let open Lens in
l₁ ≡ l₂
↔
∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
(∀ a b →
trans (sym (cong₂ (λ set get → get (set a b)) s g))
(get-set l₁ a b) ≡
get-set l₂ a b) ×
(∀ a →
trans (sym (cong₂ (λ set get → set a (get a)) s g))
(set-get l₁ a) ≡
set-get l₂ a) ×
(∀ a b₁ b₂ →
subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂)
equality-characterisation₂ {l₁ = l₁} {l₂ = l₂} =
l₁ ≡ l₂ ↝⟨ equality-characterisation₁ ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
(∀ a b → subst (λ get → get (set l₂ a b) ≡ b) g
(subst (λ set → get l₁ (set a b) ≡ b) s
(get-set l₁ a b)) ≡
get-set l₂ a b)
×
(∀ a → subst (λ get → set l₂ a (get a) ≡ a) g
(subst (λ set → set a (get l₁ a) ≡ a) s
(set-get l₁ a)) ≡
set-get l₂ a)
×
(∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂)) ↝⟨ (∃-cong λ g → ∃-cong λ s →
(∀-cong ext λ a → ∀-cong ext λ b → ≡⇒↝ _ $ cong (_≡ _) $
lemma₁ g s a b)
×-cong
(∀-cong ext λ a → ≡⇒↝ _ $ cong (_≡ _) $
lemma₂ g s a)
×-cong
F.id) ⟩□
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
(∀ a b → trans (sym (cong₂ (λ set get → get (set a b)) s g))
(get-set l₁ a b) ≡
get-set l₂ a b) ×
(∀ a → trans (sym (cong₂ (λ set get → set a (get a)) s g))
(set-get l₁ a) ≡
set-get l₂ a) ×
(∀ a b₁ b₂ →
subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂)) □
where
open Lens
lemma₁ :
(g : get l₁ ≡ get l₂) (s : set l₁ ≡ set l₂) →
∀ a b →
subst (λ get → get (set l₂ a b) ≡ b) g
(subst (λ set → get l₁ (set a b) ≡ b) s
(get-set l₁ a b)) ≡
trans (sym (cong₂ (λ set get → get (set a b)) s g))
(get-set l₁ a b)
lemma₁ g s a b =
subst (λ get → get (set l₂ a b) ≡ b) g
(subst (λ set → get l₁ (set a b) ≡ b) s
(get-set l₁ a b)) ≡⟨ cong (λ eq → subst (λ get → get (set l₂ a b) ≡ b) g eq) $
subst-in-terms-of-trans-and-cong {x≡y = s} {fx≡gx = (get-set l₁ a b)} ⟩
subst (λ get → get (set l₂ a b) ≡ b) g
(trans (sym (cong (λ set → get l₁ (set a b)) s))
(trans (get-set l₁ a b) (cong (const b) s))) ≡⟨ cong (λ eq → subst (λ get → get (set l₂ a b) ≡ b) g
(trans (sym (cong (λ set → get l₁ (set a b)) s))
(trans _ eq))) $
cong-const s ⟩
subst (λ get → get (set l₂ a b) ≡ b) g
(trans (sym (cong (λ set → get l₁ (set a b)) s))
(trans (get-set l₁ a b) (refl _))) ≡⟨ cong (λ eq → subst (λ get → get (set l₂ a b) ≡ b) g (trans _ eq)) $
trans-reflʳ _ ⟩
subst (λ get → get (set l₂ a b) ≡ b) g
(trans (sym (cong (λ set → get l₁ (set a b)) s))
(get-set l₁ a b)) ≡⟨ subst-in-terms-of-trans-and-cong {x≡y = g}
{fx≡gx = trans _ (get-set l₁ a b)} ⟩
trans (sym (cong (λ get → get (set l₂ a b)) g))
(trans (trans (sym (cong (λ set → get l₁ (set a b)) s))
(get-set l₁ a b))
(cong (const b) g)) ≡⟨ cong (λ eq → trans (sym (cong (λ get → get (set l₂ a b)) g))
(trans (trans (sym (cong (λ set → get l₁ (set a b)) s))
(get-set l₁ a b))
eq)) $
cong-const g ⟩
trans (sym (cong (λ get → get (set l₂ a b)) g))
(trans (trans (sym (cong (λ set → get l₁ (set a b)) s))
(get-set l₁ a b))
(refl _)) ≡⟨ cong (trans _) $
trans-reflʳ _ ⟩
trans (sym (cong (λ get → get (set l₂ a b)) g))
(trans (sym (cong (λ set → get l₁ (set a b)) s))
(get-set l₁ a b)) ≡⟨ sym $ trans-assoc _ _ (get-set l₁ a b) ⟩
trans (trans (sym (cong (λ get → get (set l₂ a b)) g))
(sym (cong (λ set → get l₁ (set a b)) s)))
(get-set l₁ a b) ≡⟨ cong (λ eq → trans eq (get-set l₁ a b)) $ sym $
sym-trans _ (cong (λ get → get (set l₂ a b)) g) ⟩
trans (sym (trans (cong (λ set → get l₁ (set a b)) s)
(cong (λ get → get (set l₂ a b)) g)))
(get-set l₁ a b) ≡⟨⟩
trans (sym (cong₂ (λ set get → get (set a b)) s g))
(get-set l₁ a b) ∎
lemma₂ :
(g : get l₁ ≡ get l₂) (s : set l₁ ≡ set l₂) →
∀ a →
subst (λ get → set l₂ a (get a) ≡ a) g
(subst (λ set → set a (get l₁ a) ≡ a) s
(set-get l₁ a)) ≡
trans (sym (cong₂ (λ set get → set a (get a)) s g))
(set-get l₁ a)
lemma₂ g s a =
subst (λ get → set l₂ a (get a) ≡ a) g
(subst (λ set → set a (get l₁ a) ≡ a) s
(set-get l₁ a)) ≡⟨⟩
subst (λ get → set l₂ a (get a) ≡ a) g
(subst (λ set → set a (get l₁ a) ≡ a) s
(set-get l₁ a)) ≡⟨ cong (subst (λ get → set l₂ a (get a) ≡ a) g) $
subst-in-terms-of-trans-and-cong {x≡y = s} {fx≡gx = set-get l₁ a} ⟩
subst (λ get → set l₂ a (get a) ≡ a) g
(trans (sym (cong (λ set → set a (get l₁ a)) s))
(trans (set-get l₁ a) (cong (const a) s))) ≡⟨ cong (λ eq → subst (λ get → set l₂ a (get a) ≡ a) g
(trans (sym (cong (λ set → set a (get l₁ a)) s))
(trans _ eq))) $
cong-const s ⟩
subst (λ get → set l₂ a (get a) ≡ a) g
(trans (sym (cong (λ set → set a (get l₁ a)) s))
(trans (set-get l₁ a) (refl _))) ≡⟨ cong (λ eq → subst (λ get → set l₂ a (get a) ≡ a) g (trans _ eq)) $
trans-reflʳ _ ⟩
subst (λ get → set l₂ a (get a) ≡ a) g
(trans (sym (cong (λ set → set a (get l₁ a)) s))
(set-get l₁ a)) ≡⟨ subst-in-terms-of-trans-and-cong {x≡y = g}
{fx≡gx = trans (sym (cong (λ set → set a (get l₁ a)) s)) (set-get l₁ a)} ⟩
trans (sym (cong (λ get → set l₂ a (get a)) g))
(trans (trans (sym (cong (λ set → set a (get l₁ a)) s))
(set-get l₁ a))
(cong (const a) g)) ≡⟨ cong (λ eq → trans (sym (cong (λ get → set l₂ a (get a)) g))
(trans (trans (sym (cong (λ set → set a (get l₁ a)) s))
(set-get l₁ a))
eq)) $
cong-const g ⟩
trans (sym (cong (λ get → set l₂ a (get a)) g))
(trans (trans (sym (cong (λ set → set a (get l₁ a)) s))
(set-get l₁ a))
(refl _)) ≡⟨ cong (trans _) $
trans-reflʳ _ ⟩
trans (sym (cong (λ get → set l₂ a (get a)) g))
(trans (sym (cong (λ set → set a (get l₁ a)) s))
(set-get l₁ a)) ≡⟨ sym $ trans-assoc _ _ (set-get l₁ a) ⟩
trans (trans (sym (cong (λ get → set l₂ a (get a)) g))
(sym (cong (λ set → set a (get l₁ a)) s)))
(set-get l₁ a) ≡⟨ cong (λ eq → trans eq (set-get l₁ a)) $ sym $
sym-trans _ (cong (λ get → set l₂ a (get a)) g) ⟩
trans (sym (trans (cong (λ set → set a (get l₁ a)) s)
(cong (λ get → set l₂ a (get a)) g)))
(set-get l₁ a) ≡⟨⟩
trans (sym (cong₂ (λ set get → set a (get a)) s g))
(set-get l₁ a) ∎
-- And another one.
equality-characterisation₃ :
let open Lens in
l₁ ≡ l₂
↔
∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
(∀ a b →
trans (sym (cong₂ (λ set get → get (set a b)) s g))
(get-set l₁ a b) ≡
get-set l₂ a b) ×
(∀ a →
trans (sym (cong₂ (λ set get → set a (get a)) s g))
(set-get l₁ a) ≡
set-get l₂ a) ×
(∀ a b₁ b₂ →
trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡
trans (cong (λ set → set (set a b₁) b₂) s)
(set-set l₂ a b₁ b₂))
equality-characterisation₃ {l₁ = l₁} {l₂ = l₂} =
l₁ ≡ l₂ ↝⟨ equality-characterisation₂ ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
(∀ a b → trans (sym (cong₂ (λ set get → get (set a b)) s g))
(get-set l₁ a b) ≡
get-set l₂ a b) ×
(∀ a → trans (sym (cong₂ (λ set get → set a (get a)) s g))
(set-get l₁ a) ≡
set-get l₂ a) ×
(∀ a b₁ b₂ →
subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂)) ↝⟨ (∃-cong λ g → ∃-cong λ s → ∃-cong λ _ → ∃-cong λ _ →
∀-cong ext λ a → ∀-cong ext λ b₁ → ∀-cong ext λ b₂ → ≡⇒↝ _ $
lemma g s a b₁ b₂) ⟩□
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
(∀ a b → trans (sym (cong₂ (λ set get → get (set a b)) s g))
(get-set l₁ a b) ≡
get-set l₂ a b) ×
(∀ a → trans (sym (cong₂ (λ set get → set a (get a)) s g))
(set-get l₁ a) ≡
set-get l₂ a) ×
(∀ a b₁ b₂ →
trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡
trans (cong (λ set → set (set a b₁) b₂) s)
(set-set l₂ a b₁ b₂))) □
where
open Lens
lemma :
(g : get l₁ ≡ get l₂) (s : set l₁ ≡ set l₂) →
∀ a b₁ b₂ →
(subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂) ≡
(trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡
trans (cong (λ set → set (set a b₁) b₂) s)
(set-set l₂ a b₁ b₂))
lemma g s a b₁ b₂ =
subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂ ≡⟨ cong (_≡ _) $
subst-in-terms-of-trans-and-cong {x≡y = s} {fx≡gx = set-set l₁ a b₁ b₂} ⟩
trans (sym (cong (λ set → set (set a b₁) b₂) s))
(trans (set-set l₁ a b₁ b₂)
(cong (λ set → set a b₂) s)) ≡
set-set l₂ a b₁ b₂ ≡⟨ [trans≡]≡[≡trans-symˡ] _ _ _ ⟩
trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡
trans (sym (sym (cong (λ set → set (set a b₁) b₂) s)))
(set-set l₂ a b₁ b₂) ≡⟨ cong (λ eq → trans _ (cong (λ set → set a b₂) s) ≡
trans eq (set-set l₂ a b₁ b₂)) $
sym-sym (cong (λ set → set (set a b₁) b₂) s) ⟩
trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡
trans (cong (λ set → set (set a b₁) b₂) s)
(set-set l₂ a b₁ b₂) ∎
-- And yet another one.
equality-characterisation₄ :
let open Lens in
l₁ ≡ l₂
↔
∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∃ λ (s : ∀ a b → set l₁ a b ≡ set l₂ a b) →
(∀ a b →
trans (sym (trans (cong (get l₁) (s a b))
(g (set l₂ a b))))
(get-set l₁ a b) ≡
get-set l₂ a b) ×
(∀ a →
trans (sym (trans (s a (get l₁ a))
(cong (set l₂ a) (g a))))
(set-get l₁ a) ≡
set-get l₂ a) ×
(∀ a b₁ b₂ →
trans (set-set l₁ a b₁ b₂) (s a b₂) ≡
trans (cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ∘ s)))
(set-set l₂ a b₁ b₂))
equality-characterisation₄ {l₁ = l₁} {l₂ = l₂} =
l₁ ≡ l₂ ↝⟨ equality-characterisation₃ ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
(∀ a b → trans (sym (cong₂ (λ set get → get (set a b)) s g))
(get-set l₁ a b) ≡
get-set l₂ a b) ×
(∀ a → trans (sym (cong₂ (λ set get → set a (get a)) s g))
(set-get l₁ a) ≡
set-get l₂ a) ×
(∀ a b₁ b₂ →
trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡
trans (cong (λ set → set (set a b₁) b₂) s)
(set-set l₂ a b₁ b₂))) ↝⟨ (Σ-cong (inverse $ Eq.extensionality-isomorphism ext) λ g →
Σ-cong (inverse $
Eq.extensionality-isomorphism ext F.∘
∀-cong ext λ _ → Eq.extensionality-isomorphism ext) λ s →
(∀-cong ext λ a → ∀-cong ext λ b →
≡⇒↝ _ $ cong (λ eq → trans (sym eq) (get-set l₁ a b) ≡ _) (
cong₂ (λ set get → get (set a b)) s g ≡⟨⟩
trans (cong (λ set → get l₁ (set a b)) s)
(cong (λ get → get (set l₂ a b)) g) ≡⟨ cong (λ eq → trans eq (ext⁻¹ g (set l₂ a b))) $ sym $
cong-∘ _ _ s ⟩
trans (cong (get l₁ ∘ (_$ b)) (ext⁻¹ s a))
(ext⁻¹ g (set l₂ a b)) ≡⟨ cong (λ eq → trans eq (ext⁻¹ g (set l₂ a b))) $ sym $
cong-∘ _ _ (ext⁻¹ s a) ⟩∎
trans (cong (get l₁) (ext⁻¹ (ext⁻¹ s a) b))
(ext⁻¹ g (set l₂ a b)) ∎))
×-cong
(∀-cong ext λ a →
≡⇒↝ _ $ cong (λ eq → trans (sym eq) (set-get l₁ a) ≡ _) (
cong₂ (λ set get → set a (get a)) s g ≡⟨⟩
trans (cong (λ set → set a (get l₁ a)) s)
(cong (λ get → set l₂ a (get a)) g) ≡⟨ sym $ cong₂ trans (cong-∘ _ _ s) (cong-∘ _ _ g) ⟩
trans (ext⁻¹ (ext⁻¹ s a) (get l₁ a))
(cong (set l₂ a) (ext⁻¹ g a)) ∎))
×-cong
∀-cong ext λ a → ∀-cong ext λ b₁ → ∀-cong ext λ b₂ →
≡⇒↝ _ $
cong₂ (λ p q → trans _ p ≡
trans (cong (λ set → set (set a b₁) b₂) q)
(set-set l₂ a b₁ b₂)) (
cong (λ set → set a b₂) s ≡⟨ sym $ cong-∘ _ _ s ⟩∎
ext⁻¹ (ext⁻¹ s a) b₂ ∎)
(
s ≡⟨ sym $ _≃_.right-inverse-of
(Eq.extensionality-isomorphism bad-ext) _ ⟩
⟨ext⟩ (ext⁻¹ s) ≡⟨ (cong ⟨ext⟩ $ ⟨ext⟩ λ _ → sym $
_≃_.right-inverse-of
(Eq.extensionality-isomorphism bad-ext) _) ⟩∎
⟨ext⟩ (⟨ext⟩ ∘ ext⁻¹ ∘ ext⁻¹ s) ∎)) ⟩□
(∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∃ λ (s : ∀ a b → set l₁ a b ≡ set l₂ a b) →
(∀ a b →
trans (sym (trans (cong (get l₁) (s a b))
(g (set l₂ a b))))
(get-set l₁ a b) ≡
get-set l₂ a b) ×
(∀ a →
trans (sym (trans (s a (get l₁ a))
(cong (set l₂ a) (g a))))
(set-get l₁ a) ≡
set-get l₂ a) ×
(∀ a b₁ b₂ →
trans (set-set l₁ a b₁ b₂) (s a b₂) ≡
trans (cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ∘ s)))
(set-set l₂ a b₁ b₂))) □
where
open Lens
-- A lemma that can be used to prove that two lenses with
-- definitionally equal getters and setters are equal.
equal-laws→≡ :
{get : A → B} {set : A → B → A}
{l₁′ l₂′ : (∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)} →
let l₁ = _↔_.from Lens-as-Σ (get , set , l₁′)
l₂ = _↔_.from Lens-as-Σ (get , set , l₂′)
open Lens
in
(∀ a b → get-set l₁ a b ≡ get-set l₂ a b) →
(∀ a → set-get l₁ a ≡ set-get l₂ a) →
(∀ a b₁ b₂ → set-set l₁ a b₁ b₂ ≡ set-set l₂ a b₁ b₂) →
l₁ ≡ l₂
equal-laws→≡ {l₁′ = l₁′} {l₂′ = l₂′} hyp₁ hyp₂ hyp₃ =
let l₁″ = _↔_.from Lens-as-Σ (_ , _ , l₁′)
l₂″ = _↔_.from Lens-as-Σ (_ , _ , l₂′)
in
_↔_.from equality-characterisation₂
( refl _
, refl _
, (λ a b →
trans (sym (cong₂ (λ set get → get (set a b))
(refl _) (refl _)))
(get-set l₁″ a b) ≡⟨ cong (λ eq → trans (sym eq) _) $ cong₂-refl _ ⟩
trans (sym (refl _)) (get-set l₁″ a b) ≡⟨ cong (flip trans _) sym-refl ⟩
trans (refl _) (get-set l₁″ a b) ≡⟨ trans-reflˡ _ ⟩
get-set l₁″ a b ≡⟨ hyp₁ _ _ ⟩∎
get-set l₂″ a b ∎)
, (λ a →
trans (sym (cong₂ (λ set get → set a (get a))
(refl _) (refl _)))
(set-get l₁″ a) ≡⟨ cong (λ eq → trans (sym eq) _) $ cong₂-refl _ ⟩
trans (sym (refl _)) (set-get l₁″ a) ≡⟨ cong (flip trans _) sym-refl ⟩
trans (refl _) (set-get l₁″ a) ≡⟨ trans-reflˡ _ ⟩
set-get l₁″ a ≡⟨ hyp₂ _ ⟩∎
set-get l₂″ a ∎)
, (λ a b₁ b₂ →
subst (λ set → set (set a b₁) b₂ ≡ set a b₂) (refl _)
(set-set l₁″ a b₁ b₂) ≡⟨ subst-refl _ _ ⟩
set-set l₁″ a b₁ b₂ ≡⟨ hyp₃ _ _ _ ⟩∎
set-set l₂″ a b₁ b₂ ∎)
)
where
open Lens
-- An equality characterisation lemma for lenses from sets.
equality-characterisation-for-sets :
let open Lens in
{l₁ l₂ : Lens A B} →
Is-set A →
l₁ ≡ l₂
↔
set l₁ ≡ set l₂
equality-characterisation-for-sets
{A = A} {B = B} {l₁ = l₁} {l₂ = l₂} A-set =
l₁ ≡ l₂ ↝⟨ equality-characterisation₁ ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
(∀ a b → subst (λ get → get (set l₂ a b) ≡ b) g
(subst (λ set → get l₁ (set a b) ≡ b) s
(get-set l₁ a b))
≡
get-set l₂ a b)
×
(∀ a → subst (λ get → set l₂ a (get a) ≡ a) g
(subst (λ set → set a (get l₁ a) ≡ a) s
(set-get l₁ a))
≡
set-get l₂ a)
×
(∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂)
≡
set-set l₂ a b₁ b₂)) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → drop-⊤-left-Σ $ _⇔_.to contractible⇔↔⊤ $
Π-closure ext 0 λ a →
Π-closure ext 0 λ _ →
+⇒≡ (B-set a)) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
(∀ a → subst (λ get → set l₂ a (get a) ≡ a) g
(subst (λ set → set a (get l₁ a) ≡ a) s
(set-get l₁ a))
≡
set-get l₂ a)
×
(∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂)
≡
set-set l₂ a b₁ b₂)) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → drop-⊤-left-Σ $ _⇔_.to contractible⇔↔⊤ $
Π-closure ext 0 λ _ →
+⇒≡ A-set) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
(∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂)
≡
set-set l₂ a b₁ b₂)) ↝⟨ (∃-cong λ _ → drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $
Π-closure ext 0 λ _ →
Π-closure ext 0 λ _ →
Π-closure ext 0 λ _ →
+⇒≡ A-set) ⟩
get l₁ ≡ get l₂ × set l₁ ≡ set l₂ ↝⟨ (drop-⊤-left-× λ setters-equal → _⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible
(Π-closure ext 2 λ a →
B-set a)
(getters-equal-if-setters-equal l₁ l₂ setters-equal)) ⟩□
set l₁ ≡ set l₂ □
where
open Lens
B-set : A → Is-set B
B-set a = h-level-respects-lens-from-inhabited 2 l₁ a A-set
------------------------------------------------------------------------
-- More isomorphisms/equivalences related to lenses
-- Lens ⊤ B is equivalent to Contractible B.
lens-from-⊤≃codomain-contractible :
Lens ⊤ B ≃ Contractible B
lens-from-⊤≃codomain-contractible = Eq.⇔→≃
(lens-preserves-h-level-of-domain 0 (mono₁ 0 ⊤-contractible))
(H-level-propositional ext 0)
(λ l → contractible-to-contractible l ⊤-contractible)
(λ (b , irrB) → record
{ get = λ _ → b
; get-set = λ _ → irrB
; set-get = refl
; set-set = λ _ _ _ → refl _
})
-- Lens ⊥ B is equivalent to the unit type.
lens-from-⊥≃⊤ : Lens (⊥ {ℓ = a}) B ≃ ⊤
lens-from-⊥≃⊤ = Eq.⇔→≃
(lens-preserves-h-level-of-domain 0 ⊥-propositional)
(mono₁ 0 ⊤-contractible)
_
(λ _ → record
{ get = ⊥-elim
; set = ⊥-elim
; get-set = λ a → ⊥-elim a
; set-get = λ a → ⊥-elim a
; set-set = λ a → ⊥-elim a
})
-- If A is a set and there is a lens from A to B, then A is equivalent
-- to the cartesian product of some type (that can be expressed using
-- the setter of l) and B.
--
-- This result is based on Theorem 2.3.9 from "Lenses and View Update
-- Translation" by Pierce and Schmitt.
--
-- See also Lens.Non-dependent.Traditional.Combinators.≄Σ∥set⁻¹∥×.
≃Σ∥set⁻¹∥× :
Is-set A →
(l : Lens A B) →
A ≃ ((∃ λ (f : B → A) → ∥ Lens.set l ⁻¹ f ∥) × B)
≃Σ∥set⁻¹∥× {A = A} {B = B} A-set l = Eq.↔→≃
(λ a → (set a , ∣ a , refl _ ∣) , get a)
(λ ((f , _) , b) → f b)
(λ ((f , p) , b) →
flip (Trunc.rec (×-closure 2
(Σ-closure 2
(Π-closure ext 2 λ _ → A-set) λ _ →
mono₁ 1 Trunc.truncation-is-proposition)
(B-set (f b))))
p λ (a , q) →
let
lemma₁ =
set (f b) ≡⟨ cong (λ f → set (f b)) $ sym q ⟩
set (set a b) ≡⟨ ⟨ext⟩ $ set-set a b ⟩
set a ≡⟨ q ⟩∎
f ∎
lemma₂ =
get (f b) ≡⟨ cong (λ f → get (f b)) $ sym q ⟩
get (set a b) ≡⟨ get-set _ _ ⟩∎
b ∎
in
(set (f b) , ∣ f b , refl _ ∣) , get (f b) ≡⟨ cong₂ _,_ (Σ-≡,≡→≡ lemma₁ (Trunc.truncation-is-proposition _ _)) lemma₂ ⟩∎
(f , p ) , b ∎)
(λ a →
set a (get a) ≡⟨ set-get a ⟩∎
a ∎)
where
open Lens l
B-set : A → Is-set B
B-set a =
h-level-respects-lens-from-inhabited 2 l a A-set
-- If B is an inhabited set and there is a lens from A to B, then A is
-- equivalent to the cartesian product of some type (that can be
-- expressed using the getter of l) and B.
--
-- This result is based on Corollary 13 from "Algebras and Update
-- Strategies" by Johnson, Rosebrugh and Wood.
≃get⁻¹× :
Is-set B →
(b : B)
(l : Lens A B) →
A ≃ (Lens.get l ⁻¹ b × B)
≃get⁻¹× {B = B} {A = A} B-set b₀ l = Eq.↔→≃
(λ a → (set a b₀ , get-set a b₀) , get a)
(λ ((a , _) , b) → set a b)
(λ ((a , h) , b) →
let
lemma =
set (set a b) b₀ ≡⟨ set-set a b b₀ ⟩
set a b₀ ≡⟨ cong (set a) (sym h) ⟩
set a (get a) ≡⟨ set-get a ⟩∎
a ∎
in
(set (set a b) b₀ , get-set (set a b) b₀) , get (set a b) ≡⟨ cong₂ _,_ (Σ-≡,≡→≡ lemma (B-set _ _)) (get-set a b) ⟩∎
(a , h ) , b ∎)
(λ a →
set (set a b₀) (get a) ≡⟨ set-set a b₀ (get a) ⟩
set a (get a) ≡⟨ set-get a ⟩∎
a ∎)
where
open Lens l
-- For somewhat coherent lenses the previous result can be proved
-- without the assumption that the codomain is a set.
≃get⁻¹×-coherent :
(b : B)
(l : Coherent-lens A B) →
A ≃ (Coherent-lens.get l ⁻¹ b × B)
≃get⁻¹×-coherent {B = B} {A = A} b₀ l = Eq.↔→≃
(λ a → (set a b₀ , get-set a b₀) , get a)
(λ ((a , _) , b) → set a b)
(λ ((a , h) , b) →
let
lemma₁ =
set (set a b) b₀ ≡⟨ set-set a b b₀ ⟩
set a b₀ ≡⟨ cong (set a) (sym h) ⟩
set a (get a) ≡⟨ set-get a ⟩∎
a ∎
lemma₂₁ =
cong get (trans (set-set a b b₀)
(trans (cong (set a) (sym h))
(set-get a))) ≡⟨ trans (cong-trans _ _ _) $
cong (trans _) $
trans (cong-trans _ _ _) $
cong (flip trans _) $
cong-∘ _ _ _ ⟩
trans (cong get (set-set a b b₀))
(trans (cong (get ∘ set a) (sym h))
(cong get (set-get a))) ≡⟨ cong₂ (λ p q → trans p (trans (cong (get ∘ set a) (sym h)) q))
(get-set-set _ _ _)
(get-set-get _) ⟩∎
trans (trans (get-set (set a b) b₀)
(sym (get-set a b₀)))
(trans (cong (get ∘ set a) (sym h))
(get-set a (get a))) ∎
lemma₂₂ =
sym (trans (trans (get-set (set a b) b₀)
(sym (get-set a b₀)))
(trans (cong (get ∘ set a) (sym h))
(get-set a (get a)))) ≡⟨ trans (sym-trans _ _) $
cong₂ trans
(sym-trans _ _)
(sym-trans _ _) ⟩
trans (trans (sym (get-set a (get a)))
(sym (cong (get ∘ set a) (sym h))))
(trans (sym (sym (get-set a b₀)))
(sym (get-set (set a b) b₀))) ≡⟨ cong₂ (λ p q → trans (trans (sym (get-set a (get a))) p)
(trans q (sym (get-set (set a b) b₀))))
(trans (cong sym $ cong-sym _ _) $
sym-sym _)
(sym-sym _) ⟩
trans (trans (sym (get-set a (get a)))
(cong (get ∘ set a) h))
(trans (get-set a b₀)
(sym (get-set (set a b) b₀))) ≡⟨ trans (sym $ trans-assoc _ _ _) $
cong (flip trans _) $ trans-assoc _ _ _ ⟩∎
trans (trans (sym (get-set a (get a)))
(trans (cong (get ∘ set a) h)
(get-set a b₀)))
(sym (get-set (set a b) b₀)) ∎
lemma₂ =
subst (λ a → get a ≡ b₀)
(trans (set-set a b b₀)
(trans (cong (set a) (sym h)) (set-get a)))
(get-set (set a b) b₀) ≡⟨ subst-∘ _ _ _ ⟩
subst (_≡ b₀)
(cong get (trans (set-set a b b₀)
(trans (cong (set a) (sym h))
(set-get a))))
(get-set (set a b) b₀) ≡⟨ subst-trans-sym ⟩
trans
(sym (cong get (trans (set-set a b b₀)
(trans (cong (set a) (sym h))
(set-get a)))))
(get-set (set a b) b₀) ≡⟨ cong (flip (trans ∘ sym) _) lemma₂₁ ⟩
trans
(sym (trans (trans (get-set (set a b) b₀)
(sym (get-set a b₀)))
(trans (cong (get ∘ set a) (sym h))
(get-set a (get a)))))
(get-set (set a b) b₀) ≡⟨ cong (flip trans _) lemma₂₂ ⟩
trans
(trans (trans (sym (get-set a (get a)))
(trans (cong (get ∘ set a) h)
(get-set a b₀)))
(sym (get-set (set a b) b₀)))
(get-set (set a b) b₀) ≡⟨ trans-[trans-sym]- _ _ ⟩
trans (sym (get-set a (get a)))
(trans (cong (get ∘ set a) h)
(get-set a b₀)) ≡⟨ cong (λ f → trans (sym (f (get a))) (trans (cong (get ∘ set a) h) (f b₀))) $ sym $
_≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext) (get-set a) ⟩
trans (sym (ext⁻¹ (⟨ext⟩ (get-set a)) (get a)))
(trans (cong (get ∘ set a) h)
(ext⁻¹ (⟨ext⟩ (get-set a)) b₀)) ≡⟨ elim₁
(λ {f} eq →
trans (sym (ext⁻¹ eq (get a)))
(trans (cong f h) (ext⁻¹ eq b₀)) ≡
h)
(
trans (sym (ext⁻¹ (refl id) (get a)))
(trans (cong id h) (ext⁻¹ (refl id) b₀)) ≡⟨ cong₂ (λ p q → trans p (trans (cong id h) q))
(trans (cong sym (ext⁻¹-refl _)) sym-refl)
(ext⁻¹-refl _) ⟩
trans (refl _) (trans (cong id h) (refl _)) ≡⟨ trans-reflˡ _ ⟩
trans (cong id h) (refl _) ≡⟨ trans-reflʳ _ ⟩
cong id h ≡⟨ sym $ cong-id _ ⟩∎
h ∎)
_ ⟩∎
h ∎
in
((set (set a b) b₀ , get-set (set a b) b₀) , get (set a b)) ≡⟨ cong₂ _,_ (Σ-≡,≡→≡ lemma₁ lemma₂) (get-set a b) ⟩∎
((a , h ) , b ) ∎)
(λ a →
set (set a b₀) (get a) ≡⟨ set-set a b₀ (get a) ⟩
set a (get a) ≡⟨ set-get a ⟩∎
a ∎)
where
open Coherent-lens l
------------------------------------------------------------------------
-- A conversion function
-- If A is a set, then Lens A B is equivalent to Coherent-lens A B.
≃coherent : Is-set A → Lens A B ≃ Coherent-lens A B
≃coherent {A = A} {B = B} A-set = Eq.↔→≃
to
Coherent-lens.lens
(λ l → let l′ = Coherent-lens.lens l in
$⟨ ×-closure 1
(Π-closure ext 1 λ a →
mono₁ 2 (B-set l′ a))
(Π-closure ext 1 λ a →
Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
mono₁ 2 (B-set l′ a)) ⟩
Is-proposition _ ↝⟨ (λ p → cong (l′ ,_) (p _ _)) ⦂ (_ → _) ⟩
(l′ , _) ≡ (l′ , _) ↔⟨ Eq.≃-≡ Coherent-lens-as-Σ ⟩□
to l′ ≡ l □)
refl
where
B-set : Lens A B → A → Is-set B
B-set l a =
h-level-respects-lens-from-inhabited 2 l a A-set
to : Lens A B → Coherent-lens A B
to l = record
{ lens = l
; get-set-get = λ a → B-set l a _ _
; get-set-set = λ a _ _ → B-set l a _ _
}
-- The conversion preserves getters and setters.
≃coherent-preserves-getters-and-setters :
{A : Type a}
(s : Is-set A) →
Preserves-getters-and-setters-⇔ A B
(_≃_.logical-equivalence (≃coherent s))
≃coherent-preserves-getters-and-setters _ =
(λ _ → refl _ , refl _)
, (λ _ → refl _ , refl _)
------------------------------------------------------------------------
-- Some existence results
-- There is, in general, no lens for the first projection from a
-- Σ-type.
no-first-projection-lens :
¬ Lens (∃ λ (b : Bool) → b ≡ true) Bool
no-first-projection-lens =
Non-dependent.no-first-projection-lens
Lens contractible-to-contractible
-- A variant of the previous result: If A is merely inhabited, and one
-- can "project" out a boolean from a value of type A, but this
-- boolean is necessarily true, then there is no lens corresponding to
-- this projection.
no-singleton-projection-lens :
∥ A ∥ →
(bool : A → Bool) →
(∀ x → bool x ≡ true) →
¬ ∃ λ (l : Lens A Bool) →
∀ x → Lens.get l x ≡ bool x
no-singleton-projection-lens =
Non-dependent.no-singleton-projection-lens _ _ Lens.get-set
-- There are two lenses with equal setters that are not equal
-- (assuming univalence).
--
-- (The lemma does not actually use the univalence argument, but
-- univalence is used by Circle.not-refl≢refl.)
equal-setters-but-not-equal :
Univalence lzero →
∃ λ (A : Type) →
∃ λ (B : Type) →
∃ λ (l₁ : Lens A B) →
∃ λ (l₂ : Lens A B) →
Lens.set l₁ ≡ Lens.set l₂ ×
l₁ ≢ l₂
equal-setters-but-not-equal _ =
𝕊¹ , ⊤ , l₁′ , l₂′ , refl _ , l₁′≢l₂′
where
open Lens
lemma : Lens 𝕊¹ ⊤ ≃ ((x : 𝕊¹) → x ≡ x)
lemma =
Lens 𝕊¹ ⊤ ↔⟨ lens-to-proposition↔ (mono₁ 0 ⊤-contractible) ⟩
(𝕊¹ → ⊤) × ((x : 𝕊¹) → x ≡ x) ↔⟨ (drop-⊤-left-× λ _ → →-right-zero) ⟩□
((x : 𝕊¹) → x ≡ x) □
l₁′ : Lens 𝕊¹ ⊤
l₁′ = _≃_.from lemma Circle.not-refl
l₂′ : Lens 𝕊¹ ⊤
l₂′ = _≃_.from lemma refl
set-l₁′≡set-l₂′ : set l₁′ ≡ set l₂′
set-l₁′≡set-l₂′ = refl _
l₁′≢l₂′ : l₁′ ≢ l₂′
l₁′≢l₂′ =
l₁′ ≡ l₂′ ↔⟨ Eq.≃-≡ (inverse lemma) {x = Circle.not-refl} {y = refl} ⟩
Circle.not-refl ≡ refl ↝⟨ Circle.not-refl≢refl ⟩□
⊥ □
-- A lens which is used in some counterexamples below.
bad : (a : Level) → Lens (↑ a 𝕊¹) (↑ a 𝕊¹)
bad a = record
{ get = id
; set = const id
; get-set = λ _ → cong lift ∘ Circle.not-refl ∘ lower
; set-get = refl
; set-set = λ _ _ → cong lift ∘ Circle.not-refl ∘ lower
}
-- The lens bad a has a getter which is an equivalence, but it does
-- not satisfy either of the coherence laws that Coherent-lens lenses
-- must satisfy (assuming univalence).
--
-- (The lemma does not actually use the univalence argument, but
-- univalence is used by Circle.not-refl≢refl.)
getter-equivalence-but-not-coherent :
Univalence lzero →
let open Lens (bad a) in
Is-equivalence get ×
¬ (∀ a → cong get (set-get a) ≡ get-set a (get a)) ×
¬ (∀ a₁ a₂ a₃ →
cong get (set-set a₁ a₂ a₃) ≡
trans (get-set (set a₁ a₂) a₃) (sym (get-set a₁ a₃)))
getter-equivalence-but-not-coherent {a = a} _ =
_≃_.is-equivalence F.id
, (((x : ↑ a 𝕊¹) → cong get (set-get x) ≡ get-set x (get x)) ↔⟨⟩
((x : ↑ a 𝕊¹) →
cong id (refl _) ≡ cong lift (Circle.not-refl (lower x))) ↔⟨ (Π-cong ext Bij.↑↔ λ _ → Eq.id) ⟩
((x : 𝕊¹) → cong id (refl _) ≡ cong lift (Circle.not-refl x)) ↝⟨ trans (trans (cong-refl _) (cong-id _)) ∘_ ⟩
((x : 𝕊¹) → cong lift (refl x) ≡ cong lift (Circle.not-refl x)) ↔⟨ (∀-cong ext λ _ →
Eq.≃-≡ $ inverse $ Eq.≃-≡ $ Eq.↔⇒≃ $ inverse Bij.↑↔) ⟩
((x : 𝕊¹) → refl x ≡ Circle.not-refl x) ↔⟨ Eq.extensionality-isomorphism ext ⟩
refl ≡ Circle.not-refl ↝⟨ Circle.not-refl≢refl ∘ sym ⟩□
⊥ □)
, (((x y z : ↑ a 𝕊¹) →
cong get (set-set x y z) ≡
trans (get-set (set x y) z) (sym (get-set x z))) ↔⟨⟩
((x y z : ↑ a 𝕊¹) →
cong id (cong lift (Circle.not-refl (lower z))) ≡
trans (cong lift (Circle.not-refl (lower z)))
(sym (cong lift (Circle.not-refl (lower z))))) ↔⟨ (Π-cong ext Bij.↑↔ λ _ →
Π-cong ext Bij.↑↔ λ _ →
Π-cong ext Bij.↑↔ λ _ →
Eq.id) ⟩
((x y z : 𝕊¹) →
cong id (cong lift (Circle.not-refl z)) ≡
trans (cong lift (Circle.not-refl z))
(sym (cong lift (Circle.not-refl z)))) ↝⟨ (λ hyp → hyp Circle.base Circle.base) ⟩
((x : 𝕊¹) →
cong id (cong lift (Circle.not-refl x)) ≡
trans (cong lift (Circle.not-refl x))
(sym (cong lift (Circle.not-refl x)))) ↔⟨ (∀-cong ext λ _ → ≡⇒≃ $ cong₂ _≡_
(sym $ cong-id _)
(trans (trans-symʳ _) $
sym $ cong-refl _)) ⟩
((x : 𝕊¹) →
cong lift (Circle.not-refl x) ≡ cong lift (refl x)) ↔⟨ (∀-cong ext λ _ →
Eq.≃-≡ $ inverse $ Eq.≃-≡ $ Eq.↔⇒≃ $ inverse Bij.↑↔) ⟩
((x : 𝕊¹) → Circle.not-refl x ≡ refl x) ↔⟨ Eq.extensionality-isomorphism ext ⟩
Circle.not-refl ≡ refl ↝⟨ Circle.not-refl≢refl ⟩□
⊥ □)
where
open Lens (bad a)
| {
"alphanum_fraction": 0.3500785138,
"avg_line_length": 45.1327327327,
"ext": "agda",
"hexsha": "1df7862cb8a4623b5d50d28e1565ce4e3125b74c",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-07-01T14:33:26.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-07-01T14:33:26.000Z",
"max_forks_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/dependent-lenses",
"max_forks_repo_path": "src/Lens/Non-dependent/Traditional.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811",
"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/dependent-lenses",
"max_issues_repo_path": "src/Lens/Non-dependent/Traditional.agda",
"max_line_length": 146,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/dependent-lenses",
"max_stars_repo_path": "src/Lens/Non-dependent/Traditional.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:55:52.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T12:10:46.000Z",
"num_tokens": 24407,
"size": 75146
} |
{-# OPTIONS --without-K --safe #-}
-- The category of Cats is Monoidal
module Categories.Category.Monoidal.Instance.Cats where
open import Level
open import Categories.Category.BinaryProducts using (BinaryProducts)
open import Categories.Category.Cartesian using (Cartesian)
open import Categories.Category.Cartesian.Monoidal using (module CartesianMonoidal)
open import Categories.Category.Instance.Cats using (Cats)
open import Categories.Category.Instance.One using (One-⊤)
open import Categories.Category.Monoidal using (Monoidal)
open import Categories.Category.Product using (Product; πˡ; πʳ; _※_)
open import Categories.Category.Product.Properties using (project₁; project₂; unique)
-- Cats is a Monoidal Category with Product as Bifunctor
module Product {o ℓ e : Level} where
private
C = Cats o ℓ e
Cats-has-all : BinaryProducts C
Cats-has-all = record { product = λ {A} {B} → record
{ A×B = Product A B
; π₁ = πˡ
; π₂ = πʳ
; ⟨_,_⟩ = _※_
; project₁ = λ {_} {h} {i} → project₁ {i = h} {j = i}
; project₂ = λ {_} {h} {i} → project₂ {i = h} {j = i}
; unique = unique
} }
Cats-is : Cartesian C
Cats-is = record { terminal = One-⊤ ; products = Cats-has-all }
Cats-Monoidal : Monoidal C
Cats-Monoidal = CartesianMonoidal.monoidal Cats-is
| {
"alphanum_fraction": 0.7026194145,
"avg_line_length": 33.2820512821,
"ext": "agda",
"hexsha": "adeac7d48649b135372e2ff56bc0dc682884b4ac",
"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/Category/Monoidal/Instance/Cats.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/Category/Monoidal/Instance/Cats.agda",
"max_line_length": 85,
"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/Category/Monoidal/Instance/Cats.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": 360,
"size": 1298
} |
{-# OPTIONS --warning=error --safe --without-K #-}
open import LogicalFormulae
open import Numbers.Naturals.Definition
open import Numbers.Naturals.Addition
open import Numbers.Naturals.Multiplication
open import Semirings.Definition
open import Monoids.Definition
module Numbers.Naturals.Semiring where
open Numbers.Naturals.Definition using (ℕ ; zero ; succ ; succInjective ; naughtE) public
open Numbers.Naturals.Addition using (_+N_ ; canSubtractFromEqualityRight ; canSubtractFromEqualityLeft) public
open Numbers.Naturals.Multiplication using (_*N_ ; multiplicationNIsCommutative) public
ℕSemiring : Semiring 0 1 _+N_ _*N_
Monoid.associative (Semiring.monoid ℕSemiring) a b c = equalityCommutative (additionNIsAssociative a b c)
Monoid.idLeft (Semiring.monoid ℕSemiring) _ = refl
Monoid.idRight (Semiring.monoid ℕSemiring) a = additionNIsCommutative a 0
Semiring.commutative ℕSemiring = additionNIsCommutative
Monoid.associative (Semiring.multMonoid ℕSemiring) = multiplicationNIsAssociative
Monoid.idLeft (Semiring.multMonoid ℕSemiring) a = additionNIsCommutative a 0
Monoid.idRight (Semiring.multMonoid ℕSemiring) a = transitivity (multiplicationNIsCommutative a 1) (additionNIsCommutative a 0)
Semiring.productZeroLeft ℕSemiring _ = refl
Semiring.productZeroRight ℕSemiring a = multiplicationNIsCommutative a 0
Semiring.+DistributesOver* ℕSemiring = productDistributes
Semiring.+DistributesOver*' ℕSemiring a b c rewrite multiplicationNIsCommutative (a +N b) c | multiplicationNIsCommutative a c | multiplicationNIsCommutative b c = productDistributes c a b
succExtracts : (x y : ℕ) → (x +N succ y) ≡ (succ (x +N y))
succExtracts x y = transitivity (Semiring.commutative ℕSemiring x (succ y)) (applyEquality succ (Semiring.commutative ℕSemiring y x))
productZeroImpliesOperandZero : {a b : ℕ} → a *N b ≡ 0 → (a ≡ 0) || (b ≡ 0)
productZeroImpliesOperandZero {zero} {b} pr = inl refl
productZeroImpliesOperandZero {succ a} {zero} pr = inr refl
productZeroImpliesOperandZero {succ a} {succ b} ()
*NWellDefined : {a b c d : ℕ} → (a ≡ c) → (b ≡ d) → a *N b ≡ c *N d
*NWellDefined refl refl = refl
+NWellDefined : {a b c d : ℕ} → (a ≡ c) → (b ≡ d) → a +N b ≡ c +N d
+NWellDefined refl refl = refl
| {
"alphanum_fraction": 0.7753623188,
"avg_line_length": 52.5714285714,
"ext": "agda",
"hexsha": "40c7b910a65edc9eaf468909da427d6e415b434a",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Numbers/Naturals/Semiring.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Numbers/Naturals/Semiring.agda",
"max_line_length": 188,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Numbers/Naturals/Semiring.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 701,
"size": 2208
} |
-- Type-checker for the simply-typed lambda calculus
--
-- Where we make sure that failing to typecheck a term is justified by
-- an "ill-typing judgment", which erases to the original term.
open import Data.Empty
open import Data.Unit hiding (_≟_)
open import Data.List hiding ([_])
open import Data.Nat hiding (_*_ ; _+_ ; _≟_)
open import Data.Product
open import Relation.Nullary
open import Relation.Binary hiding (_⇒_)
open import Relation.Binary.PropositionalEquality hiding ([_])
infix 5 _⊢?_∋_
infix 5 _⊢?_∈
infix 19 _↪_
infixr 30 _+_
infixr 35 _*_
infixr 40 _⇒_
infix 50 _∈_
infix 50 _∈
infix 50 _∋_
infixl 150 _▹_
-- * Types
data type : Set where
unit nat : type
_*_ _+_ _⇒_ : (A B : type) → type
bool : type
bool = unit + unit
-- TODO: automate this definition using reflection of Agda in Agda
-- see https://github.com/UlfNorell/agda-prelude/blob/master/src/Tactic/Deriving/Eq.agda
_≟_ : Decidable {A = type} _≡_
unit ≟ unit = yes refl
nat ≟ nat = yes refl
(A₁ + B₁) ≟ (A₂ + B₂)
with A₁ ≟ A₂ | B₁ ≟ B₂
... | yes refl | yes refl = yes refl
... | yes refl | no ¬p = no (λ { refl → ¬p refl })
... | no ¬p | _ = no (λ { refl → ¬p refl })
(A₁ ⇒ B₁) ≟ (A₂ ⇒ B₂)
with A₁ ≟ A₂ | B₁ ≟ B₂
... | yes refl | yes refl = yes refl
... | yes _ | no ¬p = no λ { refl → ¬p refl }
... | no ¬p | _ = no λ { refl → ¬p refl }
(A₁ * B₁) ≟ (A₂ * B₂)
with A₁ ≟ A₂ | B₁ ≟ B₂
... | yes refl | yes refl = yes refl
... | yes _ | no ¬p = no λ { refl → ¬p refl }
... | no ¬p | q₂ = no λ { refl → ¬p refl }
unit ≟ (_ ⇒ _) = no λ {()}
unit ≟ (_ * _) = no λ {()}
unit ≟ nat = no λ {()}
unit ≟ (_ + _) = no λ {()}
nat ≟ (_ ⇒ _) = no λ {()}
nat ≟ (_ * _) = no λ {()}
nat ≟ unit = no λ {()}
nat ≟ (_ + _) = no λ {()}
(_ + _) ≟ (_ ⇒ _) = no λ {()}
(_ + _) ≟ (_ * _) = no λ {()}
(_ + _) ≟ nat = no λ {()}
(_ + _) ≟ unit = no λ {()}
(_ ⇒ _) ≟ unit = no λ {()}
(_ ⇒ _) ≟ nat = no λ {()}
(_ ⇒ _) ≟ (_ * _) = no λ {()}
(_ ⇒ _) ≟ (_ + _) = no λ {()}
(_ * _) ≟ unit = no λ {()}
(_ * _) ≟ nat = no λ {()}
(_ * _) ≟ (_ ⇒ _) = no λ {()}
(_ * _) ≟ (_ + _) = no λ {()}
-- * Syntax of terms
data dir : Set where
⇑ ⇓ : dir
data can (T : Set) : Set where
tt : can T
pair : (t₁ t₂ : T) → can T
lam : (b : T) → can T
ze : can T
su : (t : T) → can T
inj₁ inj₂ : (t : T) → can T
data elim (T : Set) : dir → Set where
apply : (s : T) → elim T ⇑
fst snd : elim T ⇑
split : (c₁ c₂ : T) → elim T ⇓
data term : dir → Set where
C : (c : can (term ⇓)) → term ⇓
inv : (t : term ⇑) → term ⇓
var : (k : ℕ) → term ⇑
_#_ : ∀ {d} → (n : term ⇑)(args : elim (term ⇓) d) → term d
[_:∋:_] : (T : type)(t : term ⇓) → term ⇑
pattern Ctt = C tt
pattern Cze = C ze
pattern Csu x = C (su x)
pattern Cpair x y = C (pair x y)
pattern Clam b = C (lam b)
pattern Cinj₁ x = C (inj₁ x)
pattern Cinj₂ x = C (inj₂ x)
-- ** Tests
true : term ⇓
true = Cinj₁ Ctt
false : term ⇓
false = Cinj₂ Ctt
t1 : term ⇓
t1 = inv ([ nat ⇒ nat :∋: Clam {- x -} (inv (var {- x -} 0)) ] # apply (Csu (Csu Cze)))
t2 : term ⇓
t2 = Clam {-x-} (var {- x -} 0 # split true false)
-- * Type system
context = List type
pattern _▹_ Γ T = T ∷ Γ
pattern ε = []
data _∈_ (T : type) : context → Set where
here : ∀ {Γ} →
---------
T ∈ Γ ▹ T
there : ∀ {Γ T'} →
T ∈ Γ
→ ----------
T ∈ Γ ▹ T'
mutual
data _C⊢[_]_ : context → dir → type → Set where
lam : ∀ {Γ A B} →
Γ ▹ A ⊢[ ⇓ ] B
→ ---------------
Γ C⊢[ ⇓ ] A ⇒ B
tt : ∀ {Γ} →
--------------
Γ C⊢[ ⇓ ] unit
ze : ∀ {Γ} →
-------------
Γ C⊢[ ⇓ ] nat
su : ∀ {Γ} →
Γ ⊢[ ⇓ ] nat
→ -------------
Γ C⊢[ ⇓ ] nat
inj₁ : ∀ {Γ A B} →
Γ ⊢[ ⇓ ] A
→ ---------------
Γ C⊢[ ⇓ ] A + B
inj₂ : ∀ {Γ A B} →
Γ ⊢[ ⇓ ] B
→ ---------------
Γ C⊢[ ⇓ ] A + B
pair : ∀ {Γ A B} →
Γ ⊢[ ⇓ ] A →
Γ ⊢[ ⇓ ] B
→ ---------------
Γ C⊢[ ⇓ ] A * B
data _E⊢[_]_↝_ : context → dir → type → type → Set where
apply : ∀ {Γ A B} →
Γ ⊢[ ⇓ ] A
→ -------------------
Γ E⊢[ ⇑ ] A ⇒ B ↝ B
fst : ∀ {Γ A B} →
-------------------
Γ E⊢[ ⇑ ] A * B ↝ A
snd : ∀ {Γ A B} →
-------------------
Γ E⊢[ ⇑ ] A * B ↝ B
iter : ∀ {Γ A} →
Γ ▹ A ⊢[ ⇓ ] A →
Γ ⊢[ ⇓ ] A
→ -----------------
Γ E⊢[ ⇓ ] nat ↝ A
case : ∀ {Γ A B C} →
Γ ▹ A ⊢[ ⇓ ] C →
Γ ▹ B ⊢[ ⇓ ] C
→ -------------------
Γ E⊢[ ⇓ ] A + B ↝ C
data _⊢[_]_ : context → dir → type → Set where
C : ∀ {Γ d T} →
Γ C⊢[ d ] T
→ -----------
Γ ⊢[ d ] T
inv : ∀ {Γ T} →
Γ ⊢[ ⇑ ] T
→ ----------
Γ ⊢[ ⇓ ] T
var : ∀ {Γ T} →
T ∈ Γ
→ ----------
Γ ⊢[ ⇑ ] T
_#_ : ∀ {Γ d I O} →
Γ ⊢[ ⇑ ] I →
Γ E⊢[ d ] I ↝ O
→ ---------------
Γ ⊢[ d ] O
[_:∋:_by_] : ∀ {Γ A} →
(B : type) → Γ ⊢[ ⇓ ] B → A ≡ B
→ -------------------------------
Γ ⊢[ ⇑ ] A
-- ** Tests
⊢true : [] ⊢[ ⇓ ] bool
⊢true = C (inj₁ (C tt))
⊢false : [] ⊢[ ⇓ ] bool
⊢false = C (inj₂ (C tt))
⊢t1 : [] ⊢[ ⇓ ] nat
⊢t1 = inv ([ (nat ⇒ nat) :∋: (C (lam (inv (var here)))) by refl ]
# (apply (C (su (C (su (C ze)))))))
-- * Relating typing and terms
record _↪_ (S T : Set) : Set where
field
⌊_⌋ : S → T
open _↪_ {{...}} public
instance
VarRaw : ∀ {T Γ} → T ∈ Γ ↪ ℕ
⌊_⌋ {{ VarRaw }} here = zero
⌊_⌋ {{ VarRaw }} (there x) = suc ⌊ x ⌋
OTermRaw : ∀ {Γ T d} → Γ ⊢[ d ] T ↪ term d
⌊_⌋ {{OTermRaw}} (C (lam b)) = C (lam ⌊ b ⌋)
⌊_⌋ {{OTermRaw}} (C tt) = C tt
⌊_⌋ {{OTermRaw}} (C ze) = C ze
⌊_⌋ {{OTermRaw}} (C (su t)) = C (su ⌊ t ⌋)
⌊_⌋ {{OTermRaw}} (C (inj₁ t)) = C (inj₁ ⌊ t ⌋)
⌊_⌋ {{OTermRaw}} (C (inj₂ t)) = C (inj₂ ⌊ t ⌋)
⌊_⌋ {{OTermRaw}} (C (pair t₁ t₂)) = C (pair ⌊ t₁ ⌋ ⌊ t₂ ⌋)
⌊_⌋ {{OTermRaw}} (inv t) = inv ⌊ t ⌋
⌊_⌋ {{OTermRaw}} (var x) = var ⌊ x ⌋
⌊_⌋ {{OTermRaw}} (f # (apply s)) = ⌊ f ⌋ # apply ⌊ s ⌋
⌊_⌋ {{OTermRaw}} (p # fst) = ⌊ p ⌋ # fst
⌊_⌋ {{OTermRaw}} (p # snd) = ⌊ p ⌋ # snd
⌊_⌋ {{OTermRaw}} (t # case x y) = ⌊ t ⌋ # split ⌊ x ⌋ ⌊ y ⌋
⌊_⌋ {{OTermRaw}} (t # iter fs fz) = ⌊ t ⌋ # split ⌊ fs ⌋ ⌊ fz ⌋
⌊_⌋ {{OTermRaw}} [ T :∋: t by refl ] = [ T :∋: ⌊ t ⌋ ]
data _⊢_∋_ (Γ : context)(T : type){d} : term d → Set where
well-typed : (Δ : Γ ⊢[ d ] T ) → Γ ⊢ T ∋ ⌊ Δ ⌋
-- TODO: one could prove that `Γ ⊢ T ∋ t` is H-prop when `t : term ⇓`, ie. we have
-- lemma-proof-irr : ∀ {Γ T}{t : term ⇓} → ∀ (pf₁ pf₂ : Γ ⊢ T ∋ t) → → pf₁ ≅ pf₂
-- but this requires proving that `⌊_⌋` is injective.
-- TODO: conversely, one should be able to prove that `Γ ⊢ T ∋ t` is
-- equivalent to `type` when `t : term ⇑` but I haven't tried.
-- ** Tests
bool∋true : [] ⊢ bool ∋ true
bool∋true = well-typed ⊢true
bool∋false : [] ⊢ bool ∋ false
bool∋false = well-typed ⊢false
nat∋t1 : [] ⊢ nat ∋ t1
nat∋t1 = well-typed ⊢t1
-- * Ill-type system
data Canonical {X} : type → can X → Set where
can-unit-tt : Canonical unit tt
can-nat-ze : Canonical nat ze
can-nat-su : ∀ {a} → Canonical nat (su a)
can-sum-inj₁ : ∀ {A B a} → Canonical (A + B) (inj₁ a)
can-sum-inj₂ : ∀ {A B b} → Canonical (A + B) (inj₂ b)
can-prod-pair : ∀ {A B a b} → Canonical (A * B) (pair a b)
data IsProduct : type → Set where
is-product : ∀ {A B} → IsProduct (A * B)
data IsArrow : type → Set where
is-arrow : ∀ {A B} → IsArrow (A ⇒ B)
data IsSplit : type → Set where
is-split-nat : IsSplit nat
is-split-sum : ∀ {A B} → IsSplit (A + B)
mtype : dir → Set
mtype ⇑ = ⊤
mtype ⇓ = type
data _B⊬[_]_ (Γ : context) : (d : dir) → mtype d → Set where
not-canonical : ∀ {c : can (term ⇓)}{T} →
¬ Canonical T c
→ ---------------
Γ B⊬[ ⇓ ] T
unsafe-inv : ∀ {A B} →
Γ ⊢[ ⇑ ] A → A ≢ B
→ -------------------
Γ B⊬[ ⇓ ] B
bad-split : ∀ {A B}{c₁ c₂ : term ⇓} →
Γ ⊢[ ⇑ ] A → ¬ IsSplit A
→ -------------------------
Γ B⊬[ ⇓ ] B
out-of-scope : ∀ {x : ℕ} →
x ≥ length Γ
→ ------------
Γ B⊬[ ⇑ ] _
bad-function : ∀ {T}{s : term ⇓} →
Γ ⊢[ ⇑ ] T → ¬ IsArrow T
→ ------------------------
Γ B⊬[ ⇑ ] _
bad-fst : ∀ {T} →
Γ ⊢[ ⇑ ] T → ¬ IsProduct T
→ --------------------------
Γ B⊬[ ⇑ ] _
bad-snd : ∀ {T} →
Γ ⊢[ ⇑ ] T → ¬ IsProduct T
→ --------------------------
Γ B⊬[ ⇑ ] _
-- TODO: automate this "trisection & free monad" construction by meta-programming
-- see: "The gentle art of levitation", Chapman et al. for the free monad
-- see: "Clowns to the left of me, jokers to the right", McBride for the dissection
mutual
data _C⊬[_]_ : context → (d : dir) → mtype d → Set where
lam : ∀ {Γ A B} → Γ ▹ A ⊬[ ⇓ ] B → Γ C⊬[ ⇓ ] A ⇒ B
su : ∀ {Γ} → Γ ⊬[ ⇓ ] nat → Γ C⊬[ ⇓ ] nat
inj₁ : ∀ {Γ A B} → Γ ⊬[ ⇓ ] A → Γ C⊬[ ⇓ ] A + B
inj₂ : ∀ {Γ A B} → Γ ⊬[ ⇓ ] B → Γ C⊬[ ⇓ ] A + B
pair₁ : ∀ {Γ A B} → Γ ⊬[ ⇓ ] A → term ⇓ → Γ C⊬[ ⇓ ] A * B
pair₂ : ∀ {Γ A B} → Γ ⊢[ ⇓ ] A → Γ ⊬[ ⇓ ] B → Γ C⊬[ ⇓ ] A * B
data _E⊬[_]_↝_ : context → (d : dir) → type → mtype d → Set where
apply : ∀ {Γ A B} → Γ ⊬[ ⇓ ] A → Γ E⊬[ ⇑ ] A ⇒ B ↝ _
iter₁ : ∀ {Γ T} → Γ ▹ T ⊬[ ⇓ ] T → term ⇓ → Γ E⊬[ ⇓ ] nat ↝ T
iter₂ : ∀ {Γ T} → Γ ▹ T ⊢[ ⇓ ] T → Γ ⊬[ ⇓ ] T → Γ E⊬[ ⇓ ] nat ↝ T
case₁ : ∀ {Γ A B C} → Γ ▹ A ⊬[ ⇓ ] C → term ⇓ → Γ E⊬[ ⇓ ] A + B ↝ C
case₂ : ∀ {Γ A B C} → Γ ▹ A ⊢[ ⇓ ] C → Γ ▹ B ⊬[ ⇓ ] C → Γ E⊬[ ⇓ ] A + B ↝ C
data _⊬[_]_ : context → (d : dir) → mtype d → Set where
because : ∀ {Γ d T} → Γ B⊬[ d ] T → Γ ⊬[ d ] T
C : ∀ {Γ d T} → Γ C⊬[ d ] T → Γ ⊬[ d ] T
inv : ∀ {Γ T} → Γ ⊬[ ⇑ ] _ → Γ ⊬[ ⇓ ] T
_#₁_ : ∀ {Γ d T} → Γ ⊬[ ⇑ ] _ → elim (term ⇓) d → Γ ⊬[ d ] T
_#₂_ : ∀ {Γ d I O} → Γ ⊢[ ⇑ ] I → Γ E⊬[ d ] I ↝ O → Γ ⊬[ d ] O
[_:∋:_] : ∀ {Γ} → (T : type) → Γ ⊬[ ⇓ ] T → Γ ⊬[ ⇑ ] _
instance
BTermRaw : ∀ {Γ d T} → Γ B⊬[ d ] T ↪ term d
⌊_⌋ {{BTermRaw}} (not-canonical {c} x) = C c
⌊_⌋ {{BTermRaw}} (unsafe-inv q _) = inv ⌊ q ⌋
⌊_⌋ {{BTermRaw}} (bad-split {c₁ = c₁} {c₂} t _) = ⌊ t ⌋ # split c₁ c₂
⌊_⌋ {{BTermRaw}} (out-of-scope {x} _) = var x
⌊_⌋ {{BTermRaw}} (bad-function {s = s} f _) = ⌊ f ⌋ # apply s
⌊_⌋ {{BTermRaw}} (bad-fst p _) = ⌊ p ⌋ # fst
⌊_⌋ {{BTermRaw}} (bad-snd p _) = ⌊ p ⌋ # snd
ETermRaw : ∀ {Γ d T} → Γ ⊬[ d ] T ↪ term d
⌊_⌋ {{ETermRaw}} (because e) = ⌊ e ⌋
⌊_⌋ {{ETermRaw}} (C (lam b)) = C (lam ⌊ b ⌋)
⌊_⌋ {{ETermRaw}} (C (su t)) = C (su ⌊ t ⌋)
⌊_⌋ {{ETermRaw}} (C (inj₁ t)) = C (inj₁ ⌊ t ⌋)
⌊_⌋ {{ETermRaw}} (C (inj₂ t)) = C (inj₂ ⌊ t ⌋)
⌊_⌋ {{ETermRaw}} (C (pair₁ t₁ t₂)) = C (pair ⌊ t₁ ⌋ t₂)
⌊_⌋ {{ETermRaw}} (C (pair₂ t₁ t₂)) = C (pair ⌊ t₁ ⌋ ⌊ t₂ ⌋)
⌊_⌋ {{ETermRaw}} (inv t) = inv ⌊ t ⌋
⌊_⌋ {{ETermRaw}} [ T :∋: t ] = [ T :∋: ⌊ t ⌋ ]
⌊_⌋ {{ETermRaw}} (t #₁ e) = ⌊ t ⌋ # e
⌊_⌋ {{ETermRaw}} (t #₂ apply x) = ⌊ t ⌋ # apply ⌊ x ⌋
⌊_⌋ {{ETermRaw}} (t #₂ iter₁ fs fz) = ⌊ t ⌋ # split ⌊ fs ⌋ fz
⌊_⌋ {{ETermRaw}} (t #₂ iter₂ fs fz) = ⌊ t ⌋ # split ⌊ fs ⌋ ⌊ fz ⌋
⌊_⌋ {{ETermRaw}} (t #₂ case₁ cX cY) = ⌊ t ⌋ # split ⌊ cX ⌋ cY
⌊_⌋ {{ETermRaw}} (t #₂ case₂ cX cY) = ⌊ t ⌋ # split ⌊ cX ⌋ ⌊ cY ⌋
-- * Type-checking
-- ** View on variable lookup
data _∈-view_ : ℕ → context → Set where
yes : ∀ {T Γ} → (x : T ∈ Γ) → ⌊ x ⌋ ∈-view Γ
no : ∀ {Γ n} → n ≥ length Γ → n ∈-view Γ
_∈?_ : ∀ n Γ → n ∈-view Γ
_ ∈? ε = no z≤n
zero ∈? Γ ▹ T = yes here
suc n ∈? Γ ▹ T
with n ∈? Γ
... | yes t = yes (there t)
... | no q = no (s≤s q)
-- ** View on typing
data Dir : dir → Set where
_∈ : term ⇑ → Dir ⇑
_∋_ : type → term ⇓ → Dir ⇓
instance
DirRaw : ∀ {Γ d T} → Γ ⊢[ d ] T ↪ Dir d
⌊_⌋ {{DirRaw {d = ⇑}}} e = ⌊ e ⌋ ∈
⌊_⌋ {{DirRaw {d = ⇓}{T}}} e = T ∋ ⌊ e ⌋
EDirRaw : ∀ {Γ d T} → Γ ⊬[ d ] T ↪ Dir d
⌊_⌋ {{EDirRaw {d = ⇑}}} e = ⌊ e ⌋ ∈
⌊_⌋ {{EDirRaw {d = ⇓}{T}}} e = T ∋ ⌊ e ⌋
data _⊢[_]-view_ (Γ : context)(d : dir) : Dir d → Set where
yes : ∀ {T} (Δ : Γ ⊢[ d ] T) → Γ ⊢[ d ]-view ⌊ Δ ⌋
no : ∀ {T} (¬Δ : Γ ⊬[ d ] T) → Γ ⊢[ d ]-view ⌊ ¬Δ ⌋
isYes : ∀ {Γ T t} → Γ ⊢[ ⇓ ]-view T ∋ t → Set
isYes (yes Δ) = ⊤
isYes (no ¬Δ) = ⊥
lemma : ∀ {Γ T t} → (pf : Γ ⊢[ ⇓ ]-view T ∋ t) → isYes pf → Γ ⊢ T ∋ t
lemma (yes Δ) tt = well-typed Δ
lemma (no _) ()
-- XXX: Mutually-recursive to please the termination checker
_⊢?_∋_ : (Γ : context)(T : type)(t : term ⇓) → Γ ⊢[ ⇓ ]-view T ∋ t
_⊢?_∈ : (Γ : context)(t : term ⇑) → Γ ⊢[ ⇑ ]-view t ∈
_⊢?_∋C_ : (Γ : context)(T : type)(t : can (term ⇓)) → Γ ⊢[ ⇓ ]-view T ∋ C t
_!_∋_⊢?_∋#_ : (Γ : context)(I : type)(Δt : Γ ⊢[ ⇑ ] I)(T : type)(e : elim (term ⇓) ⇓) → Γ ⊢[ ⇓ ]-view T ∋ (⌊ Δt ⌋ # e)
_!_∋_⊢?_∈# : (Γ : context)(T : type)(Δt : Γ ⊢[ ⇑ ] T)(e : elim (term ⇓) ⇑) → Γ ⊢[ ⇑ ]-view (⌊ Δt ⌋ # e) ∈
Γ ⊢? T ∋ C t = Γ ⊢? T ∋C t
Γ ⊢? T ∋ inv t
with Γ ⊢? t ∈
... | no ¬Δ = no (inv ¬Δ)
... | yes {T'} Δ
with T' ≟ T
... | yes refl = yes (inv Δ)
... | no ¬p = no (because (unsafe-inv Δ ¬p))
Γ ⊢? A ∋ t # e
with Γ ⊢? t ∈
... | no ¬Δt = no (¬Δt #₁ e)
... | yes {T} Δt = Γ ! T ∋ Δt ⊢? A ∋# e
Γ ⊢? var k ∈
with k ∈? Γ
... | yes x = yes (var x)
... | no ¬q = no (because (out-of-scope ¬q))
Γ ⊢? t # e ∈
with Γ ⊢? t ∈
... | no ¬Δt = no (¬Δt #₁ e)
... | yes {T} Δt = Γ ! T ∋ Δt ⊢? e ∈#
Γ ⊢? [ T :∋: t ] ∈
with Γ ⊢? T ∋ t
... | yes Δt = yes [ T :∋: Δt by refl ]
... | no ¬Δt = no [ T :∋: ¬Δt ]
Γ ⊢? unit ∋C tt = yes (C tt)
Γ ⊢? unit ∋C pair _ _ = no (because (not-canonical (λ {()})))
Γ ⊢? unit ∋C lam _ = no (because (not-canonical (λ {()})))
Γ ⊢? unit ∋C ze = no (because (not-canonical (λ {()})))
Γ ⊢? unit ∋C su _ = no (because (not-canonical (λ {()})))
Γ ⊢? unit ∋C inj₁ _ = no (because (not-canonical (λ {()})))
Γ ⊢? unit ∋C inj₂ _ = no (because (not-canonical (λ {()})))
Γ ⊢? A * B ∋C pair t₁ t₂
with Γ ⊢? A ∋ t₁ | Γ ⊢? B ∋ t₂
... | yes Δ₁ | yes Δ₂ = yes (C (pair Δ₁ Δ₂))
... | yes Δ₁ | no ¬Δ₂ = no (C (pair₂ Δ₁ ¬Δ₂))
... | no ¬Δ₁ | _ = no (C (pair₁ ¬Δ₁ t₂))
Γ ⊢? A * B ∋C tt = no (because (not-canonical (λ {()})))
Γ ⊢? A * B ∋C lam _ = no (because (not-canonical (λ {()})))
Γ ⊢? A * B ∋C ze = no (because (not-canonical (λ {()})))
Γ ⊢? A * B ∋C su _ = no (because (not-canonical (λ {()})))
Γ ⊢? A * B ∋C inj₁ _ = no (because (not-canonical (λ {()})))
Γ ⊢? A * B ∋C inj₂ _ = no (because (not-canonical (λ {()})))
Γ ⊢? A ⇒ B ∋C lam b
with Γ ▹ A ⊢? B ∋ b
... | yes Δ = yes (C (lam Δ))
... | no ¬Δ = no (C (lam ¬Δ))
Γ ⊢? A ⇒ B ∋C tt = no (because (not-canonical (λ {()})))
Γ ⊢? A ⇒ B ∋C ze = no (because (not-canonical (λ {()})))
Γ ⊢? A ⇒ B ∋C su x = no (because (not-canonical (λ {()})))
Γ ⊢? A ⇒ B ∋C pair _ _ = no (because (not-canonical (λ {()})))
Γ ⊢? A ⇒ B ∋C inj₁ _ = no (because (not-canonical (λ {()})))
Γ ⊢? A ⇒ B ∋C inj₂ _ = no (because (not-canonical (λ {()})))
Γ ⊢? nat ∋C ze = yes (C ze)
Γ ⊢? nat ∋C su n
with Γ ⊢? nat ∋ n
... | yes Δ = yes (C (su Δ))
... | no ¬Δ = no (C (su ¬Δ))
Γ ⊢? nat ∋C tt = no (because (not-canonical (λ {()})))
Γ ⊢? nat ∋C pair _ _ = no (because (not-canonical (λ {()})))
Γ ⊢? nat ∋C lam _ = no (because (not-canonical (λ {()})))
Γ ⊢? nat ∋C inj₁ _ = no (because (not-canonical (λ {()})))
Γ ⊢? nat ∋C inj₂ _ = no (because (not-canonical (λ {()})))
Γ ⊢? A + B ∋C inj₁ t
with Γ ⊢? A ∋ t
... | yes Δ = yes (C (inj₁ Δ))
... | no ¬Δ = no (C (inj₁ ¬Δ))
Γ ⊢? A + B ∋C inj₂ t
with Γ ⊢? B ∋ t
... | yes Δ = yes (C (inj₂ Δ))
... | no ¬Δ = no (C (inj₂ ¬Δ))
Γ ⊢? A + B ∋C tt = no (because (not-canonical (λ {()})))
Γ ⊢? A + B ∋C pair _ _ = no (because (not-canonical (λ {()})))
Γ ⊢? A + B ∋C lam _ = no (because (not-canonical (λ {()})))
Γ ⊢? A + B ∋C ze = no (because (not-canonical (λ {()})))
Γ ⊢? A + B ∋C su _ = no (because (not-canonical (λ {()})))
Γ ! nat ∋ Δt ⊢? A ∋# split fs fz
with Γ ▹ A ⊢? A ∋ fs | Γ ⊢? A ∋ fz
... | yes Δfs | yes Δfz = yes (Δt # iter Δfs Δfz)
... | yes Δfs | no ¬Δfz = no (Δt #₂ iter₂ Δfs ¬Δfz)
... | no ¬Δfs | _ = no (Δt #₂ iter₁ ¬Δfs fz)
Γ ! X + Y ∋ Δt ⊢? A ∋# split cX cY
with (X ∷ Γ) ⊢? A ∋ cX | (Y ∷ Γ) ⊢? A ∋ cY
... | yes ΔcX | yes ΔcY = yes (Δt # case ΔcX ΔcY)
... | yes ΔcX | no ¬ΔcY = no (Δt #₂ case₂ ΔcX ¬ΔcY)
... | no ¬ΔcX | _ = no (Δt #₂ case₁ ¬ΔcX cY)
Γ ! unit ∋ Δt ⊢? A ∋# split _ _ = no (because (bad-split Δt (λ {()})))
Γ ! _ ⇒ _ ∋ Δt ⊢? A ∋# split _ _ = no (because (bad-split Δt (λ {()})))
Γ ! _ * _ ∋ Δt ⊢? A ∋# split _ _ = no (because (bad-split Δt (λ {()})))
Γ ! A ⇒ B ∋ Δf ⊢? apply s ∈#
with Γ ⊢? A ∋ s
... | yes Δs = yes (Δf # apply Δs)
... | no ¬Δs = no (Δf #₂ apply ¬Δs)
Γ ! unit ∋ Δf ⊢? apply _ ∈# = no (because (bad-function Δf λ {()}))
Γ ! nat ∋ Δf ⊢? apply _ ∈# = no (because (bad-function Δf λ {()}))
Γ ! _ + _ ∋ Δf ⊢? apply _ ∈# = no (because (bad-function Δf λ {()}))
Γ ! _ * _ ∋ Δf ⊢? apply _ ∈# = no (because (bad-function Δf λ {()}))
Γ ! A * B ∋ Δp ⊢? fst ∈# = yes (Δp # fst)
Γ ! unit ∋ Δp ⊢? fst ∈# = no (because (bad-fst Δp (λ {()})))
Γ ! nat ∋ Δp ⊢? fst ∈# = no (because (bad-fst Δp (λ {()})))
Γ ! _ + _ ∋ Δp ⊢? fst ∈# = no (because (bad-fst Δp (λ {()})))
Γ ! _ ⇒ _ ∋ Δp ⊢? fst ∈# = no (because (bad-fst Δp (λ {()})))
Γ ! A * B ∋ Δp ⊢? snd ∈# = yes (Δp # snd)
Γ ! unit ∋ Δp ⊢? snd ∈# = no (because (bad-snd Δp (λ {()})))
Γ ! nat ∋ Δp ⊢? snd ∈# = no (because (bad-snd Δp (λ {()})))
Γ ! _ + _ ∋ Δp ⊢? snd ∈# = no (because (bad-snd Δp (λ {()})))
Γ ! _ ⇒ _ ∋ Δp ⊢? snd ∈# = no (because (bad-snd Δp (λ {()})))
-- ** Tests
nat∋t1' : [] ⊢ nat ∋ t1
nat∋t1' = lemma ([] ⊢? nat ∋ t1) tt
T1 : type
T1 = nat ⇒ (unit + unit)
T2 : type
T2 = (nat + unit) ⇒ (unit + unit)
T1∋t2 : [] ⊢ T1 ∋ t2
T1∋t2 = lemma ([] ⊢? T1 ∋ t2) tt
T2∋t2 : [] ⊢ T2 ∋ t2
T2∋t2 = lemma ([] ⊢? T2 ∋ t2) tt
| {
"alphanum_fraction": 0.3955283049,
"avg_line_length": 30.1738437002,
"ext": "agda",
"hexsha": "120d854e6656ddba8e65afe476a6736c14b8edde",
"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": "f807a85ccd570905d3dd834b5966efcf6f215e64",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "pedagand/typechecker-evolution",
"max_forks_repo_path": "STLC.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f807a85ccd570905d3dd834b5966efcf6f215e64",
"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": "pedagand/typechecker-evolution",
"max_issues_repo_path": "STLC.agda",
"max_line_length": 119,
"max_stars_count": 43,
"max_stars_repo_head_hexsha": "f807a85ccd570905d3dd834b5966efcf6f215e64",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "pedagand/typechecker-evolution",
"max_stars_repo_path": "STLC.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-09T11:13:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-02-14T20:50:21.000Z",
"num_tokens": 8774,
"size": 18919
} |
-- Andreas 2015-01-07 fixing polarity of projection-like functions
-- {-# OPTIONS -v tc.polarity:20 -v tc.proj.like:10 #-}
-- {-# OPTIONS -v tc.conv.elim:25 --show-implicit #-}
open import Common.Size
-- List covariant covariant
data List (i : Size) (A : Set) : Set where
[] : List i A
cons : ∀{j : Size< i} → A → List j A → List i A
-- Id mixed mixed mixed covariant
-- Id is projection-like in argument l
Id : ∀{i A} (l : List i A) → Set → Set
Id [] X = X
Id (cons _ _) X = X
-- should pass
cast : ∀{i A} (l : List i A) → Id l (List i A) → Id l (List ∞ A)
cast l x = x
| {
"alphanum_fraction": 0.6,
"avg_line_length": 26.3636363636,
"ext": "agda",
"hexsha": "104a9feaf915851e9d3b2e96d604fff0decda834",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue1592a.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/Issue1592a.agda",
"max_line_length": 66,
"max_stars_count": 3,
"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/Issue1592a.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": 201,
"size": 580
} |
module DualTail where
open import Data.Nat
open import Data.Fin using (Fin; zero; suc)
open import Data.Product
open import Function using (id; _∘_)
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
open import Types.Direction
open import Types.Tail
private
variable
n : ℕ
-- instead of unrolling and substituting, we maintain a stack of bodies of recursive types
data Stack : ℕ → Set where
ε : Stack 0
⟪_,_⟫ : Stack n → GType (suc n) → Stack (suc n)
-- the dual of a stack
dual-stack : Stack n → Stack n
dual-stack ε = ε
dual-stack ⟪ σ , g ⟫ = ⟪ dual-stack σ , dualG g ⟫
-- obtain an entry from the stack
-- technically m = n - i, but we don't need to know
get : (i : Fin n) → Stack n → Σ ℕ λ m → Stack m × GType (suc m)
get zero ⟪ σ , x ⟫ = _ , (σ , x)
get (suc i) ⟪ σ , x ⟫ = get i σ
-- relate a stack entry to the corresponding entry on the dual stack
get-dual-stack : (x : Fin n) (σ : Stack n) →
get x (dual-stack σ) ≡ map id (map dual-stack dualG) (get x σ)
get-dual-stack zero ⟪ σ , x ⟫ = refl
get-dual-stack (suc x) ⟪ σ , x₁ ⟫ = get-dual-stack x σ
-- mapping tail recursive session types to coinductive session types
-- relies on a stack to unfold variables on the fly
import Types.COI as COI
tail2coiT : Type → COI.Type
tail2coiS : Stack n → SType n → COI.SType
tail2coiG : Stack n → GType n → COI.STypeF COI.SType
tail2coiT TUnit = COI.TUnit
tail2coiT TInt = COI.TInt
tail2coiT (TPair t t₁) = COI.TPair (tail2coiT t) (tail2coiT t₁)
tail2coiT (TChan s) = COI.TChan (tail2coiS ε s)
COI.SType.force (tail2coiS σ (gdd g)) = tail2coiG σ g
COI.SType.force (tail2coiS σ (rec g)) = tail2coiG ⟪ σ , g ⟫ g
COI.SType.force (tail2coiS σ (var x))
with get x σ
... | m , σ' , gxs = tail2coiG ⟪ σ' , gxs ⟫ gxs
tail2coiG σ (transmit d t s) = COI.transmit d (tail2coiT t) (tail2coiS σ s)
tail2coiG σ (choice d m alt) = COI.choice d m (tail2coiS σ ∘ alt)
tail2coiG σ end = COI.end
-- get coinductive bisimulation in scope
_≈_ = COI._≈_
_≈'_ = COI._≈'_
-- main proposition
dual-tailS : (σ : Stack n) (s : SType n) →
COI.dual (tail2coiS σ s) ≈ tail2coiS (dual-stack σ) (dualS s)
dual-tailG : (σ : Stack n) (g : GType n) →
COI.dualF (tail2coiG σ g) ≈' tail2coiG (dual-stack σ) (dualG g)
COI.Equiv.force (dual-tailS σ (gdd g)) = dual-tailG σ g
COI.Equiv.force (dual-tailS σ (rec g)) = dual-tailG ⟪ σ , g ⟫ g
COI.Equiv.force (dual-tailS σ (var x))
rewrite get-dual-stack x σ
with get x σ
... | m , σ' , g = dual-tailG ⟪ σ' , g ⟫ g
dual-tailG σ (transmit d t s) = COI.eq-transmit (dual-dir d) COI.≈ᵗ-refl (dual-tailS σ s)
dual-tailG σ (choice d m alt) = COI.eq-choice (dual-dir d) (dual-tailS σ ∘ alt)
dual-tailG σ end = COI.eq-end
-- corrolary for SType 0
dual-tail : ∀ s → COI.dual (tail2coiS ε s) ≈ tail2coiS ε (dualS s)
dual-tail = dual-tailS ε
| {
"alphanum_fraction": 0.6620271235,
"avg_line_length": 29.4947368421,
"ext": "agda",
"hexsha": "328547dc760811c7ced2119af9212c3119977b16",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-12-07T16:12:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-12-07T16:12:50.000Z",
"max_forks_repo_head_hexsha": "7a8bc1f6b2f808bd2a22c592bd482dbcc271979c",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "peterthiemann/dual-session",
"max_forks_repo_path": "src/DualTail.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7a8bc1f6b2f808bd2a22c592bd482dbcc271979c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "peterthiemann/dual-session",
"max_issues_repo_path": "src/DualTail.agda",
"max_line_length": 90,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "7a8bc1f6b2f808bd2a22c592bd482dbcc271979c",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "peterthiemann/dual-session",
"max_stars_repo_path": "src/DualTail.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-13T05:43:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-13T05:43:25.000Z",
"num_tokens": 1115,
"size": 2802
} |
------------------------------------------------------------------------
-- INCREMENTAL λ-CALCULUS
--
-- Terms that operate on changes (Fig. 3).
------------------------------------------------------------------------
import Parametric.Syntax.Type as Type
import Parametric.Syntax.Term as Term
import Parametric.Change.Type as ChangeType
module Parametric.Change.Term
{Base : Set}
(Const : Term.Structure Base)
(ΔBase : ChangeType.Structure Base)
where
-- Terms that operate on changes
open Type.Structure Base
open Term.Structure Base Const
open ChangeType.Structure Base ΔBase
open import Data.Product
-- Extension point 1: A term for ⊝ on base types.
DiffStructure : Set
DiffStructure = ∀ {ι Γ} → Term Γ (base ι ⇒ base ι ⇒ ΔBase ι)
-- Extension point 2: A term for ⊕ on base types.
ApplyStructure : Set
ApplyStructure = ∀ {ι Γ} → Term Γ (ΔType (base ι) ⇒ base ι ⇒ base ι)
-- Extension point 3: A term for 0 on base types.
NilStructure : Set
NilStructure = ∀ {ι Γ} → Term Γ (base ι ⇒ ΔBase ι)
module Structure
(apply-base : ApplyStructure)
(diff-base : DiffStructure)
(nil-base : NilStructure)
where
-- g ⊝ f = λ x . λ Δx . g (x ⊕ Δx) ⊝ f x
-- f ⊕ Δf = λ x . f x ⊕ Δf x (x ⊝ x)
-- We provide: terms for ⊕ and ⊝ on arbitrary types.
apply-term : ∀ {τ Γ} → Term Γ (ΔType τ ⇒ τ ⇒ τ)
diff-term : ∀ {τ Γ} → Term Γ (τ ⇒ τ ⇒ ΔType τ)
nil-term : ∀ {τ Γ} → Term Γ (τ ⇒ ΔType τ)
apply-term {base ι} = apply-base
apply-term {σ ⇒ τ} =
let
_⊕τ_ = λ {Γ} t Δt → app₂ (apply-term {τ} {Γ}) Δt t
nil-σ = λ {Γ} t → app (nil-term {σ} {Γ}) t
in
absV 3 (λ Δh h y → app h y ⊕τ app (app Δh y) (nil-σ y))
diff-term {base ι} = diff-base
diff-term {σ ⇒ τ} =
let
_⊝τ_ = λ {Γ} s t → app₂ (diff-term {τ} {Γ}) s t
_⊕σ_ = λ {Γ} t Δt → app₂ (apply-term {σ} {Γ}) Δt t
in
absV 4 (λ g f x Δx → app g (x ⊕σ Δx) ⊝τ app f x)
nil-term {base ι} = nil-base
nil-term {σ ⇒ τ} =
-- What I'd usually write:
--absV 1 (λ f → app₂ diff-term f f)
-- What I wrote in fact:
let
_⊝τ_ = λ {Γ} s t → app₂ (diff-term {τ} {Γ}) s t
_⊕σ_ = λ {Γ} t Δt → app₂ (apply-term {σ} {Γ}) Δt t
in
absV 1 (λ ff → app (absV 3 (λ f x Δx → app f (x ⊕σ Δx) ⊝τ app f x)) ff)
-- This simplified a lot proving meaning-onil by reusing meaning-⊝.
--
-- The reason is that the extra lambda-abstraction ensures that f is pushed
-- twice in the environment.
apply : ∀ τ {Γ} →
Term Γ (ΔType τ) → Term Γ τ →
Term Γ τ
apply _ = app₂ apply-term
diff : ∀ τ {Γ} →
Term Γ τ → Term Γ τ →
Term Γ (ΔType τ)
diff _ = app₂ diff-term
onil₍_₎ : ∀ τ {Γ} →
Term Γ τ →
Term Γ (ΔType τ)
onil₍ _ ₎ = app nil-term
infixl 6 apply diff
syntax apply τ x Δx = Δx ⊕₍ τ ₎ x
syntax diff τ x y = x ⊝₍ τ ₎ y
infixl 6 _⊕_ _⊝_
_⊕_ : ∀ {τ Γ} →
Term Γ (ΔType τ) → Term Γ τ →
Term Γ τ
_⊕_ {τ} = apply τ
_⊝_ : ∀ {τ Γ} →
Term Γ τ → Term Γ τ →
Term Γ (ΔType τ)
_⊝_ {τ} = diff τ
onil : ∀ {τ Γ} →
Term Γ τ →
Term Γ (ΔType τ)
onil {τ} = onil₍ τ ₎
| {
"alphanum_fraction": 0.5365539452,
"avg_line_length": 26.313559322,
"ext": "agda",
"hexsha": "b10e3f2c9621b33ca34bcdd5cb3473c71e45c797",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "inc-lc/ilc-agda",
"max_forks_repo_path": "Parametric/Change/Term.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "inc-lc/ilc-agda",
"max_issues_repo_path": "Parametric/Change/Term.agda",
"max_line_length": 79,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "inc-lc/ilc-agda",
"max_stars_repo_path": "Parametric/Change/Term.agda",
"max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z",
"num_tokens": 1190,
"size": 3105
} |
{-# OPTIONS --cubical --safe #-}
module Data.List.Sugar where
open import Data.List.Base
open import Prelude
[_] : A → List A
[ x ] = x ∷ []
pure : A → List A
pure = [_]
_>>=_ : List A → (A → List B) → List B
_>>=_ = flip concatMap
_>>_ : List A → List B → List B
xs >> ys = xs >>= const ys
_<*>_ : List (A → B) → List A → List B
fs <*> xs = do
f ← fs
x ← xs
[ f x ]
guard : Bool → List ⊤
guard false = []
guard true = [ tt ]
liftA2 : (A → B → C) → List A → List B → List C
liftA2 {A = A} {B = B} {C = C} f xs ys = go xs
where
go′ : A → List A → List B → List C
go : List A → List C
go′ x xs [] = go xs
go′ x xs (y ∷ ys) = f x y ∷ go′ x xs ys
go [] = []
go (x ∷ xs) = go′ x xs ys
| {
"alphanum_fraction": 0.4985955056,
"avg_line_length": 17.3658536585,
"ext": "agda",
"hexsha": "71a55194d872120a87d5fce49ba57c0bfe0af34a",
"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/List/Sugar.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/List/Sugar.agda",
"max_line_length": 47,
"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/List/Sugar.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": 283,
"size": 712
} |
module DCBSets where
open import prelude
open import relations
-- The objects:
Obj : Set₁
Obj = Σ[ U ∈ Set ] (Σ[ X ∈ Set ] (Σ[ x ∈ (⊤ → X) ] (Σ[ d ∈ (X × X → X) ](Σ[ α ∈ (U → X → Set) ](
(∀{u : U}{x₁ x₂ : X} → α u (d (x₁ , x₂)) → ((α u x₁) × (α u x₂))) ×
( ∀{Y : Set}{x' : X}{F : Y → X}{y : ⊤ → Y} → d (x' , F (y triv)) ≡ x' ) ×
( ∀{Y : Set}{x' : X}{F : Y → X}{y : ⊤ → Y} → d (F (y triv) , x') ≡ x' ))))))
-- The morphisms:
Hom : Obj → Obj → Set
Hom (U , X , x , d₁ , α , p₁ ) (V , Y , y , d₂ , β , p₂) =
Σ[ f ∈ (U → V) ]
(Σ[ F ∈ (U → Y → X) ] ((∀{u : U}{y : Y} → α u (F u y) → β (f u) y)))
-- Composition:
comp : {A B C : Obj} → Hom A B → Hom B C → Hom A C
comp {(U , X , x , d₁ , α , dec₁ , p₁ , p₂)} {(V , Y , y , d₂ , β , dec₂ , p₃ , p₄)} {(W , Z , z , d₃ , γ , dec₃ , p₅ , p₆)} (f , F , q₁) (g , G , q₂) =
g ∘ f , (((λ u z' → F u (G (f u) z'))) ) , (λ {u} {z'} r → q₂ (q₁ r))
infixl 5 _○_
_○_ = comp
-- The contravariant hom-functor:
Homₐ : {A' A B B' : Obj} → Hom A' A → Hom B B' → Hom A B → Hom A' B'
Homₐ f h g = comp f (comp g h)
-- The identity function:
id : {A : Obj} → Hom A A
id {(U , V , n , d , α , p)} = (id-set , curry snd , id-set)
-- In this formalization we will only worry about proving that the
-- data of morphisms are equivalent, and not worry about the morphism
-- conditions. This will make proofs shorter and faster.
--
-- If we have parallel morphisms (f,F) and (g,G) in which we know that
-- f = g and F = G, then the condition for (f,F) will imply the
-- condition of (g,G) and vice versa. Thus, we can safely ignore it.
infix 4 _≡h_
_≡h_ : {A B : Obj} → (f g : Hom A B) → Set
_≡h_ {(U , X , _ , _ , _ , _ , _ , _)}{(V , Y , _ , β , _ , _ , _ , _)} (f , F , p₁) (g , G , p₂) = f ≡ g × F ≡ G
≡h-refl : {A B : Obj}{f : Hom A B} → f ≡h f
≡h-refl {U , X , _ , α , _ , _ , _ , _}{V , Y , _ , β , _ , _ , _ , _}{f , F , _} = refl , refl
≡h-trans : ∀{A B}{f g h : Hom A B} → f ≡h g → g ≡h h → f ≡h h
≡h-trans {U , X , _ , α , _ , _ , _ , _}{V , Y , _ , β , _ , _ , _ , _}{f , F , _}{g , G , _}{h , H , _} (p₁ , p₂) (p₃ , p₄) rewrite p₁ | p₂ | p₃ | p₄ = refl , refl
≡h-sym : ∀{A B}{f g : Hom A B} → f ≡h g → g ≡h f
≡h-sym {U , X , _ , α , _ , _ , _ , _}{V , Y , _ , β , _ , _ , _ , _}{f , F , _}{g , G , _} (p₁ , p₂) rewrite p₁ | p₂ = refl , refl
≡h-subst-○ : ∀{A B C}{f₁ f₂ : Hom A B}{g₁ g₂ : Hom B C}{j : Hom A C}
→ f₁ ≡h f₂
→ g₁ ≡h g₂
→ f₂ ○ g₂ ≡h j
→ f₁ ○ g₁ ≡h j
≡h-subst-○ {U , X , _ , α , _ , _ , _ , _}
{V , Y , _ , β , _ , _ , _ , _}
{W , Z , _ , γ , _ , _ , _ , _}
{f₁ , F₁ , _}
{f₂ , F₂ , _}
{g₁ , G₁ , _}
{g₂ , G₂ , _}
{j , J , _}
(p₅ , p₆) (p₇ , p₈) (p₉ , p₁₀) rewrite p₅ | p₆ | p₇ | p₈ | p₉ | p₁₀ = refl , refl
○-assoc : ∀{A B C D}{f : Hom A B}{g : Hom B C}{h : Hom C D}
→ f ○ (g ○ h) ≡h (f ○ g) ○ h
○-assoc {U , X , _ , α , _ , _ , _ , _}{V , Y , _ , β , _ , _ , _ , _}{W , Z , _ , γ , _ , _ , _ , _}{S , T , _ , ι , _ , _ , _ , _}
{f , F , _}{g , G , _}{h , H , _} = refl , refl
○-idl : ∀{A B}{f : Hom A B} → id ○ f ≡h f
○-idl {U , X , _ , _ , _ , _ , _ , _}{V , Y , _ , _ , _ , _ , _ , _}{f , F , _} = refl , refl
○-idr : ∀{A B}{f : Hom A B} → f ○ id ≡h f
○-idr {U , X , _ , _ , _ , _ , _ , _}{V , Y , _ , _ , _ , _ , _ , _}{f , F , _} = refl , refl
-- The tensor functor: ⊗
_⊗ᵣ_ : ∀{U X V Y : Set} → (U → X → Set) → (V → Y → Set) → ((U × V) → (X × Y) → Set)
_⊗ᵣ_ α β (u , v) (x , y) = (α u x) × (β v y)
_⊗ₒ_ : (A B : Obj) → Obj
(U , X , n₁ , d₁ , α , pr₁ , q₁ , q₂ ) ⊗ₒ (V , Y , n₂ , d₂ , β , pr₂ , q₃ , q₄) = ((U × V) , (X × Y) , trans-× n₁ n₂ , d⊗ , (α ⊗ᵣ β) , pr⊗ , ((λ {Y x' F y} → q₁⊗ {Y} {x'}{F}{y}) , (λ {Y x' F y} → q₂⊗ {Y} {x'}{F}{y})))
where
d⊗ : Σ (Σ X (λ x → Y)) (λ x → Σ X (λ x₁ → Y)) → Σ X (λ x → Y)
d⊗ ((x , y) , (x' , y')) = d₁ (x , x') , d₂ (y , y')
pr⊗ : {u : Σ U (λ x → V)} {x₁ x₂ : Σ X (λ x → Y)} → (α ⊗ᵣ β) u (d⊗ (x₁ , x₂)) → Σ ((α ⊗ᵣ β) u x₁) (λ x → (α ⊗ᵣ β) u x₂)
pr⊗ {u , v}{x , y}{x' , y'} (p , p') = (fst (pr₁ p) , fst (pr₂ p')) , snd (pr₁ p) , snd (pr₂ p')
q₁⊗ : {Y₁ : Set} {x' : Σ X (λ x → Y)} {F : Y₁ → Σ X (λ x → Y)}{y : ⊤ → Y₁} → d⊗ (x' , F (y triv)) ≡ x'
q₁⊗ {_}{x , y}{F}{p} with q₁ {x' = x}{fst ∘ F}{p} | q₃ {x' = y}{snd ∘ F}{p}
... | q'₁ | q'₂ with F (p triv)
... | x' , y' rewrite q'₁ | q'₂ = refl
q₂⊗ : {Y₁ : Set} {x' : Σ X (λ x → Y)} {F : Y₁ → Σ X (λ x → Y)}{y : ⊤ → Y₁} → d⊗ (F (y triv) , x') ≡ x'
q₂⊗ {Y}{x , y}{F}{p} with q₂ {_}{x}{fst ∘ F}{p} | q₄ {_}{y}{snd ∘ F}{p}
... | q'₁ | q'₂ with F (p triv)
... | x' , y' rewrite q'₁ | q'₂ = refl
F⊗ : ∀{Z T V X U Y : Set}{F : U → Z → X}{G : V → T → Y} → (U × V) → (Z × T) → (X × Y)
F⊗ {F = F}{G} (u , v) (z , t) = F u z , G v t
_⊗ₐ_ : {A B C D : Obj} → Hom A C → Hom B D → Hom (A ⊗ₒ B) (C ⊗ₒ D)
_⊗ₐ_ {(U , X , _ , _ , α , _ , _ , _)}{(V , Y , _ , _ , β , _ , _ , _)}{(W , Z , _ , _ , γ , _ , _ , _)}{(S , T , _ , _ , δ , _ , _ , _)} (f , F , p₁) (g , G , p₂) = ⟨ f , g ⟩ , F⊗ {F = F}{G} , p⊗
where
p⊗ : {u : Σ U (λ x → V)} {y : Σ Z (λ x → T)} → (α ⊗ᵣ β) u (F⊗ {F = F}{G} u y) → (γ ⊗ᵣ δ) (⟨ f , g ⟩ u) y
p⊗ {u , v}{z , t} (p₃ , p₄) = p₁ p₃ , p₂ p₄
π₁ : {A B : Obj} → Hom (A ⊗ₒ B) A
π₁ {U , X , n₁ , _ , α , _ , _ , _}{V , Y , n₂ , _ , β , _ , _ , _} = fst , (λ r x → x , n₂ triv) , cond
where
cond : {u : Σ U (λ x → V)} {y : X} → (α ⊗ᵣ β) u (y , n₂ triv) → α (fst u) y
cond {u , v}{x} (p₁ , p₂) = p₁
π₂ : {A B : Obj} → Hom (A ⊗ₒ B) B
π₂ {U , X , n₁ , _ , α , _ , _ , _}{V , Y , n₂ , _ , β , _ , _ , _} = snd , (λ r y → n₁ triv , y) , cond
where
cond : {u : Σ U (λ x → V)} {y : Y} → (α ⊗ᵣ β) u (n₁ triv , y) → β (snd u) y
cond {u , v}{y} (p₁ , p₂) = p₂
cart-ar : {A B C : Obj}
→ (f : Hom C A)
→ (g : Hom C B)
→ Hom C (A ⊗ₒ B)
cart-ar {U , X , x , d₁ , α , pr₁ , q₁ , q₂}{V , Y , y , d₂ , β , pr₂ , q₃ , q₄}{W , Z , z , d₃ , γ , pr₃ , q₅ , q₆} (f , F , p₁) (g , G , p₂) = trans-× f g , crt , cond
where
crt : W → Σ X (λ x₁ → Y) → Z
crt w (x' , y') = d₃ ((F w x') , (G w y'))
cond : {u : W} {y₁ : Σ X (λ x₁ → Y)} → γ u (crt u y₁) → (α ⊗ᵣ β) (f u , g u) y₁
cond {w}{x' , y'} p = p₁ (fst (pr₃ {w}{F w x'}{G w y'} p)) , p₂ (snd (pr₃ {w}{F w x'}{G w y'} p))
cart-diag₁ : ∀{A B C : Obj}
→ {f : Hom C A}
→ {g : Hom C B}
→ (cart-ar f g) ○ π₁ ≡h f
cart-diag₁ {U , X , x , d₁ , α , pr₁ , q₁ , q₂}{V , Y , y , d₂ , β , q₃ , q₄ , q₅}{W , Z , z , d₃ , γ , q₆ , q₇ , q₈}{f , F , p₁}{g , G , p₂} = refl , ext-set (λ {w} → ext-set (λ {x} → q₇ {x' = F w x}{G w}{y}))
cart-diag₂ : ∀{A B C : Obj}
→ {f : Hom C A}
→ {g : Hom C B}
→ (cart-ar f g) ○ π₂ ≡h g
cart-diag₂ {U , X , x , d₁ , α , pr₁ , q₁ , q₂}{V , Y , y , d₂ , β , q₃ , q₄ , q₅}{W , Z , z , d₃ , γ , q₆ , q₇ , q₈}{f , F , p₁}{g , G , p₂} = refl , ext-set (λ {w} → ext-set (λ {y₁} → q₈ {x' = G w y₁}{F w}{x}))
-- The □-comonad:
□ₒ-cond : ∀{U X : Set} → (α : U → X → Set) → U → 𝕃 X → Set
□ₒ-cond {U}{X} α u [] = ⊤
□ₒ-cond {U}{X} α u (x :: xs) = (α u x) × (□ₒ-cond α u xs)
□ₒ-cond-++ : ∀{U X : Set}{α : U → X → Set}{u : U}{l₁ l₂ : 𝕃 X}
→ □ₒ-cond α u (l₁ ++ l₂) ≡ ((□ₒ-cond α u l₁) × (□ₒ-cond α u l₂))
□ₒ-cond-++ {U}{X}{α}{u}{[]}{l₂} = ∧-unit
□ₒ-cond-++ {U}{X}{α}{u}{x :: xs}{l₂} rewrite □ₒ-cond-++ {U}{X}{α}{u}{xs}{l₂} = ∧-assoc
□ₒ : Obj → Obj
□ₒ (U , X , x , d , α , pr , q₁ , q₂) = U , X * , (λ t → [ x t ]) , □d , □ₒ-cond {U}{X} α , {!!} , {!!} , {!!}
where
□d : (X *) × (X *) → X *
□d (l₁ , l₂) = l₁ ++ l₂
-- □pr : {u : U} {x₁ x₂ : 𝕃 X}
-- → □ₒ-cond α u (□d (x₁ , x₂))
-- → Σ (□ₒ-cond α u x₁) (λ x₃ → □ₒ-cond α u x₂)
-- □pr {_}{[]} {[]} x₁ = triv , triv
-- □pr {u}{x₁ = []} {x₁ :: x₂} (a , b) = triv , snd (pr a) , snd (□pr {u}{[]}{x₂} b)
-- □pr {u}{x₁ = x₁ :: x₂} {[]} (a , b) = (fst (pr a) , fst (□pr {u}{x₂}{[]} b)) , triv
-- □pr {_}{x₁ :: x₂} {x₃ :: x₄} (a , b) with pr a
-- ... | c , e with □pr {x₁ = x₂} b
-- ... | f , g = (c , f) , (e , g)
□q₁ : {Y : Set} {x' : 𝕃 X} {F : Y → 𝕃 X} {y : ⊤ → Y} → □d (x' , F (y triv)) ≡ x'
□q₁ {x' = []}{F}{y} = {!!}
□q₁ {x' = x₁ :: x'}{F}{y} with F (y triv)
... | [] = {!!}
... | a :: as = {!!}
{-
□ₐ-s : ∀{U Y X : Set}
→ (U → Y → X)
→ (U → Y * → X *)
□ₐ-s f u l = map (f u) l
□ₐ : {A B : Obj} → Hom A B → Hom (□ₒ A) (□ₒ B)
□ₐ {U , X , α}{V , Y , β} (f , F , p) = f , (□ₐ-s F , aux)
where
aux : {u : U} {y : 𝕃 Y} → □ₒ-cond α u (□ₐ-s F u y) → □ₒ-cond β (f u) y
aux {u}{[]} p₁ = triv
aux {u}{y :: ys} (p₁ , p₂) = p p₁ , aux p₂
-- Of-course is a comonad:
ε : ∀{A} → Hom (□ₒ A) A
ε {U , X , α} = id-set , (λ u x → [ x ]) , fst
δ-s : {U X : Set} → U → 𝕃 (𝕃 X) → 𝕃 X
δ-s u xs = foldr _++_ [] xs
δ : ∀{A} → Hom (□ₒ A) (□ₒ (□ₒ A))
δ {U , X , α} = id-set , δ-s , cond
where
cond : {u : U} {y : 𝕃 (𝕃 X)} → □ₒ-cond α u (foldr _++_ [] y) → □ₒ-cond (□ₒ-cond α) u y
cond {u}{[]} p = triv
cond {u}{l :: ls} p with □ₒ-cond-++ {U}{X}{α}{u}{l}{foldr _++_ [] ls}
... | p' rewrite p' with p
... | p₂ , p₃ = p₂ , cond {u}{ls} p₃
comonand-diag₁ : ∀{A}
→ (δ {A}) ○ (□ₐ (δ {A})) ≡h (δ {A}) ○ (δ { □ₒ A})
comonand-diag₁ {U , X , α} = refl , ext-set (λ {x} → ext-set (λ {l} → aux {x} {l}))
where
aux : ∀{x : U}{l : 𝕃 (𝕃 (𝕃 X))}
→ foldr _++_ [] (□ₐ-s (λ u xs
→ foldr _++_ [] xs) x l) ≡ foldr _++_ [] (foldr _++_ [] l)
aux {u}{[]} = refl
aux {u}{x :: xs} rewrite aux {u}{xs} = foldr-append {_}{_}{X}{X}{x}{foldr _++_ [] xs}
comonand-diag₂ : ∀{A}
→ (δ {A}) ○ (ε { □ₒ A}) ≡h (δ {A}) ○ (□ₐ (ε {A}))
comonand-diag₂ {U , X , α} =
refl , ext-set (λ {u} → ext-set (λ {l} → aux {l}))
where
aux : ∀{a : 𝕃 X} → a ++ [] ≡ foldr _++_ [] (map (λ x → x :: []) a)
aux {[]} = refl
aux {x :: xs} rewrite (++[] xs) | sym (foldr-map {_}{X}{xs}) = refl
-}
| {
"alphanum_fraction": 0.3797442244,
"avg_line_length": 39.4146341463,
"ext": "agda",
"hexsha": "57de82bb317950f59abe43b9dc83a7e74c9bda68",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "heades/AUGL",
"max_forks_repo_path": "dialectica-cats/DCBSets.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "heades/AUGL",
"max_issues_repo_path": "dialectica-cats/DCBSets.agda",
"max_line_length": 218,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "heades/AUGL",
"max_stars_repo_path": "dialectica-cats/DCBSets.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5280,
"size": 9696
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some derivable properties
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Algebra
module Algebra.Properties.Semilattice {c ℓ} (L : Semilattice c ℓ) where
open Semilattice L
open import Algebra.Structures
open import Function
open import Data.Product
open import Relation.Binary
open import Relation.Binary.Reasoning.Setoid setoid
import Relation.Binary.Construct.NaturalOrder.Left _≈_ _∧_ as LeftNaturalOrder
open import Relation.Binary.Lattice
import Relation.Binary.Properties.Poset as PosetProperties
open import Relation.Binary.Reasoning.Setoid setoid
------------------------------------------------------------------------
-- Every semilattice can be turned into a poset via the left natural
-- order.
poset : Poset c ℓ ℓ
poset = LeftNaturalOrder.poset isSemilattice
open Poset poset using (_≤_; isPartialOrder)
open PosetProperties poset using (_≥_; ≥-isPartialOrder)
------------------------------------------------------------------------
-- Every algebraic semilattice can be turned into an order-theoretic one.
∧-isOrderTheoreticMeetSemilattice : IsMeetSemilattice _≈_ _≤_ _∧_
∧-isOrderTheoreticMeetSemilattice = record
{ isPartialOrder = isPartialOrder
; infimum = LeftNaturalOrder.infimum isSemilattice
}
∧-isOrderTheoreticJoinSemilattice : IsJoinSemilattice _≈_ _≥_ _∧_
∧-isOrderTheoreticJoinSemilattice = record
{ isPartialOrder = ≥-isPartialOrder
; supremum = IsMeetSemilattice.infimum
∧-isOrderTheoreticMeetSemilattice
}
∧-orderTheoreticMeetSemilattice : MeetSemilattice c ℓ ℓ
∧-orderTheoreticMeetSemilattice = record
{ isMeetSemilattice = ∧-isOrderTheoreticMeetSemilattice
}
∧-orderTheoreticJoinSemilattice : JoinSemilattice c ℓ ℓ
∧-orderTheoreticJoinSemilattice = record
{ isJoinSemilattice = ∧-isOrderTheoreticJoinSemilattice
}
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 1.1
isOrderTheoreticMeetSemilattice = ∧-isOrderTheoreticMeetSemilattice
{-# WARNING_ON_USAGE isOrderTheoreticMeetSemilattice
"Warning: isOrderTheoreticMeetSemilattice was deprecated in v1.1.
Please use ∧-isOrderTheoreticMeetSemilattice instead."
#-}
isOrderTheoreticJoinSemilattice = ∧-isOrderTheoreticJoinSemilattice
{-# WARNING_ON_USAGE isOrderTheoreticJoinSemilattice
"Warning: isOrderTheoreticJoinSemilattice was deprecated in v1.1.
Please use ∧-isOrderTheoreticJoinSemilattice instead."
#-}
orderTheoreticMeetSemilattice = ∧-orderTheoreticMeetSemilattice
{-# WARNING_ON_USAGE orderTheoreticMeetSemilattice
"Warning: orderTheoreticMeetSemilattice was deprecated in v1.1.
Please use ∧-orderTheoreticMeetSemilattice instead."
#-}
orderTheoreticJoinSemilattice = ∧-orderTheoreticJoinSemilattice
{-# WARNING_ON_USAGE orderTheoreticJoinSemilattice
"Warning: orderTheoreticJoinSemilattice was deprecated in v1.1.
Please use ∧-orderTheoreticJoinSemilattice instead."
#-}
| {
"alphanum_fraction": 0.6971569839,
"avg_line_length": 35.9555555556,
"ext": "agda",
"hexsha": "e95994e4507da2f6b8e550eebefac116880f2efb",
"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/Properties/Semilattice.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/Properties/Semilattice.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/Properties/Semilattice.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": 837,
"size": 3236
} |
open import Nat
open import Prelude
open import core
open import contexts
open import preservation
module complete-preservation where
-- if you substitute a complete term into a complete term, the result is
-- still complete.
cp-subst : ∀ {x d1 d2} →
d1 dcomplete →
d2 dcomplete →
([ d2 / x ] d1) dcomplete
cp-subst {x = y} (DCVar {x = x}) dc2 with natEQ x y
cp-subst DCVar dc2 | Inl refl = dc2
cp-subst DCVar dc2 | Inr x₂ = DCVar
cp-subst DCConst dc2 = DCConst
cp-subst {x = x} (DCLam {x = y} dc1 x₂) dc2 with natEQ y x
cp-subst (DCLam dc1 x₃) dc2 | Inl refl = DCLam dc1 x₃
cp-subst (DCLam dc1 x₃) dc2 | Inr x₂ = DCLam (cp-subst dc1 dc2) x₃
cp-subst (DCAp dc1 dc2) dc3 = DCAp (cp-subst dc1 dc3) (cp-subst dc2 dc3)
cp-subst (DCCast dc1 x₁ x₂) dc2 = DCCast (cp-subst dc1 dc2) x₁ x₂
-- this just lets me pull the particular x out of a derivation; it's not
-- bound in any of the constructors explicitly since it's only in the
-- lambda case; so below i have no idea how else to get a name for it,
-- instead of leaving it dotted in the context
lem-proj : {x : Nat} {d : ihexp} { τ : htyp} → (·λ_[_]_ x τ d) dcomplete → Σ[ y ∈ Nat ] (y == x)
lem-proj {x} (DCLam dc x₁) = x , refl
-- a complete well typed term steps to a complete term.
cp-rhs : ∀{d τ d' Δ} →
d dcomplete →
Δ , ∅ ⊢ d :: τ →
d ↦ d' →
d' dcomplete
cp-rhs dc TAConst (Step FHOuter () FHOuter)
cp-rhs dc (TAVar x₁) stp = abort (somenotnone (! x₁))
cp-rhs dc (TALam _ wt) (Step FHOuter () FHOuter)
-- this case is a little more complicated than it feels like it ought to
-- be, just from horsing around with agda implicit variables.
cp-rhs (DCAp dc dc₁) (TAAp wt wt₁) (Step FHOuter ITLam FHOuter) with lem-proj dc
cp-rhs (DCAp dc dc₁) (TAAp wt wt₁) (Step FHOuter ITLam FHOuter) | x , refl with cp-subst {x = x} dc dc₁
... | qq with natEQ x x
cp-rhs (DCAp dc dc₁) (TAAp wt wt₁) (Step FHOuter ITLam FHOuter) | x , refl | DCLam qq x₁ | Inl refl = cp-subst qq dc₁
cp-rhs (DCAp dc dc₁) (TAAp wt wt₁) (Step FHOuter ITLam FHOuter) | x , refl | qq | Inr x₁ = abort (x₁ refl)
cp-rhs (DCAp (DCCast dc (TCArr x x₁) (TCArr x₂ x₃)) dc₁) (TAAp (TACast wt x₄) wt₁) (Step FHOuter ITApCast FHOuter) = DCCast (DCAp dc (DCCast dc₁ x₂ x)) x₁ x₃
cp-rhs (DCAp dc dc₁) (TAAp wt wt₁) (Step (FHAp1 x) x₁ (FHAp1 x₂)) = DCAp (cp-rhs dc wt (Step x x₁ x₂)) dc₁
cp-rhs (DCAp dc dc₁) (TAAp wt wt₁) (Step (FHAp2 x) x₁ (FHAp2 x₂)) = DCAp dc (cp-rhs dc₁ wt₁ (Step x x₁ x₂))
cp-rhs () (TAEHole x x₁) stp
cp-rhs () (TANEHole x wt x₁) stp
cp-rhs (DCCast dc x x₁) (TACast wt x₂) (Step FHOuter ITCastID FHOuter) = dc
cp-rhs (DCCast dc () x₁) (TACast wt x₂) (Step FHOuter (ITCastSucceed x₃) FHOuter)
cp-rhs (DCCast dc () x₁) (TACast wt x₂) (Step FHOuter (ITCastFail x₃ x₄ x₅) FHOuter)
cp-rhs (DCCast dc x ()) (TACast wt x₂) (Step FHOuter (ITGround x₃) FHOuter)
cp-rhs (DCCast dc () x₁) (TACast wt x₂) (Step FHOuter (ITExpand x₃) FHOuter)
cp-rhs (DCCast dc x x₁) (TACast wt x₂) (Step (FHCast x₃) x₄ (FHCast x₅)) = DCCast (cp-rhs dc wt (Step x₃ x₄ x₅)) x x₁
cp-rhs () (TAFailedCast wt x x₁ x₂) stp
-- this is the main result of this file.
complete-preservation : ∀{d τ d' Δ} →
binders-unique d →
d dcomplete →
Δ , ∅ ⊢ d :: τ →
d ↦ d' →
(Δ , ∅ ⊢ d' :: τ) × (d' dcomplete)
complete-preservation bd dc wt stp = preservation bd wt stp , cp-rhs dc wt stp
| {
"alphanum_fraction": 0.6253561254,
"avg_line_length": 51.6176470588,
"ext": "agda",
"hexsha": "9f1252e25754617f5716c71593cca25a753ed39a",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-09-13T18:20:02.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-09-13T18:20:02.000Z",
"max_forks_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_forks_repo_path": "complete-preservation.agda",
"max_issues_count": 54,
"max_issues_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_issues_repo_issues_event_max_datetime": "2018-11-29T16:32:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-06-29T20:53:34.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_issues_repo_path": "complete-preservation.agda",
"max_line_length": 159,
"max_stars_count": 16,
"max_stars_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_stars_repo_path": "complete-preservation.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-19T02:50:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-03-12T14:32:03.000Z",
"num_tokens": 1419,
"size": 3510
} |
module Structure.Sets.Names where
open import Data.Boolean
open import Data.Boolean.Stmt
open import Functional
import Lvl
open import Logic
open import Logic.Propositional
open import Logic.Predicate
open import Structure.Function
open import Structure.Relator
open import Structure.Setoid using (Equiv) renaming (_≡_ to _≡ₛ_ ; _≢_ to _≢ₛ_)
open import Type
open import Type.Properties.Inhabited
private variable ℓ ℓ₁ ℓ₂ ℓ₃ ℓ₄ ℓ₅ ℓ₆ ℓ₇ ℓ₈ ℓ₉ ℓ₁₀ ℓₑ ℓₑ₁ ℓₑ₂ ℓₑ₃ ℓₑₑ ℓₑₑₗ ℓₑₑᵣ ℓₑᵢ ℓₑₒ ℓₑₛ ℓₗ ℓₗ₁ ℓₗ₂ ℓₗ₃ ℓᵣ ℓₒ ℓᵣₑₗ ℓₛ : Lvl.Level
private variable A B C S S₁ S₂ Sₒ Sᵢ Sₗ Sᵣ E E₁ E₂ Eₗ Eᵣ I O : Type{ℓ}
private variable _∈ₒ_ _∈ᵢ_ : E → S → Stmt{ℓₗ}
private variable _∈ₗ_ : E → Sₗ → Stmt{ℓₗ}
private variable _∈ᵣ_ : E → Sᵣ → Stmt{ℓᵣ}
-- Derivable relation symbols from the subset relation.
module From-[⊆] (_⊆_ : Sₗ → Sᵣ → Stmt{ℓₗ}) where
-- Superset.
-- (A ⊇ B) means that every element in the set B is also in the set A (A contains the contents of B).
_⊇_ = swap(_⊆_)
-- Non-subset.
_⊈_ = (¬_) ∘₂ (_⊆_)
-- Non-superset.
_⊉_ = (¬_) ∘₂ (_⊇_)
-- Derivable relation symbols from two membership relations.
module From-[∈][∈] (_∈ₗ_ : E → Sₗ → Stmt{ℓₗ}) (_∈ᵣ_ : E → Sᵣ → Stmt{ℓᵣ}) where
-- Subset.
-- (A ⊆ B) means that every element in the set A is also in the set B (A is a part of B).
-- Alternative definition:
-- A ↦ B ↦ ∀ₗ(x ↦ ((_→ᶠ_) on₂ (x ∈_)) A B)
_⊆_ = \A B → ∀{x} → (x ∈ₗ A) → (x ∈ᵣ B)
-- Set equality.
-- (A ≡ B) means that the sets A and B contains the same elements.
_≡_ = \A B → ∀{x} → (x ∈ₗ A) ↔ (x ∈ᵣ B)
open From-[⊆] (_⊆_) public
-- Derivable relation symbols from the membership relation.
module From-[∈] (_∈_ : E → S → Stmt{ℓₗ}) where
-- Containment.
-- (a ∋ x) means that the set a contains the element x.
_∋_ = swap(_∈_)
-- Not element of.
_∉_ = (¬_) ∘₂ (_∈_)
-- Non-containment.
_∌_ = (¬_) ∘₂ (_∋_)
open From-[∈][∈] (_∈_)(_∈_) public
module From-[∋] (_∋_ : S → E → Stmt{ℓₗ}) where
_∈_ = swap(_∋_)
open From-[∈] (_∈_) hiding (_∋_) public
module Relations (_∈_ : E → S → Stmt{ℓₗ}) where
-- The property of a set being empty.
Empty : S → Type
Empty(s) = ∀ₗ(x ↦ ¬(x ∈ s))
-- The property of a set being non-empty.
NonEmpty : S → Type
NonEmpty(s) = ∃(_∈ s)
-- The property of a set being the universal set (containing all elements).
Universal : S → Type
Universal(s) = ∀ₗ(_∈ s)
-- The property of two sets being disjoint (not sharing any elements).
Disjoint : S → S → Type
Disjoint s₁ s₂ = ∀ₗ(x ↦ ((x ∈ s₁) → (x ∈ s₂) → ⊥))
module One (_∈_ : E → S → Stmt{ℓₗ}) where
open From-[∈] (_∈_)
-- The empty set containing no elements.
-- No elements are in the empty set.
-- Standard set notation: ∅ = {}.
EmptyMembership = \(∅)
→ ∀{x} → (x ∉ ∅)
-- The universal set containing all elements.
-- Every element is in the universal set.
-- Standard set notation: 𝐔 = {x. ⊤}.
UniversalMembership = \(𝐔)
→ ∀{x} → (x ∈ 𝐔)
module _ {I : Type{ℓ}} ⦃ equiv-I : Equiv{ℓₑᵢ}(I) ⦄ ⦃ equiv-E : Equiv{ℓₑₑ}(E) ⦄ where
-- The image of a function containing the elements that the function points to.
-- The elements of the form f(x) for any x.
-- Standard set notation: ⊶ f = {f(x). (x: I)}.
ImageMembership = \(⊶ : (f : I → E) → ⦃ func : Function(f) ⦄ → S)
→ ∀{f} ⦃ func : Function(f) ⦄ → ∀{y} → (y ∈ (⊶ f)) ↔ ∃(x ↦ f(x) ≡ₛ y)
module _ ⦃ equiv-E : Equiv{ℓₑₑ}(E) ⦄ {O : Type{ℓ}} ⦃ equiv-O : Equiv{ℓₑₒ}(O) ⦄ where
-- The fiber of a function together with one of its values containing the elements that point to this value.
-- Standard set notation: fiber f(y) = {x. f(x) ≡ y}
FiberMembership = \(fiber : (f : E → O) → ⦃ func : Function(f) ⦄ → (O → S))
→ ∀{f} ⦃ func : Function(f) ⦄ {y}{x} → (x ∈ fiber f(y)) ↔ (f(x) ≡ₛ y)
module _ ⦃ equiv-E : Equiv{ℓₑₑ}(E) ⦄ where
-- The singleton set of a single element containing only this element.
-- Standard set notation: singleton(x) = {x}
SingletonMembership = \(singleton : E → S)
→ ∀{y}{x} → (x ∈ singleton(y)) ↔ (x ≡ₛ y)
-- The pair set of two elements containing only the two elements.
-- Standard set notation: pair x y = {x,y}
PairMembership = \(pair : E → E → S)
→ ∀{y₁ y₂}{x} → (x ∈ pair y₁ y₂) ↔ ((x ≡ₛ y₁) ∨ (x ≡ₛ y₂))
module _ {ℓ} where
-- Set comprehension with a predicate containing all elements that satisfy this predicate.
-- Also called: Unrestricted set comprehension, set-builder notation.
-- Standard set notation: comp(P) = {x. P(x)}
ComprehensionMembership = \(comp : (P : E → Stmt{ℓ}) ⦃ unaryRelator : UnaryRelator(P) ⦄ → S)
→ ∀{P} ⦃ unaryRelator : UnaryRelator(P) ⦄ {x} → (x ∈ comp(P)) ↔ P(x)
open One public
module Two (_∈ₗ_ : E → Sₗ → Stmt{ℓₗ}) (_∈ᵣ_ : E → Sᵣ → Stmt{ℓᵣ}) where
private module Def = From-[∈][∈] (_∈ₗ_)(_∈ᵣ_)
SubsetMembership = \{ℓᵣₑₗ} (_⊆_ : Sₗ → Sᵣ → Stmt{ℓᵣₑₗ})
→ ∀{a b} → (a ⊆ b) ↔ (a Def.⊆ b)
SetEqualityMembership = \{ℓᵣₑₗ} (_≡_ : Sₗ → Sᵣ → Stmt{ℓᵣₑₗ})
→ ∀{a b} → (a ≡ b) ↔ (a Def.≡ b)
open Two public
module TwoSame (_∈ₗ_ : E → Sₗ → Stmt{ℓₗ}) (_∈ᵣ_ : E → Sᵣ → Stmt{ℓᵣ}) where
-- The set complement of a set containing all elements not in this set.
-- Standard set notation: ∁ A = {x. x ∉ A}
ComplementMembership = \(∁ : Sₗ → Sᵣ)
→ ∀{A}{x} → (x ∈ᵣ (∁ A)) ↔ ¬(x ∈ₗ A)
module _ ⦃ equiv-E : Equiv{ℓₑₑ}(E) ⦄ where
AddMembership = \(add : E → Sₗ → Sᵣ)
→ ∀{y}{a}{x} → (x ∈ᵣ add y a) ↔ ((x ∈ₗ a) ∨ (x ≡ₛ y))
RemoveMembership = \(remove : E → Sₗ → Sᵣ)
→ ∀{y}{a}{x} → (x ∈ᵣ remove y a) ↔ ((x ∈ₗ a) ∧ (x ≢ₛ y))
module _ {ℓ} where
-- The filtering of a set with a predicate containing all elements in the set that satisfy the predicate.
-- It is the subset where all elements satisfy the predicate.
-- Standard set notation: filter P(A) = {(x∊A). P(x)}
FilterMembership = \(filter : (P : E → Stmt{ℓ}) ⦃ unaryRelator : UnaryRelator(P) ⦄ → (Sₗ → Sᵣ))
→ ∀{A}{P} ⦃ unaryRelator : UnaryRelator(P) ⦄ {x} → (x ∈ᵣ filter P(A)) ↔ ((x ∈ₗ A) ∧ P(x))
-- The filtering of a set with a boolean predicate containing all elements in the set that satisfy the predicate.
-- Standard set notation: boolFilter P(A) = {(x∊A). P(x) ≡ 𝑇}
BooleanFilterMembership = \(boolFilter : (E → Bool) → (Sₗ → Sᵣ))
→ ∀{A}{P}{x} → (x ∈ᵣ boolFilter P(A)) ↔ ((x ∈ₗ A) ∧ IsTrue(P(x)))
IndexedBigUnionMembership = \{ℓ}{I : Type{ℓ}} (⋃ᵢ : (I → Sₗ) → Sᵣ)
→ ∀{Ai}{x} → (x ∈ᵣ (⋃ᵢ Ai)) ↔ ∃(i ↦ (x ∈ₗ Ai(i)))
IndexedBigIntersectionMembership = \{ℓ}{I : Type{ℓ}} (⋂ᵢ : (I → Sₗ) → Sᵣ)
→ ∀{Ai} → (◊ I) → ∀{x} → (x ∈ᵣ (⋂ᵢ Ai)) ↔ (∀{i} → (x ∈ₗ Ai(i)))
open TwoSame public
module TwoDifferent (_∈ₗ_ : Eₗ → Sₗ → Stmt{ℓₗ}) (_∈ᵣ_ : Eᵣ → Sᵣ → Stmt{ℓᵣ}) where
module _ ⦃ equiv-Eₗ : Equiv{ℓₑₑₗ}(Eₗ) ⦄ ⦃ equiv-Eᵣ : Equiv{ℓₑₑᵣ}(Eᵣ) ⦄ where
-- The image of a function and a set containing the elements that the function points to from the set (the domain is restricted to the set).
-- The elements of the form f(x) for any x in A.
-- Standard set notation: map f(A) = {f(x). x ∈ A}.
MapMembership = \(map : (f : Eₗ → Eᵣ) ⦃ func : Function(f) ⦄ → (Sₗ → Sᵣ))
→ ∀{f} ⦃ func : Function(f) ⦄ {A}{y} → (y ∈ᵣ map f(A)) ↔ ∃(x ↦ (x ∈ₗ A) ∧ (f(x) ≡ₛ y))
-- The inverse image of a function together with a set containing the elements that point to elements in the set.
-- Standard set notation: unmap f(A) = {x. f(x) ∈ A}
UnmapMembership = \(unmap : (f : Eₗ → Eᵣ) ⦃ func : Function(f) ⦄ → (Sᵣ → Sₗ))
→ ∀{f} ⦃ func : Function(f) ⦄ {A}{x} → (x ∈ₗ unmap f(A)) ↔ (f(x) ∈ᵣ A)
open TwoDifferent public
module Three (_∈ₗ_ : E → Sₗ → Stmt{ℓₗ}) (_∈ᵣ_ : E → Sᵣ → Stmt{ℓᵣ}) (_∈ₒ_ : E → Sₒ → Stmt{ℓₒ}) where
-- The union of two sets containing the elements that are in at least one of the sets.
-- Standard set notation: A ∪ B = {x. (x ∈ A) ∨ (x ∈ B)}
UnionMembership = \(_∪_ : Sₗ → Sᵣ → Sₒ)
→ (∀{A B}{x} → (x ∈ₒ (A ∪ B)) ↔ ((x ∈ₗ A) ∨ (x ∈ᵣ B)))
-- The intersection of two sets containing the elements that are in at both of the sets.
-- Standard set notation: A ∪ B = {x. (x ∈ A) ∨ (x ∈ B)}
IntersectMembership = \(_∩_ : Sₗ → Sᵣ → Sₒ)
→ (∀{A B}{x} → (x ∈ₒ (A ∩ B)) ↔ ((x ∈ₗ A) ∧ (x ∈ᵣ B)))
-- The relative complement of two sets containing the elements that are in the left set but not in the right.
-- Standard set notation: A ∖ B = {x. (x ∈ A) ∧ (x ∉ B)}
WithoutMembership = \(_∖_ : Sₗ → Sᵣ → Sₒ)
→ (∀{A B}{x} → (x ∈ₒ (A ∖ B)) ↔ ((x ∈ₗ A) ∧ ¬(x ∈ᵣ B)))
open Three public
module ThreeNestedTwoDifferent (_∈ₒ_ : Sₗ → Sₒ → Stmt{ℓₒ}) where
module _ (_⊆_ : Sₗ → Sᵣ → Stmt{ℓₛ}) where
-- The power set of a set containing all subsets of a set.
-- Standard set notation: ℘(y) = {x. x ⊆ y}
PowerMembership = \(℘ : Sᵣ → Sₒ)
→ ∀{y}{x} → (x ∈ₒ ℘(y)) ↔ (x ⊆ y)
open ThreeNestedTwoDifferent public
module ThreeTwoNested (_∈ₗ_ : E → Sₗ → Stmt{ℓₗ}) (_∈ᵣ_ : Sₗ → Sᵣ → Stmt{ℓᵣ}) (_∈ₒ_ : E → Sₒ → Stmt{ℓₒ}) where
BigUnionMembership = \(⋃ : Sᵣ → Sₒ)
→ ∀{A}{x} → (x ∈ₒ (⋃ A)) ↔ ∃(a ↦ (a ∈ᵣ A) ∧ (x ∈ₗ a))
BigIntersectionMembership = \(⋂ : Sᵣ → Sₒ)
→ ∀{A} → ∃(_∈ᵣ A) → ∀{x} → (x ∈ₒ (⋂ A)) ↔ (∀{a} → (a ∈ᵣ A) → (x ∈ₗ a))
BigIntersectionMembershipWithEmpty = \(⋂ : Sᵣ → Sₒ)
→ ∀{A}{x} → (x ∈ₒ (⋂ A)) ↔ ∃(a ↦ (a ∈ᵣ A) ∧ (x ∈ₗ a)) ∧ (∀{a} → (a ∈ᵣ A) → (x ∈ₗ a))
BigIntersectionMembershipWithUniversal = \(⋂ : Sᵣ → Sₒ)
→ ∀{A}{x} → (x ∈ₒ (⋂ A)) ↔ (∀{a} → (a ∈ᵣ A) → (x ∈ₗ a))
open ThreeTwoNested public
| {
"alphanum_fraction": 0.5348790726,
"avg_line_length": 45.8990825688,
"ext": "agda",
"hexsha": "bf48667ec8f738e7b377815a4b998718ac6bd98e",
"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/Sets/Names.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/Sets/Names.agda",
"max_line_length": 144,
"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/Sets/Names.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": 4160,
"size": 10006
} |
data Nat : Set where
Zero : Nat
Suc : Nat → Nat
{-# COMPILE AGDA2HS Nat #-}
Nat' = Nat
{-# COMPILE AGDA2HS Nat' #-}
myNat : Nat'
myNat = Suc (Suc Zero)
{-# COMPILE AGDA2HS myNat #-}
data List (a : Set) : Set where
Nil : List a
Cons : a → List a → List a
{-# COMPILE AGDA2HS List #-}
List' : Set → Set
List' a = List a
{-# COMPILE AGDA2HS List' #-}
NatList = List Nat
{-# COMPILE AGDA2HS NatList #-}
myListFun : List' Nat' → NatList
myListFun Nil = Nil
myListFun (Cons x xs) = Cons x (myListFun xs)
{-# COMPILE AGDA2HS myListFun #-}
ListList : Set → Set
ListList a = List (List a)
{-# COMPILE AGDA2HS ListList #-}
flatten : ∀ {a} → ListList a → List a
flatten Nil = Nil
flatten (Cons Nil xss) = flatten xss
flatten (Cons (Cons x xs) xss) = Cons x (flatten (Cons xs xss))
{-# COMPILE AGDA2HS flatten #-}
| {
"alphanum_fraction": 0.6329268293,
"avg_line_length": 20.5,
"ext": "agda",
"hexsha": "be765b120201004858a364691431f08bebc7b2c3",
"lang": "Agda",
"max_forks_count": 18,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:42:52.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-10-21T22:19:09.000Z",
"max_forks_repo_head_hexsha": "160478a51bc78b0fdab07b968464420439f9fed6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "seanpm2001/agda2hs",
"max_forks_repo_path": "test/TypeSynonyms.agda",
"max_issues_count": 63,
"max_issues_repo_head_hexsha": "160478a51bc78b0fdab07b968464420439f9fed6",
"max_issues_repo_issues_event_max_datetime": "2022-02-25T15:47:30.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-10-22T05:19:27.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "seanpm2001/agda2hs",
"max_issues_repo_path": "test/TypeSynonyms.agda",
"max_line_length": 63,
"max_stars_count": 55,
"max_stars_repo_head_hexsha": "8c8f24a079ed9677dbe6893cf786e7ed52dfe8b6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dxts/agda2hs",
"max_stars_repo_path": "test/TypeSynonyms.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-26T21:57:56.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-20T13:36:25.000Z",
"num_tokens": 278,
"size": 820
} |
open import Data.Empty
open import AEff
open import EffectAnnotations
open import Renamings
open import Types hiding (``)
open import Relation.Binary.PropositionalEquality hiding ([_])
module Substitutions where
-- PARALLEL SUBSTITUTIONS
data Sub : Ctx → Ctx → Set where
⟨_,_⟩ : {Γ Γ' : Ctx} {X : VType} →
Sub Γ Γ' →
Γ' ⊢V⦂ X →
--------------------------
Sub (Γ ∷ X) Γ'
ε : {Γ' : Ctx} →
------------
Sub [] Γ'
π : {Γ Γ' : Ctx} {X : VType} →
Sub Γ Γ' →
--------------------------
Sub Γ (Γ' ∷ X)
φ : {Γ Γ' : Ctx} →
Sub Γ Γ' →
----------------
Sub (Γ ■) (Γ' ■)
-- RENAMINGS AS SUBSTITUTIONS
sub-of-ren : {Γ Γ' : Ctx} →
Ren Γ Γ' →
--------------
Sub Γ Γ'
sub-of-ren ε =
ε
sub-of-ren ⟨ f , x ⟩ =
⟨ sub-of-ren f , ` x ⟩
sub-of-ren (π f) =
π (sub-of-ren f)
sub-of-ren (φ f) =
φ (sub-of-ren f)
-- IDENTITY SUBSTITUTION
sub-id : {Γ : Ctx} →
-----------
Sub Γ Γ
sub-id = sub-of-ren ren-id
-- SUBSTITUTION EXTENSION
_[_]s : {Γ Γ' : Ctx} {X : VType} →
Sub Γ Γ' →
Γ' ⊢V⦂ X →
--------------------------
Sub (Γ ∷ X) Γ'
s [ V ]s = ⟨ s , V ⟩
-- CONGRUENCE OF SUBSTITUTIONS
subst-cong : {Γ Γ' : Ctx} {X : VType} → Sub Γ Γ' → Sub (Γ ∷ X) (Γ' ∷ X)
subst-cong ⟨ s , x ⟩ =
⟨ π ⟨ s , x ⟩ , ` Hd ⟩
subst-cong ε =
⟨ ε , ` Hd ⟩
subst-cong (π s) =
⟨ π (π s) , ` Hd ⟩
subst-cong (φ s) =
⟨ π (φ s) , ` Hd ⟩
-- ACTION OF SUBSTITUTION ON WELL-TYPED VALUES AND COMPUTATIONS
val-of-sub : {Γ Γ' : Ctx} {X : VType} → Sub Γ Γ' → X ∈ Γ → Γ' ⊢V⦂ X
val-of-sub ⟨ s , V ⟩ Hd =
V
val-of-sub ⟨ s , V ⟩ (Tl-v x) =
val-of-sub s x
val-of-sub (π s) x =
V-rename ren-wk (val-of-sub s x)
val-of-sub (φ s) (Tl-■ p x) =
■-wk p (val-of-sub s x)
mutual
sub-var : {Γ Γ' : Ctx} {X : VType} →
X ∈ Γ →
Sub Γ Γ' →
--------------------------
Γ' ⊢V⦂ X
sub-var Hd ⟨ s , V ⟩ =
V
sub-var Hd (π s) =
V-rename ren-wk (val-of-sub s Hd)
sub-var (Tl-v x) ⟨ s , V ⟩ =
sub-var x s
sub-var (Tl-v x) (π s) =
V-rename ren-wk (val-of-sub s (Tl-v x))
sub-var (Tl-■ p x) (π s) =
V-rename ren-wk (val-of-sub s (Tl-■ p x))
sub-var (Tl-■ p x) (φ s) =
■-wk p (val-of-sub s x)
sub-comp : {Γ Γ' Γ'' : Ctx} →
Sub Γ' Γ'' →
Sub Γ Γ' →
------------------
Sub Γ Γ''
sub-comp t ⟨ s , V ⟩ =
⟨ sub-comp t s , V [ t ]v ⟩
sub-comp t ε =
ε
sub-comp ⟨ t , x ⟩ (π s) =
sub-comp t s
sub-comp (π t) (π s) =
π (sub-comp t (π s))
sub-comp (π t) (φ s) =
π (sub-comp t (φ s))
sub-comp (φ t) (φ s) =
φ (sub-comp t s)
_[_]v : {Γ Γ' : Ctx} {X : VType} →
Γ ⊢V⦂ X →
Sub Γ Γ' →
--------------------------
Γ' ⊢V⦂ X
(` x) [ s ]v =
sub-var x s
(´ c) [ s ]v =
´ c
⋆ [ s ]v =
⋆
(ƛ M) [ s ]v =
ƛ (M [ subst-cong s ]c)
⟨ V ⟩ [ s ]v =
⟨ V [ s ]v ⟩
(□ V) [ s ]v =
□ (V [ φ s ]v)
_[_]c : {Γ Γ' : Ctx} {C : CType} →
Γ ⊢C⦂ C →
Sub Γ Γ' →
--------------------------
Γ' ⊢C⦂ C
(return V) [ s ]c =
return (V [ s ]v)
(let= M `in N) [ s ]c =
let= (M [ s ]c) `in (N [ subst-cong s ]c)
(V · W) [ s ]c =
(V [ s ]v) · (W [ s ]v)
(↑ op p V M) [ s ]c =
↑ op p (V [ s ]v) (M [ s ]c)
(↓ op V M) [ s ]c =
↓ op (V [ s ]v) (M [ s ]c)
(promise op ∣ p ↦ M `in N) [ s ]c =
promise op ∣ p ↦ (M [ subst-cong (subst-cong s) ]c) `in (N [ subst-cong s ]c)
(await V until M) [ s ]c =
await (V [ s ]v) until (M [ subst-cong s ]c)
(unbox V `in M) [ s ]c =
unbox (V [ s ]v) `in (M [ subst-cong s ]c)
(spawn M N) [ s ]c =
spawn (M [ φ s ]c) (N [ s ]c)
(coerce p q M) [ s ]c =
coerce p q (M [ s ]c)
infix 40 _[_]v
infix 40 _[_]c
-- ACTION OF SUBSTITUTION ON WELL-TYPED PROCESSES
_[_]p : {Γ Γ' : Ctx} {o : O} {PP : PType o} →
Γ ⊢P⦂ PP →
Sub Γ Γ' →
-------------------------------------
Γ' ⊢P⦂ PP
(run M) [ s ]p =
run (M [ s ]c)
(P ∥ Q) [ s ]p =
(P [ s ]p) ∥ (Q [ s ]p)
(↑ op p V P) [ s ]p =
↑ op p (V [ s ]v) (P [ s ]p)
(↓ op V P) [ s ]p =
↓ op (V [ s ]v) (P [ s ]p)
infix 40 _[_]p
| {
"alphanum_fraction": 0.3765822785,
"avg_line_length": 21.0666666667,
"ext": "agda",
"hexsha": "759df776d2065bb8306a63944f2a636a19818686",
"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": "b41df71f4456666aab4bd14e13d285c31af80ff6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "danelahman/modal-aeff-agda",
"max_forks_repo_path": "Substitutions.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b41df71f4456666aab4bd14e13d285c31af80ff6",
"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": "danelahman/modal-aeff-agda",
"max_issues_repo_path": "Substitutions.agda",
"max_line_length": 81,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "b41df71f4456666aab4bd14e13d285c31af80ff6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "danelahman/higher-order-aeff-agda",
"max_stars_repo_path": "Substitutions.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T18:50:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-08-17T15:00:34.000Z",
"num_tokens": 1814,
"size": 4424
} |
-- Andreas, 2014-10-08, issue reported by Andrea Vezzosi
{-# OPTIONS --copatterns #-}
import Common.Level
open import Common.Product
postulate Nat : Set
record Cxt : Set₁ where
constructor Con -- essential
field
CSet : Set
CRel : (e0 e1 : CSet) → Set
record Type (Γ : Cxt) : Set₁ where
open Cxt
field
TSet : (e : CSet Γ) → Set
TRel : (e : CSet Γ) →
([e] : CRel Γ e e) →
(t : TSet e) → Set
open Type
module Works where
T : (Γ : Cxt) → (a : Type Γ) → Type Γ
TSet (T Γ a) γ = Nat × TSet a γ
TRel (T Γ a) γ [e] (n , b) = TRel a γ [e] b
module Works2 where
T : (Γ : Cxt) → (a : Type Γ) → Type Γ
TSet (T Γ a) γ = Nat × TSet a γ
TRel (T (Con S R) a) γ [e] (n , b) = TRel a γ [e] b
module Fails2 where
T : (Γ : Cxt) → (a : Type Γ) → Type Γ
TSet (T (Con S R) a) γ = Nat × TSet a γ
TRel (T Γ a) γ [e] (n , b) = TRel a γ [e] b
module Fails where
T : (Γ : Cxt) → (a : Type Γ) → Type Γ
TSet (T (Con S R) a) γ = Nat × TSet a γ
TRel (T (Con S R) a) γ [e] (n , b) = TRel a γ [e] b
-- All version should work!
| {
"alphanum_fraction": 0.5106382979,
"avg_line_length": 21.6923076923,
"ext": "agda",
"hexsha": "a304affa1a5ee3f4d1cf92242737f1ffaceb6a28",
"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/Issue1294.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/Issue1294.agda",
"max_line_length": 56,
"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/Issue1294.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": 464,
"size": 1128
} |
open import Data.Nat
open import Data.Fin
open import Data.List
open import Data.List.Membership.Propositional
open import Data.List.Relation.Unary.All as All
open import Data.List.All.Properties.Extra
open import Data.Vec hiding (_∷ʳ_ ; _>>=_ ; init)
open import Data.Product
open import Relation.Binary.PropositionalEquality hiding ([_])
open ≡-Reasoning
open import Data.Unit
open import Data.List.Prefix
open import Data.List.Properties.Extra
open import Data.Maybe
open import Common.Weakening
-- This file contains the Agda Scope Graph Library described in
-- Section 4 of the paper.
-- The definitions are parameterized by a scope graph, where a scope
-- graph is a finite map from scope identifiers to scope shape
-- descriptors.
--
-- The scope graph library is also parametric in what the notion of
-- type is for declarations in the scope graph.
--
-- We use modules for this library parameterization. The `k`
-- parameter of the `ScopesFrames` module represents the number of
-- scope identifiers in the scope graph that all definitions are
-- parameterized over; and the `Ty` parameter is a language-specific
-- notion of type.
module ScopesFrames.ScopesFrames (k : ℕ) (Ty : Set) where
------------------
-- SCOPE GRAPHS --
------------------
-- Type aliases for scope identifiers (`Scope`s) and scope graphs
-- (`Graph`s).
--
-- As described in the paper, scope shapes are given by a list of
-- types corresponding to the declarations of the scope, and a list of
-- scopes, corresponding to the edges of the scope.
Scope = Fin k
Graph = Scope → (List Ty × List Scope)
-- All the following definitions are parameterized by a scope graph
-- `g`.
module UsesGraph (g : Graph) where
-- Some projection functions:
declsOf : Scope → List Ty ; declsOf s = proj₁ (g s)
edgesOf : Scope → List Scope ; edgesOf s = proj₂ (g s)
-- A resolution path is a witness that we can traverse a sequence of
-- scope edges (`_⟶_`) in `g` to arrive at a declaration of type
-- `t`:
data _⟶_ : Scope → Scope → Set where
[] : ∀ {s} → s ⟶ s
_∷_ : ∀ {s s' s''} → s' ∈ edgesOf s → s' ⟶ s'' → s ⟶ s''
-- path concatenation
concatₚ : ∀ {s s' s''} → s ⟶ s' → s' ⟶ s'' → s ⟶ s''
concatₚ [] p₂ = p₂
concatₚ (x ∷ p₁) p₂ = x ∷ (concatₚ p₁ p₂)
data _↦_ (s : Scope) (t : Ty) : Set where
path : ∀{s'} → s ⟶ s' → t ∈ declsOf s' → s ↦ t
prepend : ∀ {s s' t} → s ⟶ s' → s' ↦ t → s ↦ t
prepend p (path p' d) = path (concatₚ p p') d
-- The definitions above fully define scope graphs. The remaining
-- definitions in this file are intrinsically-typed by this notion
-- of scope graph.
----------------------
-- FRAMES AND HEAPS --
----------------------
-- Heap types summarize what the scope is for each frame location in
-- the heap:
HeapTy = List Scope
-- A frame pointer `Frame s Σ` is a witness that there is a frame
-- location scoped by `s` in a heap typed by `Σ`:
Frame : Scope → (Σ : HeapTy) → Set
Frame s Σ = s ∈ Σ
-- Concrete frames and heaps store values that are weakened when the
-- heap is extended. The following definitions are parameterized by
-- a language-specific notion of weakenable value.
module UsesVal (Val : Ty → HeapTy → Set)
(weaken-val : ∀ {t Σ Σ'} → Σ ⊑ Σ' → Val t Σ → Val t Σ') where
-- Slots are given by a list of values that are in one-to-one
-- correspondence with a list of declarations (types):
Slots : (ds : List Ty) → (Σ : HeapTy) → Set
Slots ds Σ = All (λ t → Val t Σ) ds
-- Links are given by a list of frame pointers (links) that are in
-- one-to-one correspondence with a list of edges (scopes):
Links : (es : List Scope) → (Σ : HeapTy) → Set
Links es Σ = All (λ s → Frame s Σ) es
-- A heap frame for a scope `s` is given by a set of slots and
-- links that are in one-to-one correspondence with the
-- declarations and edges of the scope:
HeapFrame : Scope → HeapTy → Set
HeapFrame s Σ = Slots (declsOf s) Σ × Links (edgesOf s) Σ
-- A heap typed by `Σ` is given by a list of heap frames such that
-- each frame location is in the heap is typed by the
-- corresponding location in `Σ`.
Heap : (Σ : HeapTy) → Set
Heap Σ = All (λ s → HeapFrame s Σ) Σ
----------------------
-- FRAME OPERATIONS --
----------------------
-- Frame initialization extends the heap, requiring heap type
-- weakening. The `Common.Weakening` module defines a generic
-- `Weakenable` record, which we instantiate for each entity that
-- is required to be weakenable. We use Agda's instance arguments
-- to automatically resolve the right notion of weakening where
-- possible.
-- We add some instances of the Weakenable typeclass
-- to the instance argument scope:
instance
weaken-val' : ∀ {t} → Weakenable (λ Σ → Val t Σ)
weaken-val' = record { wk = weaken-val }
weaken-frame : ∀ {s} → Weakenable (Frame s)
weaken-frame = record { wk = Weakenable.wk any-weakenable }
-- Frame initialization takes as argument:
--
-- * a scope `s`;
--
-- * a scope shape witness which asserts that looking up `s` in
-- the current scope graph `g` yields a scope shape where the
-- declarations are given by a list of types `ds`, and scope
-- edges are given by a list of scopes `es`;
--
-- * a set of slots typed by `ds`;
--
-- * a set of links typed by `es`; and
--
-- * a heap typed by the heap type `Σ` which also types the slots
-- and links.
--
-- The operation returns an extended heap (`∷ʳ` appends a single
-- element to a list, and is defined in `Data.List.Base` in the
-- Agda Standard Library) and a frame pointer into the extended
-- heap, i.e., the newly allocated and initialized frame.
initFrame : (s : Scope) → ∀ {Σ ds es}⦃ shape : g s ≡ (ds , es) ⦄ →
Slots ds Σ → Links es Σ → Heap Σ → Frame s (Σ ∷ʳ s) × Heap (Σ ∷ʳ s)
initFrame s {Σ} ⦃ refl ⦄ slots links h =
let ext = ∷ʳ-⊒ s Σ -- heap extension fact
f' = ∈-∷ʳ Σ s -- updated frame pointer witness
h' = (wk ext h) all-∷ʳ (wk ext slots , wk ext links) -- extended heap
in (f' , h')
-- Frames may be self-referential. For example, the values stored
-- in the slots of a frame may contain pointers to the frame
-- itself. The `initFrame` function above does not support
-- initializing such self-referential slots, since the slots are
-- assumed to be typed under the unextended heap.
--
-- The `initFrameι` function we now define takes as argument a
-- function to be used to initialize possibly-self-referential
-- frame slots. The function takes as argument a frame pointer
-- into a heap extended by the scope that we are currently
-- initializing, and slots are typed under this extended heap;
-- hence the slots can have self-references to the frame currently
-- being initialized.
initFrameι : (s : Scope) → ∀ {Σ ds es}⦃ shape : g s ≡ (ds , es) ⦄ →
(slotsf : Frame s (Σ ∷ʳ s) → Slots ds (Σ ∷ʳ s)) → Links es Σ → Heap Σ →
Frame s (Σ ∷ʳ s) × Heap (Σ ∷ʳ s)
initFrameι s {Σ} ⦃ refl ⦄ slotsf links h =
let ext = ∷ʳ-⊒ s Σ -- heap extension fact
f' = ∈-∷ʳ Σ s -- updated frame pointer witness
h' = (wk ext h) all-∷ʳ (slotsf f' , wk ext links) -- extended heap
in (f' , h')
-- Given a witness that a declaration typed by `t` is in a scope,
-- and a frame pointer, we can fetch the well-typed value stored
-- in the corresponding frame slot:
getSlot : ∀ {s t Σ} → t ∈ declsOf s → Frame s Σ → Heap Σ → Val t Σ
getSlot d f h
with (All.lookup h f)
... | (slots , links) = All.lookup slots d
-- Given a witness that a declaration typed by `t` is in a scope,
-- and a frame pointer, we can mutate the corresponding slot in a
-- type preserving manner:
setSlot : ∀ {s t Σ} → t ∈ declsOf s → Val t Σ → Frame s Σ → Heap Σ → Heap Σ
setSlot d v f h
with (All.lookup h f)
... | (slots , links) = h All.[ f ]≔ (slots All.[ d ]≔ v , links)
-- ... and similarly for edges:
getLink : ∀ {s s' Σ} → s' ∈ edgesOf s → Frame s Σ → Heap Σ → Frame s' Σ
getLink e f h
with (All.lookup h f)
... | (slots , links) = All.lookup links e
setLink : ∀ {s s' Σ} → s' ∈ edgesOf s → Frame s' Σ → Frame s Σ → Heap Σ → Heap Σ
setLink e f' f h
with (All.lookup h f)
... | (slots , links) = h All.[ f ]≔ (slots , links All.[ e ]≔ f')
-- Given a witness that there is a path through the scope graph
-- from scope `s` to scope `s'`, a frame typed by `s`, and a
-- well-typed heap, we can traverse the path by following the
-- corresponding frame links in the heap to arrive at a frame
-- scoped by `s'`:
getFrame : ∀ {s s' Σ} → (s ⟶ s') → Frame s Σ → Heap Σ → Frame s' Σ
getFrame [] f h = f
getFrame (e ∷ p) f h
with (All.lookup h f)
... | (slots , links) = getFrame p (All.lookup links e) h
-- Given the definitions above, we can define some shorthand
-- functions for getting and setting values:
getVal : ∀ {s t} → (s ↦ t) → ∀ {Σ} → Frame s Σ → Heap Σ → Val t Σ
getVal (path p d) f h = getSlot d (getFrame p f h) h
setVal : ∀ {s t Σ} → (s ↦ t) → Val t Σ → Frame s Σ → Heap Σ → Heap Σ
setVal (path p d) v f h = setSlot d v (getFrame p f h) h
| {
"alphanum_fraction": 0.6124079916,
"avg_line_length": 37.1484375,
"ext": "agda",
"hexsha": "4586446e3bd79c483284895c5f2b18f83e04dd44",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "metaborg/mj.agda",
"max_forks_repo_path": "src/ScopesFrames/ScopesFrames.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "metaborg/mj.agda",
"max_issues_repo_path": "src/ScopesFrames/ScopesFrames.agda",
"max_line_length": 88,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "metaborg/mj.agda",
"max_stars_repo_path": "src/ScopesFrames/ScopesFrames.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z",
"num_tokens": 2886,
"size": 9510
} |
{-# OPTIONS --safe #-}
module Cubical.Data.FinSet where
open import Cubical.Data.FinSet.Base public
open import Cubical.Data.FinSet.Properties public
| {
"alphanum_fraction": 0.7828947368,
"avg_line_length": 21.7142857143,
"ext": "agda",
"hexsha": "767f13589223ab1931b095d4eda4879159577279",
"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/Data/FinSet.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/Data/FinSet.agda",
"max_line_length": 49,
"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/Data/FinSet.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": 36,
"size": 152
} |
module Impure.LFRef.Properties.Decidable where
open import Prelude
open import Relation.Unary
open import Relation.Nullary.Decidable as DecM
open import Data.Fin.Properties as FinP using ()
open import Data.List
open import Data.Vec
open import Data.Vec.Properties
open import Function.Inverse hiding (_∘_; sym)
open import Extensions.List as List↑ using ()
open import Extensions.Vec as Vec↑ using ()
open import Relation.Binary.List.Pointwise using (decidable-≡)
open import Relation.Binary.HeterogeneousEquality as Het using ()
open import Impure.LFRef.Syntax hiding (subst)
open import Impure.LFRef.Welltyped
module DecidableEquality where
-- termination checker has trouble with mapping
-- recursively over the arguments of constructors; inlining would prove this terminating
{-# TERMINATING #-}
_tm≟_ : ∀ {n} (a b : Term n) → Dec (a ≡ b)
var x tm≟ var x' with (x FinP.≟ x')
... | yes refl = yes refl
... | no neq = no (λ{ refl → neq refl })
var x tm≟ loc x₁ = no (λ ())
var x tm≟ unit = no (λ ())
var x tm≟ con fn ts = no (λ ())
loc x tm≟ var x₁ = no (λ ())
loc x tm≟ loc x' with x ≟ x'
... | yes refl = yes refl
... | no neq = no (λ{ refl → neq refl })
loc x tm≟ unit = no (λ ())
loc x tm≟ con fn ts = no (λ ())
unit tm≟ var x = no (λ ())
unit tm≟ loc x = no (λ ())
unit tm≟ unit = yes refl
unit tm≟ con fn ts = no (λ ())
con fn ts tm≟ var x = no (λ ())
con fn ts tm≟ loc x = no (λ ())
con fn ts tm≟ unit = no (λ ())
con fn ts tm≟ con fn' ts' with fn ≟ fn'
... | no neq = no (λ{ refl → neq refl })
... | yes refl with decidable-≡ _tm≟_ ts ts'
... | no neq = no (λ{ refl → neq refl })
... | yes refl = yes refl
-- decidable type equality
_ty≟_ : ∀ {n} (a b : Type n) → Dec (a ≡ b)
(x [ ts ]) ty≟ (x' [ ts' ]) with x ≟ x'
... | no neq = no (λ{ refl → neq refl })
... | yes refl with decidable-≡ _tm≟_ ts ts'
... | yes refl = yes refl
... | no neq = no (λ{ refl → neq refl })
(x [ ts ]) ty≟ Ref b = no (λ ())
(x [ ts ]) ty≟ Unit = no (λ ())
Ref a ty≟ (x [ ts ]) = no (λ ())
Ref a ty≟ Ref b with a ty≟ b
... | yes refl = yes refl
... | no neq = no (λ{ refl → neq refl })
Ref a ty≟ Unit = no (λ ())
Unit ty≟ (x [ ts ]) = no (λ ())
Unit ty≟ Ref b = no (λ ())
Unit ty≟ Unit = yes refl
module UniqueTypings where
unique-tm-type : ∀ {n a b 𝕊 Σ Γ} {t : Term n} → 𝕊 , Σ , Γ ⊢ t ∶ a → 𝕊 , Σ , Γ ⊢ t ∶ b → a ≡ b
unique-tm-type unit unit = refl
unique-tm-type (var x) (var x') with Vec↑.[]=-functional _ _ x x'
... | refl = refl
unique-tm-type (loc x) (loc x') with List↑.[]=-functional _ _ x x'
... | refl = refl
unique-tm-type (con c ts refl) (con c' ts' refl)
with List↑.[]=-functional _ _ c c'
... | refl = refl
unique-type : ∀ {n a b 𝕊 Σ Γ} {e : Exp n} → 𝕊 , Σ , Γ ⊢ₑ e ∶ a → 𝕊 , Σ , Γ ⊢ₑ e ∶ b → a ≡ b
unique-type (tm x) (tm y) = unique-tm-type x y
unique-type (fn ·★[ refl ] ts) (fn' ·★[ refl ] ts') with List↑.[]=-functional _ _ fn fn'
... | refl = refl
unique-type (ref p) (ref q) = cong Ref (unique-type p q)
unique-type (! p) (! q) with unique-type p q
... | refl = refl
unique-type (p ≔ q) (p' ≔ q') = refl
elim-mistype : ∀ {n a b 𝕊 Σ Γ} {e : Exp n} →
𝕊 , Σ , Γ ⊢ₑ e ∶ a → 𝕊 , Σ , Γ ⊢ₑ e ∶ b → ¬ (a ≢ b)
elim-mistype p q with unique-type p q
... | refl = λ neq → neq refl
module DecidableTypability where
open UniqueTypings
open DecidableEquality
mutual
type-tm : ∀ {n} 𝕊 Σ Γ (t : Term n) → Dec (∃ λ a → 𝕊 , Σ , Γ ⊢ t ∶ a)
type-tm 𝕊 Σ Γ (var x) =
yes (, var (proj₂ (Vec↑.strong-lookup _ _)))
type-tm 𝕊 Σ Γ (loc x) =
DecM.map′
(λ{ (_ , p) → Ref _ , loc p})
(λ{ (_ , loc p) → _ , p })
(List↑.dec-lookup x Σ)
type-tm 𝕊 Σ Γ unit = yes (Unit , unit)
type-tm 𝕊 Σ Γ (con c ts) with (List↑.dec-lookup c (Sig.constructors 𝕊))
... | no ¬p = no (λ{ (._ , con p _ _) → ¬p (, p)})
... | yes (p , z) with typecheck-tele 𝕊 Σ Γ ts (weaken+-tele _ (ConType.args p))
... | no ¬q = no lem
where
lem : ¬ ∃ λ ty → 𝕊 , Σ , Γ ⊢ (con c ts) ∶ ty
lem (._ , con x q p) with List↑.[]=-functional _ _ z x
... | refl = ¬q q
... | yes q = yes (, con z q (tele-fit-length q))
-- deciding whether a term matches a given type follows from
-- typability with unique type assignments
typecheck-tm : ∀ {n} 𝕊 Σ Γ (t : Term n) a → Dec (𝕊 , Σ , Γ ⊢ t ∶ a)
typecheck-tm 𝕊 Σ Γ t a with type-tm 𝕊 Σ Γ t
... | no nwt = no (λ wta → nwt (, wta))
... | yes (a' , wta') with a ty≟ a'
... | yes refl = yes wta'
... | no neq = no (λ wta → neq (unique-tm-type wta wta'))
typecheck-tele : ∀ {n m } 𝕊 Σ Γ (ts : List (Term n)) → (T : Tele n m) → Dec (𝕊 , Σ , Γ ⊢ ts ∶ⁿ T)
typecheck-tele 𝕊 Σ Γ [] ε = yes ε
typecheck-tele 𝕊 Σ Γ [] (x ⟶ T) = no (λ ())
typecheck-tele 𝕊 Σ Γ (x ∷ ts) ε = no (λ ())
typecheck-tele 𝕊 Σ Γ (x ∷ ts) (ty ⟶ T)
with typecheck-tm 𝕊 Σ Γ x ty
... | no ¬x∶ty = no (λ{ (x∶ty ⟶ _) → ¬x∶ty x∶ty })
... | yes x∶ty with typecheck-tele 𝕊 Σ Γ ts (T tele/ (sub x))
... | yes ts∶T = yes (x∶ty ⟶ ts∶T)
... | no ¬ts∶T = no (λ{ (_ ⟶ ts∶T) → ¬ts∶T ts∶T })
type : ∀ {n} 𝕊 Σ Γ (e : Exp n) → Dec (∃ λ a → 𝕊 , Σ , Γ ⊢ₑ e ∶ a)
type 𝕊 Σ Γ (tm t) = DecM.map′
(λ{ (_ , x ) → , (tm x)})
(λ{ (_ , tm x) → , x})
(type-tm 𝕊 Σ Γ t)
type {n} 𝕊 Σ Γ (fn ·★ ts) with List↑.dec-lookup fn (Sig.funs 𝕊)
... | no ¬fn! = no (λ { (_ , (fn! ·★[ q ] _)) → ¬fn! (, fn!) })
... | yes (φ , fn!) with typecheck-tele 𝕊 Σ Γ ts (weaken+-tele _ (Fun.args φ))
... | no ¬ts∶T = no lem
where
lem : ¬ ∃ λ a → 𝕊 , Σ , Γ ⊢ₑ (fn ·★ ts) ∶ a
lem (_ , (fn!' ·★[ q ] ts∶T)) with List↑.[]=-functional _ _ fn! fn!'
... | refl = ¬ts∶T ts∶T
... | yes ts∶T = yes (, fn! ·★[ tele-fit-length ts∶T ] ts∶T)
type 𝕊 Σ Γ (ref e) with (type 𝕊 Σ Γ e)
... | no ¬wte = no (λ{ (.(Ref _) , ref wte) → ¬wte (, wte)})
... | yes (a , wte) = yes (, ref wte)
type 𝕊 Σ Γ (! e) with (type 𝕊 Σ Γ e)
... | no ¬wte = no ((λ{ (x , (! wte)) → ¬wte (, wte) }))
type 𝕊 Σ Γ (! e) | yes (x [ ts ] , wte) =
no λ{ (_ , ! wte') → elim-mistype wte wte' (λ ()) }
type 𝕊 Σ Γ (! e) | yes (Unit , wte) =
no λ{ (_ , ! wte' ) → elim-mistype wte wte' (λ ()) }
type 𝕊 Σ Γ (! e) | yes (Ref a , wte) = yes (_ , (! wte))
type 𝕊 Σ Γ (l ≔ r) with type 𝕊 Σ Γ l | type 𝕊 Σ Γ r
... | no ¬wtl | _ = no (λ{ (_ , wtl ≔ _ ) → ¬wtl (, wtl) })
... | _ | no ¬wtr = no (λ{ (_ , _ ≔ wtr ) → ¬wtr (, wtr) })
... | yes (x [ ts ] , wtl) | (yes (b , wtr)) =
no (λ{ (_ , wtl' ≔ wtr) → elim-mistype wtl wtl' (λ ())})
... | yes (Unit , wtl) | (yes (b , wtr)) =
no (λ{ (_ , wtl' ≔ wtr) → elim-mistype wtl wtl' (λ ())})
... | yes (Ref a , wtl) | yes (b , wtr) with a ty≟ b
... | yes refl = yes (, wtl ≔ wtr)
... | no neq = no lem
where
lem : ¬ ∃ λ a → 𝕊 , Σ , Γ ⊢ₑ (l ≔ r) ∶ a
lem (.Unit , (wtl' ≔ wtr')) with unique-type wtl wtl'
... | refl = elim-mistype wtr wtr' (neq ∘ sym)
typecheck : ∀ {n} 𝕊 Σ Γ (e : Exp n) a → Dec (𝕊 , Σ , Γ ⊢ₑ e ∶ a)
typecheck 𝕊 Σ Γ e a with type 𝕊 Σ Γ e
... | no ¬wte = no (λ wte → ¬wte (, wte))
... | yes (a' , wte) with a' ty≟ a
... | yes refl = yes wte
... | no neq = no (λ{ wte' → elim-mistype wte wte' neq })
typecheck-seq : ∀ {n} 𝕊 Σ Γ (e : SeqExp n) a → Dec (𝕊 , Σ , Γ ⊢ₛ e ∶ a)
typecheck-seq 𝕊 Σ Γ (lett e c) a with type 𝕊 Σ Γ e
... | no ¬wte = no (λ{ (lett wte _ ) → ¬wte (, wte)})
... | yes (b , wte) with typecheck-seq 𝕊 Σ (b :+: Γ) c (weaken₁-tp a)
... | yes wtc = yes (lett wte wtc)
... | no ¬wtc = no lem
where
lem : ¬ 𝕊 , Σ , Γ ⊢ₛ lett e c ∶ a
lem (lett wte' wtc) with unique-type wte wte'
... | refl = ¬wtc wtc
typecheck-seq 𝕊 Σ Γ (ret e) a = DecM.map′ ret (λ{ (ret wte) → wte }) (typecheck 𝕊 Σ Γ e a)
| {
"alphanum_fraction": 0.5047435897,
"avg_line_length": 40.414507772,
"ext": "agda",
"hexsha": "b1c2899c77eca514f82feaf45ab3a41bbf531b9f",
"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/Impure/LFRef/Properties/Decidable.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/Impure/LFRef/Properties/Decidable.agda",
"max_line_length": 101,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Impure/LFRef/Properties/Decidable.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3312,
"size": 7800
} |
-- {-# OPTIONS -v tc.term.con:100 #-}
module Issue799 where
data D : Set where
d : D
x : D
x = d {_} {_} {interesting-argument = _} {_} {_} {_}
-- should fail
| {
"alphanum_fraction": 0.5636363636,
"avg_line_length": 16.5,
"ext": "agda",
"hexsha": "8d66d8f558ab835b6916ee955ab3da751606ab34",
"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/Issue799.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/Issue799.agda",
"max_line_length": 52,
"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/Issue799.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": 57,
"size": 165
} |
module STLC.Term where
open import Data.Fin using (Fin)
open import Data.Fin.Substitution
open import Data.Nat using (ℕ; _+_)
open import Relation.Binary.Construct.Closure.ReflexiveTransitive
using (Star; ε; _◅_)
open import Data.Vec using (Vec; []; _∷_; lookup)
open import Relation.Binary.PropositionalEquality
using (refl; _≡_; cong₂)
-- --------------------------------------------------------------------
-- Untyped terms and values
-- --------------------------------------------------------------------
infix 7 _·_
data Term (n : ℕ) : Set where
# : (x : Fin n) -> Term n
ƛ : Term (1 + n) -> Term n
_·_ : Term n -> Term n -> Term n
data Value {n : ℕ} : Term n -> Set where
ƛ :
∀ { t }
-- -----------
-> Value (ƛ t)
-- --------------------------------------------------------------------
module Substitution where
-- This sub module defines application of the subtitution
-- TODO: Rename for consistency
module SubstApplication { T : ℕ -> Set } ( l : Lift T Term ) where
open Lift l hiding (var)
-- Application of substitution to term
infixl 8 _/_
_/_ : ∀ { m n : ℕ } -> Term m -> Sub T m n -> Term n
# x / ρ = lift (lookup ρ x)
(ƛ t) / ρ = ƛ (t / ρ ↑)
(t₁ · t₂) / ρ = (t₁ / ρ) · (t₂ / ρ)
open Application (record { _/_ = _/_ }) using (_/✶_)
open TermSubst (record { var = #; app = SubstApplication._/_ }) public hiding (var)
infix 8 _[/_]
-- Shorthand for single-variable term substitutions
_[/_] : ∀ { n } → Term (1 + n) → Term n → Term n
t₁ [/ t₂ ] = t₁ / sub t₂
-- --------------------------------------------------------------------
-- TODO: Add additional operators
-- TODO: Add constants w/ delta-rules
| {
"alphanum_fraction": 0.4933410539,
"avg_line_length": 23.6575342466,
"ext": "agda",
"hexsha": "a1292ffbcfba5c7a71d384f870509d1593fdf99e",
"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": "aeb2be63381d891fabe5317e3c27553deb6bca6d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "johnyob/agda-types",
"max_forks_repo_path": "src/STLC/Term.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aeb2be63381d891fabe5317e3c27553deb6bca6d",
"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": "johnyob/agda-types",
"max_issues_repo_path": "src/STLC/Term.agda",
"max_line_length": 85,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "aeb2be63381d891fabe5317e3c27553deb6bca6d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "johnyob/agda-types",
"max_stars_repo_path": "src/STLC/Term.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 493,
"size": 1727
} |
{-# OPTIONS --without-K #-}
module sets.empty where
open import level using ()
data ⊥ : Set where
⊥-elim : ∀ {i}{A : Set i} → ⊥ → A
⊥-elim ()
¬_ : ∀ {i} → Set i → Set i
¬ X = X → ⊥
infix 3 ¬_
| {
"alphanum_fraction": 0.5101010101,
"avg_line_length": 13.2,
"ext": "agda",
"hexsha": "31bd4f69806cda96d8e8ece059555713c524f94b",
"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": "sets/empty.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": "sets/empty.agda",
"max_line_length": 33,
"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": "sets/empty.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": 79,
"size": 198
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Functor.Continuous where
open import Level
open import Data.Product using (Σ)
open import Categories.Category
open import Categories.Functor
import Categories.Category.Construction.Cones as Con
import Categories.Diagram.Cone.Properties as Conₚ
import Categories.Diagram.Limit as Lim
import Categories.Morphism as Mor
private
variable
o ℓ e : Level
C D E J : Category o ℓ e
-- G preserves the limit of F.
LimitPreserving : (G : Functor C D) {F : Functor J C} (L : Lim.Limit F) → Set _
LimitPreserving {C = C} {D = D} G {F} L = Σ (Lim.Limit (G ∘F F)) λ L′ → G.F₀ (Lim.Limit.apex L) ≅ Lim.Limit.apex L′
where module F = Functor F
module G = Functor G
open Mor D
-- continuous functors preserves all limits.
Continuous : ∀ o ℓ e (G : Functor C D) → Set _
Continuous {C = C} o ℓ e G = ∀ {J : Category o ℓ e} {F : Functor J C} (L : Lim.Limit F) → LimitPreserving G L
| {
"alphanum_fraction": 0.6845991561,
"avg_line_length": 31.6,
"ext": "agda",
"hexsha": "d30ed32fcdf4daaa82571786a0d8ce7eda9f2dde",
"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/Functor/Continuous.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/Functor/Continuous.agda",
"max_line_length": 115,
"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/Functor/Continuous.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 289,
"size": 948
} |
{-# OPTIONS --without-K #-}
module UnivalenceFiniteTypes where
open import Data.Empty
open import Data.Unit
open import Data.Unit.Core
open import Data.Nat renaming (_⊔_ to _⊔ℕ_)
open import Data.Sum renaming (map to _⊎→_)
open import Data.Product renaming (map to _×→_)
open import Function renaming (_∘_ to _○_)
open import FT
open import SimpleHoTT
open import Equivalences
open import TypeEquivalences
open import Path2Equiv
open import FT-Nat
open import Inspect
open import LeftCancellation
open import Equiv2Path
-- univalence
{- This does not typecheck in reasonable time.
univalence₁ : {B₁ B₂ : FT} →
(e : ⟦ B₁ ⟧ ≃ ⟦ B₂ ⟧) → path2equiv (equiv2path e) ≡ e
univalence₁ {B₁} {B₂} (f , feq) with equiv₂ feq
... | mkqinv g α β = {!!}
-}
-- and this can't possibly be true!
-- note that even the "normal form" of equiv2path idequiv (ctrl-C ctrl-N)
-- is an absolutely enormous term.
univalence₂ : {B₁ B₂ : FT} → (p : B₁ ⇛ B₂) → equiv2path (path2equiv p) ≡ p
univalence₂ unite₊⇛ = {!!}
univalence₂ uniti₊⇛ = {!!}
univalence₂ swap₊⇛ = {!!}
univalence₂ assocl₊⇛ = {!!}
univalence₂ assocr₊⇛ = {!!}
univalence₂ unite⋆⇛ = {!!}
univalence₂ uniti⋆⇛ = {!!}
univalence₂ swap⋆⇛ = {!!}
univalence₂ assocl⋆⇛ = {!!}
univalence₂ assocr⋆⇛ = {!!}
univalence₂ distz⇛ = {!!}
univalence₂ factorz⇛ = {!!}
univalence₂ dist⇛ = {!!}
univalence₂ factor⇛ = {!!}
univalence₂ id⇛ = {!!}
univalence₂ (sym⇛ p) = {!!}
univalence₂ (p ◎ q) = {!!}
univalence₂ (p ⊕ q) = {!!}
univalence₂ (p ⊗ q) = {!!}
{-
univalence : {B₁ B₂ : FT} → (B₁ ⇛ B₂) ≃ (⟦ B₁ ⟧ ≃ ⟦ B₂ ⟧)
univalence =
(path2equiv , equiv₁ (mkqinv equiv2path univalence₁ univalence₂))
-} | {
"alphanum_fraction": 0.6615573268,
"avg_line_length": 28.1206896552,
"ext": "agda",
"hexsha": "177877d2e2e07ef8c4163106da40ba65558e4993",
"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/OldUnivalence/UnivalenceFiniteTypes.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/OldUnivalence/UnivalenceFiniteTypes.agda",
"max_line_length": 74,
"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/OldUnivalence/UnivalenceFiniteTypes.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": 619,
"size": 1631
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module collects the property definitions for left-scaling
-- (LeftDefs), right-scaling (RightDefs), and both (BiDefs).
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
module Algebra.Module.Definitions where
open import Algebra.Core
import Algebra.Module.Definitions.Left as L
import Algebra.Module.Definitions.Right as R
import Algebra.Module.Definitions.Bi as B
module LeftDefs = L
module RightDefs = R
module BiDefs = B
| {
"alphanum_fraction": 0.5769828927,
"avg_line_length": 27.9565217391,
"ext": "agda",
"hexsha": "dbd523d2c17c83d62642ef2146f3fd608516aade",
"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/Definitions.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/Definitions.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Algebra/Module/Definitions.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": 124,
"size": 643
} |
open import Relation.Binary.PropositionalEquality
open import Data.Nat
open import Data.Nat.Properties using (+-suc)
open import Data.Product renaming (_×_ to _∧_)
open import Data.Sum renaming (_⊎_ to _∨_ ; inj₁ to left ; inj₂ to right)
{- 5.1 Extrinsic approach -}
div2 : ℕ → ℕ
div2 zero = zero
div2 (suc zero) = zero
div2 (suc (suc n)) = 1 + div2 n
test5 : ℕ
test5 = div2 (suc (suc (suc (suc (suc zero)))))
suc-≡ : {m n : ℕ} → (m ≡ n) → (suc m ≡ suc n)
suc-≡ refl = refl
div2-correct : (n : ℕ) → (2 * div2 n ≡ n) ∨ (suc (2 * div2 n) ≡ n)
div2-correct zero = left refl
div2-correct (suc zero) = right refl
div2-correct (suc (suc n)) with div2-correct n
div2-correct (suc (suc n)) | left even rewrite +-suc (div2 n) (div2 n + 0) = left (suc-≡ (suc-≡ even))
div2-correct (suc (suc n)) | right odd rewrite +-suc (div2 n) (div2 n + 0) = right (suc-≡ (suc-≡ odd))
{- 5.2 Intrinsic approach -}
{- There might be a more elegant way to rewrite this rather than using trans directly here -}
div2' : (n : ℕ) → Σ ℕ (λ q → (2 * q ≡ n) ∨ (suc (2 * q) ≡ n))
div2' zero = zero , (left refl)
div2' (suc zero) = zero , (right refl)
div2' (suc (suc n)) with proj₂ (div2' n)
... | left even =
1 + proj₁ (div2' n) ,
left ( suc-≡ (trans (+-suc (proj₁ (div2' n)) (proj₁ (div2' n) + 0)) (suc-≡ even) ))
... | right odd =
1 + proj₁ (div2' n) ,
right (suc-≡ (suc-≡ (trans (+-suc (proj₁ (div2' n)) (proj₁ (div2' n) + 0)) odd)))
| {
"alphanum_fraction": 0.5478484265,
"avg_line_length": 37.0714285714,
"ext": "agda",
"hexsha": "48226781419662abef566cb6edefbdaa9e471261",
"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": "9a0d4a3f97103550a67e5e9ecbc8322bf0a8be23",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "erwinkn/program-eq-proof",
"max_forks_repo_path": "TD6/Div2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9a0d4a3f97103550a67e5e9ecbc8322bf0a8be23",
"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": "erwinkn/program-eq-proof",
"max_issues_repo_path": "TD6/Div2.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "9a0d4a3f97103550a67e5e9ecbc8322bf0a8be23",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "erwinkn/program-eq-proof",
"max_stars_repo_path": "TD6/Div2.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 597,
"size": 1557
} |
------------------------------------------------------------------------
-- Some results about various forms of coinductively defined weak
-- bisimilarity for the delay monad
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
open import Prelude
module Bisimilarity.Weak.Delay-monad {a} {A : Type a} where
open import Delay-monad
open import Delay-monad.Bisimilarity as DB using (force)
import Delay-monad.Bisimilarity.Negative as DN
open import Equality.Propositional
open import Logical-equivalence using (_⇔_)
open import Prelude.Size
open import Function-universe equality-with-J hiding (id; _∘_)
open import Function-universe.Size equality-with-J
import Bisimilarity.Delay-monad as SD
import Bisimilarity.Weak.Alternative.Equational-reasoning-instances
import Bisimilarity.Weak.Equational-reasoning-instances
open import Bisimilarity.Weak.Equivalent
open import Equational-reasoning
import Expansion.Delay-monad as ED
open import Labelled-transition-system.Delay-monad A
open import Bisimilarity delay-monad using ([_]_∼_)
open import Bisimilarity.Weak delay-monad
open import Bisimilarity.Weak.Alternative delay-monad as AW
using (force)
open import Expansion delay-monad as BE using ([_]_≳_; _≳_)
------------------------------------------------------------------------
-- Several definitions of weak bisimilarity are pointwise logically
-- equivalent
-- Emulations of the constructors DW.later, DW.laterˡ and DW.laterʳ.
later-cong : ∀ {i x y} →
[ i ] force x ≈′ force y → [ i ] later x ≈ later y
later-cong x≈′y =
⟨ (λ { later → _ , ⟶→⇒̂ later , x≈′y })
, (λ { later → _ , ⟶→⇒̂ later , x≈′y })
⟩
laterˡ : ∀ {i x y} → [ i ] force x ≈ y → [ i ] later x ≈ y
laterˡ x≈y =
⟨ (λ { later → _ , silent _ done , convert {a = a} x≈y })
, Σ-map id (Σ-map later⇒̂ id) ∘ right-to-left x≈y
⟩
laterʳ : ∀ {i x y} → [ i ] x ≈ force y → [ i ] x ≈ later y
laterʳ x≈y =
⟨ Σ-map id (Σ-map later⇒̂ id) ∘ left-to-right x≈y
, (λ { later → _ , silent _ done , convert {a = a} x≈y })
⟩
-- The direct definition of weak bisimilarity is contained in the form
-- of weak bisimilarity obtained from the transition relation.
direct→indirect : ∀ {i x y} →
DB.[ i ] x ≈ y → [ i ] x ≈ y
direct→indirect DB.now = reflexive
direct→indirect (DB.later p) = later-cong λ { .force →
direct→indirect (force p) }
direct→indirect (DB.laterˡ p) = laterˡ (direct→indirect p)
direct→indirect (DB.laterʳ p) = laterʳ (direct→indirect p)
mutual
-- The definition of weak bisimilarity obtained from the transition
-- relation is contained in the direct one.
indirect→direct : ∀ {i} x y → [ i ] x ≈ y → DB.[ i ] x ≈ y
indirect→direct {i} (now x) y =
[ i ] now x ≈ y ↝⟨ (λ p → left-to-right p now) ⟩
(∃ λ y′ → y [ just x ]⇒̂ y′ × [ i ] now x ≈′ y′) ↝⟨ DB.≳→ ∘ ED.[just]⇒̂→≳now ∘ proj₁ ∘ proj₂ ⟩
DB.[ i ] y ≈ now x ↝⟨ DB.symmetric ⟩□
DB.[ i ] now x ≈ y □
indirect→direct {i} x (now y) =
[ i ] x ≈ now y ↝⟨ (λ p → right-to-left p now) ⟩
(∃ λ x′ → x [ just y ]⇒̂ x′ × [ i ] x′ ≈′ now y) ↝⟨ DB.≳→ ∘ ED.[just]⇒̂→≳now ∘ proj₁ ∘ proj₂ ⟩□
DB.[ i ] x ≈ now y □
indirect→direct (later x) (later y) lx≈ly
with left-to-right lx≈ly later
... | y′ , non-silent contradiction _ , _ =
⊥-elim (contradiction _)
... | y′ , silent _ (step _ later y⇒y′) , x≈′y′ =
DB.later λ { .force →
indirect→direct′ y⇒y′ (force x≈′y′) }
... | y′ , silent _ done , x≈′ly
with right-to-left lx≈ly later
... | x′ , non-silent contradiction _ , _ =
⊥-elim (contradiction _)
... | x′ , silent _ (step _ later x⇒x′) , x′≈′y =
DB.later λ { .force →
DB.symmetric $
indirect→direct′ x⇒x′ $
symmetric (force x′≈′y) }
... | x′ , silent _ done , lx≈′y =
DB.later λ { .force →
DB.laterˡʳ⁻¹
(indirect→direct _ _ (force lx≈′y))
(indirect→direct _ _ (force x≈′ly)) }
private
-- A lemma used by indirect→direct.
indirect→direct′ : ∀ {i x y y′} →
y ⇒ y′ → [ i ] x ≈ y′ → DB.[ i ] x ≈ y
indirect→direct′ done p = indirect→direct _ _ p
indirect→direct′ (step _ later tr) p = DB.laterʳ (indirect→direct′ tr p)
indirect→direct′ (step () now _)
-- The direct definition of weak bisimilarity is logically equivalent
-- to the one obtained from the transition relation.
--
-- TODO: Are the two definitions isomorphic?
direct⇔indirect : ∀ {i x y} → DB.[ i ] x ≈ y ⇔ [ i ] x ≈ y
direct⇔indirect = record
{ to = direct→indirect
; from = indirect→direct _ _
}
-- The direct definition of weak bisimilarity is logically equivalent
-- to the alternative, coinductive form of weak bisimilarity obtained
-- from the transition relation. Note that this proof is not
-- size-preserving.
direct⇔alternative : ∀ {x y} → x DB.≈ y ⇔ x AW.≈ y
direct⇔alternative {x} {y} =
x DB.≈ y ↝⟨ direct⇔indirect ⟩
x ≈ y ↝⟨ inverse alternative⇔ ⟩□
x AW.≈ y □
------------------------------------------------------------------------
-- A non-existence result for the alternative, coinductive indirect
-- definition of weak bisimilarity
private
-- If A is uninhabited, then AW._≈_ is trivial.
uninhabited→trivial : ¬ A → ∀ x y → x AW.≈ y
uninhabited→trivial =
¬ A ↝⟨ DB.uninhabited→trivial ⟩
(∀ x y → x DB.≈ y) ↝⟨ ∀-cong _ (λ _ → ∀-cong _ λ _ → _⇔_.to direct⇔alternative) ⟩
(∀ x y → x AW.≈ y) □
-- One can define a size-preserving "later-cong" function iff A is
-- uninhabited.
Later-cong =
∀ {i x y} →
AW.[ i ] force x ≈′ force y → AW.[ i ] later x ≈ later y
size-preserving-later-cong⇔uninhabited : Later-cong ⇔ ¬ A
size-preserving-later-cong⇔uninhabited = record
{ to = Later-cong ↝⟨ (λ later-cong → now≈never (λ {i} → later-cong {i})) ⟩
(∀ x → now x AW.≈ never) ↝⟨ ∀-cong _ (λ _ → _⇔_.from direct⇔alternative) ⟩
(∀ x → now x DB.≈ never) ↝⟨ (λ hyp → DB.now≉never ∘ hyp) ⟩□
¬ A □
; from = ¬ A ↝⟨ uninhabited→trivial ⟩
(∀ x y → x AW.≈ y) ↝⟨ (λ trivial {_ _ _} _ → trivial _ _) ⟩□
Later-cong □
}
where
module _ (later-cong : Later-cong) where
now≈never : ∀ {i} x → AW.[ i ] now x ≈ never
now≈never x =
now x ∼⟨ ⇒alternative (laterʳ reflexive) ⟩
later (λ { .force → now x }) ∼⟨ later-cong (λ { .force → now≈never x }) ⟩■
never
------------------------------------------------------------------------
-- Some non-existence results for the standard indirect definition of
-- weak bisimilarity
-- There is a transitivity proof that takes weak bisimilarity and
-- expansion to expansion iff A is uninhabited.
Transitivity-≈≳≳ = {x y z : Delay A ∞} → x ≈ y → y ≳ z → x ≳ z
Transitivity-≳≈≳ = {x y z : Delay A ∞} → x ≳ y → y ≈ z → x ≳ z
transitive-≈≳≳⇔uninhabited : Transitivity-≈≳≳ ⇔ ¬ A
transitive-≈≳≳⇔uninhabited =
Transitivity-≈≳≳ ↝⟨ inverse $ implicit-∀-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $
→-cong _ direct⇔indirect (→-cong _ ED.direct⇔indirect ED.direct⇔indirect) ⟩
DN.Transitivity-≈≳≳ ↝⟨ DN.transitive-≈≳≳⇔uninhabited ⟩□
¬ A □
transitive-≳≈≳⇔uninhabited : Transitivity-≳≈≳ ⇔ ¬ A
transitive-≳≈≳⇔uninhabited =
Transitivity-≳≈≳ ↝⟨ inverse $ implicit-∀-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $
→-cong _ ED.direct⇔indirect (→-cong _ direct⇔indirect ED.direct⇔indirect) ⟩
DN.Transitivity-≳≈≳ ↝⟨ DN.transitive-≳≈≳⇔uninhabited ⟩□
¬ A □
-- There is a transitivity proof that preserves the size of the second
-- argument iff A is uninhabited.
Transitivityʳ =
∀ {i} {x y z : Delay A ∞} →
x ≈ y → [ i ] y ≈ z → [ i ] x ≈ z
size-preserving-transitivityʳ⇔uninhabited : Transitivityʳ ⇔ ¬ A
size-preserving-transitivityʳ⇔uninhabited =
Transitivityʳ ↝⟨ inverse $ implicit-∀-size-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $
→-cong _ direct⇔indirect $ →-cong _ direct⇔indirect direct⇔indirect ⟩
DN.Transitivity-≈ʳ ↝⟨ DN.size-preserving-transitivity-≈ʳ⇔uninhabited ⟩□
¬ A □
-- There is a transitivity proof that preserves the size of the first
-- argument iff A is uninhabited.
Transitivityˡ =
∀ {i} {x y z : Delay A ∞} →
[ i ] x ≈ y → y ≈ z → [ i ] x ≈ z
size-preserving-transitivityˡ⇔uninhabited : Transitivityˡ ⇔ ¬ A
size-preserving-transitivityˡ⇔uninhabited =
Transitivityˡ ↝⟨ inverse $ implicit-∀-size-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $
→-cong _ direct⇔indirect $ →-cong _ direct⇔indirect direct⇔indirect ⟩
DN.Transitivity-≈ˡ ↝⟨ DN.size-preserving-transitivity-≈ˡ⇔uninhabited ⟩□
¬ A □
-- There is a transitivity proof that preserves the size of the second
-- argument, a strong bisimilarity, iff A is uninhabited.
Transitivity-≈∼ʳ =
∀ {i} {x y z : Delay A ∞} →
x ≈ y → [ i ] y ∼ z → [ i ] x ≈ z
size-preserving-transitivity-≈∼ʳ⇔uninhabited : Transitivity-≈∼ʳ ⇔ ¬ A
size-preserving-transitivity-≈∼ʳ⇔uninhabited =
Transitivity-≈∼ʳ ↝⟨ inverse $ implicit-∀-size-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $
→-cong _ direct⇔indirect $ →-cong _ SD.direct⇔indirect direct⇔indirect ⟩
DN.Transitivity-≈∼ʳ ↝⟨ DN.size-preserving-transitivity-≈∼ʳ⇔uninhabited ⟩□
¬ A □
-- There is a transitivity proof that preserves the size of the first
-- argument, a strong bisimilarity, iff A is uninhabited.
Transitivity-∼≈ˡ =
∀ {i} {x y z : Delay A ∞} →
[ i ] x ∼ y → y ≈ z → [ i ] x ≈ z
size-preserving-transitivity-∼≈ˡ⇔uninhabited : Transitivity-∼≈ˡ ⇔ ¬ A
size-preserving-transitivity-∼≈ˡ⇔uninhabited =
Transitivity-∼≈ˡ ↝⟨ inverse $ implicit-∀-size-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $
→-cong _ SD.direct⇔indirect $ →-cong _ direct⇔indirect direct⇔indirect ⟩
DN.Transitivity-∼≈ˡ ↝⟨ DN.size-preserving-transitivity-∼≈ˡ⇔uninhabited ⟩□
¬ A □
-- There is a transitivity-like proof that preserves the size of the
-- first argument, an expansion, iff A is uninhabited.
Transitivity-≳≈ˡ =
∀ {i} {x y z : Delay A ∞} →
[ i ] x ≳ y → y ≈ z → [ i ] x ≈ z
size-preserving-transitivity-≳≈ˡ⇔uninhabited : Transitivity-≳≈ˡ ⇔ ¬ A
size-preserving-transitivity-≳≈ˡ⇔uninhabited =
Transitivity-≳≈ˡ ↝⟨ inverse $ implicit-∀-size-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $
→-cong _ ED.direct⇔indirect (→-cong _ direct⇔indirect direct⇔indirect) ⟩
DN.Transitivity-≳≈ˡ ↝⟨ DN.size-preserving-transitivity-≳≈ˡ⇔uninhabited ⟩□
¬ A □
-- There is a transitivity-like proof that takes an expansion as the
-- first argument, and preserves the size of both arguments, iff A is
-- uninhabited.
Transitivity-≳≈ =
∀ {i} {x y z : Delay A ∞} →
[ i ] x ≳ y → [ i ] y ≈ z → [ i ] x ≈ z
size-preserving-transitivity-≳≈⇔uninhabited : Transitivity-≳≈ ⇔ ¬ A
size-preserving-transitivity-≳≈⇔uninhabited =
Transitivity-≳≈ ↝⟨ inverse $ implicit-∀-size-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $
→-cong _ ED.direct⇔indirect (→-cong _ direct⇔indirect direct⇔indirect) ⟩
DN.Transitivity-≳≈ ↝⟨ DN.size-preserving-transitivity-≳≈⇔uninhabited ⟩□
¬ A □
-- There is a transitivity-like proof that preserves the size of the
-- second argument, an expansion (with the arguments swapped), iff A
-- is uninhabited.
Transitivity-≈≲ʳ =
∀ {i} {x y z : Delay A ∞} →
x ≈ y → [ i ] z ≳ y → [ i ] x ≈ z
size-preserving-transitivity-≈≲ʳ⇔uninhabited : Transitivity-≈≲ʳ ⇔ ¬ A
size-preserving-transitivity-≈≲ʳ⇔uninhabited =
Transitivity-≈≲ʳ ↝⟨ inverse $ implicit-∀-size-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $
→-cong _ direct⇔indirect (→-cong _ ED.direct⇔indirect direct⇔indirect) ⟩
DN.Transitivity-≈≲ʳ ↝⟨ DN.size-preserving-transitivity-≈≲ʳ⇔uninhabited ⟩□
¬ A □
-- There is a transitivity-like proof that takes an expansion (with
-- the arguments swapped) as the second argument, and preserves the
-- size of both arguments, iff A is uninhabited.
Transitivity-≈≲ =
∀ {i} {x y z : Delay A ∞} →
[ i ] x ≈ y → [ i ] z ≳ y → [ i ] x ≈ z
size-preserving-transitivity-≈≲⇔uninhabited : Transitivity-≈≲ ⇔ ¬ A
size-preserving-transitivity-≈≲⇔uninhabited =
Transitivity-≈≲ ↝⟨ inverse $ implicit-∀-size-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $
→-cong _ direct⇔indirect (→-cong _ ED.direct⇔indirect direct⇔indirect) ⟩
DN.Transitivity-≈≲ ↝⟨ DN.size-preserving-transitivity-≈≲⇔uninhabited ⟩□
¬ A □
-- There is a transitivity-like proof that preserves the size of the
-- first argument, and takes an expansion as the second argument, iff
-- A is uninhabited.
Transitivity-≈≳ˡ =
∀ {i} {x y z : Delay A ∞} →
[ i ] x ≈ y → y ≳ z → [ i ] x ≈ z
size-preserving-transitivity-≈≳ˡ⇔uninhabited : Transitivity-≈≳ˡ ⇔ ¬ A
size-preserving-transitivity-≈≳ˡ⇔uninhabited =
Transitivity-≈≳ˡ ↝⟨ inverse $ implicit-∀-size-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $ implicit-∀-cong _ $
→-cong _ direct⇔indirect (→-cong _ ED.direct⇔indirect direct⇔indirect) ⟩
DN.Transitivity-≈≳ˡ ↝⟨ DN.size-preserving-transitivity-≈≳ˡ⇔uninhabited ⟩□
¬ A □
------------------------------------------------------------------------
-- A non-existence result for both indirect definitions of weak
-- bisimilarity
-- The function ⇒alternative translating from the standard indirect
-- definition of weak bisimilarity to the alternative, coinductive one
-- can be made size-preserving iff A is uninhabited.
size-preserving-⇒alternative⇔uninhabited :
(∀ {i p q} → [ i ] p ≈ q → AW.[ i ] p ≈ q) ⇔ ¬ A
size-preserving-⇒alternative⇔uninhabited = record
{ to =
(∀ {i p q} → [ i ] p ≈ q → AW.[ i ] p ≈ q) ↝⟨ (λ ⇒alternative x≈y y≈z →
alternative⇒ (transitive {a = a} (⇒alternative x≈y) (⇒alternative y≈z))) ⟩
Transitivityʳ ↝⟨ _⇔_.to size-preserving-transitivityʳ⇔uninhabited ⟩□
¬ A □
; from =
¬ A ↝⟨ uninhabited→trivial ⟩
(∀ x y → x AW.≈ y) ↝⟨ (λ trivial {_ _ _} _ → trivial _ _) ⟩□
(∀ {i p q} → [ i ] p ≈ q → AW.[ i ] p ≈ q) □
}
------------------------------------------------------------------------
-- More lemmas
-- If x and y both make non-silent transitions of the same kind,
-- then they are weakly bisimilar.
⟶-with-equal-labels→≈ :
∀ {x x′ y y′ μ} →
¬ Silent μ → x [ μ ]⟶ x′ → y [ μ ]⟶ y′ → x ≈ y
⟶-with-equal-labels→≈ _ now now = reflexive
⟶-with-equal-labels→≈ ¬s later _ = ⊥-elim (¬s _)
[]⇒-with-equal-labels→≈ :
∀ {x x′ y y′ μ} →
¬ Silent μ → x [ μ ]⇒ x′ → y [ μ ]⇒ y′ → x ≈ y
[]⇒-with-equal-labels→≈
{x = x} {y = y} ¬s
(steps {p′ = x′} x⇒x′ x′⟶x″ x″⇒x‴)
(steps {p′ = y′} y⇒y′ y′⟶y″ y″⇒y‴) =
x ∼⟨ direct→indirect (DB.≳→ (ED.⇒→≳ x⇒x′)) ⟩
x′ ∼⟨ ⟶-with-equal-labels→≈ ¬s x′⟶x″ y′⟶y″ ⟩
y′ ∼⟨ symmetric (direct→indirect (DB.≳→ (ED.⇒→≳ y⇒y′))) ⟩■
y
⇒̂-with-equal-labels→≈ :
∀ {x x′ y y′ μ} →
¬ Silent μ → x [ μ ]⇒̂ x′ → y [ μ ]⇒̂ y′ → x ≈ y
⇒̂-with-equal-labels→≈ ¬s (non-silent _ x⇒x′) (non-silent _ y⇒y′) =
[]⇒-with-equal-labels→≈ ¬s x⇒x′ y⇒y′
⇒̂-with-equal-labels→≈ ¬s (silent s _) = ⊥-elim (¬s s)
⇒̂-with-equal-labels→≈ ¬s _ (silent s _) = ⊥-elim (¬s s)
⟶̂-with-equal-labels→≈ :
∀ {x x′ y y′ μ} →
¬ Silent μ → x [ μ ]⟶̂ x′ → y [ μ ]⟶̂ y′ → x ≈ y
⟶̂-with-equal-labels→≈ ¬s x⟶̂x′ y⟶̂y′ =
⇒̂-with-equal-labels→≈ ¬s (⟶̂→⇒̂ x⟶̂x′) (⟶̂→⇒̂ y⟶̂y′)
| {
"alphanum_fraction": 0.5634841909,
"avg_line_length": 39.9257425743,
"ext": "agda",
"hexsha": "81efde31b325fc2a2661a215d288bf98912bf076",
"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": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/up-to",
"max_forks_repo_path": "src/Bisimilarity/Weak/Delay-monad.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"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/up-to",
"max_issues_repo_path": "src/Bisimilarity/Weak/Delay-monad.agda",
"max_line_length": 130,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/up-to",
"max_stars_repo_path": "src/Bisimilarity/Weak/Delay-monad.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6179,
"size": 16130
} |
module Signature where
open import Function renaming (const to K)
open import Category.Monad.Predicate
open import Data.Sum
open import Data.Product
open import Data.Container.Indexed hiding (_∈_)
open import Data.Container.Indexed.Combinator
renaming (_⊎_ to _⊎^C_; _×_ to _×^C_)
open import Data.Container.Indexed.FreeMonad
open import Data.Char
open import Data.String
open import Relation.Unary
open import Relation.Binary.PropositionalEquality
------------------------------------------------------------------------
data Prompt : Set where
addFeed search : Prompt
data Mode : Set where
cmd : Mode
input : Prompt → Mode
data Dir : Set where
up down : Dir
postulate
Feed : Set
Hårss : Mode ▷ Mode
Hårss =
{- move -} { cmd } ∩ K Dir ◃
U /
(λ _ _ → cmd) ⊎^C
{- prompt -} { cmd } ∩ K Prompt ◃
U /
(λ { (_ , p) _ → input p}) ⊎^C
{- putChar -} (⋃[ p ∶ Prompt ] { input p }) ∩ K Char ◃
U /
(λ { {._} ((p , refl) , _) _ → input p }) ⊎^C
{- done -} ⋃[ p ∶ Prompt ] { input p } ◃
K (String × Prompt) /
(λ _ _ → cmd) ⊎^C
{- fetch -} { cmd } ◃
K Feed /
(λ _ _ → cmd) ⊎^C
{- searchN -} { input search } ◃
K String /
(λ _ _ → input search)
pattern moveP d = inj₁ (refl , d)
move : Dir → cmd ∈ Hårss ⋆ (U ∩ { cmd })
move d = generic (moveP d)
pattern promptP p = inj₂ (inj₁ (refl , p))
prompt : (p : Prompt) → cmd ∈ Hårss ⋆ (U ∩ { input p })
prompt p = generic (promptP p)
pattern putCharP c = inj₂ (inj₂ (inj₁ ((_ , refl) , c)))
putChar : ∀ {p} → Char → input p ∈ Hårss ⋆ (U ∩ { input p })
putChar c = generic (putCharP c)
pattern doneP = inj₂ (inj₂ (inj₂ (inj₁ (_ , refl))))
done : ∀ {p} → input p ∈ Hårss ⋆ (K (String × Prompt) ∩ { cmd })
done = generic doneP
pattern fetchP = inj₂ (inj₂ (inj₂ (inj₂ (inj₁ refl))))
fetch : cmd ∈ Hårss ⋆ (K Feed ∩ { cmd })
fetch = generic fetchP
pattern searchNextP = inj₂ (inj₂ (inj₂ (inj₂ (inj₂ refl))))
searchNext : input search ∈ Hårss ⋆ (K String ∩ { input search })
searchNext = generic searchNextP
prog : cmd ∈ Hårss ⋆ (K (String × Prompt) ∩ { cmd })
prog =
move down >>
prompt search >>
putChar 'a' >>
putChar 'p' >>
putChar 'a' >>
done
where
open RawPMonad rawPMonad
| {
"alphanum_fraction": 0.5449936629,
"avg_line_length": 25.1808510638,
"ext": "agda",
"hexsha": "a96c49c1a8da1a29741cc51968bef1315803c5c2",
"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": "f767dbfbd82ce667b7cea667c4da76fe97f761eb",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "stevana/haarss",
"max_forks_repo_path": "prototype/command-response/Signature.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f767dbfbd82ce667b7cea667c4da76fe97f761eb",
"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": "stevana/haarss",
"max_issues_repo_path": "prototype/command-response/Signature.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "f767dbfbd82ce667b7cea667c4da76fe97f761eb",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "stevana/haarss",
"max_stars_repo_path": "prototype/command-response/Signature.agda",
"max_stars_repo_stars_event_max_datetime": "2015-07-30T11:43:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-30T11:43:26.000Z",
"num_tokens": 841,
"size": 2367
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.