Search is not available for this dataset
text
string | meta
dict |
---|---|
{-# OPTIONS --without-K #-}
module Pitch where
open import Data.Bool using (Bool; false; true)
open import Data.Integer using (ℤ; +_; -[1+_])
open import Data.Fin using (Fin; toℕ; #_; _≟_) renaming (zero to fz; suc to fs)
open import Data.Maybe using (Maybe; just; nothing) renaming (map to mmap)
open import Data.Nat using (ℕ; suc; _+_; _*_; _∸_; _≡ᵇ_)
open import Data.Nat.DivMod using (_mod_; _div_)
open import Data.Product using (_×_; _,_; proj₁)
open import Data.Vec using (Vec; []; _∷_; map; lookup; replicate; _[_]%=_; toList)
open import Function using (_∘_)
open import Relation.Nullary using (yes; no)
open import BitVec using (BitVec; insert)
open import Lemmas using (revMod; -_mod_; -_div_)
open import Util using (findIndex)
-- Position of a pitch on an absolute scale
-- 0 is C(-1) on the international scale (where C4 is middle C)
-- or C0 on the Midi scale (where C5 is middle C)
-- Pitch is intentially set to match Midi pitch.
-- However it is fine to let 0 represent some other note and
-- translate appropriately at the end.
data Pitch : Set where
pitch : ℕ → Pitch
unpitch : Pitch → ℕ
unpitch (pitch p) = p
-- Number of notes in the chromatic scale.
chromaticScaleSize : ℕ
chromaticScaleSize = 12
-- Number of notes in the diatonic scale.
diatonicScaleSize : ℕ
diatonicScaleSize = 7
-- Position of a pitch within an octave, in the range [0..chromaticScaleSize-1].
data PitchClass : Set where
pitchClass : Fin chromaticScaleSize → PitchClass
unPitchClass : PitchClass → Fin chromaticScaleSize
unPitchClass (pitchClass p) = p
Scale : ℕ → Set
Scale = Vec PitchClass
-- Which octave one is in.
data Octave : Set where
octave : ℕ → Octave
unoctave : Octave → ℕ
unoctave (octave n) = n
PitchOctave : Set
PitchOctave = PitchClass × Octave
relativeToAbsolute : PitchOctave → Pitch
relativeToAbsolute (pitchClass n , octave o) =
pitch (o * chromaticScaleSize + (toℕ n))
absoluteToRelative : Pitch → PitchOctave
absoluteToRelative (pitch n) =
(pitchClass (n mod chromaticScaleSize) , octave (n div chromaticScaleSize))
pitchToClass : Pitch → PitchClass
pitchToClass = proj₁ ∘ absoluteToRelative
majorScale harmonicMinorScale : Scale diatonicScaleSize
majorScale = map pitchClass (# 0 ∷ # 2 ∷ # 4 ∷ # 5 ∷ # 7 ∷ # 9 ∷ # 11 ∷ [])
harmonicMinorScale = map pitchClass (# 0 ∷ # 2 ∷ # 3 ∷ # 5 ∷ # 7 ∷ # 8 ∷ # 11 ∷ [])
indexInScale : {n : ℕ} → Vec PitchClass n → Fin chromaticScaleSize → Maybe (Fin n)
indexInScale [] p = nothing
indexInScale (pc ∷ pcs) p with (unPitchClass pc ≟ p)
... | yes _ = just fz
... | no _ = mmap fs (indexInScale pcs p)
data DiatonicDegree : Set where
diatonicDegree : Fin diatonicScaleSize → DiatonicDegree
undd : DiatonicDegree → Fin diatonicScaleSize
undd (diatonicDegree d) = d
infix 4 _≡ᵈ_
_≡ᵈ_ : DiatonicDegree → DiatonicDegree → Bool
diatonicDegree d ≡ᵈ diatonicDegree e = toℕ d ≡ᵇ toℕ e
-- round down
pitchClassToDegreeMajor : PitchClass → DiatonicDegree
pitchClassToDegreeMajor (pitchClass fz) = diatonicDegree (# 0)
pitchClassToDegreeMajor (pitchClass (fs fz)) = diatonicDegree (# 0)
pitchClassToDegreeMajor (pitchClass (fs (fs fz))) = diatonicDegree (# 1)
pitchClassToDegreeMajor (pitchClass (fs (fs (fs fz)))) = diatonicDegree (# 1)
pitchClassToDegreeMajor (pitchClass (fs (fs (fs (fs fz))))) = diatonicDegree (# 2)
pitchClassToDegreeMajor (pitchClass (fs (fs (fs (fs (fs fz)))))) = diatonicDegree (# 3)
pitchClassToDegreeMajor (pitchClass (fs (fs (fs (fs (fs (fs fz))))))) = diatonicDegree (# 3)
pitchClassToDegreeMajor (pitchClass (fs (fs (fs (fs (fs (fs (fs fz)))))))) = diatonicDegree (# 4)
pitchClassToDegreeMajor (pitchClass (fs (fs (fs (fs (fs (fs (fs (fs fz))))))))) = diatonicDegree (# 4)
pitchClassToDegreeMajor (pitchClass (fs (fs (fs (fs (fs (fs (fs (fs (fs fz)))))))))) = diatonicDegree (# 5)
pitchClassToDegreeMajor (pitchClass (fs (fs (fs (fs (fs (fs (fs (fs (fs (fs fz))))))))))) = diatonicDegree (# 5)
pitchClassToDegreeMajor (pitchClass (fs (fs (fs (fs (fs (fs (fs (fs (fs (fs (fs fz)))))))))))) = diatonicDegree (# 6)
degreeToPitchClassMajor : DiatonicDegree → PitchClass
degreeToPitchClassMajor (diatonicDegree fz) = pitchClass (# 0)
degreeToPitchClassMajor (diatonicDegree (fs fz)) = pitchClass (# 2)
degreeToPitchClassMajor (diatonicDegree (fs (fs fz))) = pitchClass (# 4)
degreeToPitchClassMajor (diatonicDegree (fs (fs (fs fz)))) = pitchClass (# 5)
degreeToPitchClassMajor (diatonicDegree (fs (fs (fs (fs fz))))) = pitchClass (# 7)
degreeToPitchClassMajor (diatonicDegree (fs (fs (fs (fs (fs fz)))))) = pitchClass (# 9)
degreeToPitchClassMajor (diatonicDegree (fs (fs (fs (fs (fs (fs fz))))))) = pitchClass (# 11)
pitchToDegreeCMajor : Pitch → DiatonicDegree
pitchToDegreeCMajor = pitchClassToDegreeMajor ∘ pitchToClass
d1 d2 d3 d4 d5 d6 d7 : DiatonicDegree
d1 = diatonicDegree (# 0)
d2 = diatonicDegree (# 1)
d3 = diatonicDegree (# 2)
d4 = diatonicDegree (# 3)
d5 = diatonicDegree (# 4)
d6 = diatonicDegree (# 5)
d7 = diatonicDegree (# 6)
thirdUp : DiatonicDegree → DiatonicDegree
thirdUp (diatonicDegree d) = diatonicDegree ((toℕ d + 2) mod diatonicScaleSize)
scaleSize : {n : ℕ} → Scale n → ℕ
scaleSize {n} _ = n
transposePitch : ℤ → Pitch → Pitch
transposePitch (+_ k) (pitch n) = pitch (n + k)
transposePitch (-[1+_] k) (pitch n) = pitch (n ∸ suc k)
-- Set of pitch classes represented as a bit vector.
PitchClassSet : Set
PitchClassSet = BitVec chromaticScaleSize
addToPitchClassSet : PitchClass → PitchClassSet → PitchClassSet
addToPitchClassSet (pitchClass p) ps = insert p ps
-- Standard Midi pitches
-- first argument is relative pitch within octave
-- second argument is octave (C5 = middle C for Midi)
standardMidiPitch : Fin chromaticScaleSize → ℕ → Pitch
standardMidiPitch p o = relativeToAbsolute (pitchClass p , octave o)
c c♯ d d♯ e f f♯ g g♯ a b♭ b : ℕ → Pitch
c = standardMidiPitch (# 0)
c♯ = standardMidiPitch (# 1)
d = standardMidiPitch (# 2)
d♯ = standardMidiPitch (# 3)
e = standardMidiPitch (# 4)
f = standardMidiPitch (# 5)
f♯ = standardMidiPitch (# 6)
g = standardMidiPitch (# 7)
g♯ = standardMidiPitch (# 8)
a = standardMidiPitch (# 9)
b♭ = standardMidiPitch (# 10)
b = standardMidiPitch (# 11)
| {
"alphanum_fraction": 0.6529817201,
"avg_line_length": 40.4484848485,
"ext": "agda",
"hexsha": "a22dc41fc25b63c8c525ad762383b8bb2f65a65f",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2020-11-10T04:04:40.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-01-12T17:02:36.000Z",
"max_forks_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "halfaya/MusicTools",
"max_forks_repo_path": "doc/icfp20/code/Pitch.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_issues_repo_issues_event_max_datetime": "2020-11-17T00:58:55.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-11-13T01:26:20.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "halfaya/MusicTools",
"max_issues_repo_path": "doc/icfp20/code/Pitch.agda",
"max_line_length": 117,
"max_stars_count": 28,
"max_stars_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "halfaya/MusicTools",
"max_stars_repo_path": "doc/icfp20/code/Pitch.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-04T18:04:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-04-21T09:08:52.000Z",
"num_tokens": 2052,
"size": 6674
} |
module Base.Prelude.Unit where
open import Data.Unit using (tt) renaming (⊤ to ⊤ᵖ) public
open import Base.Free using (Free; pure)
⊤ : (S : Set) (P : S → Set) → Set
⊤ _ _ = ⊤ᵖ
pattern Tt = pure tt
| {
"alphanum_fraction": 0.6201923077,
"avg_line_length": 20.8,
"ext": "agda",
"hexsha": "689985372b4448e5964654750a87663e0f315b23",
"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/Prelude/Unit.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/Prelude/Unit.agda",
"max_line_length": 66,
"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/Prelude/Unit.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": 78,
"size": 208
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
module stash.modalities.gbm.GbmUtil where
BM-Relation : ∀ {ℓ} (M : Modality ℓ) {A : Type ℓ} {B : Type ℓ} (Q : A → B → Type ℓ) → Type ℓ
BM-Relation M {A} {B} Q =
{a₀ : A} {b₀ : B} (q₀ : Q a₀ b₀)
{a₁ : A} (q₁ : Q a₁ b₀)
{b₁ : B} (q₂ : Q a₀ b₁) →
Modality.is-◯-connected M (((a₀ , q₀) == (a₁ , q₁)) * ((b₀ , q₀) == (b₁ , q₂)))
prop-lemma : ∀ {ℓ} {A : Type ℓ} {a₀ a₁ : A} (P : A → hProp ℓ)
(p : a₀ == a₁) (x₀ : (fst ∘ P) a₀) (x₁ : (fst ∘ P) a₁) →
x₀ == x₁ [ (fst ∘ P) ↓ p ]
prop-lemma P idp x₀ x₁ = prop-has-all-paths (snd (P _)) x₀ x₁
pths-ovr-is-prop : ∀ {ℓ} {A : Type ℓ} {a₀ a₁ : A} (P : A → hProp ℓ)
(p : a₀ == a₁) (x₀ : (fst ∘ P) a₀) (x₁ : (fst ∘ P) a₁) →
is-prop (x₀ == x₁ [ (fst ∘ P) ↓ p ])
pths-ovr-is-prop P idp x₀ x₁ = =-preserves-level (snd (P _))
pths-ovr-contr : ∀ {ℓ} {A : Type ℓ} {a₀ a₁ : A} (P : A → hProp ℓ)
(p : a₀ == a₁) (x₀ : (fst ∘ P) a₀) (x₁ : (fst ∘ P) a₁) →
is-contr (x₀ == x₁ [ (fst ∘ P) ↓ p ])
pths-ovr-contr P idp x₀ x₁ = =-preserves-level (inhab-prop-is-contr x₀ (snd (P _)))
eqv-square : ∀ {i j} {A : Type i} {B : Type j} (e : A ≃ B)
{b b' : B} (p : b == b')
→ ap (–> e ∘ <– e) p == (<–-inv-r e b) ∙ p ∙ (! (<–-inv-r e b'))
eqv-square e idp = ! (!-inv-r (<–-inv-r e _))
eqv-square' : ∀ {i j} {A : Type i} {B : Type j} (e : A ≃ B)
{a a' : A} (p : a == a')
→ ap (<– e ∘ –> e) p == <–-inv-l e a ∙ p ∙ ! (<–-inv-l e a')
eqv-square' e idp = ! (!-inv-r (<–-inv-l e _))
↓-==-in : ∀ {i j} {A : Type i} {B : Type j} {f g : A → B}
{x y : A} {p : x == y} {u : f x == g x} {v : f y == g y}
→ (u ∙ ap g p) == (ap f p ∙ v)
→ (u == v [ (λ x → f x == g x) ↓ p ])
↓-==-in {p = idp} q = ! (∙-unit-r _) ∙ q
↓-==-out : ∀ {i j} {A : Type i} {B : Type j} {f g : A → B}
{x y : A} {p : x == y} {u : f x == g x} {v : f y == g y}
→ (u == v [ (λ x → f x == g x) ↓ p ])
→ (u ∙ ap g p) == (ap f p ∙ v)
↓-==-out {p = idp} q = (∙-unit-r _) ∙ q
module HFiberSrcEquiv {i₀ i₁ i₂} {A : Type i₀} {B : Type i₁} {C : Type i₂}
(f : A → B) (h : B → C) (k : A → C)
(w : (a : A) → h (f a) == k a)
(ise-f : is-equiv f)
where
private
g = is-equiv.g ise-f
f-g = is-equiv.f-g ise-f
g-f = is-equiv.g-f ise-f
adj = is-equiv.adj ise-f
adj' = is-equiv.adj' ise-f
to : (c : C) → hfiber k c → hfiber h c
to .(k a) (a , idp) = f a , w a
to-lem₀ : (c : C) (x : hfiber k c) → fst (to c x) == f (fst x)
to-lem₀ .(k a) (a , idp) = idp
to-lem₁ : (c : C) (x : hfiber k c) → snd (to c x) == ap h (to-lem₀ c x) ∙ w (fst x) ∙ snd x
to-lem₁ .(k a) (a , idp) = ! (∙-unit-r (w a))
from : (c : C) → hfiber h c → hfiber k c
from .(h b) (b , idp) = g b , ! (w (g b)) ∙ ap h (f-g b)
from-lem₀ : (c : C) (x : hfiber h c) → fst (from c x) == g (fst x)
from-lem₀ .(h b) (b , idp) = idp
from-lem₁ : (c : C) (x : hfiber h c) → snd (from c x) == ap k (from-lem₀ c x) ∙ (! (w (g (fst x)))) ∙ ap h (f-g (fst x)) ∙ snd x
from-lem₁ .(h b) (b , idp) = ap (λ p → ! (w (g b)) ∙ p) (! (∙-unit-r (ap h (f-g b))))
to-from : (c : C) (x : hfiber h c) → to c (from c x) == x
to-from .(h b) (b , idp) = pair= (q ∙ f-g b) (↓-app=cst-in (r ∙ eq))
where c = h b
p = ! (w (g b)) ∙ ap h (f-g b)
q = to-lem₀ c (g b , p)
r = to-lem₁ c (g b , p)
eq = ap h q ∙ w (g b) ∙ ! (w (g b)) ∙ ap h (f-g b)
=⟨ ! (∙-assoc (w (g b)) (! (w (g b))) (ap h (f-g b))) |in-ctx (λ x → ap h q ∙ x) ⟩
ap h q ∙ (w (g b) ∙ (! (w (g b)))) ∙ ap h (f-g b)
=⟨ !-inv-r (w (g b)) |in-ctx (λ x → ap h q ∙ x ∙ ap h (f-g b)) ⟩
ap h q ∙ ap h (f-g b)
=⟨ ∙-ap h q (f-g b) ⟩
ap h (q ∙ f-g b)
=⟨ ! (∙-unit-r (ap h (q ∙ f-g b))) ⟩
ap h (q ∙ f-g b) ∙ idp ∎
from-to : (c : C) (x : hfiber k c) → from c (to c x) == x
from-to .(k a) (a , idp) = pair= (p ∙ g-f a) (↓-app=cst-in (q ∙ eq))
where c = k a
p = from-lem₀ c (f a , w a)
q = from-lem₁ c (f a , w a)
eq = ap k p ∙ ! (w (g (f a))) ∙ ap h (f-g (f a)) ∙ w a
=⟨ ! (adj a) |in-ctx (λ x → ap k p ∙ ! (w (g (f a))) ∙ ap h x ∙ w a) ⟩
ap k p ∙ ! (w (g (f a))) ∙ ap h (ap f (g-f a)) ∙ w a
=⟨ ∘-ap h f (g-f a) |in-ctx (λ x → ap k p ∙ ! (w (g (f a))) ∙ x ∙ w a) ⟩
ap k p ∙ ! (w (g (f a))) ∙ ap (h ∘ f) (g-f a) ∙ w a
=⟨ ! (↓-='-out (apd w (g-f a))) |in-ctx (λ x → ap k p ∙ ! (w (g (f a))) ∙ x) ⟩
ap k p ∙ ! (w (g (f a))) ∙ w (g (f a)) ∙' ap k (g-f a)
=⟨ ∙'=∙ (w (g (f a))) (ap k (g-f a)) |in-ctx (λ x → ap k p ∙ ! (w (g (f a))) ∙ x) ⟩
ap k p ∙ ! (w (g (f a))) ∙ w (g (f a)) ∙ ap k (g-f a)
=⟨ ! (∙-assoc (! (w (g (f a)))) (w (g (f a))) (ap k (g-f a))) |in-ctx (λ x → ap k p ∙ x) ⟩
ap k p ∙ (! (w (g (f a))) ∙ w (g (f a))) ∙ ap k (g-f a)
=⟨ !-inv-l (w (g (f a))) |in-ctx (λ x → ap k p ∙ x ∙ ap k (g-f a)) ⟩
ap k p ∙ ap k (g-f a)
=⟨ ∙-ap k p (g-f a) ⟩
ap k (p ∙ g-f a)
=⟨ ! (∙-unit-r (ap k (p ∙ g-f a))) ⟩
ap k (p ∙ g-f a) ∙ idp ∎
eqv : (c : C) → hfiber k c ≃ hfiber h c
eqv c = equiv (to c) (from c) (to-from c) (from-to c)
module HFiberTgtEquiv {i₀ i₁ i₂} {A : Type i₀} {B : Type i₁} {C : Type i₂}
(h : A → B) (k : A → C) (f : B → C)
(w : (a : A) → k a == f (h a))
(ise-f : is-equiv f)
where
private
g = is-equiv.g ise-f
f-g = is-equiv.f-g ise-f
g-f = is-equiv.g-f ise-f
adj = is-equiv.adj ise-f
adj' = is-equiv.adj' ise-f
to : (b : B) → hfiber h b → hfiber k (f b)
to .(h a) (a , idp) = a , w a
to-lem₀ : (b : B) (x : hfiber h b) → fst (to b x) == fst x
to-lem₀ .(h a) (a , idp) = idp
to-lem₁ : (b : B) (x : hfiber h b) → snd (to b x) == ap k (to-lem₀ b x) ∙ w (fst x) ∙ ap f (snd x)
to-lem₁ .(h a) (a , idp) = ! (∙-unit-r (w a))
from : (b : B) → hfiber k (f b) → hfiber h b
from b (a , p) = a , (! (g-f (h a)) ∙ ap g (! (w a) ∙ p) ∙ g-f b)
to-from : (b : B) (x : hfiber k (f b)) → to b (from b x) == x
to-from b (a , p) = pair= r (↓-app=cst-in (s ∙ (ap (λ x → ap k r ∙ x) eq)))
where q = ! (g-f (h a)) ∙ ap g (! (w a) ∙ p) ∙ g-f b
r = to-lem₀ b (a , q)
s = to-lem₁ b (a , q)
eq = w a ∙ ap f q
=⟨ ! (∙-ap f (! (g-f (h a))) (ap g (! (w a) ∙ p) ∙ g-f b)) |in-ctx (λ x → w a ∙ x) ⟩
w a ∙ ap f (! (g-f (h a))) ∙ ap f (ap g (! (w a) ∙ p) ∙ g-f b)
=⟨ ! (∙-ap f (ap g (! (w a) ∙ p)) (g-f b)) |in-ctx (λ x → w a ∙ ap f (! (g-f (h a))) ∙ x) ⟩
w a ∙ ap f (! (g-f (h a))) ∙ ap f (ap g (! (w a) ∙ p)) ∙ ap f (g-f b)
=⟨ ∘-ap f g (! (w a) ∙ p) |in-ctx (λ x → w a ∙ ap f (! (g-f (h a))) ∙ x ∙ ap f (g-f b)) ⟩
w a ∙ ap f (! (g-f (h a))) ∙ ap (f ∘ g) (! (w a) ∙ p) ∙ ap f (g-f b)
=⟨ ap (λ x → w a ∙ ap f (! (g-f (h a))) ∙ x ∙ ap f (g-f b)) (eqv-square (f , ise-f) (! (w a) ∙ p)) ⟩
w a ∙ ap f (! (g-f (h a))) ∙ (f-g (f (h a)) ∙ (! (w a) ∙ p) ∙ ! (f-g (f b))) ∙ ap f (g-f b)
=⟨ adj b |in-ctx (λ x → w a ∙ ap f (! (g-f (h a))) ∙ (f-g (f (h a)) ∙ (! (w a) ∙ p) ∙ ! (f-g (f b))) ∙ x) ⟩
w a ∙ ap f (! (g-f (h a))) ∙ (f-g (f (h a)) ∙ (! (w a) ∙ p) ∙ ! (f-g (f b))) ∙ f-g (f b)
=⟨ ∙-assoc (f-g (f (h a))) ((! (w a) ∙ p) ∙ ! (f-g (f b))) (f-g (f b)) |in-ctx (λ x → w a ∙ ap f (! (g-f (h a))) ∙ x) ⟩
w a ∙ ap f (! (g-f (h a))) ∙ f-g (f (h a)) ∙ ((! (w a) ∙ p) ∙ ! (f-g (f b))) ∙ f-g (f b)
=⟨ ∙-assoc (! (w a) ∙ p) (! (f-g (f b))) (f-g (f b)) |in-ctx (λ x → w a ∙ ap f (! (g-f (h a))) ∙ f-g (f (h a)) ∙ x) ⟩
w a ∙ ap f (! (g-f (h a))) ∙ f-g (f (h a)) ∙ (! (w a) ∙ p) ∙ ! (f-g (f b)) ∙ f-g (f b)
=⟨ !-inv-l (f-g (f b)) |in-ctx (λ x → w a ∙ ap f (! (g-f (h a))) ∙ f-g (f (h a)) ∙ (! (w a) ∙ p) ∙ x) ⟩
w a ∙ ap f (! (g-f (h a))) ∙ f-g (f (h a)) ∙ (! (w a) ∙ p) ∙ idp
=⟨ ∙-unit-r (! (w a) ∙ p) |in-ctx (λ x → w a ∙ ap f (! (g-f (h a))) ∙ f-g (f (h a)) ∙ x) ⟩
w a ∙ ap f (! (g-f (h a))) ∙ f-g (f (h a)) ∙ ! (w a) ∙ p
=⟨ ap-! f (g-f (h a)) |in-ctx (λ x → w a ∙ x ∙ f-g (f (h a)) ∙ ! (w a) ∙ p) ⟩
w a ∙ ! (ap f (g-f (h a))) ∙ f-g (f (h a)) ∙ ! (w a) ∙ p
=⟨ ! (adj (h a)) |in-ctx (λ x → w a ∙ ! (ap f (g-f (h a))) ∙ x ∙ ! (w a) ∙ p) ⟩
w a ∙ ! (ap f (g-f (h a))) ∙ ap f (g-f (h a)) ∙ ! (w a) ∙ p
=⟨ ! (∙-assoc (! (ap f (g-f (h a)))) (ap f (g-f (h a))) (! (w a) ∙ p)) |in-ctx (λ x → w a ∙ x)⟩
w a ∙ (! (ap f (g-f (h a))) ∙ ap f (g-f (h a))) ∙ ! (w a) ∙ p
=⟨ !-inv-l (ap f (g-f (h a))) |in-ctx (λ x → w a ∙ x ∙ ! (w a) ∙ p)⟩
w a ∙ ! (w a) ∙ p
=⟨ ! (∙-assoc (w a) (! (w a)) p) ⟩
(w a ∙ ! (w a)) ∙ p
=⟨ !-inv-r (w a) |in-ctx (λ x → x ∙ p) ⟩
p ∎
from-to : (b : B) (x : hfiber h b) → from b (to b x) == x
from-to .(h a) (a , idp) = pair= idp eq
where eq = ! (g-f (h a)) ∙ ap g (! (w a) ∙ w a) ∙ g-f (h a)
=⟨ !-inv-l (w a)|in-ctx (λ x → ! (g-f (h a)) ∙ ap g x ∙ g-f (h a)) ⟩
! (g-f (h a)) ∙ g-f (h a)
=⟨ !-inv-l (g-f (h a)) ⟩
idp ∎
eqv : (b : B) → hfiber h b ≃ hfiber k (f b)
eqv b = equiv (to b) (from b) (to-from b) (from-to b)
module HFiberSqEquiv {i₀ i₁ j₀ j₁}
{A₀ : Type i₀} {A₁ : Type i₁} {B₀ : Type j₀} {B₁ : Type j₁}
(f₀ : A₀ → B₀) (f₁ : A₁ → B₁) (hA : A₀ → A₁) (hB : B₀ → B₁)
(sq : CommSquare f₀ f₁ hA hB) (ise-hA : is-equiv hA) (ise-hB : is-equiv hB) where
open CommSquare
private
gB = is-equiv.g ise-hB
module Src = HFiberSrcEquiv hA f₁ (hB ∘ f₀) (λ a₀ → ! (commutes sq a₀)) ise-hA
module Tgt = HFiberTgtEquiv f₀ (f₁ ∘ hA) hB (λ a₀ → ! (commutes sq a₀)) ise-hB
eqv : (b₀ : B₀) → hfiber f₀ b₀ ≃ hfiber f₁ (hB b₀)
eqv b₀ = Src.eqv (hB b₀)
∘e coe-equiv (ap (λ s → hfiber s (hB b₀)) (λ= (λ a₀ → ! (commutes sq a₀))))
∘e Tgt.eqv b₀
hfiber-sq-eqv : ∀ {i₀ i₁ j₀ j₁}
{A₀ : Type i₀} {A₁ : Type i₁} {B₀ : Type j₀} {B₁ : Type j₁}
(f₀ : A₀ → B₀) (f₁ : A₁ → B₁) (hA : A₀ → A₁) (hB : B₀ → B₁)
(sq : CommSquare f₀ f₁ hA hB) (ise-hA : is-equiv hA) (ise-hB : is-equiv hB) →
(b₀ : B₀) → hfiber f₀ b₀ ≃ hfiber f₁ (hB b₀)
hfiber-sq-eqv f₀ f₁ hA hB sq ise-hA ise-hB b₀ = M.eqv b₀
where module M = HFiberSqEquiv f₀ f₁ hA hB sq ise-hA ise-hB
| {
"alphanum_fraction": 0.3431740763,
"avg_line_length": 49.1373390558,
"ext": "agda",
"hexsha": "86003e6d9447230eefd56716683c4ed18b8a885c",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/stash/modalities/gbm/GbmUtil.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/stash/modalities/gbm/GbmUtil.agda",
"max_line_length": 141,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "theorems/stash/modalities/gbm/GbmUtil.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": 5248,
"size": 11449
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import homotopy.EilenbergMacLane
open import groups.ToOmega
open import cohomology.Theory
open import cohomology.SpectrumModel
module cohomology.EMModel where
module _ {i} (G : AbGroup i) where
open EMExplicit G using (⊙EM; EM-level; EM-conn; spectrum)
private
E : (n : ℤ) → Ptd i
E (pos m) = ⊙EM m
E (negsucc m) = ⊙Lift ⊙Unit
E-spectrum : (n : ℤ) → ⊙Ω (E (succ n)) ⊙≃ E n
E-spectrum (pos n) = spectrum n
E-spectrum (negsucc O) = ≃-to-⊙≃ {X = ⊙Ω (E 0)}
(equiv (λ _ → _) (λ _ → idp)
(λ _ → idp) (prop-has-all-paths _))
idp
E-spectrum (negsucc (S n)) = ≃-to-⊙≃ {X = ⊙Ω (E (negsucc n))}
(equiv (λ _ → _) (λ _ → idp)
(λ _ → idp) (prop-has-all-paths {{=-preserves-level ⟨⟩}} _))
idp
EM-Cohomology : CohomologyTheory i
EM-Cohomology = spectrum-cohomology E E-spectrum
open CohomologyTheory EM-Cohomology
EM-dimension : {n : ℤ} → n ≠ 0 → is-trivialᴳ (C n (⊙Lift ⊙S⁰))
EM-dimension {pos O} neq = ⊥-rec (neq idp)
EM-dimension {pos (S n)} _ =
contr-is-trivialᴳ (C (pos (S n)) (⊙Lift ⊙S⁰))
{{connected-at-level-is-contr
{{⟨⟩}}
{{Trunc-preserves-conn $
equiv-preserves-conn
(pre⊙∘-equiv ⊙lower-equiv ∘e ⊙Bool→-equiv-idf _ ⁻¹)
{{path-conn (connected-≤T (⟨⟩-monotone-≤ (≤-ap-S (O≤ n)))
)}}}}}}
EM-dimension {negsucc O} _ =
contr-is-trivialᴳ (C (negsucc O) (⊙Lift ⊙S⁰))
{{Trunc-preserves-level 0 (Σ-level (Π-level λ _ →
inhab-prop-is-contr idp) ⟨⟩)}}
EM-dimension {negsucc (S n)} _ =
contr-is-trivialᴳ (C (negsucc (S n)) (⊙Lift ⊙S⁰))
{{Trunc-preserves-level 0 (Σ-level (Π-level λ _ →
=-preserves-level ⟨⟩) λ _ → =-preserves-level (=-preserves-level ⟨⟩))}}
EM-Ordinary : OrdinaryTheory i
EM-Ordinary = ordinary-theory EM-Cohomology EM-dimension
| {
"alphanum_fraction": 0.5691434469,
"avg_line_length": 32.8474576271,
"ext": "agda",
"hexsha": "c6fa0c596cd2e0c6287d1312e895478dbaacab32",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/cohomology/EMModel.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/cohomology/EMModel.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "theorems/cohomology/EMModel.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 753,
"size": 1938
} |
------------------------------------------------------------------------
-- Laws related to _⊛_ and return
------------------------------------------------------------------------
module TotalParserCombinators.Laws.ApplicativeFunctor where
open import Algebra
open import Category.Monad
open import Codata.Musical.Notation
open import Data.List
import Data.List.Categorical
import Data.List.Relation.Binary.BagAndSetEquality as BSEq
open import Function
open import Level
open RawMonad {f = zero} Data.List.Categorical.monad
using () renaming (_⊛_ to _⊛′_; _>>=_ to _>>=′_)
private
module BagMonoid {k} {A : Set} =
CommutativeMonoid (BSEq.commutativeMonoid k A)
open import TotalParserCombinators.Derivative
open import TotalParserCombinators.Congruence
hiding (return; fail) renaming (_∣_ to _∣′_)
import TotalParserCombinators.Laws.AdditiveMonoid as AdditiveMonoid
open import TotalParserCombinators.Laws.Derivative as Derivative
import TotalParserCombinators.Laws.Monad as Monad
open import TotalParserCombinators.Lib
open import TotalParserCombinators.Parser
------------------------------------------------------------------------
-- _⊛_, return, _∣_ and fail form an applicative functor "with a zero
-- and a plus"
-- Together with the additive monoid laws we get something which
-- resembles an idempotent semiring (if we restrict ourselves to
-- language equivalence).
-- First note that _⊛_ can be defined using _>>=_.
private
-- A variant of "flip map".
pam : ∀ {Tok R₁ R₂ xs} →
Parser Tok R₁ xs → (f : R₁ → R₂) →
Parser Tok R₂ (xs >>=′ [_] ∘ f)
pam p f = p >>= (return ∘ f)
infixl 10 _⊛″_
-- Note that this definition forces the argument parsers.
_⊛″_ : ∀ {Tok R₁ R₂ fs xs} →
∞⟨ xs ⟩Parser Tok (R₁ → R₂) (flatten fs) →
∞⟨ fs ⟩Parser Tok R₁ (flatten xs) →
Parser Tok R₂ (flatten fs ⊛′ flatten xs)
p₁ ⊛″ p₂ = ♭? p₁ >>= pam (♭? p₂)
⊛-in-terms-of->>= :
∀ {Tok R₁ R₂ fs xs}
(p₁ : ∞⟨ xs ⟩Parser Tok (R₁ → R₂) (flatten fs) )
(p₂ : ∞⟨ fs ⟩Parser Tok R₁ (flatten xs)) →
p₁ ⊛ p₂ ≅P p₁ ⊛″ p₂
⊛-in-terms-of->>= {R₁ = R₁} {R₂} {fs} {xs} p₁ p₂ =
BagMonoid.reflexive (Claims.⊛flatten-⊛-flatten (flatten fs) xs) ∷ λ t → ♯ (
D t (p₁ ⊛ p₂) ≅⟨ D-⊛ p₁ p₂ ⟩
D t (♭? p₁) ⊛ ♭? p₂ ∣
return⋆ (flatten fs) ⊛ D t (♭? p₂) ≅⟨ ⊛-in-terms-of->>= (D t (♭? p₁)) (♭? p₂) ∣′
⊛-in-terms-of->>= (return⋆ (flatten fs)) (D t (♭? p₂)) ⟩
D t (♭? p₁) ⊛″ ♭? p₂ ∣
return⋆ (flatten fs) ⊛″ D t (♭? p₂) ≅⟨ (D t (♭? p₁) ⊛″ ♭? p₂ ∎) ∣′
([ ○ - ○ - ○ - ○ ] return⋆ (flatten fs) ∎ >>= λ f →
sym $ lemma t f) ⟩
D t (♭? p₁) >>= pam (♭? p₂) ∣
return⋆ (flatten fs) >>= (λ f → D t (pam (♭? p₂) f)) ≅⟨ sym $ D->>= (♭? p₁) (pam (♭? p₂)) ⟩
D t (♭? p₁ >>= pam (♭? p₂)) ∎)
where
lemma : ∀ t (f : R₁ → R₂) →
D t (♭? p₂ >>= λ x → return (f x)) ≅P
D t (♭? p₂) >>= λ x → return (f x)
lemma t f =
D t (pam (♭? p₂) f) ≅⟨ D->>= (♭? p₂) (return ∘ f) ⟩
pam (D t (♭? p₂)) f ∣
(return⋆ (flatten xs) >>= λ _ → fail) ≅⟨ (pam (D t (♭? p₂)) f ∎) ∣′
Monad.right-zero (return⋆ (flatten xs)) ⟩
pam (D t (♭? p₂)) f ∣ fail ≅⟨ AdditiveMonoid.right-identity (pam (D t (♭? p₂)) f) ⟩
pam (D t (♭? p₂)) f ∎
-- We can then reduce all the laws to corresponding laws for _>>=_.
-- The zero laws have already been proved.
open Derivative public
using () renaming (left-zero-⊛ to left-zero;
right-zero-⊛ to right-zero)
-- _⊛_ distributes from the left over _∣_.
left-distributive : ∀ {Tok R₁ R₂ fs xs₁ xs₂}
(p₁ : Parser Tok (R₁ → R₂) fs)
(p₂ : Parser Tok R₁ xs₁)
(p₃ : Parser Tok R₁ xs₂) →
p₁ ⊛ (p₂ ∣ p₃) ≅P p₁ ⊛ p₂ ∣ p₁ ⊛ p₃
left-distributive p₁ p₂ p₃ =
p₁ ⊛ (p₂ ∣ p₃) ≅⟨ ⊛-in-terms-of->>= p₁ (p₂ ∣ p₃) ⟩
p₁ ⊛″ (p₂ ∣ p₃) ≅⟨ ([ ○ - ○ - ○ - ○ ] p₁ ∎ >>= λ f →
Monad.right-distributive p₂ p₃ (return ∘ f)) ⟩
(p₁ >>= λ f → pam p₂ f ∣ pam p₃ f) ≅⟨ Monad.left-distributive p₁ (pam p₂) (pam p₃) ⟩
p₁ ⊛″ p₂ ∣ p₁ ⊛″ p₃ ≅⟨ sym $ ⊛-in-terms-of->>= p₁ p₂ ∣′
⊛-in-terms-of->>= p₁ p₃ ⟩
p₁ ⊛ p₂ ∣ p₁ ⊛ p₃ ∎
-- _⊛_ distributes from the right over _∣_.
right-distributive : ∀ {Tok R₁ R₂ fs₁ fs₂ xs}
(p₁ : Parser Tok (R₁ → R₂) fs₁)
(p₂ : Parser Tok (R₁ → R₂) fs₂)
(p₃ : Parser Tok R₁ xs) →
(p₁ ∣ p₂) ⊛ p₃ ≅P p₁ ⊛ p₃ ∣ p₂ ⊛ p₃
right-distributive p₁ p₂ p₃ =
(p₁ ∣ p₂) ⊛ p₃ ≅⟨ ⊛-in-terms-of->>= (p₁ ∣ p₂) p₃ ⟩
(p₁ ∣ p₂) ⊛″ p₃ ≅⟨ Monad.right-distributive p₁ p₂ (pam p₃) ⟩
p₁ ⊛″ p₃ ∣ p₂ ⊛″ p₃ ≅⟨ sym $ ⊛-in-terms-of->>= p₁ p₃ ∣′
⊛-in-terms-of->>= p₂ p₃ ⟩
p₁ ⊛ p₃ ∣ p₂ ⊛ p₃ ∎
-- Applicative functor laws.
identity : ∀ {Tok R xs} (p : Parser Tok R xs) → return id ⊛ p ≅P p
identity p =
return id ⊛ p ≅⟨ ⊛-in-terms-of->>= (return id) p ⟩
return id ⊛″ p ≅⟨ Monad.left-identity id (pam p) ⟩
p >>= return ≅⟨ Monad.right-identity p ⟩
p ∎
homomorphism : ∀ {Tok R₁ R₂} (f : R₁ → R₂) (x : R₁) →
return f ⊛ return x ≅P return {Tok = Tok} (f x)
homomorphism f x =
return f ⊛ return x ≅⟨ ⊛-in-terms-of->>= (return f) (return x) ⟩
return f ⊛″ return x ≅⟨ Monad.left-identity f (pam (return x)) ⟩
pam (return x) f ≅⟨ Monad.left-identity x (return ∘ f) ⟩
return (f x) ∎
private
infixl 10 _⊛-cong_
_⊛-cong_ :
∀ {k Tok R₁ R₂ xs₁ xs₂ fs₁ fs₂}
{p₁ : Parser Tok (R₁ → R₂) fs₁} {p₂ : Parser Tok R₁ xs₁}
{p₃ : Parser Tok (R₁ → R₂) fs₂} {p₄ : Parser Tok R₁ xs₂} →
p₁ ∼[ k ]P p₃ → p₂ ∼[ k ]P p₄ → p₁ ⊛″ p₂ ∼[ k ]P p₃ ⊛″ p₄
_⊛-cong_ {p₁ = p₁} {p₂} {p₃} {p₄} p₁≈p₃ p₂≈p₄ =
p₁ ⊛″ p₂ ≅⟨ sym $ ⊛-in-terms-of->>= p₁ p₂ ⟩
p₁ ⊛ p₂ ∼⟨ [ ○ - ○ - ○ - ○ ] p₁≈p₃ ⊛ p₂≈p₄ ⟩
p₃ ⊛ p₄ ≅⟨ ⊛-in-terms-of->>= p₃ p₄ ⟩
p₃ ⊛″ p₄ ∎
pam-lemma : ∀ {Tok R₁ R₂ R₃ xs} {g : R₂ → List R₃}
(p₁ : Parser Tok R₁ xs) (f : R₁ → R₂)
(p₂ : (x : R₂) → Parser Tok R₃ (g x)) →
pam p₁ f >>= p₂ ≅P p₁ >>= λ x → p₂ (f x)
pam-lemma p₁ f p₂ =
pam p₁ f >>= p₂ ≅⟨ sym $ Monad.associative p₁ (return ∘ f) p₂ ⟩
(p₁ >>= λ x → return (f x) >>= p₂) ≅⟨ ([ ○ - ○ - ○ - ○ ] p₁ ∎ >>= λ x →
Monad.left-identity (f x) p₂) ⟩
(p₁ >>= λ x → p₂ (f x)) ∎
composition :
∀ {Tok R₁ R₂ R₃ fs gs xs}
(p₁ : Parser Tok (R₂ → R₃) fs)
(p₂ : Parser Tok (R₁ → R₂) gs)
(p₃ : Parser Tok R₁ xs) →
return _∘′_ ⊛ p₁ ⊛ p₂ ⊛ p₃ ≅P p₁ ⊛ (p₂ ⊛ p₃)
composition p₁ p₂ p₃ =
return _∘′_ ⊛ p₁ ⊛ p₂ ⊛ p₃ ≅⟨ ⊛-in-terms-of->>= (return _∘′_ ⊛ p₁ ⊛ p₂) p₃ ⟩
return _∘′_ ⊛ p₁ ⊛ p₂ ⊛″ p₃ ≅⟨ ⊛-in-terms-of->>= (return _∘′_ ⊛ p₁) p₂ ⊛-cong (p₃ ∎) ⟩
return _∘′_ ⊛ p₁ ⊛″ p₂ ⊛″ p₃ ≅⟨ ⊛-in-terms-of->>= (return _∘′_) p₁ ⊛-cong (p₂ ∎) ⊛-cong (p₃ ∎) ⟩
return _∘′_ ⊛″ p₁ ⊛″ p₂ ⊛″ p₃ ≅⟨ Monad.left-identity _∘′_ (pam p₁) ⊛-cong (p₂ ∎) ⊛-cong (p₃ ∎) ⟩
pam p₁ _∘′_ ⊛″ p₂ ⊛″ p₃ ≅⟨ pam-lemma p₁ _∘′_ (pam p₂) ⊛-cong (p₃ ∎) ⟩
((p₁ >>= λ f → pam p₂ (_∘′_ f)) ⊛″ p₃) ≅⟨ sym $ Monad.associative p₁ (λ f → pam p₂ (_∘′_ f)) (pam p₃) ⟩
(p₁ >>= λ f → pam p₂ (_∘′_ f) >>= pam p₃) ≅⟨ ([ ○ - ○ - ○ - ○ ] p₁ ∎ >>= λ f →
pam-lemma p₂ (_∘′_ f) (pam p₃)) ⟩
(p₁ >>= λ f → p₂ >>= λ g → pam p₃ (f ∘′ g)) ≅⟨ ([ ○ - ○ - ○ - ○ ] p₁ ∎ >>= λ f →
[ ○ - ○ - ○ - ○ ] p₂ ∎ >>= λ g →
sym $ pam-lemma p₃ g (return ∘ f)) ⟩
(p₁ >>= λ f → p₂ >>= λ g → pam (pam p₃ g) f) ≅⟨ ([ ○ - ○ - ○ - ○ ] p₁ ∎ >>= λ f →
Monad.associative p₂ (pam p₃) (return ∘ f)) ⟩
p₁ ⊛″ (p₂ ⊛″ p₃) ≅⟨ sym $ (p₁ ∎) ⊛-cong ⊛-in-terms-of->>= p₂ p₃ ⟩
p₁ ⊛″ (p₂ ⊛ p₃) ≅⟨ sym $ ⊛-in-terms-of->>= p₁ (p₂ ⊛ p₃) ⟩
p₁ ⊛ (p₂ ⊛ p₃) ∎
interchange : ∀ {Tok R₁ R₂ fs}
(p : Parser Tok (R₁ → R₂) fs) (x : R₁) →
p ⊛ return x ≅P return (λ f → f x) ⊛ p
interchange p x =
p ⊛ return x ≅⟨ ⊛-in-terms-of->>= p (return x) ⟩
p ⊛″ return x ≅⟨ ([ ○ - ○ - ○ - ○ ] p ∎ >>= λ f →
Monad.left-identity x (return ∘ f)) ⟩
(p >>= λ f → return (f x)) ≅⟨ pam p (λ f → f x) ∎ ⟩
pam p (λ f → f x) ≅⟨ sym $ Monad.left-identity (λ f → f x) (pam p) ⟩
return (λ f → f x) ⊛″ p ≅⟨ sym $ ⊛-in-terms-of->>= (return (λ f → f x)) p ⟩
return (λ f → f x) ⊛ p ∎
| {
"alphanum_fraction": 0.4273349006,
"avg_line_length": 44.9903846154,
"ext": "agda",
"hexsha": "67e927bf419867f804d1fc519ade3e4908cacbeb",
"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": "TotalParserCombinators/Laws/ApplicativeFunctor.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/parser-combinators",
"max_issues_repo_path": "TotalParserCombinators/Laws/ApplicativeFunctor.agda",
"max_line_length": 117,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/parser-combinators",
"max_stars_repo_path": "TotalParserCombinators/Laws/ApplicativeFunctor.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-03T08:56:13.000Z",
"num_tokens": 3909,
"size": 9358
} |
{-# OPTIONS --no-termination-check #-}
module RunTests where
open import Prelude.Bool
open import Prelude.Char
open import Prelude.Nat
open import Prelude.List
open import Prelude.IO
open import Prelude.String
open import Prelude.Unit
open import Prelude.Product
postulate
Stream : Set
popen : String -> String -> IO Stream
pclose : Stream -> IO Unit
readChar : Stream -> IO Char
strLen : String -> Nat
charAt : (s : String) -> Nat -> Char
_`_`_ : {A B C : Set}(x : A)(f : A -> B -> C)(y : B) -> C
x ` f ` y = f x y
infixr 9 _∘_
_∘_ : {A : Set}{B : A -> Set}{C : (x : A) -> B x -> Set}
(f : {a : A}(b : B a)-> C a b)
(g : (a : A) -> B a)(x : A) -> C x (g x)
f ∘ g = λ x -> f (g x)
infixr 1 _$_
_$_ : {A : Set}{B : A -> Set}(f : (x : A) -> B x)(x : A) -> B x
f $ x = f x
{-# COMPILED_EPIC popen (s : String, m : String, u : Unit) -> Ptr = foreign Ptr "popen" (mkString(s) : String, mkString(m) : String) #-}
{-# COMPILED_EPIC pclose (s : Ptr, u : Unit) -> Unit = foreign Int "pclose" (s : Ptr) ; u #-}
{-# COMPILED_EPIC readChar (s : Ptr, u : Unit) -> Int = foreign Int "fgetc" (s : Ptr) #-}
{-# COMPILED_EPIC strLen (s : Any) -> BigInt = foreign BigInt "intToBig" (foreign Int "strlen" (mkString(s) : String) : Int) #-}
{-# COMPILED_EPIC charAt (s : Any, n : BigInt) -> Int = foreign Int "charAtBig" (mkString(s) : String, n : BigInt) #-}
readStream : Stream -> IO (List Char)
readStream stream =
c <- readChar stream ,
if' charEq eof c
then pclose stream ,, return []
else ( cs <- readStream stream
, return (c :: cs))
system : String -> IO (List Char)
system s =
putStrLn $ "system " +S+ s ,,
x <- popen s "r" ,
y <- readStream x ,
return y
span : {A : Set} -> (p : A -> Bool) -> List A -> List A × List A
span p [] = [] , []
span p (a :: as) with p a
... | false = [] , a :: as
... | true with span p as
... | xs , ys = (a :: xs) , ys
groupBy : {A : Set} -> (A -> A -> Bool) -> List A -> List (List A)
groupBy _ [] = []
groupBy eq (x :: xs) with span (eq x) xs
... | ys , zs = (x :: ys) :: groupBy eq zs
comparing : {A B : Set} -> (A -> B) -> (B -> B -> Bool) -> A -> A -> Bool
comparing f _==_ x y = f x == f y
FilePath : Set
FilePath = String
and : List Bool -> Bool
and [] = true
and (true :: xs) = and xs
and (false :: _) = false
sequence : {A : Set} -> List (IO A) -> IO (List A)
sequence [] = return []
sequence (x :: xs) =
r <- x ,
rs <- sequence xs ,
return (r :: rs)
mapM : {A B : Set} -> (A -> IO B) -> List A -> IO (List B)
mapM f xs = sequence (map f xs)
printList : List Char -> IO Unit
printList xs =
mapM printChar xs ,,
printChar '\n'
printResult : FilePath -> List Char -> List Char -> IO Unit
printResult filename l1 l2 with l1 ` listEq charEq ` l2
... | true = putStrLn (filename +S+ ": Success!")
... | false = putStrLn (filename +S+ ": Fail!") ,,
putStrLn "Expected:" ,,
printList l2 ,,
putStrLn "Got:" ,,
printList l1
compile : FilePath -> FilePath -> IO Unit
compile dir file =
system $ "agda --epic --compile-dir=" +S+ dir +S+ "bin/ " +S+ dir +S+ file ,,
return unit
readFile : FilePath -> IO (List Char)
readFile file = system $ "cat " +S+ file
-- This won't work because of a bug in Epic...
{-
validFile : List Char -> Bool
validFile f with span (not ∘ charEq '.') f
... | _ , ('.' :: 'a' :: 'g' :: 'd' :: 'a' :: []) = true
... | _ , ('.' :: 'o' :: 'u' :: 't' :: []) = true
... | _ = false
-}
stripFileEnding : FilePath -> FilePath
stripFileEnding fp = fromList $ fst $ span (not ∘ charEq '.') (fromString fp)
testFile : FilePath -> FilePath -> FilePath -> IO Bool
testFile outdir agdafile outfile =
compile outdir (agdafile) ,,
out <- system $ outdir +S+ "bin/" +S+ stripFileEnding agdafile ,
expected <- readFile (outdir +S+ outfile) ,
printResult agdafile out expected ,,
return (out ` listEq charEq ` expected)
testFile' : FilePath -> List (List Char) -> IO Bool
testFile' outdir (agdafile :: outfile :: _) = testFile outdir (fromList agdafile) (fromList outfile)
testFile' _ _ = return true
isNewline : Char -> Bool
isNewline '\n' = true
isNewline _ = false
lines : List Char -> List (List Char)
lines list with span (not ∘ isNewline) list
... | l , [] = l :: []
... | l , _ :: s' = l :: lines s'
getFiles : FilePath -> IO (List (List Char))
getFiles dir =
out <- system $ "ls " +S+ dir ,
putStrLn "getFiles after ls" ,,
-- mapM (printList ∘ snd) $ map (span (not ∘ charEq '.')) $ lines out ,,
return $ lines out -- filter validFile $ lines out
isDot : Char -> Bool
isDot '.' = true
isDot _ = false
testFiles : FilePath -> IO Bool
testFiles dir =
files <- getFiles dir ,
putStrLn "Found the following files in the tests directory:" ,,
mapM printList files ,,
res <- mapM (testFile' dir) (groupBy (comparing (fst ∘ span (not ∘ isDot)) (listEq charEq)) files) ,
return $ and res
getCurrentDirectory : IO FilePath
getCurrentDirectory =
fromList <$> system "pwd"
main : IO Unit
main =
dir' <- getCurrentDirectory ,
putStrLn (fromList (fromString dir')) ,,
putStrLn "hello" ,,
putStrLn (fromList (tail ('h' :: 'e' :: 'j' :: []))) ,,
printList (fromString "hej igen") ,,
putStrLn (fromList (tail (fromString "hello"))) ,,
dir <- fromList ∘ init ∘ fromString <$> getCurrentDirectory ,
putStrLn dir ,,
system ("rm " +S+ dir +S+ "/tests/*.agdai") ,,
res <- testFiles (dir +S+ "/tests/") ,
(if res
then putStrLn "All tests succeeded! "
else putStrLn "Not all tests succeeded ")
| {
"alphanum_fraction": 0.5562684238,
"avg_line_length": 31.3423913043,
"ext": "agda",
"hexsha": "57b488aa066f504f645028c0c1dac9087970d3cf",
"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/epic/RunTests.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/epic/RunTests.agda",
"max_line_length": 136,
"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/epic/RunTests.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1805,
"size": 5767
} |
-- ----------------------------------------------------------------------
-- The Agda σ-library
--
-- Renamings
-- ----------------------------------------------------------------------
-- A renaming is defined as a substitution ρ, mapping
-- indices to indices (w/ explicit bounds). It is a subclass
-- of substitutions.
--
-- The σ-library provides renamings as primitives.
module Sigma.Renaming.Base where
open import Data.Nat using (ℕ; suc; zero; _+_)
open import Data.Fin using (Fin; zero; suc)
open import Function as Fun using (_∘_)
open import Data.Product using (_×_; proj₁; proj₂) renaming (_,_ to ⟨_,_⟩)
open import Sigma.Subst.Base using (Sub; _∷_; []; _++_)
-- ------------------------------------------------------------------------
-- A renaming ρ : 𝕀ⁿ → 𝕀ᵐ is denoted { i ↦ j : i ∈ 𝕀ⁿ, j ∈ 𝕀ᵐ }
Ren : ℕ → ℕ → Set
Ren m n = Sub (Fin n) m
space : ∀ { m n } → Ren m n → ℕ × ℕ
space { m } { n } _ = ⟨ m , n ⟩
dom : ∀ { m n } → Ren m n → ℕ
dom = proj₁ ∘ space
rng : ∀ { m n } → Ren m n → ℕ
rng = proj₂ ∘ space
-- Identity renaming idₙ : 𝕀ⁿ → 𝕀ⁿ.
-- Defined by idₙ = { i ↦ i : i ∈ 𝕀ⁿ }.
id : ∀ { n } → Ren n n
id = Fun.id
-- Shift operator ↑ₙ : 𝕀ⁿ → 𝕀ⁿ⁺¹
-- Defined by ↑ₙ i = 1 + i
↑ : ∀ { n } → Ren n (1 + n)
↑ = suc
infix 10 _⇑
-- Lift operator ρ ⇑
-- Defined by ρ ⇑ = { 0 ↦ 0 } ∪ { ↑ i ↦ ↑ j : i ∈ 𝕀ⁿ, j ∈ 𝕀ᵐ }
-- This operator is used for defining a capture avoiding renaming.
--
-- For example in λ. e, free variables of e are now shifted:
-- e : 0 1 2
-- λ e : 0 1 2 3
-- since λ binds 0.
_⇑ : ∀ { m n } → Ren m n → Ren (1 + m) (1 + n)
ρ ⇑ = zero ∷ ↑ ∘ ρ
-- ------------------------------------------------------------------------
-- Generalizing the above primitives to "multi-variable binders"
-- allows for formalization of binders that bind multiple variables,
-- such as patterns. So-called multi-variate binders.
-- Multi-variate identity idₙᵐ : 𝕀ᵐ → 𝕀ᵐ⁺ⁿ
-- Defined by idₙᵐ = { i ↦ i' : i ∈ 𝕀ᵐ, i' ∈ 𝕀ᵐ⁺ⁿ, i = i' }.
--
-- For example:
-- id✶ 1 = 0 ∷ []ₙ
-- id✶ 2 = 0 ∷ ↑ ∘ (0 ∷ []) = 0 ∷ 1 ∷ []ₙ
-- id✶ 3 = 0 ∷ ↑ ∘ id✶ 2 = 0 ∷ 1 ∷ 2 ∷ []ₙ
id✶ : ∀ { n } m → Ren m (m + n)
id✶ zero = []
id✶ (suc m) = zero ∷ ↑ ∘ id✶ m
-- Multi-variate shift operator ↑ₙᵐ : 𝕀ⁿ → 𝕀ᵐ⁺ⁿ
-- Defined by ↑ₙᵐ = { i ↦ m + i : i ∈ 𝕀ⁿ }
↑✶_ : ∀ { n } k → Ren n (k + n)
↑✶ zero = id
↑✶ suc k = ↑ ∘ ↑✶ k
-- Multi-variate lift operator ρ ⇑ᵏ
-- Defined by ρ ⇑ᵏ = { i ↦ i' } ∪ { ↑ᵏ i ↦ ↑ᵏ j : i ∈ 𝕀ⁿ, j ∈ 𝕀ᵐ }
-- This operator is used for defining a multi-variate capture avoiding renaming.
--
-- For example in λ. e, free variables of e are now shifted by k:
-- e : 0 1 2 3
-- λ e : 0 ... k k + 1 k + 2 k + 3
-- since λ binds 0, ..., k - 1.
_⇑✶_ : ∀ { m n } → Ren m n → ∀ k → Ren (k + m) (k + n)
ρ ⇑✶ k = id✶ k ++ (↑✶ k ∘ ρ)
| {
"alphanum_fraction": 0.4711332858,
"avg_line_length": 29.5368421053,
"ext": "agda",
"hexsha": "9461249e6351e301f212cf7ad279fd9d51f657fe",
"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": "bb895fa8a3ccbefbd2c4a135c79744ba06895be7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "johnyob/agda-sigma",
"max_forks_repo_path": "src/Sigma/Renaming/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bb895fa8a3ccbefbd2c4a135c79744ba06895be7",
"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-sigma",
"max_issues_repo_path": "src/Sigma/Renaming/Base.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bb895fa8a3ccbefbd2c4a135c79744ba06895be7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "johnyob/agda-sigma",
"max_stars_repo_path": "src/Sigma/Renaming/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1138,
"size": 2806
} |
------------------------------------------------------------------------
-- Isomorphism of monoids on sets coincides with equality (assuming
-- univalence)
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
-- This module has been developed in collaboration with Thierry
-- Coquand.
open import Equality
module Univalence-axiom.Isomorphism-is-equality.Monoid
{reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where
open import Bijection eq using (_↔_; Σ-≡,≡↔≡; ↑↔)
open Derived-definitions-and-properties eq
open import Equivalence eq as Eq using (_≃_)
open import Function-universe eq hiding (id)
open import H-level eq
open import H-level.Closure eq
open import Prelude hiding (id)
open import Univalence-axiom eq
-- Monoid laws (including the assumption that the carrier type is a
-- set).
Is-monoid : (C : Type) → (C → C → C) → C → Type
Is-monoid C _∙_ id =
-- C is a set.
Is-set C ×
-- Left and right identity laws.
(∀ x → (id ∙ x) ≡ x) ×
(∀ x → (x ∙ id) ≡ x) ×
-- Associativity.
(∀ x y z → (x ∙ (y ∙ z)) ≡ ((x ∙ y) ∙ z))
-- Monoids (on sets).
Monoid : Type₁
Monoid =
-- Carrier.
Σ Type λ C →
-- Binary operation.
Σ (C → C → C) λ _∙_ →
-- Identity.
Σ C λ id →
-- Laws.
Is-monoid C _∙_ id
-- The carrier type.
Carrier : Monoid → Type
Carrier M = proj₁ M
-- The binary operation.
op : (M : Monoid) → Carrier M → Carrier M → Carrier M
op M = proj₁ (proj₂ M)
-- The identity element.
id : (M : Monoid) → Carrier M
id M = proj₁ (proj₂ (proj₂ M))
-- The monoid laws.
laws : (M : Monoid) → Is-monoid (Carrier M) (op M) (id M)
laws M = proj₂ (proj₂ (proj₂ M))
-- Monoid morphisms.
Is-homomorphism :
(M₁ M₂ : Monoid) → (Carrier M₁ → Carrier M₂) → Type
Is-homomorphism M₁ M₂ f =
(∀ x y → f (op M₁ x y) ≡ op M₂ (f x) (f y)) ×
(f (id M₁) ≡ id M₂)
-- Monoid isomorphisms.
_≅_ : Monoid → Monoid → Type
M₁ ≅ M₂ =
Σ (Carrier M₁ ↔ Carrier M₂) λ f →
Is-homomorphism M₁ M₂ (_↔_.to f)
-- The monoid laws are propositional (assuming extensionality).
laws-propositional :
Extensionality (# 0) (# 0) →
(M : Monoid) →
Is-proposition (Is-monoid (Carrier M) (op M) (id M))
laws-propositional ext M =
×-closure 1 (H-level-propositional ext 2)
(×-closure 1 (Π-closure ext 1 λ _ →
is-set)
(×-closure 1 (Π-closure ext 1 λ _ →
is-set)
(Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
is-set)))
where is-set = proj₁ (laws M)
-- Monoid equality is isomorphic to equality of the carrier sets,
-- binary operations and identity elements, suitably transported
-- (assuming extensionality).
equality-triple-lemma :
Extensionality (# 0) (# 0) →
(M₁ M₂ : Monoid) →
M₁ ≡ M₂ ↔
Σ (Carrier M₁ ≡ Carrier M₂) λ C-eq →
subst (λ C → C → C → C) C-eq (op M₁) ≡ op M₂ ×
subst (λ C → C) C-eq (id M₁) ≡ id M₂
equality-triple-lemma
ext (C₁ , op₁ , id₁ , laws₁) (C₂ , op₂ , id₂ , laws₂) =
((C₁ , op₁ , id₁ , laws₁) ≡ (C₂ , op₂ , id₂ , laws₂)) ↔⟨ inverse $ Eq.≃-≡ $ Eq.↔⇒≃ bij ⟩
(((C₁ , op₁ , id₁) , laws₁) ≡ ((C₂ , op₂ , id₂) , laws₂)) ↝⟨ inverse $ ignore-propositional-component $
laws-propositional ext (C₂ , op₂ , id₂ , laws₂) ⟩
((C₁ , op₁ , id₁) ≡ (C₂ , op₂ , id₂)) ↝⟨ inverse Σ-≡,≡↔≡ ⟩
(Σ (C₁ ≡ C₂) λ C-eq →
subst (λ C → (C → C → C) × C) C-eq (op₁ , id₁) ≡ (op₂ , id₂)) ↝⟨ ∃-cong (λ _ → ≡⇒↝ _ $ cong (λ x → x ≡ _) $
push-subst-, (λ C → C → C → C) (λ C → C)) ⟩
(Σ (C₁ ≡ C₂) λ C-eq →
(subst (λ C → C → C → C) C-eq op₁ , subst (λ C → C) C-eq id₁) ≡
(op₂ , id₂)) ↝⟨ ∃-cong (λ _ → inverse ≡×≡↔≡) ⟩□
(Σ (C₁ ≡ C₂) λ C-eq →
subst (λ C → C → C → C) C-eq op₁ ≡ op₂ ×
subst (λ C → C) C-eq id₁ ≡ id₂) □
where
bij =
(Σ Type λ C → Σ (C → C → C) λ op → Σ C λ id → Is-monoid C op id) ↝⟨ ∃-cong (λ _ → Σ-assoc) ⟩
(Σ Type λ C → Σ ((C → C → C) × C) λ { (op , id) →
Is-monoid C op id }) ↝⟨ Σ-assoc ⟩□
(Σ (Σ Type λ C → (C → C → C) × C) λ { (C , op , id) →
Is-monoid C op id }) □
-- If two monoids are isomorphic, then they are equal (assuming
-- univalence).
isomorphic-equal :
Univalence (# 0) →
Univalence (# 1) →
(M₁ M₂ : Monoid) → M₁ ≅ M₂ → M₁ ≡ M₂
isomorphic-equal univ univ₁ M₁ M₂ (bij , bij-op , bij-id) = goal
where
open _≃_
-- Our goal:
goal : M₁ ≡ M₂
-- Extensionality follows from univalence.
ext : Extensionality (# 0) (# 0)
ext = dependent-extensionality univ₁ univ
-- Hence the goal follows from monoids-equal-if, if we can prove
-- three equalities.
C-eq : Carrier M₁ ≡ Carrier M₂
op-eq : subst (λ A → A → A → A) C-eq (op M₁) ≡ op M₂
id-eq : subst (λ A → A) C-eq (id M₁) ≡ id M₂
goal = _↔_.from (equality-triple-lemma ext M₁ M₂)
(C-eq , op-eq , id-eq)
-- Our bijection can be converted into an equivalence.
equiv : Carrier M₁ ≃ Carrier M₂
equiv = Eq.↔⇒≃ bij
-- Hence the first equality follows directly from univalence.
C-eq = ≃⇒≡ univ equiv
-- For the second equality, let us first define a "cast" operator.
cast₂ : {A B : Type} → A ≃ B → (A → A → A) → (B → B → B)
cast₂ eq f = λ x y → to eq (f (from eq x) (from eq y))
-- The transport theorem implies that cast₂ equiv can be expressed
-- using subst.
cast₂-equiv-is-subst :
∀ f → cast₂ equiv f ≡ subst (λ A → A → A → A) C-eq f
cast₂-equiv-is-subst f =
transport-theorem (λ A → A → A → A) cast₂ refl univ equiv f
-- The second equality op-eq follows from extensionality,
-- cast₂-equiv-is-subst, and the fact that the bijection is a
-- monoid homomorphism.
op-eq = apply-ext ext λ x → apply-ext ext λ y →
subst (λ A → A → A → A) C-eq (op M₁) x y ≡⟨ cong (λ f → f x y) $ sym $ cast₂-equiv-is-subst (op M₁) ⟩
to equiv (op M₁ (from equiv x) (from equiv y)) ≡⟨ bij-op (from equiv x) (from equiv y) ⟩
op M₂ (to equiv (from equiv x)) (to equiv (from equiv y)) ≡⟨ cong₂ (op M₂) (right-inverse-of equiv x) (right-inverse-of equiv y) ⟩∎
op M₂ x y ∎
-- The development above can be repeated for the identity
-- elements.
cast₀ : {A B : Type} → A ≃ B → A → B
cast₀ eq x = to eq x
cast₀-equiv-is-subst : ∀ x → cast₀ equiv x ≡ subst (λ A → A) C-eq x
cast₀-equiv-is-subst x =
transport-theorem (λ A → A) cast₀ refl univ equiv x
id-eq =
subst (λ A → A) C-eq (id M₁) ≡⟨ sym $ cast₀-equiv-is-subst (id M₁) ⟩
to equiv (id M₁) ≡⟨ bij-id ⟩∎
id M₂ ∎
-- Equality of monoids is in fact in bijective correspondence with
-- isomorphism of monoids (assuming univalence).
isomorphism-is-equality :
Univalence (# 0) →
Univalence (# 1) →
(M₁ M₂ : Monoid) → (M₁ ≅ M₂) ↔ (M₁ ≡ M₂)
isomorphism-is-equality univ univ₁
(C₁ , op₁ , id₁ , laws₁) (C₂ , op₂ , id₂ , laws₂) =
(Σ (C₁ ↔ C₂) λ f → Is-homomorphism M₁ M₂ (_↔_.to f)) ↝⟨ Σ-cong (Eq.↔↔≃ ext C₁-set) (λ _ → _ □) ⟩
(Σ (C₁ ≃ C₂) λ C-eq → Is-homomorphism M₁ M₂ (_≃_.to C-eq)) ↝⟨ ∃-cong (λ C-eq → op-lemma C-eq ×-cong id-lemma C-eq) ⟩
(Σ (C₁ ≃ C₂) λ C-eq →
subst (λ C → C → C → C) (≃⇒≡ univ C-eq) op₁ ≡ op₂ ×
subst (λ C → C) (≃⇒≡ univ C-eq) id₁ ≡ id₂) ↝⟨ inverse $ Σ-cong (≡≃≃ univ) (λ C-eq → ≡⇒↝ _ $
cong (λ eq → subst (λ C → C → C → C) eq op₁ ≡ op₂ ×
subst (λ C → C) eq id₁ ≡ id₂) $ sym $
_≃_.left-inverse-of (≡≃≃ univ) C-eq) ⟩
(Σ (C₁ ≡ C₂) λ C-eq →
subst (λ C → C → C → C) C-eq op₁ ≡ op₂ ×
subst (λ C → C) C-eq id₁ ≡ id₂) ↝⟨ inverse $ equality-triple-lemma ext M₁ M₂ ⟩
((C₁ , op₁ , id₁ , laws₁) ≡ (C₂ , op₂ , id₂ , laws₂)) □
where
-- The two monoids.
M₁ = (C₁ , op₁ , id₁ , laws₁)
M₂ = (C₂ , op₂ , id₂ , laws₂)
-- Extensionality follows from univalence.
ext : Extensionality (# 0) (# 0)
ext = dependent-extensionality univ₁ univ
-- C₁ is a set.
C₁-set : Is-set C₁
C₁-set = proj₁ laws₁
module _ (C-eq : C₁ ≃ C₂) where
open _≃_ C-eq
-- Two component lemmas.
op-lemma :
(∀ x y → to (op₁ x y) ≡ op₂ (to x) (to y)) ↔
subst (λ C → C → C → C) (≃⇒≡ univ C-eq) op₁ ≡ op₂
op-lemma =
(∀ x y → to (op₁ x y) ≡ op₂ (to x) (to y)) ↔⟨ ∀-cong ext (λ _ → Eq.extensionality-isomorphism ext) ⟩
(∀ x → (λ y → to (op₁ x y)) ≡ (λ y → op₂ (to x) (to y))) ↝⟨ ∀-cong ext (λ _ → inverse $ ∘from≡↔≡∘to ext C-eq) ⟩
(∀ x → (λ y → to (op₁ x (from y))) ≡ (λ y → op₂ (to x) y)) ↔⟨ Eq.extensionality-isomorphism ext ⟩
((λ x y → to (op₁ x (from y))) ≡ (λ x y → op₂ (to x) y)) ↝⟨ inverse $ ∘from≡↔≡∘to ext C-eq ⟩
((λ x y → to (op₁ (from x) (from y))) ≡ (λ x y → op₂ x y)) ↝⟨ ≡⇒↝ _ $ cong (λ o → o ≡ op₂) $
transport-theorem
(λ C → C → C → C)
(λ eq f x y → _≃_.to eq (f (_≃_.from eq x) (_≃_.from eq y)))
refl univ C-eq op₁ ⟩
(subst (λ C → C → C → C) (≃⇒≡ univ C-eq) op₁ ≡ op₂) □
id-lemma : (to id₁ ≡ id₂) ↔
(subst (λ C → C) (≃⇒≡ univ C-eq) id₁ ≡ id₂)
id-lemma =
(to id₁ ≡ id₂) ↝⟨ ≡⇒↝ _ $ cong (λ i → i ≡ id₂) $
transport-theorem (λ C → C) _≃_.to refl univ C-eq id₁ ⟩□
(subst (λ C → C) (≃⇒≡ univ C-eq) id₁ ≡ id₂) □
-- Equality of monoids is thus equal to equality (assuming
-- univalence).
isomorphism-is-equal-to-equality :
Univalence (# 0) →
Univalence (# 1) →
(M₁ M₂ : Monoid) → ↑ _ (M₁ ≅ M₂) ≡ (M₁ ≡ M₂)
isomorphism-is-equal-to-equality univ univ₁ M₁ M₂ =
≃⇒≡ univ₁ $ Eq.↔⇒≃ (
↑ _ (M₁ ≅ M₂) ↝⟨ ↑↔ ⟩
(M₁ ≅ M₂) ↝⟨ isomorphism-is-equality univ univ₁ M₁ M₂ ⟩□
(M₁ ≡ M₂) □)
| {
"alphanum_fraction": 0.4855414855,
"avg_line_length": 33.38170347,
"ext": "agda",
"hexsha": "361dc9bfb991a9738c8247764865ff682c25019e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/Univalence-axiom/Isomorphism-is-equality/Monoid.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/Univalence-axiom/Isomorphism-is-equality/Monoid.agda",
"max_line_length": 136,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/Univalence-axiom/Isomorphism-is-equality/Monoid.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 3964,
"size": 10582
} |
module Haskell.Prim.Char where
open import Agda.Builtin.IO
open import Agda.Builtin.String
open import Agda.Builtin.Char
open import Agda.Builtin.Bool
open import Agda.Builtin.Int using (pos; negsuc)
open import Haskell.Prim
open import Haskell.Prim.Int
open import Haskell.Prim.Integer
open import Haskell.Prim.Enum
open import Haskell.Prim.Real
ord : Char -> Int
ord c = fromEnum ((pos ∘ primCharToNat) c)
chr1 : Integer -> Char
chr1 (pos n) = primNatToChar n
chr1 _ = '_'
chr : Int -> Char
chr n = chr1 (toInteger n)
| {
"alphanum_fraction": 0.7518939394,
"avg_line_length": 22,
"ext": "agda",
"hexsha": "d6aa93f7a8446cb034adf06ebfb31de10424303e",
"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": "17cdbeb36af3d0b735c5db83bb811034c39a19cd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ioanasv/agda2hs",
"max_forks_repo_path": "lib/Haskell/Prim/Char.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "17cdbeb36af3d0b735c5db83bb811034c39a19cd",
"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": "ioanasv/agda2hs",
"max_issues_repo_path": "lib/Haskell/Prim/Char.agda",
"max_line_length": 48,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "17cdbeb36af3d0b735c5db83bb811034c39a19cd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ioanasv/agda2hs",
"max_stars_repo_path": "lib/Haskell/Prim/Char.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-25T09:41:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-05-25T09:41:34.000Z",
"num_tokens": 152,
"size": 528
} |
module TestLib where
import Lib.Bool
import Lib.Eq
import Lib.Fin
import Lib.IO
import Lib.Id
import Lib.List
import Lib.Logic
import Lib.Maybe
import Lib.Monad
import Lib.Nat
import Lib.Prelude
import Lib.Vec
| {
"alphanum_fraction": 0.8028169014,
"avg_line_length": 12.5294117647,
"ext": "agda",
"hexsha": "96ce87f4921a1264f91edd7af82bb64d38870641",
"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": "examples/simple-lib/TestLib.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": "examples/simple-lib/TestLib.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": "examples/simple-lib/TestLib.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": 59,
"size": 213
} |
module UniDB.Morph.Shift where
open import UniDB.Spec
open import UniDB.Morph.Depth
open import UniDB.Morph.Weaken
--------------------------------------------------------------------------------
data Shift : MOR where
shift : {γ₁ γ₂ : Dom} (ξ : Depth Weaken γ₁ γ₂) → Shift γ₁ γ₂
instance
iUpShift : Up Shift
_↑₁ {{iUpShift}} (shift ζ) = shift (ζ ↑₁)
_↑_ {{iUpShift}} ξ 0 = ξ
_↑_ {{iUpShift}} ξ (suc δ⁺) = ξ ↑ δ⁺ ↑₁
↑-zero {{iUpShift}} ξ = refl
↑-suc {{iUpShift}} ξ δ⁺ = refl
iWkmShift : Wkm Shift
wkm {{iWkmShift}} δ = shift (depth (weaken δ) 0)
iIdmShift : Idm Shift
idm {{iIdmShift}} _ = wkm {Shift} 0
module _ {T : STX} {{vrT : Vr T}} where
instance
iLkShift : Lk T Shift
lk {{iLkShift}} (shift ζ) i = vr {T} (lk {Ix} {Depth Weaken} ζ i)
iLkUpShift : {{wkT : Wk T}} {{wkVrT : WkVr T}} → LkUp T Shift
lk-↑₁-zero {{iLkUpShift}} (shift ξ) = cong (vr {T}) (lk-↑₁-zero {Ix} {_} ξ )
lk-↑₁-suc {{iLkUpShift}} (shift ξ) i = begin
vr {T} (lk {Ix} (ξ ↑₁) (suc i)) ≡⟨ cong (vr {T}) (lk-↑₁-suc ξ i) ⟩
vr {T} (wk₁ {Ix} (lk {Ix} ξ i)) ≡⟨ sym (wk₁-vr {T} (lk {Ix} ξ i)) ⟩
wk₁ {T} (vr {T} (lk {Ix} ξ i)) ∎
iLkWkmShift : LkWkm T Shift
lk-wkm {{iLkWkmShift}} δ i = refl
iLkIdmShift : LkIdm T Shift
lk-idm {{iLkIdmShift}} i = refl
module _ {T : STX} {{vrT : Vr T}} where
instance
iLkRenShift : LkRen T Shift
lk-ren {{iLkRenShift}} (shift ξ) i = refl
--------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.5078947368,
"avg_line_length": 28.679245283,
"ext": "agda",
"hexsha": "5dca3e98447e25ba249730d37cdbf2e86ccca8de",
"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": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "skeuchel/unidb-agda",
"max_forks_repo_path": "UniDB/Morph/Shift.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"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": "skeuchel/unidb-agda",
"max_issues_repo_path": "UniDB/Morph/Shift.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "skeuchel/unidb-agda",
"max_stars_repo_path": "UniDB/Morph/Shift.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 634,
"size": 1520
} |
------------------------------------------------------------------------------
-- Subtraction using the fixed-point operator
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.LTC-PCF.Data.Nat.SubtractionFixedPointOperator where
open import Common.FOL.Relation.Binary.EqReasoning
open import LTC-PCF.Base
open import LTC-PCF.Base.Properties
-- We add 3 to the fixities of the Agda standard library 0.8.1 (see
-- Data/Nat.agda).
infixl 9 _∸_
------------------------------------------------------------------------------
-- Subtraction's definition
∸-helper : D → D
∸-helper f = lam (λ m → lam (λ n →
if (iszero₁ n)
then m
else if (iszero₁ m)
then zero
else f · pred₁ m · pred₁ n))
_∸_ : D → D → D
_∸_ m n = fix ∸-helper · m · n
------------------------------------------------------------------------------
-- Conversion rules from the Agda standard library 0.8.1 (see
-- Data/Nat.agda) without use induction.
private
----------------------------------------------------------------------------
-- The steps
-- See doc in LTC-PCF.Program.GCD.Total.Equations.
-- Initially, the conversion rule fix-eq is applied.
∸-s₁ : D → D → D
∸-s₁ m n = ∸-helper (fix ∸-helper) · m · n
-- First argument application.
∸-s₂ : D → D
∸-s₂ m = lam (λ n →
if (iszero₁ n)
then m
else if (iszero₁ m)
then zero
else fix ∸-helper · pred₁ m · pred₁ n)
-- Second argument application.
∸-s₃ : D → D → D
∸-s₃ m n = if (iszero₁ n)
then m
else if (iszero₁ m)
then zero
else fix ∸-helper · pred₁ m · pred₁ n
-- First if_then_else_ iszero₁ n = b.
∸-s₄ : D → D → D → D
∸-s₄ m n b = if b
then m
else if (iszero₁ m)
then zero
else fix ∸-helper · pred₁ m · pred₁ n
-- First if_then_else_ when if true ...
∸-s₅ : D → D
∸-s₅ m = m
-- First if_then_else_ when if false ...
∸-s₆ : D → D → D
∸-s₆ m n = if (iszero₁ m)
then zero
else fix ∸-helper · pred₁ m · pred₁ n
-- Second if_then_else_ iszero₁ m = b.
∸-s₇ : D → D → D → D
∸-s₇ m n b = if b then zero else fix ∸-helper · pred₁ m · pred₁ n
-- Second if_then_else_ when if true ...
∸-s₈ : D
∸-s₈ = zero
-- Second if_then_else_ when if false ...
∸-s₉ : D → D → D
∸-s₉ m n = fix ∸-helper · pred₁ m · pred₁ n
----------------------------------------------------------------------------
-- Congruence properties
∸-s₄Cong₃ : ∀ {m n b₁ b₂} → b₁ ≡ b₂ → ∸-s₄ m n b₁ ≡ ∸-s₄ m n b₂
∸-s₄Cong₃ refl = refl
∸-s₇Cong₃ : ∀ {m n b₁ b₂} → b₁ ≡ b₂ → ∸-s₇ m n b₁ ≡ ∸-s₇ m n b₂
∸-s₇Cong₃ refl = refl
----------------------------------------------------------------------------
-- The execution steps
-- See doc in LTC-PCF.Program.GCD.Total.Equations.
proof₀₋₁ : ∀ m n → fix ∸-helper · m · n ≡ ∸-s₁ m n
proof₀₋₁ m n = subst (λ x → x · m · n ≡ ∸-helper (fix ∸-helper) · m · n)
(sym (fix-eq ∸-helper))
refl
proof₁₋₂ : ∀ m n → ∸-s₁ m n ≡ ∸-s₂ m · n
proof₁₋₂ m n = subst (λ x → x · n ≡ ∸-s₂ m · n)
(sym (beta ∸-s₂ m))
refl
proof₂₋₃ : ∀ m n → ∸-s₂ m · n ≡ ∸-s₃ m n
proof₂₋₃ m n = beta (∸-s₃ m) n
proof₃₋₄ : ∀ m n b → iszero₁ n ≡ b → ∸-s₃ m n ≡ ∸-s₄ m n b
proof₃₋₄ m n b = ∸-s₄Cong₃
proof₄₊ : ∀ m n → ∸-s₄ m n true ≡ ∸-s₅ m
proof₄₊ m _ = if-true (∸-s₅ m)
proof₄₋₆ : ∀ m n → ∸-s₄ m n false ≡ ∸-s₆ m n
proof₄₋₆ m n = if-false (∸-s₆ m n)
proof₆₋₇ : ∀ m n b → iszero₁ m ≡ b → ∸-s₆ m n ≡ ∸-s₇ m n b
proof₆₋₇ m n b = ∸-s₇Cong₃
proof₇₊ : ∀ m n → ∸-s₇ m n true ≡ ∸-s₈
proof₇₊ m n = if-true ∸-s₈
proof₇₋₉ : ∀ m n → ∸-s₇ m n false ≡ ∸-s₉ m n
proof₇₋₉ m n = if-false (∸-s₉ m n)
------------------------------------------------------------------------------
-- The equations for subtraction
∸-x0 : ∀ n → n ∸ zero ≡ n
∸-x0 n =
n ∸ zero ≡⟨ proof₀₋₁ n zero ⟩
∸-s₁ n zero ≡⟨ proof₁₋₂ n zero ⟩
∸-s₂ n · zero ≡⟨ proof₂₋₃ n zero ⟩
∸-s₃ n zero ≡⟨ proof₃₋₄ n zero true iszero-0 ⟩
∸-s₄ n zero true ≡⟨ proof₄₊ n zero ⟩
n ∎
∸-0S : ∀ n → zero ∸ succ₁ n ≡ zero
∸-0S n =
zero ∸ succ₁ n ≡⟨ proof₀₋₁ zero (succ₁ n) ⟩
∸-s₁ zero (succ₁ n) ≡⟨ proof₁₋₂ zero (succ₁ n) ⟩
∸-s₂ zero · (succ₁ n) ≡⟨ proof₂₋₃ zero (succ₁ n) ⟩
∸-s₃ zero (succ₁ n) ≡⟨ proof₃₋₄ zero (succ₁ n) false (iszero-S n) ⟩
∸-s₄ zero (succ₁ n) false ≡⟨ proof₄₋₆ zero (succ₁ n) ⟩
∸-s₆ zero (succ₁ n) ≡⟨ proof₆₋₇ zero (succ₁ n) true iszero-0 ⟩
∸-s₇ zero (succ₁ n) true ≡⟨ proof₇₊ zero (succ₁ n) ⟩
zero ∎
∸-SS : ∀ m n → succ₁ m ∸ succ₁ n ≡ m ∸ n
∸-SS m n =
succ₁ m ∸ succ₁ n
≡⟨ proof₀₋₁ (succ₁ m) (succ₁ n) ⟩
∸-s₁ (succ₁ m) (succ₁ n)
≡⟨ proof₁₋₂ (succ₁ m) (succ₁ n) ⟩
∸-s₂ (succ₁ m) · (succ₁ n)
≡⟨ proof₂₋₃ (succ₁ m) (succ₁ n) ⟩
∸-s₃ (succ₁ m) (succ₁ n)
≡⟨ proof₃₋₄ (succ₁ m) (succ₁ n) false (iszero-S n) ⟩
∸-s₄ (succ₁ m) (succ₁ n) false
≡⟨ proof₄₋₆ (succ₁ m) (succ₁ n) ⟩
∸-s₆ (succ₁ m) (succ₁ n)
≡⟨ proof₆₋₇ (succ₁ m) (succ₁ n) false (iszero-S m) ⟩
∸-s₇ (succ₁ m) (succ₁ n) false
≡⟨ proof₇₋₉ (succ₁ m) (succ₁ n) ⟩
fix ∸-helper · pred₁ (succ₁ m) · pred₁ (succ₁ n)
≡⟨ ·-rightCong (pred-S n) ⟩
fix ∸-helper · pred₁ (succ₁ m) · n
≡⟨ ·-leftCong (·-rightCong (pred-S m)) ⟩
fix ∸-helper · m · n ∎
| {
"alphanum_fraction": 0.4459924321,
"avg_line_length": 31.427027027,
"ext": "agda",
"hexsha": "3ddb757f359a80309cb2fbbf752151d0fdc2e531",
"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/LTC-PCF/Data/Nat/SubtractionFixedPointOperator.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/LTC-PCF/Data/Nat/SubtractionFixedPointOperator.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/LTC-PCF/Data/Nat/SubtractionFixedPointOperator.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": 2355,
"size": 5814
} |
{-# OPTIONS --type-in-type #-}
module examplesPaperJFP.agdaCodeBrady where
open import Data.List
open import Agda.Builtin.Unit public renaming (⊤ to Unit; tt to triv)
open import Data.Product
open import examplesPaperJFP.StateDependentIO
{- Brady's Effect -}
Effect : Set₁
Effect = (Result : Set) → (InResource : Set) → (OutResource : Result → Set) → Set
record MyEffect : Set₁ where
field Ops : Set
Result : Ops → Set
InResource : Ops → Set
OutResource : (o : Ops) → Result o → Set
open MyEffect
effectToIOInterfaceˢ : Effect → IOInterfaceˢ
Stateˢ (effectToIOInterfaceˢ eff) = Set
Commandˢ (effectToIOInterfaceˢ eff) s =
Σ[ Result ∈ Set ] (Σ[ outR ∈ (Result → Set) ] (eff Result s outR))
Responseˢ (effectToIOInterfaceˢ eff) s (result , outR , op) = result
nextˢ (effectToIOInterfaceˢ eff) s (result , outR , op) = outR
const : { A B : Set} → B → A → B
const b = λ _ → b
data EFFECT′ : Set₁ where
MkEff : Set → Effect → EFFECT′
EFFECT : Set₁
EFFECT = Set × Effect
data State : Effect where
Get : (a : Set) → State a a (λ _ → a)
Put : (a : Set) → (b : Set) → State a a (λ _ → b)
data myStateOps : Set₁ where
get : Set → myStateOps
put : Set → Set → myStateOps
myState : MyEffect
Ops myState = myStateOps
Result myState (get a) = a
InResource myState (get a) = a
OutResource myState (get a) _ = a
Result myState (put a b) = a
InResource myState (put a b) = a
OutResource myState (put a b) _ = b
STATE : Set → EFFECT
STATE x = ( x , State )
postulate String : Set
data Stdio : Effect where
PutStr : String → Stdio Unit Unit (const Unit)
GetStr : Stdio String String (const String)
STDIO : EFFECT
STDIO = ( Unit , Stdio )
data Eff : (x : Set) → List EFFECT → (x → List EFFECT) → Set where
get : (x : Set) → Eff x [ STATE x ] (const [ STATE x ])
put : (x : Set) → x → Eff Unit [ STATE x ] (const [ STATE x ])
putM : (x : Set) → (y : Set) → y → Eff Unit [ STATE x ] (const [ STATE y ])
update : (x : Set) → (x → x) → Eff Unit [ STATE x ] (const [ STATE x ])
data EffM : (m : Set → Set) → (res : Set) →
(inEffects : List EFFECT) →
(outEffects : res → List EFFECT)
→ Set where
_>>=_ : {m : Set → Set} → {res : Set} →
{inEffects : List EFFECT} →
{outEffects : res → List EFFECT} →
{res′ : Set} →
{inEffects′ : res → List EFFECT} →
{outEffects′ : res′ → List EFFECT} →
EffM m res inEffects outEffects →
((x : res) → EffM m res′ (inEffects′ x) outEffects′) →
EffM m res′ inEffects outEffects′
record SetInterfaceˢ : Set where
field Commandˢ′ : Set → Set
Responseˢ′ : (s : Set) → Commandˢ′ s → Set
nextˢ′ : (s : Set) → (c : Commandˢ′ s) → Responseˢ′ s c → Set
open SetInterfaceˢ
module _ (I : SetInterfaceˢ ) (let Stateˢ = Set)
(let C = Commandˢ′ I) (let R = Responseˢ′ I)
(let next = nextˢ′ I) where
handle : (M : Set → Set) → Set
handle M =
(A : Set) → (s : Stateˢ) → (c : C s) → (f : (r : R s c) → next s c r → M A) → M A
postulate Char : Set
| {
"alphanum_fraction": 0.569915914,
"avg_line_length": 30.0093457944,
"ext": "agda",
"hexsha": "16c54a140e7bd0e696f48439899fc018ae1043ee",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z",
"max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/ooAgda",
"max_forks_repo_path": "examples/examplesPaperJFP/agdaCodeBrady.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/ooAgda",
"max_issues_repo_path": "examples/examplesPaperJFP/agdaCodeBrady.agda",
"max_line_length": 88,
"max_stars_count": 23,
"max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/ooAgda",
"max_stars_repo_path": "examples/examplesPaperJFP/agdaCodeBrady.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z",
"num_tokens": 1092,
"size": 3211
} |
-- Andreas, Ulf, 2016-06-01, discussing issue #679
-- {-# OPTIONS -v tc.with.strip:20 #-}
postulate anything : {A : Set} → A
data Ty : Set where
_=>_ : (a b : Ty) → Ty
⟦_⟧ : Ty → Set
⟦ a => b ⟧ = ⟦ a ⟧ → ⟦ b ⟧
eq : (a : Ty) → ⟦ a ⟧ → ⟦ a ⟧ → Set
eq (a => b) f g = ∀ {x y : ⟦ a ⟧} → eq a x y → eq b (f x) (g y)
bad : (a : Ty) (x : ⟦ a ⟧) → eq a x x
bad (a => b) f h with b
bad (a => b) f h | _ = anything
-- ERROR WAS: Too few arguments in with clause!
-- Should work now.
| {
"alphanum_fraction": 0.4822546973,
"avg_line_length": 23.95,
"ext": "agda",
"hexsha": "102bb4a31a9912be7855a6fdf7b97af781fbaae6",
"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/Issue679u.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/Issue679u.agda",
"max_line_length": 63,
"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/Issue679u.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": 213,
"size": 479
} |
-- Andreas, 2014-09-23
-- Issue 1194, reported by marco.vax91, 2014-06-13
-- {-# OPTIONS -v scope.operators:50 #-}
module _ where
module A where
data D1 : Set where
c : D1
-- Just default notation for c here.
module B where
data D2 : Set where
c : A.D1 → D2
-- Interesting notation for c here.
syntax c x = ⟦ x ⟧
open A
open B
-- Since there is only one interesting notation for c in scope
-- we should be able to use it.
test : D2
test = ⟦ c ⟧
| {
"alphanum_fraction": 0.6392405063,
"avg_line_length": 15.2903225806,
"ext": "agda",
"hexsha": "f5e12eda90d452609ed9d6f6b7bb4cf4663ff336",
"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/Issue1194a.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/Issue1194a.agda",
"max_line_length": 62,
"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/Issue1194a.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": 158,
"size": 474
} |
{-
This second-order signature was created from the following second-order syntax description:
syntax CommGroup | CG
type
* : 0-ary
term
unit : * | ε
add : * * -> * | _⊕_ l20
neg : * -> * | ⊖_ r40
theory
(εU⊕ᴸ) a |> add (unit, a) = a
(εU⊕ᴿ) a |> add (a, unit) = a
(⊕A) a b c |> add (add(a, b), c) = add (a, add(b, c))
(⊖N⊕ᴸ) a |> add (neg (a), a) = unit
(⊖N⊕ᴿ) a |> add (a, neg (a)) = unit
(⊕C) a b |> add(a, b) = add(b, a)
-}
module CommGroup.Signature where
open import SOAS.Context
open import SOAS.Common
open import SOAS.Syntax.Signature *T public
open import SOAS.Syntax.Build *T public
-- Operator symbols
data CGₒ : Set where
unitₒ addₒ negₒ : CGₒ
-- Term signature
CG:Sig : Signature CGₒ
CG:Sig = sig λ
{ unitₒ → ⟼₀ *
; addₒ → (⊢₀ *) , (⊢₀ *) ⟼₂ *
; negₒ → (⊢₀ *) ⟼₁ *
}
open Signature CG:Sig public
| {
"alphanum_fraction": 0.5651672434,
"avg_line_length": 18.847826087,
"ext": "agda",
"hexsha": "0e9fc926a00b48028df26550ca2280dec6c99377",
"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/CommGroup/Signature.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/CommGroup/Signature.agda",
"max_line_length": 91,
"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/CommGroup/Signature.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": 379,
"size": 867
} |
-- {-# OPTIONS --safe #-}
module Language where
open import Map
open import Relation.Binary.PropositionalEquality
open import Data.String using (String)
open import Data.Nat
open import Data.Bool
open import Data.Maybe using (Maybe; just; nothing)
open import Agda.Builtin.Unit
open import Data.Empty
open import Relation.Nullary using (¬_)
open import Data.Product using (_×_)
open import Data.List
-- I separated this because of function calls
data VarId : Set where
Var : (x : String) → VarId
-- This is the language of expressions
data Aexp {A : Set} : Set where
_+`_ : ∀(x1 x2 : Aexp {A}) → Aexp
_-`_ : ∀(x1 x2 : Aexp {A}) → Aexp
_*`_ : ∀(x1 x2 : Aexp {A}) → Aexp
Avar : ∀(x : String) → Aexp
Anum : ∀(x : A) → Aexp
-- Type A should be comparable to 0
-- _/_ : ∀(x1 x2 : A) → (x2 ≡ 0) → Aexp
-- Special - for ℕ
_~-~_ : (a b : ℕ) → ℕ
zero ~-~ b = 0
suc a ~-~ b = a ~-~ b
-- Evaluation of Arithexp
aeval : (st : String → ℕ) → (exp : Aexp {ℕ}) → ℕ
aeval st (e +` e₁) = aeval st e + aeval st e₁
aeval st (e -` e₁) = aeval st e ~-~ aeval st e₁
aeval st (e *` e₁) = aeval st e * aeval st e₁
aeval st (Avar x) = st x
aeval st (Anum x) = x
-- This is the language of boolean expressions
data Bexp {A : Set} : Set where
TRUE : Bexp
FALSE : Bexp
_<`_ : ∀ (x1 x2 : Aexp {A}) → Bexp
_>`_ : ∀ (x1 x2 : Aexp {A}) → Bexp
_≤`_ : ∀ (x1 x2 : Aexp {A}) → Bexp
_≥`_ : ∀ (x1 x2 : Aexp {A}) → Bexp
_≡`_ : ∀ (x1 x2 : Aexp {A}) → Bexp
¬`_ : ∀ (b : Bexp {A}) → Bexp
_&&`_ : ∀ (b1 b2 : Bexp {A}) → Bexp
_||`_ : ∀ (b1 b2 : Bexp {A}) → Bexp
-- Bool evaluation for ℕ
beval : (st : String → ℕ) → (b : Bexp {ℕ}) → Bool
beval st TRUE = true
beval st FALSE = false
beval st (x1 <` x2) = let ql = aeval st x1 in
let qr = aeval st x2 in
((not ((ql ≤ᵇ qr) ∧ (qr ≤ᵇ ql))) ∧ (ql ≤ᵇ qr))
beval st (x1 >` x2) = let ql = aeval st x1 in
let qr = aeval st x2 in
((not ((ql ≤ᵇ qr) ∧ (qr ≤ᵇ ql))) ∧ (qr ≤ᵇ ql))
beval st (x1 ≤` x2) = let l = aeval st x1 in
let r = aeval st x2 in
l ≤ᵇ r
beval st (x1 ≥` x2) = let l = aeval st x1 in
let r = aeval st x2 in
r ≤ᵇ l
beval st (x1 ≡` x2) = let l = aeval st x1 in
let r = aeval st x2 in
(l ≤ᵇ r) ∧ (r ≤ᵇ l)
beval st (¬` b) = not (beval st b)
beval st (b &&` b₁) = beval st b ∧ beval st b₁
beval st (b ||` b₁) = beval st b ∨ beval st b₁
data ATuple : Set where
Arg : (v : String) → ATuple
_,`_ : (f : ATuple) → (n : ATuple) → ATuple
data RTuple : Set where
Ret : (v : String) → RTuple
_,`_ : (f : RTuple) → (n : RTuple) → RTuple
-- Make a list of RTuple
rtuple2list : RTuple → List (String)
rtuple2list (Ret v) = v ∷ []
rtuple2list (r ,` r₁) = rtuple2list r ++ rtuple2list r₁
-- Name of functions are in different namespace
data FuncCall {A : Set} : Set where
-- Calling a function
<_>:=_<_> : (ret : RTuple) → (f : String) →
(args : ATuple) → FuncCall
-- XXX: Note that the below allows writing code like
-- this: F()||F()//F()
_||`_ : (l r : FuncCall {A}) → FuncCall
-- _//`_ : (l r : FuncCall {A}) → FuncCall
-- This is the command language that we have
data Cmd {A : Set} : Set where
SKIP : Cmd
_:=_ : (l : VarId) → (r : Aexp {A}) → Cmd
_;_ : (c1 c2 : Cmd {A}) → Cmd
IF_THEN_ELSE_END : (b : Bexp {A}) → (t : Cmd {A}) →
(c : Cmd {A}) → Cmd
WHILE_DO_END : (b : Bexp {A}) → (bo : Cmd {A}) → Cmd
-- This makes calling the function a command
EXEC : FuncCall {A} → Cmd
-- This is defining a function
-- This should give state of type (f → Maybe (Ret strings, args string, Cmd))
-- This should be an eval function, not a relation
-- This will be called from funccall and go from st => st'
data FuncDef {A : Set} : Set where
-- Define a function/thread
DEF_<_>⇒<_>:_END : (f : String) → (ATuple)
→ (RTuple) → (c : Cmd {A}) → FuncDef
-- Toplevel
-- This should start from MAIN
-- This should be an topeval function KP => st
data Top {A : Set} : Set where
MAIN:_END : (c : Cmd {A}) → Top
_;_ : FuncDef {A} → (a : Top {A}) → Top
infix 22 _:=_
infixl 21 _;_
infixl 20 _||`_
-- infixl 20 _//`_
infixl 23 _-`_
infixl 23 _+`_
infixl 24 _*`_
infixl 25 _,`_ -- Highest precedence and left assoc
-- Example of a program with multiple functions
Main : Top
Main = DEF "Factorial" < Arg "K" >⇒< Ret "fact" ,` Ret "K" >:
Var "n" := Avar "K" ;
Var "fact" := Anum 1 ;
WHILE (Avar "n" >` Anum 0) DO
Var "fact" := Avar "fact" *` Avar "n" ;
Var "n" := Avar "n" -` Anum 1
END ;
Var "res" := Anum 0 ;
IF ((Avar "K" ≡` Anum 4) &&` (Avar "fact" ≡` Anum 24)) THEN
Var "res" := Anum 1
ELSE
Var "res" := Anum 0
END
END ;
MAIN:
Var "K" := Anum 4 ;
-- The below 2 have to be declared before being used
Var "fact" := Anum 0 ;
-- We should also have a tuple with each function/thread for
-- pre-post.
EXEC < Ret "fact" ,` Ret "K" >:= "Factorial" < Arg "K" >
END
-- Making the tuple type needed to hold the program
data ProgTuple {A : Set} : Set where
_,_,_ : (a : ATuple) → (r : RTuple) → (c : Cmd {A}) → ProgTuple
-- Getting stuff from the Progtuple
getProgCmd : {A : Set} → (p : Maybe (ProgTuple {A})) → Cmd {A}
getProgCmd (just (a , r , c)) = c
getProgCmd nothing = SKIP -- Dangerous
getProgArgs : {A : Set} → (p : Maybe (ProgTuple {A})) → ATuple
getProgArgs (just (a , r , c)) = a
getProgArgs nothing = Arg "VOID"
getProgRets : {A : Set} → (p : Maybe (ProgTuple {A})) → RTuple
getProgRets (just (a , r , c)) = r
getProgRets nothing = Ret "VOID"
-- Semantics from here
-- All stacks should come from point of function call
-- Here Γ is the caller' stack
data _,_-[_]->ᴬ_ {A : Set} (Γ : (String → ( A))) :
(String → ( A)) → (ATuple)
→ (String → A) → Set where
hd : ∀ (v : String) → ∀ (st : (String → A)) →
-- Γ v ≡ just vv → -- Make sure that Arg is in the caller' stack
-----------------------------------------------------------
Γ , st -[ Arg v ]->ᴬ (Store st v (Γ v))
tl : (l r : ATuple) → (st st' st'' : (String → A)) →
(Γ , st -[ l ]->ᴬ st') → (Γ , st' -[ r ]->ᴬ st'') →
-----------------------------------------------------------
Γ , st -[ (l ,` r) ]->ᴬ st''
-- Here Γ is the callee' stack
data _,_-[_]->ᴿ_ {A : Set}
(Γ : (String → A)) :
(String → A) → RTuple → (String → A)
→ Set where
hd : ∀ (v : String) → ∀ (v1 v2 : A) → ∀ (st : (String → A)) →
-- → Γ v ≡ just v1 → st v ≡ just v2 →
-- (_⊕_ : A → A → A) → ∀ (a b c : A) → (a ⊕ b ≡ b ⊕ a)
-- → ((a ⊕ b) ⊕ c ≡ a ⊕ (b ⊕ c)) →
-----------------------------------------------------------
Γ , st -[ Ret v ]->ᴿ (Store st v (Γ v))
-- Γ , st -[ Ret v ]->ᴿ (Store st v (Γ v ⊕ st v))
tl : ∀ (l r : RTuple) → (st st' st'' : (String → A)) →
(Γ , st -[ l ]->ᴿ st') → (Γ , st' -[ r ]->ᴿ st'') →
-----------------------------------------------------------
Γ , st -[ (l ,` r) ]->ᴿ st''
mutual
-- These are the relations for ℕ
data _,_=[_]=>_ (Γ : String → Maybe (ProgTuple {ℕ})) :
(String → ℕ) →
Cmd {ℕ} → (String → ℕ) →
Set where
CSKIP : ∀ (st : (String → ℕ)) →
-----------------------
Γ , st =[ SKIP ]=> st
CASSIGN : ∀ (st : (String → ℕ)) → ∀ (x : String) →
∀ (e : Aexp {ℕ}) →
-----------------------------------------------------------
Γ , st =[ Var x := e ]=> (Store st x (aeval st e))
CSEQ : ∀ (st st' st'' : (String → ℕ)) → ∀ (c1 c2 : Cmd {ℕ}) →
Γ , st =[ c1 ]=> st' →
Γ , st' =[ c2 ]=> st'' →
-----------------------------------------------------------
Γ , st =[ (c1 ; c2)]=> st''
CIFT : ∀ (st st' : (String → ℕ)) → (b : Bexp {ℕ}) →
(t e : Cmd {ℕ}) →
beval st b ≡ true →
Γ , st =[ t ]=> st' →
-----------------------------------------------------------
Γ , st =[ (IF b THEN t ELSE e END)]=> st'
CIFE : ∀ (st st' : (String → ℕ)) →
(b : Bexp {ℕ}) → (t e : Cmd {ℕ}) →
beval st b ≡ false →
Γ , st =[ e ]=> st' →
-----------------------------------------------------------
Γ , st =[ (IF b THEN t ELSE e END)]=> st'
CLF : (st : (String → ℕ)) →
(b : Bexp {ℕ}) → (c : Cmd {ℕ}) →
beval st b ≡ false →
-----------------------------------------------------------
Γ , st =[ (WHILE b DO c END) ]=> st
CLT : (st st' st'' : (String → ℕ)) →
(b : Bexp {ℕ}) → (c : Cmd {ℕ}) →
beval st b ≡ true →
Γ , st =[ c ]=> st' →
Γ , st' =[ (WHILE b DO c END) ]=> st'' →
-----------------------------------------------------------
Γ , st =[ (WHILE b DO c END) ]=> st''
-- XXX: Done.
CEX : ∀ (f : FuncCall {ℕ}) → ∀ (st st' : (String → ℕ))
→ Γ , st =[ f ]=>ᶠ st'
-----------------------------------------------------------
→ Γ , st =[ EXEC f ]=> st'
-- TODO: The function calls and definition with ℕ
data _,_=[_]=>ᶠ_ (Γ : String → (Maybe (ProgTuple {ℕ}))) :
(String → ℕ) → FuncCall {ℕ} → (String → ℕ)
→ Set where
Base : ∀ (fname : String) → -- name of the function
∀ (stm : String → ℕ) -- caller stack,
→ (stf' stf'' : String → ℕ) -- These are the pre-call and
-- post-call callee stack,
-- respectively.
→ (stm' : String → ℕ) -- The resultant caller stack
-- res of putting values on callee stack
→ stm , (K 0) -[ getProgArgs (Γ fname) ]->ᴬ stf'
-- result of running the function
→ Γ , stf' =[ getProgCmd (Γ fname) ]=> stf''
-- copying ret values back on caller' stack
→ stf'' , stm -[ getProgRets (Γ fname) ]->ᴿ stm'
-----------------------------------------------------------
→ Γ , stm =[ < getProgRets (Γ fname) >:=
fname < getProgArgs (Γ fname) > ]=>ᶠ stm'
-- XXX: The above needs to be extended to return a list of
-- fname with stm'. This will allow merge to be called in ||
-- and //
-- Doing the evaluation of top
evalProg : {A : Set} → (p : Top {A}) →
(st : String → Maybe (ProgTuple {A})) →
(String → Maybe (ProgTuple {A}))
evalProg MAIN: c END st = (StoreP st "MAIN" (Arg "void" , Ret "void" , c))
evalProg (DEF f < x >⇒< x1 >: c END ; p) st =
StoreP (evalProg p st) f (x , x1 , c)
-- Example of relation on ℕ
ex1 : ∀ (Γ : (String → Maybe ProgTuple)) → ∀ (st : (String → ℕ))
→ Γ , st =[ SKIP ]=> st
ex1 Γ st = CSKIP st
-- Hoare logic starts here!
{-# NO_POSITIVITY_CHECK #-}
-- XXX: Maybe later define another language for it?
-- Logical expressions with ℕ as relations (used for Hoare Propositions)
data _|=_ (st : String → ℕ) : Bexp {ℕ} → Set where
LT : ∀ (l r : Aexp {ℕ}) → (aeval st l) Data.Nat.< (aeval st r)
→ st |= (l <` r)
LE : ∀ (l r : Aexp {ℕ}) → (aeval st l) Data.Nat.≤ (aeval st r)
→ st |= (l ≤` r)
GT : ∀ (l r : Aexp {ℕ}) → (aeval st l) Data.Nat.> (aeval st r)
→ st |= (l >` r)
GE : ∀ (l r : Aexp {ℕ}) → (aeval st l) Data.Nat.≥ (aeval st r)
→ st |= (l ≥` r)
EQ : ∀ (l r : Aexp {ℕ}) → (aeval st l) ≡ (aeval st r)
→ st |= (l ≡` r)
TT : st |= TRUE
AND : ∀ (b1 b2 : Bexp {ℕ}) → (st |= b1) → (st |= b2)
→ st |= (b1 &&` b2)
ORL : ∀ (b1 b2 : Bexp {ℕ}) → (st |= b1) → (st |= (b1 ||` b2))
ORR : ∀ (b1 b2 : Bexp {ℕ}) → (st |= b2) → (st |= (b1 ||` b2))
-- XXX: Had to disable POSITIVITY_CHECK
NOT : ∀ (b : Bexp {ℕ}) → ((st |= b) → ⊥) → st |= (¬` b)
-- Assert with ℙrops
Assertℙ : ∀ (b : Bexp {ℕ}) → (String → ℕ) → Set
Assertℙ b st = st |= b
-- Defn of substitution rule with ℙrop
Subsℙ : ∀ (b : Bexp {ℕ}) -- b is my assertion
→ (X : String)
→ (e : Aexp {ℕ}) → (String → ℕ)
→ Set
Subsℙ b X e st = (Store st X (aeval st e)) |= b
getStates : ∀ (stf stm : String → ℕ) → ATuple → (String → ℕ)
getStates stf stm (Arg v) = Store stf v (stm v)
getStates stf stm (l ,` r) = getStates (getStates stf stm l) stm r
getStatesR : ∀ (stm stf : String → ℕ) → RTuple → (String → ℕ)
getStatesR stm stf (Ret v) = Store stm v (stf v)
getStatesR stm stf (rets ,` rets₁) = getStatesR (getStatesR stm stf rets) stf rets₁
-- Subs for the input arguments before calling a function
SubsArgs : ∀ (Q : Bexp {ℕ}) → (args : ATuple) → (stf stm : (String → ℕ))
→ Set
SubsArgs Q args stf stm = (getStates stf stm args) |= Q
-- Subs for the output rets after calling function
SubsRets : ∀ (R : Bexp {ℕ}) → (rets : RTuple) → (stm stf : (String → ℕ))
→ Set
SubsRets R rets stm stf = (getStatesR stm stf rets) |= R
-- Lemma for getStates
getstates-eq-lemma : ∀ (st stm st' : (String → ℕ)) → (args : ATuple)
→ stm , st -[ args ]->ᴬ st'
→ (getStates st stm args) ≡ st'
getstates-eq-lemma st stm .(Store st v (stm v)) (Arg v) (hd .v .st) = refl
getstates-eq-lemma st stm st' (args ,` args₁) (tl .args .args₁ .st st'' .st' cmd cmd₁) with
getstates-eq-lemma st stm st'' args cmd
... | refl = getstates-eq-lemma st'' stm st' args₁ cmd₁
-- Lemma for getStatesR
getstatesr-eq-lemma : ∀ (stm stf stm' : (String → ℕ)) → (rets : RTuple)
→ (stf , stm -[ rets ]->ᴿ stm')
→ (getStatesR stm stf rets) ≡ stm'
getstatesr-eq-lemma stm stf .(Store stm v (stf v)) .(Ret v) (hd v v1 v2 .stm) = refl
getstatesr-eq-lemma stm stf stm' .(l ,` r) (tl l r .stm st' .stm' cmd cmd₁) with
getstatesr-eq-lemma stm stf st' l cmd
... | refl = getstatesr-eq-lemma st' stf stm' r cmd₁
-- Now the soundness proof for SubsArgs
SubsArgs-theorem : ∀ (stf stm stf' : (String → ℕ)) → (Q : Bexp {ℕ})
→ (args : ATuple) → (P : SubsArgs Q args stf stm)
→ (cmd : stm , stf -[ args ]->ᴬ stf')
→ (stf' |= Q)
SubsArgs-theorem stf stm .(Store stf v (stm v)) .(l <` r) .(Arg v) (LT l r x) (hd v .stf) = LT l r x
SubsArgs-theorem stf stm .(Store stf v (stm v)) .(l ≤` r) .(Arg v) (LE l r x) (hd v .stf) = LE l r x
SubsArgs-theorem stf stm .(Store stf v (stm v)) .(l >` r) .(Arg v) (GT l r x) (hd v .stf) = GT l r x
SubsArgs-theorem stf stm .(Store stf v (stm v)) .(l ≥` r) .(Arg v) (GE l r x) (hd v .stf) = GE l r x
SubsArgs-theorem stf stm .(Store stf v (stm v)) .(l ≡` r) .(Arg v) (EQ l r x) (hd v .stf) = EQ l r x
SubsArgs-theorem stf stm .(Store stf v (stm v)) .TRUE .(Arg v) TT (hd v .stf) = TT
SubsArgs-theorem stf stm .(Store stf v (stm v)) .(b1 &&` b2) .(Arg v) (AND b1 b2 P P₁) (hd v .stf) = AND b1 b2 P P₁
SubsArgs-theorem stf stm .(Store stf v (stm v)) .(b1 ||` b2) .(Arg v) (ORL b1 b2 P) (hd v .stf) = ORL b1 b2 P
SubsArgs-theorem stf stm .(Store stf v (stm v)) .(b1 ||` b2) .(Arg v) (ORR b1 b2 P) (hd v .stf) = ORR b1 b2 P
SubsArgs-theorem stf stm .(Store stf v (stm v)) .(¬` b) .(Arg v) (NOT b x) (hd v .stf) = NOT b x
SubsArgs-theorem stf stm stf' .(l₁ <` r₁) .(l ,` r) (LT l₁ r₁ x) (tl l r .stf st' .stf' cmd cmd₁) rewrite
getstates-eq-lemma stf stm st' l cmd | getstates-eq-lemma st' stm stf' r cmd₁ = LT l₁ r₁ x
SubsArgs-theorem stf stm stf' .(l₁ ≤` r₁) .(l ,` r) (LE l₁ r₁ x) (tl l r .stf st' .stf' cmd cmd₁) rewrite
getstates-eq-lemma stf stm st' l cmd | getstates-eq-lemma st' stm stf' r cmd₁ = LE l₁ r₁ x
SubsArgs-theorem stf stm stf' .(l₁ >` r₁) .(l ,` r) (GT l₁ r₁ x) (tl l r .stf st' .stf' cmd cmd₁) rewrite
getstates-eq-lemma stf stm st' l cmd | getstates-eq-lemma st' stm stf' r cmd₁ = GT l₁ r₁ x
SubsArgs-theorem stf stm stf' .(l₁ ≥` r₁) .(l ,` r) (GE l₁ r₁ x) (tl l r .stf st' .stf' cmd cmd₁) rewrite
getstates-eq-lemma stf stm st' l cmd | getstates-eq-lemma st' stm stf' r cmd₁ = GE l₁ r₁ x
SubsArgs-theorem stf stm stf' .(l₁ ≡` r₁) .(l ,` r) (EQ l₁ r₁ x) (tl l r .stf st' .stf' cmd cmd₁) rewrite
getstates-eq-lemma stf stm st' l cmd | getstates-eq-lemma st' stm stf' r cmd₁ = EQ l₁ r₁ x
SubsArgs-theorem stf stm stf' .TRUE .(l ,` r) TT (tl l r .stf st' .stf' cmd cmd₁) = TT
SubsArgs-theorem stf stm stf' .(b1 &&` b2) .(l ,` r) (AND b1 b2 P P₁) (tl l r .stf st' .stf' cmd cmd₁) rewrite
getstates-eq-lemma stf stm st' l cmd | getstates-eq-lemma st' stm stf' r cmd₁ = AND b1 b2 P P₁
SubsArgs-theorem stf stm stf' .(b1 ||` b2) .(l ,` r) (ORL b1 b2 P) (tl l r .stf st' .stf' cmd cmd₁) rewrite
getstates-eq-lemma stf stm st' l cmd | getstates-eq-lemma st' stm stf' r cmd₁ = ORL b1 b2 P
SubsArgs-theorem stf stm stf' .(b1 ||` b2) .(l ,` r) (ORR b1 b2 P) (tl l r .stf st' .stf' cmd cmd₁) rewrite
getstates-eq-lemma stf stm st' l cmd | getstates-eq-lemma st' stm stf' r cmd₁ = ORR b1 b2 P
SubsArgs-theorem stf stm stf' .(¬` b) .(l ,` r) (NOT b x) (tl l r .stf st' .stf' cmd cmd₁) rewrite
getstates-eq-lemma stf stm st' l cmd | getstates-eq-lemma st' stm stf' r cmd₁ = NOT b x
-- The inductive case for concurrent function calls either (// or ||)
-- This thorem is saying that if the product (conjunction) of two
-- pre-conditions holds on the caller' stack then the pre-condition
-- holds for each of the Funccall in the concurrent execution.
-- TODO: The below theorem can be extended to N instead of just two
-- inductively with ease. Leaving it to two for now as proof of concept.
conc-pre-theorem : ∀ (stm stf1 stf1' stf2 stf2' : (String → ℕ))
→ ∀ (a1 a2 : ATuple)
→ (c1 : stm , stf1 -[ a1 ]->ᴬ stf1')
→ (c2 : stm , stf2 -[ a2 ]->ᴬ stf2')
→ ∀ (Q1 Q2 : Bexp {ℕ})
→ (SubsArgs Q1 a1 stf1 stm) × (SubsArgs Q2 a2 stf2 stm)
→ (stf1' |= Q1) × (stf2' |= Q2)
conc-pre-theorem stm stf1 stf1' stf2 stf2' a1 a2 c1 c2 Q1 Q2 (fst Data.Product., snd)
= (SubsArgs-theorem stf1 stm stf1' Q1 a1 fst c1) Data.Product.,
(SubsArgs-theorem stf2 stm stf2' Q2 a2 snd c2)
-- DONE: We do the same as Subsargs for ret but with stacks swapped
SubsRets-theorem : ∀ (stm stf stm' : (String → ℕ)) → (Q : Bexp {ℕ})
→ (rets : RTuple) → (P : SubsRets Q rets stm stf)
→ (cmd : stf , stm -[ rets ]->ᴿ stm')
→ (stm' |= Q)
SubsRets-theorem stm stf .(Store stm v (stf v)) .(l <` r) .(Ret v) (LT l r x) (hd v v1 v2 .stm) = LT l r x
SubsRets-theorem stm stf .(Store stm v (stf v)) .(l ≤` r) .(Ret v) (LE l r x) (hd v v1 v2 .stm) = LE l r x
SubsRets-theorem stm stf .(Store stm v (stf v)) .(l >` r) .(Ret v) (GT l r x) (hd v v1 v2 .stm) = GT l r x
SubsRets-theorem stm stf .(Store stm v (stf v)) .(l ≥` r) .(Ret v) (GE l r x) (hd v v1 v2 .stm) = GE l r x
SubsRets-theorem stm stf .(Store stm v (stf v)) .(l ≡` r) .(Ret v) (EQ l r x) (hd v v1 v2 .stm) = EQ l r x
SubsRets-theorem stm stf .(Store stm v (stf v)) .TRUE .(Ret v) TT (hd v v1 v2 .stm) = TT
SubsRets-theorem stm stf .(Store stm v (stf v)) .(b1 &&` b2) .(Ret v) (AND b1 b2 P P₁) (hd v v1 v2 .stm) =
AND b1 b2 P P₁
SubsRets-theorem stm stf .(Store stm v (stf v)) .(b1 ||` b2) .(Ret v) (ORL b1 b2 P) (hd v v1 v2 .stm) = ORL b1 b2 P
SubsRets-theorem stm stf .(Store stm v (stf v)) .(b1 ||` b2) .(Ret v) (ORR b1 b2 P) (hd v v1 v2 .stm) = ORR b1 b2 P
SubsRets-theorem stm stf .(Store stm v (stf v)) .(¬` b) .(Ret v) (NOT b x) (hd v v1 v2 .stm) = NOT b x
SubsRets-theorem stm stf stm' .(l₁ <` r₁) .(l ,` r) (LT l₁ r₁ x) (tl l r .stm st' .stm' cmd cmd₁) rewrite
getstatesr-eq-lemma stm stf st' l cmd | getstatesr-eq-lemma st' stf stm' r cmd₁ = LT l₁ r₁ x
SubsRets-theorem stm stf stm' .(l₁ ≤` r₁) .(l ,` r) (LE l₁ r₁ x) (tl l r .stm st' .stm' cmd cmd₁) rewrite
getstatesr-eq-lemma stm stf st' l cmd | getstatesr-eq-lemma st' stf stm' r cmd₁ = LE l₁ r₁ x
SubsRets-theorem stm stf stm' .(l₁ >` r₁) .(l ,` r) (GT l₁ r₁ x) (tl l r .stm st' .stm' cmd cmd₁) rewrite
getstatesr-eq-lemma stm stf st' l cmd | getstatesr-eq-lemma st' stf stm' r cmd₁ = GT l₁ r₁ x
SubsRets-theorem stm stf stm' .(l₁ ≥` r₁) .(l ,` r) (GE l₁ r₁ x) (tl l r .stm st' .stm' cmd cmd₁) rewrite
getstatesr-eq-lemma stm stf st' l cmd | getstatesr-eq-lemma st' stf stm' r cmd₁ = GE l₁ r₁ x
SubsRets-theorem stm stf stm' .(l₁ ≡` r₁) .(l ,` r) (EQ l₁ r₁ x) (tl l r .stm st' .stm' cmd cmd₁) rewrite
getstatesr-eq-lemma stm stf st' l cmd | getstatesr-eq-lemma st' stf stm' r cmd₁ = EQ l₁ r₁ x
SubsRets-theorem stm stf stm' .TRUE .(l ,` r) TT (tl l r .stm st' .stm' cmd cmd₁) = TT
SubsRets-theorem stm stf stm' .(b1 &&` b2) .(l ,` r) (AND b1 b2 P P₁) (tl l r .stm st' .stm' cmd cmd₁) rewrite
getstatesr-eq-lemma stm stf st' l cmd | getstatesr-eq-lemma st' stf stm' r cmd₁ = AND b1 b2 P P₁
SubsRets-theorem stm stf stm' .(b1 ||` b2) .(l ,` r) (ORL b1 b2 P) (tl l r .stm st' .stm' cmd cmd₁) rewrite
getstatesr-eq-lemma stm stf st' l cmd | getstatesr-eq-lemma st' stf stm' r cmd₁ = ORL b1 b2 P
SubsRets-theorem stm stf stm' .(b1 ||` b2) .(l ,` r) (ORR b1 b2 P) (tl l r .stm st' .stm' cmd cmd₁) rewrite
getstatesr-eq-lemma stm stf st' l cmd | getstatesr-eq-lemma st' stf stm' r cmd₁ = ORR b1 b2 P
SubsRets-theorem stm stf stm' .(¬` b) .(l ,` r) (NOT b x) (tl l r .stm st' .stm' cmd cmd₁) rewrite
getstatesr-eq-lemma stm stf st' l cmd | getstatesr-eq-lemma st' stf stm' r cmd₁ = NOT b x
-- FIXME: The post condition is being proved only for 2 concurrent
-- calls, but can be easily extended to N using an inductive
-- data-structure.
conc-post-lemma : ∀ (stf1 stf2 stm1 stm1' stm2 stm2' : (String → ℕ)) → (Q1 Q2 : Bexp {ℕ})
→ (r1 r2 : RTuple)
→ (c1 : stf1 , stm1 -[ r1 ]->ᴿ stm1')
→ (c2 : stf2 , stm2 -[ r2 ]->ᴿ stm2')
→ (SubsRets Q1 r1 stm1 stf1) × (SubsRets Q2 r2 stm2 stf2)
→ (stm1' |= Q1 × stm2' |= Q2)
conc-post-lemma stf1 stf2 stm1 stm1' stm2 stm2' Q1 Q2 r1 r2 c1 c2 (fst Data.Product., snd) =
(SubsRets-theorem stm1 stf1 stm1' Q1 r1 fst c1) Data.Product., SubsRets-theorem stm2 stf2 stm2' Q2 r2 snd c2
-- TODO: We need to show that stm2 |= Q2 ≡ stm |= Q2. This requires us
-- to show that merge does not change the values of stm2, which
-- guarantee stm2 |= Q2. This is from the rule of constancy
-- TODO: Rule of constancy can be proven, by first using t_update_neq
-- from Map and then proving the lookup on aeval.
merge-cong : ∀ (v1 v2 : String) → (v1 ≡ v2) → (Ret v1 ≡ Ret v2)
merge-cong v1 .v1 refl = refl
postulate merge-lemma : ∀ (stm1 stm2 stm : (String → ℕ)) → (Q2 : Bexp {ℕ})
→ (r1 r2 : RTuple) → (merge : stm1 , stm2 -[ r1 ]->ᴿ stm)
→ stm2 |= Q2 → ¬ (r2 ≡ r1) → stm |= Q2
-- merge-lemma stm1 stm2 .(Store stm2 v (stm1 v)) Q2 .(Ret v) (Ret v₂) (hd v v1 v2 .stm2) p q rewrite t-update-neq stm2 v v₂ (stm1 v) λ x → ⊥-elim (q (merge-cong v₂ v x)) = {!!}
-- merge-lemma stm1 stm2 .(Store stm2 v (stm1 v)) Q2 .(Ret v) (r2 ,` r3) (hd v v1 v2 .stm2) p q = {!!}
-- merge-lemma stm1 stm2 stm Q2 .(l ,` r) r2 (tl l r .stm2 st' .stm merge merge₁) p q = {!!}
-- Now the theorem that Q1 &&` Q2 hold on the merged stm stack XXX:
-- Again this is being done only for two concurrent functions, but can
-- be extended to N via an inductive data type.
conc-post-theorem : ∀ (stm1 stm2 stm : (String → ℕ)) → (Q1 Q2 : Bexp {ℕ})
-- stm is the merged stack
→ (r1 r2 : RTuple) → (merge : stm1 , stm2 -[ r1 ]->ᴿ stm)
→ (stm1 |= Q1 × stm2 |= Q2)
→ (P : SubsRets Q1 r1 stm2 stm1)
→ ¬ (r2 ≡ r1)
→ (stm |= (Q1 &&` Q2))
conc-post-theorem stm1 stm2 stm Q1 Q2 r1 r2 merge (_ Data.Product., snd) P nr =
AND Q1 Q2 (SubsRets-theorem stm2 stm1 stm Q1 r1 P merge) (merge-lemma stm1 stm2 stm Q2 r1 r2 merge snd nr)
-- TODO: This is the theorem for post-condition for two concurrent
-- function calls. This is harder than the pre-condition.
-- 1.) In this case caller stack goes from stm -> stm' and stm -> stm''
-- for the two functions called concurrently.
-- 2.) stm'' and stm' need to be combined into a single stm''' after the
-- execution of the two functions concurrently? But how? This will be
-- done in FuncCall relational semantics data type above.
-- 3.) Once we have point 2 done then we can prove the correctness same
-- as conc-pre-theorem but for post-condition of || or //.
-- XXX: Use the above lemma to show the side condition state of R' X ≡
-- stf I and so on for all outputs.
-- Subs theorem states that Hoare' subs rule is valid (or sound)
subs-theoremℙ : ∀ (Γ : String → Maybe (ProgTuple {ℕ}))
→ ∀ (st st' : (String → ℕ)) → (X : String) → (e : Aexp {ℕ})
→ (Q : Bexp {ℕ}) → (P : (Subsℙ Q X e st))
→ (C : Γ , st =[ Var X := e ]=> st')
→ (Assertℙ Q st')
subs-theoremℙ Γ st .(Store st X (aeval st e)) X e .(l <` r) (LT l r x) (CASSIGN .st .X .e) = LT l r x
subs-theoremℙ Γ st .(Store st X (aeval st e)) X e .(l ≤` r) (LE l r x) (CASSIGN .st .X .e) = LE l r x
subs-theoremℙ Γ st .(Store st X (aeval st e)) X e .(l >` r) (GT l r x) (CASSIGN .st .X .e) = GT l r x
subs-theoremℙ Γ st .(Store st X (aeval st e)) X e .(l ≥` r) (GE l r x) (CASSIGN .st .X .e) = GE l r x
subs-theoremℙ Γ st .(Store st X (aeval st e)) X e .(l ≡` r) (EQ l r x) (CASSIGN .st .X .e) = EQ l r x
subs-theoremℙ Γ st .(Store st X (aeval st e)) X e .TRUE TT (CASSIGN .st .X .e) = TT
subs-theoremℙ Γ st .(Store st X (aeval st e)) X e .(b1 &&` b2) (AND b1 b2 p p₁) (CASSIGN .st .X .e) = AND b1 b2 p p₁
subs-theoremℙ Γ st .(Store st X (aeval st e)) X e .(b1 ||` b2) (ORL b1 b2 p) (CASSIGN .st .X .e) = ORL b1 b2 p
subs-theoremℙ Γ st .(Store st X (aeval st e)) X e .(b1 ||` b2) (ORR b1 b2 p) (CASSIGN .st .X .e) = ORR b1 b2 p
subs-theoremℙ Γ st .(Store st X (aeval st e)) X e .(¬` b) (NOT b p) (CASSIGN .st .X .e) = NOT b p
-- Consequence hoare rule theorem the general case soundness theorem.
-- This works for both P₁ ⇒ P ∧ Q ⇒ Q₁. Model the implication using (¬`
-- P₁) ||` P and (¬` Q) ||` Q₁
cons-theorem : ∀ (st : (String → ℕ)) → ∀ (P Q : Bexp {ℕ}) → Assertℙ P st
→ st |= ((¬` P) ||` Q) → Assertℙ Q st
cons-theorem st P Q a (ORL .(¬` P) .Q (NOT .P x)) = ⊥-elim (x a)
cons-theorem st P Q a (ORR .(¬` P) .Q b) = b
-- The SKIP Hoare rule soundness theorem
skip-theorem : ∀ (Γ : String → Maybe (ProgTuple {ℕ})) →
∀ (st st' : (String → ℕ)) → ∀ (P : Bexp {ℕ})
→ Assertℙ P st → Γ , st =[ SKIP ]=> st'
→ Assertℙ P st'
skip-theorem Γ st .st p sk (CSKIP .st) = sk
-- The Sequence Hoare rule soundness theorem.
-- Definition of a sound sequence rule
data _,≪_≫_≪_≫ (Γ : String → Maybe (ProgTuple {ℕ})) : Bexp {ℕ}
→ Cmd {ℕ} → Bexp {ℕ} → Set where
HSEQ : ∀ (st st' : (String → ℕ))
→ (c1 c2 : Cmd {ℕ})
→ (P Q : Bexp {ℕ})
→ st |= P
→ Γ , st =[ c1 ; c2 ]=> st'
→ st' |= Q
→
-----------------------------------------------------------
Γ ,≪ P ≫ (c1 ; c2) ≪ Q ≫
-- The sequence rule soundness theorem
-- this is a different way of looking at it
seq-theorem : ∀ (Γ : String → Maybe (ProgTuple {ℕ}))
→ ∀ (st st' st'' : (String → ℕ))
→ (c1 c2 : Cmd {ℕ})
→ (P Q R : Bexp {ℕ})
→ (Γ , st =[ c1 ]=> st')
→ (Γ , st' =[ c2 ]=> st'')
→ st |= P
→ st' |= Q
→ st'' |= R
→ Γ ,≪ P ≫ c1 ; c2 ≪ R ≫
seq-theorem Γ st st' st'' c1 c2 P Q R sc1 sc2 p _ r
= HSEQ st st'' c1 c2 P R p (CSEQ st st' st'' c1 c2 sc1 sc2) r
-- Help lemma
contradiction-lemma : ∀ (b : Bexp {ℕ}) → ∀ (st : (String → ℕ))
→ (beval st b ≡ true)
→ (beval st b ≡ false) → ⊥
contradiction-lemma b st p rewrite p = λ ()
-- Deterministic lemma for argument passing
deterministic-ret-lemma : ∀ (stf stm stm' stm'' : (String → ℕ)) → (rets : RTuple)
→ (stm , stf -[ rets ]->ᴿ stm') → (stm , stf -[ rets ]->ᴿ stm'')
→ (stm' ≡ stm'')
deterministic-ret-lemma stf stm .(Store stf v (stm v)) .(Store stf v (stm v)) .(Ret v) (hd v v1 v2 .stf) (hd .v v3 v4 .stf) = refl
deterministic-ret-lemma stf stm stm' stm'' .(l ,` r) (tl l r .stf st' .stm' p1 p3) (tl .l .r .stf st'' .stm'' p2 p4) with deterministic-ret-lemma stf stm st' st'' l p1 p2
... | refl with deterministic-ret-lemma st' stm stm' stm'' r p3 p4
... | refl = refl
-- Deterministic lemma for argument passing
deterministic-arg-lemma : ∀ (stm stf stf' stf'' : (String → ℕ)) → (args : ATuple)
→ (stm , stf -[ args ]->ᴬ stf') → (stm , stf -[ args ]->ᴬ stf'')
→ (stf' ≡ stf'')
deterministic-arg-lemma stm stf .(Store stf v (stm v)) .(Store stf v (stm v)) .(Arg v) (hd v .stf) (hd .v .stf) = refl
deterministic-arg-lemma stm stf stf' stf'' .(l ,` r) (tl l r .stf st' .stf' p1 p3) (tl .l .r .stf st'' .stf'' p2 p4) with deterministic-arg-lemma stm stf st' st'' l p1 p2
... | refl with deterministic-arg-lemma stm st' stf' stf'' r p3 p4
... | refl = refl
mutual
-- The deterministic execution for function calls
deterministic-func-theorem : ∀ (Γ : (String → Maybe (ProgTuple {ℕ})))
→ ∀ (stm stm1 stm2 : (String → ℕ))
→ ∀ (f : FuncCall {ℕ} )
→ Γ , stm =[ f ]=>ᶠ stm2
→ Γ , stm =[ f ]=>ᶠ stm1
→ stm2 ≡ stm1
deterministic-func-theorem Γ stm stm1 stm2 .(< getProgRets (Γ fname) >:= fname < getProgArgs (Γ fname) >) (Base fname .stm stf' stf'' .stm2 x x₁ x₂) (Base .fname .stm stf''' stf'''' .stm1 x₃ x₄ x₅) with deterministic-arg-lemma stm (K 0) stf' stf''' (getProgArgs (Γ fname)) x x₃
... | refl with deterministic-exec-theorem Γ stf' stf'' stf'''' (getProgCmd (Γ fname)) x₁ x₄
... | refl with deterministic-ret-lemma stm stf'' stm1 stm2 (getProgRets (Γ fname)) x₅ x₂
... | refl = refl
-- Lemma for deterministic execution of commands
deterministic-exec-theorem : ∀ (Γ : String → Maybe (ProgTuple {ℕ}))
→ ∀ (st st' st'' : String → ℕ)
→ ∀ (c : Cmd {ℕ})
→ Γ , st =[ c ]=> st'
→ Γ , st =[ c ]=> st''
→ st' ≡ st''
deterministic-exec-theorem Γ st .st .st .SKIP (CSKIP .st) (CSKIP .st) = refl
deterministic-exec-theorem Γ st .(Store st x (aeval st e)) .(Store st x (aeval st e)) .(Var x := e) (CASSIGN .st x e) (CASSIGN .st .x .e) = refl
deterministic-exec-theorem Γ st st' st'' .(c1 ; c2) (CSEQ .st st''' .st' c1 c2 e1 e3) (CSEQ .st st'''' .st'' .c1 .c2 e2 e4) with deterministic-exec-theorem Γ st st''' st'''' c1 e1 e2
... | refl with deterministic-exec-theorem Γ st''' st'' st' c2 e4 e3
... | refl = refl
deterministic-exec-theorem Γ st st' st'' .(IF b THEN t ELSE e END) (CIFT .st .st' b t e x e1) (CIFT .st .st'' .b .t .e x₁ e2) with deterministic-exec-theorem Γ st st'' st' t e2 e1
... | refl = refl
deterministic-exec-theorem Γ st st' st'' .(IF b THEN t ELSE e END) (CIFT .st .st' b t e x e1) (CIFE .st .st'' .b .t .e x₁ e2) = ⊥-elim (contradiction-lemma b st x x₁)
deterministic-exec-theorem Γ st st' st'' .(IF b THEN t ELSE e END) (CIFE .st .st' b t e x e1) (CIFT .st .st'' .b .t .e x₁ e2) = ⊥-elim (contradiction-lemma b st x₁ x)
deterministic-exec-theorem Γ st st' st'' .(IF b THEN t ELSE e END) (CIFE .st .st' b t e x e1) (CIFE .st .st'' .b .t .e x₁ e2) with deterministic-exec-theorem Γ st st'' st' e e2 e1
... | refl = refl
deterministic-exec-theorem Γ st .st .st .(WHILE b DO c END) (CLF .st b c x) (CLF .st .b .c x₁) = refl
deterministic-exec-theorem Γ st .st st'' .(WHILE b DO c END) (CLF .st b c x) (CLT .st st' .st'' .b .c x₁ e2 e3) = ⊥-elim (contradiction-lemma b st x₁ x)
deterministic-exec-theorem Γ st st' .st .(WHILE b DO c END) (CLT .st st''' .st' b c x e1 e3) (CLF .st .b .c x₁) = ⊥-elim (contradiction-lemma b st x x₁)
deterministic-exec-theorem Γ st st' st'' .(WHILE b DO c END) (CLT .st st''' .st' b c x e1 e3) (CLT .st st'''' .st'' .b .c x₁ e2 e4) with deterministic-exec-theorem Γ st st'''' st''' c e2 e1
... | refl with deterministic-exec-theorem Γ st''' st'' st' (WHILE b DO c END) e4 e3
... | refl = refl
deterministic-exec-theorem Γ st st' st'' (EXEC < ret >:= f < args >) (CEX .(< ret >:= f < args >) .st .st' x) (CEX .(< ret >:= f < args >) .st .st'' x₁) with deterministic-func-theorem Γ st st' st'' < ret >:= f < args > x₁ x
... | refl = refl
-- Proving seq rule soundness via standard technique
seq-theorem1 : ∀ (Γ : String → Maybe (ProgTuple {ℕ}))
→ ∀ (st1 st2 st3 st4 : (String → ℕ))
→ (c1 c2 : Cmd {ℕ})
→ (P Q R : Bexp {ℕ})
→ (Γ , st1 =[ c1 ]=> st2)
→ (Γ , st2 =[ c2 ]=> st3)
→ st1 |= P
→ st2 |= Q
→ st3 |= R
→ Γ , st1 =[ c1 ; c2 ]=> st4
→ st4 |= R
seq-theorem1 Γ st1 st2 st3 st4 c1 c2 P Q R ec1 ec2 st1p st2q st3r (CSEQ .st1 st' .st4 .c1 .c2 ec12 ec13) with deterministic-exec-theorem Γ st1 st2 st' c1 ec1 ec12
... | refl with deterministic-exec-theorem Γ st2 st3 st4 c2 ec2 ec13
... | refl = st3r
-- TODO: Add If-else and while soundness rules if you want here
-- This is the derivable one (completely syntactic, not semantic)
-- In my case I will follow the same technique as SF, but instead of
-- taking propositions I will take the state and the boolean expression
-- for each proposition. This will make the syntactic derivation of
-- Hoare rules possible.
| {
"alphanum_fraction": 0.5255818085,
"avg_line_length": 48.3175965665,
"ext": "agda",
"hexsha": "f52d1e05b29c14c428e3179df4ff83c8fe99ea2b",
"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": "bff8c271b54f55ceac550c603e468f68838a07ee",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "amal029/compositional-real-time-contracts",
"max_forks_repo_path": "Language.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bff8c271b54f55ceac550c603e468f68838a07ee",
"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": "amal029/compositional-real-time-contracts",
"max_issues_repo_path": "Language.agda",
"max_line_length": 278,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bff8c271b54f55ceac550c603e468f68838a07ee",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "amal029/compositional-real-time-contracts",
"max_stars_repo_path": "Language.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 12828,
"size": 33774
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Finite.Fin.Instance.Parallel where
open import Data.Nat using (ℕ)
open import Data.Fin
open import Data.Fin.Patterns
open import Relation.Binary.PropositionalEquality using (_≡_ ; refl)
open import Categories.Category.Finite.Fin
open import Categories.Category
private
variable
a b c d : Fin 2
--
-- /---0---\
-- 0 1
-- \---1---/
--
ParallelShape : FinCatShape
ParallelShape = record
{ size = 2
; ∣_⇒_∣ = card
; hasShape = record
{ id = id
; _∘_ = _∘_
; assoc = assoc
; identityˡ = identityˡ
; identityʳ = identityʳ
}
}
where card : Fin 2 → Fin 2 → ℕ
card 0F 0F = 1
card 0F 1F = 2
card 1F 0F = 0
card 1F 1F = 1
id : Fin (card a a)
id {0F} = 0F
id {1F} = 0F
_∘_ : ∀ {a b c} → Fin (card b c) → Fin (card a b) → Fin (card a c)
_∘_ {0F} {0F} {0F} 0F 0F = 0F
_∘_ {0F} {0F} {1F} 0F 0F = 0F
_∘_ {0F} {0F} {1F} 1F 0F = 1F
_∘_ {0F} {1F} {1F} 0F 0F = 0F
_∘_ {0F} {1F} {1F} 0F 1F = 1F
_∘_ {1F} {1F} {1F} 0F 0F = 0F
assoc : ∀ {f : Fin (card a b)} {g : Fin (card b c)} {h : Fin (card c d)} →
((h ∘ g) ∘ f) ≡ (h ∘ (g ∘ f))
assoc {0F} {0F} {0F} {0F} {0F} {0F} {0F} = refl
assoc {0F} {0F} {0F} {1F} {0F} {0F} {0F} = refl
assoc {0F} {0F} {0F} {1F} {0F} {0F} {1F} = refl
assoc {0F} {0F} {1F} {1F} {0F} {0F} {0F} = refl
assoc {0F} {0F} {1F} {1F} {0F} {1F} {0F} = refl
assoc {0F} {1F} {1F} {1F} {0F} {0F} {0F} = refl
assoc {0F} {1F} {1F} {1F} {1F} {0F} {0F} = refl
assoc {1F} {1F} {1F} {1F} {0F} {0F} {0F} = refl
identityˡ : ∀ {a b} {f : Fin (card a b)} → (id ∘ f) ≡ f
identityˡ {0F} {0F} {0F} = refl
identityˡ {0F} {1F} {0F} = refl
identityˡ {0F} {1F} {1F} = refl
identityˡ {1F} {1F} {0F} = refl
identityʳ : ∀ {a b} {f : Fin (card a b)} → (f ∘ id) ≡ f
identityʳ {0F} {0F} {0F} = refl
identityʳ {0F} {1F} {0F} = refl
identityʳ {0F} {1F} {1F} = refl
identityʳ {1F} {1F} {0F} = refl
Parallel : Category _ _ _
Parallel = FinCategory ParallelShape
module Parallel = Category Parallel
| {
"alphanum_fraction": 0.4825935596,
"avg_line_length": 29.0886075949,
"ext": "agda",
"hexsha": "c2f9bd1f7897d7515bd28470b805471fbcc5358d",
"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/Category/Finite/Fin/Instance/Parallel.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/Category/Finite/Fin/Instance/Parallel.agda",
"max_line_length": 82,
"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/Category/Finite/Fin/Instance/Parallel.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1049,
"size": 2298
} |
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.types.Bool
open import lib.types.Group
open import lib.types.Nat
open import lib.types.Pi
open import lib.types.Sigma
open import lib.types.Coproduct
open import lib.types.Truncation
open import lib.groups.Homomorphism
open import lib.groups.Isomorphism
open import lib.groups.SubgroupProp
open import lib.groups.Lift
open import lib.groups.Unit
module lib.groups.GroupProduct where
{- binary product -}
×-group-struct : ∀ {i j} {A : Type i} {B : Type j}
(GS : GroupStructure A) (HS : GroupStructure B)
→ GroupStructure (A × B)
×-group-struct {A = A} {B = B} GS HS = record {M} where
module G = GroupStructure GS
module H = GroupStructure HS
module M where
ident : A × B
ident = G.ident , H.ident
inv : A × B → A × B
inv (g , h) = G.inv g , H.inv h
comp : A × B → A × B → A × B
comp (g₁ , h₁) (g₂ , h₂) = G.comp g₁ g₂ , H.comp h₁ h₂
abstract
unit-l : ∀ ab → comp ident ab == ab
unit-l (g , h) = pair×= (G.unit-l g) (H.unit-l h)
assoc : ∀ ab₁ ab₂ ab₃ → comp (comp ab₁ ab₂) ab₃ == comp ab₁ (comp ab₂ ab₃)
assoc (g₁ , h₁) (g₂ , h₂) (g₃ , h₃) =
pair×= (G.assoc g₁ g₂ g₃) (H.assoc h₁ h₂ h₃)
inv-l : ∀ ab → comp (inv ab) ab == ident
inv-l (g , h) = pair×= (G.inv-l g) (H.inv-l h)
infix 80 _×ᴳ_
_×ᴳ_ : ∀ {i j} → Group i → Group j → Group (lmax i j)
_×ᴳ_ (group A A-level A-struct) (group B B-level B-struct) =
group (A × B) (×-level A-level B-level) (×-group-struct A-struct B-struct)
{- general product -}
Π-group-struct : ∀ {i j} {I : Type i} {A : I → Type j}
(FS : (i : I) → GroupStructure (A i))
→ GroupStructure (Π I A)
Π-group-struct FS = record {
ident = ident ∘ FS;
inv = λ f i → inv (FS i) (f i);
comp = λ f g i → comp (FS i) (f i) (g i);
unit-l = λ f → (λ= (λ i → unit-l (FS i) (f i)));
assoc = λ f g h → (λ= (λ i → assoc (FS i) (f i) (g i) (h i)));
inv-l = λ f → (λ= (λ i → inv-l (FS i) (f i)))}
where open GroupStructure
Πᴳ : ∀ {i j} (I : Type i) (F : I → Group j) → Group (lmax i j)
Πᴳ I F = group (Π I (El ∘ F)) (Π-level (λ i → El-level (F i)))
(Π-group-struct (group-struct ∘ F))
where open Group
{- functorial behavior of [Πᴳ] -}
Πᴳ-emap-r : ∀ {i j k} (I : Type i) {F : I → Group j} {G : I → Group k}
→ (∀ i → F i ≃ᴳ G i) → Πᴳ I F ≃ᴳ Πᴳ I G
Πᴳ-emap-r I {F} {G} iso = ≃-to-≃ᴳ (Π-emap-r (GroupIso.f-equiv ∘ iso))
(λ f g → λ= λ i → GroupIso.pres-comp (iso i) (f i) (g i))
{- the product of abelian groups is abelian -}
×ᴳ-is-abelian : ∀ {i j} (G : Group i) (H : Group j)
→ is-abelian G → is-abelian H → is-abelian (G ×ᴳ H)
×ᴳ-is-abelian G H aG aH (g₁ , h₁) (g₂ , h₂) = pair×= (aG g₁ g₂) (aH h₁ h₂)
×ᴳ-abgroup : ∀ {i j} → AbGroup i → AbGroup j → AbGroup (lmax i j)
×ᴳ-abgroup (G , aG) (H , aH) = G ×ᴳ H , ×ᴳ-is-abelian G H aG aH
Πᴳ-is-abelian : ∀ {i j} {I : Type i} {F : I → Group j}
→ (∀ i → is-abelian (F i)) → is-abelian (Πᴳ I F)
Πᴳ-is-abelian aF f₁ f₂ = λ= (λ i → aF i (f₁ i) (f₂ i))
{- defining a homomorphism into a product -}
×ᴳ-fanout : ∀ {i j k} {G : Group i} {H : Group j} {K : Group k}
→ (G →ᴳ H) → (G →ᴳ K) → (G →ᴳ H ×ᴳ K)
×ᴳ-fanout (group-hom h h-comp) (group-hom k k-comp) =
group-hom
(λ x → (h x , k x))
(λ x y → pair×= (h-comp x y) (k-comp x y))
Πᴳ-fanout : ∀ {i j k} {I : Type i} {G : Group j} {F : I → Group k}
→ ((i : I) → G →ᴳ F i) → (G →ᴳ Πᴳ I F)
Πᴳ-fanout h = group-hom
(λ x i → GroupHom.f (h i) x)
(λ x y → λ= (λ i → GroupHom.pres-comp (h i) x y))
×ᴳ-fanout-pre∘ : ∀ {i j k l}
{G : Group i} {H : Group j} {K : Group k} {J : Group l}
(φ : G →ᴳ H) (ψ : G →ᴳ K) (χ : J →ᴳ G)
→ ×ᴳ-fanout φ ψ ∘ᴳ χ == ×ᴳ-fanout (φ ∘ᴳ χ) (ψ ∘ᴳ χ)
×ᴳ-fanout-pre∘ φ ψ χ = group-hom= idp
{- projection homomorphisms -}
×ᴳ-fst : ∀ {i j} {G : Group i} {H : Group j} → (G ×ᴳ H →ᴳ G)
×ᴳ-fst = group-hom fst (λ _ _ → idp)
×ᴳ-snd : ∀ {i j} {G : Group i} {H : Group j} → (G ×ᴳ H →ᴳ H)
×ᴳ-snd = group-hom snd (λ _ _ → idp)
×ᴳ-snd-is-surj : ∀ {i j} {G : Group i} {H : Group j}
→ is-surjᴳ (×ᴳ-snd {G = G} {H = H})
×ᴳ-snd-is-surj {G = G} h = [ (Group.ident G , h) , idp ]
Πᴳ-proj : ∀ {i j} {I : Type i} {F : I → Group j} (i : I)
→ (Πᴳ I F →ᴳ F i)
Πᴳ-proj i = group-hom (λ f → f i) (λ _ _ → idp)
{- injection homomorphisms -}
module _ {i j} {G : Group i} {H : Group j} where
×ᴳ-inl : G →ᴳ G ×ᴳ H
×ᴳ-inl = ×ᴳ-fanout (idhom G) cst-hom
×ᴳ-inr : H →ᴳ G ×ᴳ H
×ᴳ-inr = ×ᴳ-fanout (cst-hom {H = G}) (idhom H)
×ᴳ-diag : ∀ {i} {G : Group i} → (G →ᴳ G ×ᴳ G)
×ᴳ-diag = ×ᴳ-fanout (idhom _) (idhom _)
{- when G is abelian, we can define a map H×K → G as a sum of maps
- H → G and K → G (that is, the product behaves as a sum) -}
module _ {i j k} {G : Group i} {H : Group j} {K : Group k}
(G-abelian : is-abelian G) where
private
module G = Group G
module H = Group H
module K = Group K
abstract
interchange : (g₁ g₂ g₃ g₄ : G.El) →
G.comp (G.comp g₁ g₂) (G.comp g₃ g₄)
== G.comp (G.comp g₁ g₃) (G.comp g₂ g₄)
interchange g₁ g₂ g₃ g₄ =
(g₁ □ g₂) □ (g₃ □ g₄)
=⟨ G.assoc g₁ g₂ (g₃ □ g₄) ⟩
g₁ □ (g₂ □ (g₃ □ g₄))
=⟨ G-abelian g₃ g₄ |in-ctx (λ w → g₁ □ (g₂ □ w)) ⟩
g₁ □ (g₂ □ (g₄ □ g₃))
=⟨ ! (G.assoc g₂ g₄ g₃) |in-ctx (λ w → g₁ □ w) ⟩
g₁ □ ((g₂ □ g₄) □ g₃)
=⟨ G-abelian (g₂ □ g₄) g₃ |in-ctx (λ w → g₁ □ w) ⟩
g₁ □ (g₃ □ (g₂ □ g₄))
=⟨ ! (G.assoc g₁ g₃ (g₂ □ g₄)) ⟩
(g₁ □ g₃) □ (g₂ □ g₄) =∎
where
infix 80 _□_
_□_ = G.comp
×ᴳ-fanin : (H →ᴳ G) → (K →ᴳ G) → (H ×ᴳ K →ᴳ G)
×ᴳ-fanin φ ψ = group-hom (λ {(h , k) → G.comp (φ.f h) (ψ.f k)}) lemma
where
module φ = GroupHom φ
module ψ = GroupHom ψ
abstract
lemma : preserves-comp (Group.comp (H ×ᴳ K)) G.comp
(λ {(h , k) → G.comp (φ.f h) (ψ.f k)})
lemma (h₁ , k₁) (h₂ , k₂) =
G.comp (φ.f (H.comp h₁ h₂)) (ψ.f (K.comp k₁ k₂))
=⟨ φ.pres-comp h₁ h₂ |in-ctx (λ w → G.comp w (ψ.f (K.comp k₁ k₂))) ⟩
G.comp (G.comp (φ.f h₁) (φ.f h₂)) (ψ.f (K.comp k₁ k₂))
=⟨ ψ.pres-comp k₁ k₂
|in-ctx (λ w → G.comp (G.comp (φ.f h₁) (φ.f h₂)) w) ⟩
G.comp (G.comp (φ.f h₁) (φ.f h₂)) (G.comp (ψ.f k₁) (ψ.f k₂))
=⟨ interchange (φ.f h₁) (φ.f h₂) (ψ.f k₁) (ψ.f k₂) ⟩
G.comp (G.comp (φ.f h₁) (ψ.f k₁)) (G.comp (φ.f h₂) (ψ.f k₂)) =∎
abstract
×ᴳ-fanin-η : ∀ {i j} (G : Group i) (H : Group j)
(aGH : is-abelian (G ×ᴳ H))
→ idhom (G ×ᴳ H) == ×ᴳ-fanin aGH (×ᴳ-inl {G = G}) (×ᴳ-inr {G = G})
×ᴳ-fanin-η G H aGH = group-hom= $ λ= λ {(g , h) →
! (pair×= (Group.unit-r G g) (Group.unit-l H h))}
×ᴳ-fanin-pre∘ : ∀ {i j k l}
{G : Group i} {H : Group j} {K : Group k} {L : Group l}
(aK : is-abelian K) (aL : is-abelian L)
(φ : K →ᴳ L) (ψ : G →ᴳ K) (χ : H →ᴳ K)
→ ×ᴳ-fanin aL (φ ∘ᴳ ψ) (φ ∘ᴳ χ) == φ ∘ᴳ (×ᴳ-fanin aK ψ χ)
×ᴳ-fanin-pre∘ aK aL φ ψ χ = group-hom= $ λ= λ {(g , h) →
! (GroupHom.pres-comp φ (GroupHom.f ψ g) (GroupHom.f χ h))}
{- define a homomorphism [G₁ × G₂ → H₁ × H₂] from homomorphisms
- [G₁ → H₁] and [G₂ → H₂] -}
×ᴳ-fmap : ∀ {i j k l} {G₁ : Group i} {G₂ : Group j}
{H₁ : Group k} {H₂ : Group l}
→ (G₁ →ᴳ H₁) → (G₂ →ᴳ H₂) → (G₁ ×ᴳ G₂ →ᴳ H₁ ×ᴳ H₂)
×ᴳ-fmap {G₁ = G₁} {G₂} {H₁} {H₂} φ ψ = group-hom (×-fmap φ.f ψ.f) lemma
where
module φ = GroupHom φ
module ψ = GroupHom ψ
abstract
lemma : preserves-comp (Group.comp (G₁ ×ᴳ G₂)) (Group.comp (H₁ ×ᴳ H₂))
(λ {(h₁ , h₂) → (φ.f h₁ , ψ.f h₂)})
lemma (h₁ , h₂) (h₁' , h₂') = pair×= (φ.pres-comp h₁ h₁') (ψ.pres-comp h₂ h₂')
×ᴳ-emap : ∀ {i j k l} {G₁ : Group i} {G₂ : Group j}
{H₁ : Group k} {H₂ : Group l}
→ (G₁ ≃ᴳ H₁) → (G₂ ≃ᴳ H₂) → (G₁ ×ᴳ G₂ ≃ᴳ H₁ ×ᴳ H₂)
×ᴳ-emap (φ , φ-is-equiv) (ψ , ψ-is-equiv) =
×ᴳ-fmap φ ψ , ×-isemap φ-is-equiv ψ-is-equiv
{- equivalences in Πᴳ -}
Πᴳ-emap-l : ∀ {i j k} {A : Type i} {B : Type j} (F : B → Group k)
→ (e : A ≃ B) → Πᴳ A (F ∘ –> e) ≃ᴳ Πᴳ B F
Πᴳ-emap-l {A = A} {B = B} F e = ≃-to-≃ᴳ (Π-emap-l (Group.El ∘ F) e) lemma
where abstract lemma = λ f g → λ= λ b → transp-El-pres-comp F (<–-inv-r e b) (f (<– e b)) (g (<– e b))
{- 0ᴳ is a unit for product -}
×ᴳ-unit-l : ∀ {i} (G : Group i) → 0ᴳ ×ᴳ G ≃ᴳ G
×ᴳ-unit-l _ = ×ᴳ-snd {G = 0ᴳ} , is-eq snd (λ g → (unit , g)) (λ _ → idp) (λ _ → idp)
×ᴳ-unit-r : ∀ {i} (G : Group i) → G ×ᴳ 0ᴳ ≃ᴳ G
×ᴳ-unit-r _ = ×ᴳ-fst , is-eq fst (λ g → (g , unit)) (λ _ → idp) (λ _ → idp)
{- A product Πᴳ indexed by Bool is the same as a binary product -}
module _ {i j k} {A : Type i} {B : Type j} (F : A ⊔ B → Group k) where
Πᴳ₁-⊔-iso-×ᴳ : Πᴳ (A ⊔ B) F ≃ᴳ Πᴳ A (F ∘ inl) ×ᴳ Πᴳ B (F ∘ inr)
Πᴳ₁-⊔-iso-×ᴳ = ≃-to-≃ᴳ (Π₁-⊔-equiv-× (Group.El ∘ F)) (λ _ _ → idp)
{- Commutativity of ×ᴳ -}
×ᴳ-comm : ∀ {i j} (H : Group i) (K : Group j) → H ×ᴳ K ≃ᴳ K ×ᴳ H
×ᴳ-comm H K =
group-hom (λ {(h , k) → (k , h)}) (λ _ _ → idp) ,
is-eq _ (λ {(k , h) → (h , k)}) (λ _ → idp) (λ _ → idp)
{- Associativity of ×ᴳ -}
×ᴳ-assoc : ∀ {i j k} (G : Group i) (H : Group j) (K : Group k)
→ ((G ×ᴳ H) ×ᴳ K) ≃ᴳ (G ×ᴳ (H ×ᴳ K))
×ᴳ-assoc G H K =
group-hom (λ {((g , h) , k) → (g , (h , k))}) (λ _ _ → idp) ,
is-eq _ (λ {(g , (h , k)) → ((g , h) , k)}) (λ _ → idp) (λ _ → idp)
module _ {i} where
infixl 80 _^ᴳ_
_^ᴳ_ : Group i → ℕ → Group i
H ^ᴳ O = Lift-group {j = i} 0ᴳ
H ^ᴳ (S n) = H ×ᴳ (H ^ᴳ n)
^ᴳ-+ : (H : Group i) (m n : ℕ) → H ^ᴳ (m + n) ≃ᴳ (H ^ᴳ m) ×ᴳ (H ^ᴳ n)
^ᴳ-+ H O n = ×ᴳ-emap (lift-iso {G = 0ᴳ}) (idiso (H ^ᴳ n)) ∘eᴳ ×ᴳ-unit-l (H ^ᴳ n) ⁻¹ᴳ
^ᴳ-+ H (S m) n = ×ᴳ-assoc H (H ^ᴳ m) (H ^ᴳ n) ⁻¹ᴳ ∘eᴳ ×ᴳ-emap (idiso H) (^ᴳ-+ H m n)
module _ where
Πᴳ-is-trivial : ∀ {i j} (I : Type i) (F : I → Group j)
→ (∀ (i : I) → is-trivialᴳ (F i)) → is-trivialᴳ (Πᴳ I F)
Πᴳ-is-trivial I F F-is-trivial = λ f → λ= λ i → F-is-trivial i (f i)
module _ {j} {F : Unit → Group j} where
Πᴳ₁-Unit : Πᴳ Unit F ≃ᴳ F unit
Πᴳ₁-Unit = ≃-to-≃ᴳ Π₁-Unit (λ _ _ → idp)
| {
"alphanum_fraction": 0.4967398937,
"avg_line_length": 36.7859778598,
"ext": "agda",
"hexsha": "34c0a9649601cce1b49a0bb512e7bdd60ff5cf1a",
"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/groups/GroupProduct.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/groups/GroupProduct.agda",
"max_line_length": 104,
"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/groups/GroupProduct.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5060,
"size": 9969
} |
{-# OPTIONS --without-K #-}
open import library.Basics
open import library.types.Sigma
open import library.types.Bool
open import library.types.Truncation hiding (Trunc)
module Sec8judgmentalBeta where
{-
Recall Definition 3.6:
postulate
Trunc : Type → Type
h-tr : (X : Type) → is-prop (Trunc X)
∣_∣ : {X : Type} → X → Trunc X
rec : {X : Type} → {P : Type} → (is-prop P) → (X → P) → Trunc X → P
We now redefine the propositional truncation so that rec has the judgmental β rule.
We use the library implementation (library.types.Truncation).
However, we still only talk about the *propositional* truncation (not the more general n-truncation).
This file is independent of all the previous files of the article.
For the part in Subsection 9.4, we need some statements for for than the lowest universe. Therefore,
we choose to be more careful about universe levels.
-}
Trunc : ∀ {i} → Type i → Type i
Trunc = library.types.Truncation.Trunc ⟨-1⟩
h-tr : ∀ {i} → (X : Type i) → is-prop (Trunc X)
h-tr X = Trunc-level
∣_∣ : ∀ {i} → {X : Type i} → X → Trunc X
∣_∣ = [_]
rec : ∀ {i j} → {X : Type i} → {P : Type j} → (is-prop P) → (X → P) → Trunc X → P
rec = Trunc-rec
ind : ∀ {i j} → {X : Type i} → {P : Trunc X → Type j} → ((z : Trunc X) → is-prop (P z)) → ((x : X) → P ∣ x ∣) → (z : Trunc X) → P z
ind = Trunc-elim
-- Subsection 8.1
-- Theorem 8.1
interval : Type₀
interval = Trunc Bool
i₁ : interval
i₁ = ∣ true ∣
i₂ : interval
i₂ = ∣ false ∣
seg : i₁ == i₂
seg = prop-has-all-paths (h-tr _) _ _
-- We prove that the interval has the "correct" recursion principle:
module interval {i} {Y : Type i} (y₁ y₂ : Y) (p : y₁ == y₂) where
g : Bool → Σ Y λ y → y₁ == y
g true = (y₁ , idp)
g false = (y₂ , p)
ĝ : interval → Σ Y λ y → y₁ == y
ĝ = rec (contr-is-prop (pathfrom-is-contr _)) g
f : interval → Y
f = fst ∘ ĝ
f-i₁ : f i₁ == y₁
f-i₁ = idp
f-i₂ : f i₂ == y₂
f-i₂ = idp
f-seg : ap f seg == p
f-seg =
ap f seg =⟨ idp ⟩
ap (fst ∘ ĝ) seg =⟨ ! (∘-ap _ _ _) ⟩
(ap fst) (ap ĝ seg) =⟨ ap (ap fst) (prop-has-all-paths (contr-is-set (pathfrom-is-contr _) _ _) _ _) ⟩
(ap fst) (pair= p po-aux) =⟨ fst=-β p _ ⟩
p ∎ where
po-aux : idp == p [ _==_ y₁ ↓ p ]
po-aux = from-transp (_==_ y₁) p (trans-pathfrom p idp)
-- Everything again outside the module:
interval-rec : ∀ {i} → {Y : Type i} → (y₁ y₂ : Y) → (p : y₁ == y₂) → (interval → Y)
interval-rec = interval.f
interval-rec-i₁ : ∀ {i} → {Y : Type i} → (y₁ y₂ : Y) → (p : y₁ == y₂) → (interval-rec y₁ y₂ p) i₁ == y₁
interval-rec-i₁ = interval.f-i₁ -- or: λ _ _ _ → idp
interval-rec-i₂ : ∀ {i} → {Y : Type i} → (y₁ y₂ : Y) → (p : y₁ == y₂) → (interval-rec y₁ y₂ p) i₂ == y₂
interval-rec-i₂ = interval.f-i₂ -- or: λ _ _ _ → idp
interval-rec-seg : ∀ {i} → {Y : Type i} → (y₁ y₂ : Y) → (p : y₁ == y₂) → ap (interval-rec y₁ y₂ p) seg == p
interval-rec-seg = interval.f-seg
-- Subsection 8.2
-- Lemma 8.2 (Shulman) / Corollary 8.3
interval→funext : ∀ {i j} → {X : Type i} → {Y : Type j} → (f g : (X → Y)) → ((x : X) → f x == g x) → f == g
interval→funext {X = X} {Y = Y} f g hom = ap i-x seg where
x-i : X → interval → Y
x-i x = interval-rec (f x) (g x) (hom x)
i-x : interval → X → Y
i-x i x = x-i x i
-- Thus, function extensionality holds automatically.
open import library.types.Pi
-- Subsection 8.3
-- We use the definitions from Section 5, but we re-define them as our definition of "Trunc" has chanced
factors : ∀ {i j} → {X : Type i} → {Y : Type j} → (f : X → Y) → Type (lmax i j)
factors {X = X} {Y = Y} f = Σ (Trunc X → Y) λ f' → (x : X) → f' ∣ x ∣ == f x
-- Theorem 8.4 - note the line proof' = λ _ → idp
judgmental-factorr : ∀ {i j} → {X : Type i} → {Y : Type j} → (f : X → Y) → factors f → factors f
judgmental-factorr {X = X} {Y = Y} f (f₂ , proof) = f' , proof' where
g : X → (z : Trunc X) → Σ Y λ y → y == f₂ z
g x = λ z → f x , f x =⟨ ! (proof _) ⟩
f₂ ∣ x ∣ =⟨ ap f₂ (prop-has-all-paths (h-tr _) _ _) ⟩
f₂ z ∎
g-codom-prop : is-prop ((z : Trunc X) → Σ Y λ y → y == f₂ z)
g-codom-prop = contr-is-prop (Π-level (λ z → pathto-is-contr _))
ĝ : Trunc X → (z : Trunc X) → Σ Y λ y → y == f₂ z
ĝ = rec g-codom-prop g
f' : Trunc X → Y
f' = λ z → fst (ĝ z z)
proof' : (x : X) → f' ∣ x ∣ == f x
proof' = λ _ → idp
-- Theorem 8.5 - we need the induction principle, but with that, it is actually simpler than the previous construction.
-- Still, it is nearly a replication.
factors-dep : ∀ {i j} → {X : Type i} → {Y : Trunc X → Type j} → (f : (x : X) → (Y ∣ x ∣)) → Type (lmax i j)
factors-dep {X = X} {Y = Y} f = Σ ((z : Trunc X) → Y z) λ f₂ → ((x : X) → f x == f₂ ∣ x ∣)
judgmental-factorr-dep : ∀ {i j} → {X : Type i} → {Y : Trunc X → Type j}
→ (f : (x : X) → Y ∣ x ∣) → factors-dep {X = X} {Y = Y} f → factors-dep {X = X} {Y = Y} f
judgmental-factorr-dep {X = X} {Y = Y} f (f₂ , proof) = f' , proof' where
g : (x : X) → Σ (Y ∣ x ∣) λ y → y == f₂ ∣ x ∣
g x = f x , proof x
g-codom-prop : (z : Trunc X) → is-prop (Σ (Y z) λ y → y == f₂ z)
g-codom-prop z = contr-is-prop (pathto-is-contr _)
ĝ : (z : Trunc X) → Σ (Y z) λ y → y == f₂ z
ĝ = ind g-codom-prop g
f' : (z : Trunc X) → Y z
f' = fst ∘ ĝ
proof' : (x : X) → f' ∣ x ∣ == f x
proof' x = idp
-- Subsection 8.4
-- The content of this section is partially taken from an earlier formalization by the first-named author;
-- see
--
-- http://homotopytypetheory.org/2013/10/28/
--
-- for a discussion and
--
-- http://red.cs.nott.ac.uk/~ngk/html-trunc-inverse/trunc-inverse.html
--
-- for a formalization (the slightly simpler formalization that is mentioned in the article).
-- Definition 8.6
-- Pointed types
Type• : ∀ {i} → Type (lsucc i)
Type• {i} = Σ (Type i) (idf _)
module _ {i} (X : Type• {i}) where
base = fst X
pt = snd X
-- We have already used the pathto-types a couple of times.
-- Let's introduce a name for those that work with pointed types:
pathto : Type (lsucc i)
pathto = Σ (Type• {i}) (λ Y → Y == X)
-- As it is well-known, these type is contractible and thereby propositional:
pathto-prop : is-prop pathto
pathto-prop = contr-is-prop (pathto-is-contr X)
-- Definition 8.7
is-transitive : ∀ {i} → Type i → Type (lsucc i)
is-transitive {i} X = (x₁ x₂ : X) → _==_ {A = Type•} (X , x₁) (X , x₂)
-- Example 8.8
module dec-trans {i} (X : Type i) (dec : has-dec-eq X) where
module _ (x₁ x₂ : X) where
-- I define a function X → X that switches x and x₀.
switch : X → X
switch = λ y → match dec y x₁
withl (λ _ → x₂)
withr (λ _ → match dec y x₂
withl (λ _ → x₁)
withr (λ _ → y))
-- Rather tedious to prove, but completely straightforward:
-- this map is its own inverse.
switch-selfinverse : (y : X) → switch (switch y) == y
switch-selfinverse y with dec y x₁
switch-selfinverse y | inl _ with dec x₂ x₁
switch-selfinverse y | inl y-x₁ | inl x-x₁ = x-x₁ ∙ ! y-x₁
switch-selfinverse y | inl _ | inr _ with dec x₂ x₂
switch-selfinverse y | inl y-x₁ | inr _ | inl _ = ! y-x₁
switch-selfinverse y | inl _ | inr _ | inr ¬x₂-x₂ = Empty-elim {A = λ _ → x₂ == y} (¬x₂-x₂ idp)
switch-selfinverse y | inr _ with dec y x₂
switch-selfinverse y | inr _ | inl _ with dec x₂ x₁
switch-selfinverse y | inr ¬x₂-x₁ | inl y-x₂ | inl x₂-x₁ = Empty-elim (¬x₂-x₁ (y-x₂ ∙ x₂-x₁))
switch-selfinverse y | inr _ | inl _ | inr _ with dec x₁ x₁
switch-selfinverse y | inr _ | inl y-x₂ | inr _ | inl _ = ! y-x₂
switch-selfinverse y | inr _ | inl _ | inr _ | inr ¬x₁-x₁ = Empty-elim {A = λ _ → _ == y} (¬x₁-x₁ idp)
switch-selfinverse y | inr _ | inr _ with dec y x₁
switch-selfinverse y | inr ¬y-x₁ | inr _ | inl y-x₁ = Empty-elim {A = λ _ → x₂ == y} (¬y-x₁ y-x₁)
switch-selfinverse y | inr _ | inr _ | inr _ with dec y x₂
switch-selfinverse y | inr _ | inr ¬y-x₂ | inr _ | inl y-x₂ = Empty-elim {A = λ _ → x₁ == y} (¬y-x₂ y-x₂)
switch-selfinverse y | inr _ | inr _ | inr _ | inr _ = idp
switch-maps : switch x₂ == x₁
switch-maps with dec x₂ x₁
switch-maps | inl x₂-x₁ = x₂-x₁
switch-maps | inr _ with dec x₂ x₂
switch-maps | inr _ | inl _ = idp
switch-maps | inr _ | inr ¬x-x = Empty-elim {A = λ _ → x₂ == x₁} (¬x-x idp)
-- switch is an equivalence
switch-eq : X ≃ X
switch-eq = equiv switch switch
switch-selfinverse switch-selfinverse
-- X is transitive:
is-trans : is-transitive X
is-trans x₁ x₂ = pair= (ua X-X) x₁-x₂ where
X-X : X ≃ X
X-X = switch-eq x₂ x₁
x₁-x₂ : PathOver (idf (Type i)) (ua X-X) x₁ x₂
x₁-x₂ = ↓-idf-ua-in X-X (switch-maps x₂ x₁)
-- Example 8.8 addendum: ℕ is transitive.
open import library.types.Nat
ℕ-trans : is-transitive ℕ
ℕ-trans = dec-trans.is-trans ℕ ℕ-has-dec-eq
-- Example 9.9
-- (Note that this does not need the univalence axiom)
-- preparation
path-trans-aux : ∀ {i} → (X : Type i) → (x₁ x₂ x₃ : X) → (x₂ == x₃)
→ (p₁₂ : x₁ == x₂) → (p₁₃ : x₁ == x₃) → _==_ {A = Type•} (x₁ == x₂ , p₁₂) (x₁ == x₃ , p₁₃)
path-trans-aux X x₁ .x₁ .x₁ p idp idp = idp
-- the lemma
path-trans : ∀ {i} → (X : Type i) → (x₁ x₂ : X) → is-transitive (x₁ == x₂)
path-trans X x₁ x₂ = path-trans-aux X x₁ x₂ x₂ idp
-- In particular, the lemma works for loop spaces.
-- We define them as follows:
Ω : ∀ {i} → Type• {i} → Type• {i}
Ω (X , x) = (x == x , idp)
-- We choose precomposition here - whether the function exponentiation operator is more
-- convenient to use with pre- or postcomposition depends on the concrete case.
infix 10 _^_
_^_ : ∀ {i} {A : Set i} → (A → A) → ℕ → A → A
f ^ 0 = idf _
f ^ S n = f ∘ f ^ n
loop-trans : ∀ {i} → (X : Type• {i}) → (n : ℕ) → is-transitive (fst ((Ω ^ (1 + n)) X))
loop-trans {i} X n = path-trans type point point where
type : Type i
type = fst ((Ω ^ n) X)
point : type
point = snd ((Ω ^ n) X)
-- Example 8.10 and 8.11
-- (not formalized)
module constr-myst {i} (X : Type i) (x₀ : X) (t : is-transitive X) where
f : X → Type• {i}
f x = (X , x)
f'' : Trunc X → Type• {i}
f'' _ = (X , x₀)
f-fact : factors f
f-fact = f'' , (λ x → t x₀ x)
f' : Trunc X → Type• {i}
f' = fst (judgmental-factorr f f-fact)
-- Theorem 9.12
-- the myst function:
myst : (z : Trunc X) → fst (f' z)
myst = snd ∘ f'
check : (x : X) → myst ∣ x ∣ == x
check x = idp
myst-∣_∣-is-id : myst ∘ ∣_∣ == idf X
myst-∣_∣-is-id = λ= λ x → idp
-- Let us do it explicitly for ℕ:
open import library.types.Nat
myst-ℕ = constr-myst.myst ℕ 0 (dec-trans.is-trans ℕ ℕ-has-dec-eq)
myst-∣_∣-is-id : (n : ℕ) → myst-ℕ ∣ n ∣ == n
myst-∣_∣-is-id n = idp
test : myst-ℕ ∣ 17 ∣ == 17
test = idp
| {
"alphanum_fraction": 0.5528938466,
"avg_line_length": 31.5187319885,
"ext": "agda",
"hexsha": "e05b3bace1e37d6984c8b0630716e5b364ad59cc",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "nicolai/anonymousExistence/Sec8judgmentalBeta.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "nicolai/anonymousExistence/Sec8judgmentalBeta.agda",
"max_line_length": 131,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nicolaikraus/HoTT-Agda",
"max_stars_repo_path": "nicolai/anonymousExistence/Sec8judgmentalBeta.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z",
"num_tokens": 4295,
"size": 10937
} |
open import Prelude
module Implicits.Semantics.RewriteContext where
open import Implicits.Syntax
open import Implicits.Substitutions
open import Implicits.Substitutions.Lemmas
open import Data.Vec
open import Data.List.All as All
open import Extensions.Vec
-- rewrite context (relation between implicit and explicit context)
_#_ : ∀ {ν n} (Γ : Ctx ν n) (Δ : ICtx ν) → Set
Γ # Δ = All (λ i → i ∈ Γ) Δ
K# : ∀ {ν n} (K : Ktx ν n) → Set
K# (Γ , Δ) = Γ # Δ
#tvar : ∀ {ν n} {K : Ktx ν n} → K# K → K# (ktx-weaken K)
#tvar All.[] = All.[]
#tvar (px All.∷ K#K) = (∈⋆map px (λ t → t tp/tp TypeLemmas.wk)) All.∷ (#tvar K#K)
#var : ∀ {ν n} {K : Ktx ν n} → (a : Type ν) → K# K → K# (a ∷Γ K)
#var a All.[] = All.[]
#var a (px All.∷ K#K) = there px All.∷ (#var a K#K)
#ivar : ∀ {ν n} {K : Ktx ν n} → (a : Type ν) → K# K → K# (a ∷K K)
#ivar a K#K = here All.∷ (All.map there K#K)
| {
"alphanum_fraction": 0.5871559633,
"avg_line_length": 29.0666666667,
"ext": "agda",
"hexsha": "b97b796c5cb1e11af06e6d7cc51236c9cd7ead1e",
"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/Semantics/RewriteContext.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/Semantics/RewriteContext.agda",
"max_line_length": 81,
"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/Semantics/RewriteContext.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": 371,
"size": 872
} |
{-# OPTIONS --allow-unsolved-metas #-}
module _ where
open import Agda.Primitive using (Level)
variable
l : Level
postulate
Σ : {l' : Level}{X : Set} (Y : X → Set l') -> Set
_,_ : {l' : Level}{X : Set} {Y : X → Set l'} -> (x : X)(y : Y x) -> Σ Y
is-universal-element : {l' : Level}{X : Set} {A : X → Set l'} -> Σ A → Set
universality-section : {X : Set} {A : X → Set l} -> (x : X) (a : A x)
→ is-universal-element {X = X} (x , a)
| {
"alphanum_fraction": 0.4946921444,
"avg_line_length": 27.7058823529,
"ext": "agda",
"hexsha": "d65421c38bc0e9206242077475fc0636a48f6ba4",
"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/Issue3516.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/Issue3516.agda",
"max_line_length": 76,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue3516.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": 174,
"size": 471
} |
open import Auto.Core
open import Data.List using (_∷_; []; length)
open import Data.Nat using (ℕ; zero; suc)
open import Data.Product using (_,_)
open import Data.Sum using (inj₁; inj₂)
open import Reflection using (Term; Name; lam; visible; abs; TC; returnTC; bindTC)
module Auto.Extensible (instHintDB : IsHintDB) where
open IsHintDB instHintDB public
open PsExtensible instHintDB public
open Auto.Core public using (dfs; bfs; Exception; throw; searchSpaceExhausted; unsupportedSyntax)
auto : Strategy → ℕ → HintDB → Term → TC Term
auto search depth db type
with agda2goal×premises type
... | inj₁ msg = returnTC (quoteError msg)
... | inj₂ ((n , g) , args)
with search (suc depth) (solve g (fromRules args ∙ db))
... | [] = returnTC (quoteError searchSpaceExhausted)
... | (p ∷ _) = bindTC (reify p) (λ rp → returnTC (intros rp))
where
intros : Term → Term
intros = introsAcc (length args)
where
introsAcc : ℕ → Term → Term
introsAcc zero t = t
introsAcc (suc k) t = lam visible (abs "TODO" (introsAcc k t))
infixl 5 _<<_
_<<_ : HintDB → Name → TC HintDB
db << n = bindTC (name2rule n) (λ
{(inj₁ msg) → returnTC db
; (inj₂ (k , r)) → returnTC (db ∙ return r)})
-- db << n with (name2rule n)
-- db << n | inj₁ msg = db
-- db << n | inj₂ (k , r) = db ∙ return r
| {
"alphanum_fraction": 0.6341642229,
"avg_line_length": 31.7209302326,
"ext": "agda",
"hexsha": "d66a2e6a3f28831a601bb66d66a1f6510c2a534d",
"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/Auto/Extensible.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/Auto/Extensible.agda",
"max_line_length": 111,
"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/Auto/Extensible.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": 431,
"size": 1364
} |
module Issue4267.A1 where
record RA1 : Set₁ where
field
A : Set
| {
"alphanum_fraction": 0.6901408451,
"avg_line_length": 11.8333333333,
"ext": "agda",
"hexsha": "697580afb4ea77bf54aeb24d8a6d50e23ada677d",
"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/Issue4267/A1.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/Issue4267/A1.agda",
"max_line_length": 25,
"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/Issue4267/A1.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 24,
"size": 71
} |
module consoleExamples.helloWorld where
open import ConsoleLib
main : ConsoleProg
main = run (WriteString "Hello World")
| {
"alphanum_fraction": 0.8048780488,
"avg_line_length": 17.5714285714,
"ext": "agda",
"hexsha": "3ac59fbcb490278c232cd544e84faa242eff2c2b",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z",
"max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/ooAgda",
"max_forks_repo_path": "examples/consoleExamples/helloWorld.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/ooAgda",
"max_issues_repo_path": "examples/consoleExamples/helloWorld.agda",
"max_line_length": 39,
"max_stars_count": 23,
"max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/ooAgda",
"max_stars_repo_path": "examples/consoleExamples/helloWorld.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z",
"num_tokens": 28,
"size": 123
} |
module Prelude.Smashed where
open import Prelude.Equality
open import Prelude.Unit
open import Prelude.Empty
open import Prelude.Nat.Core
open import Prelude.Function
open import Prelude.Ord
record Smashed {a} (A : Set a) : Set a where
field
smashed : ∀ {x y : A} → x ≡ y
open Smashed {{...}} public
{-# DISPLAY Smashed.smashed _ = smashed #-}
instance
Smash⊤ : Smashed ⊤
smashed {{Smash⊤}} = refl
Smash⊥ : Smashed ⊥
smashed {{Smash⊥}} {}
Smash≡ : ∀ {a} {A : Set a} {a b : A} → Smashed (a ≡ b)
smashed {{Smash≡}} {x = refl} {refl} = refl
-- Can't be instance, since this would interfere with the ⊤ and ⊥ instances.
SmashNonZero : ∀ {n : Nat} → Smashed (NonZero n)
SmashNonZero {zero} = it
SmashNonZero {suc n} = it
| {
"alphanum_fraction": 0.6522911051,
"avg_line_length": 23.1875,
"ext": "agda",
"hexsha": "7ffee0a17595991e7cb460dd51fd4fa9bac918a7",
"lang": "Agda",
"max_forks_count": 24,
"max_forks_repo_forks_event_max_datetime": "2021-04-22T06:10:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-12T18:03:45.000Z",
"max_forks_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "L-TChen/agda-prelude",
"max_forks_repo_path": "src/Prelude/Smashed.agda",
"max_issues_count": 59,
"max_issues_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T07:32:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-02-09T05:36:44.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "L-TChen/agda-prelude",
"max_issues_repo_path": "src/Prelude/Smashed.agda",
"max_line_length": 76,
"max_stars_count": 111,
"max_stars_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "L-TChen/agda-prelude",
"max_stars_repo_path": "src/Prelude/Smashed.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-12T23:29:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-05T11:28:15.000Z",
"num_tokens": 252,
"size": 742
} |
{-# OPTIONS --cubical --safe #-}
open import Agda.Builtin.Cubical.Path
open import Agda.Primitive
private
variable
a : Level
A B : Set a
Is-proposition : Set a → Set a
Is-proposition A = (x y : A) → x ≡ y
data ∥_∥ (A : Set a) : Set a where
∣_∣ : A → ∥ A ∥
@0 trivial : Is-proposition ∥ A ∥
rec : @0 Is-proposition B → (A → B) → ∥ A ∥ → B
rec p f ∣ x ∣ = f x
rec p f (trivial x y i) = p (rec p f x) (rec p f y) i
| {
"alphanum_fraction": 0.54,
"avg_line_length": 21.4285714286,
"ext": "agda",
"hexsha": "c5825c66a10a1320262bb7d98e70f8f205f8bf25",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "cagix/agda",
"max_forks_repo_path": "test/Succeed/Issue4638-Cubical.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "cagix/agda",
"max_issues_repo_path": "test/Succeed/Issue4638-Cubical.agda",
"max_line_length": 53,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "cagix/agda",
"max_stars_repo_path": "test/Succeed/Issue4638-Cubical.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": 181,
"size": 450
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Object.Product.Core {o ℓ e} (𝒞 : Category o ℓ e) where
open import Level
open import Function using (flip; _$_)
open import Categories.Morphism 𝒞
open import Categories.Morphism.Reasoning 𝒞
open Category 𝒞
open HomReasoning
private
variable
A B C D X Y Z : Obj
h i j : A ⇒ B
-- Borrowed from Dan Doel's definition of products
record Product (A B : Obj) : Set (o ⊔ ℓ ⊔ e) where
infix 10 ⟨_,_⟩
field
A×B : Obj
π₁ : A×B ⇒ A
π₂ : A×B ⇒ B
⟨_,_⟩ : C ⇒ A → C ⇒ B → C ⇒ A×B
project₁ : π₁ ∘ ⟨ h , i ⟩ ≈ h
project₂ : π₂ ∘ ⟨ h , i ⟩ ≈ i
unique : π₁ ∘ h ≈ i → π₂ ∘ h ≈ j → ⟨ i , j ⟩ ≈ h
g-η : ⟨ π₁ ∘ h , π₂ ∘ h ⟩ ≈ h
g-η = unique refl refl
η : ⟨ π₁ , π₂ ⟩ ≈ id
η = unique identityʳ identityʳ
⟨⟩-cong₂ : ∀ {f f′ : C ⇒ A} {g g′ : C ⇒ B} → f ≈ f′ → g ≈ g′ → ⟨ f , g ⟩ ≈ ⟨ f′ , g′ ⟩
⟨⟩-cong₂ f≡f′ g≡g′ = unique (project₁ ○ ⟺ f≡f′) (project₂ ○ ⟺ g≡g′)
∘-distribʳ-⟨⟩ : ∀ {f : C ⇒ A} {g : C ⇒ B} {q : D ⇒ C} → ⟨ f , g ⟩ ∘ q ≈ ⟨ f ∘ q , g ∘ q ⟩
∘-distribʳ-⟨⟩ = ⟺ $ unique (pullˡ project₁) (pullˡ project₂)
unique′ : π₁ ∘ h ≈ π₁ ∘ i → π₂ ∘ h ≈ π₂ ∘ i → h ≈ i
unique′ eq₁ eq₂ = trans (sym (unique eq₁ eq₂)) g-η
module _ {A B : Obj} where
open Product {A} {B} renaming (⟨_,_⟩ to _⟨_,_⟩)
repack : (p₁ p₂ : Product A B) → A×B p₁ ⇒ A×B p₂
repack p₁ p₂ = p₂ ⟨ π₁ p₁ , π₂ p₁ ⟩
repack∘ : (p₁ p₂ p₃ : Product A B) → repack p₂ p₃ ∘ repack p₁ p₂ ≈ repack p₁ p₃
repack∘ p₁ p₂ p₃ = ⟺ $ unique p₃
(glueTrianglesʳ (project₁ p₃) (project₁ p₂))
(glueTrianglesʳ (project₂ p₃) (project₂ p₂))
repack≡id : (p : Product A B) → repack p p ≈ id
repack≡id = η
repack-cancel : (p₁ p₂ : Product A B) → repack p₁ p₂ ∘ repack p₂ p₁ ≈ id
repack-cancel p₁ p₂ = repack∘ p₂ p₁ p₂ ○ repack≡id p₂
up-to-iso : ∀ (p₁ p₂ : Product A B) → Product.A×B p₁ ≅ Product.A×B p₂
up-to-iso p₁ p₂ = record
{ from = repack p₁ p₂
; to = repack p₂ p₁
; iso = record
{ isoˡ = repack-cancel p₂ p₁
; isoʳ = repack-cancel p₁ p₂
}
}
transport-by-iso : ∀ (p : Product A B) → ∀ {X} → Product.A×B p ≅ X → Product A B
transport-by-iso p {X} p≅X = record
{ A×B = X
; π₁ = π₁ ∘ to
; π₂ = π₂ ∘ to
; ⟨_,_⟩ = λ h₁ h₂ → from ∘ ⟨ h₁ , h₂ ⟩
; project₁ = cancelInner isoˡ ○ project₁
; project₂ = cancelInner isoˡ ○ project₂
; unique = λ {_ i l r} pf₁ pf₂ → begin
from ∘ ⟨ l , r ⟩ ≈˘⟨ refl⟩∘⟨ ⟨⟩-cong₂ pf₁ pf₂ ⟩
from ∘ ⟨ (π₁ ∘ to) ∘ i , (π₂ ∘ to) ∘ i ⟩ ≈⟨ refl⟩∘⟨ unique (⟺ assoc) (⟺ assoc) ⟩
from ∘ to ∘ i ≈⟨ cancelˡ isoʳ ⟩
i ∎
}
where open Product p
open _≅_ p≅X
Reversible : (p : Product A B) → Product B A
Reversible p = record
{ A×B = A×B
; π₁ = π₂
; π₂ = π₁
; ⟨_,_⟩ = flip ⟨_,_⟩
; project₁ = project₂
; project₂ = project₁
; unique = flip unique
}
where open Product p
Commutative : (p₁ : Product A B) (p₂ : Product B A) → Product.A×B p₁ ≅ Product.A×B p₂
Commutative p₁ p₂ = up-to-iso p₁ (Reversible p₂)
Associable : ∀ (p₁ : Product X Y) (p₂ : Product Y Z) (p₃ : Product X (Product.A×B p₂)) → Product (Product.A×B p₁) Z
Associable p₁ p₂ p₃ = record
{ A×B = A×B p₃
; π₁ = p₁ ⟨ π₁ p₃ , π₁ p₂ ∘ π₂ p₃ ⟩
; π₂ = π₂ p₂ ∘ π₂ p₃
; ⟨_,_⟩ = λ f g → p₃ ⟨ π₁ p₁ ∘ f , p₂ ⟨ π₂ p₁ ∘ f , g ⟩ ⟩
; project₁ = λ {_ f g} → begin
p₁ ⟨ π₁ p₃ , π₁ p₂ ∘ π₂ p₃ ⟩ ∘ p₃ ⟨ π₁ p₁ ∘ f , p₂ ⟨ π₂ p₁ ∘ f , g ⟩ ⟩ ≈⟨ ∘-distribʳ-⟨⟩ p₁ ⟩
p₁ ⟨ π₁ p₃ ∘ p₃ ⟨ π₁ p₁ ∘ f , p₂ ⟨ π₂ p₁ ∘ f , g ⟩ ⟩
, (π₁ p₂ ∘ π₂ p₃) ∘ p₃ ⟨ π₁ p₁ ∘ f , p₂ ⟨ π₂ p₁ ∘ f , g ⟩ ⟩ ⟩ ≈⟨ ⟨⟩-cong₂ p₁ (project₁ p₃) (glueTrianglesˡ (project₁ p₂) (project₂ p₃)) ⟩
p₁ ⟨ π₁ p₁ ∘ f , π₂ p₁ ∘ f ⟩ ≈⟨ g-η p₁ ⟩
f ∎
; project₂ = λ {_ f g} → glueTrianglesˡ (project₂ p₂) (project₂ p₃)
; unique = λ {_ i f g} pf₁ pf₂ → begin
p₃ ⟨ π₁ p₁ ∘ f , p₂ ⟨ π₂ p₁ ∘ f , g ⟩ ⟩ ≈⟨ ⟨⟩-cong₂ p₃ (∘-resp-≈ʳ (sym pf₁))
(⟨⟩-cong₂ p₂ (∘-resp-≈ʳ (sym pf₁)) (sym pf₂)) ⟩
p₃ ⟨ π₁ p₁ ∘ p₁ ⟨ π₁ p₃ , π₁ p₂ ∘ π₂ p₃ ⟩ ∘ i
, p₂ ⟨ π₂ p₁ ∘ p₁ ⟨ π₁ p₃ , π₁ p₂ ∘ π₂ p₃ ⟩ ∘ i
, (π₂ p₂ ∘ π₂ p₃) ∘ i ⟩ ⟩ ≈⟨ ⟨⟩-cong₂ p₃ (pullˡ (project₁ p₁))
(⟨⟩-cong₂ p₂ (trans (pullˡ (project₂ p₁)) assoc)
assoc) ⟩
p₃ ⟨ π₁ p₃ ∘ i
, p₂ ⟨ π₁ p₂ ∘ π₂ p₃ ∘ i , π₂ p₂ ∘ π₂ p₃ ∘ i ⟩ ⟩ ≈⟨ ⟨⟩-cong₂ p₃ refl (g-η p₂) ⟩
p₃ ⟨ π₁ p₃ ∘ i , π₂ p₃ ∘ i ⟩ ≈⟨ g-η p₃ ⟩
i ∎
}
where open Product renaming (⟨_,_⟩ to _⟨_,_⟩)
Associative : ∀ (p₁ : Product X Y) (p₂ : Product Y Z)
(p₃ : Product X (Product.A×B p₂)) (p₄ : Product (Product.A×B p₁) Z) →
(Product.A×B p₃) ≅ (Product.A×B p₄)
Associative p₁ p₂ p₃ p₄ = up-to-iso (Associable p₁ p₂ p₃) p₄
Mobile : ∀ {A₁ B₁ A₂ B₂} (p : Product A₁ B₁) → A₁ ≅ A₂ → B₁ ≅ B₂ → Product A₂ B₂
Mobile p A₁≅A₂ B₁≅B₂ = record
{ A×B = A×B
; π₁ = from A₁≅A₂ ∘ π₁
; π₂ = from B₁≅B₂ ∘ π₂
; ⟨_,_⟩ = λ h k → ⟨ to A₁≅A₂ ∘ h , to B₁≅B₂ ∘ k ⟩
; project₁ = begin
(from A₁≅A₂ ∘ π₁) ∘ ⟨ to A₁≅A₂ ∘ _ , to B₁≅B₂ ∘ _ ⟩ ≈⟨ pullʳ project₁ ⟩
from A₁≅A₂ ∘ (to A₁≅A₂ ∘ _) ≈⟨ cancelˡ (isoʳ A₁≅A₂) ⟩
_ ∎
; project₂ = begin
(from B₁≅B₂ ∘ π₂) ∘ ⟨ to A₁≅A₂ ∘ _ , to B₁≅B₂ ∘ _ ⟩ ≈⟨ pullʳ project₂ ⟩
from B₁≅B₂ ∘ (to B₁≅B₂ ∘ _) ≈⟨ cancelˡ (isoʳ B₁≅B₂) ⟩
_ ∎
; unique = λ pfˡ pfʳ → unique (switch-fromtoˡ A₁≅A₂ (⟺ assoc ○ pfˡ))
(switch-fromtoˡ B₁≅B₂ (⟺ assoc ○ pfʳ))
}
where open Product p
open _≅_
| {
"alphanum_fraction": 0.4544565749,
"avg_line_length": 38.1180124224,
"ext": "agda",
"hexsha": "5c528c05dfd44b7c22d32e29467fb883eba4db40",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Taneb/agda-categories",
"max_forks_repo_path": "Categories/Object/Product/Core.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Taneb/agda-categories",
"max_issues_repo_path": "Categories/Object/Product/Core.agda",
"max_line_length": 150,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Taneb/agda-categories",
"max_stars_repo_path": "Categories/Object/Product/Core.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2799,
"size": 6137
} |
module _ where
open import Agda.Builtin.Nat
postulate
F : Set → Set
pure : ∀ {A} → A → F A
-- _<*>_ : ∀ {A B} → F (A → B) → F A → F B
fail : F Nat → F Nat
fail a = (| suc a |)
| {
"alphanum_fraction": 0.4946236559,
"avg_line_length": 14.3076923077,
"ext": "agda",
"hexsha": "e35b5c127768d9b343537c9a31d4ee9ace1d24fb",
"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/IdiomBracketsNotInScope.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/IdiomBracketsNotInScope.agda",
"max_line_length": 44,
"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/IdiomBracketsNotInScope.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": 80,
"size": 186
} |
postulate
A : Set
f : (B : Set) → B → A
f A a = a
-- Expected error:
-- A !=< A of type Set
-- (because one is a variable and one a defined identifier)
-- when checking that the expression a has type A
| {
"alphanum_fraction": 0.6359223301,
"avg_line_length": 18.7272727273,
"ext": "agda",
"hexsha": "0efbcf3feb24d59c1841cd80f4772e8a788e0226",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Fail/Issue998c.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Fail/Issue998c.agda",
"max_line_length": 59,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Fail/Issue998c.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": 63,
"size": 206
} |
{-# OPTIONS --rewriting #-}
module FFI.Data.Aeson where
open import Agda.Builtin.Equality using (_≡_)
open import Agda.Builtin.Equality.Rewrite using ()
open import Agda.Builtin.Bool using (Bool)
open import Agda.Builtin.String using (String)
open import FFI.Data.ByteString using (ByteString)
open import FFI.Data.HaskellString using (HaskellString; pack)
open import FFI.Data.Maybe using (Maybe; just; nothing)
open import FFI.Data.Either using (Either; mapL)
open import FFI.Data.Scientific using (Scientific)
open import FFI.Data.Vector using (Vector)
open import Properties.Equality using (_≢_)
{-# FOREIGN GHC import qualified Data.Aeson #-}
{-# FOREIGN GHC import qualified Data.Aeson.Key #-}
{-# FOREIGN GHC import qualified Data.Aeson.KeyMap #-}
postulate
KeyMap : Set → Set
Key : Set
fromString : String → Key
toString : Key → String
empty : ∀ {A} → KeyMap A
singleton : ∀ {A} → Key → A → (KeyMap A)
insert : ∀ {A} → Key → A → (KeyMap A) → (KeyMap A)
delete : ∀ {A} → Key → (KeyMap A) → (KeyMap A)
unionWith : ∀ {A} → (A → A → A) → (KeyMap A) → (KeyMap A) → (KeyMap A)
lookup : ∀ {A} → Key -> KeyMap A -> Maybe A
{-# POLARITY KeyMap ++ #-}
{-# COMPILE GHC KeyMap = type Data.Aeson.KeyMap.KeyMap #-}
{-# COMPILE GHC Key = type Data.Aeson.Key.Key #-}
{-# COMPILE GHC fromString = Data.Aeson.Key.fromText #-}
{-# COMPILE GHC toString = Data.Aeson.Key.toText #-}
{-# COMPILE GHC empty = \_ -> Data.Aeson.KeyMap.empty #-}
{-# COMPILE GHC singleton = \_ -> Data.Aeson.KeyMap.singleton #-}
{-# COMPILE GHC insert = \_ -> Data.Aeson.KeyMap.insert #-}
{-# COMPILE GHC delete = \_ -> Data.Aeson.KeyMap.delete #-}
{-# COMPILE GHC unionWith = \_ -> Data.Aeson.KeyMap.unionWith #-}
{-# COMPILE GHC lookup = \_ -> Data.Aeson.KeyMap.lookup #-}
postulate lookup-insert : ∀ {A} k v (m : KeyMap A) → (lookup k (insert k v m) ≡ just v)
postulate lookup-empty : ∀ {A} k → (lookup {A} k empty ≡ nothing)
postulate lookup-insert-not : ∀ {A} j k v (m : KeyMap A) → (j ≢ k) → (lookup k m ≡ lookup k (insert j v m))
postulate singleton-insert-empty : ∀ {A} k (v : A) → (singleton k v ≡ insert k v empty)
postulate insert-swap : ∀ {A} j k (v w : A) m → (j ≢ k) → insert j v (insert k w m) ≡ insert k w (insert j v m)
postulate insert-over : ∀ {A} j k (v w : A) m → (j ≡ k) → insert j v (insert k w m) ≡ insert j v m
postulate to-from : ∀ k → toString(fromString k) ≡ k
postulate from-to : ∀ k → fromString(toString k) ≡ k
{-# REWRITE lookup-insert lookup-empty singleton-insert-empty #-}
data Value : Set where
object : KeyMap Value → Value
array : Vector Value → Value
string : String → Value
number : Scientific → Value
bool : Bool → Value
null : Value
{-# COMPILE GHC Value = data Data.Aeson.Value (Data.Aeson.Object|Data.Aeson.Array|Data.Aeson.String|Data.Aeson.Number|Data.Aeson.Bool|Data.Aeson.Null) #-}
Object = KeyMap Value
Array = Vector Value
postulate
decode : ByteString → Maybe Value
eitherHDecode : ByteString → Either HaskellString Value
{-# COMPILE GHC decode = Data.Aeson.decodeStrict #-}
{-# COMPILE GHC eitherHDecode = Data.Aeson.eitherDecodeStrict #-}
eitherDecode : ByteString → Either String Value
eitherDecode bytes = mapL pack (eitherHDecode bytes)
| {
"alphanum_fraction": 0.6746724891,
"avg_line_length": 41.1025641026,
"ext": "agda",
"hexsha": "43014719abbb1e56727573588132745f3edf89b8",
"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": "72d8d443431875607fd457a13fe36ea62804d327",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "TheGreatSageEqualToHeaven/luau",
"max_forks_repo_path": "prototyping/FFI/Data/Aeson.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "72d8d443431875607fd457a13fe36ea62804d327",
"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": "TheGreatSageEqualToHeaven/luau",
"max_issues_repo_path": "prototyping/FFI/Data/Aeson.agda",
"max_line_length": 154,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "72d8d443431875607fd457a13fe36ea62804d327",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "TheGreatSageEqualToHeaven/luau",
"max_stars_repo_path": "prototyping/FFI/Data/Aeson.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-05T21:53:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-12-05T21:53:03.000Z",
"num_tokens": 934,
"size": 3206
} |
import cedille-options
module elaboration-helpers (options : cedille-options.options) where
open import lib
open import monad-instances
open import general-util
open import cedille-types
open import syntax-util
open import ctxt
open import conversion
open import constants
open import to-string options
open import subst
open import rename
open import is-free
open import toplevel-state options {id}
open import spans options {id}
open import datatype-functions
open import templates
open import erase
uncurry' : ∀ {A B C D : Set} → (A → B → C → D) → (A × B × C) → D
uncurry' f (a , b , c) = f a b c
uncurry'' : ∀ {A B C D E : Set} → (A → B → C → D → E) → (A × B × C × D) → E
uncurry'' f (a , b , c , d) = f a b c d
uncurry''' : ∀ {A B C D E F : Set} → (A → B → C → D → E → F) → (A × B × C × D × E) → F
uncurry''' f (a , b , c , d , e) = f a b c d e
ctxt-term-decl' : posinfo → var → type → ctxt → ctxt
ctxt-term-decl' pi x T (mk-ctxt (fn , mn , ps , q) ss is os Δ) =
mk-ctxt (fn , mn , ps , trie-insert q x (x , [])) ss
(trie-insert is x (term-decl T , fn , pi)) os Δ
ctxt-type-decl' : posinfo → var → kind → ctxt → ctxt
ctxt-type-decl' pi x k (mk-ctxt (fn , mn , ps , q) ss is os Δ) =
mk-ctxt (fn , mn , ps , trie-insert q x (x , [])) ss
(trie-insert is x (type-decl k , fn , pi)) os Δ
ctxt-tk-decl' : posinfo → var → tk → ctxt → ctxt
ctxt-tk-decl' pi x (Tkt T) = ctxt-term-decl' pi x T
ctxt-tk-decl' pi x (Tkk k) = ctxt-type-decl' pi x k
ctxt-param-decl : var → var → tk → ctxt → ctxt
ctxt-param-decl x x' atk Γ @ (mk-ctxt (fn , mn , ps , q) ss is os Δ) =
let d = case atk of λ {(Tkt T) → term-decl T; (Tkk k) → type-decl k} in
mk-ctxt
(fn , mn , ps , trie-insert q x (x , [])) ss
(trie-insert is x' (d , fn , pi-gen)) os Δ
ctxt-term-def' : var → var → term → type → opacity → ctxt → ctxt
ctxt-term-def' x x' t T op Γ @ (mk-ctxt (fn , mn , ps , q) ss is os Δ) = mk-ctxt
(fn , mn , ps , qualif-insert-params q (mn # x) x ps) ss
(trie-insert is x' (term-def (just ps) op (just $ hnf Γ unfold-head t tt) T , fn , x)) os Δ
ctxt-type-def' : var → var → type → kind → opacity → ctxt → ctxt
ctxt-type-def' x x' T k op Γ @ (mk-ctxt (fn , mn , ps , q) ss is os Δ) = mk-ctxt
(fn , mn , ps , qualif-insert-params q (mn # x) x ps) ss
(trie-insert is x' (type-def (just ps) op (just $ hnf Γ (unfolding-elab unfold-head) T tt) k , fn , x)) os Δ
ctxt-let-term-def : posinfo → var → term → type → ctxt → ctxt
ctxt-let-term-def pi x t T Γ @ (mk-ctxt (fn , mn , ps , q) ss is os Δ) =
mk-ctxt (fn , mn , ps , trie-insert q x (x , [])) ss
(trie-insert is x (term-def nothing OpacTrans (just $ hnf Γ unfold-head t tt) T , fn , pi)) os Δ
ctxt-let-type-def : posinfo → var → type → kind → ctxt → ctxt
ctxt-let-type-def pi x T k Γ @ (mk-ctxt (fn , mn , ps , q) ss is os Δ) =
mk-ctxt (fn , mn , ps , trie-insert q x (x , [])) ss
(trie-insert is x (type-def nothing OpacTrans (just $ hnf Γ (unfolding-elab unfold-head) T tt) k , fn , pi)) os Δ
{-
ctxt-μ-out-def : var → term → term → var → ctxt → ctxt
ctxt-μ-out-def x t c y (mk-ctxt mod ss is os Δ) =
let is' = is --trie-insert is y (term-udef nothing OpacTrans c , "missing" , "missing")
is'' = trie-insert is' x (term-udef nothing OpacTrans t , y , y) in
mk-ctxt mod ss is'' os Δ
-}
ctxt-datatype-decl' : var → var → var → args → ctxt → ctxt
ctxt-datatype-decl' X isType/v Type/v as Γ@(mk-ctxt (fn , mn , ps , q) ss is os (Δ , μ' , μ)) =
mk-ctxt (fn , mn , ps , q) ss is os $ Δ , trie-insert μ' Type/v (X , isType/v , as) , μ
--mk-ctxt (fn , mn , ps , q) ss (trie-insert is ("/" ^ Type/v) $ rename-def ("/" ^ X) , "missing" , "missing") os $ Δ , trie-insert μ' Type/v (X , isType/v , as) , μ
{-
ctxt-rename-def' : var → var → args → ctxt → ctxt
ctxt-rename-def' x x' as (mk-ctxt (fn , mn , ps , q) ss is os Δ) = mk-ctxt (fn , mn , ps , trie-insert q x (x' , as)) ss (trie-insert is x (rename-def x' , "missing" , "missing")) os Δ
-}
ctxt-kind-def' : var → var → params → kind → ctxt → ctxt
ctxt-kind-def' x x' ps2 k Γ @ (mk-ctxt (fn , mn , ps1 , q) ss is os Δ) = mk-ctxt
(fn , mn , ps1 , qualif-insert-params q (mn # x) x ps1) ss
(trie-insert is x' (kind-def (ps1 ++ qualif-params Γ ps2) k' , fn , pi-gen)) os Δ
where
k' = hnf Γ (unfolding-elab unfold-head) k tt
{-
ctxt-datatype-def' : var → var → params → kind → kind → ctrs → ctxt → ctxt
ctxt-datatype-def' x x' psᵢ kᵢ k cs Γ@(mk-ctxt (fn , mn , ps , q) ss is os (Δ , μₓ)) = mk-ctxt
(fn , mn , ps , q') ss
(trie-insert is x' (type-def (just $ ps ++ psᵢ) OpacTrans nothing k , fn , x)) os
(trie-insert Δ x' (ps ++ psᵢ , kᵢ , k , cs) , μₓ)
where
q' = qualif-insert-params q x x' ps
-}
ctxt-lookup-term-var' : ctxt → var → maybe type
ctxt-lookup-term-var' Γ @ (mk-ctxt (fn , mn , ps , q) ss is os Δ) x =
env-lookup Γ x ≫=maybe λ where
(term-decl T , _) → just T
(term-def ps _ _ T , _ , x') →
let ps = maybe-else [] id ps in
just $ abs-expand-type ps T
_ → nothing
-- TODO: Could there be parameter/argument clashes if the same parameter variable is defined multiple times?
-- TODO: Could variables be parameter-expanded multiple times?
ctxt-lookup-type-var' : ctxt → var → maybe kind
ctxt-lookup-type-var' Γ @ (mk-ctxt (fn , mn , ps , q) ss is os Δ) x =
env-lookup Γ x ≫=maybe λ where
(type-decl k , _) → just k
(type-def ps _ _ k , _ , x') →
let ps = maybe-else [] id ps in
just $ abs-expand-kind ps k
_ → nothing
subst-qualif : ∀ {ed : exprd} → ctxt → renamectxt → ⟦ ed ⟧ → ⟦ ed ⟧
subst-qualif{TERM} Γ ρₓ = subst-renamectxt Γ ρₓ ∘ qualif-term Γ
subst-qualif{TYPE} Γ ρₓ = subst-renamectxt Γ ρₓ ∘ qualif-type Γ
subst-qualif{KIND} Γ ρₓ = subst-renamectxt Γ ρₓ ∘ qualif-kind Γ
subst-qualif Γ ρₓ = id
rename-validify : string → string
rename-validify = 𝕃char-to-string ∘ (h ∘ string-to-𝕃char) where
validify-char : char → 𝕃 char
validify-char '/' = [ '-' ]
validify-char c with
(c =char 'a') ||
(c =char 'z') ||
(c =char 'A') ||
(c =char 'Z') ||
(c =char '\'') ||
(c =char '-') ||
(c =char '_') ||
is-digit c ||
(('a' <char c) && (c <char 'z')) ||
(('A' <char c) && (c <char 'Z'))
...| tt = [ c ]
...| ff = 'Z' :: string-to-𝕃char (ℕ-to-string (toNat c)) ++ [ 'Z' ]
h : 𝕃 char → 𝕃 char
h [] = []
h (c :: cs) = validify-char c ++ h cs
-- Returns a fresh variable name by adding primes and replacing invalid characters
fresh-var' : string → (string → 𝔹) → renamectxt → string
fresh-var' = fresh-var ∘ rename-validify
rename-new_from_for_ : ∀ {X : Set} → var → ctxt → (var → X) → X
rename-new ignored-var from Γ for f = f $ fresh-var' "x" (ctxt-binds-var Γ) empty-renamectxt
rename-new x from Γ for f = f $ fresh-var' x (ctxt-binds-var Γ) empty-renamectxt
rename_from_for_ : ∀ {X : Set} → var → ctxt → (var → X) → X
rename ignored-var from Γ for f = f ignored-var
rename x from Γ for f = f $ fresh-var' x (ctxt-binds-var Γ) empty-renamectxt
fresh-id-term : ctxt → term
fresh-id-term Γ = rename "x" from Γ for λ x → mlam x $ mvar x
get-renaming : renamectxt → var → var → var × renamectxt
get-renaming ρₓ xₒ x = let x' = fresh-var' x (renamectxt-in-range ρₓ) ρₓ in x' , renamectxt-insert ρₓ xₒ x'
rename_-_from_for_ : ∀ {X : Set} → var → var → renamectxt → (var → renamectxt → X) → X
rename xₒ - ignored-var from ρₓ for f = f ignored-var ρₓ
rename xₒ - x from ρₓ for f = uncurry f $ get-renaming ρₓ xₒ x
rename_-_lookup_for_ : ∀ {X : Set} → var → var → renamectxt → (var → renamectxt → X) → X
rename xₒ - x lookup ρₓ for f with renamectxt-lookup ρₓ xₒ
...| nothing = rename xₒ - x from ρₓ for f
...| just x' = f x' ρₓ
qualif-new-var : ctxt → var → var
qualif-new-var Γ x = ctxt-get-current-modname Γ # x
ctxt-datatype-def' : var → var → var → params → kind → kind → ctrs → ctxt → ctxt
ctxt-datatype-def' v Is/v is/v psᵢ kᵢ k cs Γ@(mk-ctxt (fn , mn , ps , q) ss i os (Δ , μ' , μ)) =
mk-ctxt (fn , mn , ps , q) ss i os
(trie-insert Δ v (ps ++ psᵢ , kᵢ , k , cs) ,
trie-insert μ' elab-mu-prev-key (v , is/v , []) ,
trie-insert μ Is/v v)
mbeta : term → term → term
mrho : term → var → type → term → term
mtpeq : term → term → type
mbeta t t' = Beta pi-gen (SomeTerm t pi-gen) (SomeTerm t' pi-gen)
mrho t x T t' = Rho pi-gen RhoPlain NoNums t (Guide pi-gen x T) t'
mtpeq t1 t2 = TpEq pi-gen t1 t2 pi-gen
{-
subst-args-params : ctxt → args → params → kind → kind
subst-args-params Γ (ArgsCons (TermArg _ t) ys) (ParamsCons (Decl _ _ _ x _ _) ps) k =
subst-args-params Γ ys ps $ subst Γ t x k
subst-args-params Γ (ArgsCons (TypeArg t) ys) (ParamsCons (Decl _ _ _ x _ _) ps) k =
subst-args-params Γ ys ps $ subst Γ t x k
subst-args-params Γ ys ps k = k
-}
module reindexing (Γ : ctxt) (isₒ : indices) where
reindex-fresh-var : renamectxt → trie indices → var → var
reindex-fresh-var ρₓ is ignored-var = ignored-var
reindex-fresh-var ρₓ is x =
fresh-var x (λ x' → ctxt-binds-var Γ x' || trie-contains is x') ρₓ
rename-indices : renamectxt → trie indices → indices
rename-indices ρₓ is = foldr {B = renamectxt → indices}
(λ {(Index x atk) f ρₓ →
let x' = reindex-fresh-var ρₓ is x in
Index x' (substh-tk {TERM} Γ ρₓ empty-trie atk) :: f (renamectxt-insert ρₓ x x')})
(λ ρₓ → []) isₒ ρₓ
reindex-subst : ∀ {ed} → ⟦ ed ⟧ → ⟦ ed ⟧
reindex-subst {ed} = substs {ed} {TERM} Γ empty-trie
reindex-t : Set → Set
reindex-t X = renamectxt → trie indices → X → X
{-# TERMINATING #-}
reindex : ∀ {ed} → reindex-t ⟦ ed ⟧
reindex-term : reindex-t term
reindex-type : reindex-t type
reindex-kind : reindex-t kind
reindex-tk : reindex-t tk
reindex-liftingType : reindex-t liftingType
reindex-optTerm : reindex-t optTerm
reindex-optType : reindex-t optType
reindex-optGuide : reindex-t optGuide
reindex-optClass : reindex-t optClass
reindex-lterms : reindex-t lterms
reindex-args : reindex-t args
reindex-arg : reindex-t arg
reindex-theta : reindex-t theta
reindex-vars : reindex-t (maybe vars)
reindex-defTermOrType : renamectxt → trie indices → defTermOrType → defTermOrType × renamectxt
reindex{TERM} = reindex-term
reindex{TYPE} = reindex-type
reindex{KIND} = reindex-kind
reindex{TK} = reindex-tk
reindex = λ ρₓ is x → x
rc-is : renamectxt → indices → renamectxt
rc-is = foldr λ {(Index x atk) ρₓ → renamectxt-insert ρₓ x x}
index-var = "indices"
index-type-var = "Indices"
is-index-var = isJust ∘ is-pfx index-var
is-index-type-var = isJust ∘ is-pfx index-type-var
reindex-term ρₓ is (App t me (Var pi x)) with trie-lookup is x
...| nothing = App (reindex-term ρₓ is t) me (reindex-term ρₓ is (Var pi x))
...| just is' = indices-to-apps is' $ reindex-term ρₓ is t
reindex-term ρₓ is (App t me t') =
App (reindex-term ρₓ is t) me (reindex-term ρₓ is t')
reindex-term ρₓ is (AppTp t T) =
AppTp (reindex-term ρₓ is t) (reindex-type ρₓ is T)
reindex-term ρₓ is (Beta pi ot ot') =
Beta pi (reindex-optTerm ρₓ is ot) (reindex-optTerm ρₓ is ot')
reindex-term ρₓ is (Chi pi oT t) =
Chi pi (reindex-optType ρₓ is oT) (reindex-term ρₓ is t)
reindex-term ρₓ is (Delta pi oT t) =
Delta pi (reindex-optType ρₓ is oT) (reindex-term ρₓ is t)
reindex-term ρₓ is (Epsilon pi lr m t) =
Epsilon pi lr m (reindex-term ρₓ is t)
reindex-term ρₓ is (Hole pi) =
Hole pi
reindex-term ρₓ is (IotaPair pi t t' g pi') =
IotaPair pi (reindex-term ρₓ is t) (reindex-term ρₓ is t') (reindex-optGuide ρₓ is g) pi'
reindex-term ρₓ is (IotaProj t n pi) =
IotaProj (reindex-term ρₓ is t) n pi
reindex-term ρₓ is (Lam pi me pi' x oc t) with is-index-var x
...| ff = let x' = reindex-fresh-var ρₓ is x in
Lam pi me pi' x' (reindex-optClass ρₓ is oc) (reindex-term (renamectxt-insert ρₓ x x') is t)
...| tt with rename-indices ρₓ is | oc
...| isₙ | NoClass = indices-to-lams' isₙ $ reindex-term (rc-is ρₓ isₙ) (trie-insert is x isₙ) t
...| isₙ | SomeClass atk = indices-to-lams isₙ $ reindex-term (rc-is ρₓ isₙ) (trie-insert is x isₙ) t
reindex-term ρₓ is (Let pi fe d t) =
elim-pair (reindex-defTermOrType ρₓ is d) λ d' ρₓ' → Let pi fe d' (reindex-term ρₓ' is t)
reindex-term ρₓ is (Open pi o pi' x t) =
Open pi o pi' x (reindex-term ρₓ is t)
reindex-term ρₓ is (Parens pi t pi') =
reindex-term ρₓ is t
reindex-term ρₓ is (Phi pi t₌ t₁ t₂ pi') =
Phi pi (reindex-term ρₓ is t₌) (reindex-term ρₓ is t₁) (reindex-term ρₓ is t₂) pi'
reindex-term ρₓ is (Rho pi op on t og t') =
Rho pi op on (reindex-term ρₓ is t) (reindex-optGuide ρₓ is og) (reindex-term ρₓ is t')
reindex-term ρₓ is (Sigma pi t) =
Sigma pi (reindex-term ρₓ is t)
reindex-term ρₓ is (Theta pi θ t ts) =
Theta pi (reindex-theta ρₓ is θ) (reindex-term ρₓ is t) (reindex-lterms ρₓ is ts)
reindex-term ρₓ is (Var pi x) =
Var pi $ renamectxt-rep ρₓ x
reindex-term ρₓ is (Mu pi pi' x t oT pi'' cs pi''') = Var pi-gen "template-mu-not-allowed"
reindex-term ρₓ is (Mu' pi ot t oT pi' cs pi'') = Var pi-gen "template-mu-not-allowed"
reindex-type ρₓ is (Abs pi me pi' x atk T) with is-index-var x
...| ff = let x' = reindex-fresh-var ρₓ is x in
Abs pi me pi' x' (reindex-tk ρₓ is atk) (reindex-type (renamectxt-insert ρₓ x x') is T)
...| tt = let isₙ = rename-indices ρₓ is in
indices-to-alls isₙ $ reindex-type (rc-is ρₓ isₙ) (trie-insert is x isₙ) T
reindex-type ρₓ is (Iota pi pi' x T T') =
let x' = reindex-fresh-var ρₓ is x in
Iota pi pi' x' (reindex-type ρₓ is T) (reindex-type (renamectxt-insert ρₓ x x') is T')
reindex-type ρₓ is (Lft pi pi' x t lT) =
let x' = reindex-fresh-var ρₓ is x in
Lft pi pi' x' (reindex-term (renamectxt-insert ρₓ x x') is t) (reindex-liftingType ρₓ is lT)
reindex-type ρₓ is (NoSpans T pi) =
NoSpans (reindex-type ρₓ is T) pi
reindex-type ρₓ is (TpLet pi d T) =
elim-pair (reindex-defTermOrType ρₓ is d) λ d' ρₓ' → TpLet pi d' (reindex-type ρₓ' is T)
reindex-type ρₓ is (TpApp T T') =
TpApp (reindex-type ρₓ is T) (reindex-type ρₓ is T')
reindex-type ρₓ is (TpAppt T (Var pi x)) with trie-lookup is x
...| nothing = TpAppt (reindex-type ρₓ is T) (reindex-term ρₓ is (Var pi x))
...| just is' = indices-to-tpapps is' $ reindex-type ρₓ is T
reindex-type ρₓ is (TpAppt T t) =
TpAppt (reindex-type ρₓ is T) (reindex-term ρₓ is t)
reindex-type ρₓ is (TpArrow (TpVar pi x) Erased T) with is-index-type-var x
...| ff = TpArrow (reindex-type ρₓ is (TpVar pi x)) Erased (reindex-type ρₓ is T)
...| tt = let isₙ = rename-indices ρₓ is in
indices-to-alls isₙ $ reindex-type (rc-is ρₓ isₙ) is T
reindex-type ρₓ is (TpArrow T me T') =
TpArrow (reindex-type ρₓ is T) me (reindex-type ρₓ is T')
reindex-type ρₓ is (TpEq pi t t' pi') =
TpEq pi (reindex-term ρₓ is t) (reindex-term ρₓ is t') pi'
reindex-type ρₓ is (TpHole pi) =
TpHole pi
reindex-type ρₓ is (TpLambda pi pi' x atk T) with is-index-var x
...| ff = let x' = reindex-fresh-var ρₓ is x in
TpLambda pi pi' x' (reindex-tk ρₓ is atk) (reindex-type (renamectxt-insert ρₓ x x') is T)
...| tt = let isₙ = rename-indices ρₓ is in
indices-to-tplams isₙ $ reindex-type (rc-is ρₓ isₙ) (trie-insert is x isₙ) T
reindex-type ρₓ is (TpParens pi T pi') =
reindex-type ρₓ is T
reindex-type ρₓ is (TpVar pi x) =
TpVar pi $ renamectxt-rep ρₓ x
reindex-kind ρₓ is (KndParens pi k pi') =
reindex-kind ρₓ is k
reindex-kind ρₓ is (KndArrow k k') =
KndArrow (reindex-kind ρₓ is k) (reindex-kind ρₓ is k')
reindex-kind ρₓ is (KndPi pi pi' x atk k) with is-index-var x
...| ff = let x' = reindex-fresh-var ρₓ is x in
KndPi pi pi' x' (reindex-tk ρₓ is atk) (reindex-kind (renamectxt-insert ρₓ x x') is k)
...| tt = let isₙ = rename-indices ρₓ is in
indices-to-kind isₙ $ reindex-kind (rc-is ρₓ isₙ) (trie-insert is x isₙ) k
reindex-kind ρₓ is (KndTpArrow (TpVar pi x) k) with is-index-type-var x
...| ff = KndTpArrow (reindex-type ρₓ is (TpVar pi x)) (reindex-kind ρₓ is k)
...| tt = let isₙ = rename-indices ρₓ is in
indices-to-kind isₙ $ reindex-kind (rc-is ρₓ isₙ) is k
reindex-kind ρₓ is (KndTpArrow T k) =
KndTpArrow (reindex-type ρₓ is T) (reindex-kind ρₓ is k)
reindex-kind ρₓ is (KndVar pi x as) =
KndVar pi (renamectxt-rep ρₓ x) (reindex-args ρₓ is as)
reindex-kind ρₓ is (Star pi) =
Star pi
reindex-tk ρₓ is (Tkt T) = Tkt $ reindex-type ρₓ is T
reindex-tk ρₓ is (Tkk k) = Tkk $ reindex-kind ρₓ is k
-- Can't reindex large indices in a lifting type (LiftPi requires a type, not a tk),
-- so for now we will just ignore reindexing lifting types.
-- Types withing lifting types will still be reindexed, though.
reindex-liftingType ρₓ is (LiftArrow lT lT') =
LiftArrow (reindex-liftingType ρₓ is lT) (reindex-liftingType ρₓ is lT')
reindex-liftingType ρₓ is (LiftParens pi lT pi') =
reindex-liftingType ρₓ is lT
reindex-liftingType ρₓ is (LiftPi pi x T lT) =
let x' = reindex-fresh-var ρₓ is x in
LiftPi pi x' (reindex-type ρₓ is T) (reindex-liftingType (renamectxt-insert ρₓ x x') is lT)
reindex-liftingType ρₓ is (LiftStar pi) =
LiftStar pi
reindex-liftingType ρₓ is (LiftTpArrow T lT) =
LiftTpArrow (reindex-type ρₓ is T) (reindex-liftingType ρₓ is lT)
reindex-optTerm ρₓ is NoTerm = NoTerm
reindex-optTerm ρₓ is (SomeTerm t pi) = SomeTerm (reindex-term ρₓ is t) pi
reindex-optType ρₓ is NoType = NoType
reindex-optType ρₓ is (SomeType T) = SomeType (reindex-type ρₓ is T)
reindex-optClass ρₓ is NoClass = NoClass
reindex-optClass ρₓ is (SomeClass atk) = SomeClass (reindex-tk ρₓ is atk)
reindex-optGuide ρₓ is NoGuide = NoGuide
reindex-optGuide ρₓ is (Guide pi x T) =
let x' = reindex-fresh-var ρₓ is x in
Guide pi x' (reindex-type (renamectxt-insert ρₓ x x') is T)
reindex-lterms ρₓ is = map λ where
(Lterm me t) → Lterm me (reindex-term ρₓ is t)
reindex-theta ρₓ is (AbstractVars xs) = maybe-else Abstract AbstractVars $ reindex-vars ρₓ is $ just xs
reindex-theta ρₓ is θ = θ
reindex-vars''' : vars → vars → vars
reindex-vars''' (VarsNext x xs) xs' = VarsNext x $ reindex-vars''' xs xs'
reindex-vars''' (VarsStart x) xs = VarsNext x xs
reindex-vars'' : vars → maybe vars
reindex-vars'' (VarsNext x (VarsStart x')) = just $ VarsStart x
reindex-vars'' (VarsNext x xs) = maybe-map (VarsNext x) $ reindex-vars'' xs
reindex-vars'' (VarsStart x) = nothing
reindex-vars' : renamectxt → trie indices → var → maybe vars
reindex-vars' ρₓ is x = maybe-else (just $ VarsStart $ renamectxt-rep ρₓ x)
(reindex-vars'' ∘ flip foldr (VarsStart "") λ {(Index x atk) → VarsNext x}) (trie-lookup is x)
reindex-vars ρₓ is (just (VarsStart x)) = reindex-vars' ρₓ is x
reindex-vars ρₓ is (just (VarsNext x xs)) = maybe-else (reindex-vars ρₓ is $ just xs)
(λ xs' → maybe-map (reindex-vars''' xs') $ reindex-vars ρₓ is $ just xs) $ reindex-vars' ρₓ is x
reindex-vars ρₓ is nothing = nothing
reindex-arg ρₓ is (TermArg me t) = TermArg me (reindex-term ρₓ is t)
reindex-arg ρₓ is (TypeArg T) = TypeArg (reindex-type ρₓ is T)
reindex-args ρₓ is = map(reindex-arg ρₓ is)
reindex-defTermOrType ρₓ is (DefTerm pi x oT t) =
let x' = reindex-fresh-var ρₓ is x
oT' = optType-map oT reindex-subst in
DefTerm elab-hide-key x' (reindex-optType ρₓ is oT') (reindex-term ρₓ is $ reindex-subst t) , renamectxt-insert ρₓ x x'
reindex-defTermOrType ρₓ is (DefType pi x k T) =
let x' = reindex-fresh-var ρₓ is x in
DefType elab-hide-key x' (reindex-kind ρₓ is $ reindex-subst k) (reindex-type ρₓ is $ reindex-subst T) , renamectxt-insert ρₓ x x'
reindex-cmds : renamectxt → trie indices → cmds → cmds × renamectxt
reindex-cmds ρₓ is [] = [] , ρₓ
reindex-cmds ρₓ is ((ImportCmd i) :: cs) =
elim-pair (reindex-cmds ρₓ is cs) $ _,_ ∘ _::_ (ImportCmd i)
reindex-cmds ρₓ is ((DefTermOrType op d pi) :: cs) =
elim-pair (reindex-defTermOrType ρₓ is d) λ d' ρₓ' →
elim-pair (reindex-cmds ρₓ' is cs) $ _,_ ∘ _::_ (DefTermOrType op d' pi)
reindex-cmds ρₓ is ((DefKind pi x ps k pi') :: cs) =
let x' = reindex-fresh-var ρₓ is x in
elim-pair (reindex-cmds (renamectxt-insert ρₓ x x') is cs) $ _,_ ∘ _::_
(DefKind pi x' ps (reindex-kind ρₓ is $ reindex-subst k) pi')
reindex-cmds ρₓ is ((DefDatatype dt pi) :: cs) =
reindex-cmds ρₓ is cs -- Templates can't use datatypes!
reindex-file : ctxt → indices → start → cmds × renamectxt
reindex-file Γ is (File csᵢ pi' pi'' x ps cs pi''') =
reindex-cmds empty-renamectxt empty-trie cs
where open reindexing Γ is
parameterize-file : ctxt → params → cmds → cmds
parameterize-file Γ ps cs = foldr {B = qualif → cmds}
(λ c cs σ → elim-pair (h c σ) λ c σ → c :: cs σ) (λ _ → []) cs empty-trie
where
ps' = ps -- substs-params {ARG} Γ empty-trie ps
σ+ = λ σ x → qualif-insert-params σ x x ps'
subst-ps : ∀ {ed} → qualif → ⟦ ed ⟧ → ⟦ ed ⟧
subst-ps = substs $ add-params-to-ctxt ps' Γ
h' : defTermOrType → qualif → defTermOrType × qualif
h' (DefTerm pi x T? t) σ =
let T?' = case T? of λ where
(SomeType T) → SomeType $ abs-expand-type ps' $ subst-ps σ T
NoType → NoType
t' = params-to-lams ps' $ subst-ps σ t in
DefTerm pi x T?' t' , σ+ σ x
h' (DefType pi x k T) σ =
let k' = abs-expand-kind ps' $ subst-ps σ k
T' = params-to-tplams ps' $ subst-ps σ T in
DefType pi x k' T' , σ+ σ x
h : cmd → qualif → cmd × qualif
h (ImportCmd i) σ = ImportCmd i , σ
h (DefTermOrType op d pi) σ = elim-pair (h' d σ) λ d σ → DefTermOrType op d pi , σ
h (DefKind pi x ps'' k pi') σ = DefKind pi x ps'' k pi' , σ
h (DefDatatype dt pi) σ = DefDatatype dt pi , σ
open import cedille-syntax
mk-ctr-term : maybeErased → (x X : var) → ctrs → params → term
mk-ctr-term me x X cs ps =
let t = Mlam X $ ctrs-to-lams' cs $ params-to-apps ps $ mvar x in
case me of λ where
Erased → Beta pi-gen NoTerm $ SomeTerm t pi-gen
NotErased → IotaPair pi-gen (Beta pi-gen NoTerm $ SomeTerm t pi-gen)
t NoGuide pi-gen
mk-ctr-type : maybeErased → ctxt → ctr → ctrs → var → type
mk-ctr-type me Γ (Ctr _ x T) cs Tₕ with decompose-ctr-type (ctxt-var-decl Tₕ Γ) T
...| Tₓ , ps , is =
params-to-alls ps $
TpAppt (recompose-tpapps is $ mtpvar Tₕ) $
rename "X" from add-params-to-ctxt ps (ctxt-var-decl Tₕ Γ) for λ X →
mk-ctr-term me x X cs ps
mk-ctr-fmap-t : Set → Set
mk-ctr-fmap-t X = ctxt → (var × var × var × var × term) → X
{-# TERMINATING #-}
mk-ctr-fmap-η+ : mk-ctr-fmap-t (term → type → term)
mk-ctr-fmap-η- : mk-ctr-fmap-t (term → type → term)
mk-ctr-fmap-η? : mk-ctr-fmap-t (term → type → term) → mk-ctr-fmap-t (term → type → term)
mk-ctr-fmapₖ-η+ : mk-ctr-fmap-t (type → kind → type)
mk-ctr-fmapₖ-η- : mk-ctr-fmap-t (type → kind → type)
mk-ctr-fmapₖ-η? : mk-ctr-fmap-t (type → kind → type) → mk-ctr-fmap-t (type → kind → type)
mk-ctr-fmap-η? f Γ x x' T with is-free-in tt (fst x) T
...| tt = f Γ x x' T
...| ff = x'
mk-ctr-fmapₖ-η? f Γ x x' k with is-free-in tt (fst x) k
...| tt = f Γ x x' k
...| ff = x'
mk-ctr-fmap-η+ Γ x x' T with decompose-ctr-type Γ T
...| Tₕ , ps , _ =
params-to-lams' ps $
let Γ' = add-params-to-ctxt ps Γ in
foldl
(λ {(Decl _ _ me x'' (Tkt T) _) t → App t me $ mk-ctr-fmap-η? mk-ctr-fmap-η- Γ' x (mvar x'') T;
(Decl _ _ _ x'' (Tkk k) _) t → AppTp t $ mk-ctr-fmapₖ-η? mk-ctr-fmapₖ-η- Γ' x (mtpvar x'') k})
x' ps
mk-ctr-fmapₖ-η+ Γ xₒ @ (x , Aₓ , Bₓ , cₓ , castₓ) x' k =
let is = kind-to-indices Γ (subst Γ (mtpvar Aₓ) x k) in
indices-to-tplams is $
let Γ' = add-indices-to-ctxt is Γ in
foldl
(λ {(Index x'' (Tkt T)) → flip TpAppt $ mk-ctr-fmap-η? mk-ctr-fmap-η- Γ' xₒ (mvar x'') T;
(Index x'' (Tkk k)) → flip TpApp $ mk-ctr-fmapₖ-η? mk-ctr-fmapₖ-η- Γ' xₒ (mtpvar x'') k})
x' $ map (λ {(Index x'' atk) → Index x'' $ subst Γ' (mtpvar x) Aₓ atk}) is
mk-ctr-fmap-η- Γ xₒ @ (x , Aₓ , Bₓ , cₓ , castₓ) x' T with decompose-ctr-type Γ T
...| TpVar _ x'' , ps , as =
params-to-lams' ps $
let Γ' = add-params-to-ctxt ps Γ in
(if ~ x'' =string x then id else mapp
(recompose-apps (ttys-to-args Erased as) $
mappe (AppTp (AppTp castₓ (mtpvar Aₓ)) (mtpvar Bₓ)) (mvar cₓ)))
(foldl (λ {(Decl _ _ me x'' (Tkt T) _) t →
App t me $ mk-ctr-fmap-η? mk-ctr-fmap-η+ Γ' xₒ (mvar x'') T;
(Decl _ _ me x'' (Tkk k) _) t →
AppTp t $ mk-ctr-fmapₖ-η? mk-ctr-fmapₖ-η+ Γ' xₒ (mtpvar x'') k}) x' ps)
...| Iota _ _ x'' T₁ T₂ , ps , [] =
let Γ' = add-params-to-ctxt ps Γ
tₒ = foldl (λ {
(Decl _ _ me x'' (Tkt T) _) t →
App t me $ mk-ctr-fmap-η? mk-ctr-fmap-η+ Γ' xₒ (mvar x'') T;
(Decl _ _ me x'' (Tkk k) _) t →
AppTp t $ mk-ctr-fmapₖ-η? mk-ctr-fmapₖ-η+ Γ' xₒ (mtpvar x'') k
}) x' ps
t₁ = mk-ctr-fmap-η? mk-ctr-fmap-η- Γ' xₒ (IotaProj tₒ "1" pi-gen) T₁
t₂ = mk-ctr-fmap-η? mk-ctr-fmap-η- Γ' xₒ (IotaProj tₒ "2" pi-gen)
(subst Γ (mk-ctr-fmap-η? mk-ctr-fmap-η- Γ' xₒ (mvar x'') T₁) x'' T₂) in
params-to-lams' ps $ IotaPair pi-gen t₁ t₂ NoGuide pi-gen
...| Tₕ , ps , as = x'
mk-ctr-fmapₖ-η- Γ xₒ @ (x , Aₓ , Bₓ , cₓ , castₓ) x' k with kind-to-indices Γ (subst Γ (mtpvar Bₓ) x k)
...| is =
indices-to-tplams is $
let Γ' = add-indices-to-ctxt is Γ in
foldl (λ {(Index x'' (Tkt T)) → flip TpAppt $ mk-ctr-fmap-η? mk-ctr-fmap-η+ Γ' xₒ (mvar x'') T;
(Index x'' (Tkk k)) → flip TpApp $ mk-ctr-fmapₖ-η? mk-ctr-fmapₖ-η+ Γ' xₒ (mtpvar x'') k})
x' $ map (λ {(Index x'' atk) → Index x'' $ subst Γ' (mtpvar x) Bₓ atk}) is
record encoded-datatype-names : Set where
constructor mk-encoded-datatype-names
field
data-functor : var
data-fmap : var
data-Mu : var
data-mu : var
data-cast : var
data-functor-ind : var
cast : var
fixpoint-type : var
fixpoint-in : var
fixpoint-out : var
fixpoint-ind : var
fixpoint-lambek : var
elab-mu-t : Set
elab-mu-t = ctxt → ctxt-datatype-info → encoded-datatype-names → var → var ⊎ maybe (term × var × 𝕃 tty) → term → type → cases → maybe (term × ctxt)
record encoded-datatype : Set where
constructor mk-encoded-datatype
field
--data-def : datatype
--mod-ps : params
names : encoded-datatype-names
elab-mu : elab-mu-t
elab-mu-pure : ctxt → ctxt-datatype-info → maybe var → term → cases → maybe term
check-mu : ctxt → ctxt-datatype-info → var → var ⊎ maybe (term × var × 𝕃 tty) → term → optType → cases → type → maybe (term × ctxt)
check-mu Γ d Xₒ x? t oT ms T with d --data-def
check-mu Γ d Xₒ x? t oT ms T | mk-data-info X mu asₚ asᵢ ps kᵢ k cs fcs -- Data X ps is cs
with kind-to-indices Γ kᵢ | oT
check-mu Γ d Xₒ x? t oT ms T | mk-data-info X mu asₚ asᵢ ps kᵢ k cs fcs | is | NoType =
elab-mu Γ {-(Data X ps is cs)-} d names Xₒ x? t
(indices-to-tplams is $ TpLambda pi-gen pi-gen ignored-var
(Tkt $ indices-to-tpapps is $ flip apps-type asₚ $ mtpvar X) T) ms
check-mu Γ d Xₒ x? t oT ms T | mk-data-info X mu asₚ asᵢ ps kᵢ k cs fcs | is | SomeType Tₘ =
elab-mu Γ d names Xₒ x? t Tₘ ms
synth-mu : ctxt → ctxt-datatype-info → var → var ⊎ maybe (term × var × 𝕃 tty) → term → optType → cases → maybe (term × ctxt)
synth-mu Γ d Xₒ x? t NoType ms = nothing
synth-mu Γ d Xₒ x? t (SomeType Tₘ) ms = elab-mu Γ d names Xₒ x? t Tₘ ms
record datatype-encoding : Set where
constructor mk-datatype-encoding
field
template : start
functor : var
cast : var
fixpoint-type : var
fixpoint-in : var
fixpoint-out : var
fixpoint-ind : var
fixpoint-lambek : var
elab-mu : elab-mu-t
elab-mu-pure : ctxt → ctxt-datatype-info → encoded-datatype-names → maybe var → term → cases → maybe term
{-# TERMINATING #-}
mk-defs : ctxt → datatype → cmds × cmds × encoded-datatype
mk-defs Γ'' (Data x ps is cs) =
tcs ,
(csn OpacTrans functor-cmd $
csn OpacTrans functor-ind-cmd $
csn OpacTrans fmap-cmd $
csn OpacOpaque type-cmd $
csn OpacOpaque Mu-cmd $
csn OpacTrans mu-cmd $
csn OpacTrans cast-cmd $
foldr (csn OpacTrans ∘ ctr-cmd) [] cs) ,
record {
elab-mu = elab-mu;
elab-mu-pure = λ Γ d → elab-mu-pure Γ d namesₓ;
--data-def = Data x ps is cs;
--mod-ps = ctxt-get-current-params Γ;
names = namesₓ}
where
csn : opacity → defTermOrType → cmds → cmds
csn o d = DefTermOrType o d pi-gen ::_
k = indices-to-kind is $ Star pi-gen
Γ' = add-params-to-ctxt ps $ add-ctrs-to-ctxt cs $ ctxt-var-decl x Γ''
tcs-ρ = reindex-file Γ' is template
tcs = parameterize-file Γ' (params-set-erased Erased $ {-ctxt-get-current-params Γ'' ++-} ps) $ fst tcs-ρ
ρₓ = snd tcs-ρ
data-functorₓ = fresh-var (x ^ "F") (ctxt-binds-var Γ') ρₓ
data-fmapₓ = fresh-var (x ^ "Fmap") (ctxt-binds-var Γ') ρₓ
--data-fresh-check = λ f → fresh-var x (λ x → ctxt-binds-var Γ' (f x) || renamectxt-in-field ρₓ (rename-validify $ f x) || renamectxt-in-field ρₓ (f x) || renamectxt-in-field ρₓ (rename-validify $ f x)) ρₓ
data-Muₓₒ = x -- data-fresh-check data-Is/
data-muₓₒ = x -- data-fresh-check data-is/
data-castₓₒ = x -- data-fresh-check data-to/
data-Muₓ = data-Is/ data-Muₓₒ
data-muₓ = data-is/ data-muₓₒ
data-castₓ = data-to/ data-castₓₒ
data-Muₓᵣ = rename-validify data-Muₓ
data-muₓᵣ = rename-validify data-muₓ
data-castₓᵣ = rename-validify data-castₓ
data-functor-indₓ = fresh-var (x ^ "IndF") (ctxt-binds-var Γ') ρₓ
functorₓ = renamectxt-rep ρₓ functor
castₓ = renamectxt-rep ρₓ cast
fixpoint-typeₓ = renamectxt-rep ρₓ fixpoint-type
fixpoint-inₓ = renamectxt-rep ρₓ fixpoint-in
fixpoint-outₓ = renamectxt-rep ρₓ fixpoint-out
fixpoint-indₓ = renamectxt-rep ρₓ fixpoint-ind
fixpoint-lambekₓ = renamectxt-rep ρₓ fixpoint-lambek
Γ = foldr ctxt-var-decl (add-indices-to-ctxt is Γ') (data-functorₓ :: data-fmapₓ :: data-Muₓ :: data-muₓ :: data-castₓ :: data-Muₓᵣ :: data-muₓᵣ :: data-functor-indₓ :: [])
--Γ = add-indices-to-ctxt is $ ctxt-var-decl data-functorₓ $ ctxt-var-decl data-fmapₓ $ ctxt-var-decl data-Muₓ $ ctxt-var-decl data-muₓ $ ctxt-var-decl data-castₓ $ ctxt-var-decl data-functor-indₓ Γ'
namesₓ = record {
data-functor = data-functorₓ;
data-fmap = data-fmapₓ;
data-Mu = data-Muₓᵣ;
data-mu = data-muₓᵣ;
data-cast = data-castₓᵣ;
data-functor-ind = data-functor-indₓ;
cast = castₓ;
fixpoint-type = fixpoint-typeₓ;
fixpoint-in = fixpoint-inₓ;
fixpoint-out = fixpoint-outₓ;
fixpoint-ind = fixpoint-indₓ;
fixpoint-lambek = fixpoint-lambekₓ}
new-var : ∀ {ℓ} {X : Set ℓ} → var → (var → X) → X
new-var x f = f $ fresh-var x (ctxt-binds-var Γ) ρₓ
functor-cmd = DefType pi-gen data-functorₓ (params-to-kind ps $ KndArrow k k) $
params-to-tplams ps $
TpLambda pi-gen pi-gen x (Tkk $ k) $
indices-to-tplams is $
new-var "x" λ xₓ → new-var "X" λ Xₓ →
Iota pi-gen pi-gen xₓ (mtpeq id-term id-term) $
Abs pi-gen Erased pi-gen Xₓ
(Tkk $ indices-to-kind is $ KndTpArrow (mtpeq id-term id-term) star) $
foldr (λ c → flip TpArrow NotErased $ mk-ctr-type Erased Γ c cs Xₓ)
(TpAppt (indices-to-tpapps is $ mtpvar Xₓ) (mvar xₓ)) cs
-- Note: had to set params to erased because args later in mu or mu' could be erased
functor-ind-cmd = DefTerm pi-gen data-functor-indₓ NoType $
params-to-lams ps $
Lam pi-gen Erased pi-gen x (SomeClass $ Tkk k) $
indices-to-lams is $
new-var "x" λ xₓ → new-var "y" λ yₓ → new-var "e" λ eₓ → new-var "X" λ Xₓ →
let T = indices-to-tpapps is $ TpApp (params-to-tpapps ps $ mtpvar data-functorₓ) (mtpvar x) in
Lam pi-gen NotErased pi-gen xₓ (SomeClass $ Tkt T) $
Lam pi-gen Erased pi-gen Xₓ
(SomeClass $ Tkk $ indices-to-kind is $ KndTpArrow T star) $
flip (foldr λ {c @ (Ctr _ x' _) → Lam pi-gen NotErased pi-gen x' $ SomeClass $
Tkt $ mk-ctr-type NotErased Γ c cs Xₓ}) cs $
flip mappe (Beta pi-gen NoTerm NoTerm) $
flip mappe (mvar xₓ) $
let Γ' = ctxt-var-decl xₓ $ ctxt-var-decl yₓ $ ctxt-var-decl eₓ $ ctxt-var-decl Xₓ Γ in
flip (foldl λ {(Ctr _ x' T) → flip mapp $
elim-pair (decompose-arrows Γ T) λ ps' Tₕ →
params-to-lams' ps' $
Mlam yₓ $ Mlam eₓ $
params-to-apps ps' $ mvar x'}) cs $
AppTp (IotaProj (mvar xₓ) "2" pi-gen) $
indices-to-tplams is $
TpLambda pi-gen pi-gen xₓ (Tkt $ mtpeq id-term id-term) $
Abs pi-gen Erased pi-gen yₓ (Tkt T) $
Abs pi-gen Erased pi-gen eₓ (Tkt $ mtpeq (mvar yₓ) (mvar xₓ)) $
TpAppt (indices-to-tpapps is $ mtpvar Xₓ) $
Phi pi-gen (mvar eₓ) (mvar yₓ) (mvar xₓ) pi-gen
fmap-cmd : defTermOrType
fmap-cmd with new-var "A" id | new-var "B" id | new-var "c" id
...| Aₓ | Bₓ | cₓ = DefTerm pi-gen data-fmapₓ (SomeType $
params-to-alls ps $
TpApp (params-to-tpapps ps $ mtpvar functorₓ) $
params-to-tpapps ps $
mtpvar data-functorₓ) $
params-to-lams ps $
Mlam Aₓ $ Mlam Bₓ $ Mlam cₓ $
IotaPair pi-gen
(indices-to-lams is $
new-var "x" λ xₓ → mlam xₓ $
IotaPair pi-gen (IotaProj (mvar xₓ) "1" pi-gen)
(new-var "X" λ Xₓ → Mlam Xₓ $
ctrs-to-lams' cs $
foldl
(flip mapp ∘ eta-expand-ctr)
(AppTp (IotaProj (mvar xₓ) "2" pi-gen) $ mtpvar Xₓ) cs)
NoGuide pi-gen)
(Beta pi-gen NoTerm NoTerm) NoGuide pi-gen
where
eta-expand-ctr : ctr → term
eta-expand-ctr (Ctr _ x' T) =
mk-ctr-fmap-η+ (ctxt-var-decl Aₓ $ ctxt-var-decl Bₓ $ ctxt-var-decl cₓ Γ)
(x , Aₓ , Bₓ , cₓ , params-to-apps (params-set-erased Erased ps) (mvar castₓ)) (mvar x') T
type-cmd = DefType pi-gen x (params-to-kind ps k) $
params-to-tplams ps $ TpAppt
(TpApp (params-to-tpapps ps $ mtpvar fixpoint-typeₓ) $
params-to-tpapps ps $ mtpvar data-functorₓ)
(params-to-apps ps $ mvar data-fmapₓ)
mu-proj : var → 𝔹 → type × (term → term)
mu-proj Xₓ b =
rename "i" from add-params-to-ctxt ps Γ for λ iₓ →
let u = if b then id-term else params-to-apps (params-set-erased Erased ps) (mvar fixpoint-outₓ)
Tₙ = λ T → Iota pi-gen pi-gen iₓ (indices-to-alls is $ TpArrow (indices-to-tpapps is $ mtpvar Xₓ) NotErased $ indices-to-tpapps is T) $ mtpeq (mvar iₓ) u
T₁ = Tₙ $ params-to-tpapps ps $ mtpvar x
T₂ = Tₙ $ TpApp (params-to-tpapps ps $ mtpvar data-functorₓ) $ mtpvar Xₓ
T = if b then T₁ else T₂
rₓ = if b then "c" else "o"
t = λ mu → mapp (AppTp mu T) $ mlam "c" $ mlam "o" $ mvar rₓ in
T , λ mu → Open pi-gen OpacTrans pi-gen data-Muₓ (Phi pi-gen (IotaProj (t mu) "2" pi-gen) (IotaProj (t mu) "1" pi-gen) u pi-gen)
Mu-cmd = DefType pi-gen data-Muₓ (params-to-kind ps $ KndArrow k star) $
params-to-tplams ps $
rename "X" from add-params-to-ctxt ps Γ for λ Xₓ →
rename "Y" from add-params-to-ctxt ps Γ for λ Yₓ →
TpLambda pi-gen pi-gen Xₓ (Tkk k) $
mall Yₓ (Tkk star) $
flip (flip TpArrow NotErased) (mtpvar Yₓ) $
TpArrow (fst $ mu-proj Xₓ tt) NotErased $
TpArrow (fst $ mu-proj Xₓ ff) NotErased $
mtpvar Yₓ
mu-cmd = DefTerm pi-gen data-muₓ (SomeType $ params-to-alls (params-set-erased Erased ps) $ TpApp (params-to-tpapps ps $ mtpvar data-Muₓ) $ params-to-tpapps ps $ mtpvar x) $
params-to-lams (params-set-erased Erased ps) $
Open pi-gen OpacTrans pi-gen x $
Open pi-gen OpacTrans pi-gen data-Muₓ $
rename "Y" from add-params-to-ctxt ps Γ for λ Yₓ →
rename "f" from add-params-to-ctxt ps Γ for λ fₓ →
let pair = λ t → IotaPair pi-gen t (Beta pi-gen NoTerm (SomeTerm (erase t) pi-gen)) NoGuide pi-gen in
Mlam Yₓ $ mlam fₓ $ mapp (mapp (mvar fₓ) $ pair $ indices-to-lams is $ id-term) $ pair $
mappe (AppTp (params-to-apps (params-set-erased Erased ps) (mvar fixpoint-outₓ)) $ (params-to-tpapps ps $ mtpvar data-functorₓ)) (params-to-apps ps $ mvar data-fmapₓ)
cast-cmd =
rename "Y" from add-params-to-ctxt ps Γ for λ Yₓ →
rename "mu" from add-params-to-ctxt ps Γ for λ muₓ →
DefTerm pi-gen data-castₓ NoType $
params-to-lams ps $
Lam pi-gen Erased pi-gen Yₓ (SomeClass $ Tkk k) $
Lam pi-gen Erased pi-gen muₓ (SomeClass $ Tkt $
TpApp (params-to-tpapps ps $ mtpvar data-Muₓ) $ mtpvar Yₓ) $
snd (mu-proj Yₓ tt) $ mvar muₓ
ctr-cmd : ctr → defTermOrType
ctr-cmd (Ctr _ x' T) with subst Γ (params-to-tpapps ps $ mtpvar x) x T
...| T' with decompose-ctr-type Γ T'
...| Tₕ , ps' , as' = DefTerm pi-gen x' (SomeType $ params-to-alls (ps ++ ps') T') $
Open pi-gen OpacTrans pi-gen x $
params-to-lams ps $
params-to-lams ps' $
mapp (recompose-apps (ttys-to-args Erased $ drop (length ps) as') $
mappe (AppTp (params-to-apps (params-set-erased Erased ps) $ mvar fixpoint-inₓ) $
params-to-tpapps ps $ mtpvar data-functorₓ) $
params-to-apps ps $ mvar data-fmapₓ) $
rename "X" from add-params-to-ctxt ps' Γ for λ Xₓ →
mk-ctr-term NotErased x' Xₓ cs ps'
{- Datatypes -}
ctxt-elab-ctr-def : var → params → type → (ctrs-length ctr-index : ℕ) → ctxt → ctxt
ctxt-elab-ctr-def c ps' t n i Γ@(mk-ctxt mod @ (fn , mn , ps , q) ss is os Δ) = mk-ctxt
mod ss (trie-insert is ("//" ^ c) (ctr-def [] t n i (unerased-arrows $ abs-expand-type (ps ++ ps') t) , "missing" , "missing")) os Δ
ctxt-elab-ctrs-def : ctxt → params → ctrs → ctxt
ctxt-elab-ctrs-def Γ ps cs = foldr {B = ℕ → ctxt} (λ {(Ctr _ x T) Γ i → ctxt-elab-ctr-def x ps T (length cs) i $ Γ $ suc i}) (λ _ → Γ) cs 0
mendler-elab-mu-pure : ctxt → ctxt-datatype-info → encoded-datatype-names → maybe var → term → cases → maybe term
mendler-elab-mu-pure Γ (mk-data-info X is/X? asₚ asᵢ ps kᵢ k cs fcs) (mk-encoded-datatype-names _ _ _ _ _ _ _ _ fixpoint-inₓ fixpoint-outₓ fixpoint-indₓ fixpoint-lambekₓ) x? t ms =
let ps-tm = id --λ t → foldr (const $ flip mapp id-term) t $ erase-params ps
fix-ind = mvar fixpoint-indₓ -- hnf Γ unfold-all (ps-tm $ mvar fixpoint-indₓ) tt
fix-out = mvar fixpoint-outₓ -- hnf Γ unfold-all (ps-tm $ mvar fixpoint-outₓ) tt
μ-tm = λ x msf → mapp (mapp fix-ind t) $ mlam x $ rename "x" from ctxt-var-decl x Γ for λ fₓ → mlam fₓ $ msf $ mvar fₓ -- mapp fix-out $ mvar fₓ
μ'-tm = λ msf → msf $ mapp fix-out t
set-nth = λ l n a → foldr{B = maybe ℕ → 𝕃 (maybe term)}
(λ {a' t nothing → a' :: t nothing;
a' t (just zero) → a :: t nothing;
a' t (just (suc n)) → a' :: t (just n)})
(λ _ → []) l (just n) in
-- Note: removing the implicit arguments below hangs Agda's type-checker!
foldl{B = 𝕃 (maybe term) → maybe (term → term)}
(λ c msf l → case_of_{B = maybe (term → term)} c
λ {(Case _ x cas t) → env-lookup Γ ("//" ^ x) ≫=maybe
λ {(ctr-def ps? _ n i a , _ , _) →
msf (set-nth l i (just $ caseArgs-to-lams cas t)); _ → nothing}})
(-- Note: lambda-expanding this "foldr..." also hangs Agda...?
foldr (λ t? msf → msf ≫=maybe λ msf → t? ≫=maybe λ t →
just λ t' → (msf (mapp t' t))) (just λ t → t))
ms (map (λ _ → nothing) ms) ≫=maybe (just ∘ maybe-else' x? μ'-tm μ-tm)
mendler-elab-mu : elab-mu-t
mendler-elab-mu Γ (mk-data-info X is/X? asₚ asᵢ ps kᵢ k cs fcs)
(mk-encoded-datatype-names
data-functorₓ data-fmapₓ data-Muₓ data-muₓ data-castₓ data-functor-indₓ castₓ
fixpoint-typeₓ fixpoint-inₓ fixpoint-outₓ fixpoint-indₓ fixpoint-lambekₓ)
Xₒ x? t Tₘ ms =
let infixl 10 _-is _-ps _`ps _·is _·ps
_-is = recompose-apps $ ttys-to-args Erased asᵢ
_`ps = recompose-apps asₚ
_-ps = recompose-apps $ args-set-erased Erased asₚ
_·is = recompose-tpapps asᵢ
_·ps = recompose-tpapps $ args-to-ttys asₚ
σ = fst (mk-inst ps (asₚ ++ ttys-to-args NotErased asᵢ))
is = kind-to-indices Γ (substs Γ σ k)
Γᵢₛ = add-indices-to-ctxt is $ add-params-to-ctxt ps Γ
is-as : indices → args
is-as = map λ {(Index x atk) →
tk-elim atk (λ _ → TermArg Erased $ `vₓ x) (λ _ → TypeArg $ `Vₓ x)}
is/X? = maybe-map `vₓ_ is/X? maybe-or either-else' x? (λ _ → nothing) (maybe-map fst)
open? = Open pi-gen OpacTrans pi-gen X
close? = Open pi-gen OpacOpaque pi-gen X
ms' = foldr (λ {(Case _ x cas t) σ →
let Γ' = add-caseArgs-to-ctxt cas Γᵢₛ in
trie-insert σ x $ caseArgs-to-lams cas $
rename "y" from Γ' for λ yₓ →
rename "e" from Γ' for λ eₓ →
`Λ yₓ ₊ `Λ eₓ ₊ close? (`ρ (`ς `vₓ eₓ) - t)}) empty-trie ms
fmap = `vₓ data-fmapₓ `ps
functor = `Vₓ data-functorₓ ·ps
Xₜₚ = `Vₓ X ·ps
in-fix = λ is/X? T asᵢ t → either-else' x? (λ x → recompose-apps asᵢ (`vₓ fixpoint-inₓ -ps · functor - fmap) ` (maybe-else' is/X? t λ is/X →
recompose-apps asᵢ (`vₓ castₓ -ps - (fmap · T · Xₜₚ - (`open data-Muₓ - (is/X ` (`λ "to" ₊ `λ "out" ₊ `vₓ "to"))))) ` t)) (λ e → maybe-else' (is/X? maybe-or maybe-map fst e) t λ is/X → recompose-apps asᵢ (`vₓ castₓ -ps · `Vₓ Xₒ · Xₜₚ - (`open data-Muₓ - (is/X ` (`λ "to" ₊ `λ "out" ₊ `vₓ "to")))) ` t)
app-lambek = λ is/X? t T asᵢ body → body - (in-fix is/X? T asᵢ t) -
(recompose-apps asᵢ (`vₓ fixpoint-lambekₓ -ps · functor - fmap) ` (in-fix is/X? T asᵢ t)) in
rename "x" from Γᵢₛ for λ xₓ →
rename "y" from Γᵢₛ for λ yₓ →
rename "y'" from ctxt-var-decl yₓ Γᵢₛ for λ y'ₓ →
rename "z" from Γᵢₛ for λ zₓ →
rename "e" from Γᵢₛ for λ eₓ →
rename "X" from Γᵢₛ for λ Xₓ →
foldl (λ {(Ctr _ x Tₓ) rec → rec ≫=maybe λ rec → trie-lookup ms' x ≫=maybe λ t →
just λ tₕ → rec tₕ ` t}) (just λ t → t) cs ≫=maybe λ msf →
just $ flip (either-else' x?)
(λ _ → open? (app-lambek is/X? t (`Vₓ Xₒ ·ps) (ttys-to-args Erased asᵢ) (msf
(let Tₛ = maybe-else' is/X? Xₜₚ λ _ → `Vₓ Xₒ
fcₜ = maybe-else' is/X? id λ is/X → _`_ $ indices-to-apps is $
`vₓ castₓ -ps · (functor ·ₜ Tₛ) · (functor ·ₜ Xₜₚ) -
(fmap · Tₛ · Xₜₚ - (`open data-Muₓ - (is/X ` (`λ "to" ₊ `λ "out" ₊ `vₓ "to"))))
out = maybe-else' is/X? (`vₓ fixpoint-outₓ -ps · functor - fmap) λ is/X →
let i = `open data-Muₓ - is/X · (`ι xₓ :ₜ indices-to-alls is (indices-to-tpapps is Tₛ ➔ indices-to-tpapps is (functor ·ₜ Tₛ)) ₊ `[ `vₓ xₓ ≃ `vₓ fixpoint-outₓ ]) ` (`λ "to" ₊ `λ "out" ₊ `vₓ "out") in
`φ i `₊2 - i `₊1 [ `vₓ fixpoint-outₓ ] in
(`φ `β - (`vₓ data-functor-indₓ `ps · Tₛ -is ` (out -is ` t)) [ `vₓ fixpoint-outₓ ` erase t ])
· (indices-to-tplams is $ `λₜ yₓ :ₜ indices-to-tpapps is (functor ·ₜ Tₛ) ₊
`∀ y'ₓ :ₜ indices-to-tpapps is Xₜₚ ₊ `∀ eₓ :ₜ `[ `vₓ fixpoint-inₓ -ps ` `vₓ yₓ ≃ `vₓ y'ₓ ] ₊
indices-to-tpapps is Tₘ `ₜ (`φ `vₓ eₓ -
(indices-to-apps is (`vₓ fixpoint-inₓ -ps · functor - fmap) ` (fcₜ (`vₓ yₓ))) [ `vₓ y'ₓ ]))))) , Γ)
λ xₒ → rename xₒ from Γᵢₛ for λ x →
let Rₓₒ = mu-Type/ x
isRₓₒ = mu-isType/ x in
rename Rₓₒ from Γᵢₛ for λ Rₓ →
rename isRₓₒ from Γᵢₛ for λ isRₓ →
rename "to" from Γᵢₛ for λ toₓ →
rename "out" from Γᵢₛ for λ outₓ →
let fcₜ = `vₓ castₓ -ps · (functor ·ₜ `Vₓ Rₓ) · (functor ·ₜ Xₜₚ) - (fmap · `Vₓ Rₓ · Xₜₚ - `vₓ toₓ)
subst-msf = subst-renamectxt Γᵢₛ (maybe-extract
(renamectxt-insert* empty-renamectxt (xₒ :: isRₓₒ :: Rₓₒ :: toₓ :: outₓ :: xₓ :: yₓ :: y'ₓ :: []) (x :: isRₓ :: Rₓ :: toₓ :: outₓ :: xₓ :: yₓ :: y'ₓ :: [])) refl) ∘ msf in
open? (`vₓ fixpoint-indₓ -ps · functor - fmap -is ` t · Tₘ `
(`Λ Rₓ ₊ `Λ toₓ ₊ `Λ outₓ ₊ `λ x ₊
indices-to-lams is (`λ yₓ ₊
`-[ isRₓ :ₜ `Vₓ data-Muₓ ·ps ·ₜ (`Vₓ Rₓ) `=
`open data-Muₓ - (`Λ ignored-var ₊ `λ xₓ ₊ `vₓ xₓ ` (`vₓ toₓ) ` (`vₓ outₓ))]-
(app-lambek (just $ `vₓ isRₓ) (`vₓ yₓ) (`Vₓ Rₓ) (is-as is) $ subst-msf
((`φ `β - (indices-to-apps is (`vₓ data-functor-indₓ `ps · (`Vₓ Rₓ)) ` `vₓ yₓ) [ `vₓ yₓ ]) ·
(indices-to-tplams is $ `λₜ yₓ :ₜ indices-to-tpapps is (functor ·ₜ (`Vₓ Rₓ)) ₊
`∀ y'ₓ :ₜ indices-to-tpapps is Xₜₚ ₊ `∀ eₓ :ₜ `[ `vₓ fixpoint-inₓ -ps ` `vₓ yₓ ≃ `vₓ y'ₓ ] ₊
indices-to-tpapps is Tₘ `ₜ (`φ `vₓ eₓ -
(`vₓ fixpoint-inₓ -ps · functor - fmap ` (indices-to-apps is fcₜ ` (`vₓ yₓ)))
[ `vₓ y'ₓ ]))))))) , ctxt-datatype-decl' X isRₓ Rₓ asₚ Γ
mendler-encoding : datatype-encoding
mendler-encoding =
record {
template = templateMendler;
functor = "Functor";
cast = "cast";
fixpoint-type = "CVFixIndM";
fixpoint-in = "cvInFixIndM";
fixpoint-out = "cvOutFixIndM";
fixpoint-ind = "cvIndFixIndM";
fixpoint-lambek = "lambek";
elab-mu = mendler-elab-mu;
elab-mu-pure = mendler-elab-mu-pure
}
mendler-simple-encoding : datatype-encoding
mendler-simple-encoding =
record {
template = templateMendlerSimple;
functor = "RecFunctor";
cast = "cast";
fixpoint-type = "FixM";
fixpoint-out = "outFix";
fixpoint-in = "inFix";
fixpoint-ind = "IndFixM";
fixpoint-lambek = "lambek";
elab-mu = mendler-elab-mu;
elab-mu-pure = mendler-elab-mu-pure
}
selected-encoding = case cedille-options.options.datatype-encoding options of λ where
cedille-options.Mendler → mendler-simple-encoding
cedille-options.Mendler-old → mendler-encoding
| {
"alphanum_fraction": 0.6034864598,
"avg_line_length": 46.9187242798,
"ext": "agda",
"hexsha": "11a9d8ef9f14ef8f7924e770a22ea392e8692a1d",
"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": "f5ce42258b7d9bc66f75cd679c785d6133b82b58",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CarlOlson/cedille",
"max_forks_repo_path": "src/elaboration-helpers.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f5ce42258b7d9bc66f75cd679c785d6133b82b58",
"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": "CarlOlson/cedille",
"max_issues_repo_path": "src/elaboration-helpers.agda",
"max_line_length": 309,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f5ce42258b7d9bc66f75cd679c785d6133b82b58",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CarlOlson/cedille",
"max_stars_repo_path": "src/elaboration-helpers.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 18034,
"size": 45605
} |
------------------------------------------------------------------------
-- An example: A function that, given a stream, tries to find an
-- element satisfying a predicate
------------------------------------------------------------------------
{-# OPTIONS --cubical --safe #-}
module Search where
open import Equality.Propositional.Cubical
open import Prelude hiding (⊥)
open import Monad equality-with-J
open import Univalence-axiom equality-with-J
open import Partiality-algebra.Monotone
open import Partiality-monad.Inductive
open import Partiality-monad.Inductive.Fixpoints
open import Partiality-monad.Inductive.Monad
-- Streams.
infixr 5 _∷_
record Stream {a} (A : Type a) : Type a where
coinductive
constructor _∷_
field
head : A
tail : Stream A
open Stream
-- A direct implementation of the function.
module Direct {a} {A : Type a} (q : A → Bool) where
Φ : Trans (Stream A) (λ _ → A)
Φ f xs = if q (head xs) then return (head xs) else f (tail xs)
Φ-monotone :
∀ {f₁ f₂} → (∀ xs → f₁ xs ⊑ f₂ xs) → ∀ xs → Φ f₁ xs ⊑ Φ f₂ xs
Φ-monotone f₁⊑f₂ xs with q (head xs)
... | true = return (head xs) ■
... | false = f₁⊑f₂ (tail xs)
Φ-⊑ : Trans-⊑ (Stream A) (λ _ → A)
Φ-⊑ = record { function = Φ; monotone = Φ-monotone }
search : Stream A → A ⊥
search = fix→ Φ-⊑
search-least :
∀ f → (∀ xs → Φ f xs ⊑ f xs) →
∀ xs → search xs ⊑ f xs
search-least = fix→-is-least Φ-⊑
Φ-ω-continuous :
(s : ∃ λ (f : ℕ → Stream A → A ⊥) →
∀ n xs → f n xs ⊑ f (suc n) xs) →
Φ (⨆ ∘ at s) ≡ ⨆ ∘ at [ Φ-⊑ $ s ]-inc
Φ-ω-continuous s = ⟨ext⟩ helper
where
helper : ∀ xs → Φ (⨆ ∘ at s) xs ≡ ⨆ (at [ Φ-⊑ $ s ]-inc xs)
helper xs with q (head xs)
... | true = return (head xs) ≡⟨ sym ⨆-const ⟩∎
⨆ (constˢ (return (head xs))) ∎
... | false = ⨆ (at s (tail xs)) ∎
Φ-ω : Trans-ω (Stream A) (λ _ → A)
Φ-ω = record
{ monotone-function = Φ-⊑
; ω-continuous = Φ-ω-continuous
}
search-fixpoint : search ≡ Φ search
search-fixpoint = fix→-is-fixpoint-combinator Φ-ω
-- An arguably more convenient implementation.
module Indirect {a} {A : Type a} (q : A → Bool) where
ΦP : Stream A → Partial (Stream A) (λ _ → A) A
ΦP xs =
if q (head xs) then
return (head xs)
else
rec (tail xs)
Φ : Trans (Stream A) (λ _ → A)
Φ = Trans-⊑.function (transformer ΦP)
search : Stream A → A ⊥
search = fixP ΦP
search-least :
∀ f → (∀ xs → Φ f xs ⊑ f xs) →
∀ xs → search xs ⊑ f xs
search-least = fixP-is-least ΦP
search-fixpoint : search ≡ Φ search
search-fixpoint = fixP-is-fixpoint-combinator ΦP
| {
"alphanum_fraction": 0.5492324972,
"avg_line_length": 25.932038835,
"ext": "agda",
"hexsha": "36a38529d0bd4af8c466be56422b89e132ea3df7",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/partiality-monad",
"max_forks_repo_path": "src/Search.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/partiality-monad",
"max_issues_repo_path": "src/Search.agda",
"max_line_length": 72,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/partiality-monad",
"max_stars_repo_path": "src/Search.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:59:18.000Z",
"num_tokens": 970,
"size": 2671
} |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.ZCohomology.Groups.Coproduct where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.HLevels
open import Cubical.Data.Nat
open import Cubical.Data.Sigma
open import Cubical.Data.Sum as Sum
open import Cubical.Algebra.Group
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties
open import Cubical.Algebra.Group.DirProd
open import Cubical.Algebra.Ring
open import Cubical.Algebra.Ring.DirectProd
open import Cubical.HITs.SetTruncation as ST
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.GroupStructure
private variable
ℓ ℓ' : Level
module _
{X : Type ℓ}
{Y : Type ℓ'}
where
open Iso
open IsGroupHom
open GroupStr
Equiv-Coproduct-CoHom : {n : ℕ} → GroupIso (coHomGr n (X ⊎ Y)) (DirProd (coHomGr n X) (coHomGr n Y))
Iso.fun (fst Equiv-Coproduct-CoHom) = ST.rec (isSet× squash₂ squash₂) (λ f → ∣ f ∘ inl ∣₂ , ∣ (f ∘ inr) ∣₂)
Iso.inv (fst Equiv-Coproduct-CoHom) = uncurry
(ST.rec (λ u v p q i j y → squash₂ (u y) (v y) (λ X → p X y) (λ X → q X y) i j)
(λ g → ST.rec squash₂ (λ h → ∣ Sum.rec g h ∣₂)))
Iso.rightInv (fst Equiv-Coproduct-CoHom) = uncurry
(ST.elim (λ x → isProp→isSet λ u v i y → isSet× squash₂ squash₂ _ _ (u y) (v y) i)
(λ g → ST.elim (λ _ → isProp→isSet (isSet× squash₂ squash₂ _ _))
(λ h → refl)))
Iso.leftInv (fst Equiv-Coproduct-CoHom) = ST.elim (λ _ → isProp→isSet (squash₂ _ _))
λ f → cong ∣_∣₂ (funExt (Sum.elim (λ x → refl) (λ x → refl)))
snd Equiv-Coproduct-CoHom = makeIsGroupHom
(ST.elim (λ x → isProp→isSet λ u v i y → isSet× squash₂ squash₂ _ _ (u y) (v y) i)
(λ g → ST.elim (λ _ → isProp→isSet (isSet× squash₂ squash₂ _ _))
λ h → refl))
| {
"alphanum_fraction": 0.6169507576,
"avg_line_length": 40.6153846154,
"ext": "agda",
"hexsha": "886b7f5b9be5e13649fce9f9e0a0728265dc0cf3",
"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/ZCohomology/Groups/Coproduct.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/ZCohomology/Groups/Coproduct.agda",
"max_line_length": 114,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/ZCohomology/Groups/Coproduct.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": 665,
"size": 2112
} |
-- Step-indexed logical relations based on functional big-step semantics.
--
-- Goal for now: just prove the fundamental theorem of logical relations,
-- relating a term to itself in a different environments.
--
-- But to betray the eventual goal, I can also relate integer values with a
-- change in the relation witness. That was a completely local change. But that
-- might also be because we only have few primitives.
--
-- Because of closures, we need relations across different terms with different
-- contexts and environments.
--
-- This development is strongly inspired by "Imperative self-adjusting
-- computation" (ISAC below), POPL'08, in preference to Dargaye and Leroy (2010), "A verified
-- framework for higher-order uncurrying optimizations", but I deviate
-- somewhere, especially to try following "Functional Big-Step Semantics"),
-- though I deviate somewhere.
-- In fact, this development is typed, hence some parts of the model are closer
-- to Ahmed (ESOP 2006), "Step-Indexed Syntactic Logical Relations for Recursive
-- and Quantified Types". But for many relevant aspects, the two papers are
-- interchangeable.
--
-- The main insight from the ISAC paper missing from the other one is how to
-- step-index a big-step semantics correctly: just ensure that the steps in the
-- big-step semantics agree with the ones in the small-step semantics. *Then*
-- everything just works with big-step semantics. Quite a few other details are
-- fiddly, but those are the same in small-step semantics.
--
-- CHEATS:
-- "Fuctional big-step semantics" requires an external termination proof for the
-- semantics. There it is also mechanized, here it isn't. Worse, the same
-- termination problem affects some lemmas about the semantics.
module Thesis.FunBigStepSILR2 where
open import Data.Empty
open import Data.Unit.Base hiding (_≤_)
open import Data.Product
open import Relation.Binary.PropositionalEquality
open import Relation.Binary hiding (_⇒_)
open import Data.Nat -- using (ℕ; zero; suc; decTotalOrder; _<_; _≤_)
open import Data.Nat.Properties
data Type : Set where
_⇒_ : (σ τ : Type) → Type
nat : Type
infixr 20 _⇒_
⟦_⟧Type : Type → Set
⟦ σ ⇒ τ ⟧Type = ⟦ σ ⟧Type → ⟦ τ ⟧Type
⟦ nat ⟧Type = ℕ
open import Base.Syntax.Context Type public
open import Base.Syntax.Vars Type public
data Const : (τ : Type) → Set where
lit : ℕ → Const nat
-- succ : Const (int ⇒ int)
data Term (Γ : Context) :
(τ : Type) → Set where
-- constants aka. primitives
const : ∀ {τ} →
(c : Const τ) →
Term Γ τ
var : ∀ {τ} →
(x : Var Γ τ) →
Term Γ τ
app : ∀ {σ τ}
(s : Term Γ (σ ⇒ τ)) →
(t : Term Γ σ) →
Term Γ τ
-- we use de Bruijn indices, so we don't need binding occurrences.
abs : ∀ {σ τ}
(t : Term (σ • Γ) τ) →
Term Γ (σ ⇒ τ)
weaken : ∀ {Γ₁ Γ₂ τ} →
(Γ₁≼Γ₂ : Γ₁ ≼ Γ₂) →
Term Γ₁ τ →
Term Γ₂ τ
weaken Γ₁≼Γ₂ (const c) = const c
weaken Γ₁≼Γ₂ (var x) = var (weaken-var Γ₁≼Γ₂ x)
weaken Γ₁≼Γ₂ (app s t) = app (weaken Γ₁≼Γ₂ s) (weaken Γ₁≼Γ₂ t)
weaken Γ₁≼Γ₂ (abs {σ} t) = abs (weaken (keep σ • Γ₁≼Γ₂) t)
data Val : Type → Set
open import Base.Denotation.Environment Type Val public
open import Base.Data.DependentList public
data Val where
closure : ∀ {Γ σ τ} → (t : Term (σ • Γ) τ) → (ρ : ⟦ Γ ⟧Context) → Val (σ ⇒ τ)
intV : ∀ (n : ℕ) → Val nat
import Base.Denotation.Environment
-- Den stands for Denotational semantics.
module Den = Base.Denotation.Environment Type ⟦_⟧Type
--
-- Functional big-step semantics
--
-- Termination is far from obvious to Agda once we use closures. So we use
-- step-indexing with a fuel value.
-- WARNING: ISAC's big-step semantics produces a step count as "output". But
-- that would not help Agda establish termination. That's only a problem for a
-- functional big-step semantics, not for a relational semantics.
--
-- So, instead, I tried to use a sort of writer monad: the interpreter gets fuel
-- and returns the remaining fuel. That's the same trick as in "functional
-- big-step semantics". That *makes* the function terminating, even though Agda
-- cannot see this because it does not know that the returned fuel is no bigger.
-- Since we focus for now on STLC, unlike that
-- paper, we could avoid error values because we keep types.
--
-- One could drop types and add error values instead.
data ErrVal (τ : Type) : Set where
Done : (v : Val τ) → (n1 : ℕ) → ErrVal τ
Error : ErrVal τ
TimeOut : ErrVal τ
Res : Type → Set
Res τ = (n : ℕ) → ErrVal τ
_>>=_ : ∀ {σ τ} → Res σ → (Val σ → Res τ) → Res τ
(s >>= t) n0 with s n0
... | Done v n1 = t v n1
... | Error = Error
... | TimeOut = TimeOut
evalConst : ∀ {τ} → Const τ → Res τ
evalConst (lit v) n = Done (intV v) n
{-# TERMINATING #-}
eval : ∀ {Γ τ} → Term Γ τ → ⟦ Γ ⟧Context → Res τ
apply : ∀ {σ τ} → Val (σ ⇒ τ) → Val σ → Res τ
apply (closure t ρ) a n = eval t (a • ρ) n
eval (var x) ρ n = Done (⟦ x ⟧Var ρ) n
eval (abs t) ρ n = Done (closure t ρ) n
eval (const c) ρ n = evalConst c n
eval _ ρ zero = TimeOut
eval (app s t) ρ (suc n) = (eval s ρ >>= (λ sv → eval t ρ >>= λ tv → apply sv tv)) n
eval-const-dec : ∀ {τ} → (c : Const τ) → ∀ {v} n0 n1 → evalConst c n0 ≡ Done v n1 → n1 ≤ n0
eval-const-dec (lit v) n0 .n0 refl = ≤-refl
{-# TERMINATING #-}
eval-dec : ∀ {Γ τ} → (t : Term Γ τ) → ∀ ρ v n0 n1 → eval t ρ n0 ≡ Done v n1 → n1 ≤ n0
eval-dec (const c) ρ v n0 n1 eq = eval-const-dec c n0 n1 eq
eval-dec (var x) ρ .(⟦ x ⟧Var ρ) n0 .n0 refl = ≤-refl
eval-dec (abs t) ρ .(closure t ρ) n0 .n0 refl = ≤-refl
eval-dec (app s t) ρ v zero n1 ()
eval-dec (app s t) ρ v (suc n0) n3 eq with eval s ρ n0 | inspect (eval s ρ) n0
eval-dec (app s t) ρ v (suc n0) n3 eq | Done sv sn1 | [ seq ] with eval t ρ sn1 | inspect (eval t ρ) sn1
eval-dec (app s t) ρ v (suc n0) n3 eq | Done sv@(closure st sρ) sn1 | [ seq ] | (Done tv tn2) | [ teq ] = ≤-step (≤-trans (≤-trans (eval-dec st _ _ _ _ eq) (eval-dec t _ _ _ _ teq)) (eval-dec s _ _ _ _ seq))
eval-dec (app s t) ρ v (suc n0) n3 () | Done sv sn1 | [ seq ] | Error | [ teq ]
eval-dec (app s t) ρ v (suc n0) n3 () | Done sv sn1 | [ seq ] | TimeOut | [ teq ]
eval-dec (app s t) ρ v (suc n0) n3 () | Error | [ seq ]
eval-dec (app s t) ρ v (suc n0) n3 () | TimeOut | [ seq ]
eval-const-mono : ∀ {τ} → (c : Const τ) → ∀ {v} n0 n1 → evalConst c n0 ≡ Done v n1 → evalConst c (suc n0) ≡ Done v (suc n1)
eval-const-mono (lit v) n0 .n0 refl = refl
-- ARGH
{-# TERMINATING #-}
eval-mono : ∀ {Γ τ} → (t : Term Γ τ) → ∀ ρ v n0 n1 → eval t ρ n0 ≡ Done v n1 → eval t ρ (suc n0) ≡ Done v (suc n1)
eval-mono (const c) ρ v n0 n1 eq = eval-const-mono c n0 n1 eq
eval-mono (var x) ρ .(⟦ x ⟧Var ρ) n0 .n0 refl = refl
eval-mono (abs t) ρ .(closure t ρ) n0 .n0 refl = refl
eval-mono (app s t) ρ v zero n1 ()
eval-mono (app s t) ρ v (suc n0) n1 eq with eval s ρ n0 | inspect (eval s ρ) n0
eval-mono (app s t) ρ v (suc n0) n2 eq | Done sv n1 | [ seq ] with eval s ρ (suc n0) | eval-mono s ρ sv n0 n1 seq
eval-mono (app s t) ρ v (suc n0) n2 eq | Done sv n1 | [ seq ] | .(Done sv (suc n1)) | refl with eval t ρ n1 | inspect (eval t ρ) n1
eval-mono (app s t) ρ v (suc n0) n3 eq | Done sv n1 | [ seq ] | .(Done sv (suc n1)) | refl | Done tv n2 | [ teq ] with eval t ρ (suc n1) | eval-mono t ρ tv n1 n2 teq
eval-mono (app s t) ρ v (suc n0) n3 eq | Done (closure t₁ ρ₁) n1 | [ seq ] | .(Done (closure {Γ = _} {σ = _} {τ = _} t₁ ρ₁) (suc n1)) | refl | (Done tv n2) | [ teq ] | .(Done tv (suc n2)) | refl = eval-mono t₁ (tv • ρ₁) v n2 n3 eq
eval-mono (app s t) ρ v (suc n0) n2 () | Done sv n1 | [ seq ] | .(Done sv (suc n1)) | refl | Error | [ teq ]
eval-mono (app s t) ρ v (suc n0) n2 () | Done sv n1 | [ seq ] | .(Done sv (suc n1)) | refl | TimeOut | [ teq ]
eval-mono (app s t) ρ v (suc n0) n1 () | Error | [ seq ]
eval-mono (app s t) ρ v (suc n0) n1 () | TimeOut | [ seq ]
eval-adjust-plus : ∀ d {Γ τ} → (t : Term Γ τ) → ∀ ρ v n0 n1 → eval t ρ n0 ≡ Done v n1 → eval t ρ (d + n0) ≡ Done v (d + n1)
eval-adjust-plus zero t ρ v n0 n1 eq = eq
eval-adjust-plus (suc d) t ρ v n0 n1 eq = eval-mono t ρ v (d + n0) (d + n1) (eval-adjust-plus d t ρ v n0 n1 eq)
eval-const-strengthen : ∀ {τ} → (c : Const τ) → ∀ {v} n0 n1 → evalConst c (suc n0) ≡ Done v (suc n1) → evalConst c n0 ≡ Done v n1
eval-const-strengthen (lit v) n0 .n0 refl = refl
-- I started trying to prove eval-strengthen, which I appeal to informally
-- below, but I gave up. I still guess the lemma is true but proving it looks
-- too painful to bother.
-- Without this lemma, I can't fully prove that this logical relation is
-- equivalent to the original one.
-- But this one works (well, at least up to the fundamental theorem, haven't
-- attempted other lemmas), so it should be good enough.
-- eval-mono-err : ∀ {Γ τ} → (t : Term Γ τ) → ∀ ρ n → eval t ρ n ≡ Error → eval t ρ (suc n) ≡ Error
-- eval-mono-err (const (lit x)) ρ zero eq = {!!}
-- eval-mono-err (const (lit x)) ρ (suc n) eq = {!!}
-- eval-mono-err (var x) ρ n eq = {!!}
-- eval-mono-err (app t t₁) ρ n eq = {!!}
-- eval-mono-err (abs t) ρ n eq = {!!}
-- -- eval t ρ (suc n0) ≡ Done v (suc n1) → eval t ρ n0 ≡ Done v n
-- eval-aux : ∀ {Γ τ} → (t : Term Γ τ) → ∀ ρ n → (Σ[ res0 ∈ ErrVal τ ] eval t ρ n ≡ res0) × (Σ[ resS ∈ ErrVal τ ] eval t ρ n ≡ resS)
-- eval-aux t ρ n with
-- eval t ρ n | inspect (eval t ρ) n |
-- eval t ρ (suc n) | inspect (eval t ρ) (suc n)
-- eval-aux t ρ n | res0 | [ eq0 ] | (Done v1 n1) | [ eq1 ] = {!!}
-- eval-aux t ρ n | res0 | [ eq0 ] | Error | [ eq1 ] = {!!}
-- eval-aux t ρ n | Done v n1 | [ eq0 ] | TimeOut | [ eq1 ] = {!!}
-- eval-aux t ρ n | Error | [ eq0 ] | TimeOut | [ eq1 ] = {!!}
-- eval-aux t ρ n | TimeOut | [ eq0 ] | TimeOut | [ eq1 ] = (TimeOut , refl) , (TimeOut , refl)
-- {-# TERMINATING #-}
-- eval-strengthen : ∀ {Γ τ} → (t : Term Γ τ) → ∀ ρ v n0 n1 → eval t ρ (suc n0) ≡ Done v (suc n1) → eval t ρ n0 ≡ Done v n1
-- eval-strengthen (const c) ρ v n0 n1 eq = eval-const-strengthen c n0 n1 eq
-- eval-strengthen (var x) ρ .(⟦ x ⟧Var ρ) n0 .n0 refl = refl
-- eval-strengthen (abs t) ρ .(closure t ρ) n0 .n0 refl = refl
-- eval-strengthen (app s t) ρ v zero n1 eq with eval s ρ 0 | inspect (eval s ρ) 0
-- eval-strengthen (app s t) ρ v zero n1 eq | Done sv sn1 | [ seq ] with eval-dec s ρ sv 0 sn1 seq
-- eval-strengthen (app s t) ρ v zero n1 eq | Done sv .0 | [ seq ] | z≤n with eval t ρ 0 | inspect (eval t ρ) 0
-- eval-strengthen (app s t) ρ v zero n1 eq | Done sv _ | [ seq ] | z≤n | Done tv tn1 | [ teq ] with eval-dec t ρ tv 0 tn1 teq
-- eval-strengthen (app s t) ρ v zero n1 eq | Done (closure st sρ) _ | [ seq ] | z≤n | (Done tv .0) | [ teq ] | z≤n with eval-dec st _ v 0 (suc n1) eq
-- eval-strengthen (app s t) ρ v zero n1 eq | Done (closure st sρ) _ | [ seq ] | z≤n | (Done tv _) | [ teq ] | z≤n | ()
-- eval-strengthen (app s t) ρ v zero n1 () | Done sv _ | [ seq ] | z≤n | Error | [ teq ]
-- eval-strengthen (app s t) ρ v zero n1 () | Done sv _ | [ seq ] | z≤n | TimeOut | [ teq ]
-- eval-strengthen (app s t) ρ v zero n1 () | Error | [ seq ]
-- eval-strengthen (app s t) ρ v zero n1 () | TimeOut | [ seq ]
-- -- eval-dec s ρ
-- -- {!eval-dec s ρ ? (suc zero) (suc n1) !}
-- -- eval-strengthen (app s t) ρ v (suc n0) n1 eq with eval s ρ (suc n0) | inspect (eval s ρ) (suc n0)
-- -- eval-strengthen (app s t) ρ v₁ (suc n0) n2 eq | Done sv n1 | [ seq ] with eval s ρ n0 = {!eval-strengthen s ρ v n0 n1 seq !}
-- -- eval-strengthen (app s t) ρ v (suc n0) n1 () | Error | [ seq ]
-- -- eval-strengthen (app s t) ρ v (suc n0) n1 () | TimeOut | [ seq ]
-- eval-strengthen (app s t) ρ v (suc n0) n1 eq with eval s ρ n0 | inspect (eval s ρ) n0
-- eval-strengthen (app s t) ρ v (suc n0) n2 eq | Done sv n1 | [ seq ] with eval s ρ (suc n0) | eval-mono s ρ sv n0 n1 seq
-- eval-strengthen (app s t) ρ v (suc n0) n2 eq | Done sv n1 | [ seq ] | .(Done sv (suc n1)) | refl with eval t ρ n1 | inspect (eval t ρ) n1
-- eval-strengthen (app s t) ρ v (suc n0) n3 eq | Done sv n1 | [ seq ] | .(Done sv (suc n1)) | refl | Done tv n2 | [ teq ] with eval t ρ (suc n1) | eval-mono t ρ tv n1 n2 teq
-- eval-strengthen (app s t) ρ v (suc n0) n3 eq | Done (closure t₁ ρ₁) n1 | [ seq ] | .(Done (closure {Γ = _} {σ = _} {τ = _} t₁ ρ₁) (suc n1)) | refl | (Done tv n2) | [ teq ] | .(Done tv (suc n2)) | refl = eval-strengthen t₁ (tv • ρ₁) v n2 n3 eq
-- eval-strengthen (app s t) ρ v (suc n0) n2 eq | Done sv n1 | [ seq ] | .(Done sv (suc n1)) | refl | Error | [ teq ] = {!!}
-- eval-strengthen (app s t) ρ v (suc n0) n2 eq | Done sv n1 | [ seq ] | .(Done sv (suc n1)) | refl | TimeOut | [ teq ] = {!!}
-- eval-strengthen (app s t) ρ v (suc n0) n1 eq | Error | [ seq ] = {!!}
-- eval-strengthen (app s t) ρ v (suc n0) n1 eq | TimeOut | [ seq ] = {!!}
-- eval-adjust-minus : ∀ d {Γ τ} → (t : Term Γ τ) → ∀ {ρ v} n0 n1 → eval t ρ (d + n0) ≡ Done v (d + n1) → eval t ρ n0 ≡ Done v n1
-- eval-adjust-minus zero t n0 n1 eq = eq
-- eval-adjust-minus (suc d) t n0 n1 eq = eval-adjust-minus d t n0 n1 (eval-strengthen t _ _ (d + n0) (d + n1) eq)
import Data.Integer as I
open I using (ℤ)
mutual
-- Warning: compared to Ahmed's papers, this definition for relT also requires
-- t1 to be well-typed, not just t2.
--
-- This difference might affect the status of some proofs in Ahmed's papers,
-- but that's not a problem here.
-- Also: can't confirm this in any of the papers I'm using, but I'd guess that
-- all papers using environments allow to relate closures with different
-- implementations and different hidden environments.
--
-- To check if the proof goes through with equal context, I changed the proof.
-- Now a proof that two closures are equivalent contains a proof that their
-- typing contexts are equivalent. The changes were limited softawre
-- engineering, the same proofs go through.
-- This is not the same definition of relT, but it is equivalent.
relT : ∀ {τ Γ} (t1 : Term Γ τ) (t2 : Term Γ τ) (ρ1 : ⟦ Γ ⟧Context) (ρ2 : ⟦ Γ ⟧Context) → ℕ → Set
-- This equation is a lemma in the original definition.
relT t1 t2 ρ1 ρ2 zero = ⊤
-- To compare this definition, note that the original k is suc n here.
relT {τ} t1 t2 ρ1 ρ2 (suc n) =
(v1 : Val τ) →
-- Originally we have 0 ≤ j < k, so j < suc n, so k - j = suc n - j.
-- It follows that 0 < k - j ≤ k, hence suc n - j ≤ suc n, or n - j ≤ n.
-- Here, instead of binding j we bind n-j = n - j, require n - j ≤ n, and
-- use suc n-j instead of k - j.
∀ n-j (n-j≤n : n-j ≤ n) →
-- The next assumption is important. This still says that evaluation consumes j steps.
-- Since j ≤ n, it is OK to start evaluation with n steps.
-- Starting with (suc n) and getting suc n-j is equivalent, per eval-mono
-- and eval-strengthen. But in practice this version is easier to use.
(eq : eval t1 ρ1 n ≡ Done v1 n-j) →
Σ[ v2 ∈ Val τ ] Σ[ n2 ∈ ℕ ] eval t2 ρ2 n2 ≡ Done v2 0 × relV τ v1 v2 (suc n-j)
-- Here, computing t2 is allowed to take an unbounded number of steps. Having to write a number at all is annoying.
relV : ∀ τ (v1 v2 : Val τ) → ℕ → Set
-- Show the proof still goes through if we relate clearly different values by
-- inserting changes in the relation.
-- There's no syntax to produce such changes, but you can add changes to the
-- environment.
relV nat (intV v1) (intV v2) n = Σ[ dv ∈ ℤ ] dv I.+ (I.+ v1) ≡ (I.+ v2)
relV (σ ⇒ τ) (closure {Γ1} t1 ρ1) (closure {Γ2} t2 ρ2) n =
Σ (Γ1 ≡ Γ2) λ { refl →
∀ (k : ℕ) (k≤n : k < n) v1 v2 →
relV σ v1 v2 k →
relT t1 t2 (v1 • ρ1) (v2 • ρ2) k
}
-- Above, in the conclusion, I'm not relating app (closure t1 ρ1) v1 with app
-- (closure t2 ρ2) v2 (or some encoding of that that actually works), but the
-- result of taking a step from that configuration. That is important, because
-- both Pitts' "Step-Indexed Biorthogonality: a Tutorial Example" and
-- "Imperative Self-Adjusting Computation" do the same thing (and point out it's
-- important).
Δτ : Type → Type
Δτ (σ ⇒ τ) = σ ⇒ (Δτ σ) ⇒ Δτ τ
Δτ nat = nat
mutual
-- The original relation allows unrelated environments. However, while that is
-- fine as a logical relation, it's not OK if we want to prove that validity
-- agrees with oplus. We want a finer relation.
-- Also: we still need to demand the actual environments to be related, and
-- the bodies to match. Haven't done that yet. On the other hand, since we do want
-- to allow for replacement changes, that would probably complicate the proof
-- elsewhere.
relT3 : ∀ {τ Γ ΔΓ} (t1 : Term Γ τ) (dt : Term ΔΓ (Δτ τ)) (t2 : Term Γ τ) (ρ1 : ⟦ Γ ⟧Context) (dρ : ⟦ ΔΓ ⟧Context) (ρ2 : ⟦ Γ ⟧Context) → ℕ → Set
relT3 t1 dt t2 ρ1 dρ ρ2 zero = ⊤
relT3 {τ} t1 dt t2 ρ1 dρ ρ2 (suc n) =
(v1 : Val τ) →
∀ n-j (n-j≤n : n-j ≤ n) →
(eq : eval t1 ρ1 n ≡ Done v1 n-j) →
Σ[ v2 ∈ Val τ ] Σ[ n2 ∈ ℕ ] eval t2 ρ2 n2 ≡ Done v2 0 ×
Σ[ dv ∈ Val (Δτ τ) ] Σ[ dn ∈ ℕ ] eval dt dρ dn ≡ Done dv 0 ×
relV3 τ v1 dv v2 (suc n-j)
-- Weakening in this definition is going to be annoying to use. And having to
-- construct terms is ugly.
-- Worse, evaluating the application consumes computation steps.
-- Weakening could be avoided if we use a separate language of change terms
-- with two environments, and with a dclosure binding two variables at once,
-- and so on.
relV3 : ∀ τ (v1 : Val τ) (dv : Val (Δτ τ)) (v2 : Val τ) → ℕ → Set
relV3 nat (intV v1) (intV dv) (intV v2) n = dv + v1 ≡ v2
relV3 (σ ⇒ τ) (closure {Γ1} t1 ρ1) (closure dt dρ) (closure {Γ2} t2 ρ2) n =
Σ (Γ1 ≡ Γ2) λ { refl →
∀ (k : ℕ) (k<n : k < n) v1 dv v2 →
relV3 σ v1 dv v2 k →
relT3 t1 (app (weaken (drop (Δτ σ) • ≼-refl) dt) (var this)) t2 (v1 • ρ1) (dv • v1 • dρ) (v2 • ρ2) k
}
-- Relate λ x → 0 and λ x → 1 at any step count.
example1 : ∀ n → relV (nat ⇒ nat) (closure (const (lit 0)) ∅) (closure (const (lit 1)) ∅) n
example1 n = refl ,
λ { zero k<n v1 v2 x → tt
; (suc k) k<n v1 v2 x .(intV 0) .k n-j≤n refl → intV 1 , 0 , refl , (I.+ 1 , refl)
}
-- Relate λ x → 0 and λ x → x at any step count.
example2 : ∀ n → relV (nat ⇒ nat) (closure (const (lit 0)) ∅) (closure (var this) ∅) n
example2 n = refl ,
λ { zero k<n v1 v2 x → tt
; (suc k) k<n (intV v1) (intV v2) x .(intV 0) .k n-j≤n refl → intV v2 , 0 , refl , (I.+ v2 , cong I.+_ (+-identityʳ v2))
}
relρ : ∀ Γ (ρ1 ρ2 : ⟦ Γ ⟧Context) → ℕ → Set
relρ ∅ ∅ ∅ n = ⊤
relρ (τ • Γ) (v1 • ρ1) (v2 • ρ2) n = relV τ v1 v2 n × relρ Γ ρ1 ρ2 n
relV-mono : ∀ m n → m ≤ n → ∀ τ v1 v2 → relV τ v1 v2 n → relV τ v1 v2 m
relV-mono m n m≤n nat (intV v1) (intV v2) vv = vv
relV-mono m n m≤n (σ ⇒ τ) (closure t1 ρ1) (closure t2 ρ2) (refl , ff) = refl , λ k k≤m → ff k (≤-trans k≤m m≤n)
relρ-mono : ∀ m n → m ≤ n → ∀ Γ ρ1 ρ2 → relρ Γ ρ1 ρ2 n → relρ Γ ρ1 ρ2 m
relρ-mono m n m≤n ∅ ∅ ∅ tt = tt
relρ-mono m n m≤n (τ • Γ) (v1 • ρ1) (v2 • ρ2) (vv , ρρ) = relV-mono m n m≤n _ v1 v2 vv , relρ-mono m n m≤n Γ ρ1 ρ2 ρρ
fundamentalV : ∀ {Γ τ} (x : Var Γ τ) → (n : ℕ) → (ρ1 ρ2 : ⟦ Γ ⟧Context) (ρρ : relρ Γ ρ1 ρ2 n) → relT (var x) (var x) ρ1 ρ2 n
fundamentalV x zero ρ1 ρ2 ρρ = tt
fundamentalV this (suc n) (v1 • ρ1) (v2 • ρ2) (vv , ρρ) .v1 .n n-j≤n refl = v2 , zero , refl , vv
fundamentalV (that x) (suc n) (v1 • ρ1) (v2 • ρ2) (vv , ρρ) = fundamentalV x (suc n) ρ1 ρ2 ρρ
lt1 : ∀ {k n} → k < n → k ≤ n
lt1 (s≤s p) = ≤-step p
fundamental : ∀ {Γ τ} (t : Term Γ τ) → (n : ℕ) → (ρ1 ρ2 : ⟦ Γ ⟧Context) (ρρ : relρ Γ ρ1 ρ2 n) → relT t t ρ1 ρ2 n
fundamental t zero ρ1 ρ2 ρρ = tt
fundamental (var x) (suc n) ρ1 ρ2 ρρ = fundamentalV x (suc n) ρ1 ρ2 ρρ
fundamental (const (lit v)) (suc n) ρ1 ρ2 ρρ .(intV v) .n n-j≤n refl = intV v , zero , refl , I.+ zero , refl
fundamental (abs t) (suc n) ρ1 ρ2 ρρ .(closure t ρ1) .n n-j≤n refl = closure t ρ2 , zero , refl , refl , λ k k<n v1 v2 vv → fundamental t k (v1 • ρ1) (v2 • ρ2) (vv , relρ-mono k (suc n) (lt1 k<n) _ _ _ ρρ)
fundamental (app s t) (suc zero) ρ1 ρ2 ρρ v1 n-j n-j≤n ()
fundamental (app s t) (suc (suc n)) ρ1 ρ2 ρρ v1 n-j n-j≤n eq with eval s ρ1 n | inspect (eval s ρ1) n
fundamental (app s t) (suc (suc n)) ρ1 ρ2 ρρ v1 n-j n-j≤n eq | Done sv1 n1 | [ s1eq ] with eval-dec s _ _ n n1 s1eq | eval t ρ1 n1 | inspect (eval t ρ1) n1
fundamental (app s t) (suc (suc n)) ρ1 ρ2 ρρ v1 n-j n-j≤n eq | Done (closure st1 sρ1) n1 | [ s1eq ] | n1≤n | Done tv1 n2 | [ t1eq ] with eval-dec t _ _ n1 n2 t1eq
... | n2≤n1 with fundamental s (suc (suc n)) ρ1 ρ2 ρρ (closure st1 sρ1) (suc n1) (s≤s n1≤n) (eval-mono s ρ1 (closure st1 sρ1) n n1 s1eq)
| fundamental t (suc (suc n1)) ρ1 ρ2 (relρ-mono (suc (suc n1)) (suc (suc n)) (s≤s (s≤s n1≤n)) _ _ _ ρρ) tv1 (suc n2) (s≤s n2≤n1) (eval-mono t ρ1 tv1 n1 n2 t1eq)
... | sv2@(closure st2 sρ2) , sn3 , s2eq , refl , svv | tv2 , tn3 , t2eq , tvv with svv (suc n2) (s≤s (s≤s n2≤n1)) tv1 tv2 (relV-mono (suc n2) (suc (suc n2)) (s≤s (n≤1+n n2)) _ tv1 tv2 tvv) v1 n-j (eval-dec st1 _ _ _ _ eq) eq
... | v2 , n3 , eq2 , vv = v2 , suc (sn3 + (tn3 + n3)) , comp , vv
where
s2eq-adj : eval s ρ2 (sn3 + (tn3 + n3)) ≡ Done (closure st2 sρ2) (tn3 + n3)
s2eq-adj rewrite +-comm sn3 (tn3 + n3)| cong (Done (closure st2 sρ2)) (sym (+-identityʳ (tn3 + n3))) = eval-adjust-plus (tn3 + n3) s _ sv2 _ _ s2eq
t2eq-adj : eval t ρ2 (tn3 + n3) ≡ Done tv2 n3
t2eq-adj rewrite +-comm tn3 n3 | cong (Done tv2) (sym (+-identityʳ n3)) = eval-adjust-plus n3 t _ tv2 _ _ t2eq
comp : (eval s ρ2 >>= (λ sv → eval t ρ2 >>= apply sv))
(sn3 + (tn3 + n3))
≡ Done v2 0
comp rewrite s2eq-adj | t2eq-adj = eq2
fundamental (app s t) (suc (suc n)) ρ1 ρ2 ρρ v1 n-j n-j≤n () | Done sv1 n1 | [ s1eq ] | n1≤n | Error | [ t1eq ]
fundamental (app s t) (suc (suc n)) ρ1 ρ2 ρρ v1 n-j n-j≤n () | Done sv1 n1 | [ s1eq ] | n1≤n | TimeOut | [ t1eq ]
fundamental (app s t) (suc (suc n)) ρ1 ρ2 ρρ v1 n-j n-j≤n () | Error | [ s1eq ]
fundamental (app s t) (suc (suc n)) ρ1 ρ2 ρρ v1 n-j n-j≤n () | TimeOut | [ s1eq ]
| {
"alphanum_fraction": 0.604519774,
"avg_line_length": 52.7142857143,
"ext": "agda",
"hexsha": "44b82987ded763b77e5f762b226c18fd0490e5a7",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "inc-lc/ilc-agda",
"max_forks_repo_path": "Thesis/FunBigStepSILR2.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "inc-lc/ilc-agda",
"max_issues_repo_path": "Thesis/FunBigStepSILR2.agda",
"max_line_length": 245,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "inc-lc/ilc-agda",
"max_stars_repo_path": "Thesis/FunBigStepSILR2.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": 8861,
"size": 21771
} |
{-
Automatically generating proofs of UnivalentStr for records
-}
{-# OPTIONS --cubical --no-exact-split --safe #-}
module Cubical.Structures.Record where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.SIP
open import Cubical.Foundations.Structure
open import Cubical.Foundations.Univalence
open import Cubical.Data.Sigma
open import Cubical.Data.Nat
open import Cubical.Data.List as List
open import Cubical.Data.Vec as Vec
open import Cubical.Data.Bool
open import Cubical.Data.Maybe
open import Cubical.Data.Sum
open import Cubical.Structures.Auto
import Cubical.Structures.Macro as M
import Agda.Builtin.Reflection as R
open import Cubical.Reflection.Base
-- Magic number
private
FUEL = 10000
-- Types for specifying inputs to the tactics
data AutoFieldSpec : Typeω where
autoFieldSpec : ∀ {ℓ ℓ₁ ℓ₂} (R : Type ℓ → Type ℓ₁) {S : Type ℓ → Type ℓ₂}
→ ({X : Type ℓ} → R X → S X)
→ AutoFieldSpec
module _ {ℓ ℓ₁ ℓ₁'} where
mutual
data AutoFields (R : Type ℓ → Type ℓ₁) (ι : StrEquiv R ℓ₁') : Typeω
where
fields: : AutoFields R ι
_data[_∣_] : (fs : AutoFields R ι)
→ ∀ {ℓ₂ ℓ₂'} {S : Type ℓ → Type ℓ₂} {ι' : StrEquiv S ℓ₂'}
→ (f : {X : Type ℓ} → R X → S X)
→ ({A B : TypeWithStr ℓ R} {e : typ A ≃ typ B} → ι A B e → ι' (map-snd f A) (map-snd f B) e)
→ AutoFields R ι
_prop[_∣_] : (fs : AutoFields R ι)
→ ∀ {ℓ₂} {P : (X : Type ℓ) → GatherFields fs X → Type ℓ₂}
→ ({X : Type ℓ} (r : R X) → P X (projectFields fs r))
→ isPropProperty R ι fs P
→ AutoFields R ι
GatherFieldsLevel : {R : Type ℓ → Type ℓ₁} {ι : StrEquiv R ℓ₁'}
→ AutoFields R ι
→ Level
GatherFieldsLevel fields: = ℓ-zero
GatherFieldsLevel (_data[_∣_] fs {ℓ₂ = ℓ₂} _ _) = ℓ-max (GatherFieldsLevel fs) ℓ₂
GatherFieldsLevel (_prop[_∣_] fs {ℓ₂ = ℓ₂} _ _) = ℓ-max (GatherFieldsLevel fs) ℓ₂
GatherFields : {R : Type ℓ → Type ℓ₁} {ι : StrEquiv R ℓ₁'}
(dat : AutoFields R ι)
→ Type ℓ → Type (GatherFieldsLevel dat)
GatherFields fields: X = Unit
GatherFields (_data[_∣_] fs {S = S} _ _) X = GatherFields fs X × S X
GatherFields (_prop[_∣_] fs {P = P} _ _) X =
Σ[ s ∈ GatherFields fs X ] (P X s)
projectFields : {R : Type ℓ → Type ℓ₁} {ι : StrEquiv R ℓ₁'}
(fs : AutoFields R ι)
→ {X : Type ℓ} → R X → GatherFields fs X
projectFields fields: = _
projectFields (fs data[ f ∣ _ ]) r = projectFields fs r , f r
projectFields (fs prop[ f ∣ _ ]) r = projectFields fs r , f r
isPropProperty : ∀ {ℓ₂} (R : Type ℓ → Type ℓ₁)
(ι : StrEquiv R ℓ₁')
(fs : AutoFields R ι)
(P : (X : Type ℓ) → GatherFields fs X → Type ℓ₂)
→ Type (ℓ-max (ℓ-suc ℓ) (ℓ-max ℓ₁ ℓ₂))
isPropProperty R ι fs P =
{X : Type ℓ} (r : R X) → isProp (P X (projectFields fs r))
data AutoRecordSpec : Typeω where
autoRecordSpec : (R : Type ℓ → Type ℓ₁) (ι : StrEquiv R ℓ₁')
→ AutoFields R ι
→ AutoRecordSpec
-- Some reflection utilities
private
tApply : R.Term → List (R.Arg R.Term) → R.Term
tApply t l = R.def (quote idfun) (R.unknown v∷ t v∷ l)
tStrMap : R.Term → R.Term → R.Term
tStrMap A f = R.def (quote map-snd) (f v∷ A v∷ [])
tStrProj : R.Term → R.Name → R.Term
tStrProj A sfield = tStrMap A (R.def sfield [])
Fun : ∀ {ℓ ℓ'} → Type ℓ → Type ℓ' → Type (ℓ-max ℓ ℓ')
Fun A B = A → B
-- Helper functions used in the generated univalence proof
private
pathMap : ∀ {ℓ ℓ'} {S : I → Type ℓ} {T : I → Type ℓ'} (f : {i : I} → S i → T i)
{x : S i0} {y : S i1} → PathP S x y → PathP T (f x) (f y)
pathMap f p i = f (p i)
-- Property field helper functions
module _
{ℓ ℓ₁ ℓ₁' ℓ₂}
(R : Type ℓ → Type ℓ₁) -- Structure record
(ι : StrEquiv R ℓ₁') -- Equivalence record
(fs : AutoFields R ι) -- Prior fields
(P : (X : Type ℓ) → GatherFields fs X → Type ℓ₂) -- Property type
(f : {X : Type ℓ} (r : R X) → P X (projectFields fs r)) -- Property projection
where
prev = projectFields fs
Prev = GatherFields fs
PropHelperCenterType : Type _
PropHelperCenterType =
(A B : TypeWithStr ℓ R) (e : A .fst ≃ B .fst)
(p : PathP (λ i → Prev (ua e i)) (prev (A .snd)) (prev (B .snd)))
→ PathP (λ i → P (ua e i) (p i)) (f (A .snd)) (f (B .snd))
PropHelperContractType : PropHelperCenterType → Type _
PropHelperContractType c =
(A B : TypeWithStr ℓ R) (e : A .fst ≃ B .fst)
{p₀ : PathP (λ i → Prev (ua e i)) (prev (A .snd)) (prev (B .snd))}
(q : PathP (λ i → R (ua e i)) (A .snd) (B .snd))
(p : p₀ ≡ (λ i → prev (q i)))
→ PathP (λ k → PathP (λ i → P (ua e i) (p k i)) (f (A .snd)) (f (B .snd)))
(c A B e p₀)
(λ i → f (q i))
PropHelperType : Type _
PropHelperType =
Σ PropHelperCenterType PropHelperContractType
derivePropHelper : isPropProperty R ι fs P → PropHelperType
derivePropHelper propP .fst A B e p =
isOfHLevelPathP' 0 (propP _) (f (A .snd)) (f (B .snd)) .fst
derivePropHelper propP .snd A B e q p =
isOfHLevelPathP' 0 (isOfHLevelPathP 1 (propP _) _ _) _ _ .fst
-- Build proof of univalence from an isomorphism
module _ {ℓ ℓ₁ ℓ₁'} (S : Type ℓ → Type ℓ₁) (ι : StrEquiv S ℓ₁') where
fwdShape : Type _
fwdShape =
(A B : TypeWithStr ℓ S) (e : typ A ≃ typ B) → ι A B e → PathP (λ i → S (ua e i)) (str A) (str B)
bwdShape : Type _
bwdShape =
(A B : TypeWithStr ℓ S) (e : typ A ≃ typ B) → PathP (λ i → S (ua e i)) (str A) (str B) → ι A B e
fwdBwdShape : fwdShape → bwdShape → Type _
fwdBwdShape fwd bwd =
(A B : TypeWithStr ℓ S) (e : typ A ≃ typ B) → ∀ p → fwd A B e (bwd A B e p) ≡ p
bwdFwdShape : fwdShape → bwdShape → Type _
bwdFwdShape fwd bwd =
(A B : TypeWithStr ℓ S) (e : typ A ≃ typ B) → ∀ r → bwd A B e (fwd A B e r) ≡ r
-- The implicit arguments A,B in UnivalentStr make some things annoying so let's avoid them
ExplicitUnivalentStr : Type _
ExplicitUnivalentStr =
(A B : TypeWithStr _ S) (e : typ A ≃ typ B) → ι A B e ≃ PathP (λ i → S (ua e i)) (str A) (str B)
explicitUnivalentStr : (fwd : fwdShape) (bwd : bwdShape)
→ fwdBwdShape fwd bwd → bwdFwdShape fwd bwd
→ ExplicitUnivalentStr
explicitUnivalentStr fwd bwd fwdBwd bwdFwd A B e = isoToEquiv isom
where
open Iso
isom : Iso _ _
isom .fun = fwd A B e
isom .inv = bwd A B e
isom .rightInv = fwdBwd A B e
isom .leftInv = bwdFwd A B e
ExplicitUnivalentDesc : ∀ ℓ → (d : M.Desc ℓ) → Type _
ExplicitUnivalentDesc _ d =
ExplicitUnivalentStr (M.MacroStructure d) (M.MacroEquivStr d)
explicitUnivalentDesc : ∀ ℓ → (d : M.Desc ℓ) → ExplicitUnivalentDesc ℓ d
explicitUnivalentDesc _ d A B e = M.MacroUnivalentStr d e
-- Internal record specification type
private
record TypedTerm : Type where
field
type : R.Term
term : R.Term
record InternalDatumField : Type where
field
sfield : R.Name -- name of structure field
efield : R.Name -- name of equivalence field
record InternalPropField : Type where
field
sfield : R.Name -- name of structure field
InternalField : Type
InternalField = InternalDatumField ⊎ InternalPropField
record InternalSpec (A : Type) : Type where
field
srec : R.Term -- structure record type
erec : R.Term -- equivalence record type
fields : List (InternalField × A) -- in reverse order
open TypedTerm
open InternalDatumField
open InternalPropField
-- Parse a field and record specifications
private
findName : R.Term → R.TC R.Name
findName (R.def name _) = R.returnTC name
findName (R.lam R.hidden (R.abs _ t)) = findName t
findName t = R.typeError (R.strErr "Not a name + spine: " ∷ R.termErr t ∷ [])
parseFieldSpec : R.Term → R.TC (R.Term × R.Term × R.Term × R.Term)
parseFieldSpec (R.con (quote autoFieldSpec) (ℓ h∷ ℓ₁ h∷ ℓ₂ h∷ R v∷ S h∷ f v∷ [])) =
R.reduce ℓ >>= λ ℓ →
R.returnTC (ℓ , ℓ₂ , S , f)
parseFieldSpec t =
R.typeError (R.strErr "Malformed field specification: " ∷ R.termErr t ∷ [])
parseSpec : R.Term → R.TC (InternalSpec TypedTerm)
parseSpec (R.con (quote autoRecordSpec) (ℓ h∷ ℓ₁ h∷ ℓ₁' h∷ srecTerm v∷ erecTerm v∷ fs v∷ [])) =
parseFields fs >>= λ fs' →
R.returnTC λ { .srec → srecTerm ; .erec → erecTerm ; .fields → fs'}
where
open InternalSpec
parseFields : R.Term → R.TC (List (InternalField × TypedTerm))
parseFields (R.con (quote fields:) _) = R.returnTC []
parseFields (R.con (quote _data[_∣_])
(ℓ h∷ ℓ₁ h∷ ℓ₁' h∷ R h∷ ι h∷ fs v∷ ℓ₂ h∷ ℓ₂' h∷ S h∷ ι' h∷ sfieldTerm v∷ efieldTerm v∷ []))
=
R.reduce ℓ >>= λ ℓ →
findName sfieldTerm >>= λ sfieldName →
findName efieldTerm >>= λ efieldName →
buildDesc FUEL ℓ ℓ₂ S >>= λ d →
let
f : InternalField × TypedTerm
f = λ
{ .fst → inl λ { .sfield → sfieldName ; .efield → efieldName }
; .snd .type → R.def (quote ExplicitUnivalentDesc) (ℓ v∷ d v∷ [])
; .snd .term → R.def (quote explicitUnivalentDesc) (ℓ v∷ d v∷ [])
}
in
liftTC (f ∷_) (parseFields fs)
parseFields (R.con (quote _prop[_∣_])
(ℓ h∷ ℓ₁ h∷ ℓ₁' h∷ R h∷ ι h∷ fs v∷ ℓ₂ h∷ P h∷ fieldTerm v∷ prop v∷ []))
=
findName fieldTerm >>= λ fieldName →
let
p : InternalField × TypedTerm
p = λ
{ .fst → inr λ { .sfield → fieldName }
; .snd .type →
R.def (quote PropHelperType) (srecTerm v∷ erecTerm v∷ fs v∷ P v∷ fieldTerm v∷ [])
; .snd .term →
R.def (quote derivePropHelper) (srecTerm v∷ erecTerm v∷ fs v∷ P v∷ fieldTerm v∷ prop v∷ [])
}
in
liftTC (p ∷_) (parseFields fs)
parseFields t = R.typeError (R.strErr "Malformed autoRecord specification (1): " ∷ R.termErr t ∷ [])
parseSpec t = R.typeError (R.strErr "Malformed autoRecord specification (2): " ∷ R.termErr t ∷ [])
-- Build a proof of univalence from an InternalSpec
module _ (spec : InternalSpec ℕ) where
open InternalSpec spec
private
fwdDatum : Vec R.Term 4 → R.Term → InternalDatumField × ℕ → R.Term
fwdDatum (A ∷ B ∷ e ∷ streq ∷ _) i (dat , n) =
R.def (quote equivFun)
(tApply (v n) (tStrProj A (dat .sfield) v∷ tStrProj B (dat .sfield) v∷ e v∷ [])
v∷ R.def (dat .efield) (streq v∷ [])
v∷ i
v∷ [])
fwdProperty : Vec R.Term 4 → R.Term → R.Term → InternalPropField × ℕ → R.Term
fwdProperty (A ∷ B ∷ e ∷ streq ∷ _) i prevPath prop =
R.def (quote fst) (v (prop .snd) v∷ A v∷ B v∷ e v∷ prevPath v∷ i v∷ [])
bwdClause : Vec R.Term 4 → InternalDatumField × ℕ → R.Clause
bwdClause (A ∷ B ∷ e ∷ q ∷ _) (dat , n) =
R.clause [] (R.proj (dat .efield) v∷ [])
(R.def (quote invEq)
(tApply
(v n)
(tStrProj A (dat .sfield) v∷ tStrProj B (dat .sfield) v∷ e v∷ [])
v∷ R.def (quote pathMap) (R.def (dat .sfield) [] v∷ q v∷ [])
v∷ []))
fwdBwdDatum : Vec R.Term 4 → R.Term → R.Term → InternalDatumField × ℕ → R.Term
fwdBwdDatum (A ∷ B ∷ e ∷ q ∷ _) j i (dat , n) =
R.def (quote retEq)
(tApply
(v n)
(tStrProj A (dat .sfield) v∷ tStrProj B (dat .sfield) v∷ e v∷ [])
v∷ R.def (quote pathMap) (R.def (dat .sfield) [] v∷ q v∷ [])
v∷ j v∷ i
v∷ [])
fwdBwdProperty : Vec R.Term 4 → (j i prevPath : R.Term) → InternalPropField × ℕ → R.Term
fwdBwdProperty (A ∷ B ∷ e ∷ q ∷ _) j i prevPath prop =
R.def (quote snd) (v (prop .snd) v∷ A v∷ B v∷ e v∷ q v∷ prevPath v∷ j v∷ i v∷ [])
bwdFwdClause : Vec R.Term 4 → R.Term → InternalDatumField × ℕ → R.Clause
bwdFwdClause (A ∷ B ∷ e ∷ streq ∷ _) j (dat , n) =
R.clause [] (R.proj (dat .efield) v∷ [])
(R.def (quote secEq)
(tApply
(v n)
(tStrProj A (dat .sfield) v∷ tStrProj B (dat .sfield) v∷ e v∷ [])
v∷ R.def (dat .efield) (streq v∷ [])
v∷ j
v∷ []))
makeVarsFrom : {n : ℕ} → ℕ → Vec R.Term n
makeVarsFrom {zero} k = []
makeVarsFrom {suc n} k = v (n + k) ∷ (makeVarsFrom k)
fwd : R.Term
fwd =
vlam "A" (vlam "B" (vlam "e" (vlam "streq" (vlam "i" (R.pat-lam body [])))))
where
-- input list is in reverse order
fwdClauses : ℕ → List (InternalField × ℕ) → List (R.Name × R.Term)
fwdClauses k [] = []
fwdClauses k ((inl f , n) ∷ fs) =
fwdClauses k fs
∷ʳ (f .sfield , fwdDatum (makeVarsFrom k) (v 0) (map-snd (4 + k +_) (f , n)))
fwdClauses k ((inr p , n) ∷ fs) =
fwdClauses k fs
∷ʳ (p .sfield , fwdProperty (makeVarsFrom k) (v 0) prevPath (map-snd (4 + k +_) (p , n)))
where
prevPath =
vlam "i"
(List.foldl
(λ t (_ , t') → R.con (quote _,_) (t v∷ t' v∷ []))
(R.con (quote tt) [])
(fwdClauses (suc k) fs))
body =
List.map (λ (n , t) → R.clause [] [ varg (R.proj n) ] t) (fwdClauses 1 fields)
bwd : R.Term
bwd =
vlam "A" (vlam "B" (vlam "e" (vlam "q" (R.pat-lam (bwdClauses fields) []))))
where
-- input is in reverse order
bwdClauses : List (InternalField × ℕ) → List R.Clause
bwdClauses [] = []
bwdClauses ((inl f , n) ∷ fs) =
bwdClauses fs
∷ʳ bwdClause (makeVarsFrom 0) (map-snd (4 +_) (f , n))
bwdClauses ((inr p , n) ∷ fs) = bwdClauses fs
fwdBwd : R.Term
fwdBwd =
vlam "A" (vlam "B" (vlam "e" (vlam "q" (vlam "j" (vlam "i" (R.pat-lam body []))))))
where
-- input is in reverse order
fwdBwdClauses : ℕ → List (InternalField × ℕ) → List (R.Name × R.Term)
fwdBwdClauses k [] = []
fwdBwdClauses k ((inl f , n) ∷ fs) =
fwdBwdClauses k fs
∷ʳ (f .sfield , fwdBwdDatum (makeVarsFrom k) (v 1) (v 0) (map-snd (4 + k +_) (f , n)))
fwdBwdClauses k ((inr p , n) ∷ fs) =
fwdBwdClauses k fs
∷ʳ ((p .sfield , fwdBwdProperty (makeVarsFrom k) (v 1) (v 0) prevPath (map-snd (4 + k +_) (p , n))))
where
prevPath =
vlam "j"
(vlam "i"
(List.foldl
(λ t (_ , t') → R.con (quote _,_) (t v∷ t' v∷ []))
(R.con (quote tt) [])
(fwdBwdClauses (2 + k) fs)))
body = List.map (λ (n , t) → R.clause [] [ varg (R.proj n) ] t) (fwdBwdClauses 2 fields)
bwdFwd : R.Term
bwdFwd =
vlam "A" (vlam "B" (vlam "e" (vlam "streq" (vlam "j" (R.pat-lam (bwdFwdClauses fields) [])))))
where
bwdFwdClauses : List (InternalField × ℕ) → List R.Clause
bwdFwdClauses [] = []
bwdFwdClauses ((inl f , n) ∷ fs) =
bwdFwdClauses fs
∷ʳ bwdFwdClause (makeVarsFrom 1) (v 0) (map-snd (5 +_) (f , n))
bwdFwdClauses ((inr _ , n) ∷ fs) = bwdFwdClauses fs
univalentRecord : R.Term
univalentRecord =
R.def (quote explicitUnivalentStr)
(R.unknown v∷ R.unknown v∷ fwd v∷ bwd v∷ fwdBwd v∷ bwdFwd v∷ [])
macro
autoFieldEquiv : R.Term → R.Term → R.Term → R.Term → R.TC Unit
autoFieldEquiv spec A B hole =
(R.reduce spec >>= parseFieldSpec) >>= λ (ℓ , ℓ₂ , S , f) →
buildDesc FUEL ℓ ℓ₂ S >>= λ d →
R.unify hole (R.def (quote M.MacroEquivStr) (d v∷ tStrMap A f v∷ tStrMap B f v∷ []))
autoUnivalentRecord : R.Term → R.Term → R.TC Unit
autoUnivalentRecord t hole =
(R.reduce t >>= parseSpec) >>= λ spec →
-- R.typeError (R.strErr "WOW: " ∷ R.termErr (main spec) ∷ [])
R.unify (main spec) hole
where
module _ (spec : InternalSpec TypedTerm) where
open InternalSpec spec
mapUp : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} → (ℕ → A → B) → ℕ → List A → List B
mapUp f _ [] = []
mapUp f n (x ∷ xs) = f n x ∷ mapUp f (suc n) xs
closureSpec : InternalSpec ℕ
closureSpec .InternalSpec.srec = srec
closureSpec .InternalSpec.erec = erec
closureSpec .InternalSpec.fields = mapUp (λ n → map-snd (λ _ → n)) 0 fields
closure : R.Term
closure =
iter (List.length fields) (vlam "") (univalentRecord closureSpec)
env : List (R.Arg R.Term)
env = List.map (varg ∘ term ∘ snd) (List.rev fields)
closureTy : R.Term
closureTy =
List.foldr
(λ ty cod → R.def (quote Fun) (ty v∷ cod v∷ []))
(R.def (quote ExplicitUnivalentStr) (srec v∷ erec v∷ []))
(List.map (type ∘ snd) (List.rev fields))
main : R.Term
main = R.def (quote idfun) (closureTy v∷ closure v∷ env)
| {
"alphanum_fraction": 0.568551279,
"avg_line_length": 36.8546255507,
"ext": "agda",
"hexsha": "edec938d96f2342073ccff70b3faac862245f2aa",
"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": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Schippmunk/cubical",
"max_forks_repo_path": "Cubical/Structures/Record.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Schippmunk/cubical",
"max_issues_repo_path": "Cubical/Structures/Record.agda",
"max_line_length": 108,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Schippmunk/cubical",
"max_stars_repo_path": "Cubical/Structures/Record.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6100,
"size": 16732
} |
module Record where
module M where
record A
: Set
where
constructor
a
open M
record B
: Set
where
record C
: Set
where
constructor
c
x
: A
x
= a
y
: C
y
= record {}
record D
(E : Set)
: Set
where
record F
: Set₁
where
field
G
: Set
z
: G
| {
"alphanum_fraction": 0.4835820896,
"avg_line_length": 6.2037037037,
"ext": "agda",
"hexsha": "d4db21321510b92325d5e75c2ca1410237953daa",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-01T16:38:14.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-01T16:38:14.000Z",
"max_forks_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "msuperdock/agda-unused",
"max_forks_repo_path": "data/declaration/Record.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9",
"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": "msuperdock/agda-unused",
"max_issues_repo_path": "data/declaration/Record.agda",
"max_line_length": 19,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "f327f9aab8dcb07022b857736d8201906bba02e9",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "msuperdock/agda-unused",
"max_stars_repo_path": "data/declaration/Record.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-01T16:38:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-29T09:38:43.000Z",
"num_tokens": 122,
"size": 335
} |
{-# OPTIONS --cubical --safe #-}
module JustBeInjective where
open import Cubical.Core.Everything
open import Cubical.Data.Unit
data maybe (A : Set) : Set where
just : A -> maybe A
nothing : maybe A
variable A : Set
unwrap : A → (a : maybe A) → A
unwrap _ (just x) = x
unwrap a nothing = a
just-injective : ∀ {A : Set} (a b : A) → just a ≡ just b → a ≡ b
just-injective a b p i = unwrap a (p i)
| {
"alphanum_fraction": 0.6401985112,
"avg_line_length": 22.3888888889,
"ext": "agda",
"hexsha": "da91190350526ff4406160cb94884e26bc1d10dd",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-12-13T04:50:46.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-12-13T04:50:46.000Z",
"max_forks_repo_head_hexsha": "eb2cef0556efb9a4ce11783f8516789ea48cc344",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Brethland/LEARNING-STUFF",
"max_forks_repo_path": "Agda/JustBeInjective.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "eb2cef0556efb9a4ce11783f8516789ea48cc344",
"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": "Brethland/LEARNING-STUFF",
"max_issues_repo_path": "Agda/JustBeInjective.agda",
"max_line_length": 64,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "eb2cef0556efb9a4ce11783f8516789ea48cc344",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Brethland/LEARNING-STUFF",
"max_stars_repo_path": "Agda/JustBeInjective.agda",
"max_stars_repo_stars_event_max_datetime": "2020-03-11T10:35:42.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-02-03T05:05:52.000Z",
"num_tokens": 133,
"size": 403
} |
{-# OPTIONS --cubical #-}
module LaterPrims where
open import Agda.Primitive
open import Agda.Primitive.Cubical renaming (itIsOne to 1=1)
open import Agda.Builtin.Cubical.Path
open import Agda.Builtin.Cubical.Sub renaming (Sub to _[_↦_]; primSubOut to outS)
module Prims where
primitive
primLockUniv : Set₁
open Prims renaming (primLockUniv to LockU) public
private
variable
l : Level
A B : Set l
-- We postulate Tick as it is supposed to be an abstract sort.
postulate
Tick : LockU
▹_ : ∀ {l} → Set l → Set l
▹_ A = (@tick x : Tick) -> A
▸_ : ∀ {l} → ▹ Set l → Set l
▸ A = (@tick x : Tick) → A x
next : A → ▹ A
next x _ = x
_⊛_ : ▹ (A → B) → ▹ A → ▹ B
_⊛_ f x a = f a (x a)
map▹ : (f : A → B) → ▹ A → ▹ B
map▹ f x α = f (x α)
transpLater : ∀ (A : I → ▹ Set) → ▸ (A i0) → ▸ (A i1)
transpLater A u0 a = primTransp (\ i → A i a) i0 (u0 a)
transpLater-prim : (A : I → ▹ Set) → (x : ▸ (A i0)) → ▸ (A i1)
transpLater-prim A x = primTransp (\ i → ▸ (A i)) i0 x
transpLater-test : ∀ (A : I → ▹ Set) → (x : ▸ (A i0)) → transpLater-prim A x ≡ transpLater A x
transpLater-test A x = \ _ → transpLater-prim A x
hcompLater-prim : ∀ (A : ▹ Set) φ (u : I → Partial φ (▸ A)) → (u0 : (▸ A) [ φ ↦ u i0 ]) → ▸ A
hcompLater-prim A φ u u0 a = primHComp (\ { i (φ = i1) → u i 1=1 a }) (outS u0 a)
hcompLater : ∀ (A : ▹ Set) φ (u : I → Partial φ (▸ A)) → (u0 : (▸ A) [ φ ↦ u i0 ]) → ▸ A
hcompLater A φ u u0 = primHComp (\ { i (φ = i1) → u i 1=1 }) (outS u0)
hcompLater-test : ∀ (A : ▹ Set) φ (u : I → Partial φ (▸ A)) → (u0 : (▸ A) [ φ ↦ u i0 ]) → hcompLater A φ u u0 ≡ hcompLater-prim A φ u u0
hcompLater-test A φ u x = \ _ → hcompLater-prim A φ u x
ap : ∀ {A B : Set} (f : A → B) → ∀ {x y} → x ≡ y → f x ≡ f y
ap f eq = \ i → f (eq i)
_$>_ : ∀ {A B : Set} {f g : A → B} → f ≡ g → ∀ x → f x ≡ g x
eq $> x = \ i → eq i x
later-ext : ∀ {A : Set} → {f g : ▹ A} → (▸ \ α → f α ≡ g α) → f ≡ g
later-ext eq = \ i α → eq α i
postulate
dfix : ∀ {l} {A : Set l} → (▹ A → A) → ▹ A
pfix : ∀ {l} {A : Set l} (f : ▹ A → A) → dfix f ≡ (\ _ → f (dfix f))
pfix' : ∀ {l} {A : Set l} (f : ▹ A → A) → ▸ \ α → dfix f α ≡ f (dfix f)
pfix' f α i = pfix f i α
fix : ∀ {l} {A : Set l} → (▹ A → A) → A
fix f = f (dfix f)
data gStream (A : Set) : Set where
cons : (x : A) (xs : ▹ gStream A) → gStream A
repeat : ∀ {A : Set} → A → gStream A
repeat a = fix \ repeat▹ → cons a repeat▹
repeat-eq : ∀ {A : Set} (a : A) → repeat a ≡ cons a (\ α → repeat a)
repeat-eq a = ap (cons a) (pfix (cons a))
map : ∀ {A B : Set} → (A → B) → gStream A → gStream B
map f = fix \ map▹ → \ { (cons a as) → cons (f a) \ α → map▹ α (as α) }
map-eq : ∀ {A B : Set} → (f : A → B) → ∀ a as → map f (cons a as) ≡ cons (f a) (\ α → map f (as α))
map-eq f a b = ap (cons _) (later-ext \ α → pfix' _ α $> b α)
_∙_ : ∀ {A : Set} {x y z : A} → x ≡ y → y ≡ z → x ≡ z
_∙_ {x = x} p q i = primHComp (\ j → \ { (i = i0) → x; (i = i1) → q j}) (p i)
map-repeat : ∀ {A B : Set} → (a : A) → (f : A → B) → map f (repeat a) ≡ repeat (f a)
map-repeat a f = fix \ prf▹ → ap (map f) (repeat-eq a) ∙ (map-eq f a _ ∙ ap (cons (f a)) (later-ext prf▹ ∙ later-ext \ α → \ i → pfix' (cons (f a)) α (primINeg i) ))
| {
"alphanum_fraction": 0.500630517,
"avg_line_length": 32.3673469388,
"ext": "agda",
"hexsha": "fc209f506b36c7cc9763ae06ed156c7b1bd9f4b0",
"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": "02fe8918eb5c22bf75de040a4952c148858badb0",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "rwe/agda",
"max_forks_repo_path": "test/Succeed/LaterPrims.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "02fe8918eb5c22bf75de040a4952c148858badb0",
"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": "rwe/agda",
"max_issues_repo_path": "test/Succeed/LaterPrims.agda",
"max_line_length": 165,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "02fe8918eb5c22bf75de040a4952c148858badb0",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "rwe/agda",
"max_stars_repo_path": "test/Succeed/LaterPrims.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1457,
"size": 3172
} |
module 120-natural-induction-necessary where
open import 010-false-true
open import 020-equivalence
open import 100-natural
-- We prove that the induction axiom is necessary.
-- Peano axioms without induction.
record NaturalWithoutInduction
{M : Set}
(zero : M)
(suc : M -> M)
(_==_ : M -> M -> Set)
: Set1 where
-- axioms
field
equiv : Equivalence _==_
sucn!=zero : ∀ {r} -> suc r == zero -> False
sucinjective : ∀ {r s} -> suc r == suc s -> r == s
cong : ∀ {r s} -> r == s -> suc r == suc s
not-induction :
((p : M -> Set) -> p zero -> (∀ n -> p n -> p (suc n)) -> ∀ n -> p n)
-> False
open Equivalence equiv public
-- Construct a model, and prove it satisfies NaturalWithoutInduction
-- but not Natural. To do this, we add an extra zero.
data M : Set where
zero1 : M
zero2 : M
suc : M -> M
thm-M-is-natural-without-induction : NaturalWithoutInduction zero1 suc _≡_
thm-M-is-natural-without-induction = record {
equiv = thm-≡-is-equivalence;
sucn!=zero = sucn!=zero;
sucinjective = sucinjective;
cong = cong;
not-induction = not-induction
}
where
sucn!=zero : ∀ {r} -> suc r ≡ zero1 -> False
sucn!=zero ()
sucinjective : ∀ {r s} -> suc r ≡ suc s -> r ≡ s
sucinjective refl = refl
cong : ∀ {r s} -> r ≡ s -> suc r ≡ suc s
cong refl = refl
-- To prove that induction fails, we test the property "is a
-- successor of zero1 but not of zero2". This holds for zero1 (the
-- base case), and it also holds for every successor of n if it
-- holds for n, but it does not hold for zero2 (or for any of its
-- successors).
not-induction :
((p : M -> Set) -> p zero1 -> (∀ n -> p n -> p (suc n)) -> ∀ n -> p n)
-> False
not-induction induction = induction p base hypothesis zero2
where
-- Property "is a successor of zero1 but not a successor of zero2".
p : M -> Set
p zero1 = True -- true for zero1
p zero2 = False -- false (no proof) for zero2
p (suc n) = p n -- true for successor of n if and only if true for n
-- Base case is trivial.
base : p zero1
base = trivial
-- Induction hypothesis follows by application of "p n" itself
-- due to the recursive definition of p.
hypothesis : ∀ n -> p n -> p (suc n)
hypothesis n pn = pn
-- To round this off, we explicitly prove that M is not natural.
thm-M-is-not-natural : (Natural zero1 suc _≡_) -> False
thm-M-is-not-natural nat =
(NaturalWithoutInduction.not-induction thm-M-is-natural-without-induction)
(Natural.induction nat)
| {
"alphanum_fraction": 0.60587562,
"avg_line_length": 31.2023809524,
"ext": "agda",
"hexsha": "b72c2a282d8c3756edf72c7976dd465722b9ef4b",
"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": "76fe404b25210258810641cc6807feecf0ff8d6c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mcmtroffaes/agda-proofs",
"max_forks_repo_path": "120-natural-induction-necessary.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "76fe404b25210258810641cc6807feecf0ff8d6c",
"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": "mcmtroffaes/agda-proofs",
"max_issues_repo_path": "120-natural-induction-necessary.agda",
"max_line_length": 76,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "76fe404b25210258810641cc6807feecf0ff8d6c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mcmtroffaes/agda-proofs",
"max_stars_repo_path": "120-natural-induction-necessary.agda",
"max_stars_repo_stars_event_max_datetime": "2016-08-17T16:15:42.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-09T22:51:55.000Z",
"num_tokens": 794,
"size": 2621
} |
module Issue468 where
data Unit : Set where
nothing : Unit
data Maybe (A : Set) : Set where
nothing : Maybe A
just : A → Maybe A
data P : (R : Set) → Maybe R → Set₁ where
p : (R : Set) (x : R) → P R (just x)
works : P Unit (just _)
works = p _ nothing
fails : Unit → P Unit (just _)
fails x = p _ nothing
| {
"alphanum_fraction": 0.6037735849,
"avg_line_length": 16.7368421053,
"ext": "agda",
"hexsha": "993b9cdfa40ea839c5270ea7bdb20510d0df9715",
"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/Issue468.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/Issue468.agda",
"max_line_length": 41,
"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/Issue468.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": 106,
"size": 318
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import Setoids.Setoids
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import Groups.Definition
open import Groups.Homomorphisms.Definition
module Groups.Isomorphisms.Definition where
record GroupIso {m n o p : _} {A : Set m} {S : Setoid {m} {o} A} {_·A_ : A → A → A} {B : Set n} {T : Setoid {n} {p} B} {_·B_ : B → B → B} (G : Group S _·A_) (H : Group T _·B_) (f : A → B) : Set (m ⊔ n ⊔ o ⊔ p) where
open Setoid S renaming (_∼_ to _∼G_)
open Setoid T renaming (_∼_ to _∼H_)
field
groupHom : GroupHom G H f
bij : SetoidBijection S T f
record GroupsIsomorphic {m n o p : _} {A : Set m} {S : Setoid {m} {o} A} {_·A_ : A → A → A} {B : Set n} {T : Setoid {n} {p} B} {_·B_ : B → B → B} (G : Group S _·A_) (H : Group T _·B_) : Set (m ⊔ n ⊔ o ⊔ p) where
field
isomorphism : A → B
proof : GroupIso G H isomorphism
| {
"alphanum_fraction": 0.5977900552,
"avg_line_length": 43.0952380952,
"ext": "agda",
"hexsha": "1a6ab397a1ed9add09e18c6947fbc8cfe6050ef3",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Groups/Isomorphisms/Definition.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Groups/Isomorphisms/Definition.agda",
"max_line_length": 215,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Groups/Isomorphisms/Definition.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": 365,
"size": 905
} |
module Lib.Vec where
open import Lib.Prelude
open import Lib.Nat
open import Lib.Fin
infixr 40 _::_ _++_
data Vec (A : Set) : Nat -> Set where
[] : Vec A 0
_::_ : forall {n} -> A -> Vec A n -> Vec A (suc n)
_++_ : {A : Set}{n m : Nat} -> Vec A n -> Vec A m -> Vec A (n + m)
[] ++ ys = ys
(x :: xs) ++ ys = x :: xs ++ ys
_!_ : forall {A n} -> Vec A n -> Fin n -> A
[] ! ()
x :: xs ! zero = x
x :: xs ! suc i = xs ! i
tabulate : forall {A n} -> (Fin n -> A) -> Vec A n
tabulate {n = zero} f = []
tabulate {n = suc n} f = f zero :: tabulate (f ∘ suc)
vec : forall {A n} -> A -> Vec A n
vec x = tabulate (\_ -> x)
infixl 30 _<*>_
_<*>_ : forall {A B n} -> Vec (A -> B) n -> Vec A n -> Vec B n
[] <*> [] = []
f :: fs <*> x :: xs = f x :: (fs <*> xs)
map : forall {A B n} -> (A -> B) -> Vec A n -> Vec B n
map f xs = vec f <*> xs
zip : forall {A B C n} -> (A -> B -> C) -> Vec A n -> Vec B n -> Vec C n
zip f xs ys = vec f <*> xs <*> ys
| {
"alphanum_fraction": 0.4563206578,
"avg_line_length": 23.7317073171,
"ext": "agda",
"hexsha": "6394315f305aacf874d571d51830f603f1209c13",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "examples/simple-lib/Lib/Vec.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "examples/simple-lib/Lib/Vec.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "examples/simple-lib/Lib/Vec.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 381,
"size": 973
} |
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommRing.Instances.Unit where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Unit
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
private
variable
ℓ : Level
open CommRingStr
UnitCommRing : ∀ {ℓ} → CommRing ℓ
fst UnitCommRing = Unit*
0r (snd UnitCommRing) = tt*
1r (snd UnitCommRing) = tt*
_+_ (snd UnitCommRing) = λ _ _ → tt*
_·_ (snd UnitCommRing) = λ _ _ → tt*
- snd UnitCommRing = λ _ → tt*
isCommRing (snd UnitCommRing) =
makeIsCommRing isSetUnit* (λ _ _ _ → refl) (λ { tt* → refl }) (λ _ → refl)
(λ _ _ → refl) (λ _ _ _ → refl) (λ { tt* → refl })
(λ _ _ _ → refl) (λ _ _ → refl)
| {
"alphanum_fraction": 0.6420612813,
"avg_line_length": 25.6428571429,
"ext": "agda",
"hexsha": "3a9e6a3685850f03af509c116f8290679aa860d9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Algebra/CommRing/Instances/Unit.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Algebra/CommRing/Instances/Unit.agda",
"max_line_length": 76,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Algebra/CommRing/Instances/Unit.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": 235,
"size": 718
} |
module Prelude.String where
open import Prelude.Bool
open import Prelude.Char
open import Prelude.List
open import Prelude.Nat
postulate
String : Set
nil : String
primStringToNat : String → Nat
charToString : Char -> String
{-# BUILTIN STRING String #-}
primitive
primStringAppend : String → String → String
primStringToList : String → List Char
primStringFromList : List Char → String
primStringEquality : String → String → Bool
{-# COMPILED_EPIC nil () -> String = "" #-}
{-# COMPILED_EPIC primStringToNat (s : String) -> BigInt = foreign BigInt "strToBigInt" (s : String) #-}
-- {-# COMPILED_EPIC charToString (c : Int) -> String = charToString(c) #-}
strEq : (x y : String) -> Bool
strEq = primStringEquality
infixr 30 _+S+_
_+S+_ : (x y : String) -> String
_+S+_ = primStringAppend
fromList : List Char -> String
fromList = primStringFromList
fromString : String -> List Char
fromString = primStringToList
| {
"alphanum_fraction": 0.7066950053,
"avg_line_length": 24.1282051282,
"ext": "agda",
"hexsha": "b47024c9c43f630b6a9d3222debac749d6929801",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/epic/Prelude/String.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/epic/Prelude/String.agda",
"max_line_length": 104,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/epic/Prelude/String.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 260,
"size": 941
} |
module Everything where
import Library
import Syntax
import RenamingAndSubstitution
import EquationalTheory
| {
"alphanum_fraction": 0.8899082569,
"avg_line_length": 15.5714285714,
"ext": "agda",
"hexsha": "34c9b1ec61af6d818bff3c0ecf23627d9682e0dd",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2018-02-23T18:22:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-11-10T16:44:52.000Z",
"max_forks_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "ryanakca/strong-normalization",
"max_forks_repo_path": "agda/Everything.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2",
"max_issues_repo_issues_event_max_datetime": "2018-02-20T14:54:18.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-02-14T16:42:36.000Z",
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "ryanakca/strong-normalization",
"max_issues_repo_path": "agda/Everything.agda",
"max_line_length": 30,
"max_stars_count": 32,
"max_stars_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "ryanakca/strong-normalization",
"max_stars_repo_path": "agda/Everything.agda",
"max_stars_repo_stars_event_max_datetime": "2021-03-05T12:12:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-05-22T14:33:27.000Z",
"num_tokens": 22,
"size": 109
} |
-- TODO: Unfinished
open import Logic
open import Type
open import Structure.Relator
open import Structure.Setoid
module Geometry.HilbertAxioms
{ℓₚ ℓₗ ℓₚₑ ℓₗₑ ℓₚₗ ℓₚₚₚ}
(Point : Type{ℓₚ}) ⦃ equiv-point : Equiv{ℓₚₑ}(Point) ⦄ -- The type of points on a plane.
(Line : Type{ℓₗ}) ⦃ equiv-line : Equiv{ℓₗₑ}(Line) ⦄ -- The type of lines on a plane.
(Distance : Type{ℓₗ}) ⦃ equiv-distance : Equiv{ℓₗₑ}(Distance) ⦄
(Angle : Type{ℓₗ}) ⦃ equiv-angle : Equiv{ℓₗₑ}(Angle) ⦄
(_∈ₚₗ_ : Point → Line → Stmt{ℓₚₗ}) -- `p ∈ₚₗ l` means that the point `p` lies on the line `l`.
(_―_―_ : Point → Point → Point → Stmt{ℓₚₚₚ}) -- `p₁ ― p₂ ― p₃` means that the second point `p₂` lies between `p₁` and `p₃` in some line.
⦃ incidence-relator : BinaryRelator(_∈ₚₗ_) ⦄
⦃ betweenness-relator : TrinaryRelator(_―_―_) ⦄
where
open import Data.Tuple as Tuple using (_⨯_ ; _,_)
open import Functional
open import Functional.Combinations
import Lvl
open import Logic.Predicate
open import Logic.Propositional
open import Logic.Propositional.Xor
open import Sets.ExtensionalPredicateSet renaming (_≡_ to _≡ₛ_)
open import Structure.Relator.Properties
open import Structure.Setoid.Uniqueness
open import Syntax.Function
private variable p p₁ p₂ p₃ p₄ q q₁ q₂ q₃ q₄ : Point
private variable l l₁ l₂ : Line
module _ where
-- An open line segment.
-- The set of points strictly between two points in a line.
-- Also called:
-- • Open interval in A Minimal Version of Hilbert's Axioms for Plane Geometry by William Richter.
betweens : Point → Point → PredSet(Point)
betweens a b ∋ p = a ― p ― b
PredSet.preserve-equiv (betweens a b) = TrinaryRelator.unary₂ betweenness-relator
extensionPoints : Point → Point → PredSet(Point)
extensionPoints a b ∋ p = a ― b ― p
PredSet.preserve-equiv (extensionPoints a b) = TrinaryRelator.unary₃ betweenness-relator
-- A line segment.
-- The set of points between two points in a line including the endpoints.
segment : Point → Point → PredSet(Point)
segment a b = (• a) ∪ (• b) ∪ (betweens a b)
-- A ray.
-- The set of points between starting from `a` in the direction of `b` in a line.
ray : Point → Point → PredSet(Point)
ray a b = (• a) ∪ (• b) ∪ (extensionPoints a b)
angle : Point → Point → Point → PredSet(PredSet(Point))
angle p₁ p₂ p₃ = (• ray p₁ p₂) ∪ (• ray p₁ p₃)
Distinct₃ : Point → Point → Point → Stmt
Distinct₃ = combine₃Fn₂Op₂(_≢_)(_∧_)
Collinear₃ : Point → Point → Point → Stmt
Collinear₃ p₁ p₂ p₃ = ∃(l ↦ all₃Fn₁Op₂(_∈ₚₗ l)(_∧_) p₁ p₂ p₃)
record Axioms : Type{ℓₚ Lvl.⊔ ℓₗ Lvl.⊔ ℓₚₑ Lvl.⊔ ℓₗₑ Lvl.⊔ ℓₚₗ Lvl.⊔ ℓₚₚₚ} where
field
-- There is an unique line for every unordered distinct pair of points.
-- Also called:
-- • I1 in Hilbert’s Axiom System for Plane Geometry, A Short Introduction by Bjørn Jahren.
-- • I.1 and I.2 in Project Gutenberg’s The Foundations of Geometry by David Hilbert.
-- • I1 in A Minimal Version of Hilbert's Axioms for Plane Geometry by William Richter.
line-construction : (p₁ ≢ p₂) → ∃!(l ↦ (p₁ ∈ₚₗ l) ∧ (p₂ ∈ₚₗ l))
-- There are two distinct points on every line.
-- Also called:
-- • I2 in Hilbert’s Axiom System for Plane Geometry, A Short Introduction by Bjørn Jahren.
-- • I.7 in Project Gutenberg’s The Foundations of Geometry by David Hilbert.
-- • I2 in A Minimal Version of Hilbert's Axioms for Plane Geometry by William Richter.
line-deconstruction : ∃{Obj = Point ⨯ Point}(\{(p₁ , p₂) → (p₁ ≢ p₂) ∧ (p₁ ∈ₚₗ l) ∧ (p₂ ∈ₚₗ l)})
-- There exists three points that constructs a triangle (not all on the same line).
-- • I3 in Hilbert’s Axiom System for Plane Geometry, A Short Introduction by Bjørn Jahren.
-- • I3 in A Minimal Version of Hilbert's Axioms for Plane Geometry by William Richter.
triangle-existence : ∃{Obj = Point ⨯ Point ⨯ Point}(\{(p₁ , p₂ , p₃) → ¬(Collinear₃ p₁ p₂ p₃)})
-- The betweenness relation is strict (pairwise irreflexive).
-- There are no points between a single point.
betweenness-strictness : ¬(p₁ ― p₂ ― p₁)
-- The betweenness relation is symmetric.
-- Also called:
-- • B1 in Hilbert’s Axiom System for Plane Geometry, A Short Introduction by Bjørn Jahren.
-- • II.1 in Project Gutenberg’s The Foundations of Geometry by David Hilbert.
-- • B1 in A Minimal Version of Hilbert's Axioms for Plane Geometry by William Richter.
betweenness-symmetry : (p₁ ― p₂ ― p₃) → (p₃ ― p₂ ― p₁)
-- A line segment can be extended to a third point.
-- • Part of II.2 in Project Gutenberg’s The Foundations of Geometry by David Hilbert.
-- • B2 in Hilbert’s Axiom System for Plane Geometry, A Short Introduction by Bjørn Jahren.
-- • B2 in A Minimal Version of Hilbert's Axioms for Plane Geometry by William Richter.
betweenness-extensionᵣ : (p₁ ≢ p₂) → ∃(p₃ ↦ (p₁ ― p₂ ― p₃))
-- Three points are always between each other in a certain order.
betweenness-antisymmetryₗ : (p₁ ― p₂ ― p₃) → (p₂ ― p₁ ― p₃) → ⊥
-- Three distinct points on a line are always between each other in a certain order.
-- Also called:
-- • Part of B3 in Hilbert’s Axiom System for Plane Geometry, A Short Introduction by Bjørn Jahren.
-- • Part of II.3 in Project Gutenberg’s The Foundations of Geometry by David Hilbert.
-- • Part of B3 in A Minimal Version of Hilbert's Axioms for Plane Geometry by William Richter.
betweenness-cases : (Distinct₃ p₁ p₂ p₃) → (Collinear₃ p₁ p₂ p₃) → (rotate₃Fn₃Op₂(_―_―_)(_∨_) p₁ p₂ p₃)
-- For three points that forms a triangle, and a line not intersecting the triangle's vertices, but intersecting one of its edges. Such a line intersects exactly one of the other edges of the triangle.
-- Also called:
-- • Pasch's axiom
-- • B4 in Hilbert’s Axiom System for Plane Geometry, A Short Introduction by Bjørn Jahren.
-- • II.5 in Project Gutenberg’s The Foundations of Geometry by David Hilbert.
-- • B4 in A Minimal Version of Hilbert's Axioms for Plane Geometry by William Richter.
line-triangle-intersection : ¬(Collinear₃ p₁ p₂ p₃) → (all₃Fn₁Op₂(¬_ ∘ (_∈ₚₗ l))(_∧_) p₁ p₂ p₃) → ((p ∈ₚₗ l) ∧ (p₁ ― p ― p₂)) → (∃(p ↦ (p ∈ₚₗ l) ∧ (p₁ ― p ― p₃)) ⊕ ∃(p ↦ (p ∈ₚₗ l) ∧ (p₂ ― p ― p₃)))
-- TODO: The rest of the axioms are not yet formulated because I am not sure what the best way to express them is
ray-segment : ∃!(p ↦ (p ∈ ray p₁ p₂) ∧ (segment q₁ q₂ ≡ₛ segment p₁ p))
segment-concat : (p₁ ― p₂ ― p₃) → (q₁ ― q₂ ― q₃) → (segment p₁ p₂ ≡ₛ segment q₁ q₂) → (segment p₂ p₃ ≡ₛ segment q₂ q₃) → (segment p₁ p₃ ≡ₛ segment q₁ q₃)
-- A pair of points constructs a line.
line : (a : Point) → (b : Point) → (a ≢ b) → Line
line a b nab = [∃!]-witness(line-construction nab)
-- A line can be deconstructed to two points.
linePoints : Line → (Point ⨯ Point)
linePoints l = [∃]-witness(line-deconstruction{l})
-- The point to the left in the construction of a line is in the line.
line-construction-pointₗ : (np12 : p₁ ≢ p₂) → (p₁ ∈ₚₗ line p₁ p₂ np12)
line-construction-pointₗ np12 = [∧]-elimₗ([∃!]-proof (line-construction np12))
-- The point to the right in the construction of a line is in the line.
line-construction-pointᵣ : (np12 : p₁ ≢ p₂) → (p₂ ∈ₚₗ line p₁ p₂ np12)
line-construction-pointᵣ np12 = [∧]-elimᵣ([∃!]-proof (line-construction np12))
-- Two lines having a pair of common points are the same line..
line-uniqueness : (p₁ ≢ p₂) → (p₁ ∈ₚₗ l₁) → (p₂ ∈ₚₗ l₁) → (p₁ ∈ₚₗ l₂) → (p₂ ∈ₚₗ l₂) → (l₁ ≡ l₂)
line-uniqueness np12 p1l1 p2l1 p1l2 p2l2 = [∃!]-uniqueness (line-construction np12) ([∧]-intro p1l1 p2l1) ([∧]-intro p1l2 p2l2)
-- The deconstructed points of a line are distinct.
linePoints-distinct : let (a , b) = linePoints(l) in (a ≢ b)
linePoints-distinct = [∧]-elimₗ([∧]-elimₗ([∃]-proof(line-deconstruction)))
-- The left deconstructed point of a line is in the line.
linePoints-pointₗ : Tuple.left(linePoints(l)) ∈ₚₗ l
linePoints-pointₗ = [∧]-elimᵣ([∧]-elimₗ([∃]-proof(line-deconstruction)))
-- The right deconstructed point of a line is in the line.
linePoints-pointᵣ : Tuple.right(linePoints(l)) ∈ₚₗ l
linePoints-pointᵣ = [∧]-elimᵣ([∃]-proof(line-deconstruction))
-- The line of the deconstructed points of a line is the same line.
line-linePoints-inverseᵣ : let (a , b) = linePoints(l) in (line a b linePoints-distinct ≡ l)
line-linePoints-inverseᵣ = line-uniqueness
linePoints-distinct (line-construction-pointₗ linePoints-distinct) (line-construction-pointᵣ linePoints-distinct) linePoints-pointₗ linePoints-pointᵣ
betweenness-antisymmetryᵣ : (p₁ ― p₂ ― p₃) → (p₁ ― p₃ ― p₂) → ⊥
betweenness-antisymmetryᵣ p123 p132 = betweenness-antisymmetryₗ (betweenness-symmetry p123) (betweenness-symmetry p132)
betweenness-irreflexivityₗ : ¬(p₁ ― p₁ ― p₂)
betweenness-irreflexivityₗ p112 = betweenness-antisymmetryₗ p112 p112
betweenness-irreflexivityᵣ : ¬(p₁ ― p₂ ― p₂)
betweenness-irreflexivityᵣ p122 = betweenness-irreflexivityₗ (betweenness-symmetry p122)
-- Also called:
-- • B1 in Hilbert’s Axiom System for Plane Geometry, A Short Introduction by Bjørn Jahren.
-- • B1 in A Minimal Version of Hilbert's Axioms for Plane Geometry by William Richter.
betweenness-distinct : (p₁ ― p₂ ― p₃) → (Distinct₃ p₁ p₂ p₃)
Tuple.left (betweenness-distinct p123) p12 = betweenness-irreflexivityₗ(substitute₃-unary₁(_―_―_) p12 p123)
Tuple.left (Tuple.right (betweenness-distinct p123)) p13 = betweenness-strictness(substitute₃-unary₁(_―_―_) p13 p123)
Tuple.right(Tuple.right (betweenness-distinct p123)) p23 = betweenness-irreflexivityᵣ(substitute₃-unary₂(_―_―_) p23 p123)
betweenness-extensionₗ : (p₂ ≢ p₃) → ∃(p₁ ↦ (p₁ ― p₂ ― p₃))
betweenness-extensionₗ np23 = [∃]-map-proof betweenness-symmetry (betweenness-extensionᵣ (np23 ∘ symmetry(_≡_)))
-- Three points are always between each other in a certain order.
-- Also called:
-- • B3 in Hilbert’s Axiom System for Plane Geometry, A Short Introduction by Bjørn Jahren.
-- • II.3 in Project Gutenberg’s The Foundations of Geometry by David Hilbert.
-- • B3 in A Minimal Version of Hilbert's Axioms for Plane Geometry by William Richter.
betweenness-distinct-cases : (Distinct₃ p₁ p₂ p₃) → (Collinear₃ p₁ p₂ p₃) → ((p₁ ― p₂ ― p₃) ⊕₃ (p₂ ― p₃ ― p₁) ⊕₃ (p₃ ― p₁ ― p₂))
betweenness-distinct-cases pd pl with betweenness-cases pd pl
... | [∨]-introₗ p123 = [⊕₃]-intro₁ p123 (betweenness-antisymmetryₗ (betweenness-symmetry p123)) (betweenness-antisymmetryᵣ (betweenness-symmetry p123))
... | [∨]-introᵣ ([∨]-introₗ p231) = [⊕₃]-intro₂ (betweenness-antisymmetryᵣ ((betweenness-symmetry p231))) p231 (betweenness-antisymmetryₗ ((betweenness-symmetry p231)))
... | [∨]-introᵣ ([∨]-introᵣ p312) = [⊕₃]-intro₃ (betweenness-antisymmetryₗ (betweenness-symmetry p312)) (betweenness-antisymmetryᵣ (betweenness-symmetry p312)) p312
--betweenness-between : (p₁ ≢ p₂) → (p₁ ∈ₚₗ l) → (p₂ ∈ₚₗ l) → ∃(p ↦ p₁ ― p ― p₂)
--betweenness-between np12 p1l p2l = {!!}
--betweenness-collinnear : (p₁ ― p₂ ― p₃) → (Collinear₃ p₁ p₂ p₃)
| {
"alphanum_fraction": 0.6823837,
"avg_line_length": 55.46,
"ext": "agda",
"hexsha": "a49d5abf493bd67a61e5b97af31aa24f7cd03c4f",
"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": "Geometry/HilbertAxioms.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": "Geometry/HilbertAxioms.agda",
"max_line_length": 205,
"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": "Geometry/HilbertAxioms.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": 3950,
"size": 11092
} |
{-# OPTIONS --sized-types #-}
module GiveSize where
postulate Size : Set
{-# BUILTIN SIZE Size #-}
id : Size → Size
id i = {!i!}
| {
"alphanum_fraction": 0.6183206107,
"avg_line_length": 14.5555555556,
"ext": "agda",
"hexsha": "2ae0553e83b96b713adde62418a827dc8237c7e4",
"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": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "np/agda-git-experiment",
"max_forks_repo_path": "test/interaction/GiveSize.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"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": "np/agda-git-experiment",
"max_issues_repo_path": "test/interaction/GiveSize.agda",
"max_line_length": 29,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "np/agda-git-experiment",
"max_stars_repo_path": "test/interaction/GiveSize.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 37,
"size": 131
} |
open import Formalization.PredicateLogic.Signature
module Formalization.PredicateLogic.Syntax.NegativeTranslations (𝔏 : Signature) where
open Signature(𝔏)
open import Data.ListSized
import Lvl
open import Formalization.PredicateLogic.Syntax (𝔏)
open import Functional using (_∘_ ; _∘₂_ ; swap)
open import Numeral.Finite
open import Numeral.Natural
open import Sets.PredicateSet using (PredSet)
open import Type
private variable ℓ : Lvl.Level
private variable args vars : ℕ
-- Also called: Gödel-Gentzen's negative translation.
-- 2.3.3
ggTrans : Formula(vars) → Formula(vars)
ggTrans (P $ x) = ¬¬(P $ x)
ggTrans ⊤ = ⊤
ggTrans ⊥ = ⊥
ggTrans (φ ∧ ψ) = (ggTrans φ) ∧ (ggTrans ψ)
ggTrans (φ ∨ ψ) = ¬(¬(ggTrans φ) ∧ ¬(ggTrans ψ))
ggTrans (φ ⟶ ψ) = (ggTrans φ) ⟶ (ggTrans ψ)
ggTrans (Ɐ φ) = Ɐ(ggTrans φ)
ggTrans (∃ φ) = ¬ Ɐ(¬(ggTrans φ))
-- Also called: Kolmogorov's negative translation.
-- 2.3.7A
koTrans : Formula(vars) → Formula(vars)
koTrans (P $ x) = ¬¬(P $ x)
koTrans ⊤ = ⊤
koTrans ⊥ = ⊥
koTrans (φ ∧ ψ) = ¬¬((koTrans φ) ∧ (koTrans ψ))
koTrans (φ ∨ ψ) = ¬¬((koTrans φ) ∨ (koTrans ψ))
koTrans (φ ⟶ ψ) = ¬¬((koTrans φ) ⟶ (koTrans ψ))
koTrans (Ɐ φ) = ¬¬ Ɐ(koTrans φ)
koTrans (∃ φ) = ¬¬ ∃(koTrans φ)
-- Also called: Kuroda's negative translation.
-- 2.3.7B
kuTrans : Formula(vars) → Formula(vars)
kuTrans (P $ x) = P $ x
kuTrans ⊤ = ⊤
kuTrans ⊥ = ⊥
kuTrans (φ ∧ ψ) = ((koTrans φ) ∧ (koTrans ψ))
kuTrans (φ ∨ ψ) = ((koTrans φ) ∨ (koTrans ψ))
kuTrans (φ ⟶ ψ) = ((koTrans φ) ⟶ (koTrans ψ))
kuTrans (Ɐ φ) = Ɐ(¬¬(koTrans φ))
kuTrans (∃ φ) = ∃(koTrans φ)
| {
"alphanum_fraction": 0.6288916563,
"avg_line_length": 30.3018867925,
"ext": "agda",
"hexsha": "152b54cda5eb7edcc26862aadbb58857ab2d4b99",
"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": "Formalization/PredicateLogic/Syntax/NegativeTranslations.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": "Formalization/PredicateLogic/Syntax/NegativeTranslations.agda",
"max_line_length": 85,
"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": "Formalization/PredicateLogic/Syntax/NegativeTranslations.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": 628,
"size": 1606
} |
module Lawvere where
open import Library
open import Data.Sum
open import Categories
open import Categories.Sets
open import Categories.Initial
open import Categories.PushOuts
open import Categories.Products hiding (_×_)
open import Categories.CoProducts
open import Categories.Terminal
open import Functors
open import Functors.Fin
record Lawvere {a}{b} : Set (lsuc (a ⊔ b)) where
constructor lawvere
field T : Cat {a}{b}
L : Fun (Nats Op) T
L0 : Term T (Fun.OMap L zero)
LP : ∀ m n → Prod T (Fun.OMap L m) (Fun.OMap L n)
-- it's not the identity, it switches some implicit in fid and fcomp I think
FunOp : ∀{a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}} →
Fun C D → Fun (C Op) (D Op)
FunOp (functor OMap HMap fid fcomp) = functor OMap HMap fid fcomp
LSet : Lawvere
LSet = lawvere
(Sets Op)
(FunOp FinF)
(term (λ ()) (ext λ ()))
λ m n → prod
(Fin m ⊎ Fin n)
inj₁
inj₂
[_,_]′
refl
refl
λ p q → ext (λ{ (inj₁ a) -> fcong a p; (inj₂ b) -> fcong b q})
open import RMonads
open import RMonads.RKleisli
open import RMonads.RKleisli.Functors
lem : RMonad FinF → Lawvere {lzero}{lzero}
lem M = lawvere
(Kl M Op)
(FunOp (RKlL M) )
(term (λ ()) (ext λ ()))
λ m n → prod
(m + n)
(η ∘ extend)
(η ∘ lift m)
(case m)
(ext λ i → trans (fcong (extend i) law2) (lem1 m _ _ i))
(ext λ i → trans (fcong (lift m i) law2) (lem2 m _ _ i))
λ {o} {f} {g} {h} p q → ext (lem3
m
f
g
h
(trans (ext λ i → sym (fcong (extend i) law2)) p)
(trans (ext λ i → sym (fcong (lift m i) law2)) q))
where open RMonad M
lem-1 : Lawvere {lzero}{lzero} → RMonad FinF
lem-1 LT = rmonad
(λ n → Cat.Hom (Lawvere.T LT) (Fun.OMap (Lawvere.L LT) 1) (Fun.OMap (Lawvere.L LT) n))
{!!}
{!!}
{!!}
{!!}
{!!}
open import Categories.Products
record Model {a}{b}{c}{d} (Law : Lawvere {a}{b}) : Set (lsuc (a ⊔ b ⊔ c ⊔ d))
where
open Lawvere Law
field C : Cat {c}{d}
F : Fun T C
F0 : Term C (Fun.OMap F (Fun.OMap L zero))
FP : ∀ m n → Prod C (Fun.OMap F (Fun.OMap L m))
(Fun.OMap F (Fun.OMap L n))
open import RMonads.REM
open import RMonads.CatofRAdj.InitRAdj
open import RMonads.CatofRAdj.TermRAdjObj
open import RMonads.REM.Functors
model : (T : RMonad FinF) → Model (lem T)
model T = record {
C = EM T Op ;
F = FunOp (K' T (EMObj T));
F0 = term (λ{alg} → ralgmorph (RAlg.astr alg {0} (λ ()))
(λ {n}{f} →
sym $ RAlg.alaw2 alg {n}{zero}{f}{λ ()} ))
(λ{alg}{f} → RAlgMorphEq T (ext (λ t → trans
(trans (cong (λ f₁ → RAlg.astr alg f₁ t) (ext (λ ())))
(sym (fcong t (RAlgMorph.ahom f {0}{RMonad.η T}))))
(cong (RAlgMorph.amor f) (fcong t (RMonad.law1 T))))));
FP = λ m n → prod
(Fun.OMap (REML FinF T) (m + n) )
(Fun.HMap (REML FinF T) extend)
(Fun.HMap (REML FinF T) (lift m))
(λ{alg} f g → ralgmorph
(RAlg.astr alg
(case m (RAlgMorph.amor f ∘ RMonad.η T)
(RAlgMorph.amor g ∘ RMonad.η T)))
(sym (RAlg.alaw2 alg)))
(λ {alg}{f}{g} → RAlgMorphEq T (trans
(sym (RAlg.alaw2 alg))
(trans (cong (RAlg.astr alg)
(ext λ i → trans (fcong (extend i) (sym (RAlg.alaw1 alg)))
(lem1 m _ _ i)))
(trans (sym (RAlgMorph.ahom f))
(ext λ i → cong (RAlgMorph.amor f)
(fcong i (RMonad.law1 T)))))))
(λ {alg}{f}{g} → RAlgMorphEq T (trans
(sym (RAlg.alaw2 alg))
(trans (cong (RAlg.astr alg)
(ext λ i → trans (fcong (lift m i) (sym (RAlg.alaw1 alg)))
(lem2 m _ _ i)))
(trans (sym (RAlgMorph.ahom g))
(ext λ i → cong (RAlgMorph.amor g)
(fcong i (RMonad.law1 T)))))))
λ{alg}{f}{g}{h} p q → RAlgMorphEq T (trans
(trans (ext λ i → cong (RAlgMorph.amor h)
(sym (fcong i (RMonad.law1 T))))
(RAlgMorph.ahom h))
(cong (RAlg.astr alg) (ext (lem3
m
(RAlgMorph.amor f ∘ RMonad.η T)
(RAlgMorph.amor g ∘ RMonad.η T)
(RAlgMorph.amor h ∘ RMonad.η T)
(ext λ i → trans
(cong (RAlgMorph.amor h) (sym (fcong i (RMonad.law2 T))))
(fcong (RMonad.η T i) (cong RAlgMorph.amor p)))
(ext λ i → trans
(cong (RAlgMorph.amor h) (sym (fcong i (RMonad.law2 T))))
(fcong (RMonad.η T i) (cong RAlgMorph.amor q)))))))}
| {
"alphanum_fraction": 0.5220004293,
"avg_line_length": 32.5804195804,
"ext": "agda",
"hexsha": "425e108e66089088ba41b392350267cbe3faecd5",
"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": "Lawvere.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": "Lawvere.agda",
"max_line_length": 88,
"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": "Lawvere.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": 1701,
"size": 4659
} |
module UniDB.Subst.Core where
open import UniDB.Spec public
open import UniDB.Morph.Unit
record Ap (T X : STX) : Set₁ where
field
ap : {Ξ : MOR} {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}}
{γ₁ γ₂ : Dom} (ξ : Ξ γ₁ γ₂) (x : X γ₁) → X γ₂
open Ap {{...}} public
record ApVr (T : STX) {{vrT : Vr T}} {{apTT : Ap T T}} : Set₁ where
field
ap-vr :
{Ξ : MOR} {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}}
{γ₁ γ₂ : Dom} (ξ : Ξ γ₁ γ₂) →
(i : Ix γ₁) → ap {T} ξ (vr i) ≡ lk {T} ξ i
open ApVr {{...}} public
record LkCompAp
(T : STX) {{vrT : Vr T}} {{apTT : Ap T T}}
(Ξ : MOR) {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}} {{compΞ : Comp Ξ}} : Set₁ where
field
lk-⊙-ap : {γ₁ γ₂ γ₃ : Dom} (ξ₁ : Ξ γ₁ γ₂) (ξ₂ : Ξ γ₂ γ₃)
(i : Ix γ₁) → lk {T} (ξ₁ ⊙ ξ₂) i ≡ ap {T} ξ₂ (lk ξ₁ i)
open LkCompAp {{...}} public
record ApIdm
(T : STX) {{vrT : Vr T}}
(X : STX) {{apTX : Ap T X}} : Set₁ where
field
ap-idm :
{Ξ : MOR} {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}} {{idmΞ : Idm Ξ}}
{{lkIdmTΞ : LkIdm T Ξ}} {{upIdmΞ : UpIdm Ξ}}
{γ : Dom} (x : X γ) →
ap {T} (idm {Ξ} γ) x ≡ x
open ApIdm {{...}} public
record ApRel
(T : STX) {{vrT : Vr T}}
(X : STX) {{apTX : Ap T X}} : Set₁ where
field
ap-rel≅ :
{Ξ : MOR} {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}}
{Ζ : MOR} {{lkTΖ : Lk T Ζ}} {{upΖ : Up Ζ}}
{γ₁ γ₂ : Dom} {ξ : Ξ γ₁ γ₂} {ζ : Ζ γ₁ γ₂} (hyp : [ T ] ξ ≅ ζ)
(x : X γ₁) → ap {T} ξ x ≡ ap {T} ζ x
ap-rel≃ : {{wkT : Wk T}}
{Ξ : MOR} {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}} {{lkUpTΞ : LkUp T Ξ}}
{Ζ : MOR} {{lkTΖ : Lk T Ζ}} {{upΖ : Up Ζ}} {{lkUpTΖ : LkUp T Ζ}}
{γ₁ γ₂ : Dom} {ξ : Ξ γ₁ γ₂} {ζ : Ζ γ₁ γ₂} (hyp : [ T ] ξ ≃ ζ)
(x : X γ₁) → ap {T} ξ x ≡ ap {T} ζ x
ap-rel≃ hyp = ap-rel≅ (≃-to-≅` (≃-↑ hyp))
open ApRel {{...}} public
module _
(T : STX) {{vrT : Vr T}} {{wkT : Wk T}}
(X : STX) {{wkX : Wk X}} {{apTX : Ap T X}}
where
record ApWkmWk : Set₁ where
field
ap-wkm-wk₁ :
{Ξ : MOR} {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}} {{wkmΞ : Wkm Ξ}}
{{lkUpTΞ : LkUp T Ξ}} {{lkWkmTΞ : LkWkm T Ξ}}
{γ : Dom} (x : X γ) →
ap {T} (wkm {Ξ} 1) x ≡ wk₁ x
ap-wkm-wk :
{Ξ : MOR} {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}} {{wkmΞ : Wkm Ξ}}
{{lkUpTΞ : LkUp T Ξ}} {{lkWkmTΞ : LkWkm T Ξ}}
{γ : Dom} (δ : Dom) (x : X γ) →
ap {T} (wkm {Ξ} δ) x ≡ wk δ x
open ApWkmWk {{...}} public
module _
(T : STX) {{vrT : Vr T}} {{wkT : Wk T}}
(X : STX) {{wkX : Wk X}} {{apTX : Ap T X}}
where
record ApWk : Set₁ where
field
ap-wk₁ :
{Ξ : MOR} {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}}
{{lkUpTΞ : LkUp T Ξ}}
{γ₁ γ₂ : Dom} (ξ : Ξ γ₁ γ₂) (x : X γ₁) →
ap {T} (ξ ↑₁) (wk₁ x) ≡ wk₁ (ap {T} ξ x)
open ApWk {{...}} public
module _
(T : STX) {{vrT : Vr T}} {{wkT : Wk T}} {{apTT : Ap T T}}
(X : STX) {{apTX : Ap T X}}
where
record ApComp : Set₁ where
field
ap-⊙ :
{Ξ : MOR} {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}} {{compΞ : Comp Ξ}}
{{upCompΞ : UpComp Ξ}} {{lkCompTΞ : LkCompAp T Ξ}}
{γ₁ γ₂ γ₃ : Dom} (ξ₁ : Ξ γ₁ γ₂) (ξ₂ : Ξ γ₂ γ₃) →
(x : X γ₁) → ap {T} (ξ₁ ⊙ ξ₂) x ≡ ap {T} ξ₂ (ap {T} ξ₁ x)
open ApComp {{...}} public
instance
iApIx : Ap Ix Ix
ap {{iApIx}} = lk
iApVrIx : ApVr Ix
ap-vr {{iApVrIx}} ξ i = refl
iApIdmIxIx : ApIdm Ix Ix
ap-idm {{iApIdmIxIx}} {Ξ} = lk-idm {Ix} {Ξ}
iApWkmWkIxIx : ApWkmWk Ix Ix
ap-wkm-wk₁ {{iApWkmWkIxIx}} {Ξ} = lk-wkm {Ix} {Ξ} 1
ap-wkm-wk {{iApWkmWkIxIx}} {Ξ} = lk-wkm {Ix} {Ξ}
iApRelIxIx : ApRel Ix Ix
ap-rel≅ {{iApRelIxIx}} = lk≃ ∘ ≅-to-≃
iApWkIxIx : ApWk Ix Ix
ap-wk₁ {{iApWkIxIx}} {Ξ} ξ i = lk-↑₁-suc {Ix} {Ξ} ξ i
-- TODO: Remove
module _
(T : STX) {{vrT : Vr T}} {{apTT : Ap T T}}
(Ξ : MOR) {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}}
(Ζ : MOR) {{lkTΖ : Lk T Ζ}} {{upΖ : Up Ζ}}
(Θ : MOR) {{lkTΘ : Lk T Θ}} {{upΘ : Up Θ}}
{{hcompΞΖΘ : HComp Ξ Ζ Θ}}
where
record LkHCompAp : Set₁ where
field
lk-⊡-ap : {γ₁ γ₂ γ₃ : Dom} (ξ : Ξ γ₁ γ₂) (ζ : Ζ γ₂ γ₃)
(i : Ix γ₁) → lk {T} {Θ} (ξ ⊡ ζ) i ≡ ap {T} ζ (lk ξ i)
open LkHCompAp {{...}} public
-- TODO: Remove
module _
(T : STX) {{vrT : Vr T}} {{wkT : Wk T}} {{apTT : Ap T T}}
(X : STX) {{apTX : Ap T X}}
where
record ApHComp : Set₁ where
field
ap-⊡ :
{Ξ : MOR} {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}}
{Ζ : MOR} {{lkTΖ : Lk T Ζ}} {{upΖ : Up Ζ}}
{Θ : MOR} {{lkTΘ : Lk T Θ}} {{upΘ : Up Θ}}
{{hcompΞΖΘ : HComp Ξ Ζ Θ}} {{upHCompΞ : UpHComp Ξ Ζ Θ}}
{{lkHCompTΞΖΘ : LkHCompAp T Ξ Ζ Θ}}
{γ₁ γ₂ γ₃ : Dom} (ξ : Ξ γ₁ γ₂) (ζ : Ζ γ₂ γ₃) →
(x : X γ₁) → ap {T} {X} {Θ} (ξ ⊡ ζ) x ≡ ap {T} ζ (ap {T} ξ x)
open ApHComp {{...}} public
-- TODO: Move
module _
{T : STX} {{vrT : Vr T}} {{wkT : Wk T}} {{wkVrT : WkVr T}}
{X : STX} {{wkX : Wk X}} {{apTX : Ap T X}} {{apRelTX : ApRel T X}} {{apIdmTX : ApIdm T X}}
{Ξ : MOR} {{lkTΞ : Lk T Ξ}} {{upΞ : Up Ξ}} {{idmΞ : Idm Ξ}} {{lkIdmTΞ : LkIdm T Ξ}}
{{lkUpTΞ : LkUp T Ξ}}
where
ap-idm` : {γ : Dom} (x : X γ) → ap {T} (idm {Ξ} γ) x ≡ x
ap-idm` {γ} x = begin
ap {T} (idm {Ξ} γ) x ≡⟨ ap-rel≃ {T} lem x ⟩
ap {T} (idm {Unit} γ) x ≡⟨ ap-idm {T} x ⟩
x ∎
where
lem : [ T ] idm {Ξ} γ ≃ unit
lk≃ lem = lk-idm {T} {Ξ}
| {
"alphanum_fraction": 0.4548227221,
"avg_line_length": 29.9771428571,
"ext": "agda",
"hexsha": "2e1ad682f6e7bd17e316f0c45e921fd71093321d",
"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": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "skeuchel/unidb-agda",
"max_forks_repo_path": "UniDB/Subst/Core.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"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": "skeuchel/unidb-agda",
"max_issues_repo_path": "UniDB/Subst/Core.agda",
"max_line_length": 92,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "skeuchel/unidb-agda",
"max_stars_repo_path": "UniDB/Subst/Core.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2809,
"size": 5246
} |
{-# OPTIONS --allow-unsolved-metas #-}
infixr 6 _∷_
data List (A : Set) : Set where
[] : List A
_∷_ : A -> List A -> List A
postulate
Bool : Set
t : Bool
long : List Bool
long =
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷ t ∷
[]
meta : Set
meta = _
| {
"alphanum_fraction": 0.251088627,
"avg_line_length": 70.9818181818,
"ext": "agda",
"hexsha": "ca99b438d3dd6dde1059e52043cd97dee748e0fb",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/Issue1108.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/succeed/Issue1108.agda",
"max_line_length": 76,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "test/succeed/Issue1108.agda",
"max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z",
"num_tokens": 11678,
"size": 15616
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.ZCohomology.Groups.Unit where
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.Properties
open import Cubical.HITs.Sn
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.HITs.Susp
open import Cubical.HITs.SetTruncation renaming (rec to sRec ; elim to sElim ; elim2 to sElim2)
open import Cubical.HITs.PropositionalTruncation renaming (rec to pRec ; elim to pElim ; elim2 to pElim2 ; ∥_∥ to ∥_∥₋₁ ; ∣_∣ to ∣_∣₋₁)
open import Cubical.HITs.Nullification
open import Cubical.Data.Int hiding (_+_ ; +-comm)
open import Cubical.Data.Nat
open import Cubical.HITs.Truncation
open import Cubical.Homotopy.Connected
open import Cubical.Data.Unit
open import Cubical.Algebra.Group
-- H⁰(Unit)
open GroupHom
open GroupIso
private
H⁰-Unit≅ℤ' : GroupIso (coHomGr 0 Unit) intGroup
fun (GroupIso.map H⁰-Unit≅ℤ') = sRec isSetInt (λ f → f tt)
isHom (GroupIso.map H⁰-Unit≅ℤ') = sElim2 (λ _ _ → isOfHLevelPath 2 isSetInt _ _) λ a b → addLemma (a tt) (b tt)
inv H⁰-Unit≅ℤ' a = ∣ (λ _ → a) ∣₂
rightInv H⁰-Unit≅ℤ' _ = refl
leftInv H⁰-Unit≅ℤ' = sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ a → refl
H⁰-Unit≅ℤ : GroupEquiv (coHomGr 0 Unit) intGroup
H⁰-Unit≅ℤ = GrIsoToGrEquiv H⁰-Unit≅ℤ'
{- Hⁿ(Unit) for n ≥ 1 -}
isContrHⁿ-Unit : (n : ℕ) → isContr (coHom (suc n) Unit)
isContrHⁿ-Unit n = subst isContr (λ i → ∥ UnitToTypePath (coHomK (suc n)) (~ i) ∥₂) (helper' n)
where
helper' : (n : ℕ) → isContr (∥ coHomK (suc n) ∥₂)
helper' n =
subst isContr
((isoToPath (truncOfTruncIso {A = S₊ (1 + n)} 2 (1 + n)))
∙∙ sym propTrunc≡Trunc2
∙∙ λ i → ∥ hLevelTrunc (suc (+-comm n 2 i)) (S₊ (1 + n)) ∥₂)
(isConnectedSubtr 2 (helper2 n .fst)
(subst (λ x → isConnected x (S₊ (suc n))) (sym (helper2 n .snd)) (sphereConnected (suc n))) )
where
helper2 : (n : ℕ) → Σ[ m ∈ ℕ ] m + 2 ≡ 2 + n
helper2 zero = 0 , refl
helper2 (suc n) = (suc n) , λ i → suc (+-comm n 2 i)
Hⁿ-Unit≅0' : (n : ℕ) → GroupIso (coHomGr (suc n) Unit) trivialGroup
GroupHom.fun (GroupIso.map (Hⁿ-Unit≅0' n)) _ = _
GroupHom.isHom (GroupIso.map (Hⁿ-Unit≅0' n)) _ _ = refl
GroupIso.inv (Hⁿ-Unit≅0' n) _ = 0ₕ
GroupIso.rightInv (Hⁿ-Unit≅0' n) _ = refl
GroupIso.leftInv (Hⁿ-Unit≅0' n) _ = isOfHLevelSuc 0 (isContrHⁿ-Unit n) _ _
Hⁿ-Unit≅0 : (n : ℕ) → GroupEquiv (coHomGr (suc n) Unit) trivialGroup
Hⁿ-Unit≅0 n = GrIsoToGrEquiv (Hⁿ-Unit≅0' n)
{- Hⁿ for arbitrary contractible types -}
private
Hⁿ-contrTypeIso : ∀ {ℓ} {A : Type ℓ} (n : ℕ) → isContr A
→ Iso (coHom (suc n) A) (coHom (suc n) Unit)
Hⁿ-contrTypeIso n contr = compIso (setTruncIso (isContr→Iso2 contr))
(setTruncIso (invIso (isContr→Iso2 isContrUnit)))
Hⁿ-contrType≅0' : ∀ {ℓ} {A : Type ℓ} (n : ℕ) → isContr A
→ GroupIso (coHomGr (suc n) A) trivialGroup
fun (GroupIso.map (Hⁿ-contrType≅0' _ _)) _ = _
isHom (GroupIso.map (Hⁿ-contrType≅0' _ _)) _ _ = refl
inv (Hⁿ-contrType≅0' _ _) _ = 0ₕ
rightInv (Hⁿ-contrType≅0' _ _) _ = refl
leftInv (Hⁿ-contrType≅0' {A = A} n contr) _ = isOfHLevelSuc 0 helper _ _
where
helper : isContr (coHom (suc n) A)
helper = (Iso.inv (Hⁿ-contrTypeIso n contr) 0ₕ)
, λ y → cong (Iso.inv (Hⁿ-contrTypeIso n contr))
(isOfHLevelSuc 0 (isContrHⁿ-Unit n) 0ₕ (Iso.fun (Hⁿ-contrTypeIso n contr) y))
∙ Iso.leftInv (Hⁿ-contrTypeIso n contr) y
Hⁿ-contrType≅0 : ∀ {ℓ} {A : Type ℓ} (n : ℕ) → isContr A
→ GroupEquiv (coHomGr (suc n) A) trivialGroup
Hⁿ-contrType≅0 n contr = GrIsoToGrEquiv (Hⁿ-contrType≅0' n contr)
| {
"alphanum_fraction": 0.6415044012,
"avg_line_length": 43.5930232558,
"ext": "agda",
"hexsha": "f61572cbbd69dddca54b5fb3072481ddd594619a",
"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": "f6771617374bfe65a7043d00731fed5a673aa729",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "knrafto/cubical",
"max_forks_repo_path": "Cubical/ZCohomology/Groups/Unit.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f6771617374bfe65a7043d00731fed5a673aa729",
"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": "knrafto/cubical",
"max_issues_repo_path": "Cubical/ZCohomology/Groups/Unit.agda",
"max_line_length": 135,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f6771617374bfe65a7043d00731fed5a673aa729",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "knrafto/cubical",
"max_stars_repo_path": "Cubical/ZCohomology/Groups/Unit.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1545,
"size": 3749
} |
{-# OPTIONS --safe #-}
module Cubical.Algebra.AbGroup.Instances.FreeAbGroup where
open import Cubical.Foundations.Prelude
open import Cubical.HITs.FreeAbGroup
open import Cubical.Algebra.AbGroup
private variable
ℓ : Level
module _ {A : Type ℓ} where
FAGAbGroup : AbGroup ℓ
FAGAbGroup = makeAbGroup {G = FreeAbGroup A} ε _·_ _⁻¹ trunc assoc identityᵣ invᵣ comm
| {
"alphanum_fraction": 0.7675675676,
"avg_line_length": 24.6666666667,
"ext": "agda",
"hexsha": "1ddc12a1df5316a88b7ab6647a0b9d7a0119431b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Algebra/AbGroup/Instances/FreeAbGroup.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Algebra/AbGroup/Instances/FreeAbGroup.agda",
"max_line_length": 88,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Algebra/AbGroup/Instances/FreeAbGroup.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": 115,
"size": 370
} |
module Data.Collection where
open import Data.Collection.Core public
open import Data.Collection.Equivalence
open import Data.Collection.Inclusion
open import Relation.Nullary
--------------------------------------------------------------------------------
-- Singleton
--------------------------------------------------------------------------------
singleton : String → Collection
singleton x = x ∷ []
--------------------------------------------------------------------------------
-- Delete
--------------------------------------------------------------------------------
delete : String → Collection → Collection
delete x [] = []
delete x (a ∷ A) with x ≟ a
delete x (a ∷ A) | yes p = delete x A -- keep deleting, because there might be many of them
delete x (a ∷ A) | no ¬p = a ∷ delete x A
--------------------------------------------------------------------------------
-- Union
--------------------------------------------------------------------------------
union : Collection → Collection → Collection
union [] B = B
union (a ∷ A) B with a ∈? B
union (a ∷ A) B | yes p = union A B
union (a ∷ A) B | no ¬p = a ∷ union A B
--
-- open import Data.List
-- open import Data.String hiding (setoid)
-- open import Data.List using ([]; _∷_) public
-- open import Data.Product
-- open import Data.Sum renaming (map to mapSum)
-- -- open import Data.Bool using (Bool; true; false; T; not)
-- open import Level renaming (zero to lvl0)
-- open import Function using (_∘_; id; flip; _on_)
-- open import Function.Equivalence using (_⇔_; Equivalence; equivalence)
--
-- open import Function.Equality using (_⟨$⟩_) renaming (cong to cong≈)
-- open import Relation.Nullary
-- open import Relation.Unary
-- open import Relation.Nullary.Negation
-- open import Relation.Nullary.Decidable renaming (map to mapDec; map′ to mapDec′)
-- open import Relation.Binary hiding (_⇒_)
-- open import Relation.Binary.PropositionalEquality
-- -- open ≡-Reasoning
--
--
-- -- I know this notation is a bit confusing
-- _⊈_ : ∀ {a ℓ₁ ℓ₂} {A : Set a} → Pred A ℓ₁ → Pred A ℓ₂ → Set _
-- P ⊈ Q = ∀ {x} → x ∉ P → x ∉ Q
--
--
-- ⊆-IsPreorder : IsPreorder _≋_ _⊆_
-- ⊆-IsPreorder = record
-- { isEquivalence = {! !}
-- ; reflexive = {! !}
-- ; trans = {! !}
-- }
--
--
-- []-empty : Empty c[ [] ]
-- []-empty = λ x → λ ()
--
-- here-respects-≡ : ∀ {A} → (λ x → x ∈ c[ A ]) Respects _≡_
-- here-respects-≡ refl = id
--
-- there-respects-≡ : ∀ {x A} → (λ a → x ∈ c[ a ∷ A ]) Respects _≡_
-- there-respects-≡ refl = id
--
-- ∈-respects-≡ : ∀ {x} → (λ P → x ∈ c[ P ]) Respects _≡_
-- ∈-respects-≡ refl = id
--
-- there-if-not-here : ∀ {x a A} → x ≢ a → x ∈ c[ a ∷ A ] → x ∈ c[ A ]
-- there-if-not-here x≢a here = contradiction refl x≢a
-- there-if-not-here x≢a (there x∈a∷A) = x∈a∷A
--
-- here-if-not-there : ∀ {x a A} → x ∉ c[ A ] → x ∈ c[ a ∷ A ] → x ≡ a
-- here-if-not-there x∉A here = refl
-- here-if-not-there x∉A (there x∈A) = contradiction x∈A x∉A
--
-- map-¬∷ : ∀ {x a A B} → (x ∉ c[ A ] → x ∉ c[ B ]) → x ≢ a → x ∉ c[ a ∷ A ] → x ∉ c[ a ∷ B ]
-- map-¬∷ f x≢x x∉a∷A here = contradiction refl x≢x
-- map-¬∷ f x≢a x∉a∷A (there x∈B) = f (x∉a∷A ∘ there) x∈B
--
-- still-not-there : ∀ {x y} A → x ≢ y → x ∉ c[ A ] → x ∉ c[ y ∷ A ]
-- still-not-there [] x≢y x∉[y] here = x≢y refl
-- still-not-there [] x≢y x∉[y] (there ())
-- still-not-there (a ∷ A) x≢y x∉a∷A here = x≢y refl
-- still-not-there (a ∷ A) x≢y x∉a∷A (there x∈a∷A) = x∉a∷A x∈a∷A
--
-- --------------------------------------------------------------------------------
-- -- Union
-- --------------------------------------------------------------------------------
--
-- union : Collection → Collection → Collection
-- union [] B = B
-- union (a ∷ A) B with a ∈? B
-- union (a ∷ A) B | yes p = union A B
-- union (a ∷ A) B | no ¬p = a ∷ union A B
--
-- in-right-union : ∀ A B → c[ B ] ⊆ c[ union A B ]
-- in-right-union [] B x∈B = x∈B
-- in-right-union (a ∷ A) B x∈B with a ∈? B
-- in-right-union (a ∷ A) B x∈B | yes p = in-right-union A B x∈B
-- in-right-union (a ∷ A) B x∈B | no ¬p = there (in-right-union A B x∈B)
--
-- in-left-union : ∀ A B → c[ A ] ⊆ c[ union A B ]
-- in-left-union [] B ()
-- in-left-union (a ∷ A) B x∈A with a ∈? B
-- in-left-union (a ∷ A) B here | yes p = in-right-union A B p
-- in-left-union (a ∷ A) B (there x∈A) | yes p = in-left-union A B x∈A
-- in-left-union (a ∷ A) B here | no ¬p = here
-- in-left-union (a ∷ A) B (there x∈A) | no ¬p = there (in-left-union A B x∈A)
--
-- ∪-left-identity : ∀ A → c[ [] ] ∪ c[ A ] ≋ c[ A ]
-- ∪-left-identity A = equivalence to inj₂
-- where
-- to : c[ [] ] ∪ c[ A ] ⊆ c[ A ]
-- to (inj₁ ())
-- to (inj₂ ∈A) = ∈A
--
-- ∪-right-identity : ∀ A → c[ A ] ∪ c[ [] ] ≋ c[ A ]
-- ∪-right-identity A = equivalence to inj₁
-- where
-- to : c[ A ] ∪ c[ [] ] ⊆ c[ A ]
-- to (inj₁ ∈A) = ∈A
-- to (inj₂ ())
--
-- in-either : ∀ A B → c[ union A B ] ⊆ c[ A ] ∪ c[ B ]
-- in-either [] B x∈A∪B = inj₂ x∈A∪B
-- in-either (a ∷ A) B x∈A∪B with a ∈? B
-- in-either (a ∷ A) B x∈A∪B | yes p = mapSum there id (in-either A B x∈A∪B)
-- in-either (a ∷ A) B here | no ¬p = inj₁ here
-- in-either (a ∷ A) B (there x∈A∪B) | no ¬p = mapSum there id (in-either A B x∈A∪B)
--
-- ∪-union : ∀ A B → c[ A ] ∪ c[ B ] ≋ c[ union A B ]
-- ∪-union A B = equivalence to (in-either A B)
-- where to : ∀ {x} → x ∈ c[ A ] ∪ c[ B ] → x ∈ c[ union A B ]
-- to (inj₁ ∈A) = in-left-union A B ∈A
-- to (inj₂ ∈B) = in-right-union A B ∈B
--
-- -- map-⊆-union : ∀ {A B C} → c[ A ] ⊆ c[ B ] → c[ B ] ⊆ c[ C ] → c[ ] ⊆ c[ union C D ]
-- -- map-⊆-union f g ∈union = {! !}
--
--
-- union-branch-1 : ∀ {x a} A B → a ∈ c[ B ] → x ∈ c[ union (a ∷ A) B ] → x ∈ c[ union A B ]
-- union-branch-1 {x} {a} A B a∈B x∈union with a ∈? B
-- union-branch-1 A B a∈B x∈union | yes p = x∈union
-- union-branch-1 A B a∈B x∈union | no ¬p = contradiction a∈B ¬p
--
-- there-left-union-coherence : ∀ {x} {a} A B → x ∈ c[ a ∷ A ] → x ∈c a ∷ union A B
-- there-left-union-coherence A B here = here
-- there-left-union-coherence A B (there x∈a∷A) = there (in-left-union A B x∈a∷A)
--
--
-- in-neither : ∀ {x} A B → x ∉c union A B → x ∉ c[ A ] × x ∉ c[ B ]
-- in-neither [] B x∉A∪B = (λ ()) , x∉A∪B
-- in-neither (a ∷ A) B x∉A∪B with a ∈? B
-- in-neither (a ∷ A) B x∉A∪B | yes a∈B = (contraposition (union-branch-1 A B a∈B ∘ in-left-union (a ∷ A) B) x∉A∪B) , (contraposition (in-right-union A B) x∉A∪B)
-- in-neither (a ∷ A) B x∉A∪B | no a∉B = (contraposition (there-left-union-coherence A B) x∉A∪B) , contraposition (there ∘ in-right-union A B) x∉A∪B
--
--
-- delete : String → Collection → Collection
-- delete x [] = []
-- delete x (a ∷ A) with x ≟ a
-- delete x (a ∷ A) | yes p = delete x A -- keep deleting, because there might be many of them
-- delete x (a ∷ A) | no ¬p = a ∷ delete x A
--
-- ∉-after-deleted : ∀ x A → x ∉ c[ delete x A ]
-- ∉-after-deleted x [] ()
-- ∉-after-deleted x (a ∷ A) with x ≟ a
-- ∉-after-deleted x (a ∷ A) | yes p = ∉-after-deleted x A
-- ∉-after-deleted x (a ∷ A) | no ¬p = still-not-there (delete x A) ¬p (∉-after-deleted x A)
--
--
-- still-∈-after-deleted : ∀ {x} y A → x ≢ y → x ∈ c[ A ] → x ∈ c[ delete y A ]
-- still-∈-after-deleted y [] x≢y ()
-- still-∈-after-deleted y (a ∷ A) x≢y x∈A with y ≟ a
-- still-∈-after-deleted y (.y ∷ A) x≢y x∈A | yes refl = still-∈-after-deleted y A x≢y (there-if-not-here x≢y x∈A)
-- still-∈-after-deleted y (a ∷ A) x≢y x∈A | no ¬p = ∷-⊆-monotone {! !} {! x∈A !}
-- -- still-∈-after-deleted y (a ∷ A) x≢y x∈A | no ¬p = ∷-⊆-monotone (still-∈-after-deleted y A x≢y) x∈A
--
-- -- still-∉-after-deleted : ∀ {x} y A → x ≢ y → x ∉ c[ A ] → x ∉ c[ delete y A ]
-- -- still-∉-after-deleted y [] x≢y x∉A = x∉A
-- -- still-∉-after-deleted y (a ∷ A) x≢y x∉A with y ≟ a
-- -- still-∉-after-deleted y (.y ∷ A) x≢y x∉A | yes refl = still-∉-after-deleted y A x≢y (x∉A ∘ there)
-- -- still-∉-after-deleted {x} y (a ∷ A) x≢y x∉A | (no ¬p) with x ≟ a
-- -- still-∉-after-deleted y (x ∷ A) x≢y x∉A | no ¬p | yes refl = contradiction here x∉A
-- -- still-∉-after-deleted y (a ∷ A) x≢y x∉A | no ¬p | no ¬q = map-¬∷ (still-∉-after-deleted y A x≢y) ¬q x∉A
-- --
-- -- still-∉-after-recovered : ∀ {x} y A → x ≢ y → x ∉c delete y A → x ∉ c[ A ]
-- -- still-∉-after-recovered y [] x≢y x∉deleted ()
-- -- still-∉-after-recovered y (a ∷ A) x≢y x∉deleted x∈a∷A with y ≟ a
-- -- still-∉-after-recovered y (.y ∷ A) x≢y x∉deleted x∈a∷A | yes refl = still-∉-after-recovered y A x≢y x∉deleted (there-if-not-here x≢y x∈a∷A)
-- -- still-∉-after-recovered {x} y (a ∷ A) x≢y x∉deleted x∈a∷A | no ¬p with x ≟ a
-- -- still-∉-after-recovered y (x ∷ A) x≢y x∉deleted x∈a∷A | no ¬p | yes refl = contradiction here x∉deleted
-- -- still-∉-after-recovered y (a ∷ A) x≢y x∉deleted x∈a∷A | no ¬p | no ¬q = x∉deleted (∷-⊆-monotone (still-∈-after-deleted y A x≢y) x∈a∷A)
--
-- singleton : String → Collection
-- singleton x = x ∷ []
--
-- singleton-≡ : ∀ {x y} → x ∈ c[ singleton y ] → x ≡ y
-- singleton-≡ here = refl
-- singleton-≡ (there ())
| {
"alphanum_fraction": 0.4879930457,
"avg_line_length": 42.8046511628,
"ext": "agda",
"hexsha": "332f22f4a36a57ed8f7e7986a681faf46fbcfc47",
"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": "f81b116473582ab7956adc4bf1d7ebf1ae2a213a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/lambda-calculus",
"max_forks_repo_path": "Data/Collection.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f81b116473582ab7956adc4bf1d7ebf1ae2a213a",
"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": "banacorn/lambda-calculus",
"max_issues_repo_path": "Data/Collection.agda",
"max_line_length": 161,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f81b116473582ab7956adc4bf1d7ebf1ae2a213a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/lambda-calculus",
"max_stars_repo_path": "Data/Collection.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3721,
"size": 9203
} |
module Numeral.Natural.Oper.Proofs.Rewrite where
import Lvl
open import Numeral.Natural
open import Numeral.Natural.Oper
open import Numeral.Natural.Induction
open import Relator.Equals
open import Relator.Equals.Proofs
open import Syntax.Function
private variable x y : ℕ
[+]-baseₗ : 𝟎 + y ≡ y
[+]-baseₗ {x} = ℕ-elim [≡]-intro (x ↦ [≡]-with(𝐒) {𝟎 + x}{x}) x
{-# REWRITE [+]-baseₗ #-}
[+]-baseᵣ : x + 𝟎 ≡ x
[+]-baseᵣ = [≡]-intro
[+]-stepₗ : 𝐒(x) + y ≡ 𝐒(x + y)
[+]-stepₗ {x}{y} = ℕ-elim [≡]-intro (i ↦ [≡]-with(𝐒) {𝐒(x) + i} {x + 𝐒(i)}) y
{-# REWRITE [+]-stepₗ #-}
[+]-stepᵣ : x + 𝐒(y) ≡ 𝐒(x + y)
[+]-stepᵣ = [≡]-intro
| {
"alphanum_fraction": 0.5888,
"avg_line_length": 24.0384615385,
"ext": "agda",
"hexsha": "97d3c66cba3ba1df41d66f65ba59bf875d2239c7",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Numeral/Natural/Oper/Proofs/Rewrite.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Numeral/Natural/Oper/Proofs/Rewrite.agda",
"max_line_length": 77,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Numeral/Natural/Oper/Proofs/Rewrite.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": 294,
"size": 625
} |
module Numeral.PositiveInteger where
import Lvl
open import Syntax.Number
open import Data.Boolean.Stmt
open import Functional
open import Numeral.Natural.Oper.Comparisons
open import Numeral.Natural as ℕ using (ℕ)
open import Type
data ℕ₊ : Type{Lvl.𝟎} where
𝟏 : ℕ₊
𝐒 : ℕ₊ → ℕ₊
ℕ₊-to-ℕ : ℕ₊ → ℕ
ℕ₊-to-ℕ (𝟏) = ℕ.𝐒(ℕ.𝟎)
ℕ₊-to-ℕ (𝐒(n)) = ℕ.𝐒(ℕ₊-to-ℕ (n))
ℕ-to-ℕ₊ : (n : ℕ) → ⦃ _ : IsTrue(positive?(n)) ⦄ → ℕ₊
ℕ-to-ℕ₊ (ℕ.𝟎) ⦃ ⦄
ℕ-to-ℕ₊ (ℕ.𝐒(ℕ.𝟎)) ⦃ _ ⦄ = 𝟏
ℕ-to-ℕ₊ (ℕ.𝐒(ℕ.𝐒(x))) ⦃ p ⦄ = 𝐒(ℕ-to-ℕ₊ (ℕ.𝐒(x)) ⦃ p ⦄)
instance
ℕ₊-numeral : Numeral(ℕ₊)
Numeral.restriction-ℓ (ℕ₊-numeral) = Lvl.𝟎
Numeral.restriction (ℕ₊-numeral) (n) = IsTrue(positive?(n))
num ⦃ ℕ₊-numeral ⦄ (n) ⦃ proof ⦄ = ℕ-to-ℕ₊ (n) ⦃ proof ⦄
𝐒-from-ℕ : ℕ → ℕ₊
𝐒-from-ℕ (ℕ.𝟎) = 𝟏
𝐒-from-ℕ (ℕ.𝐒(n)) = 𝐒(𝐒-from-ℕ(n))
𝐏-to-ℕ : ℕ₊ → ℕ
𝐏-to-ℕ (𝟏) = ℕ.𝟎
𝐏-to-ℕ (𝐒(n)) = ℕ.𝐒(𝐏-to-ℕ(n))
| {
"alphanum_fraction": 0.5551763367,
"avg_line_length": 23.7567567568,
"ext": "agda",
"hexsha": "c54225b856f2aef2f11f2ec2469a88ad61bd410d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Numeral/PositiveInteger.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Numeral/PositiveInteger.agda",
"max_line_length": 63,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Numeral/PositiveInteger.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": 570,
"size": 879
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import LogicalFormulae
module Functions.Definition where
Rel : {a b : _} → Set a → Set (a ⊔ lsuc b)
Rel {a} {b} A = A → A → Set b
_∘_ : {a b c : _} {A : Set a} {B : Set b} {C : Set c} → (f : B → C) → (g : A → B) → (A → C)
g ∘ f = λ a → g (f a)
Injection : {a b : _} {A : Set a} {B : Set b} (f : A → B) → Set (a ⊔ b)
Injection {A = A} f = {x y : A} → (f x ≡ f y) → x ≡ y
Surjection : {a b : _} {A : Set a} {B : Set b} (f : A → B) → Set (a ⊔ b)
Surjection {A = A} {B = B} f = (b : B) → Sg A (λ a → f a ≡ b)
record Bijection {a b : _} {A : Set a} {B : Set b} (f : A → B) : Set (a ⊔ b) where
field
inj : Injection f
surj : Surjection f
record Invertible {a b : _} {A : Set a} {B : Set b} (f : A → B) : Set (a ⊔ b) where
field
inverse : B → A
isLeft : (b : B) → f (inverse b) ≡ b
isRight : (a : A) → inverse (f a) ≡ a
id : {a : _} {A : Set a} → (A → A)
id a = a
dom : {a b : _} {A : Set a} {B : Set b} (f : A → B) → Set a
dom {A = A} f = A
codom : {a b : _} {A : Set a} {B : Set b} (f : A → B) → Set b
codom {B = B} f = B
| {
"alphanum_fraction": 0.470890411,
"avg_line_length": 29.2,
"ext": "agda",
"hexsha": "27335aeb9c3ecce076513b07af2a95ebe6a64a4d",
"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": "Functions/Definition.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": "Functions/Definition.agda",
"max_line_length": 91,
"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": "Functions/Definition.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": 531,
"size": 1168
} |
-- This is a selection of useful function
-- from the standard library that we tend to use a lot.
module Prelude where
open import Data.Nat
hiding (_⊔_)
public
open import Level
renaming (suc to lsuc; zero to ℓ0)
public
open import Relation.Binary.PropositionalEquality
renaming ([_] to Reveal[_] )
public
open import Relation.Unary
public
open import Data.Unit
using (⊤; tt)
public
open import Data.Sum
public
open import Data.Nat.Properties
public
open import Relation.Nullary
hiding (Irrelevant)
public
open import Data.Product
using (_×_; proj₁; proj₂; Σ; _,_; ∃; Σ-syntax; ∃-syntax)
public
open import Data.Empty
using (⊥; ⊥-elim)
public
open import Function
using (_∘_)
public
open import Data.List.Relation.Unary.Any
using (Any; here; there)
public
| {
"alphanum_fraction": 0.6628701595,
"avg_line_length": 17.2156862745,
"ext": "agda",
"hexsha": "294afd93527e4a3b47c9c932d612662c1773c891",
"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": "391e148f391dc2d246249193788a0d203285b38e",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "lisandrasilva/agda-liveness",
"max_forks_repo_path": "src/Prelude.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "391e148f391dc2d246249193788a0d203285b38e",
"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": "lisandrasilva/agda-liveness",
"max_issues_repo_path": "src/Prelude.agda",
"max_line_length": 60,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "391e148f391dc2d246249193788a0d203285b38e",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "lisandrasilva/agda-liveness",
"max_stars_repo_path": "src/Prelude.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 248,
"size": 878
} |
{-# OPTIONS --allow-unsolved-metas #-}
open import Agda.Primitive using (Level)
module Tutorials.Monday where
-- Two dashes to comment out the rest of the line
{-
Opening {-
and closing -}
for a multi-line comment
-}
-- In Agda all the tokens are tokenised using whitespace (with the exception of parentheses and some other symbols)
-- Agda offers unicode support
-- We can input unicode using the backslash \ and (most of the time) typing what one would type in LaTeX
-- If in emacs, we can put the cursor over a characted and use M-x describe-char to see how that character is inputted
-- ⊥ is written using \bot
data ⊥ : Set where
-- AKA the empty set, bottom, falsehood, the absurd type, the empty type, the initial object
-- ⊥ : Set means ⊥ is a Type (Set = Type, for historical reasons)
-- The data keyword creates a data type where we list all the constructors of the types
-- ⊥ has no constructors: there is no way of making something of type ⊥
record ⊤ : Set where
-- AKA the singleton set, top, truth, the trivial type, the unit type, the terminal object
-- The record keyword creates a record type
-- Records have a single constructor
-- To create a record you must populate all of its fields
-- ⊤ has no fields: it is trivial to make one, and contains no information
constructor tt
data Bool : Set where
-- Bool has two constructors: one bit worth of information
true : Bool
false : Bool
--------
-- Simple composite types
--------
module Simple where
record _×_ (A : Set) (B : Set) : Set where
-- AKA logical and, product type
-- Agda offers support for mixfix notation
-- We use the underscores to specify where the arguments goal
-- In this case the arguments are the type parameters A and B, so we can write A × B
-- A × B models a type packing up *both* an A *and* a B
-- A and B are type parameters, both of type Set, i.e. types
-- A × B itself is of type Set, i.e. a type
-- We use the single record constructor _,_ to make something of type A × B
-- The constructor _,_ takes two parameters: the fields fst and snd, of type A and B, respectively
-- If we have a of type A and b of type B, then (a , b) is of type A × B
constructor _,_
field
fst : A
snd : B
-- Agda has a very expressive module system (more on modules later)
-- Every record has a module automatically attached to it
-- Opening a record exposes its constructor and it fields
-- The fields are projection functions out of the record
-- In the case of _×_, it exposes
-- fst : A × B → A
-- snd : A × B → B
open _×_
data _⊎_ (A B : Set) : Set where
-- AKA logical or, sum type, disjoint union
-- A ⊎ B models a type packing *either* an A *or* a B
-- A and B are type parameters, both of type Set, i.e. types
-- A ⊎ B itself is of type Set, i.e. a type
-- A ⊎ B has two constructors: inl and inr
-- The constructor inl takes something of type A as an argument and returns something of type A ⊎ B
-- The constructor inr takes something of type B as an argument and returns something of type A ⊎ B
-- We can make something of type A ⊎ B either by using inl and supplying an A, or by using inr and supplying a B
inl : A → A ⊎ B
inr : B → A ⊎ B
--------
-- Some simple proofs!
--------
-- In constructive mathematics logical implication is modelled as function types
-- An object of type A → B shows that assuming an object of type A, we can construct an object of type B
-- Below we want to show that assuming an object of type A × B, we can construct an object of type A
-- We want to show that this is the case regardless of what A and B actually are
-- We do this using a polymorphic function that is parametrised over A and B, both of type Set
-- We use curly braces {} to make these function parameters implicit
-- When we call this function we won't have to supply the arguments A and B unless we want to
-- When we define this function we won't have to accept A and B as arguments unless we want to
-- The first line below gives the type of the function get-fst
-- The second line gives its definition
get-fst : {A : Set} {B : Set} → A × B → A
get-fst x = {!!}
-- Agda is an *interactive* proof assistant
-- We don't provide our proofs/programs all at once: we develop them iteratively
-- We write ? where we don't yet have a program to provide, and we reload the file
-- What we get back is a hole where we can place the cursor and have a conversation with Agda
-- ctrl+c is the prefix that we use to communicate with Agda
-- ctrl+c ctrl+l reload the file
-- ctrl+c ctrl+, shows the goal and the context
-- ctrl+c ctrl+. shows the goal, the context, and what we have so far
-- ctrl+c ctrl+c pattern matches against a given arguments
-- ctrl+c ctrl+space fill in hole
-- ctrl+c ctrl+r refines the goal: it will ask Agda to insert the first constructor we need
-- ctrl+c ctrl+a try to automatically fulfill the goal
-- key bindings: https://agda.readthedocs.io/en/v2.6.1.3/getting-started/quick-guide.html
get-snd : ∀ {A B} → A × B → B
get-snd x = {!!}
-- The variable keyword enables us to declare convention for notation
-- Unless said otherwise, whenever we refer to A, B or C and these are not bound, we will refer to objects of type Set
variable
ℓ : Level
A B C : Set ℓ
-- Notice how we don't have to declare A, B and C anymore
curry : (A → B → C) → (A × B → C)
curry f = {!!}
uncurry : (A × B → C) → (A → B → C)
uncurry f = {!!}
×-comm : A × B → B × A
×-comm = {!!}
×-assoc : (A × B) × C → A × (B × C)
×-assoc = {!!}
-- Pattern matching has to be exhaustive: all cases must be addressed
⊎-comm : A ⊎ B → B ⊎ A
⊎-comm = {!!}
⊎-assoc : (A ⊎ B) ⊎ C → A ⊎ (B ⊎ C)
⊎-assoc = {!!}
-- If there are no cases to be addressed there is nothing for us left to do
-- If you believe ⊥ exist you believe anything
absurd : ⊥ → A
absurd a = {!!}
-- In constructive mathematics all proofs are constructions
-- How do we show that an object of type A cannot possibly be constructed, while using a construction to show so?
-- We take the cannonically impossible-to-construct object ⊥, and show that if we were to assume the existence of A, we could use it to construct ⊥
¬_ : Set ℓ → Set ℓ
¬ A = A → ⊥
-- In classical logic double negation can be eliminated: ¬ ¬ A ⇒ A
-- That is however not the case in constructive mathematics:
-- The proof ¬ ¬ A is a function that takes (A → ⊥) into ⊥, and offers no witness for A
-- The opposite direction is however constructive:
⇒¬¬ : A → ¬ ¬ A
⇒¬¬ = {!!}
-- Moreover, double negation can be eliminated from non-witnesses
¬¬¬⇒¬ : ¬ ¬ ¬ A → ¬ A
¬¬¬⇒¬ = {!!}
-- Here we have a choice of two programs to write
×-⇒-⊎₁ : A × B → A ⊎ B
×-⇒-⊎₁ = {!!}
×-⇒-⊎₂ : A × B → A ⊎ B
×-⇒-⊎₂ = {!!}
-- A little more involved
-- Show that the implication (A ⊎ B → A × B) is not always true for all A and Bs
⊎-⇏-× : ¬ (∀ {A B} → A ⊎ B → A × B)
⊎-⇏-× f = {!!}
variable
ℓ : Level
A B C : Set ℓ
--------
-- Inductive data types
--------
data ℕ : Set where
-- The type of unary natural numbers
-- The zero constructor takes no arguments; the base case
-- The suc constructor takes one argument: an existing natural number; the inductive case
-- We represent natural numbers by using ticks: ||| ≈ 3
-- zero: no ticks
-- suc: one more tick
-- suc (suc (suc zero)) ≈ ||| ≈ 3
zero : ℕ
suc : ℕ → ℕ
three : ℕ
three = suc (suc (suc zero))
-- Compiler pragmas allow us to give instructions to Agda
-- They are introduced with an opening {-# and a closing #-}
-- Here we the pragma BUILTIN to tell Agda to use ℕ as the builtin type for natural numbers
-- This allows us to say 3 instead of suc (suc (suc zero))
{-# BUILTIN NATURAL ℕ #-}
three' : ℕ
three' = 3
-- Whenever we say n or m and they haven't been bound, they refer to natural numbers
variable
n m l : ℕ
-- Brief interlude: we declare the fixity of certain functions
-- By default, all definitions have precedence 20
-- The higher the precedence, the tighter they bind
-- Here we also declare that _+_ is left associative, i.e. 1 + 2 + 3 is parsed as (1 + 2) + 3
infixl 20 _+_
-- Define addition of natural numbers by structural recursion
_+_ : ℕ → ℕ → ℕ
x + y = {!!}
-- In functions recursion must always occur on structurally smaller values (otherwise the computation might never terminate)
-- In Agda *all computations must terminate*
-- We can tell Agda to ignore non-termination with this pragma
{-# TERMINATING #-}
non-terminating : ℕ → ℕ
non-terminating n = non-terminating n
-- However, doing so would allow us to define elements of the type ⊥
-- This is not considered safe: running Agda with the --safe option will make type-checking fail
{-# TERMINATING #-}
loop : ⊥
loop = loop
-- Use structural recursion to define multiplication
_*_ : ℕ → ℕ → ℕ
x * y = {!!}
-- The module keyword allows us to define modules (namespaces)
module List where
infixr 15 _∷_ _++_
data List (A : Set) : Set where
-- Lists are another example of inductive types
-- The type parameter A is the type of every element in the list
-- They are like natural numbers, but the successor case contains an A
[] : List A
_∷_ : A → List A → List A
-- List concatenation by structural recursion
_++_ : List A → List A → List A
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ (xs ++ ys)
-- Apply a function (A → B) to every element of a list
map : (A → B) → List A → List B
map = {!!}
-- A base case B and an inductive case A → B → B is all we need to take a List A and make a B
foldr : (A → B → B) → B → List A → B
foldr f b [] = b
foldr f b (x ∷ xs) = f x (foldr f b xs)
--------
-- Dependent Types
--------
-- Dependent types are types that depend on values, objects of another type
-- Dependent types allow us to model predicates on types
-- A predicate P on a type A is a function taking elements of A into types
Pred : Set → Set₁
Pred A = A → Set
-- Let us define a predicate on ℕ that models the even numbers
-- Even numbers are taken to the type ⊤, which is trivial to satisfy
-- Odd numbers are taken to the type ⊥, which is impossible to satisfy
Even : Pred ℕ
Even x = {!!}
-- We can now use Even as a precondition on a previous arguments
-- Here we bind the first argument of type ℕ to the name n
-- We then use n as an argument to the type Even
-- As we expose the constructors of n, Even will compute
half : (n : ℕ) → Even n → ℕ
half n n-even = {!!}
-- There is an alternative way of definiting dependent types
-- EvenData is a data type indexed by elements of the type ℕ
-- That is, for every (n : ℕ), EvenData n is a type
-- The constructor zero constructs an element of the type EvenData zero
-- The constructor 2+_ takes an element of the type EvenData n and constructs one of type EvenData (suc (suc n))
-- Note that there is no constructors that constructs elements of the type Evendata (suc zero)
data EvenData : ℕ → Set where -- Pred ℕ
zero : EvenData zero
2+_ : EvenData n → EvenData (suc (suc n))
-- We can use EvenData as a precondition too
-- The difference is that while Even n computes automatically, we have to take EvenData n appart by pattern matching
-- It leaves a trace of *why* n is even
half-data : (n : ℕ) → EvenData n → ℕ
half-data n n-even = {!!}
-- Function composition: (f ∘ g) composes two functions f and g
-- The result takes the input, feeds it through g, then feeds the result through f
infixr 20 _∘_
_∘_ : (B → C) → (A → B) → (A → C)
(f ∘ g) x = f (g x)
--------
-- Example of common uses of dependent types
--------
module Fin where
-- The type Fin n has n distinct inhabitants
data Fin : ℕ → Set where
zero : Fin (suc n)
suc : Fin n → Fin (suc n)
-- Note that there is no constructor for Fin zero
Fin0 : Fin zero → ⊥
Fin0 x = {!!}
-- We can erase the type level information to get a ℕ back
to-ℕ : Fin n → ℕ
to-ℕ zero = zero
to-ℕ (suc x) = suc (to-ℕ x)
module Vec where
open Fin
-- Vectors are like lists, but they keep track of their length
-- The type Vec A n is the type of lists of length n containing values of type A
-- Notice that while A is a parameter (remains unchanged in all constructors), n is an index
-- We can bind parameters to names (since they don't change) but we cannot bind indices
data Vec (A : Set) : ℕ → Set where
[] : Vec A zero
_∷_ : A → Vec A n → Vec A (suc n)
-- Now we can define concatenation, but giving more assurances about the resulting length
_++_ : Vec A n → Vec A m → Vec A (n + m)
xs ++ ys = {!!}
map : (A → B) → Vec A n → Vec B n
map = {!!}
-- Given a vector and a fin, we can use the latter as a lookup index into the former
-- Question: what happens if there vector is empty?
_!_ : Vec A n → Fin n → A
xs ! i = {!!}
-- A vector Vec A n is just the inductive form of a function Fin n → A
tabulate : ∀ {n} → (Fin n → A) → Vec A n
tabulate {n = zero} f = []
tabulate {n = suc n} f = f zero ∷ tabulate (f ∘ suc)
untabulate : Vec A n → (Fin n → A)
untabulate [] ()
untabulate (x ∷ xs) zero = x
untabulate (x ∷ xs) (suc i) = untabulate xs i
-- Predicates need not be unary, they can be binary! (i.e. relations)
Rel : Set → Set₁
Rel A = A → A → Set
-- Question: how many proofs are there for any n ≤ m
data _≤_ : Rel ℕ where
z≤n : zero ≤ n
s≤s : n ≤ m → suc n ≤ suc m
_<_ : ℕ → ℕ → Set
n < m = suc n ≤ m
-- _≤_ is reflexive and transitive
≤-refl : ∀ n → n ≤ n
≤-refl n = {!!}
≤-trans : n ≤ m → m ≤ l → n ≤ l
≤-trans a b = {!!}
-----------
-- Propositional Equality
-----------
-- Things get interesting: we can use type indices to define propositional equality
-- For any (x y : A) the type x ≡ y is a proof showing that x and y are in fact definitionally equal
-- It has a single constructor refl which limits the ways of making something of type x ≡ y to those where x and y are in fact the same, i.e. x ≡ x
-- When we pattern match against something of type x ≡ y, the constructor refl will make x and y unify: Agda will internalise the equality
infix 10 _≡_
-- \== ≡
data _≡_ (x : A) : A → Set where
refl : x ≡ x
{-# BUILTIN EQUALITY _≡_ #-}
-- Definitional equality holds when the two sides compute to the same symbols
2+2≡4 : 2 + 2 ≡ 4
2+2≡4 = {!!}
-- Because of the way in which defined _+_, zero + x ≡ x holds definitionally (the first case in the definition)
+-idˡ : ∀ x → (zero + x) ≡ x
+-idˡ x = {!!}
-- We show that equality respects congruence
cong : {x y : A} (f : A → B) → x ≡ y → f x ≡ f y
cong f p = {!!}
-- However this does not hold definitionally
-- We need to use proof by induction
-- We miss some pieces to prove this
+-idʳ : ∀ x → (x + zero) ≡ x
+-idʳ x = {!!}
-- Propositional equality is reflexive by construction, here we show it is also symmetric and transitive
sym : {x y : A} → x ≡ y → y ≡ x
sym p = {!!}
trans : {x y z : A} → x ≡ y → y ≡ z → x ≡ z
trans p q = {!!}
-- A binary version that will come in use later on
cong₂ : {x y : A} {w z : B} (f : A → B → C) → x ≡ y → w ≡ z → f x w ≡ f y z
cong₂ f refl refl = refl
-- Leibniz equality, transport
subst : {x y : A} {P : Pred A} → x ≡ y → P x → P y
subst eq p = {!!}
-- Now we can start proving slightly more interesting things!
+-assoc : ∀ x y z → (x + y) + z ≡ x + (y + z)
+-assoc x y z = {!!}
-- Introduce underscores on the RHS
+-comm : ∀ x y → x + y ≡ y + x
+-comm x zero = {!!}
+-comm x (suc y) = {!!}
-- The keyword where allows us to introduce local definitions
where
+-suc : ∀ x y → x + suc y ≡ suc (x + y)
+-suc x y = {!!}
-----------
-- Some tooling for equational reasoning
-----------
infix 3 _∎
infixr 2 step-≡
infix 1 begin_
begin_ : ∀{x y : A} → x ≡ y → x ≡ y
begin_ x≡y = x≡y
step-≡ : ∀ (x {y z} : A) → y ≡ z → x ≡ y → x ≡ z
step-≡ _ y≡z x≡y = trans x≡y y≡z
syntax step-≡ x y≡z x≡y = x ≡⟨ x≡y ⟩ y≡z
_∎ : ∀ (x : A) → x ≡ x
_∎ _ = refl
-- The equational resoning style allows us to explicitly write down the goals at each stage
-- This starts to look like what one would do on the whiteboard
+-comm′ : ∀ x y → x + y ≡ y + x
+-comm′ x zero = {!!}
+-comm′ x (suc y) = begin
(x + suc y) ≡⟨ {!!} ⟩
suc (x + y) ≡⟨ {!!} ⟩
suc (y + x) ∎
| {
"alphanum_fraction": 0.6409188361,
"avg_line_length": 35.0321888412,
"ext": "agda",
"hexsha": "e0cd7a0fe38b08839562c63e873e369d803be0f5",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-11-24T10:50:55.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-23T08:50:13.000Z",
"max_forks_repo_head_hexsha": "ccd2a78642e93754011deffbe85e9ef5071e4cb7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "poncev/agda-bcam",
"max_forks_repo_path": "Tutorials/Monday.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ccd2a78642e93754011deffbe85e9ef5071e4cb7",
"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": "poncev/agda-bcam",
"max_issues_repo_path": "Tutorials/Monday.agda",
"max_line_length": 149,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "ccd2a78642e93754011deffbe85e9ef5071e4cb7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "poncev/agda-bcam",
"max_stars_repo_path": "Tutorials/Monday.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-03T22:53:51.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-09-23T17:59:21.000Z",
"num_tokens": 5005,
"size": 16325
} |
module map-Tree where
-- ツリー
data Tree (A B : Set) : Set where
leaf : A → Tree A B
node : Tree A B → B → Tree A B → Tree A B
-- ツリーのmap
map-Tree : ∀ {A B C D : Set} → (A → C) → (B → D) → Tree A B → Tree C D
map-Tree f g (leaf a) = leaf (f a)
map-Tree f g (node treeˡ b treeʳ) = node (map-Tree f g treeˡ) (g b) (map-Tree f g treeʳ)
| {
"alphanum_fraction": 0.547277937,
"avg_line_length": 29.0833333333,
"ext": "agda",
"hexsha": "c84b9330cbc4699fdc78efa6a18f5f7b81cfce2f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "akiomik/plfa-solutions",
"max_forks_repo_path": "part1/lists/map-Tree.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "akiomik/plfa-solutions",
"max_issues_repo_path": "part1/lists/map-Tree.agda",
"max_line_length": 88,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "akiomik/plfa-solutions",
"max_stars_repo_path": "part1/lists/map-Tree.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-07T09:42:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-07T09:42:22.000Z",
"num_tokens": 149,
"size": 349
} |
{-# OPTIONS --without-K #-}
open import Base
open import Homotopy.PullbackDef
module Homotopy.PullbackIsPullback {i} (d : pullback-diag i) where
open pullback-diag d
import Homotopy.PullbackUP as PullbackUP
open PullbackUP d (λ _ → unit)
pullback-cone : cone (pullback d)
pullback-cone = (pullback.a d , pullback.b d , pullback.h d)
factor-pullback : (E : Set i) → (cone E → (E → pullback d))
factor-pullback E (top→A , top→B , h) x = (top→A x , top→B x , h x)
pullback-is-pullback : is-pullback (pullback d) pullback-cone
pullback-is-pullback E = iso-is-eq _
(factor-pullback E)
(λ y → refl)
(λ f → refl)
| {
"alphanum_fraction": 0.6865912763,
"avg_line_length": 25.7916666667,
"ext": "agda",
"hexsha": "73d54c80009cf9a3bfc8ba809ca1473612b93874",
"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": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "old/Homotopy/PullbackIsPullback.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"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": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "old/Homotopy/PullbackIsPullback.agda",
"max_line_length": 67,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "old/Homotopy/PullbackIsPullback.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": 215,
"size": 619
} |
module GUIgeneric.GUIExampleLib where
open import GUIgeneric.Prelude hiding (addButton)
open import GUIgeneric.GUIDefinitions renaming (add to add'; add' to add)
open import GUIgeneric.GUI
executeChangeGui : ∀{i} → (fr : FFIFrame)(mvar : MVar StateAndGuiObj)
(mvarFFI : MVar StateAndFFIComp)
(let state = addVar mvar (SingleMVar mvarFFI))
→ StateAndGuiObj × StateAndFFIComp →
IOˢ GuiLev2Interface i (λ _ → prod state) state
executeChangeGui fr varO varFFI ((gNew , (prop , obj)) , (gOld , ffi)) =
deleteComp gOld ffi >>=ₚˢ λ _ →
reCreateFrame gNew fr >>=ₚˢ λ ffiNew →
setHandlerG gNew ffiNew varO (SingleMVar varFFI) >>=ₚˢ λ _ →
(translateLev1toLev2 (setAttributes ∞ gNew prop ffiNew)) >>=ˢ λ _ _ →
returnˢ ((gNew , (prop , obj)) , (gNew , ffiNew ))
setRightClick₃ : ∀{i} →
(g : Frame)
(ffiComp : FFIcomponents g)
(mvar : MVar StateAndGuiObj)
(mvarFFI : MVar StateAndFFIComp)
(getFr : FFIcomponents g → FFIFrame)
(let state = addVar mvar (SingleMVar mvarFFI))
→ IOˢ GuiLev3Interface i (λ s → s ≡ state × Unit) state
setRightClick₃ g ffi mvar mvarFFI getFr =
doˢ (setRightClick (getFr ffi)
(executeChangeGui (getFr ffi) mvar mvarFFI ∷ [])) λ r →
returnˢ (refl , _)
setCustomEvent₃ : ∀{i} →
(g : Frame)
(ffiComp : FFIcomponents g)
(mvar : MVar StateAndGuiObj)
(mvarFFI : MVar StateAndFFIComp)
(getFr : FFIcomponents g → FFIFrame)
(let state = addVar mvar (SingleMVar mvarFFI))
→ IOˢ GuiLev3Interface i (λ s → s ≡ state × Unit) state
setCustomEvent₃ g ffi mvar mvarFFI getFr =
doˢ (setCustomEvent (getFr ffi)
(executeChangeGui (getFr ffi) mvar mvarFFI ∷ [])) λ r →
returnˢ (refl , _)
mainGeneric : (g : Frame)(a : properties g)(o : HandlerObject ∞ g)(getFr : FFIcomponents g → FFIFrame)
→ IOˢ GuiLev3Interface ∞ (λ _ → Unit) []
mainGeneric g propDef objDef getFr =
let _>>=_ = _>>=ₚˢ_
createGUIElements = λ g → cmd3 (createFrame g)
setAttributes = λ g prop ffi → cmd3 (translateLev1toLev2ₚ (setAttributes ∞ g prop ffi))
in
createGUIElements g >>= λ ffi →
setAttributes g propDef ffi >>= λ _ →
cmd3 (initFFIMVar g ffi) >>=ₚsemiˢ λ mvaffi →
cmd3 (initHandlerMVar (SingleMVar mvaffi) g propDef objDef) >>=ₚsemiˢ λ mvar →
cmd3 (setHandlerG g ffi mvar (SingleMVar mvaffi)) >>=ₚˢ λ _ →
setCustomEvent₃ g ffi mvar mvaffi getFr >>=ˢ λ _ _ →
returnˢ _
where
cmd3 = translateLev2toLev3
compileProgram : (g : Frame)(a : properties g) (h : HandlerObject ∞ g)
→ NativeIO Unit
compileProgram g a h = start (translateLev3 (mainGeneric g a h (getFrameGen g)))
generateProgram = compileProgram
addButton : String → CompEls frame → (isOpt : IsOptimized) → CompEls frame
addButton str fr isOpt = add' buttonFrame (create-button str) fr isOpt
addTxtBox' : String → CompEls frame → (isOpt : IsOptimized) → CompEls frame
addTxtBox' str fr isOpt = add' buttonFrame (create-txtbox str) fr isOpt
record GUI {i : Size} : Set₁ where
field
defFrame : Frame
property : properties defFrame
obj : HandlerObject i defFrame
open GUI public
guiFull2IOˢprog : GUI → IOˢ GuiLev3Interface ∞ (λ _ → Unit) []
guiFull2IOˢprog g = mainGeneric (g .defFrame) (g .property) (g .obj) (getFrameGen (g .defFrame))
compileGUI : GUI → NativeIO Unit
compileGUI g = start (translateLev3 (guiFull2IOˢprog g))
| {
"alphanum_fraction": 0.6091222487,
"avg_line_length": 34.5963302752,
"ext": "agda",
"hexsha": "b2aa0b99f6f6164bb5fafa96065093f4538cb921",
"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": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "stephanadls/state-dependent-gui",
"max_forks_repo_path": "examples/GUIgeneric/GUIExampleLib.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01",
"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": "stephanadls/state-dependent-gui",
"max_issues_repo_path": "examples/GUIgeneric/GUIExampleLib.agda",
"max_line_length": 102,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "2bc84cb14a568b560acb546c440cbe0ddcbb2a01",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "stephanadls/state-dependent-gui",
"max_stars_repo_path": "examples/GUIgeneric/GUIExampleLib.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-31T17:20:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-31T15:37:39.000Z",
"num_tokens": 1183,
"size": 3771
} |
import cedille-options
open import general-util
module spans (options : cedille-options.options) {mF : Set → Set} {{_ : monad mF}} where
open import lib
open import functions
open import cedille-types
open import constants
open import conversion
open import ctxt
open import is-free
open import syntax-util
open import to-string options
open import subst
open import erase
open import datatype-functions
--------------------------------------------------
-- span datatype
--------------------------------------------------
err-m : Set
err-m = maybe string
data span : Set where
mk-span : string → posinfo → posinfo → 𝕃 tagged-val {- extra information for the span -} → err-m → span
span-to-rope : span → rope
span-to-rope (mk-span name start end extra nothing) =
[[ "[\"" ^ name ^ "\"," ^ start ^ "," ^ end ^ ",{" ]] ⊹⊹ tagged-vals-to-rope 0 extra ⊹⊹ [[ "}]" ]]
span-to-rope (mk-span name start end extra (just err)) =
[[ "[\"" ^ name ^ "\"," ^ start ^ "," ^ end ^ ",{" ]] ⊹⊹ tagged-vals-to-rope 0 (strRunTag "error" empty-ctxt (strAdd err) :: extra) ⊹⊹ [[ "}]" ]]
data error-span : Set where
mk-error-span : string → posinfo → posinfo → 𝕃 tagged-val → string → error-span
data spans : Set where
regular-spans : maybe error-span → 𝕃 span → spans
global-error : string {- error message -} → maybe span → spans
is-error-span : span → 𝔹
is-error-span (mk-span _ _ _ _ err) = isJust err
get-span-error : span → err-m
get-span-error (mk-span _ _ _ _ err) = err
get-tagged-vals : span → 𝕃 tagged-val
get-tagged-vals (mk-span _ _ _ tvs _) = tvs
spans-have-error : spans → 𝔹
spans-have-error (regular-spans es ss) = isJust es
spans-have-error (global-error _ _) = tt
empty-spans : spans
empty-spans = regular-spans nothing []
𝕃span-to-rope : 𝕃 span → rope
𝕃span-to-rope (s :: []) = span-to-rope s
𝕃span-to-rope (s :: ss) = span-to-rope s ⊹⊹ [[ "," ]] ⊹⊹ 𝕃span-to-rope ss
𝕃span-to-rope [] = [[]]
spans-to-rope : spans → rope
spans-to-rope (regular-spans _ ss) = [[ "{\"spans\":["]] ⊹⊹ 𝕃span-to-rope ss ⊹⊹ [[ "]}" ]] where
spans-to-rope (global-error e s) =
[[ global-error-string e ]] ⊹⊹ maybe-else [[]] (λ s → [[", \"global-error\":"]] ⊹⊹ span-to-rope s) s
print-file-id-table : ctxt → 𝕃 tagged-val
print-file-id-table (mk-ctxt mod (syms , mn-fn , mn-ps , fn-ids , id , id-fns) is os Δ) =
h [] id-fns where
h : ∀ {i} → 𝕃 tagged-val → 𝕍 string i → 𝕃 tagged-val
h ts [] = ts
h {i} ts (fn :: fns) = h (strRunTag "fileid" empty-ctxt (strAdd fn) :: ts) fns
add-span : span → spans → spans
add-span s@(mk-span dsc pi pi' tv nothing) (regular-spans es ss) =
regular-spans es (s :: ss)
add-span s@(mk-span dsc pi pi' tv (just err)) (regular-spans es ss) =
regular-spans (just (mk-error-span dsc pi pi' tv err)) (s :: ss)
add-span s (global-error e e') =
global-error e e'
--------------------------------------------------
-- spanM, a state monad for spans
--------------------------------------------------
spanM : Set → Set
spanM A = ctxt → spans → mF (A × ctxt × spans)
-- return for the spanM monad
spanMr : ∀{A : Set} → A → spanM A
spanMr a Γ ss = returnM (a , Γ , ss)
spanMok : spanM ⊤
spanMok = spanMr triv
get-ctxt : ∀{A : Set} → (ctxt → spanM A) → spanM A
get-ctxt m Γ ss = m Γ Γ ss
set-ctxt : ctxt → spanM ⊤
set-ctxt Γ _ ss = returnM (triv , Γ , ss)
get-error : ∀ {A : Set} → (maybe error-span → spanM A) → spanM A
get-error m Γ ss@(global-error _ _) = m nothing Γ ss
get-error m Γ ss@(regular-spans nothing _) = m nothing Γ ss
get-error m Γ ss@(regular-spans (just es) _) = m (just es) Γ ss
set-error : maybe (error-span) → spanM ⊤
set-error es Γ ss@(global-error _ _) = returnM (triv , Γ , ss)
set-error es Γ (regular-spans _ ss) = returnM (triv , Γ , regular-spans es ss)
restore-def : Set
restore-def = maybe qualif-info × maybe sym-info
spanM-set-params : params → spanM ⊤
spanM-set-params ps Γ ss = returnM (triv , (ctxt-params-def ps Γ) , ss)
-- this returns the previous ctxt-info, if any, for the given variable
spanM-push-term-decl : posinfo → var → type → spanM restore-def
spanM-push-term-decl pi x t Γ ss = let qi = ctxt-get-qi Γ x in returnM ((qi , qi ≫=maybe λ qi → ctxt-get-info (fst qi) Γ) , ctxt-term-decl pi x t Γ , ss)
-- let bindings currently cannot be made opaque, so this is OpacTrans. -tony
spanM-push-term-def : posinfo → var → term → type → spanM restore-def
spanM-push-term-def pi x t T Γ ss = let qi = ctxt-get-qi Γ x in returnM ((qi , qi ≫=maybe λ qi → ctxt-get-info (fst qi) Γ) , ctxt-term-def pi localScope OpacTrans x (just t) T Γ , ss)
spanM-push-term-udef : posinfo → var → term → spanM restore-def
spanM-push-term-udef pi x t Γ ss = let qi = ctxt-get-qi Γ x in returnM ((qi , qi ≫=maybe λ qi → ctxt-get-info (fst qi) Γ) , ctxt-term-udef pi localScope OpacTrans x t Γ , ss)
-- return previous ctxt-info, if any
spanM-push-type-decl : posinfo → var → kind → spanM restore-def
spanM-push-type-decl pi x k Γ ss = let qi = ctxt-get-qi Γ x in returnM ((qi , qi ≫=maybe λ qi → ctxt-get-info (fst qi) Γ) , ctxt-type-decl pi x k Γ , ss)
spanM-push-type-def : posinfo → var → type → kind → spanM restore-def
spanM-push-type-def pi x t T Γ ss = let qi = ctxt-get-qi Γ x in returnM ((qi , qi ≫=maybe λ qi → ctxt-get-info (fst qi) Γ) , ctxt-type-def pi localScope OpacTrans x (just t) T Γ , ss)
spanM-lookup-restore-info : var → spanM restore-def
spanM-lookup-restore-info x =
get-ctxt λ Γ →
let qi = ctxt-get-qi Γ x in
spanMr (qi , qi ≫=maybe λ qi → ctxt-get-info (fst qi) Γ)
-- returns the original sym-info.
-- clarification is idempotent: if the definition was already clarified,
-- then the operation succeeds, and returns (just sym-info).
-- this only returns nothing in the case that the opening didnt make sense:
-- you tried to open a term def, you tried to open an unknown def, etc...
-- basically any situation where the def wasnt a "proper" type def
spanM-clarify-def : opacity → var → spanM (maybe sym-info)
spanM-clarify-def o x Γ ss = returnM (result (ctxt-clarify-def Γ o x))
where
result : maybe (sym-info × ctxt) → (maybe sym-info × ctxt × spans)
result (just (si , Γ')) = ( just si , Γ' , ss )
result nothing = ( nothing , Γ , ss )
spanM-restore-clarified-def : var → sym-info → spanM ⊤
spanM-restore-clarified-def x si Γ ss = returnM (triv , ctxt-set-sym-info Γ x si , ss)
-- restore ctxt-info for the variable with given posinfo
spanM-restore-info : var → restore-def → spanM ⊤
spanM-restore-info v rd Γ ss = returnM (triv , ctxt-restore-info Γ v (fst rd) (snd rd) , ss)
_≫=span_ : ∀{A B : Set} → spanM A → (A → spanM B) → spanM B
(m₁ ≫=span m₂) ss Γ = m₁ ss Γ ≫=monad λ where (v , Γ , ss) → m₂ v Γ ss
_≫span_ : ∀{A B : Set} → spanM A → spanM B → spanM B
(m₁ ≫span m₂) = m₁ ≫=span (λ _ → m₂)
spanM-restore-info* : 𝕃 (var × restore-def) → spanM ⊤
spanM-restore-info* [] = spanMok
spanM-restore-info* ((v , qi , m) :: s) = spanM-restore-info v (qi , m) ≫span spanM-restore-info* s
infixl 2 _≫span_ _≫=span_ _≫=spanj_ _≫=spanm_ _≫=spanm'_ _≫=spanc_ _≫=spanc'_ _≫spanc_ _≫spanc'_
_≫=spanj_ : ∀{A : Set} → spanM (maybe A) → (A → spanM ⊤) → spanM ⊤
_≫=spanj_{A} m m' = m ≫=span cont
where cont : maybe A → spanM ⊤
cont nothing = spanMok
cont (just x) = m' x
-- discard changes made by the first computation
_≫=spand_ : ∀{A B : Set} → spanM A → (A → spanM B) → spanM B
_≫=spand_{A} m m' Γ ss = m Γ ss ≫=monad λ where (v , _ , _) → m' v Γ ss
-- discard *spans* generated by first computation
_≫=spands_ : ∀ {A B : Set} → spanM A → (A → spanM B) → spanM B
_≫=spands_ m f Γ ss = m Γ ss ≫=monad λ where (v , Γ , _ ) → f v Γ ss
_≫=spanm_ : ∀{A : Set} → spanM (maybe A) → (A → spanM (maybe A)) → spanM (maybe A)
_≫=spanm_{A} m m' = m ≫=span cont
where cont : maybe A → spanM (maybe A)
cont nothing = spanMr nothing
cont (just a) = m' a
_≫=spans'_ : ∀ {A B E : Set} → spanM (E ∨ A) → (A → spanM (E ∨ B)) → spanM (E ∨ B)
_≫=spans'_ m f = m ≫=span λ where
(inj₁ e) → spanMr (inj₁ e)
(inj₂ a) → f a
_≫=spanm'_ : ∀{A B : Set} → spanM (maybe A) → (A → spanM (maybe B)) → spanM (maybe B)
_≫=spanm'_{A}{B} m m' = m ≫=span cont
where cont : maybe A → spanM (maybe B)
cont nothing = spanMr nothing
cont (just a) = m' a
-- Currying/uncurry span binding
_≫=spanc_ : ∀{A B C} → spanM (A × B) → (A → B → spanM C) → spanM C
(m ≫=spanc m') Γ ss = m Γ ss ≫=monad λ where
((a , b) , Γ' , ss') → m' a b Γ' ss'
_≫=spanc'_ : ∀{A B C} → spanM (A × B) → (B → spanM C) → spanM C
(m ≫=spanc' m') Γ ss = m Γ ss ≫=monad λ where
((a , b) , Γ' , ss') → m' b Γ' ss'
_≫spanc'_ : ∀{A B} → spanM A → B → spanM (A × B)
(m ≫spanc' b) = m ≫=span λ a → spanMr (a , b)
_≫spanc_ : ∀{A B} → spanM A → spanM B → spanM (A × B)
(ma ≫spanc mb) = ma ≫=span λ a → mb ≫=span λ b → spanMr (a , b)
spanMok' : ∀{A} → A → spanM (⊤ × A)
spanMok' a = spanMr (triv , a)
_on-fail_≫=spanm'_ : ∀ {A B} → spanM (maybe A) → spanM B
→ (A → spanM B) → spanM B
_on-fail_≫=spanm'_ {A}{B} m fail f = m ≫=span cont
where cont : maybe A → spanM B
cont nothing = fail
cont (just x) = f x
_on-fail_≫=spans'_ : ∀ {A B E} → spanM (E ∨ A) → (E → spanM B) → (A → spanM B) → spanM B
_on-fail_≫=spans'_ {A}{B}{E} m fail f = m ≫=span cont
where cont : E ∨ A → spanM B
cont (inj₁ err) = fail err
cont (inj₂ a) = f a
_exit-early_≫=spans'_ = _on-fail_≫=spans'_
with-ctxt : ∀ {A} → ctxt → spanM A → spanM A
with-ctxt Γ sm
= get-ctxt λ Γ' → set-ctxt Γ
≫span sm
≫=span λ a → set-ctxt Γ'
≫span spanMr a
sequence-spanM : ∀ {A} → 𝕃 (spanM A) → spanM (𝕃 A)
sequence-spanM [] = spanMr []
sequence-spanM (sp :: sps)
= sp
≫=span λ x → sequence-spanM sps
≫=span λ xs → spanMr (x :: xs)
foldr-spanM : ∀ {A B} → (A → spanM B → spanM B) → spanM B → 𝕃 (spanM A) → spanM B
foldr-spanM f n [] = n
foldr-spanM f n (m :: ms)
= m ≫=span λ a → f a (foldr-spanM f n ms)
foldl-spanM : ∀ {A B} → (spanM B → A → spanM B) → spanM B → 𝕃 (spanM A) → spanM B
foldl-spanM f m [] = m
foldl-spanM f m (m' :: ms) =
m' ≫=span λ a → foldl-spanM f (f m a) ms
spanM-for_init_use_ : ∀ {A B} → 𝕃 (spanM A) → spanM B → (A → spanM B → spanM B) → spanM B
spanM-for xs init acc use f = foldr-spanM f acc xs
spanM-add : span → spanM ⊤
spanM-add s Γ ss = returnM (triv , Γ , add-span s ss)
spanM-addl : 𝕃 span → spanM ⊤
spanM-addl [] = spanMok
spanM-addl (s :: ss) = spanM-add s ≫span spanM-addl ss
debug-span : posinfo → posinfo → 𝕃 tagged-val → span
debug-span pi pi' tvs = mk-span "Debug" pi pi' tvs nothing
spanM-debug : posinfo → posinfo → 𝕃 tagged-val → spanM ⊤
--spanM-debug pi pi' tvs = spanM-add (debug-span pi pi' tvs)
spanM-debug pi pi' tvs = spanMok
to-string-tag-tk : (tag : string) → ctxt → tk → tagged-val
to-string-tag-tk t Γ (Tkt T) = to-string-tag t Γ T
to-string-tag-tk t Γ (Tkk k) = to-string-tag t Γ k
--------------------------------------------------
-- tagged-val constants
--------------------------------------------------
location-data : location → tagged-val
location-data (file-name , pi) = strRunTag "location" empty-ctxt (strAdd file-name ≫str strAdd " - " ≫str strAdd pi)
var-location-data : ctxt → var → tagged-val
var-location-data Γ @ (mk-ctxt _ _ i _ _) x =
location-data (maybe-else ("missing" , "missing") snd
(trie-lookup i x maybe-or trie-lookup i (qualif-var Γ x)))
{-
{-# TERMINATING #-}
var-location-data : ctxt → var → maybe language-level → tagged-val
var-location-data Γ x (just ll-term) with ctxt-var-location Γ x | qualif-term Γ (Var posinfo-gen x)
...| ("missing" , "missing") | (Var pi x') = location-data (ctxt-var-location Γ x')
...| loc | _ = location-data loc
var-location-data Γ x (just ll-type) with ctxt-var-location Γ x | qualif-type Γ (TpVar posinfo-gen x)
...| ("missing" , "missing") | (TpVar pi x') = location-data (ctxt-var-location Γ x')
...| loc | _ = location-data loc
var-location-data Γ x (just ll-kind) with ctxt-var-location Γ x | qualif-kind Γ (KndVar posinfo-gen x ArgsNil)
...| ("missing" , "missing") | (KndVar pi x' as) = location-data (ctxt-var-location Γ x')
...| loc | _ = location-data loc
var-location-data Γ x nothing with ctxt-lookup-term-var Γ x | ctxt-lookup-type-var Γ x | ctxt-lookup-kind-var-def Γ x
...| just _ | _ | _ = var-location-data Γ x (just ll-term)
...| _ | just _ | _ = var-location-data Γ x (just ll-type)
...| _ | _ | just _ = var-location-data Γ x (just ll-kind)
...| _ | _ | _ = location-data ("missing" , "missing")
-}
explain : string → tagged-val
explain = strRunTag "explanation" empty-ctxt ∘ strAdd
reason : string → tagged-val
reason = strRunTag "reason" empty-ctxt ∘ strAdd
expected-type : ctxt → type → tagged-val
expected-type = to-string-tag "expected-type"
expected-type-subterm : ctxt → type → tagged-val
expected-type-subterm = to-string-tag "expected-type of the subterm"
missing-expected-type : tagged-val
missing-expected-type = strRunTag "expected-type" empty-ctxt $ strAdd "[missing]"
-- hnf-type : ctxt → type → tagged-val
-- hnf-type Γ tp = to-string-tag "hnf of type" Γ (hnf-term-type Γ ff tp)
-- hnf-expected-type : ctxt → type → tagged-val
-- hnf-expected-type Γ tp = to-string-tag "hnf of expected type" Γ (hnf-term-type Γ ff tp)
expected-kind : ctxt → kind → tagged-val
expected-kind = to-string-tag "expected kind"
expected-kind-if : ctxt → maybe kind → 𝕃 tagged-val
expected-kind-if _ nothing = []
expected-kind-if Γ (just k) = [ expected-kind Γ k ]
expected-type-if : ctxt → maybe type → 𝕃 tagged-val
expected-type-if _ nothing = []
expected-type-if Γ (just tp) = [ expected-type Γ tp ]
-- hnf-expected-type-if : ctxt → maybe type → 𝕃 tagged-val
-- hnf-expected-type-if Γ nothing = []
-- hnf-expected-type-if Γ (just tp) = [ hnf-expected-type Γ tp ]
type-data : ctxt → type → tagged-val
type-data = to-string-tag "type"
missing-type : tagged-val
missing-type = strRunTag "type" empty-ctxt $ strAdd "[undeclared]"
warning-data : string → tagged-val
warning-data = strRunTag "warning" empty-ctxt ∘ strAdd
check-for-type-mismatch : ctxt → string → type → type → 𝕃 tagged-val × err-m
check-for-type-mismatch Γ s tp tp' =
let tp'' = hnf Γ unfold-head tp' tt in
expected-type Γ tp :: [ type-data Γ tp' ] ,
if conv-type Γ tp tp'' then nothing else just ("The expected type does not match the " ^ s ^ " type.")
check-for-type-mismatch-if : ctxt → string → maybe type → type → 𝕃 tagged-val × err-m
check-for-type-mismatch-if Γ s (just tp) = check-for-type-mismatch Γ s tp
check-for-type-mismatch-if Γ s nothing tp = [ type-data Γ tp ] , nothing
summary-data : {ed : exprd} → (name : string) → ctxt → ⟦ ed ⟧ → tagged-val
summary-data name Γ t = strRunTag "summary" Γ (strVar name ≫str strAdd " : " ≫str to-stringh t)
missing-kind : tagged-val
missing-kind = strRunTag "kind" empty-ctxt $ strAdd "[undeclared]"
head-kind : ctxt → kind → tagged-val
head-kind = to-string-tag "the kind of the head"
head-type : ctxt → type → tagged-val
head-type = to-string-tag "the type of the head"
arg-type : ctxt → type → tagged-val
arg-type = to-string-tag "computed arg type"
arg-exp-type : ctxt → type → tagged-val
arg-exp-type = to-string-tag "expected arg type"
type-app-head : ctxt → type → tagged-val
type-app-head = to-string-tag "the head"
term-app-head : ctxt → term → tagged-val
term-app-head = to-string-tag "the head"
term-argument : ctxt → term → tagged-val
term-argument = to-string-tag "the argument"
type-argument : ctxt → type → tagged-val
type-argument = to-string-tag "the argument"
contextual-type-argument : ctxt → type → tagged-val
contextual-type-argument = to-string-tag "contextual type arg"
arg-argument : ctxt → arg → tagged-val
arg-argument Γ (TermArg me x) = term-argument Γ x
arg-argument Γ (TypeArg x) = type-argument Γ x
kind-data : ctxt → kind → tagged-val
kind-data = to-string-tag "kind"
liftingType-data : ctxt → liftingType → tagged-val
liftingType-data = to-string-tag "lifting type"
kind-data-if : ctxt → maybe kind → 𝕃 tagged-val
kind-data-if Γ (just k) = [ kind-data Γ k ]
kind-data-if _ nothing = []
super-kind-data : tagged-val
super-kind-data = strRunTag "superkind" empty-ctxt $ strAdd "□"
symbol-data : string → tagged-val
symbol-data = strRunTag "symbol" empty-ctxt ∘ strAdd
tk-data : ctxt → tk → tagged-val
tk-data Γ (Tkk k) = kind-data Γ k
tk-data Γ (Tkt t) = type-data Γ t
checking-to-string : checking-mode → string
checking-to-string checking = "checking"
checking-to-string synthesizing = "synthesizing"
checking-to-string untyped = "untyped"
checking-data : checking-mode → tagged-val
checking-data = strRunTag "checking-mode" empty-ctxt ∘' strAdd ∘' checking-to-string
checked-meta-var : var → tagged-val
checked-meta-var = strRunTag "checked meta-var" empty-ctxt ∘ strAdd
ll-data : language-level → tagged-val
ll-data = strRunTag "language-level" empty-ctxt ∘' strAdd ∘' ll-to-string
ll-data-term = ll-data ll-term
ll-data-type = ll-data ll-type
ll-data-kind = ll-data ll-kind
{-
binder-data : ℕ → tagged-val
binder-data n = "binder" , [[ ℕ-to-string n ]] , []
-- this is the subterm position in the parse tree (as determined by
-- spans) for the bound variable of a binder
binder-data-const : tagged-val
binder-data-const = binder-data 0
bound-data : defTermOrType → ctxt → tagged-val
bound-data (DefTerm pi v mtp t) Γ = to-string-tag "bound-value" Γ t
bound-data (DefType pi v k tp) Γ = to-string-tag "bound-value" Γ tp
-}
binder-data : ctxt → posinfo → var → (atk : tk) → maybeErased → maybe (if tk-is-type atk then term else type) → (from to : posinfo) → tagged-val
binder-data Γ pi x atk me val s e =
strRunTag "binder" Γ $
strAdd "symbol:" ≫str --strAdd "{\\\\\"symbol\\\\\":\\\\\"" ≫str
strAdd x ≫str --strAdd "\\\\\"," ≫str
atk-val atk val ≫str
strAdd "§from:" ≫str --strAdd ",\\\\\"from\\\\\":" ≫str
strAdd s ≫str
strAdd "§to:" ≫str --strAdd ",\\\\\"to\\\\\":" ≫str
strAdd e ≫str
loc ≫str
erased?
--strAdd "}"
where
loc : strM
{-loc = maybe-else' (ctxt-get-info (qualif-var Γ x) Γ) strEmpty $ λ where
(_ , fn , pi) →
strAdd "§fn:" ≫str --strAdd ",\\\\\"fn\\\\\":\\\\\"" ≫str
strAdd fn ≫str
strAdd "§pos:" ≫str --strAdd "\\\\\",\\\\\"pos\\\\\":" ≫str
strAdd pi-}
loc = strAdd "§fn:" ≫str strAdd (ctxt-get-current-filename Γ) ≫str strAdd "§pos:" ≫str strAdd pi
erased? : strM
erased? =
strAdd "§erased:" ≫str --strAdd ",\\\\\"erased\\\\\":" ≫str
strAdd (if me then "true" else "false")
val? : ∀ {ed} → maybe ⟦ ed ⟧ → strM
val? = maybe-else strEmpty λ x →
strAdd "§value:" ≫str --strAdd "\\\\\",\\\\\"value\\\\\":\\\\\"" ≫str
to-stringh x
atk-val : (atk : tk) → maybe (if tk-is-type atk then term else type) → strM
atk-val (Tkt T) t? =
strAdd "§type:" ≫str --strAdd "\\\\\"type\\\\\":\\\\\"" ≫str
to-stringh T ≫str
val? t? -- ≫str
--strAdd "\\\\\""
atk-val (Tkk k) T? =
strAdd "§kind:" ≫str --strAdd "\\\\\"kind\\\\\":\\\\\"" ≫str
to-stringh k ≫str
val? T? -- ≫str
--strAdd "\\\\\""
punctuation-data : tagged-val
punctuation-data = strRunTag "punctuation" empty-ctxt $ strAdd "true"
not-for-navigation : tagged-val
not-for-navigation = strRunTag "not-for-navigation" empty-ctxt $ strAdd "true"
is-erased : type → 𝔹
is-erased (TpVar _ _ ) = tt
is-erased _ = ff
keywords = "keywords"
--keyword-erased = "erased"
--keyword-noterased = "noterased"
keyword-application = "application"
keyword-locale = "meta-var-locale"
--noterased : tagged-val
--noterased = keywords , [[ keyword-noterased ]] , []
keywords-data : 𝕃 string → tagged-val
keywords-data kws = keywords , h kws , [] where
h : 𝕃 string → rope
h [] = [[]]
h (k :: []) = [[ k ]]
h (k :: ks) = [[ k ]] ⊹⊹ [[ " " ]] ⊹⊹ h ks
{-
keywords-data-var : maybeErased → tagged-val
keywords-data-var e =
keywords , [[ if e then keyword-erased else keyword-noterased ]] , []
-}
keywords-app : (is-locale : 𝔹) → tagged-val
keywords-app l = keywords-data ([ keyword-application ] ++ (if l then [ keyword-locale ] else []))
keywords-app-if-typed : checking-mode → (is-locale : 𝔹) → 𝕃 tagged-val
keywords-app-if-typed untyped l = []
keywords-app-if-typed _ l = [ keywords-app l ]
error-if-not-eq : ctxt → type → 𝕃 tagged-val → 𝕃 tagged-val × err-m
error-if-not-eq Γ (TpEq pi t1 t2 pi') tvs = expected-type Γ (TpEq pi t1 t2 pi') :: tvs , nothing
error-if-not-eq Γ tp tvs = expected-type Γ tp :: tvs , just "This term is being checked against the following type, but an equality type was expected"
error-if-not-eq-maybe : ctxt → maybe type → 𝕃 tagged-val → 𝕃 tagged-val × err-m
error-if-not-eq-maybe Γ (just tp) = error-if-not-eq Γ tp
error-if-not-eq-maybe _ _ tvs = tvs , nothing
params-data : ctxt → params → 𝕃 tagged-val
params-data _ [] = []
params-data Γ ps = [ params-to-string-tag "parameters" Γ ps ]
--------------------------------------------------
-- span-creating functions
--------------------------------------------------
Star-name : string
Star-name = "Star"
parens-span : posinfo → posinfo → span
parens-span pi pi' = mk-span "parentheses" pi pi' [] nothing
data decl-class : Set where
param : decl-class
index : decl-class
decl-class-name : decl-class → string
decl-class-name param = "parameter"
decl-class-name index = "index"
Decl-span : ctxt → decl-class → posinfo → posinfo → var → tk → maybeErased → posinfo → span
Decl-span Γ dc pi pi' v atk me pi'' = mk-span ((if tk-is-type atk then "Term " else "Type ") ^ (decl-class-name dc))
pi pi'' [ binder-data Γ pi' v atk me nothing (tk-end-pos atk) pi'' ] nothing
TpVar-span : ctxt → posinfo → string → checking-mode → 𝕃 tagged-val → err-m → span
TpVar-span Γ pi v check tvs =
mk-span name pi (posinfo-plus-str pi (unqual-local v))
(checking-data check :: ll-data-type :: var-location-data Γ v :: symbol-data (unqual-local v) :: tvs)
where
v' = unqual-local v
name = if isJust (data-lookup Γ (qualif-var Γ v') [])
then "Datatype variable" else "Type variable"
Var-span : ctxt → posinfo → string → checking-mode → 𝕃 tagged-val → err-m → span
Var-span Γ pi v check tvs =
mk-span name pi (posinfo-plus-str pi v')
(checking-data check :: ll-data-term :: var-location-data Γ v :: symbol-data v' :: tvs)
where
v' = unqual-local v
name : string
name with qual-lookup Γ v'
...| just (_ , ctr-def _ _ _ _ _ , _) = "Constructor variable"
...| _ = "Term variable"
KndVar-span : ctxt → (posinfo × var) → (end-pi : posinfo) → params → checking-mode → 𝕃 tagged-val → err-m → span
KndVar-span Γ (pi , v) pi' ps check tvs =
mk-span "Kind variable" pi pi'
(checking-data check :: ll-data-kind :: var-location-data Γ v :: symbol-data (unqual-local v) :: super-kind-data :: (params-data Γ ps ++ tvs))
var-span-with-tags : maybeErased → ctxt → posinfo → string → checking-mode → tk → 𝕃 tagged-val → err-m → span
var-span-with-tags _ Γ pi x check (Tkk k) tags = TpVar-span Γ pi x check ({-keywords-data-var ff ::-} [ kind-data Γ k ] ++ tags)
var-span-with-tags e Γ pi x check (Tkt t) tags = Var-span Γ pi x check ({-keywords-data-var e ::-} [ type-data Γ t ] ++ tags)
var-span : maybeErased → ctxt → posinfo → string → checking-mode → tk → err-m → span
var-span e Γ pi x check tk = var-span-with-tags e Γ pi x check tk []
redefined-var-span : ctxt → posinfo → var → span
redefined-var-span Γ pi x = mk-span "Variable definition" pi (posinfo-plus-str pi x)
[ var-location-data Γ x ] (just "This symbol was defined already.")
TpAppt-span : type → term → checking-mode → 𝕃 tagged-val → err-m → span
TpAppt-span tp t check tvs = mk-span "Application of a type to a term" (type-start-pos tp) (term-end-pos t) (checking-data check :: ll-data-type :: tvs)
TpApp-span : type → type → checking-mode → 𝕃 tagged-val → err-m → span
TpApp-span tp tp' check tvs = mk-span "Application of a type to a type" (type-start-pos tp) (type-end-pos tp') (checking-data check :: ll-data-type :: tvs)
App-span : (is-locale : 𝔹) → term → term → checking-mode → 𝕃 tagged-val → err-m → span
App-span l t t' check tvs = mk-span "Application of a term to a term" (term-start-pos t) (term-end-pos t') (checking-data check :: ll-data-term :: keywords-app-if-typed check l ++ tvs)
AppTp-span : term → type → checking-mode → 𝕃 tagged-val → err-m → span
AppTp-span t tp check tvs = mk-span "Application of a term to a type" (term-start-pos t) (type-end-pos tp) (checking-data check :: ll-data-term :: keywords-app-if-typed check ff ++ tvs)
TpQuant-e = 𝔹
is-pi : TpQuant-e
is-pi = tt
TpQuant-span : ctxt → TpQuant-e → posinfo → posinfo → var → tk → type → checking-mode → 𝕃 tagged-val → err-m → span
TpQuant-span Γ is-pi pi pi' x atk body check tvs err =
let err-if-type-pi = if ~ tk-is-type atk && is-pi then just "Π-types must bind a term, not a type (use ∀ instead)" else nothing in
mk-span (if is-pi then "Dependent function type" else "Implicit dependent function type")
pi (type-end-pos body) (checking-data check :: ll-data-type :: binder-data Γ pi' x atk (~ is-pi) nothing (type-start-pos body) (type-end-pos body) :: tvs) (if isJust err-if-type-pi then err-if-type-pi else err)
TpLambda-span : ctxt → posinfo → posinfo → var → tk → type → checking-mode → 𝕃 tagged-val → err-m → span
TpLambda-span Γ pi pi' x atk body check tvs =
mk-span "Type-level lambda abstraction" pi (type-end-pos body)
(checking-data check :: ll-data-type :: binder-data Γ pi' x atk NotErased nothing (type-start-pos body) (type-end-pos body) :: tvs)
Iota-span : ctxt → posinfo → posinfo → var → type → checking-mode → 𝕃 tagged-val → err-m → span
Iota-span Γ pi pi' x t2 check tvs = mk-span "Iota-abstraction" pi (type-end-pos t2) (explain "A dependent intersection type" :: checking-data check :: binder-data Γ pi' x (Tkt t2) ff nothing (type-start-pos t2) (type-end-pos t2) :: ll-data-type :: tvs)
TpArrow-span : type → type → checking-mode → 𝕃 tagged-val → err-m → span
TpArrow-span t1 t2 check tvs = mk-span "Arrow type" (type-start-pos t1) (type-end-pos t2) (checking-data check :: ll-data-type :: tvs)
TpEq-span : posinfo → term → term → posinfo → checking-mode → 𝕃 tagged-val → err-m → span
TpEq-span pi t1 t2 pi' check tvs = mk-span "Equation" pi pi'
(explain "Equation between terms" :: checking-data check :: ll-data-type :: tvs)
Star-span : posinfo → checking-mode → err-m → span
Star-span pi check = mk-span Star-name pi (posinfo-plus pi 1) (checking-data check :: [ ll-data-kind ])
KndPi-span : ctxt → posinfo → posinfo → var → tk → kind → checking-mode → err-m → span
KndPi-span Γ pi pi' x atk k check =
mk-span "Pi kind" pi (kind-end-pos k)
(checking-data check :: ll-data-kind :: binder-data Γ pi' x atk ff nothing (kind-start-pos k) (kind-end-pos k) :: [ super-kind-data ])
KndArrow-span : kind → kind → checking-mode → err-m → span
KndArrow-span k k' check = mk-span "Arrow kind" (kind-start-pos k) (kind-end-pos k') (checking-data check :: ll-data-kind :: [ super-kind-data ])
KndTpArrow-span : type → kind → checking-mode → err-m → span
KndTpArrow-span t k check = mk-span "Arrow kind" (type-start-pos t) (kind-end-pos k) (checking-data check :: ll-data-kind :: [ super-kind-data ])
{- [[file:../cedille-mode.el::(defun%20cedille-mode-filter-out-special(data)][Frontend]] -}
special-tags : 𝕃 string
special-tags =
"symbol" :: "location" :: "language-level" :: "checking-mode" :: "summary"
:: "binder" :: "bound-value" :: "keywords" :: []
error-span-filter-special : error-span → error-span
error-span-filter-special (mk-error-span dsc pi pi' tvs msg) =
mk-error-span dsc pi pi' tvs' msg
where tvs' = (flip filter) tvs λ tag → list-any (_=string (fst tag)) special-tags
erasure : ctxt → term → tagged-val
erasure Γ t = to-string-tag "erasure" Γ (erase-term t)
erased-marg-span : ctxt → term → maybe type → span
erased-marg-span Γ t mtp = mk-span "Erased module parameter" (term-start-pos t) (term-end-pos t)
(maybe-else [] (λ tp → [ type-data Γ tp ]) mtp)
(just "An implicit module parameter variable occurs free in the erasure of the term.")
Lam-span-erased : maybeErased → string
Lam-span-erased Erased = "Erased lambda abstraction (term-level)"
Lam-span-erased NotErased = "Lambda abstraction (term-level)"
Lam-span : ctxt → checking-mode → posinfo → posinfo → maybeErased → var → tk → term → 𝕃 tagged-val → err-m → span
Lam-span Γ c pi pi' NotErased x {-(SomeClass-} (Tkk k) {-)-} t tvs e =
mk-span (Lam-span-erased NotErased) pi (term-end-pos t) (ll-data-term :: binder-data Γ pi' x (Tkk k) NotErased nothing (term-start-pos t) (term-end-pos t) :: checking-data c :: tvs) (e maybe-or just "λ-terms must bind a term, not a type (use Λ instead)")
--Lam-span Γ c pi l x NoClass t tvs = mk-span (Lam-span-erased l) pi (term-end-pos t) (ll-data-term :: binder-data Γ x :: checking-data c :: tvs)
Lam-span Γ c pi pi' l x {-(SomeClass-} atk {-)-} t tvs = mk-span (Lam-span-erased l) pi (term-end-pos t)
((ll-data-term :: binder-data Γ pi' x atk l nothing (term-start-pos t) (term-end-pos t) :: checking-data c :: tvs)
++ bound-tp atk)
where
bound-tp : tk → 𝕃 tagged-val
bound-tp (Tkt (TpHole _)) = []
bound-tp atk = [ to-string-tag-tk "type of bound variable" Γ atk ]
compileFail-in : ctxt → term → 𝕃 tagged-val × err-m
compileFail-in Γ t with is-free-in check-erased compileFail-qual | qualif-term Γ t
...| is-free | tₒ with erase-term tₒ | hnf Γ unfold-all tₒ ff
...| tₑ | tₙ with is-free tₒ
...| ff = [] , nothing
...| tt with is-free tₙ | is-free tₑ
...| tt | _ = [ to-string-tag "normalized term" Γ tₙ ] , just "compileFail occurs in the normalized term"
...| ff | ff = [ to-string-tag "the term" Γ tₒ ] , just "compileFail occurs in an erased position"
...| ff | tt = [] , nothing
DefTerm-span : ctxt → posinfo → var → (checked : checking-mode) → maybe type → term → posinfo → 𝕃 tagged-val → span
DefTerm-span Γ pi x checked tp t pi' tvs =
h ((h-summary tp) ++ ({-erasure Γ t ::-} tvs)) pi x checked tp pi'
where h : 𝕃 tagged-val → posinfo → var → (checked : checking-mode) → maybe type → posinfo → span
h tvs pi x checking _ pi' =
mk-span "Term-level definition (checking)" pi pi' tvs nothing
h tvs pi x _ (just tp) pi' =
mk-span "Term-level definition (synthesizing)" pi pi' (to-string-tag "synthesized type" Γ tp :: tvs) nothing
h tvs pi x _ nothing pi' =
mk-span "Term-level definition (synthesizing)" pi pi' ((strRunTag "synthesized type" empty-ctxt $ strAdd "[nothing]") :: tvs) nothing
h-summary : maybe type → 𝕃 tagged-val
h-summary nothing = [(checking-data synthesizing)]
h-summary (just tp) = (checking-data checking :: [ summary-data x Γ tp ])
CheckTerm-span : ctxt → (checked : checking-mode) → maybe type → term → posinfo → 𝕃 tagged-val → span
CheckTerm-span Γ checked tp t pi' tvs =
h ({-erasure Γ t ::-} tvs) checked tp (term-start-pos t) pi'
where h : 𝕃 tagged-val → (checked : checking-mode) → maybe type → posinfo → posinfo → span
h tvs checking _ pi pi' =
mk-span "Checking a term" pi pi' (checking-data checking :: tvs) nothing
h tvs _ (just tp) pi pi' =
mk-span "Synthesizing a type for a term" pi pi' (checking-data synthesizing :: to-string-tag "synthesized type" Γ tp :: tvs) nothing
h tvs _ nothing pi pi' =
mk-span "Synthesizing a type for a term" pi pi' (checking-data synthesizing :: (strRunTag "synthesized type" empty-ctxt $ strAdd "[nothing]") :: tvs) nothing
normalized-type : ctxt → type → tagged-val
normalized-type = to-string-tag "normalized type"
DefType-span : ctxt → posinfo → var → (checked : checking-mode) → maybe kind → type → posinfo → 𝕃 tagged-val → span
DefType-span Γ pi x checked mk tp pi' tvs =
h ((h-summary mk) ++ tvs) checked mk
where h : 𝕃 tagged-val → checking-mode → maybe kind → span
h tvs checking _ = mk-span "Type-level definition (checking)" pi pi' tvs nothing
h tvs _ (just k) =
mk-span "Type-level definition (synthesizing)" pi pi' (to-string-tag "synthesized kind" Γ k :: tvs) nothing
h tvs _ nothing =
mk-span "Type-level definition (synthesizing)" pi pi' ( (strRunTag "synthesized kind" empty-ctxt $ strAdd "[nothing]") :: tvs) nothing
h-summary : maybe kind → 𝕃 tagged-val
h-summary nothing = [(checking-data synthesizing)]
h-summary (just k) = (checking-data checking :: [ summary-data x Γ k ])
DefKind-span : ctxt → posinfo → var → kind → posinfo → span
DefKind-span Γ pi x k pi' = mk-span "Kind-level definition" pi pi' (kind-data Γ k :: [ summary-data x Γ (Var pi "□") ]) nothing
DefDatatype-span : ctxt → posinfo → posinfo → var → params → (reg Mu bound : kind) → (mu : type) → (cast : type) → ctrs → posinfo → span
DefDatatype-span Γ pi pi' x ps k kₘᵤ kₓ Tₘᵤ Tₜₒ cs pi'' =
mk-span "Datatype definition" pi pi'' (binder-data Γ pi' x (Tkk kₓ) ff nothing (kind-end-pos k) pi'' :: summary-data x Γ k :: summary-data (data-Is/ x) Γ kₘᵤ :: summary-data (data-is/ x) Γ Tₘᵤ :: summary-data (data-to/ x) Γ Tₜₒ :: to-string-tag (data-Is/ x) Γ kₘᵤ :: to-string-tag (data-is/ x) Γ Tₘᵤ :: to-string-tag (data-to/ x) Γ Tₜₒ :: []) nothing
{-unchecked-term-span : term → span
unchecked-term-span t = mk-span "Unchecked term" (term-start-pos t) (term-end-pos t)
(ll-data-term :: not-for-navigation :: [ explain "This term has not been type-checked."]) nothing-}
Beta-span : posinfo → posinfo → checking-mode → 𝕃 tagged-val → err-m → span
Beta-span pi pi' check tvs = mk-span "Beta axiom" pi pi'
(checking-data check :: ll-data-term :: explain "A term constant whose type states that β-equal terms are provably equal" :: tvs)
hole-span : ctxt → posinfo → maybe type → 𝕃 tagged-val → span
hole-span Γ pi tp tvs =
mk-span "Hole" pi (posinfo-plus pi 1)
(ll-data-term :: expected-type-if Γ tp ++ tvs)
(just "This hole remains to be filled in")
tp-hole-span : ctxt → posinfo → maybe kind → 𝕃 tagged-val → span
tp-hole-span Γ pi k tvs =
mk-span "Hole" pi (posinfo-plus pi 1)
(ll-data-term :: expected-kind-if Γ k ++ tvs)
(just "This hole remains to be filled in")
expected-to-string : checking-mode → string
expected-to-string checking = "expected"
expected-to-string synthesizing = "synthesized"
expected-to-string untyped = "untyped"
Epsilon-span : posinfo → leftRight → maybeMinus → term → checking-mode → 𝕃 tagged-val → err-m → span
Epsilon-span pi lr m t check tvs = mk-span "Epsilon" pi (term-end-pos t)
(checking-data check :: ll-data-term :: tvs ++
[ explain ("Normalize " ^ side lr ^ " of the "
^ expected-to-string check ^ " equation, using " ^ maybeMinus-description m
^ " reduction." ) ])
where side : leftRight → string
side Left = "the left-hand side"
side Right = "the right-hand side"
side Both = "both sides"
maybeMinus-description : maybeMinus → string
maybeMinus-description EpsHnf = "head"
maybeMinus-description EpsHanf = "head-applicative"
optGuide-spans : optGuide → checking-mode → spanM ⊤
optGuide-spans NoGuide _ = spanMok
optGuide-spans (Guide pi x tp) expected =
get-ctxt λ Γ → spanM-add (Var-span Γ pi x expected [] nothing)
Rho-span : posinfo → term → term → checking-mode → rhoHnf → ℕ ⊎ var → 𝕃 tagged-val → err-m → span
Rho-span pi t t' expected r (inj₂ x) tvs =
mk-span "Rho" pi (term-end-pos t')
(checking-data expected :: ll-data-term :: explain ("Rewrite all places where " ^ x ^ " occurs in the " ^ expected-to-string expected ^ " type, using an equation. ") :: tvs)
Rho-span pi t t' expected r (inj₁ numrewrites) tvs err =
mk-span "Rho" pi (term-end-pos t')
(checking-data expected :: ll-data-term :: tvs ++
(explain ("Rewrite terms in the "
^ expected-to-string expected ^ " type, using an equation. "
^ (if r then "" else "Do not ") ^ "Beta-reduce the type as we look for matches.") :: fst h)) (snd h)
where h : 𝕃 tagged-val × err-m
h = if isJust err
then [] , err
else if numrewrites =ℕ 0
then [] , just "No rewrites could be performed."
else [ strRunTag "Number of rewrites" empty-ctxt (strAdd $ ℕ-to-string numrewrites) ] , err
Phi-span : posinfo → posinfo → checking-mode → 𝕃 tagged-val → err-m → span
Phi-span pi pi' expected tvs = mk-span "Phi" pi pi' (checking-data expected :: ll-data-term :: tvs)
Chi-span : ctxt → posinfo → optType → term → checking-mode → 𝕃 tagged-val → err-m → span
Chi-span Γ pi m t' check tvs = mk-span "Chi" pi (term-end-pos t') (ll-data-term :: checking-data check :: tvs ++ helper m)
where helper : optType → 𝕃 tagged-val
helper (SomeType T) = explain ("Check a term against an asserted type") :: [ to-string-tag "the asserted type" Γ T ]
helper NoType = [ explain ("Change from checking mode (outside the term) to synthesizing (inside)") ]
Sigma-span : posinfo → term → checking-mode → 𝕃 tagged-val → err-m → span
Sigma-span pi t check tvs =
mk-span "Sigma" pi (term-end-pos t)
(ll-data-term :: checking-data check :: explain "Swap the sides of the equation synthesized for the body of this term" :: tvs)
Delta-span : ctxt → posinfo → optType → term → checking-mode → 𝕃 tagged-val → err-m → span
Delta-span Γ pi T t check tvs =
mk-span "Delta" pi (term-end-pos t)
(ll-data-term :: explain "Prove anything you want from a contradiction" :: checking-data check :: tvs)
Open-span : ctxt → opacity → posinfo → var → term → checking-mode → 𝕃 tagged-val → err-m → span
Open-span Γ o pi x t check tvs =
elim-pair (if o iff OpacTrans
then ("Open" , "Open an opaque definition")
else ("Close" , "Hide a definition")) λ name expl →
mk-span name pi (term-end-pos t)
(ll-data-term :: explain expl :: checking-data check :: tvs)
motive-label : string
motive-label = "the motive"
the-motive : ctxt → type → tagged-val
the-motive = to-string-tag motive-label
Theta-span : ctxt → posinfo → theta → term → lterms → checking-mode → 𝕃 tagged-val → err-m → span
Theta-span Γ pi u t ls check tvs = mk-span "Theta" pi (lterms-end-pos (term-end-pos t) ls) (ll-data-term :: checking-data check :: tvs ++ do-explain u)
where do-explain : theta → 𝕃 tagged-val
do-explain Abstract = [ explain ("Perform an elimination with the first term, after abstracting it from the expected type.") ]
do-explain (AbstractVars vs) = [ strRunTag "explanation" Γ (strAdd "Perform an elimination with the first term, after abstracting the listed variables (" ≫str vars-to-string vs ≫str strAdd ") from the expected type.") ]
do-explain AbstractEq = [ explain ("Perform an elimination with the first term, after abstracting it with an equation "
^ "from the expected type.") ]
Mu-span : ctxt → posinfo → maybe var → posinfo → (motive? : maybe type) → checking-mode → 𝕃 tagged-val → err-m → span
Mu-span Γ pi x? pi' motive? check tvs = mk-span (if isJust x? then "Mu" else "Mu'") pi pi' (ll-data-term :: checking-data check :: explain ("Pattern match on a term" ^ (if isJust motive? then ", with a motive" else "")) :: tvs)
pattern-ctr-span : ctxt → posinfo → var → caseArgs → maybe type → err-m → span
pattern-ctr-span Γ pi x as tp =
let x' = unqual-local x in
mk-span "Pattern constructor" pi (posinfo-plus-str pi x') (checking-data synthesizing :: var-location-data Γ x :: ll-data-term :: symbol-data x' :: maybe-else' tp [] (λ tp → params-to-string-tag "args" Γ (rename-to-args empty-renamectxt as $ fst $ decompose-arrows Γ tp) :: []))
where
open import rename
rename-to-args : renamectxt → caseArgs → params → params
rename-to-args ρ (CaseTermArg _ _ x :: as) (Decl pi pi' me x' atk pi'' :: ps) =
Decl pi pi' me x (subst-renamectxt Γ ρ atk) pi'' ::
rename-to-args (renamectxt-insert ρ x' x) as ps
rename-to-args ρ (CaseTypeArg _ x :: as) (Decl pi pi' me x' atk pi'' :: ps) =
Decl pi pi' me x (subst-renamectxt Γ ρ atk) pi'' ::
rename-to-args (renamectxt-insert ρ x' x) as ps
rename-to-args ρ [] (Decl pi pi' me x atk pi'' :: ps) =
Decl pi pi' me x (subst-renamectxt Γ ρ atk) pi'' ::
rename-to-args (renamectxt-insert ρ x x) [] ps
rename-to-args ρ as ps = ps
Lft-span : ctxt → posinfo → posinfo → var → term → checking-mode → 𝕃 tagged-val → err-m → span
Lft-span Γ pi pi' X t check tvs = mk-span "Lift type" pi (term-end-pos t) (checking-data check :: ll-data-type :: binder-data Γ pi' X (Tkk star) tt nothing (term-start-pos t) (term-end-pos t) :: tvs)
File-span : ctxt → posinfo → posinfo → string → span
File-span Γ pi pi' filename = mk-span ("Cedille source file (" ^ filename ^ ")") pi pi' (print-file-id-table Γ) nothing
Module-span : posinfo → posinfo → span
Module-span pi pi' = mk-span "Module declaration" pi pi' [ not-for-navigation ] nothing
Module-header-span : posinfo → posinfo → span
Module-header-span pi pi' = mk-span "Module header" pi pi' [ not-for-navigation ] nothing
DefDatatype-header-span : posinfo → span
DefDatatype-header-span pi = mk-span "Data" pi (posinfo-plus-str pi "data") [ not-for-navigation ] nothing
Import-span : posinfo → string → posinfo → 𝕃 tagged-val → err-m → span
Import-span pi file pi' tvs = mk-span ("Import of another source file") pi pi' (("Path" , [[ file ]] , []) :: location-data (file , first-position) :: tvs)
Import-module-span : ctxt → (posinfo × var) → params → 𝕃 tagged-val → err-m → span
Import-module-span Γ (pi , mn) ps tvs = mk-span "Imported module" pi (posinfo-plus-str pi mn) (params-data Γ ps ++ tvs)
punctuation-span : string → posinfo → posinfo → span
punctuation-span name pi pi' = mk-span name pi pi' ( punctuation-data :: not-for-navigation :: [] ) nothing
whitespace-span : posinfo → posinfo → span
whitespace-span pi pi' = mk-span "Whitespace" pi pi' [ not-for-navigation ] nothing
comment-span : posinfo → posinfo → span
comment-span pi pi' = mk-span "Comment" pi pi' [ not-for-navigation ] nothing
IotaPair-span : posinfo → posinfo → checking-mode → 𝕃 tagged-val → err-m → span
IotaPair-span pi pi' c tvs =
mk-span "Iota pair" pi pi' (explain "Inhabit a iota-type (dependent intersection type)." :: checking-data c :: ll-data-term :: tvs)
IotaProj-span : term → posinfo → checking-mode → 𝕃 tagged-val → err-m → span
IotaProj-span t pi' c tvs = mk-span "Iota projection" (term-start-pos t) pi' (checking-data c :: ll-data-term :: tvs)
-- <<<<<<< HEAD
Let-span : ctxt → checking-mode → posinfo → posinfo → forceErased → var → (atk : tk) → (if tk-is-type atk then term else type) → term → 𝕃 tagged-val → err-m → span
Let-span Γ c pi pi' fe x atk val t' tvs =
mk-span name pi (term-end-pos t') (binder-data Γ pi' x atk ff (just val) (term-start-pos t') (term-end-pos t') :: ll-data-term :: checking-data c :: tvs)
where name = if fe then "Erased Term Let" else "Term Let"
-- =======
-- Let-span : ctxt → checking-mode → posinfo → forceErased → defTermOrType → term → 𝕃 tagged-val → err-m → span
-- Let-span Γ c pi fe d t' tvs = mk-span name pi (term-end-pos t') (binder-data-const :: bound-data d Γ :: ll-data-term :: checking-data c :: tvs)
-- where name = if fe then "Erased Term Let" else "Term Let"
-- >>>>>>> master
TpLet-span : ctxt → checking-mode → posinfo → posinfo → var → (atk : tk) → (if tk-is-type atk then term else type) → type → 𝕃 tagged-val → err-m → span
TpLet-span Γ c pi pi' x atk val t' tvs =
mk-span "Type Let" pi (type-end-pos t') (binder-data Γ pi' x atk ff (just val) (type-start-pos t') (type-end-pos t') :: ll-data-type :: checking-data c :: tvs)
| {
"alphanum_fraction": 0.6348741419,
"avg_line_length": 46.8884120172,
"ext": "agda",
"hexsha": "b407fbf714adfd5e601ee6589869447d3baa605e",
"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": "f5ce42258b7d9bc66f75cd679c785d6133b82b58",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CarlOlson/cedille",
"max_forks_repo_path": "src/spans.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f5ce42258b7d9bc66f75cd679c785d6133b82b58",
"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": "CarlOlson/cedille",
"max_issues_repo_path": "src/spans.agda",
"max_line_length": 352,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f5ce42258b7d9bc66f75cd679c785d6133b82b58",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CarlOlson/cedille",
"max_stars_repo_path": "src/spans.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 13740,
"size": 43700
} |
module Issue2749-2 where
-- testing unicode lambda and arrow
id : {A : Set} -> A -> A
id = {!!}
-- testing unicode double braces
it : {A : Set} {{a : A}} → A → A
it = {!!}
data B : Set where
mkB : B → B → B
-- testing unicode suffixes
left : B → B
left b₁ = {!!}
open import Agda.Builtin.Equality
-- testing ascii only forall
allq : (∀ m n → m ≡ n) ≡ {!!}
allq = refl
| {
"alphanum_fraction": 0.5771276596,
"avg_line_length": 16.347826087,
"ext": "agda",
"hexsha": "30bf6337c7b55fd94f9e0a9920fff1be1d406584",
"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/interaction/Issue2749-2.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/interaction/Issue2749-2.agda",
"max_line_length": 35,
"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/interaction/Issue2749-2.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": 129,
"size": 376
} |
open import Coinduction using ( ♯_ )
open import Relation.Binary.PropositionalEquality using ( _≡_ ; refl ; sym ; cong ; subst )
open import System.IO.Transducers.Lazy using ( _⇒_ ; inp ; out ; done ; ⟦_⟧ ; _≃_ )
open import System.IO.Transducers.Strict using ( Strict )
open import System.IO.Transducers.Session using ( Session ; I ; Σ ; _/_ )
open import System.IO.Transducers.Trace using ( Trace ; [] ; _∷_ ; _✓ ; _⊑_ )
open import System.IO.Transducers.Properties.Lemmas using ( I-η ; ⟦⟧-mono ; ⟦⟧-resp-✓ ; ⟦⟧-resp-[] )
open import System.IO.Transducers.Properties.Category using ( _≣_ ; ⟦⟧-refl-≣ )
module System.IO.Transducers.Properties.Equivalences where
open Relation.Binary.PropositionalEquality.≡-Reasoning
_//_ : ∀ S → (Trace S) → Session
S // [] = S
S // (a ∷ as) = (S / a) // as
suffix : ∀ {S} {as bs : Trace S} → (as ⊑ bs) → (Trace (S // as))
suffix {bs = bs} [] = bs
suffix (a ∷ as⊑bs) = suffix as⊑bs
_+++_ : ∀ {S} (as : Trace S) (bs : Trace (S // as)) → (Trace S)
[] +++ bs = bs
(a ∷ as) +++ bs = a ∷ (as +++ bs)
suffix-+++ : ∀ {S} {as : Trace S} {bs} (as⊑bs : as ⊑ bs) →
as +++ suffix as⊑bs ≡ bs
suffix-+++ [] = refl
suffix-+++ (a ∷ as⊑bs) = cong (_∷_ a) (suffix-+++ as⊑bs)
suffix-mono : ∀ {S} {as : Trace S} {bs cs} (as⊑bs : as ⊑ bs) (as⊑cs : as ⊑ cs) →
(bs ⊑ cs) → (suffix as⊑bs ⊑ suffix as⊑cs)
suffix-mono [] [] bs⊑cs = bs⊑cs
suffix-mono (.a ∷ as⊑bs) (.a ∷ as⊑cs) (a ∷ bs⊑cs) = suffix-mono as⊑bs as⊑cs bs⊑cs
suffix-resp-✓ : ∀ {S} {as : Trace S} {bs} (as⊑bs : as ⊑ bs) →
(bs ✓) → (suffix as⊑bs ✓)
suffix-resp-✓ [] bs✓ = bs✓
suffix-resp-✓ (.a ∷ as⊑bs) (a ∷ bs✓) = suffix-resp-✓ as⊑bs bs✓
suffix-[] : ∀ {S} {as : Trace S} (as⊑as : as ⊑ as) →
(suffix as⊑as ≡ [])
suffix-[] [] = refl
suffix-[] (a ∷ as⊑as) = suffix-[] as⊑as
strictify : ∀ {S T} (f : Trace S → Trace T) →
(∀ as bs → as ⊑ bs → f as ⊑ f bs) →
(Trace S → Trace (T // f []))
strictify f f-mono as = suffix (f-mono [] as [])
lazify : ∀ {S T} (f : Trace S → Trace T) a →
(Trace (S / a) → Trace T)
lazify f a as = f (a ∷ as)
strictify-mono : ∀ {S T} (f : Trace S → Trace T) f-mono →
(∀ as bs → as ⊑ bs → strictify f f-mono as ⊑ strictify f f-mono bs)
strictify-mono f f-mono as bs as⊑bs = suffix-mono (f-mono [] as []) (f-mono [] bs []) (f-mono as bs as⊑bs)
strictify-resp-✓ : ∀ {S T} (f : Trace S → Trace T) f-mono →
(∀ as → as ✓ → f as ✓) →
(∀ as → as ✓ → strictify f f-mono as ✓)
strictify-resp-✓ f f-mono f-resp-✓ as as✓ = suffix-resp-✓ (f-mono [] as []) (f-resp-✓ as as✓)
strictify-strict : ∀ {S T} (f : Trace S → Trace T) f-mono →
(strictify f f-mono [] ≡ [])
strictify-strict f f-mono = suffix-[] (f-mono [] [] [])
lazify-mono : ∀ {S T} (f : Trace S → Trace T) a →
(∀ as bs → as ⊑ bs → f as ⊑ f bs) →
(∀ as bs → as ⊑ bs → lazify f a as ⊑ lazify f a bs)
lazify-mono f a f-mono as bs as⊑bs = f-mono (a ∷ as) (a ∷ bs) (a ∷ as⊑bs)
lazify-resp-✓ : ∀ {S T} (f : Trace S → Trace T) a →
(∀ as → as ✓ → f as ✓) →
(∀ as → as ✓ → lazify f a as ✓)
lazify-resp-✓ f a f-resp-✓ as as✓ = f-resp-✓ (a ∷ as) (a ∷ as✓)
mutual
lazy' : ∀ {T S} bs (f : Trace S → Trace (T // bs)) →
(∀ as bs → as ⊑ bs → f as ⊑ f bs) →
(∀ as → as ✓ → f as ✓) → (f [] ≡ []) →
(S ⇒ T)
lazy' [] f f-mono f-resp-✓ f-strict = strict f f-mono f-resp-✓ f-strict
lazy' {Σ V F} (b ∷ bs) f f-mono f-resp-✓ f-strict = out b (lazy' bs f f-mono f-resp-✓ f-strict)
lazy' {I} (() ∷ bs) f f-mono f-resp-✓ f-strict
lazy : ∀ {T S} (f : Trace S → Trace T) →
(∀ as bs → as ⊑ bs → f as ⊑ f bs) →
(∀ as → as ✓ → f as ✓) →
(S ⇒ T)
lazy f f-mono f-resp-✓ = lazy' (f []) (strictify f f-mono) (strictify-mono f f-mono) (strictify-resp-✓ f f-mono f-resp-✓) (strictify-strict f f-mono)
strict : ∀ {S T} (f : Trace S → Trace T) →
(∀ as bs → as ⊑ bs → f as ⊑ f bs) →
(∀ as → as ✓ → f as ✓) → (f [] ≡ []) →
(S ⇒ T)
strict {I} {I} f f-mono f-resp-✓ f-strict = done
strict {Σ V F} f f-mono f-resp-✓ f-strict = inp (♯ λ a → lazy (lazify f a) (lazify-mono f a f-mono) (lazify-resp-✓ f a f-resp-✓))
strict {I} {Σ W G} f f-mono f-resp-✓ f-strict with subst _✓ f-strict (f-resp-✓ [] [])
strict {I} {Σ W G} f f-mono f-resp-✓ f-strict | ()
mutual
lazy'-⟦⟧ : ∀ {T S} bs (f : Trace S → Trace (T // bs)) f-mono f-resp-✓ f-strict →
∀ as → ⟦ lazy' bs f f-mono f-resp-✓ f-strict ⟧ as ≡ bs +++ f as
lazy'-⟦⟧ [] f f-mono f-resp-✓ f-strict as = strict-⟦⟧ f f-mono f-resp-✓ f-strict as
lazy'-⟦⟧ {Σ W G} (b ∷ bs) f f-mono f-resp-✓ f-strict as = cong (_∷_ b) (lazy'-⟦⟧ bs f f-mono f-resp-✓ f-strict as)
lazy'-⟦⟧ {I} (() ∷ bs) f f-mono f-resp-✓ f-strict as
lazy-⟦⟧ : ∀ {S T} (f : Trace S → Trace T) f-mono f-resp-✓ →
⟦ lazy f f-mono f-resp-✓ ⟧ ≃ f
lazy-⟦⟧ f f-mono f-resp-✓ as =
begin
⟦ lazy f f-mono f-resp-✓ ⟧ as
≡⟨ lazy'-⟦⟧ (f []) (strictify f f-mono) (strictify-mono f f-mono) (strictify-resp-✓ f f-mono f-resp-✓) (strictify-strict f f-mono) as ⟩
f [] +++ strictify f f-mono as
≡⟨ suffix-+++ (f-mono [] as []) ⟩
f as
∎
strict-⟦⟧ : ∀ {S T} (f : Trace S → Trace T) f-mono f-resp-✓ f-strict →
⟦ strict f f-mono f-resp-✓ f-strict ⟧ ≃ f
strict-⟦⟧ {I} {I} f f-mono f-resp-✓ f-strict [] = sym (I-η (f []))
strict-⟦⟧ {Σ V F} f f-mono f-resp-✓ f-strict [] = sym f-strict
strict-⟦⟧ {Σ V F} f f-mono f-resp-✓ f-strict (a ∷ as) = lazy-⟦⟧ (lazify f a) (lazify-mono f a f-mono) (lazify-resp-✓ f a f-resp-✓) as
strict-⟦⟧ {I} {Σ W G} f f-mono f-resp-✓ f-strict as with subst _✓ f-strict (f-resp-✓ [] [])
strict-⟦⟧ {I} {Σ W G} f f-mono f-resp-✓ f-strict as | ()
strict-⟦⟧ {I} f f-mono f-resp-✓ f-strict (() ∷ as)
⟦⟧-lazy : ∀ {S T} (P : S ⇒ T) →
lazy ⟦ P ⟧ (⟦⟧-mono P) (⟦⟧-resp-✓ P) ≣ P
⟦⟧-lazy P = ⟦⟧-refl-≣ (lazy ⟦ P ⟧ (⟦⟧-mono P) (⟦⟧-resp-✓ P)) P (lazy-⟦⟧ ⟦ P ⟧ (⟦⟧-mono P) (⟦⟧-resp-✓ P))
⟦⟧-strict : ∀ {S T} (P : S ⇒ T) (#P : Strict P) →
strict ⟦ P ⟧ (⟦⟧-mono P) (⟦⟧-resp-✓ P) (⟦⟧-resp-[] #P) ≣ P
⟦⟧-strict P #P = ⟦⟧-refl-≣ (strict ⟦ P ⟧ (⟦⟧-mono P) (⟦⟧-resp-✓ P) (⟦⟧-resp-[] #P)) P (strict-⟦⟧ ⟦ P ⟧ (⟦⟧-mono P) (⟦⟧-resp-✓ P) (⟦⟧-resp-[] #P))
| {
"alphanum_fraction": 0.5099836334,
"avg_line_length": 44.2753623188,
"ext": "agda",
"hexsha": "e921f8033805f5013f28a6471f0f48a7fd88796c",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:23.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-08-10T06:12:54.000Z",
"max_forks_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ilya-fiveisky/agda-system-io",
"max_forks_repo_path": "src/System/IO/Transducers/Properties/Equivalences.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "ilya-fiveisky/agda-system-io",
"max_issues_repo_path": "src/System/IO/Transducers/Properties/Equivalences.agda",
"max_line_length": 151,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ilya-fiveisky/agda-system-io",
"max_stars_repo_path": "src/System/IO/Transducers/Properties/Equivalences.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-15T04:35:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-04T13:45:16.000Z",
"num_tokens": 2907,
"size": 6110
} |
module Text.Greek.SBLGNT.3John where
open import Data.List
open import Text.Greek.Bible
open import Text.Greek.Script
open import Text.Greek.Script.Unicode
ΙΩΑΝΝΟΥ-Γ : List (Word)
ΙΩΑΝΝΟΥ-Γ =
word (Ὁ ∷ []) "3John.1.1"
∷ word (π ∷ ρ ∷ ε ∷ σ ∷ β ∷ ύ ∷ τ ∷ ε ∷ ρ ∷ ο ∷ ς ∷ []) "3John.1.1"
∷ word (Γ ∷ α ∷ ΐ ∷ ῳ ∷ []) "3John.1.1"
∷ word (τ ∷ ῷ ∷ []) "3John.1.1"
∷ word (ἀ ∷ γ ∷ α ∷ π ∷ η ∷ τ ∷ ῷ ∷ []) "3John.1.1"
∷ word (ὃ ∷ ν ∷ []) "3John.1.1"
∷ word (ἐ ∷ γ ∷ ὼ ∷ []) "3John.1.1"
∷ word (ἀ ∷ γ ∷ α ∷ π ∷ ῶ ∷ []) "3John.1.1"
∷ word (ἐ ∷ ν ∷ []) "3John.1.1"
∷ word (ἀ ∷ ∙λ ∷ η ∷ θ ∷ ε ∷ ί ∷ ᾳ ∷ []) "3John.1.1"
∷ word (Ἀ ∷ γ ∷ α ∷ π ∷ η ∷ τ ∷ έ ∷ []) "3John.1.2"
∷ word (π ∷ ε ∷ ρ ∷ ὶ ∷ []) "3John.1.2"
∷ word (π ∷ ά ∷ ν ∷ τ ∷ ω ∷ ν ∷ []) "3John.1.2"
∷ word (ε ∷ ὔ ∷ χ ∷ ο ∷ μ ∷ α ∷ ί ∷ []) "3John.1.2"
∷ word (σ ∷ ε ∷ []) "3John.1.2"
∷ word (ε ∷ ὐ ∷ ο ∷ δ ∷ ο ∷ ῦ ∷ σ ∷ θ ∷ α ∷ ι ∷ []) "3John.1.2"
∷ word (κ ∷ α ∷ ὶ ∷ []) "3John.1.2"
∷ word (ὑ ∷ γ ∷ ι ∷ α ∷ ί ∷ ν ∷ ε ∷ ι ∷ ν ∷ []) "3John.1.2"
∷ word (κ ∷ α ∷ θ ∷ ὼ ∷ ς ∷ []) "3John.1.2"
∷ word (ε ∷ ὐ ∷ ο ∷ δ ∷ ο ∷ ῦ ∷ τ ∷ α ∷ ί ∷ []) "3John.1.2"
∷ word (σ ∷ ο ∷ υ ∷ []) "3John.1.2"
∷ word (ἡ ∷ []) "3John.1.2"
∷ word (ψ ∷ υ ∷ χ ∷ ή ∷ []) "3John.1.2"
∷ word (ἐ ∷ χ ∷ ά ∷ ρ ∷ η ∷ ν ∷ []) "3John.1.3"
∷ word (γ ∷ ὰ ∷ ρ ∷ []) "3John.1.3"
∷ word (∙λ ∷ ί ∷ α ∷ ν ∷ []) "3John.1.3"
∷ word (ἐ ∷ ρ ∷ χ ∷ ο ∷ μ ∷ έ ∷ ν ∷ ω ∷ ν ∷ []) "3John.1.3"
∷ word (ἀ ∷ δ ∷ ε ∷ ∙λ ∷ φ ∷ ῶ ∷ ν ∷ []) "3John.1.3"
∷ word (κ ∷ α ∷ ὶ ∷ []) "3John.1.3"
∷ word (μ ∷ α ∷ ρ ∷ τ ∷ υ ∷ ρ ∷ ο ∷ ύ ∷ ν ∷ τ ∷ ω ∷ ν ∷ []) "3John.1.3"
∷ word (σ ∷ ο ∷ υ ∷ []) "3John.1.3"
∷ word (τ ∷ ῇ ∷ []) "3John.1.3"
∷ word (ἀ ∷ ∙λ ∷ η ∷ θ ∷ ε ∷ ί ∷ ᾳ ∷ []) "3John.1.3"
∷ word (κ ∷ α ∷ θ ∷ ὼ ∷ ς ∷ []) "3John.1.3"
∷ word (σ ∷ ὺ ∷ []) "3John.1.3"
∷ word (ἐ ∷ ν ∷ []) "3John.1.3"
∷ word (ἀ ∷ ∙λ ∷ η ∷ θ ∷ ε ∷ ί ∷ ᾳ ∷ []) "3John.1.3"
∷ word (π ∷ ε ∷ ρ ∷ ι ∷ π ∷ α ∷ τ ∷ ε ∷ ῖ ∷ ς ∷ []) "3John.1.3"
∷ word (μ ∷ ε ∷ ι ∷ ζ ∷ ο ∷ τ ∷ έ ∷ ρ ∷ α ∷ ν ∷ []) "3John.1.4"
∷ word (τ ∷ ο ∷ ύ ∷ τ ∷ ω ∷ ν ∷ []) "3John.1.4"
∷ word (ο ∷ ὐ ∷ κ ∷ []) "3John.1.4"
∷ word (ἔ ∷ χ ∷ ω ∷ []) "3John.1.4"
∷ word (χ ∷ α ∷ ρ ∷ ά ∷ ν ∷ []) "3John.1.4"
∷ word (ἵ ∷ ν ∷ α ∷ []) "3John.1.4"
∷ word (ἀ ∷ κ ∷ ο ∷ ύ ∷ ω ∷ []) "3John.1.4"
∷ word (τ ∷ ὰ ∷ []) "3John.1.4"
∷ word (ἐ ∷ μ ∷ ὰ ∷ []) "3John.1.4"
∷ word (τ ∷ έ ∷ κ ∷ ν ∷ α ∷ []) "3John.1.4"
∷ word (ἐ ∷ ν ∷ []) "3John.1.4"
∷ word (τ ∷ ῇ ∷ []) "3John.1.4"
∷ word (ἀ ∷ ∙λ ∷ η ∷ θ ∷ ε ∷ ί ∷ ᾳ ∷ []) "3John.1.4"
∷ word (π ∷ ε ∷ ρ ∷ ι ∷ π ∷ α ∷ τ ∷ ο ∷ ῦ ∷ ν ∷ τ ∷ α ∷ []) "3John.1.4"
∷ word (Ἀ ∷ γ ∷ α ∷ π ∷ η ∷ τ ∷ έ ∷ []) "3John.1.5"
∷ word (π ∷ ι ∷ σ ∷ τ ∷ ὸ ∷ ν ∷ []) "3John.1.5"
∷ word (π ∷ ο ∷ ι ∷ ε ∷ ῖ ∷ ς ∷ []) "3John.1.5"
∷ word (ὃ ∷ []) "3John.1.5"
∷ word (ἐ ∷ ὰ ∷ ν ∷ []) "3John.1.5"
∷ word (ἐ ∷ ρ ∷ γ ∷ ά ∷ σ ∷ ῃ ∷ []) "3John.1.5"
∷ word (ε ∷ ἰ ∷ ς ∷ []) "3John.1.5"
∷ word (τ ∷ ο ∷ ὺ ∷ ς ∷ []) "3John.1.5"
∷ word (ἀ ∷ δ ∷ ε ∷ ∙λ ∷ φ ∷ ο ∷ ὺ ∷ ς ∷ []) "3John.1.5"
∷ word (κ ∷ α ∷ ὶ ∷ []) "3John.1.5"
∷ word (τ ∷ ο ∷ ῦ ∷ τ ∷ ο ∷ []) "3John.1.5"
∷ word (ξ ∷ έ ∷ ν ∷ ο ∷ υ ∷ ς ∷ []) "3John.1.5"
∷ word (ο ∷ ἳ ∷ []) "3John.1.6"
∷ word (ἐ ∷ μ ∷ α ∷ ρ ∷ τ ∷ ύ ∷ ρ ∷ η ∷ σ ∷ ά ∷ ν ∷ []) "3John.1.6"
∷ word (σ ∷ ο ∷ υ ∷ []) "3John.1.6"
∷ word (τ ∷ ῇ ∷ []) "3John.1.6"
∷ word (ἀ ∷ γ ∷ ά ∷ π ∷ ῃ ∷ []) "3John.1.6"
∷ word (ἐ ∷ ν ∷ ώ ∷ π ∷ ι ∷ ο ∷ ν ∷ []) "3John.1.6"
∷ word (ἐ ∷ κ ∷ κ ∷ ∙λ ∷ η ∷ σ ∷ ί ∷ α ∷ ς ∷ []) "3John.1.6"
∷ word (ο ∷ ὓ ∷ ς ∷ []) "3John.1.6"
∷ word (κ ∷ α ∷ ∙λ ∷ ῶ ∷ ς ∷ []) "3John.1.6"
∷ word (π ∷ ο ∷ ι ∷ ή ∷ σ ∷ ε ∷ ι ∷ ς ∷ []) "3John.1.6"
∷ word (π ∷ ρ ∷ ο ∷ π ∷ έ ∷ μ ∷ ψ ∷ α ∷ ς ∷ []) "3John.1.6"
∷ word (ἀ ∷ ξ ∷ ί ∷ ω ∷ ς ∷ []) "3John.1.6"
∷ word (τ ∷ ο ∷ ῦ ∷ []) "3John.1.6"
∷ word (θ ∷ ε ∷ ο ∷ ῦ ∷ []) "3John.1.6"
∷ word (ὑ ∷ π ∷ ὲ ∷ ρ ∷ []) "3John.1.7"
∷ word (γ ∷ ὰ ∷ ρ ∷ []) "3John.1.7"
∷ word (τ ∷ ο ∷ ῦ ∷ []) "3John.1.7"
∷ word (ὀ ∷ ν ∷ ό ∷ μ ∷ α ∷ τ ∷ ο ∷ ς ∷ []) "3John.1.7"
∷ word (ἐ ∷ ξ ∷ ῆ ∷ ∙λ ∷ θ ∷ ο ∷ ν ∷ []) "3John.1.7"
∷ word (μ ∷ η ∷ δ ∷ ὲ ∷ ν ∷ []) "3John.1.7"
∷ word (∙λ ∷ α ∷ μ ∷ β ∷ ά ∷ ν ∷ ο ∷ ν ∷ τ ∷ ε ∷ ς ∷ []) "3John.1.7"
∷ word (ἀ ∷ π ∷ ὸ ∷ []) "3John.1.7"
∷ word (τ ∷ ῶ ∷ ν ∷ []) "3John.1.7"
∷ word (ἐ ∷ θ ∷ ν ∷ ι ∷ κ ∷ ῶ ∷ ν ∷ []) "3John.1.7"
∷ word (ἡ ∷ μ ∷ ε ∷ ῖ ∷ ς ∷ []) "3John.1.8"
∷ word (ο ∷ ὖ ∷ ν ∷ []) "3John.1.8"
∷ word (ὀ ∷ φ ∷ ε ∷ ί ∷ ∙λ ∷ ο ∷ μ ∷ ε ∷ ν ∷ []) "3John.1.8"
∷ word (ὑ ∷ π ∷ ο ∷ ∙λ ∷ α ∷ μ ∷ β ∷ ά ∷ ν ∷ ε ∷ ι ∷ ν ∷ []) "3John.1.8"
∷ word (τ ∷ ο ∷ ὺ ∷ ς ∷ []) "3John.1.8"
∷ word (τ ∷ ο ∷ ι ∷ ο ∷ ύ ∷ τ ∷ ο ∷ υ ∷ ς ∷ []) "3John.1.8"
∷ word (ἵ ∷ ν ∷ α ∷ []) "3John.1.8"
∷ word (σ ∷ υ ∷ ν ∷ ε ∷ ρ ∷ γ ∷ ο ∷ ὶ ∷ []) "3John.1.8"
∷ word (γ ∷ ι ∷ ν ∷ ώ ∷ μ ∷ ε ∷ θ ∷ α ∷ []) "3John.1.8"
∷ word (τ ∷ ῇ ∷ []) "3John.1.8"
∷ word (ἀ ∷ ∙λ ∷ η ∷ θ ∷ ε ∷ ί ∷ ᾳ ∷ []) "3John.1.8"
∷ word (Ἔ ∷ γ ∷ ρ ∷ α ∷ ψ ∷ ά ∷ []) "3John.1.9"
∷ word (τ ∷ ι ∷ []) "3John.1.9"
∷ word (τ ∷ ῇ ∷ []) "3John.1.9"
∷ word (ἐ ∷ κ ∷ κ ∷ ∙λ ∷ η ∷ σ ∷ ί ∷ ᾳ ∷ []) "3John.1.9"
∷ word (ἀ ∷ ∙λ ∷ ∙λ ∷ []) "3John.1.9"
∷ word (ὁ ∷ []) "3John.1.9"
∷ word (φ ∷ ι ∷ ∙λ ∷ ο ∷ π ∷ ρ ∷ ω ∷ τ ∷ ε ∷ ύ ∷ ω ∷ ν ∷ []) "3John.1.9"
∷ word (α ∷ ὐ ∷ τ ∷ ῶ ∷ ν ∷ []) "3John.1.9"
∷ word (Δ ∷ ι ∷ ο ∷ τ ∷ ρ ∷ έ ∷ φ ∷ η ∷ ς ∷ []) "3John.1.9"
∷ word (ο ∷ ὐ ∷ κ ∷ []) "3John.1.9"
∷ word (ἐ ∷ π ∷ ι ∷ δ ∷ έ ∷ χ ∷ ε ∷ τ ∷ α ∷ ι ∷ []) "3John.1.9"
∷ word (ἡ ∷ μ ∷ ᾶ ∷ ς ∷ []) "3John.1.9"
∷ word (δ ∷ ι ∷ ὰ ∷ []) "3John.1.10"
∷ word (τ ∷ ο ∷ ῦ ∷ τ ∷ ο ∷ []) "3John.1.10"
∷ word (ἐ ∷ ὰ ∷ ν ∷ []) "3John.1.10"
∷ word (ἔ ∷ ∙λ ∷ θ ∷ ω ∷ []) "3John.1.10"
∷ word (ὑ ∷ π ∷ ο ∷ μ ∷ ν ∷ ή ∷ σ ∷ ω ∷ []) "3John.1.10"
∷ word (α ∷ ὐ ∷ τ ∷ ο ∷ ῦ ∷ []) "3John.1.10"
∷ word (τ ∷ ὰ ∷ []) "3John.1.10"
∷ word (ἔ ∷ ρ ∷ γ ∷ α ∷ []) "3John.1.10"
∷ word (ἃ ∷ []) "3John.1.10"
∷ word (π ∷ ο ∷ ι ∷ ε ∷ ῖ ∷ []) "3John.1.10"
∷ word (∙λ ∷ ό ∷ γ ∷ ο ∷ ι ∷ ς ∷ []) "3John.1.10"
∷ word (π ∷ ο ∷ ν ∷ η ∷ ρ ∷ ο ∷ ῖ ∷ ς ∷ []) "3John.1.10"
∷ word (φ ∷ ∙λ ∷ υ ∷ α ∷ ρ ∷ ῶ ∷ ν ∷ []) "3John.1.10"
∷ word (ἡ ∷ μ ∷ ᾶ ∷ ς ∷ []) "3John.1.10"
∷ word (κ ∷ α ∷ ὶ ∷ []) "3John.1.10"
∷ word (μ ∷ ὴ ∷ []) "3John.1.10"
∷ word (ἀ ∷ ρ ∷ κ ∷ ο ∷ ύ ∷ μ ∷ ε ∷ ν ∷ ο ∷ ς ∷ []) "3John.1.10"
∷ word (ἐ ∷ π ∷ ὶ ∷ []) "3John.1.10"
∷ word (τ ∷ ο ∷ ύ ∷ τ ∷ ο ∷ ι ∷ ς ∷ []) "3John.1.10"
∷ word (ο ∷ ὔ ∷ τ ∷ ε ∷ []) "3John.1.10"
∷ word (α ∷ ὐ ∷ τ ∷ ὸ ∷ ς ∷ []) "3John.1.10"
∷ word (ἐ ∷ π ∷ ι ∷ δ ∷ έ ∷ χ ∷ ε ∷ τ ∷ α ∷ ι ∷ []) "3John.1.10"
∷ word (τ ∷ ο ∷ ὺ ∷ ς ∷ []) "3John.1.10"
∷ word (ἀ ∷ δ ∷ ε ∷ ∙λ ∷ φ ∷ ο ∷ ὺ ∷ ς ∷ []) "3John.1.10"
∷ word (κ ∷ α ∷ ὶ ∷ []) "3John.1.10"
∷ word (τ ∷ ο ∷ ὺ ∷ ς ∷ []) "3John.1.10"
∷ word (β ∷ ο ∷ υ ∷ ∙λ ∷ ο ∷ μ ∷ έ ∷ ν ∷ ο ∷ υ ∷ ς ∷ []) "3John.1.10"
∷ word (κ ∷ ω ∷ ∙λ ∷ ύ ∷ ε ∷ ι ∷ []) "3John.1.10"
∷ word (κ ∷ α ∷ ὶ ∷ []) "3John.1.10"
∷ word (ἐ ∷ κ ∷ []) "3John.1.10"
∷ word (τ ∷ ῆ ∷ ς ∷ []) "3John.1.10"
∷ word (ἐ ∷ κ ∷ κ ∷ ∙λ ∷ η ∷ σ ∷ ί ∷ α ∷ ς ∷ []) "3John.1.10"
∷ word (ἐ ∷ κ ∷ β ∷ ά ∷ ∙λ ∷ ∙λ ∷ ε ∷ ι ∷ []) "3John.1.10"
∷ word (Ἀ ∷ γ ∷ α ∷ π ∷ η ∷ τ ∷ έ ∷ []) "3John.1.11"
∷ word (μ ∷ ὴ ∷ []) "3John.1.11"
∷ word (μ ∷ ι ∷ μ ∷ ο ∷ ῦ ∷ []) "3John.1.11"
∷ word (τ ∷ ὸ ∷ []) "3John.1.11"
∷ word (κ ∷ α ∷ κ ∷ ὸ ∷ ν ∷ []) "3John.1.11"
∷ word (ἀ ∷ ∙λ ∷ ∙λ ∷ ὰ ∷ []) "3John.1.11"
∷ word (τ ∷ ὸ ∷ []) "3John.1.11"
∷ word (ἀ ∷ γ ∷ α ∷ θ ∷ ό ∷ ν ∷ []) "3John.1.11"
∷ word (ὁ ∷ []) "3John.1.11"
∷ word (ἀ ∷ γ ∷ α ∷ θ ∷ ο ∷ π ∷ ο ∷ ι ∷ ῶ ∷ ν ∷ []) "3John.1.11"
∷ word (ἐ ∷ κ ∷ []) "3John.1.11"
∷ word (τ ∷ ο ∷ ῦ ∷ []) "3John.1.11"
∷ word (θ ∷ ε ∷ ο ∷ ῦ ∷ []) "3John.1.11"
∷ word (ἐ ∷ σ ∷ τ ∷ ι ∷ ν ∷ []) "3John.1.11"
∷ word (ὁ ∷ []) "3John.1.11"
∷ word (κ ∷ α ∷ κ ∷ ο ∷ π ∷ ο ∷ ι ∷ ῶ ∷ ν ∷ []) "3John.1.11"
∷ word (ο ∷ ὐ ∷ χ ∷ []) "3John.1.11"
∷ word (ἑ ∷ ώ ∷ ρ ∷ α ∷ κ ∷ ε ∷ ν ∷ []) "3John.1.11"
∷ word (τ ∷ ὸ ∷ ν ∷ []) "3John.1.11"
∷ word (θ ∷ ε ∷ ό ∷ ν ∷ []) "3John.1.11"
∷ word (Δ ∷ η ∷ μ ∷ η ∷ τ ∷ ρ ∷ ί ∷ ῳ ∷ []) "3John.1.12"
∷ word (μ ∷ ε ∷ μ ∷ α ∷ ρ ∷ τ ∷ ύ ∷ ρ ∷ η ∷ τ ∷ α ∷ ι ∷ []) "3John.1.12"
∷ word (ὑ ∷ π ∷ ὸ ∷ []) "3John.1.12"
∷ word (π ∷ ά ∷ ν ∷ τ ∷ ω ∷ ν ∷ []) "3John.1.12"
∷ word (κ ∷ α ∷ ὶ ∷ []) "3John.1.12"
∷ word (ὑ ∷ π ∷ ὸ ∷ []) "3John.1.12"
∷ word (α ∷ ὐ ∷ τ ∷ ῆ ∷ ς ∷ []) "3John.1.12"
∷ word (τ ∷ ῆ ∷ ς ∷ []) "3John.1.12"
∷ word (ἀ ∷ ∙λ ∷ η ∷ θ ∷ ε ∷ ί ∷ α ∷ ς ∷ []) "3John.1.12"
∷ word (κ ∷ α ∷ ὶ ∷ []) "3John.1.12"
∷ word (ἡ ∷ μ ∷ ε ∷ ῖ ∷ ς ∷ []) "3John.1.12"
∷ word (δ ∷ ὲ ∷ []) "3John.1.12"
∷ word (μ ∷ α ∷ ρ ∷ τ ∷ υ ∷ ρ ∷ ο ∷ ῦ ∷ μ ∷ ε ∷ ν ∷ []) "3John.1.12"
∷ word (κ ∷ α ∷ ὶ ∷ []) "3John.1.12"
∷ word (ο ∷ ἶ ∷ δ ∷ α ∷ ς ∷ []) "3John.1.12"
∷ word (ὅ ∷ τ ∷ ι ∷ []) "3John.1.12"
∷ word (ἡ ∷ []) "3John.1.12"
∷ word (μ ∷ α ∷ ρ ∷ τ ∷ υ ∷ ρ ∷ ί ∷ α ∷ []) "3John.1.12"
∷ word (ἡ ∷ μ ∷ ῶ ∷ ν ∷ []) "3John.1.12"
∷ word (ἀ ∷ ∙λ ∷ η ∷ θ ∷ ή ∷ ς ∷ []) "3John.1.12"
∷ word (ἐ ∷ σ ∷ τ ∷ ι ∷ ν ∷ []) "3John.1.12"
∷ word (Π ∷ ο ∷ ∙λ ∷ ∙λ ∷ ὰ ∷ []) "3John.1.13"
∷ word (ε ∷ ἶ ∷ χ ∷ ο ∷ ν ∷ []) "3John.1.13"
∷ word (γ ∷ ρ ∷ ά ∷ ψ ∷ α ∷ ι ∷ []) "3John.1.13"
∷ word (σ ∷ ο ∷ ι ∷ []) "3John.1.13"
∷ word (ἀ ∷ ∙λ ∷ ∙λ ∷ []) "3John.1.13"
∷ word (ο ∷ ὐ ∷ []) "3John.1.13"
∷ word (θ ∷ έ ∷ ∙λ ∷ ω ∷ []) "3John.1.13"
∷ word (δ ∷ ι ∷ ὰ ∷ []) "3John.1.13"
∷ word (μ ∷ έ ∷ ∙λ ∷ α ∷ ν ∷ ο ∷ ς ∷ []) "3John.1.13"
∷ word (κ ∷ α ∷ ὶ ∷ []) "3John.1.13"
∷ word (κ ∷ α ∷ ∙λ ∷ ά ∷ μ ∷ ο ∷ υ ∷ []) "3John.1.13"
∷ word (σ ∷ ο ∷ ι ∷ []) "3John.1.13"
∷ word (γ ∷ ρ ∷ ά ∷ φ ∷ ε ∷ ι ∷ ν ∷ []) "3John.1.13"
∷ word (ἐ ∷ ∙λ ∷ π ∷ ί ∷ ζ ∷ ω ∷ []) "3John.1.14"
∷ word (δ ∷ ὲ ∷ []) "3John.1.14"
∷ word (ε ∷ ὐ ∷ θ ∷ έ ∷ ω ∷ ς ∷ []) "3John.1.14"
∷ word (σ ∷ ε ∷ []) "3John.1.14"
∷ word (ἰ ∷ δ ∷ ε ∷ ῖ ∷ ν ∷ []) "3John.1.14"
∷ word (κ ∷ α ∷ ὶ ∷ []) "3John.1.14"
∷ word (σ ∷ τ ∷ ό ∷ μ ∷ α ∷ []) "3John.1.14"
∷ word (π ∷ ρ ∷ ὸ ∷ ς ∷ []) "3John.1.14"
∷ word (σ ∷ τ ∷ ό ∷ μ ∷ α ∷ []) "3John.1.14"
∷ word (∙λ ∷ α ∷ ∙λ ∷ ή ∷ σ ∷ ο ∷ μ ∷ ε ∷ ν ∷ []) "3John.1.14"
∷ word (Ε ∷ ἰ ∷ ρ ∷ ή ∷ ν ∷ η ∷ []) "3John.1.15"
∷ word (σ ∷ ο ∷ ι ∷ []) "3John.1.15"
∷ word (ἀ ∷ σ ∷ π ∷ ά ∷ ζ ∷ ο ∷ ν ∷ τ ∷ α ∷ ί ∷ []) "3John.1.15"
∷ word (σ ∷ ε ∷ []) "3John.1.15"
∷ word (ο ∷ ἱ ∷ []) "3John.1.15"
∷ word (φ ∷ ί ∷ ∙λ ∷ ο ∷ ι ∷ []) "3John.1.15"
∷ word (ἀ ∷ σ ∷ π ∷ ά ∷ ζ ∷ ο ∷ υ ∷ []) "3John.1.15"
∷ word (τ ∷ ο ∷ ὺ ∷ ς ∷ []) "3John.1.15"
∷ word (φ ∷ ί ∷ ∙λ ∷ ο ∷ υ ∷ ς ∷ []) "3John.1.15"
∷ word (κ ∷ α ∷ τ ∷ []) "3John.1.15"
∷ word (ὄ ∷ ν ∷ ο ∷ μ ∷ α ∷ []) "3John.1.15"
∷ []
| {
"alphanum_fraction": 0.3607026924,
"avg_line_length": 45.5391304348,
"ext": "agda",
"hexsha": "8baf4b8398572e7ad2d47123d28aac1585bc23b0",
"lang": "Agda",
"max_forks_count": 5,
"max_forks_repo_forks_event_max_datetime": "2017-06-11T11:25:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-27T22:34:13.000Z",
"max_forks_repo_head_hexsha": "915c46c27c7f8aad5907474d8484f2685a4cd6a7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "scott-fleischman/GreekGrammar",
"max_forks_repo_path": "agda/Text/Greek/SBLGNT/3John.agda",
"max_issues_count": 13,
"max_issues_repo_head_hexsha": "915c46c27c7f8aad5907474d8484f2685a4cd6a7",
"max_issues_repo_issues_event_max_datetime": "2020-09-07T11:58:38.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-28T20:04:08.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "scott-fleischman/GreekGrammar",
"max_issues_repo_path": "agda/Text/Greek/SBLGNT/3John.agda",
"max_line_length": 74,
"max_stars_count": 44,
"max_stars_repo_head_hexsha": "915c46c27c7f8aad5907474d8484f2685a4cd6a7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "scott-fleischman/GreekGrammar",
"max_stars_repo_path": "agda/Text/Greek/SBLGNT/3John.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-06T15:41:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-29T14:48:51.000Z",
"num_tokens": 7352,
"size": 10474
} |
module Dummy where
| {
"alphanum_fraction": 0.8,
"avg_line_length": 6.6666666667,
"ext": "agda",
"hexsha": "42cc06d8d2ce39dc62ed6f075df4f541cf44cee9",
"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/outdated-and-incorrect/iird/Dummy.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/outdated-and-incorrect/iird/Dummy.agda",
"max_line_length": 18,
"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/outdated-and-incorrect/iird/Dummy.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": 5,
"size": 20
} |
{-# OPTIONS --without-K --safe #-}
open import Algebra.Structures.Bundles.Field
open import Algebra.Linear.Structures.Bundles
module Algebra.Linear.Space.Hom
{k ℓ} (K : Field k ℓ)
{a₁ ℓ₁} (V₁-space : VectorSpace K a₁ ℓ₁)
{a₂ ℓ₂} (V₂-space : VectorSpace K a₂ ℓ₂)
where
open import Relation.Binary
open import Level using (_⊔_; suc)
open import Data.Nat using (ℕ) renaming (_+_ to _+ℕ_)
open import Algebra.Linear.Morphism.Bundles K
open import Algebra.Linear.Morphism.Properties K
open import Algebra.Linear.Structures.VectorSpace
open import Data.Product
open VectorSpaceField K
open VectorSpace V₁-space
using ()
renaming
( Carrier to V₁
; _≈_ to _≈₁_
; isEquivalence to ≈₁-isEquiv
; refl to ≈₁-refl
; sym to ≈₁-sym
; trans to ≈₁-trans
; setoid to setoid₁
; _+_ to _+₁_
; _∙_ to _∙₁_
; -_ to -₁_
; 0# to 0₁
; +-identityˡ to +₁-identityˡ
; +-identityʳ to +₁-identityʳ
; +-identity to +₁-identity
; +-cong to +₁-cong
; +-assoc to +₁-assoc
; +-comm to +₁-comm
; *ᵏ-∙-compat to *ᵏ-∙₁-compat
; ∙-+-distrib to ∙₁-+₁-distrib
; ∙-+ᵏ-distrib to ∙₁-+ᵏ-distrib
; ∙-cong to ∙₁-cong
; ∙-identity to ∙₁-identity
; ∙-absorbˡ to ∙₁-absorbˡ
; ∙-absorbʳ to ∙₁-absorbʳ
; -‿cong to -₁‿cong
; -‿inverseˡ to -₁‿inverseˡ
; -‿inverseʳ to -₁‿inverseʳ
)
open VectorSpace V₂-space
using ()
renaming
( Carrier to V₂
; _≈_ to _≈₂_
; isEquivalence to ≈₂-isEquiv
; refl to ≈₂-refl
; sym to ≈₂-sym
; trans to ≈₂-trans
; setoid to setoid₂
; _+_ to _+₂_
; _∙_ to _∙₂_
; -_ to -₂_
; 0# to 0₂
; +-identityˡ to +₂-identityˡ
; +-identityʳ to +₂-identityʳ
; +-identity to +₂-identity
; +-cong to +₂-cong
; +-assoc to +₂-assoc
; +-comm to +₂-comm
; *ᵏ-∙-compat to *ᵏ-∙₂-compat
; ∙-+-distrib to ∙₂-+₂-distrib
; ∙-+ᵏ-distrib to ∙₂-+ᵏ-distrib
; ∙-cong to ∙₂-cong
; ∙-identity to ∙₂-identity
; ∙-absorbˡ to ∙₂-absorbˡ
; ∙-absorbʳ to ∙₂-absorbʳ
; ∙-∙-comm to ∙₂-∙₂-comm
; -‿cong to -₂‿cong
; -‿inverseˡ to -₂‿inverseˡ
; -‿inverseʳ to -₂‿inverseʳ
; -‿+-comm to -₂‿+₂-comm
; -1∙u≈-u to -1∙u≈₂-u
)
import Function
private
V : Set (suc (k ⊔ a₁ ⊔ a₂ ⊔ ℓ₁ ⊔ ℓ₂))
V = LinearMap V₁-space V₂-space
open LinearMap using (_⟪$⟫_; ⟦⟧-cong; distrib-linear)
setoid : Setoid (suc (k ⊔ a₁ ⊔ a₂ ⊔ ℓ₁ ⊔ ℓ₂)) _
setoid = linearMap-setoid V₁-space V₂-space
open Setoid setoid public
renaming (isEquivalence to ≈-isEquiv)
open import Algebra.FunctionProperties _≈_
open import Algebra.Structures _≈_
open import Function.Equality hiding (setoid; _∘_)
open import Relation.Binary.EqReasoning setoid₂
0# : V
0# = record
{ ⟦_⟧ = λ x → 0₂
; isLinearMap = linear V₁-space V₂-space π
λ a b u v →
begin
0₂
≈⟨ ≈₂-trans (≈₂-sym (∙₂-absorbʳ b)) (≈₂-sym (+₂-identityˡ (b ∙₂ 0₂))) ⟩
0₂ +₂ b ∙₂ 0₂
≈⟨ +₂-cong (≈₂-sym (∙₂-absorbʳ a)) ≈₂-refl ⟩
a ∙₂ 0₂ +₂ b ∙₂ 0₂
∎
}
where π : setoid₁ ⟶ setoid₂
π = record
{ _⟨$⟩_ = λ x → 0₂
; cong = λ r → ≈₂-refl }
-_ : Op₁ V
- f = record
{ ⟦_⟧ = λ x → -₂ f ⟪$⟫ x
; isLinearMap = linear V₁-space V₂-space π
let -[a∙u]≈₂a∙[-u] : ∀ (a : K') (u : V₂) -> (-₂ (a ∙₂ u)) ≈₂ a ∙₂ (-₂ u)
-[a∙u]≈₂a∙[-u] a u =
begin
(-₂ (a ∙₂ u))
≈⟨ ≈₂-sym (-1∙u≈₂-u (a ∙₂ u)) ⟩
(-ᵏ 1ᵏ) ∙₂ (a ∙₂ u)
≈⟨ ≈₂-sym (*ᵏ-∙₂-compat (-ᵏ 1ᵏ) a u) ⟩
((-ᵏ 1ᵏ) *ᵏ a) ∙₂ u
≈⟨ ∙₂-cong (≈ᵏ-trans (≈ᵏ-sym (-ᵏ‿distribˡ-*ᵏ 1ᵏ a)) (-ᵏ‿cong (*ᵏ-identityˡ a))) ≈₂-refl ⟩
(-ᵏ a) ∙₂ u
≈⟨ ∙₂-cong (≈ᵏ-trans (-ᵏ‿cong (≈ᵏ-sym (*ᵏ-identityʳ a))) (-ᵏ‿distribʳ-*ᵏ a 1ᵏ)) ≈₂-refl ⟩
(a *ᵏ (-ᵏ 1ᵏ)) ∙₂ u
≈⟨ ≈₂-trans (*ᵏ-∙₂-compat a (-ᵏ 1ᵏ) u) (∙₂-cong ≈ᵏ-refl (-1∙u≈₂-u u)) ⟩
a ∙₂ (-₂ u)
∎
in λ a b u v →
begin
π ⟨$⟩ a ∙₁ u +₁ b ∙₁ v
≈⟨ -₂‿cong (distrib-linear f a b u v) ⟩
-₂ (a ∙₂ (f ⟪$⟫ u) +₂ b ∙₂ (f ⟪$⟫ v))
≈⟨ ≈₂-sym (-₂‿+₂-comm (a ∙₂ (f ⟪$⟫ u)) ( b ∙₂ (f ⟪$⟫ v))) ⟩
((-₂ (a ∙₂ (f ⟪$⟫ u))) +₂ (-₂ (b ∙₂ (f ⟪$⟫ v))))
≈⟨ +₂-cong (-[a∙u]≈₂a∙[-u] a (f ⟪$⟫ u)) (-[a∙u]≈₂a∙[-u] b (f ⟪$⟫ v)) ⟩
a ∙₂ (π ⟨$⟩ u) +₂ b ∙₂ (π ⟨$⟩ v)
∎
} where π : setoid₁ ⟶ setoid₂
π = record
{ _⟨$⟩_ = λ x → -₂ f ⟪$⟫ x
; cong = λ r → -₂‿cong (⟦⟧-cong f r)
}
infixr 25 _+_
_+_ : Op₂ V
f + g = record
{ ⟦_⟧ = λ x -> (f ⟪$⟫ x) +₂ (g ⟪$⟫ x)
; isLinearMap = linear V₁-space V₂-space π
let reassoc : ∀ (u v u' v' : V₂) -> (u +₂ v) +₂ (u' +₂ v') ≈₂ (u +₂ u') +₂ (v +₂ v')
reassoc u v u' v' =
begin
(u +₂ v) +₂ (u' +₂ v')
≈⟨ +₂-assoc u v (u' +₂ v') ⟩
u +₂ (v +₂ (u' +₂ v'))
≈⟨ +₂-cong ≈₂-refl (≈₂-trans (≈₂-sym (+₂-assoc v u' v')) (+₂-cong (+₂-comm v u') ≈₂-refl)) ⟩
u +₂ ((u' +₂ v) +₂ v')
≈⟨ ≈₂-trans (+₂-cong ≈₂-refl (+₂-assoc u' v v')) (≈₂-sym (+₂-assoc u u' (v +₂ v'))) ⟩
(u +₂ u') +₂ (v +₂ v')
∎
distrib-f-g k w = ≈₂-sym (∙₂-+₂-distrib k (f ⟪$⟫ w) (g ⟪$⟫ w))
in λ a b u v →
begin
π ⟨$⟩ a ∙₁ u +₁ b ∙₁ v
≡⟨⟩
(f ⟪$⟫ (a ∙₁ u +₁ b ∙₁ v)) +₂ (g ⟪$⟫ (a ∙₁ u +₁ b ∙₁ v))
≈⟨ +₂-cong (distrib-linear f a b u v) (distrib-linear g a b u v) ⟩
(a ∙₂ (f ⟪$⟫ u) +₂ b ∙₂ (f ⟪$⟫ v)) +₂ ((a ∙₂ (g ⟪$⟫ u) +₂ b ∙₂ (g ⟪$⟫ v)))
≈⟨ reassoc (a ∙₂ (f ⟪$⟫ u)) (b ∙₂ (f ⟪$⟫ v)) (a ∙₂ (g ⟪$⟫ u)) (b ∙₂ (g ⟪$⟫ v)) ⟩
(a ∙₂ (f ⟪$⟫ u) +₂ a ∙₂ (g ⟪$⟫ u)) +₂ ((b ∙₂ (f ⟪$⟫ v)) +₂ b ∙₂ (g ⟪$⟫ v))
≈⟨ +₂-cong (distrib-f-g a u) (distrib-f-g b v) ⟩
a ∙₂ (π ⟨$⟩ u) +₂ b ∙₂ (π ⟨$⟩ v)
∎
} where π : setoid₁ ⟶ setoid₂
π = record
{ _⟨$⟩_ = λ x → (f ⟪$⟫ x) +₂ (g ⟪$⟫ x)
; cong = λ r → +₂-cong (⟦⟧-cong f r) (⟦⟧-cong g r)
}
infixr 30 _∙_
_∙_ : K' -> V -> V
c ∙ f = record
{ ⟦_⟧ = λ x → c ∙₂ (f ⟪$⟫ x)
; isLinearMap = linear V₁-space V₂-space π
λ a b u v →
begin
π ⟨$⟩ a ∙₁ u +₁ b ∙₁ v
≈⟨ ∙₂-cong ≈ᵏ-refl (distrib-linear f a b u v) ⟩
c ∙₂ (a ∙₂ (f ⟪$⟫ u) +₂ b ∙₂ (f ⟪$⟫ v))
≈⟨ ∙₂-+₂-distrib c (a ∙₂ (f ⟪$⟫ u)) ( b ∙₂ (f ⟪$⟫ v)) ⟩
(c ∙₂ (a ∙₂ (f ⟪$⟫ u))) +₂ (c ∙₂ (b ∙₂ (f ⟪$⟫ v)))
≈⟨ +₂-cong (∙₂-∙₂-comm c a (f ⟪$⟫ u)) (∙₂-∙₂-comm c b (f ⟪$⟫ v)) ⟩
a ∙₂ (π ⟨$⟩ u) +₂ b ∙₂ (π ⟨$⟩ v)
∎
} where π : setoid₁ ⟶ setoid₂
π = record
{ _⟨$⟩_ = λ x → c ∙₂ (f ⟪$⟫ x)
; cong = λ r → ∙₂-cong ≈ᵏ-refl (⟦⟧-cong f r)
}
+-cong : Congruent₂ _+_
+-cong r₁ r₂ = λ rₓ -> +₂-cong (r₁ rₓ) (r₂ rₓ)
+-assoc : Associative _+_
+-assoc f g h {y = y} rₓ = ≈₂-trans
(+₂-cong (+₂-cong (⟦⟧-cong f rₓ) (⟦⟧-cong g rₓ)) (⟦⟧-cong h rₓ))
(+₂-assoc (f ⟪$⟫ y) (g ⟪$⟫ y) (h ⟪$⟫ y))
+-identityˡ : LeftIdentity 0# _+_
+-identityˡ f {x} rₓ = ≈₂-trans
(+₂-identityˡ (f ⟪$⟫ x))
(⟦⟧-cong f rₓ)
+-identityʳ : RightIdentity 0# _+_
+-identityʳ f {x} rₓ = ≈₂-trans
(+₂-identityʳ (f ⟪$⟫ x))
(⟦⟧-cong f rₓ)
+-identity : Identity 0# _+_
+-identity = +-identityˡ , +-identityʳ
+-comm : Commutative _+_
+-comm f g {x} rₓ = ≈₂-trans
(+₂-comm (f ⟪$⟫ x) (g ⟪$⟫ x))
(+₂-cong (⟦⟧-cong g rₓ) (⟦⟧-cong f rₓ))
*ᵏ-∙-compat : ∀ (a b : K') (f : V) -> ((a *ᵏ b) ∙ f) ≈ (a ∙ (b ∙ f))
*ᵏ-∙-compat a b f {x} rₓ = ≈₂-trans
(*ᵏ-∙₂-compat a b (f ⟪$⟫ x))
(∙₂-cong ≈ᵏ-refl (∙₂-cong ≈ᵏ-refl (⟦⟧-cong f rₓ)))
∙-+-distrib : ∀ (a : K') (f g : V) -> (a ∙ (f + g)) ≈ ((a ∙ f) + (a ∙ g))
∙-+-distrib a f g {x} rₓ = ≈₂-trans
(∙₂-+₂-distrib a (f ⟪$⟫ x) (g ⟪$⟫ x))
(+₂-cong (∙₂-cong ≈ᵏ-refl (⟦⟧-cong f rₓ)) (∙₂-cong ≈ᵏ-refl (⟦⟧-cong g rₓ)))
∙-+ᵏ-distrib : ∀ (a b : K') (f : V) -> ((a +ᵏ b) ∙ f) ≈ ((a ∙ f) + (b ∙ f))
∙-+ᵏ-distrib a b f {x} rₓ = ≈₂-trans
(∙₂-+ᵏ-distrib a b (f ⟪$⟫ x))
(+₂-cong cf cf)
where cf : ∀ {c : K'} -> _
cf {c} = ∙₂-cong (≈ᵏ-refl {c}) (⟦⟧-cong f rₓ)
∙-cong : ∀ {a b : K'} {f g : V} -> a ≈ᵏ b -> f ≈ g -> (a ∙ f) ≈ (b ∙ g)
∙-cong {f = f} {g = g} rk rf rₓ = ≈₂-trans
(∙₂-cong rk (rf rₓ))
(∙₂-cong ≈ᵏ-refl (⟦⟧-cong g ≈₁-refl))
∙-identity : ∀ (f : V) → (1ᵏ ∙ f) ≈ f
∙-identity f {x} rₓ = ≈₂-trans (∙₂-identity (f ⟪$⟫ x)) (⟦⟧-cong f rₓ)
∙-absorbˡ : ∀ (x : V) → (0ᵏ ∙ x) ≈ 0#
∙-absorbˡ f {x} _ = ≈₂-trans (∙₂-absorbˡ (f ⟪$⟫ x)) ≈₂-refl
-‿inverseˡ : LeftInverse 0# -_ _+_
-‿inverseˡ f {x} _ = ≈₂-trans (-₂‿inverseˡ (f ⟪$⟫ x)) ≈₂-refl
-‿inverseʳ : RightInverse 0# -_ _+_
-‿inverseʳ f {x} _ = -₂‿inverseʳ (f ⟪$⟫ x)
-‿inverse : Inverse 0# -_ _+_
-‿inverse = -‿inverseˡ , -‿inverseʳ
-‿cong : Congruent₁ -_
-‿cong r rₓ = -₂‿cong (r rₓ)
isMagma : IsMagma _+_
isMagma = record
{ isEquivalence = ≈-isEquiv
-- I don't know how to solve this: I'd like to write simply ∙-cong = +-cong
; ∙-cong = λ {f} {g} {u} {v} -> +-cong {f} {g} {u} {v}
}
isSemigroup : IsSemigroup _+_
isSemigroup = record
{ isMagma = isMagma
; assoc = +-assoc
}
isMonoid : IsMonoid _+_ 0#
isMonoid = record
{ isSemigroup = isSemigroup
; identity = +-identity
}
isGroup : IsGroup _+_ 0# -_
isGroup = record
{ isMonoid = isMonoid
; inverse = -‿inverse
; ⁻¹-cong = λ {f} {g} -> -‿cong {f} {g}
}
isAbelianGroup : IsAbelianGroup _+_ 0# -_
isAbelianGroup = record
{ isGroup = isGroup
; comm = +-comm
}
isVectorSpace : IsVectorSpace K _≈_ _+_ _∙_ -_ 0#
isVectorSpace = record
{ isAbelianGroup = isAbelianGroup
; *ᵏ-∙-compat = *ᵏ-∙-compat
; ∙-+-distrib = ∙-+-distrib
; ∙-+ᵏ-distrib = ∙-+ᵏ-distrib
; ∙-cong = λ {a} {b} {f} {g} -> ∙-cong {a} {b} {f} {g}
; ∙-identity = ∙-identity
; ∙-absorbˡ = ∙-absorbˡ
}
vectorSpace : VectorSpace K (suc (k ⊔ a₁ ⊔ a₂ ⊔ ℓ₁ ⊔ ℓ₂)) (a₁ ⊔ ℓ₁ ⊔ ℓ₂)
vectorSpace = record { isVectorSpace = isVectorSpace }
| {
"alphanum_fraction": 0.4610706809,
"avg_line_length": 30.396969697,
"ext": "agda",
"hexsha": "a6b57632a0ab9e4199e4ad177ce117cc3a07320a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "felko/linear-algebra",
"max_forks_repo_path": "src/Algebra/Linear/Space/Hom.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "felko/linear-algebra",
"max_issues_repo_path": "src/Algebra/Linear/Space/Hom.agda",
"max_line_length": 102,
"max_stars_count": 15,
"max_stars_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "felko/linear-algebra",
"max_stars_repo_path": "src/Algebra/Linear/Space/Hom.agda",
"max_stars_repo_stars_event_max_datetime": "2020-12-30T06:18:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-02T14:11:00.000Z",
"num_tokens": 5181,
"size": 10031
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Functions.Definition
open import Groups.Groups
open import Groups.Definition
open import Rings.Definition
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Naturals
open import Numbers.Naturals.Order
open import Numbers.Naturals.Order.Lemmas
open import Numbers.Integers.Integers
open import Numbers.Primes.PrimeNumbers
open import Numbers.Modulo.Definition
open import Numbers.Modulo.Group
open import Numbers.Naturals.EuclideanAlgorithm
open import Orders.Total.Definition
module Rings.Examples.Proofs where
nToZn' : (n : ℕ) (pr : 0 <N n) (x : ℕ) → ℤn n pr
nToZn' 0 ()
nToZn' (succ n) pr x with divisionAlg (succ n) x
nToZn' (succ n) pr1 x | record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = inl thing ; quotSmall = quotSmall } = record { x = rem ; xLess = thing }
nToZn' (succ n) pr1 x | record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = inr () ; quotSmall = quotSmall }
mod' : (n : ℕ) → (pr : 0 <N n) → ℤ → ℤn n pr
mod' zero () a
mod' (succ n) pr (nonneg x) = nToZn' (succ n) pr x
mod' (succ n) pr (negSucc x) = Group.inverse (ℤnGroup (succ n) pr) (nToZn' (succ n) pr (succ x))
subtractionEquiv : (a : ℕ) → {b c : ℕ} → (c<b : c <N b) → a +N c ≡ b → a ≡ subtractionNResult.result (-N (inl c<b))
subtractionEquiv 0 {b} {c} c<b pr rewrite pr = exFalso (TotalOrder.irreflexive ℕTotalOrder c<b)
subtractionEquiv (succ a) {b} {c} c<b pr = equivalentSubtraction 0 b (succ a) c (succIsPositive a) c<b (equalityCommutative pr)
modNExampleSurjective' : (n : ℕ) → (pr : 0 <N n) → Surjection (mod' n pr)
modNExampleSurjective' zero ()
modNExampleSurjective' (succ n) pr record { x = x ; xLess = xLess } with divisionAlg (succ n) x
modNExampleSurjective' (succ n) p record { x = x ; xLess = xLess } | record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = inl remIsSmall ; quotSmall = q } = nonneg x , lhs'
where
rs' : rem ≡ x
rs' = modIsUnique (record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = inl remIsSmall ; quotSmall = q }) (record { quot = 0 ; rem = x ; pr = blah ; remIsSmall = inl (<NProp xLess) ; quotSmall = inl (succIsPositive n) })
where
blah : n *N 0 +N x ≡ x
blah rewrite multiplicationNIsCommutative n 0 = refl
lhs : nToZn' (succ n) p x ≡ record { x = rem ; xLess = remIsSmall }
lhs with divisionAlg (succ n) x
lhs | record { quot = quot' ; rem = rem' ; pr = pr' ; remIsSmall = inl t ; quotSmall = quotSmall } = equalityZn (equalityCommutative rs)
where
rs : rem ≡ rem'
rs = modIsUnique (record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = inl remIsSmall; quotSmall = q }) (record { quot = quot' ; rem = rem' ; pr = pr' ; remIsSmall = inl t ; quotSmall = quotSmall })
lhs | record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = inr () ; quotSmall = quotSmall }
lhs' : nToZn' (succ n) p x ≡ record { x = x ; xLess = xLess }
lhs' = transitivity lhs (equalityZn rs')
modNExampleSurjective' (succ n) p record { x = x ; xLess = xLess } | record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = inr () ; quotSmall = quotSmall }
{-
modNExampleGroupHom' : (n : ℕ) → (pr : 0 <N n) → GroupHom ℤGroup (ℤnGroup n pr) (mod' n pr)
modNExampleGroupHom' 0 ()
GroupHom.wellDefined (modNExampleGroupHom' (succ n) pr) {x} {.x} refl = refl
GroupHom.groupHom (modNExampleGroupHom' (succ n) _) {nonneg a} {nonneg b} with divisionAlg (succ n) a
GroupHom.groupHom (modNExampleGroupHom' (succ n) _) {nonneg a} {nonneg b} | record { quot = quotA ; rem = remA ; pr = prA ; remIsSmall = inl remA<sn ; quotSmall = quotSmallA } with divisionAlg (succ n) b
GroupHom.groupHom (modNExampleGroupHom' (succ n) _) {nonneg a} {nonneg b} | record { quot = quotA ; rem = remA ; pr = prA ; remIsSmall = inl remA<sn ; quotSmall = quotSmallA } | record { quot = quotB ; rem = remB ; pr = prB ; remIsSmall = inl remB<sn ; quotSmall = quotSmallB } with orderIsTotal (remA +N remB) (succ n)
GroupHom.groupHom (modNExampleGroupHom' (succ n) pr1) {nonneg a} {nonneg b} | record { quot = quotA ; rem = remA ; pr = prA ; remIsSmall = inl remA<sn ; quotSmall = _ } | record { quot = quotB ; rem = remB ; pr = prB ; remIsSmall = inl remB<sn ; quotSmall = _ } | inl (inl rarb<sn) rewrite addingNonnegIsHom a b = equalityZn _ _ lemma
where
lemma : ℤn.x (nToZn' (succ n) pr1 (a +N b)) ≡ remA +N remB
lemma with divisionAlg (succ n) (a +N b)
lemma | record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = inl x ; quotSmall = inl _ } = equalityCommutative thing5
where
thing : ((succ n) *N quotA +N remA) +N ((succ n) *N quotB +N remB) ≡ a +N b
thing rewrite prA | prB = refl
thing2 : ((succ n) *N quotA +N remA) +N ((succ n) *N quotB +N remB) ≡ (succ n) *N quot +N rem
thing2 rewrite pr = thing
thing3 : (((succ n) *N quotA) +N ((succ n) *N quotB)) +N (remA +N remB) ≡ (succ n) *N quot +N rem
thing3 rewrite equalityCommutative (additionNIsAssociative (((succ n) *N quotA) +N ((succ n) *N quotB)) remA remB) | additionNIsAssociative ((succ n) *N quotA) ((succ n) *N quotB) remA | additionNIsCommutative ((succ n) *N quotB) remA | equalityCommutative (additionNIsAssociative ((succ n) *N quotA) remA ((succ n) *N quotB)) | additionNIsAssociative ((succ n) *N quotA +N remA) ((succ n) *N quotB) remB = thing2
thing4 : (succ n) *N (quotA +N quotB) +N (remA +N remB) ≡ (succ n) *N quot +N rem
thing4 rewrite productDistributes (succ n) quotA quotB = thing3
thing5 : remA +N remB ≡ rem
thing5 = modUniqueLemma {remA +N remB} {rem} {succ n} (quotA +N quotB) quot rarb<sn x thing4
lemma | record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = inl x ; quotSmall = inr () }
lemma | record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = inr () ; quotSmall = quotSmall }
GroupHom.groupHom (modNExampleGroupHom' (succ n) pr1) {nonneg a} {nonneg b} | record { quot = quotA ; rem = remA ; pr = prA ; remIsSmall = inl remA<sn } | record { quot = quotB ; rem = remB ; pr = prB ; remIsSmall = inl remB<sn } | inl (inr sn<rarb) rewrite addingNonnegIsHom a b = equalityZn _ _ lemma
where
lemma : ℤn.x (nToZn' (succ n) pr1 (a +N b)) ≡ subtractionNResult.result (-N (inl sn<rarb))
lemma with divisionAlg (succ n) (a +N b)
lemma | record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = inl x ; quotSmall = q } = modIsUnique record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = inl x ; quotSmall = q } record { quot = succ quotA +N quotB ; rem = subtractionNResult.result (-N (inl sn<rarb)) ; pr = answer ; remIsSmall = inl remSmall ; quotSmall = inl (succIsPositive n) }
where
transform : (a : ℕ) → {b c : ℕ} → (p : b <N c) → c <N a +N b → subtractionNResult.result (-N (inl p)) <N a
transform a {b} {c} pr (le y proof1) with addIntoSubtraction (succ y) {b} {c} (inl pr)
... | bl = le y (transitivity bl (equalityCommutative (subtractionEquiv a (orderIsTransitive pr (addingIncreases c y)) (equalityCommutative (identityOfIndiscernablesLeft _ _ _ _≡_ proof1 (additionNIsCommutative (succ y) c))))))
thing : ((succ n) *N quotA +N remA) +N ((succ n) *N quotB +N remB) ≡ a +N b
thing rewrite prA | prB = refl
thing2 : (((succ n) *N quotA) +N ((succ n) *N quotB)) +N (remA +N remB) ≡ a +N b
thing2 = identityOfIndiscernablesLeft _ _ _ _≡_ thing (transitivity (equalityCommutative (additionNIsAssociative ((quotA +N n *N quotA) +N remA) (succ n *N quotB) remB)) (transitivity (applyEquality (λ i → i +N remB) (additionNIsAssociative (quotA +N n *N quotA) remA (quotB +N n *N quotB))) (transitivity (applyEquality (λ i → ((quotA +N n *N quotA) +N i) +N remB) (additionNIsCommutative remA (quotB +N n *N quotB))) (transitivity (applyEquality (λ i → i +N remB) (equalityCommutative (additionNIsAssociative (quotA +N n *N quotA) (quotB +N n *N quotB) remA))) (additionNIsAssociative _ remA remB)))))
thing3 : (succ n) *N (quotA +N quotB) +N (remA +N remB) ≡ a +N b
thing3 = identityOfIndiscernablesLeft _ _ _ _≡_ thing2 (equalityCommutative (applyEquality (λ i → i +N (remA +N remB)) (productDistributes (succ n) (quotA) quotB)))
answer : (succ n *N succ (quotA +N quotB)) +N subtractionNResult.result (-N (inl sn<rarb)) ≡ a +N b
answer with addIntoSubtraction (succ n *N succ (quotA +N quotB)) (inl sn<rarb)
... | bl = transitivity bl (moveOneSubtraction' {a<=b = inl (orderIsTransitive sn<rarb (addingIncreases (remA +N remB) ((quotA +N quotB) +N n *N succ (quotA +N quotB))))} answer')
where
snTimes1 : succ n ≡ succ n *N 1
snTimes1 rewrite multiplicationNIsCommutative (succ n) 1 | additionNIsCommutative (succ n) 0 = refl
q' : succ n *N succ (quotA +N quotB) ≡ succ n +N (succ n *N (quotA +N quotB))
q' rewrite additionNIsCommutative (succ n) (succ n *N (quotA +N quotB)) | snTimes1 | equalityCommutative (productDistributes (succ n) (quotA +N quotB) 1) = applyEquality (λ i → (succ n) *N i) (succIsAddOne (quotA +N quotB))
answer'' : (succ n *N succ (quotA +N quotB)) +N (remA +N remB) ≡ (succ n) +N ((succ n *N (quotA +N quotB)) +N (remA +N remB))
answer'' rewrite equalityCommutative (additionNIsAssociative (succ n) (succ n *N (quotA +N quotB)) (remA +N remB)) = applyEquality (λ i → i +N (remA +N remB)) q'
answer' : (remA +N remB) +N (succ n *N succ (quotA +N quotB)) ≡ succ n +N (a +N b)
answer' rewrite equalityCommutative thing3 = transitivity (additionNIsCommutative (remA +N remB) (succ n *N succ (quotA +N quotB))) answer''
remSmall : subtractionNResult.result (-N (inl sn<rarb)) <N succ n
remSmall = transform (succ n) sn<rarb (addStrongInequalities remA<sn remB<sn)
lemma | record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = inr () ; quotSmall = quotSmall }
GroupHom.groupHom (modNExampleGroupHom' (succ n) pr1) {nonneg a} {nonneg b} | record { quot = quotA ; rem = remA ; pr = prA ; remIsSmall = inl remA<sn } | record { quot = quotB ; rem = remB ; pr = prB ; remIsSmall = inl remB<sn } | inr rarb=sn rewrite addingNonnegIsHom a b = equalityZn _ _ lemma
where
lemma : ℤn.x (nToZn' (succ n) pr1 (a +N b)) ≡ 0
lemma with divisionAlg (succ n) (a +N b)
lemma | record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = inl x } = equalityCommutative (modUniqueLemma ((quotA +N quotB) +N 1) quot pr1 x thing7)
where
thing : ((succ n) *N quotA +N remA) +N ((succ n) *N quotB +N remB) ≡ a +N b
thing rewrite prA | prB = refl
thing2 : ((succ n) *N quotA +N remA) +N ((succ n) *N quotB +N remB) ≡ (succ n) *N quot +N rem
thing2 rewrite pr = thing
thing3 : (((succ n) *N quotA) +N ((succ n) *N quotB)) +N (remA +N remB) ≡ (succ n) *N quot +N rem
thing3 rewrite equalityCommutative (additionNIsAssociative (((succ n) *N quotA) +N ((succ n) *N quotB)) remA remB) | additionNIsAssociative ((succ n) *N quotA) ((succ n) *N quotB) remA | additionNIsCommutative ((succ n) *N quotB) remA | equalityCommutative (additionNIsAssociative ((succ n) *N quotA) remA ((succ n) *N quotB)) | additionNIsAssociative ((succ n) *N quotA +N remA) ((succ n) *N quotB) remB = thing2
thing4 : (succ n) *N (quotA +N quotB) +N (remA +N remB) ≡ (succ n) *N quot +N rem
thing4 rewrite productDistributes (succ n) quotA quotB = thing3
thing5 : (succ n) *N (quotA +N quotB) +N (succ n) ≡ (succ n) *N quot +N rem
thing5 rewrite equalityCommutative rarb=sn = thing4
thing6 : (succ n) *N ((quotA +N quotB) +N 1) ≡ (succ n) *N quot +N rem
thing6 rewrite productDistributes (succ n) (quotA +N quotB) 1 | multiplicationNIsCommutative n 1 | additionNIsCommutative n 0 = thing5
thing7 : (succ n) *N ((quotA +N quotB) +N 1) +N 0 ≡ (succ n) *N quot +N rem
thing7 = identityOfIndiscernablesLeft _ _ _ _≡_ thing6 (additionNIsCommutative 0 _)
lemma | record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = inr () ; quotSmall = quotSmall }
GroupHom.groupHom (modNExampleGroupHom' (succ n) _) {nonneg a} {nonneg b} | record { quot = quotA ; rem = remA ; pr = prA ; remIsSmall = inl remA<sn ; quotSmall = quotSmallA } | record { quot = quotB ; rem = remB ; pr = prB ; remIsSmall = inr () ; quotSmall = quotSmallB }
GroupHom.groupHom (modNExampleGroupHom' (succ n) _) {nonneg a} {nonneg b} | record { quot = quot ; rem = rem ; pr = pr ; remIsSmall = inr () ; quotSmall = quotSmall }
GroupHom.groupHom (modNExampleGroupHom' (succ n) _) {nonneg a} {negSucc b} with divisionAlg (succ n) a
GroupHom.groupHom (modNExampleGroupHom' (succ n) _) {nonneg a} {negSucc b} | record { quot = quotA ; rem = remA ; pr = prA ; remIsSmall = remIsSmallA ; quotSmall = quotSmallA } = {!!}
GroupHom.groupHom (modNExampleGroupHom' (succ n) _) {negSucc x} {nonneg b} with divisionAlg (succ n) (succ x)
... | bl = {!!}
GroupHom.groupHom (modNExampleGroupHom' (succ n) _) {negSucc x} {negSucc b} with divisionAlg (succ n) (succ x)
... | bl = {!!}
-}
| {
"alphanum_fraction": 0.6300617191,
"avg_line_length": 93.5633802817,
"ext": "agda",
"hexsha": "d255f6968c0d5dd99d74c31ae696526898074c99",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Rings/Examples/Proofs.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Rings/Examples/Proofs.agda",
"max_line_length": 613,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Rings/Examples/Proofs.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": 4691,
"size": 13286
} |
module Common.Weakening where
-- open import Agda.Primitive
import Data.List as List
open import Data.List.Base
open import Data.List.Membership.Propositional
open import Data.List.Relation.Unary.All as All
open import Data.List.Prefix
open import Function
open import Level
{-
The following `Weakenable` record defines a class of weakenable (or
monotone) predicates over lists.
We can make the definitions of `Weakenable` available using the
syntax:
open Weakenable ⦃...⦄ public
Whenever we use `wk e p` where `e : x ⊑ x'`, `p : P x` where `x x' :
List X`, Agda will use instance argument search to find a defined
instance of `Weakenable {X} P`. See also
http://agda.readthedocs.io/en/v2.5.3/language/instance-arguments.html
-}
record Weakenable {i j}{A : Set i}(p : List A → Set j) : Set (i ⊔ j) where
field wk : ∀ {w w'} → w ⊑ w' → p w → p w'
{-
In general, weakenable predicates can be defined over *any* preorder.
See `Experiments.Category` for a more general definition and
treatment.
The definition of `Weakenable` above is specialized to the
interpreters in our paper which are all defined in terms of
weakenable predicates over lists.
-}
open Weakenable ⦃...⦄ public
{-
We define a few derived instances of `Weakenable` that appear
commonly.
-}
module _ {i} {A : Set i} where
instance
any-weakenable : ∀ {x : A} → Weakenable (λ xs → x ∈ xs)
any-weakenable = record { wk = λ ext l → ∈-⊒ l ext }
all-weakenable : ∀ {j} {B : Set j} {xs : List B}
→ ∀ {k} {C : B → List A → Set k} {{wₐ : ∀ {x} → Weakenable (C x)}}
→ Weakenable (λ ys → All (λ x → C x ys) xs)
all-weakenable {{wₐ}} = record {
wk = λ ext v → All.map (λ {a} y → Weakenable.wk wₐ ext y) v }
-- const-weakenable : ∀ {j}{I : Set j} → Weakenable {A = I} (λ _ → A)
-- const-weakenable = record { wk = λ ext c → c }
list-weakenable : ∀ {b}{B : List A → Set b}
→ {{wb : Weakenable B}} → Weakenable (λ W → List (B W))
list-weakenable {{ wₐ }} = record {wk = λ ext v → List.map (wk ext) v }
-- Nicer syntax for transitivity of prefixes:
infixl 30 _⊚_
_⊚_ : ∀ {i} {A : Set i} {W W' W'' : List A} → W' ⊒ W → W'' ⊒ W' → W'' ⊒ W
_⊚_ co₁ co₂ = ⊑-trans co₁ co₂
{-
Another common construction is that of products of weakenable
predicates. Section 3.4 defines this type, which corresponds to
`_∩_` from the Agda Standard Library:
-}
open import Relation.Unary
open import Data.Product
_⊗_ : ∀ {a}{i j}{W : Set a}(p : W → Set i)(q : W → Set j)(w : W) → Set (i ⊔ j)
_⊗_ = _∩_
-- We prove that when `_⊗_` is a product of two weakenable predicates,
-- then `_⊗_` is an instance of `Weakenable`:
instance
weaken-pair : ∀ {a}{A : Set a}{i j}{p : List A → Set i}{q : List A → Set j}
→ {{wp : Weakenable p}} {{wq : Weakenable q}}
→ Weakenable (p ⊗ q)
weaken-pair = record { wk = λ{ ext (x , y) → (wk ext x , wk ext y) } }
| {
"alphanum_fraction": 0.6153585927,
"avg_line_length": 33.9770114943,
"ext": "agda",
"hexsha": "ca54305f59b94a1164136bf0f5b8a9d9dd999763",
"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/Common/Weakening.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/Common/Weakening.agda",
"max_line_length": 85,
"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/Common/Weakening.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": 999,
"size": 2956
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Foundations.Pointed where
open import Cubical.Foundations.Pointed.Base public
open import Cubical.Foundations.Pointed.Properties public
open import Cubical.Foundations.Pointed.FunExt public
open import Cubical.Foundations.Pointed.Homotopy public
open import Cubical.Foundations.Pointed.Homogeneous
| {
"alphanum_fraction": 0.8333333333,
"avg_line_length": 36.6,
"ext": "agda",
"hexsha": "b9bfbbbc0924eb9cc2df700b8c8e5179a06509ac",
"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": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Foundations/Pointed.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/Foundations/Pointed.agda",
"max_line_length": 57,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/Foundations/Pointed.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 90,
"size": 366
} |
postulate
A B : Set
f : A → B
data D : B → Set where
c : {n : A} → D (f n)
test : (x : B) → D x → Set
test n c = {!!}
test2 : Set
test2 =
let X = A in
let X = B in
{!!}
| {
"alphanum_fraction": 0.4402173913,
"avg_line_length": 11.5,
"ext": "agda",
"hexsha": "f619b3639d17be61f392d2cb7ff8944c2c2e1835",
"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/Issue3813-ctx.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/Issue3813-ctx.agda",
"max_line_length": 26,
"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/Issue3813-ctx.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": 184
} |
module ProcessRun where
open import Data.Bool
open import Data.List
open import Data.Maybe
open import Data.Product
open import Relation.Binary.PropositionalEquality
open import Typing
open import ProcessSyntax
open import Channel
open import Global
open import Values
open import Session
open import Schedule
-- auxiliary lemmas
list-right-zero : ∀ {A : Set} → (xs : List A) → xs ++ [] ≡ xs
list-right-zero [] = refl
list-right-zero (x ∷ xs) = cong (_∷_ x) (list-right-zero xs)
list-assoc : ∀ {A : Set} → (xs ys zs : List A) → (xs ++ ys) ++ zs ≡ xs ++ (ys ++ zs)
list-assoc [] ys zs = refl
list-assoc (x ∷ xs) ys zs = cong (_∷_ x) (list-assoc xs ys zs)
cons-assoc : ∀ {A : Set} → (x : A) (xs ys : List A) → (x ∷ xs) ++ ys ≡ x ∷ (xs ++ ys)
cons-assoc x xs ys = refl
inactive-clone : (G : SCtx) → SCtx
inactive-clone [] = []
inactive-clone (x ∷ G) = nothing ∷ inactive-clone G
inactive-extension : ∀ {G} → Inactive G → (G' : SCtx) → Inactive (inactive-clone G' ++ G)
inactive-extension inaG [] = inaG
inactive-extension inaG (x ∷ G') = ::-inactive (inactive-extension inaG G')
splitting-extension : ∀ {G G₁ G₂} (G' : SCtx)
→ SSplit G G₁ G₂ → SSplit (inactive-clone G' ++ G) (inactive-clone G' ++ G₁) (inactive-clone G' ++ G₂)
splitting-extension [] ss = ss
splitting-extension (x ∷ G') ss = ss-both (splitting-extension G' ss)
left-right : (G' G'' : SCtx)
→ SSplit (G' ++ G'') (G' ++ inactive-clone G'') (inactive-clone G' ++ G'')
left-right [] [] = ss-[]
left-right [] (just x ∷ G'') = ss-right (left-right [] G'')
left-right [] (nothing ∷ G'') = ss-both (left-right [] G'')
left-right (x ∷ G') G'' with left-right G' G''
... | ss-G'G'' with x
left-right (x ∷ G') G'' | ss-G'G'' | just x₁ = ss-left ss-G'G''
left-right (x ∷ G') G'' | ss-G'G'' | nothing = ss-both ss-G'G''
ssplit-append : { G11 G12 G21 G22 : SCtx} (G1 G2 : SCtx) → SSplit G1 G11 G12 → SSplit G2 G21 G22 → SSplit (G1 ++ G2) (G11 ++ G21) (G12 ++ G22)
ssplit-append _ _ ss-[] ss2 = ss2
ssplit-append _ _ (ss-both ss1) ss2 = ss-both (ssplit-append _ _ ss1 ss2)
ssplit-append _ _ (ss-left ss1) ss2 = ss-left (ssplit-append _ _ ss1 ss2)
ssplit-append _ _ (ss-right ss1) ss2 = ss-right (ssplit-append _ _ ss1 ss2)
ssplit-append _ _ (ss-posneg ss1) ss2 = ss-posneg (ssplit-append _ _ ss1 ss2)
ssplit-append _ _ (ss-negpos ss1) ss2 = ss-negpos (ssplit-append _ _ ss1 ss2)
-- weakening #1
weaken1-cr : ∀ {G b s} G' → ChannelRef G b s → ChannelRef (inactive-clone G' ++ G) b s
weaken1-cr [] cr = cr
weaken1-cr (x ∷ G') cr = there (weaken1-cr G' cr)
weaken1-val : ∀ {G t} G' → Val G t → Val (inactive-clone G' ++ G) t
weaken1-venv : ∀ {G Φ} G' → VEnv G Φ → VEnv (inactive-clone G' ++ G) Φ
weaken1-val G' (VUnit inaG) = VUnit (inactive-extension inaG G')
weaken1-val G' (VInt i inaG) = VInt i (inactive-extension inaG G')
weaken1-val G' (VPair ss-GG₁G₂ v v₁) = VPair (splitting-extension G' ss-GG₁G₂) (weaken1-val G' v) (weaken1-val G' v₁)
weaken1-val G' (VChan b vcr) = VChan b (weaken1-cr G' vcr)
weaken1-val G' (VFun x ϱ e) = VFun x (weaken1-venv G' ϱ) e
weaken1-venv G' (vnil ina) = vnil (inactive-extension ina G')
weaken1-venv G' (vcons ssp v ϱ) = vcons (splitting-extension G' ssp) (weaken1-val G' v) (weaken1-venv G' ϱ)
weaken1-cont : ∀ {G t φ} G' → Cont G φ t → Cont (inactive-clone G' ++ G) φ t
weaken1-cont G' (halt inaG un-t) = halt (inactive-extension inaG G') un-t
weaken1-cont G' (bind ts ss e₂ ϱ₂ κ) = bind ts (splitting-extension G' ss) e₂ (weaken1-venv G' ϱ₂) (weaken1-cont G' κ)
weaken1-cont G' (bind-thunk ts ss e₂ ϱ₂ κ) = bind-thunk ts (splitting-extension G' ss) e₂ (weaken1-venv G' ϱ₂) (weaken1-cont G' κ)
weaken1-cont G' (subsume x κ) = subsume x (weaken1-cont G' κ)
weaken1-command : ∀ {G} G' → Command G → Command (inactive-clone G' ++ G)
weaken1-command G' (Fork ss κ₁ κ₂) = Fork (splitting-extension G' ss) (weaken1-cont G' κ₁) (weaken1-cont G' κ₂)
weaken1-command G' (Ready ss v κ) = Ready (splitting-extension G' ss) (weaken1-val G' v) (weaken1-cont G' κ)
weaken1-command G' (Halt x x₁ x₂) = Halt (inactive-extension x G') x₁ (weaken1-val G' x₂)
weaken1-command G' (New s κ) = New s (weaken1-cont G' κ)
weaken1-command G' (Close ss v κ) = Close (splitting-extension G' ss) (weaken1-val G' v) (weaken1-cont G' κ)
weaken1-command G' (Wait ss v κ) = Wait (splitting-extension G' ss) (weaken1-val G' v) (weaken1-cont G' κ)
weaken1-command G' (Send ss ss-args vch v κ) = Send (splitting-extension G' ss) (splitting-extension G' ss-args) (weaken1-val G' vch) (weaken1-val G' v) (weaken1-cont G' κ)
weaken1-command G' (Recv ss vch κ) = Recv (splitting-extension G' ss) (weaken1-val G' vch) (weaken1-cont G' κ)
weaken1-command G' (Select ss lab vch κ) = Select (splitting-extension G' ss) lab (weaken1-val G' vch) (weaken1-cont G' κ)
weaken1-command G' (Branch ss vch dcont) = Branch (splitting-extension G' ss) (weaken1-val G' vch) λ lab → weaken1-cont G' (dcont lab)
weaken1-command G' (NSelect ss lab vch κ) = NSelect (splitting-extension G' ss) lab (weaken1-val G' vch) (weaken1-cont G' κ)
weaken1-command G' (NBranch ss vch dcont) = NBranch (splitting-extension G' ss) (weaken1-val G' vch) λ lab → weaken1-cont G' (dcont lab)
weaken1-threadpool : ∀ {G} G' → ThreadPool G → ThreadPool (inactive-clone G' ++ G)
weaken1-threadpool G' (tnil ina) = tnil (inactive-extension ina G')
weaken1-threadpool G' (tcons ss cmd tp) = tcons (splitting-extension G' ss) (weaken1-command G' cmd) (weaken1-threadpool G' tp)
-- auxiliary
inactive-insertion : ∀ {G} G' G'' → Inactive (G' ++ G) → Inactive (G' ++ inactive-clone G'' ++ G)
inactive-insertion [] G'' ina-G'G = inactive-extension ina-G'G G''
inactive-insertion (just x ∷ G') G'' ()
inactive-insertion (nothing ∷ G') G'' (::-inactive ina-G'G) = ::-inactive (inactive-insertion G' G'' ina-G'G)
splitting-insertion : ∀ {G G₁ G₂} {G' G₁' G₂'} G''
→ SSplit G' G₁' G₂'
→ SSplit G G₁ G₂
→ SSplit (G' ++ inactive-clone G'' ++ G) (G₁' ++ inactive-clone G'' ++ G₁) (G₂' ++ inactive-clone G'' ++ G₂)
splitting-insertion G'' ss-[] ss = splitting-extension G'' ss
splitting-insertion G'' (ss-both ss') ss = ss-both (splitting-insertion G'' ss' ss)
splitting-insertion G'' (ss-left ss') ss = ss-left (splitting-insertion G'' ss' ss)
splitting-insertion G'' (ss-right ss') ss = ss-right (splitting-insertion G'' ss' ss)
splitting-insertion G'' (ss-posneg ss') ss = ss-posneg (splitting-insertion G'' ss' ss)
splitting-insertion G'' (ss-negpos ss') ss = ss-negpos (splitting-insertion G'' ss' ss)
split-append : ∀ {G G1 G2} G'
→ SSplit (G' ++ G) G1 G2
→ ∃ λ G₁' → ∃ λ G₂' → ∃ λ G₁ → ∃ λ G₂
→ SSplit G' G₁' G₂' × SSplit G G₁ G₂ × G1 ≡ G₁' ++ G₁ × G2 ≡ G₂' ++ G₂
split-append [] ss = _ , _ , _ , _ , ss-[] , ss , refl , refl
split-append (.nothing ∷ G') (ss-both ss) with split-append G' ss
... | G₁' , G₂' , G₁ , G₂ , ss' , ss0 , refl , refl = _ , _ , _ , _ , (ss-both ss') , ss0 , refl , refl
split-append (.(just _) ∷ G') (ss-left ss) with split-append G' ss
... | G₁' , G₂' , G₁ , G₂ , ss' , ss0 , refl , refl = _ , _ , _ , _ , (ss-left ss') , ss0 , refl , refl
split-append (.(just _) ∷ G') (ss-right ss) with split-append G' ss
... | G₁' , G₂' , G₁ , G₂ , ss' , ss0 , refl , refl = _ , _ , _ , _ , (ss-right ss') , ss0 , refl , refl
split-append (.(just (_ , POSNEG)) ∷ G') (ss-posneg ss) with split-append G' ss
... | G₁' , G₂' , G₁ , G₂ , ss' , ss0 , refl , refl = _ , _ , _ , _ , (ss-posneg ss') , ss0 , refl , refl
split-append (.(just (_ , POSNEG)) ∷ G') (ss-negpos ss) with split-append G' ss
... | G₁' , G₂' , G₁ , G₂ , ss' , ss0 , refl , refl = _ , _ , _ , _ , (ss-negpos ss') , ss0 , refl , refl
-- weakening #2
weaken2-cr : ∀ {G b s} G' G'' → ChannelRef (G' ++ G) b s → ChannelRef (G' ++ inactive-clone G'' ++ G) b s
weaken2-cr [] G'' cr = weaken1-cr G'' cr
weaken2-cr (.(just (_ , POS)) ∷ G') G'' (here-pos ina-G x) = here-pos (inactive-insertion G' G'' ina-G) x
weaken2-cr (.(just (_ , NEG)) ∷ G') G'' (here-neg ina-G x) = here-neg (inactive-insertion G' G'' ina-G) x
weaken2-cr (.nothing ∷ G') G'' (there cr) = there (weaken2-cr G' G'' cr)
weaken2-val : ∀ {G t} G' G'' → Val (G' ++ G) t → Val (G' ++ inactive-clone G'' ++ G) t
weaken2-venv : ∀ {G Φ} G' G'' → VEnv (G' ++ G) Φ → VEnv (G' ++ inactive-clone G'' ++ G) Φ
weaken2-val G' G'' (VUnit inaG) = VUnit (inactive-insertion G' G'' inaG)
weaken2-val G' G'' (VInt i inaG) = VInt i (inactive-insertion G' G'' inaG)
weaken2-val G' G'' (VPair ss-GG₁G₂ v₁ v₂) with split-append G' ss-GG₁G₂
... | G₁' , G₂' , G₁ , G₂ , ss' , ss0 , refl , refl = VPair (splitting-insertion G'' ss' ss0) (weaken2-val G₁' G'' v₁) (weaken2-val G₂' G'' v₂)
weaken2-val G' G'' (VChan b vcr) = VChan b (weaken2-cr G' G'' vcr)
weaken2-val G' G'' (VFun x ϱ e) = VFun x (weaken2-venv G' G'' ϱ) e
weaken2-venv G' G'' (vnil ina) = vnil (inactive-insertion G' G'' ina)
weaken2-venv G' G'' (vcons{G₁ = Gv}{G₂ = Gϱ} ssp v ϱ) with split-append G' ssp
... | G₁' , G₂' , G₁ , G₂ , ss' , ss0 , refl , refl = vcons (splitting-insertion G'' ss' ss0) (weaken2-val G₁' G'' v) (weaken2-venv G₂' G'' ϱ)
weaken2-cont : ∀ {G t φ} G' G'' → Cont (G' ++ G) φ t → Cont (G' ++ inactive-clone G'' ++ G) φ t
weaken2-cont G' G'' (halt x un-t) = halt (inactive-insertion G' G'' x) un-t
weaken2-cont G' G'' (bind ts ss e₂ ϱ₂ κ) with split-append G' ss
... | G₁' , G₂' , G₁ , G₂ , ss' , ss0 , refl , refl = bind ts (splitting-insertion G'' ss' ss0) e₂ (weaken2-venv G₁' G'' ϱ₂) (weaken2-cont G₂' G'' κ)
weaken2-cont G' G'' (bind-thunk ts ss e₂ ϱ₂ κ) with split-append G' ss
... | G₁' , G₂' , G₁ , G₂ , ss' , ss0 , refl , refl = bind-thunk ts (splitting-insertion G'' ss' ss0) e₂ (weaken2-venv G₁' G'' ϱ₂) (weaken2-cont G₂' G'' κ)
weaken2-cont G' G'' (subsume x κ) = subsume x (weaken2-cont G' G'' κ)
weaken2-command : ∀ {G} G' G'' → Command (G' ++ G) → Command (G' ++ inactive-clone G'' ++ G)
weaken2-command G' G'' (Fork ss κ₁ κ₂) with split-append G' ss
... | G₁' , G₂' , G₁ , G₂ , ss' , ss0 , refl , refl = Fork (splitting-insertion G'' ss' ss0) (weaken2-cont G₁' G'' κ₁) (weaken2-cont G₂' G'' κ₂)
weaken2-command G' G'' (Ready ss v κ) with split-append G' ss
... | G₁' , G₂' , G₁ , G₂ , ss' , ss0 , refl , refl = Ready (splitting-insertion G'' ss' ss0) (weaken2-val G₁' G'' v) (weaken2-cont G₂' G'' κ)
weaken2-command G' G'' (Halt x x₁ x₂) = Halt (inactive-insertion G' G'' x) x₁ (weaken2-val G' G'' x₂)
weaken2-command G' G'' (New s κ) = New s (weaken2-cont G' G'' κ)
weaken2-command G' G'' (Close ss v κ) with split-append G' ss
... | G₁' , G₂' , G₁ , G₂ , ss' , ss0 , refl , refl = Close (splitting-insertion G'' ss' ss0) (weaken2-val G₁' G'' v) (weaken2-cont G₂' G'' κ)
weaken2-command G' G'' (Wait ss v κ) with split-append G' ss
... | G₁' , G₂' , G₁ , G₂ , ss' , ss0 , refl , refl = Wait (splitting-insertion G'' ss' ss0) (weaken2-val G₁' G'' v) (weaken2-cont G₂' G'' κ)
weaken2-command G' G'' (Send ss ss-args vch v κ) with split-append G' ss
... | G₁' , G₂' , G₁ , G₂ , ss' , ss0 , refl , refl with split-append G₁' ss-args
... | G₁₁' , G₁₂' , G₁₁ , G₁₂ , ss-args' , ss0-args , refl , refl = Send (splitting-insertion G'' ss' ss0) (splitting-insertion G'' ss-args' ss0-args) (weaken2-val G₁₁' G'' vch) (weaken2-val G₁₂' G'' v) (weaken2-cont G₂' G'' κ)
weaken2-command G' G'' (Recv ss vch κ) with split-append G' ss
... | G₁' , G₂' , G₁ , G₂ , ss' , ss0 , refl , refl = Recv (splitting-insertion G'' ss' ss0) (weaken2-val G₁' G'' vch) (weaken2-cont G₂' G'' κ)
weaken2-command G' G'' (Select ss lab vch κ) with split-append G' ss
... | G₁' , G₂' , G₁ , G₂ , ss' , ss0 , refl , refl = Select (splitting-insertion G'' ss' ss0) lab (weaken2-val G₁' G'' vch) (weaken2-cont G₂' G'' κ)
weaken2-command G' G'' (Branch ss vch dcont) with split-append G' ss
... | G₁' , G₂' , G₁ , G₂ , ss' , ss0 , refl , refl = Branch (splitting-insertion G'' ss' ss0) (weaken2-val G₁' G'' vch) λ lab → weaken2-cont G₂' G'' (dcont lab)
weaken2-command G' G'' (NSelect ss lab vch κ) with split-append G' ss
... | G₁' , G₂' , G₁ , G₂ , ss' , ss0 , refl , refl = NSelect (splitting-insertion G'' ss' ss0) lab (weaken2-val G₁' G'' vch) (weaken2-cont G₂' G'' κ)
weaken2-command G' G'' (NBranch ss vch dcont) with split-append G' ss
... | G₁' , G₂' , G₁ , G₂ , ss' , ss0 , refl , refl = NBranch (splitting-insertion G'' ss' ss0) (weaken2-val G₁' G'' vch) λ lab → weaken2-cont G₂' G'' (dcont lab)
weaken2-threadpool : ∀ {G} G' G'' → ThreadPool (G' ++ G) → ThreadPool (G' ++ inactive-clone G'' ++ G)
weaken2-threadpool G' G'' (tnil ina) = tnil (inactive-insertion G' G'' ina)
weaken2-threadpool G' G'' (tcons ss cmd tp) with split-append G' ss
... | G₁' , G₂' , G₁ , G₂ , ss' , ss0 , refl , refl = tcons (splitting-insertion G'' ss' ss0) (weaken2-command G₁' G'' cmd) (weaken2-threadpool G₂' G'' tp)
-- translate a process term to semantics (i.e., a list of commands)
runProc : ∀ {Φ} → (G : SCtx) → Proc Φ → VEnv G Φ → ∃ λ G' → ThreadPool (G' ++ G)
runProc G (exp e) ϱ with ssplit-refl-left-inactive G
... | G' , ina-G' , sp-GGG' = [] , (tcons sp-GGG' (run (split-all-left _) sp-GGG' e ϱ (halt ina-G' UUnit)) (tnil ina-G'))
runProc G (par sp P₁ P₂) ϱ with split-env sp ϱ
... | (G₁ , G₂) , ss-GG1G2 , ϱ₁ , ϱ₂ with runProc G₁ P₁ ϱ₁ | runProc G₂ P₂ ϱ₂
... | (G₁' , tp1) | (G₂' , tp2) with weaken1-threadpool G₁' tp2
... | tp2' with weaken2-threadpool G₁' G₂' tp1
... | tp1' with left-right G₁' G₂'
... | ss-G1'G2' rewrite sym (list-assoc G₁' (inactive-clone G₂') G₁) | sym (list-assoc (inactive-clone G₁') G₂' G₂) = (G₁' ++ G₂') , tappend ssfinal tp1' tp2'
where
ssfinal : SSplit ((G₁' ++ G₂') ++ G) ((G₁' ++ inactive-clone G₂') ++ G₁) ((inactive-clone G₁' ++ G₂') ++ G₂)
ssfinal = ssplit-append (G₁' ++ G₂') G ss-G1'G2' ss-GG1G2
runProc G (res s P) ϱ with ssplit-refl-right-inactive G
... | G1 , ina-G1 , ss-GG1G with runProc (just (SType.force s , POSNEG) ∷ G) P (vcons (ss-posneg ss-GG1G) (VChan POS (here-pos ina-G1 (subF-refl _))) (vcons (ss-left ss-GG1G) (VChan NEG (here-neg ina-G1 (subF-refl _))) (lift-venv ϱ)))
... | G' , tp = G' ++ just (SType.force s , POSNEG) ∷ [] , tp'
where
tp' : ThreadPool ((G' ++ just (SType.force s , POSNEG) ∷ []) ++ G)
tp' rewrite list-assoc G' (just (SType.force s , POSNEG) ∷ []) G = tp
startProc : Gas → Proc [] → Outcome
startProc f P with runProc [] P (vnil []-inactive)
... | G , tp = schedule f tp
| {
"alphanum_fraction": 0.6152600831,
"avg_line_length": 63.1422222222,
"ext": "agda",
"hexsha": "91be1f5b163222506fb1186d36f8fd12acf9ee33",
"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": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "peterthiemann/definitional-session",
"max_forks_repo_path": "src/ProcessRun.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c",
"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": "peterthiemann/definitional-session",
"max_issues_repo_path": "src/ProcessRun.agda",
"max_line_length": 234,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "peterthiemann/definitional-session",
"max_stars_repo_path": "src/ProcessRun.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-18T08:10:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-01-19T16:33:27.000Z",
"num_tokens": 5665,
"size": 14207
} |
{-# OPTIONS --safe --warning=error --without-K --guardedness #-}
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import LogicalFormulae
open import Groups.Lemmas
open import Groups.Definition
open import Setoids.Orders.Total.Definition
open import Setoids.Setoids
open import Functions.Definition
open import Sets.EquivalenceRelations
open import Rings.Definition
open import Rings.Orders.Total.Definition
open import Rings.Orders.Partial.Definition
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
open import Numbers.Modulo.Definition
open import Semirings.Definition
open import Orders.Total.Definition
open import Sequences
open import Numbers.Integers.Definition
open import Numbers.Integers.Addition
open import Numbers.Integers.Multiplication
open import Numbers.Integers.Order
open import Numbers.Rationals.Definition
open import Vectors
open import Fields.Fields
module Rings.Orders.Total.Examples where
open import Rings.Orders.Total.BaseExpansion (ℚOrdered) {10} (le 8 refl)
open Field ℚField
t : Vec ℚ 5
t = take 5 (partialSums (funcToSequence injectionNQ))
u : Vec ℚ 5
u = vecMap injectionNQ (0 ,- (1 ,- (3 ,- (6 ,- (10 ,- [])))))
pr : Vec (ℚ && ℚ) 5
pr = vecZip t u
ans : vecAllTrue (λ x → _&&_.fst x =Q _&&_.snd x) pr
ans = refl ,, (refl ,, (refl ,, (refl ,, (refl ,, record {}))))
open import Rings.InitialRing ℚRing
a : Sequence ℚ
a with allInvertible (fromN 10) (λ ())
... | 1/10 , pr1/10 = approximations 1/10 pr1/10 (baseNExpansion (underlying (allInvertible (injectionNQ 7) λ ())) (lessInherits (succIsPositive 0)) (lessInherits (le 5 refl)))
expected : Vec ℚ _
expected = record { num = nonneg 1 ; denom = nonneg 10 ; denomNonzero = f } ,- record { num = nonneg 14 ; denom = nonneg 100 ; denomNonzero = λ () } ,- record { num = nonneg 142 ; denom = nonneg 1000 ; denomNonzero = λ () } ,- []
where
f : nonneg 10 ≡ nonneg 0 → False
f ()
ans' : vecAllTrue (λ x → _&&_.fst x =Q _&&_.snd x) (vecZip (take _ a) expected)
ans' = refl ,, (refl ,, (refl ,, record {}))
| {
"alphanum_fraction": 0.7209985316,
"avg_line_length": 34.6271186441,
"ext": "agda",
"hexsha": "98daa30c82f9fbd96f20c4e2f821414c6ae8b6bc",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Rings/Orders/Total/Examples.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Rings/Orders/Total/Examples.agda",
"max_line_length": 229,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Rings/Orders/Total/Examples.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": 613,
"size": 2043
} |
module Haskell.Prim.Eq where
open import Agda.Builtin.Nat as Nat hiding (_==_)
open import Agda.Builtin.Char
open import Agda.Builtin.Unit
open import Agda.Builtin.List
open import Haskell.Prim
open import Haskell.Prim.Bool
open import Haskell.Prim.Integer
open import Haskell.Prim.Int
open import Haskell.Prim.Word
open import Haskell.Prim.Double
open import Haskell.Prim.Tuple
open import Haskell.Prim.Maybe
open import Haskell.Prim.Either
--------------------------------------------------
-- Eq
record Eq (a : Set) : Set where
infix 4 _==_ _/=_
field
_==_ : a → a → Bool
_/=_ : a → a → Bool
x /= y = not (x == y)
open Eq ⦃ ... ⦄ public
{-# COMPILE AGDA2HS Eq existing-class #-}
instance
iEqNat : Eq Nat
iEqNat ._==_ = Nat._==_
iEqInteger : Eq Integer
iEqInteger ._==_ = eqInteger
iEqInt : Eq Int
iEqInt ._==_ = eqInt
iEqWord : Eq Word
iEqWord ._==_ = eqWord
iEqDouble : Eq Double
iEqDouble ._==_ = primFloatNumericalEquality
iEqBool : Eq Bool
iEqBool ._==_ false false = true
iEqBool ._==_ true true = true
iEqBool ._==_ _ _ = false
iEqChar : Eq Char
iEqChar ._==_ = primCharEquality
iEqUnit : Eq ⊤
iEqUnit ._==_ _ _ = true
iEqTuple₀ : Eq (Tuple [])
iEqTuple₀ ._==_ _ _ = true
iEqTuple : ∀ {as} → ⦃ Eq a ⦄ → ⦃ Eq (Tuple as) ⦄ → Eq (Tuple (a ∷ as))
iEqTuple ._==_ (x ∷ xs) (y ∷ ys) = x == y && xs == ys
iEqList : ⦃ Eq a ⦄ → Eq (List a)
iEqList ._==_ [] [] = true
iEqList ._==_ (x ∷ xs) (y ∷ ys) = x == y && xs == ys
iEqList ._==_ _ _ = false
iEqMaybe : ⦃ Eq a ⦄ → Eq (Maybe a)
iEqMaybe ._==_ Nothing Nothing = true
iEqMaybe ._==_ (Just x) (Just y) = x == y
iEqMaybe ._==_ _ _ = false
iEqEither : ⦃ Eq a ⦄ → ⦃ Eq b ⦄ → Eq (Either a b)
iEqEither ._==_ (Left x) (Left y) = x == y
iEqEither ._==_ (Right x) (Right y) = x == y
iEqEither ._==_ _ _ = false
| {
"alphanum_fraction": 0.5769230769,
"avg_line_length": 23.7530864198,
"ext": "agda",
"hexsha": "bbaabe892013a8a9a7d2039fc3d1630fb58d306f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "8c8f24a079ed9677dbe6893cf786e7ed52dfe8b6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dxts/agda2hs",
"max_forks_repo_path": "lib/Haskell/Prim/Eq.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8c8f24a079ed9677dbe6893cf786e7ed52dfe8b6",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dxts/agda2hs",
"max_issues_repo_path": "lib/Haskell/Prim/Eq.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "8c8f24a079ed9677dbe6893cf786e7ed52dfe8b6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dxts/agda2hs",
"max_stars_repo_path": "lib/Haskell/Prim/Eq.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 703,
"size": 1924
} |
-- 2017-05-11, Reported by Ulf
-- Implicit absurd matches should be treated in the same way as explicit ones
-- when it comes to being used/unused.
open import Agda.Builtin.Bool
open import Agda.Builtin.Equality
data ⊥ : Set where
record ⊤ : Set where
abort : (A : Set) {_ : ⊥} → A
abort A {}
test : (x y : ⊥) → abort Bool {x} ≡ abort Bool {y}
test x y = refl
| {
"alphanum_fraction": 0.6703296703,
"avg_line_length": 22.75,
"ext": "agda",
"hexsha": "85858559f1b3966e4818fee4dee864e76d886548",
"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/Issue2580.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/Issue2580.agda",
"max_line_length": 77,
"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/Issue2580.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": 116,
"size": 364
} |
module logical_foundations.Naturals where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎)
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
_+_ : ℕ → ℕ → ℕ
zero + n = n
suc m + n = suc (m + n)
{-# BUILTIN NATPLUS _+_ #-}
-- zero + n = n -- 0 + n = n
-- suc m + n = suc (m + n) -- (1 + m) + n = 1 + (m + n)
infixl 6 _+_
_ : 2 + 3 ≡ 5
_ =
begin
2 + 3
≡⟨⟩
(suc (suc zero)) + (suc (suc (suc zero)))
≡⟨⟩
suc ((suc zero) + (suc (suc (suc zero))))
≡⟨⟩
suc (suc (zero + (suc (suc (suc zero)))))
≡⟨⟩
5
∎
_ : 2 + 3 ≡ 5
_ =
begin
2 + 3
≡⟨⟩
suc (1 + 3)
≡⟨⟩
suc (suc (0 + 3))
≡⟨⟩
suc (suc 3)
≡⟨⟩
5
∎
_ : 2 + 3 ≡ 5
_ = refl
_ : 3 + 4 ≡ 7
_ =
begin
3 + 4
≡⟨⟩
suc (2 + 4)
≡⟨⟩
suc (suc (1 + 4))
≡⟨⟩
suc (suc (suc (0 + 4)))
≡⟨⟩
suc (suc (suc 4))
≡⟨⟩
7
∎
_*_ : ℕ → ℕ → ℕ
zero * n = zero -- 0 * n = 0
suc m * n = n + (m * n) -- (1 + m) * n = n + (m * n)
{-# BUILTIN NATTIMES _*_ #-}
infixl 7 _*_
_ : 2 * 3 ≡ 6
_ =
begin
2 * 3
≡⟨⟩
3 + (1 * 3)
≡⟨⟩
3 + (3 + (0 * 3))
≡⟨⟩
3 + (3 + 0)
≡⟨⟩
6
∎
_^_ : ℕ → ℕ → ℕ
m ^ zero = suc zero
m ^ suc n = m * (m ^ n)
infixl 8 _^_
_ : 2 ^ 3 ≡ 8
_ =
begin
2 ^ 3
≡⟨⟩
2 * (2 ^ 2)
≡⟨⟩
2 * (2 * (2 ^ 1))
≡⟨⟩
2 * (2 * (2 * (2 ^ 0)))
≡⟨⟩
2 * (2 * (2 * 1))
≡⟨⟩
8
∎
_ : 3 ^ 4 ≡ 81
_ = refl
_∸_ : ℕ → ℕ → ℕ
m ∸ zero = m
zero ∸ suc n = zero
suc m ∸ suc n = m ∸ n
{-# BUILTIN NATMINUS _∸_ #-}
infixl 6 _∸_
_ =
begin
3 ∸ 2
≡⟨⟩
2 ∸ 1
≡⟨⟩
1 ∸ 0
≡⟨⟩
1
∎
_ =
begin
2 ∸ 3
≡⟨⟩
1 ∸ 2
≡⟨⟩
0 ∸ 1
≡⟨⟩
0
∎
data Bin : Set where
nil : Bin
x0_ : Bin → Bin
x1_ : Bin → Bin
inc : Bin → Bin
inc nil = x1 nil
inc (x0 b) = x1 b
inc (x1 b) = x0 (inc b)
_ : inc (x1 x1 x0 x1 nil) ≡ x0 x0 x1 x1 nil
_ = refl
_ : inc (x1 x1 x1 x1 nil) ≡ x0 x0 x0 x0 x1 nil
_ = refl
to : ℕ → Bin
to zero = x0 nil
to (suc n) = inc (to n)
_ : to 0 ≡ x0 nil
_ = refl
_ : to 1 ≡ x1 nil
_ = refl
_ : to 2 ≡ x0 x1 nil
_ = refl
_ : to 3 ≡ x1 x1 nil
_ = refl
_ : to 14 ≡ x0 x1 x1 x1 nil
_ = refl
two = suc (suc zero)
from : Bin → ℕ
from nil = zero
from (x0 n) = two * (from n)
from (x1 n) = suc (two * (from n))
_ : from nil ≡ zero
_ = refl
_ : from (x0 nil) ≡ zero
_ = refl
_ : from (x1 nil) ≡ suc zero
_ = refl
_ : from (x0 x1 nil) ≡ two
_ = refl
_ : from (x0 x1 nil) ≡ two * suc zero
_ = refl
_ : from (x1 x1 nil) ≡ suc (suc (suc zero))
_ = refl
_ : from (x1 x1 nil) ≡ suc (two * suc zero)
_ = refl
_ : from (x0 x0 x1 nil) ≡ suc (suc (suc (suc zero)))
_ = refl
_ : from (x0 x0 x1 nil) ≡ two * (two * suc zero)
_ = refl
_ : from (x1 x0 x1 nil) ≡ suc (suc (suc (suc (suc zero))))
_ = refl
_ : from (x1 x0 x1 nil) ≡ suc (two * (two * suc zero))
_ = refl
| {
"alphanum_fraction": 0.4379738112,
"avg_line_length": 13.2511415525,
"ext": "agda",
"hexsha": "7e58c1777fef001a9a7907394a3d1a5454e8e260",
"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": "d6ca8fb32c4fe02c96f6e5eef82c2f24b7206e1b",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "tobal/plfa",
"max_forks_repo_path": "logical_foundations/Naturals.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d6ca8fb32c4fe02c96f6e5eef82c2f24b7206e1b",
"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": "tobal/plfa",
"max_issues_repo_path": "logical_foundations/Naturals.agda",
"max_line_length": 58,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "d6ca8fb32c4fe02c96f6e5eef82c2f24b7206e1b",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "tobal/plfa",
"max_stars_repo_path": "logical_foundations/Naturals.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1546,
"size": 2902
} |
open import HoTT
open import cohomology.FunctionOver
module cohomology.Exactness where
module _ {i j k} {G : Group i} {H : Group j} {K : Group k}
(φ : G →ᴳ H) (ψ : H →ᴳ K) where
private
module G = Group G
module H = Group H
module K = Group K
module φ = GroupHom φ
module ψ = GroupHom ψ
{- in image of φ ⇒ in kernel of ψ -}
is-exact-itok : Type (lmax k (lmax j i))
is-exact-itok = (h : H.El)
→ Trunc -1 (Σ G.El (λ g → φ.f g == h)) → ψ.f h == K.ident
{- in kernel of ψ ⇒ in image of φ -}
is-exact-ktoi : Type (lmax k (lmax j i))
is-exact-ktoi = (h : H.El)
→ ψ.f h == K.ident → Trunc -1 (Σ G.El (λ g → φ.f g == h))
record is-exact : Type (lmax k (lmax j i)) where
field
itok : is-exact-itok
ktoi : is-exact-ktoi
open is-exact public
{- an equivalent version of is-exact-ktoi -}
itok-alt-in : ((g : G.El) → ψ.f (φ.f g) == K.ident) → is-exact-itok
itok-alt-in r h = Trunc-rec (K.El-level _ _) (λ {(g , p) → ap ψ.f (! p) ∙ r g})
itok-alt-out : is-exact-itok → ((g : G.El) → ψ.f (φ.f g) == K.ident)
itok-alt-out s g = s (φ.f g) [ g , idp ]
{- Convenient notation for sequences of homomorphisms -}
infix 15 _⊣|
infixr 10 _⟨_⟩→_
data HomSequence {i} : Group i → Group i → Type (lsucc i) where
_⊣| : (G : Group i) → HomSequence G G
_⟨_⟩→_ : (G : Group i) {H K : Group i} (φ : G →ᴳ H)
→ HomSequence H K → HomSequence G K
data Sequence= {i} : {G₁ H₁ G₂ H₂ : Group i}
(S₁ : HomSequence G₁ H₁) (S₂ : HomSequence G₂ H₂)
→ G₁ == G₂ → H₁ == H₂ → Type (lsucc i) where
_∥⊣| : ∀ {G₁ G₂} (p : G₁ == G₂) → Sequence= (G₁ ⊣|) (G₂ ⊣|) p p
_∥⟨_⟩∥_ : ∀ {G₁ G₂} (pG : G₁ == G₂)
{H₁ K₁ H₂ K₂ : Group i} {φ₁ : G₁ →ᴳ H₁} {φ₂ : G₂ →ᴳ H₂}
{S₁ : HomSequence H₁ K₁} {S₂ : HomSequence H₂ K₂}
{pH : H₁ == H₂} {pK : K₁ == K₂}
(over : φ₁ == φ₂ [ uncurry _→ᴳ_ ↓ pair×= pG pH ])
→ Sequence= S₁ S₂ pH pK
→ Sequence= (G₁ ⟨ φ₁ ⟩→ S₁) (G₂ ⟨ φ₂ ⟩→ S₂) pG pK
infix 15 _↓⊣| _∥⊣|
infixr 10 _↓⟨_⟩↓_ _∥⟨_⟩∥_
data SequenceIso {i j} : {G₁ H₁ : Group i} {G₂ H₂ : Group j}
(S₁ : HomSequence G₁ H₁) (S₂ : HomSequence G₂ H₂)
→ G₁ ≃ᴳ G₂ → H₁ ≃ᴳ H₂ → Type (lsucc (lmax i j)) where
_↓⊣| : ∀ {G₁ G₂} (iso : G₁ ≃ᴳ G₂) → SequenceIso (G₁ ⊣|) (G₂ ⊣|) iso iso
_↓⟨_⟩↓_ : ∀ {G₁ G₂} (isoG : G₁ ≃ᴳ G₂)
{H₁ K₁ : Group i} {H₂ K₂ : Group j} {φ₁ : G₁ →ᴳ H₁} {φ₂ : G₂ →ᴳ H₂}
{S₁ : HomSequence H₁ K₁} {S₂ : HomSequence H₂ K₂}
{isoH : H₁ ≃ᴳ H₂} {isoK : K₁ ≃ᴳ K₂}
(over : fst isoH ∘ᴳ φ₁ == φ₂ ∘ᴳ fst isoG)
→ SequenceIso S₁ S₂ isoH isoK
→ SequenceIso (G₁ ⟨ φ₁ ⟩→ S₁) (G₂ ⟨ φ₂ ⟩→ S₂) isoG isoK
seq-iso-to-path : ∀ {i} {G₁ H₁ G₂ H₂ : Group i}
{S₁ : HomSequence G₁ H₁} {S₂ : HomSequence G₂ H₂}
{isoG : G₁ ≃ᴳ G₂} {isoH : H₁ ≃ᴳ H₂}
→ SequenceIso S₁ S₂ isoG isoH
→ Sequence= S₁ S₂ (group-ua isoG) (group-ua isoH)
seq-iso-to-path (iso ↓⊣|) = group-ua iso ∥⊣|
seq-iso-to-path (iso ↓⟨ over ⟩↓ si') =
group-ua iso
∥⟨ hom-over-isos $ function-over-equivs _ _ $ ap GroupHom.f over ⟩∥
seq-iso-to-path si'
sequence= : ∀ {i} {G₁ H₁ G₂ H₂ : Group i}
{S₁ : HomSequence G₁ H₁} {S₂ : HomSequence G₂ H₂}
(pG : G₁ == G₂) (pH : H₁ == H₂) → Sequence= S₁ S₂ pG pH
→ S₁ == S₂ [ uncurry HomSequence ↓ pair×= pG pH ]
sequence= idp .idp (.idp ∥⊣|) = idp
sequence= {G₁ = G₁} idp idp
(_∥⟨_⟩∥_ .idp {φ₁ = φ₁} {pH = idp} idp sp') =
ap (λ S' → G₁ ⟨ φ₁ ⟩→ S') (sequence= idp idp sp')
sequence-iso-ua : ∀ {i} {G₁ H₁ G₂ H₂ : Group i}
{S₁ : HomSequence G₁ H₁} {S₂ : HomSequence G₂ H₂}
(isoG : G₁ ≃ᴳ G₂) (isoH : H₁ ≃ᴳ H₂) → SequenceIso S₁ S₂ isoG isoH
→ S₁ == S₂ [ uncurry HomSequence ↓ pair×= (group-ua isoG) (group-ua isoH) ]
sequence-iso-ua isoG isoH si = sequence= _ _ (seq-iso-to-path si)
data is-exact-seq {i} : {G H : Group i} → HomSequence G H → Type (lsucc i) where
exact-seq-zero : {G : Group i} → is-exact-seq (G ⊣|)
exact-seq-one : {G H : Group i} {φ : G →ᴳ H} → is-exact-seq (G ⟨ φ ⟩→ H ⊣|)
exact-seq-two : {G H K J : Group i} {φ : G →ᴳ H} {ψ : H →ᴳ K}
{diag : HomSequence K J} → is-exact φ ψ
→ is-exact-seq (H ⟨ ψ ⟩→ diag) → is-exact-seq (G ⟨ φ ⟩→ H ⟨ ψ ⟩→ diag)
private
exact-get-type : ∀ {i} {G H : Group i} → HomSequence G H → ℕ → Type i
exact-get-type (G ⊣|) _ = Lift Unit
exact-get-type (G ⟨ φ ⟩→ H ⊣|) _ = Lift Unit
exact-get-type (G ⟨ φ ⟩→ (H ⟨ ψ ⟩→ s)) O = is-exact φ ψ
exact-get-type (_ ⟨ _ ⟩→ s) (S n) = exact-get-type s n
exact-get : ∀ {i} {G H : Group i} {diag : HomSequence G H}
→ is-exact-seq diag → (n : ℕ) → exact-get-type diag n
exact-get exact-seq-zero _ = lift unit
exact-get exact-seq-one _ = lift unit
exact-get (exact-seq-two ex s) O = ex
exact-get (exact-seq-two ex s) (S n) = exact-get s n
private
exact-build-arg-type : ∀ {i} {G H : Group i} → HomSequence G H → List (Type i)
exact-build-arg-type (G ⊣|) = nil
exact-build-arg-type (G ⟨ φ ⟩→ H ⊣|) = nil
exact-build-arg-type (G ⟨ φ ⟩→ H ⟨ ψ ⟩→ s) =
is-exact φ ψ :: exact-build-arg-type (H ⟨ ψ ⟩→ s)
exact-build-helper : ∀ {i} {G H : Group i} (seq : HomSequence G H)
→ HList (exact-build-arg-type seq) → is-exact-seq seq
exact-build-helper (G ⊣|) nil = exact-seq-zero
exact-build-helper (G ⟨ φ ⟩→ H ⊣|) nil = exact-seq-one
exact-build-helper (G ⟨ φ ⟩→ H ⟨ ψ ⟩→ s) (ie :: ies) =
exact-seq-two ie (exact-build-helper (H ⟨ ψ ⟩→ s) ies)
exact-build : ∀ {i} {G H : Group i} (seq : HomSequence G H)
→ hlist-curry-type (exact-build-arg-type seq) (λ _ → is-exact-seq seq)
exact-build seq = hlist-curry (exact-build-helper seq)
private
hom-seq-snoc : ∀ {i} {G H K : Group i}
→ HomSequence G H → (H →ᴳ K) → HomSequence G K
hom-seq-snoc (G ⊣|) ψ = G ⟨ ψ ⟩→ _ ⊣|
hom-seq-snoc (G ⟨ φ ⟩→ s) ψ = G ⟨ φ ⟩→ hom-seq-snoc s ψ
hom-seq-concat : ∀ {i} {G H K : Group i}
→ HomSequence G H → HomSequence H K → HomSequence G K
hom-seq-concat (G ⊣|) s₂ = s₂
hom-seq-concat (G ⟨ φ ⟩→ s₁) s₂ = G ⟨ φ ⟩→ (hom-seq-concat s₁ s₂)
abstract
exact-concat : ∀ {i} {G H K L : Group i}
{seq₁ : HomSequence G H} {φ : H →ᴳ K} {seq₂ : HomSequence K L}
→ is-exact-seq (hom-seq-snoc seq₁ φ) → is-exact-seq (H ⟨ φ ⟩→ seq₂)
→ is-exact-seq (hom-seq-concat seq₁ (H ⟨ φ ⟩→ seq₂))
exact-concat {seq₁ = G ⊣|} exact-seq-one es₂ = es₂
exact-concat {seq₁ = G ⟨ ψ ⟩→ H ⊣|} (exact-seq-two ex _) es₂ =
exact-seq-two ex es₂
exact-concat {seq₁ = G ⟨ ψ ⟩→ H ⟨ χ ⟩→ s} (exact-seq-two ex es₁) es₂ =
exact-seq-two ex (exact-concat {seq₁ = H ⟨ χ ⟩→ s} es₁ es₂)
| {
"alphanum_fraction": 0.5604826073,
"avg_line_length": 39.1533742331,
"ext": "agda",
"hexsha": "72ebf4f3f2dc667755a6101f13fd52dbc93b793c",
"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": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cmknapp/HoTT-Agda",
"max_forks_repo_path": "theorems/cohomology/Exactness.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"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": "cmknapp/HoTT-Agda",
"max_issues_repo_path": "theorems/cohomology/Exactness.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cmknapp/HoTT-Agda",
"max_stars_repo_path": "theorems/cohomology/Exactness.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2885,
"size": 6382
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.CommRing.Integers where
open import Cubical.Foundations.Prelude
open import Cubical.Algebra.CommRing
module _ where
open import Cubical.HITs.Ints.BiInvInt
renaming (
_+_ to _+ℤ_;
-_ to _-ℤ_;
+-assoc to +ℤ-assoc;
+-comm to +ℤ-comm
)
BiInvIntAsCommRing : CommRing {ℓ-zero}
BiInvIntAsCommRing =
makeCommRing
zero (suc zero) _+ℤ_ _·_ _-ℤ_
isSetBiInvInt
+ℤ-assoc +-zero +-invʳ +ℤ-comm
·-assoc ·-identityʳ
(λ x y z → sym (·-distribˡ x y z))
·-comm
-- makeCommRing ? ? ? ? ? ? ? ? ? ? ? ? ? ?
module _ where
open import Cubical.Data.Int
IntAsCommRing : CommRing {ℓ-zero}
IntAsCommRing = makeCommRing {R = Int} 0 1 _+_ _·_ -_ isSetInt
+-assoc +-identityʳ +-inverseʳ +-comm (λ x y z → sym (·-assoc x y z)) ·-identityʳ
(λ x y z → sym (·-distribˡ x y z)) ·-comm
module _ where
open import Cubical.HITs.Ints.QuoInt
QuoIntAsCommRing : CommRing {ℓ-zero}
QuoIntAsCommRing = makeCommRing {R = ℤ} 0 1 _+_ _·_ -_ isSetℤ
+-assoc +-identityʳ +-inverseʳ +-comm ·-assoc ·-identityʳ
(λ x y z → sym (·-distribˡ x y z)) ·-comm
module _ where
open import Cubical.Data.DiffInt
DiffIntAsCommRing : CommRing {ℓ-zero}
DiffIntAsCommRing = makeCommRing {R = ℤ} 0 1 _+_ _·_ -_ isSetℤ
+-assoc +-identityʳ +-inverseʳ +-comm ·-assoc ·-identityʳ ·-distribˡ ·-comm
open import Cubical.Algebra.Ring using (ringequiv)
open import Cubical.Foundations.Equiv
open import Cubical.Reflection.Base using (_$_) -- TODO: add this to Foundation.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Structure
open import Cubical.HITs.Ints.BiInvInt using (BiInvInt)
open import Cubical.Data.Nat using (suc; zero) renaming (_·_ to _·ⁿ_; _+_ to _+ⁿ_)
open import Cubical.Data.Int as Int using (sucInt; predInt; Int) renaming
( _+_ to _+'_
; _·_ to _·'_
; -_ to -'_
; pos to pos'
; negsuc to negsuc'
; sgn to sgn'
; abs to abs'
; signed to signed'
)
module _ where
open import Cubical.HITs.Ints.BiInvInt renaming
( fwd to ⟦_⟧
; suc to sucᵇ
)
private
suc-⟦⟧ : ∀ x → sucᵇ ⟦ x ⟧ ≡ ⟦ sucInt x ⟧
suc-⟦⟧ (pos' n) = refl
suc-⟦⟧ (negsuc' zero) = suc-pred _
suc-⟦⟧ (negsuc' (suc n)) = suc-pred _
pred-⟦⟧ : ∀ x → predl ⟦ x ⟧ ≡ ⟦ predInt x ⟧
pred-⟦⟧ (pos' zero) = refl
pred-⟦⟧ (pos' (suc n)) = pred-suc _
pred-⟦⟧ (negsuc' zero) = refl
pred-⟦⟧ (negsuc' (suc n)) = refl
neg-⟦⟧ : ∀ x → - ⟦ x ⟧ ≡ ⟦ -' x ⟧
neg-⟦⟧ (pos' zero) = refl
neg-⟦⟧ (pos' (suc n)) = (λ i → predl (neg-⟦⟧ (pos' n) i)) ∙ pred-⟦⟧ (-' pos' n) ∙ cong ⟦_⟧ (Int.predInt-neg (pos' n))
neg-⟦⟧ (negsuc' zero) = refl
neg-⟦⟧ (negsuc' (suc n)) = (λ i → sucᵇ (neg-⟦⟧ (negsuc' n) i))
pres1 : 1 ≡ ⟦ 1 ⟧
pres1 = refl
isHom+ : ∀ x y → ⟦ x +' y ⟧ ≡ ⟦ x ⟧ + ⟦ y ⟧
isHom+ (pos' zero) y i = ⟦ Int.+-comm 0 y i ⟧
isHom+ (pos' (suc n)) y =
⟦ pos' (suc n) +' y ⟧ ≡[ i ]⟨ ⟦ Int.sucInt+ (pos' n) y (~ i) ⟧ ⟩
⟦ sucInt (pos' n +' y) ⟧ ≡⟨ sym $ suc-⟦⟧ _ ⟩
sucᵇ ⟦ pos' n +' y ⟧ ≡[ i ]⟨ sucᵇ $ isHom+ (pos' n) y i ⟩
sucᵇ (⟦ pos' n ⟧ + ⟦ y ⟧) ≡⟨ refl ⟩
sucᵇ ⟦ pos' n ⟧ + ⟦ y ⟧ ∎
isHom+ (negsuc' zero) y = pred-suc-inj _ _ (λ i → predl (γ i)) where
-- γ = sucᵇ ⟦ negsuc' zero +' y ⟧ ≡⟨ suc-⟦⟧ (negsuc' zero +' y) ⟩
-- ⟦ sucInt (negsuc' zero +' y)⟧ ≡⟨ cong ⟦_⟧ $ Int.sucInt+ (negsuc' zero) y ∙ Int.+-comm 0 y ⟩
-- ⟦ y ⟧ ≡⟨ sym (suc-pred ⟦ y ⟧) ⟩
-- sucᵇ (pred zero + ⟦ y ⟧) ∎
γ = suc-⟦⟧ (negsuc' zero +' y) ∙ (λ i → ⟦ (Int.sucInt+ (negsuc' zero) y ∙ Int.+-comm 0 y) i ⟧) ∙ sym (suc-pred ⟦ y ⟧)
isHom+ (negsuc' (suc n)) y = (λ i → ⟦ Int.predInt+ (negsuc' n) y (~ i) ⟧) ∙ sym (pred-⟦⟧ (negsuc' n +' y))
∙ (λ i → pred $ isHom+ (negsuc' n) y i)
isHom· : ∀ x y → ⟦ x ·' y ⟧ ≡ ⟦ x ⟧ · ⟦ y ⟧
isHom· (pos' zero) y i = ⟦ Int.signed-zero (Int.sgn y) i ⟧
isHom· (pos' (suc n)) y =
⟦ pos' (suc n) ·' y ⟧ ≡⟨ cong ⟦_⟧ $ Int.·-pos-suc n y ⟩
⟦ y +' pos' n ·' y ⟧ ≡⟨ isHom+ y _ ⟩
⟦ y ⟧ + ⟦ pos' n ·' y ⟧ ≡[ i ]⟨ ⟦ y ⟧ + isHom· (pos' n) y i ⟩
⟦ y ⟧ + ⟦ pos' n ⟧ · ⟦ y ⟧ ≡⟨ (λ i → ⟦ y ⟧ + ·-comm ⟦ pos' n ⟧ ⟦ y ⟧ i)
∙ sym (·-suc ⟦ y ⟧ ⟦ pos' n ⟧) ∙ ·-comm ⟦ y ⟧ _ ⟩
sucᵇ ⟦ pos' n ⟧ · ⟦ y ⟧ ∎
isHom· (negsuc' zero) y =
⟦ -1 ·' y ⟧ ≡⟨ cong ⟦_⟧ (Int.·-neg1 y) ⟩
⟦ -' y ⟧ ≡⟨ sym (neg-⟦⟧ y) ⟩
- ⟦ y ⟧ ≡⟨ sym (·-neg1 ⟦ y ⟧) ⟩
-1 · ⟦ y ⟧ ∎
isHom· (negsuc' (suc n)) y =
⟦ negsuc' (suc n) ·' y ⟧ ≡⟨ cong ⟦_⟧ $ Int.·-negsuc-suc n y ⟩
⟦ -' y +' negsuc' n ·' y ⟧ ≡⟨ isHom+ (-' y) _ ⟩
⟦ -' y ⟧ + ⟦ negsuc' n ·' y ⟧ ≡[ i ]⟨ ⟦ -' y ⟧ + isHom· (negsuc' n) y i ⟩
⟦ -' y ⟧ + ⟦ negsuc' n ⟧ · ⟦ y ⟧ ≡⟨ cong₂ _+_ (sym (neg-⟦⟧ y)) refl ⟩
- ⟦ y ⟧ + ⟦ negsuc' n ⟧ · ⟦ y ⟧ ≡⟨ (λ i → - ⟦ y ⟧ + ·-comm ⟦ negsuc' n ⟧ ⟦ y ⟧ i)
∙ sym (·-pred ⟦ y ⟧ ⟦ negsuc' n ⟧) ∙ ·-comm ⟦ y ⟧ _ ⟩
pred ⟦ negsuc' n ⟧ · ⟦ y ⟧ ∎
⟦⟧-isEquiv : isEquiv ⟦_⟧
⟦⟧-isEquiv = isoToIsEquiv (iso ⟦_⟧ bwd fwd-bwd bwd-fwd)
Int≃BiInvInt-CommRingEquivΣ : Σ[ e ∈ ⟨ IntAsCommRing ⟩ ≃ ⟨ BiInvIntAsCommRing ⟩ ] CommRingEquiv IntAsCommRing BiInvIntAsCommRing e
Int≃BiInvInt-CommRingEquivΣ .fst = ⟦_⟧ , ⟦⟧-isEquiv
Int≃BiInvInt-CommRingEquivΣ .snd = ringequiv pres1 isHom+ isHom·
Int≡BiInvInt-AsCommRing : IntAsCommRing ≡ BiInvIntAsCommRing
Int≡BiInvInt-AsCommRing = CommRingPath _ _ .fst Int≃BiInvInt-CommRingEquivΣ
module _ where
open import Cubical.HITs.Ints.QuoInt as QuoInt renaming
( Int→ℤ to ⟦_⟧
)
open import Cubical.Data.Bool
private
suc-⟦⟧ : ∀ x → sucℤ ⟦ x ⟧ ≡ ⟦ sucInt x ⟧
suc-⟦⟧ (pos' n) = refl
suc-⟦⟧ (negsuc' zero) = sym posneg
suc-⟦⟧ (negsuc' (suc n)) = refl
pred-⟦⟧ : ∀ x → predℤ ⟦ x ⟧ ≡ ⟦ predInt x ⟧
pred-⟦⟧ (pos' zero) = refl
pred-⟦⟧ (pos' (suc n)) = refl
pred-⟦⟧ (negsuc' n) = refl
neg-⟦⟧ : ∀ x → - ⟦ x ⟧ ≡ ⟦ -' x ⟧
neg-⟦⟧ (pos' zero) = sym posneg
neg-⟦⟧ (pos' (suc n)) = refl
neg-⟦⟧ (negsuc' n) = refl
pres1 : 1 ≡ ⟦ 1 ⟧
pres1 = refl
isHom+ : ∀ x y → ⟦ x +' y ⟧ ≡ ⟦ x ⟧ + ⟦ y ⟧
isHom+ (pos' zero) y i = ⟦ Int.+-comm 0 y i ⟧
isHom+ (pos' (suc n)) y =
⟦ pos' (suc n) +' y ⟧ ≡[ i ]⟨ ⟦ Int.sucInt+ (pos' n) y (~ i) ⟧ ⟩
⟦ sucInt (pos' n +' y) ⟧ ≡⟨ sym $ suc-⟦⟧ _ ⟩
sucℤ ⟦ pos' n +' y ⟧ ≡[ i ]⟨ sucℤ $ isHom+ (pos' n) y i ⟩
sucℤ (⟦ pos' n ⟧ + ⟦ y ⟧) ≡⟨ refl ⟩
sucℤ ⟦ pos' n ⟧ + ⟦ y ⟧ ∎
isHom+ (negsuc' zero ) y = sucℤ-inj _ _ (suc-⟦⟧ (negsuc' zero +' y)
∙ (cong ⟦_⟧ $ Int.sucInt+ (negsuc' zero) y
∙ Int.+-identityˡ y)
∙ sym (sucPredℤ ⟦ y ⟧))
isHom+ (negsuc' (suc n)) y = cong ⟦_⟧ (sym (Int.predInt+ (negsuc' n) y))
∙ (sym $ pred-⟦⟧ (negsuc' n +' y))
∙ (λ i → predℤ $ isHom+ (negsuc' n) y i)
isHom· : ∀ x y → ⟦ x ·' y ⟧ ≡ ⟦ x ⟧ · ⟦ y ⟧
isHom· (pos' zero) y = (cong ⟦_⟧ $ Int.signed-zero (sgn' y)) ∙ sym (signed-zero (sign ⟦ y ⟧) spos)
isHom· (pos' (suc n)) y =
⟦ pos' (suc n) ·' y ⟧ ≡⟨ cong ⟦_⟧ $ Int.·-pos-suc n y ⟩
⟦ y +' pos' n ·' y ⟧ ≡⟨ isHom+ y _ ⟩
⟦ y ⟧ + ⟦ pos' n ·' y ⟧ ≡[ i ]⟨ ⟦ y ⟧ + isHom· (pos' n) y i ⟩
⟦ y ⟧ + ⟦ pos' n ⟧ · ⟦ y ⟧ ≡⟨ sym $ ·-pos-suc n ⟦ y ⟧ ⟩
sucℤ ⟦ pos' n ⟧ · ⟦ y ⟧ ∎
isHom· (negsuc' zero) y =
⟦ -1 ·' y ⟧ ≡⟨ cong ⟦_⟧ (Int.·-neg1 y) ⟩
⟦ -' y ⟧ ≡⟨ sym (neg-⟦⟧ y) ⟩
- ⟦ y ⟧ ≡⟨ sym (·-neg1 ⟦ y ⟧) ⟩
-1 · ⟦ y ⟧ ∎
isHom· (negsuc' (suc n)) y =
⟦ negsuc' (suc n) ·' y ⟧ ≡⟨ cong ⟦_⟧ $ Int.·-negsuc-suc n y ⟩
⟦ -' y +' negsuc' n ·' y ⟧ ≡⟨ isHom+ (-' y) _ ⟩
⟦ -' y ⟧ + ⟦ negsuc' n ·' y ⟧ ≡[ i ]⟨ ⟦ -' y ⟧ + isHom· (negsuc' n) y i ⟩
⟦ -' y ⟧ + ⟦ negsuc' n ⟧ · ⟦ y ⟧ ≡⟨ cong₂ _+_ (sym (neg-⟦⟧ y)) refl ⟩
- ⟦ y ⟧ + ⟦ negsuc' n ⟧ · ⟦ y ⟧ ≡⟨ sym (·-neg-suc (suc n) ⟦ y ⟧) ⟩
predℤ ⟦ negsuc' n ⟧ · ⟦ y ⟧ ∎
⟦⟧-isEquiv : isEquiv ⟦_⟧
⟦⟧-isEquiv = isoToIsEquiv (iso ⟦_⟧ ℤ→Int ℤ→Int→ℤ Int→ℤ→Int)
Int≃QuoInt-CommRingEquivΣ : Σ[ e ∈ ⟨ IntAsCommRing ⟩ ≃ ⟨ QuoIntAsCommRing ⟩ ] CommRingEquiv IntAsCommRing QuoIntAsCommRing e
Int≃QuoInt-CommRingEquivΣ .fst = ⟦_⟧ , ⟦⟧-isEquiv
Int≃QuoInt-CommRingEquivΣ .snd = ringequiv pres1 isHom+ isHom·
Int≡QuoInt-AsCommRing : IntAsCommRing ≡ QuoIntAsCommRing
Int≡QuoInt-AsCommRing = CommRingPath _ _ .fst Int≃QuoInt-CommRingEquivΣ
QuoInt≡BiInvInt-AsCommRing : QuoIntAsCommRing ≡ BiInvIntAsCommRing
QuoInt≡BiInvInt-AsCommRing = sym Int≡QuoInt-AsCommRing ∙ Int≡BiInvInt-AsCommRing
open import Cubical.HITs.SetQuotients
module _ where
open import Cubical.Data.Sigma
open import Cubical.Data.Bool
open import Cubical.Data.Nat using (ℕ) renaming (_·_ to _·ⁿ_)
open import Cubical.HITs.Rationals.QuoQ using (ℚ) renaming (_+_ to _+ʳ_)
open import Cubical.HITs.Ints.QuoInt using (ℤ; sign; signed; abs) renaming (_+_ to _+ᶻ_)
open import Cubical.Data.NatPlusOne using (ℕ₊₁; 1+_)
test1 : ℤ → _
test1 x = {! x +ᶻ x !}
-- Normal form:
-- x +ᶻ x
test2 : ℤ × ℕ₊₁ → _
test2 x = {! [ x ] +ʳ [ x ] !}
-- Normal form:
-- [ signed (sign (fst x) ⊕ false) (abs (fst x) ·ⁿ suc (ℕ₊₁.n (snd x)))
-- +ᶻ signed (sign (fst x) ⊕ false) (abs (fst x) ·ⁿ suc (ℕ₊₁.n (snd x)))
-- , (1+ (ℕ₊₁.n (snd x) +ⁿ ℕ₊₁.n (snd x) ·ⁿ suc (ℕ₊₁.n (snd x))))
-- ]
test3 : ℚ → ℤ × ℕ₊₁ → _
test3 x y = {! x +ʳ [ y ] !}
-- Normal form:
-- rec
-- (λ f g F G i j z →
-- squash/ (f z) (g z) (λ i₁ → F i₁ z) (λ i₁ → G i₁ z) i j)
-- (λ a → ...
-- ...
-- ... 2000 more lines ...
open import Cubical.Data.DiffInt as DiffInt hiding (_+'_; _·'_)
⟦⟧-isEquiv : isEquiv ⟦_⟧
⟦⟧-isEquiv = isoToIsEquiv (iso ⟦_⟧ bwd fwd-bwd bwd-fwd)
pres1 : 1 ≡ ⟦ 1 ⟧
pres1 = refl
isHom+ : ∀ x y → ⟦ x +' y ⟧ ≡ ⟦ x ⟧ + ⟦ y ⟧
isHom+ (pos' zero) y = {! !}
isHom+ (pos' (suc n)) y = {! !} -- ? ∙ λ i → sucℤ (isHom+ (pos' n) y i)
isHom+ (negsuc' zero) y = {! [ 0 , 1 ] + ⟦ y ⟧ !}
isHom+ (negsuc' (suc n)) y = {! !}
isHom· : ∀ x y → ⟦ x ·' y ⟧ ≡ ⟦ x ⟧ · ⟦ y ⟧
isHom· = {! !}
Int≃DiffInt-CommRingEquivΣ : Σ[ e ∈ ⟨ IntAsCommRing ⟩ ≃ ⟨ DiffIntAsCommRing ⟩ ] CommRingEquiv IntAsCommRing DiffIntAsCommRing e
Int≃DiffInt-CommRingEquivΣ .fst = ⟦_⟧ , ⟦⟧-isEquiv
Int≃DiffInt-CommRingEquivΣ .snd = ringequiv pres1 isHom+ isHom·
Int≡DiffInt-AsCommRing : IntAsCommRing ≡ DiffIntAsCommRing
Int≡DiffInt-AsCommRing = CommRingPath _ _ .fst Int≃DiffInt-CommRingEquivΣ
DiffInt≡BiInvInt-AsCommRing : DiffIntAsCommRing ≡ BiInvIntAsCommRing
DiffInt≡BiInvInt-AsCommRing = sym Int≡DiffInt-AsCommRing ∙ Int≡BiInvInt-AsCommRing
| {
"alphanum_fraction": 0.5069482538,
"avg_line_length": 38.6501766784,
"ext": "agda",
"hexsha": "27199ca54561cff38b2a09dd8b8d3b1b64fbcc62",
"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": "cc6ad25d5ffbe4f20ea7020474f266d24b97caa0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mchristianl/cubical",
"max_forks_repo_path": "Cubical/Algebra/CommRing/Integers.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "cc6ad25d5ffbe4f20ea7020474f266d24b97caa0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mchristianl/cubical",
"max_issues_repo_path": "Cubical/Algebra/CommRing/Integers.agda",
"max_line_length": 132,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "cc6ad25d5ffbe4f20ea7020474f266d24b97caa0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mchristianl/cubical",
"max_stars_repo_path": "Cubical/Algebra/CommRing/Integers.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5260,
"size": 10938
} |
-- Andreas, 2018-10-18, issue #3289 reported by Ulf
--
-- For postfix projections, we have no hiding info
-- for the eliminated record value.
-- Thus, contrary to the prefix case, it cannot be
-- taken into account (e.g. for projection disambiguation).
open import Agda.Builtin.Nat
record R : Set where
field
p : Nat
open R {{...}}
test : R
test .p = 0
-- Error WAS: Wrong hiding used for projection R.p
-- Should work now.
| {
"alphanum_fraction": 0.6833712984,
"avg_line_length": 19.0869565217,
"ext": "agda",
"hexsha": "c3c65fdd9d97dbcefc4baebd07a219b5c5652739",
"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": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue3289.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/Issue3289.agda",
"max_line_length": 59,
"max_stars_count": 2,
"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/Issue3289.agda",
"max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z",
"num_tokens": 125,
"size": 439
} |
-- Test that postponing tactic applications work properly
module _ where
open import Common.Prelude
open import Common.Reflection
data Zero : Set where
zero : Zero
macro
fill : Term → Tactic
fill = give
_asTypeOf_ : {A : Set} → A → A → A
x asTypeOf _ = x
-- Requires postponing the macro evaluation until the 'zero' has been
-- disambiguated.
foo : Nat
foo = let z = zero in
fill z asTypeOf z
| {
"alphanum_fraction": 0.703163017,
"avg_line_length": 17.8695652174,
"ext": "agda",
"hexsha": "00f987e9e6b38f076e42b9491bbdbf91a630afda",
"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/PostponeTactic.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/PostponeTactic.agda",
"max_line_length": 69,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/PostponeTactic.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": 117,
"size": 411
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Surjections
------------------------------------------------------------------------
module Function.Surjection where
open import Level
open import Function.Equality as F
using (_⟶_) renaming (_∘_ to _⟪∘⟫_)
open import Function.Equivalence using (Equivalence)
open import Function.Injection hiding (id; _∘_)
open import Function.LeftInverse as Left hiding (id; _∘_)
open import Data.Product
open import Relation.Binary
import Relation.Binary.PropositionalEquality as P
-- Surjective functions.
record Surjective {f₁ f₂ t₁ t₂}
{From : Setoid f₁ f₂} {To : Setoid t₁ t₂}
(to : From ⟶ To) :
Set (f₁ ⊔ f₂ ⊔ t₁ ⊔ t₂) where
field
from : To ⟶ From
right-inverse-of : from RightInverseOf to
-- The set of all surjections from one setoid to another.
record Surjection {f₁ f₂ t₁ t₂}
(From : Setoid f₁ f₂) (To : Setoid t₁ t₂) :
Set (f₁ ⊔ f₂ ⊔ t₁ ⊔ t₂) where
field
to : From ⟶ To
surjective : Surjective to
open Surjective surjective public
right-inverse : RightInverse From To
right-inverse = record
{ to = from
; from = to
; left-inverse-of = right-inverse-of
}
open LeftInverse right-inverse public
using () renaming (to-from to from-to)
injective : Injective from
injective = LeftInverse.injective right-inverse
injection : Injection To From
injection = LeftInverse.injection right-inverse
equivalence : Equivalence From To
equivalence = record
{ to = to
; from = from
}
-- Right inverses can be turned into surjections.
fromRightInverse :
∀ {f₁ f₂ t₁ t₂} {From : Setoid f₁ f₂} {To : Setoid t₁ t₂} →
RightInverse From To → Surjection From To
fromRightInverse r = record
{ to = from
; surjective = record
{ from = to
; right-inverse-of = left-inverse-of
}
} where open LeftInverse r
-- The set of all surjections from one set to another.
infix 3 _↠_
_↠_ : ∀ {f t} → Set f → Set t → Set _
From ↠ To = Surjection (P.setoid From) (P.setoid To)
-- Identity and composition.
id : ∀ {s₁ s₂} {S : Setoid s₁ s₂} → Surjection S S
id {S = S} = record
{ to = F.id
; surjective = record
{ from = LeftInverse.to id′
; right-inverse-of = LeftInverse.left-inverse-of id′
}
} where id′ = Left.id {S = S}
infixr 9 _∘_
_∘_ : ∀ {f₁ f₂ m₁ m₂ t₁ t₂}
{F : Setoid f₁ f₂} {M : Setoid m₁ m₂} {T : Setoid t₁ t₂} →
Surjection M T → Surjection F M → Surjection F T
f ∘ g = record
{ to = to f ⟪∘⟫ to g
; surjective = record
{ from = LeftInverse.to g∘f
; right-inverse-of = LeftInverse.left-inverse-of g∘f
}
}
where
open Surjection
g∘f = Left._∘_ (right-inverse g) (right-inverse f)
| {
"alphanum_fraction": 0.5774695535,
"avg_line_length": 27.3703703704,
"ext": "agda",
"hexsha": "a8889a2df74fe2dc6938342f1eeb690bb06dc60a",
"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/Function/Surjection.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/Function/Surjection.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/Function/Surjection.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": 861,
"size": 2956
} |
{-# OPTIONS --no-import-sorts --prop #-}
open import Agda.Primitive renaming (Set to Set; Prop to Set₁)
test : Set₁
test = Set
| {
"alphanum_fraction": 0.6821705426,
"avg_line_length": 18.4285714286,
"ext": "agda",
"hexsha": "957c4ad3e657b3a84719fee29cad85436e2f2f9f",
"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/AmbiguousSet1.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/AmbiguousSet1.agda",
"max_line_length": 62,
"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/AmbiguousSet1.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": 36,
"size": 129
} |
{-
Index a structure T a positive structure S: X ↦ S X → T X
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Structures.Relational.Function where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Structure
open import Cubical.Foundations.RelationalStructure
open import Cubical.Foundations.Univalence
open import Cubical.Functions.FunExtEquiv
open import Cubical.Data.Sigma
open import Cubical.Relation.Binary.Base
open import Cubical.Relation.ZigZag.Base
open import Cubical.HITs.SetQuotients
open import Cubical.HITs.PropositionalTruncation as Trunc
open import Cubical.Structures.Function
private
variable
ℓ ℓ₁ ℓ₁' ℓ₁'' ℓ₂ ℓ₂' ℓ₂'' : Level
FunctionRelStr : {S : Type ℓ → Type ℓ₁} {T : Type ℓ → Type ℓ₂}
→ StrRel S ℓ₁' → StrRel T ℓ₂' → StrRel (FunctionStructure S T) (ℓ-max ℓ₁ (ℓ-max ℓ₁' ℓ₂'))
FunctionRelStr ρ₁ ρ₂ R f g =
∀ {x y} → ρ₁ R x y → ρ₂ R (f x) (g y)
open isEquivRel
private
composeWith[_] : {A : Type ℓ} (R : EquivPropRel A ℓ)
→ compPropRel (R .fst) (quotientPropRel (R .fst .fst)) .fst ≡ graphRel [_]
composeWith[_] R =
funExt₂ λ a t →
hPropExt squash (squash/ _ _)
(Trunc.rec (squash/ _ _) (λ {(b , r , p) → eq/ a b r ∙ p }))
(λ p → ∣ a , R .snd .reflexive a , p ∣)
[_]∙[_]⁻¹ : {A : Type ℓ} (R : EquivPropRel A ℓ)
→ compPropRel (quotientPropRel (R .fst .fst)) (invPropRel (quotientPropRel (R .fst .fst))) .fst
≡ R .fst .fst
[_]∙[_]⁻¹ R =
funExt₂ λ a b →
hPropExt squash (R .fst .snd a b)
(Trunc.rec (R .fst .snd a b)
(λ {(c , p , q) → effective (R .fst .snd) (R .snd) a b (p ∙ sym q)}))
(λ r → ∣ _ , eq/ a b r , refl ∣)
functionSuitableRel : {S : Type ℓ → Type ℓ₁} {T : Type ℓ → Type ℓ₂}
{ρ₁ : StrRel S ℓ₁'} {ρ₂ : StrRel T ℓ₂'}
(θ₁ : SuitableStrRel S ρ₁)
→ PositiveStrRel θ₁
→ SuitableStrRel T ρ₂
→ SuitableStrRel (FunctionStructure S T) (FunctionRelStr ρ₁ ρ₂)
functionSuitableRel {S = S} {T = T} {ρ₁ = ρ₁} {ρ₂} θ₁ σ₁ θ₂ .quo (X , f) R h =
final
where
ref : (s : S X) → ρ₁ (R .fst .fst) s s
ref = posRelReflexive σ₁ R
[f] : S X / ρ₁ (R .fst .fst) → T (X / R .fst .fst)
[f] [ s ] = θ₂ .quo (X , f s) R (h (ref s)) .fst .fst
[f] (eq/ s₀ s₁ r i) =
cong fst
(θ₂ .quo (X , f s₀) R (h (ref s₀)) .snd
( [f] [ s₁ ]
, subst (λ R' → ρ₂ R' (f s₀) ([f] [ s₁ ]))
(composeWith[_] R)
(θ₂ .transitive (R .fst) (quotientPropRel (R .fst .fst))
(h r)
(θ₂ .quo (X , f s₁) R (h (ref s₁)) .fst .snd))
))
i
[f] (squash/ _ _ p q j i) =
θ₂ .set squash/ _ _ (cong [f] p) (cong [f] q) j i
relLemma : (s : S X) (t : S X)
→ ρ₁ (graphRel [_]) s (funIsEq (σ₁ .quo R) [ t ])
→ ρ₂ (graphRel [_]) (f s) ([f] [ t ])
relLemma s t r =
subst (λ R' → ρ₂ R' (f s) ([f] [ t ]))
(composeWith[_] R)
(θ₂ .transitive (R .fst) (quotientPropRel (R .fst .fst))
(h r')
(θ₂ .quo (X , f t) R (h (ref t)) .fst .snd))
where
r' : ρ₁ (R .fst .fst) s t
r' =
subst (λ R' → ρ₁ R' s t) ([_]∙[_]⁻¹ R)
(θ₁ .transitive
(quotientPropRel (R .fst .fst))
(invPropRel (quotientPropRel (R .fst .fst)))
r
(θ₁ .symmetric (quotientPropRel (R .fst .fst))
(subst
(λ t' → ρ₁ (graphRel [_]) t' (funIsEq (σ₁ .quo R) [ t ]))
(σ₁ .act .actStrId t)
(σ₁ .act .actRel eq/ t t (ref t)))))
quoRelLemma : (s : S X) (t : S X / ρ₁ (R .fst .fst))
→ ρ₁ (graphRel [_]) s (funIsEq (σ₁ .quo R) t)
→ ρ₂ (graphRel [_]) (f s) ([f] t)
quoRelLemma s =
elimProp (λ _ → isPropΠ λ _ → θ₂ .prop (λ _ _ → squash/ _ _) _ _)
(relLemma s)
final : Σ (Σ _ _) _
final .fst .fst = [f] ∘ invIsEq (σ₁ .quo R)
final .fst .snd {s} {t} r =
quoRelLemma s
(invIsEq (σ₁ .quo R) t)
(subst (ρ₁ (graphRel [_]) s) (sym (secIsEq (σ₁ .quo R) t)) r)
final .snd (f' , c) =
Σ≡Prop
(λ _ → isPropImplicitΠ λ s →
isPropImplicitΠ λ t →
isPropΠ λ _ → θ₂ .prop (λ _ _ → squash/ _ _) _ _)
(funExt λ s → contractorLemma (invIsEq (σ₁ .quo R) s) ∙ cong f' (secIsEq (σ₁ .quo R) s))
where
contractorLemma : (s : S X / ρ₁ (R .fst .fst))
→ [f] s ≡ f' (funIsEq (σ₁ .quo R) s)
contractorLemma =
elimProp
(λ _ → θ₂ .set squash/ _ _)
(λ s →
cong fst
(θ₂ .quo (X , f s) R (h (ref s)) .snd
( f' (funIsEq (σ₁ .quo R) [ s ])
, c
(subst
(λ s' → ρ₁ (graphRel [_]) s' (funIsEq (σ₁ .quo R) [ s ]))
(σ₁ .act .actStrId s)
(σ₁ .act .actRel eq/ s s (ref s)))
)))
functionSuitableRel {ρ₁ = ρ₁} {ρ₂} θ₁ σ θ₂ .symmetric R h r =
θ₂ .symmetric R (h (θ₁ .symmetric (invPropRel R) r))
functionSuitableRel {ρ₁ = ρ₁} {ρ₂} θ₁ σ θ₂ .transitive R R' h h' rr' =
Trunc.rec
(θ₂ .prop (λ _ _ → squash) _ _)
(λ {(_ , r , r') → θ₂ .transitive R R' (h r) (h' r')})
(σ .detransitive R R' rr')
functionSuitableRel {ρ₁ = ρ₁} {ρ₂} θ₁ σ θ₂ .set setX =
isSetΠ λ _ → θ₂ .set setX
functionSuitableRel {ρ₁ = ρ₁} {ρ₂} θ₁ σ θ₂ .prop propR f g =
isPropImplicitΠ λ _ →
isPropImplicitΠ λ _ →
isPropΠ λ _ →
θ₂ .prop propR _ _
functionRelMatchesEquiv : {S : Type ℓ → Type ℓ₁} {T : Type ℓ → Type ℓ₂}
(ρ₁ : StrRel S ℓ₁') {ι₁ : StrEquiv S ℓ₁''}
(ρ₂ : StrRel T ℓ₂') {ι₂ : StrEquiv T ℓ₂''}
→ StrRelMatchesEquiv ρ₁ ι₁
→ StrRelMatchesEquiv ρ₂ ι₂
→ StrRelMatchesEquiv (FunctionRelStr ρ₁ ρ₂) (FunctionEquivStr ι₁ ι₂)
functionRelMatchesEquiv ρ₁ ρ₂ μ₁ μ₂ (X , f) (Y , g) e =
equivImplicitΠCod (equivImplicitΠCod (equiv→ (μ₁ _ _ e) (μ₂ _ _ e)))
functionRelMatchesEquiv+ : {S : Type ℓ → Type ℓ₁} {T : Type ℓ → Type ℓ₂}
(ρ₁ : StrRel S ℓ₁') (α₁ : EquivAction S)
(ρ₂ : StrRel T ℓ₂') (ι₂ : StrEquiv T ℓ₂'')
→ StrRelMatchesEquiv ρ₁ (EquivAction→StrEquiv α₁)
→ StrRelMatchesEquiv ρ₂ ι₂
→ StrRelMatchesEquiv (FunctionRelStr ρ₁ ρ₂) (FunctionEquivStr+ α₁ ι₂)
functionRelMatchesEquiv+ ρ₁ α₁ ρ₂ ι₂ μ₁ μ₂ (X , f) (Y , g) e =
compEquiv
(functionRelMatchesEquiv ρ₁ ρ₂ μ₁ μ₂ (X , f) (Y , g) e)
(isoToEquiv isom)
where
open Iso
isom : Iso
(FunctionEquivStr (EquivAction→StrEquiv α₁) ι₂ (X , f) (Y , g) e)
(FunctionEquivStr+ α₁ ι₂ (X , f) (Y , g) e)
isom .fun h s = h refl
isom .inv k {x} = J (λ y _ → ι₂ (X , f x) (Y , g y) e) (k x)
isom .rightInv k i x = JRefl (λ y _ → ι₂ (X , f x) (Y , g y) e) (k x) i
isom .leftInv h =
implicitFunExt λ {x} →
implicitFunExt λ {y} →
funExt λ p →
J (λ y p → isom .inv (isom .fun h) p ≡ h p)
(funExt⁻ (isom .rightInv (isom .fun h)) x)
p
| {
"alphanum_fraction": 0.5590481786,
"avg_line_length": 35.4583333333,
"ext": "agda",
"hexsha": "4ab42b9967b32c404280999f067e5a8d33e82142",
"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": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Schippmunk/cubical",
"max_forks_repo_path": "Cubical/Structures/Relational/Function.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"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": "Schippmunk/cubical",
"max_issues_repo_path": "Cubical/Structures/Relational/Function.agda",
"max_line_length": 99,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Schippmunk/cubical",
"max_stars_repo_path": "Cubical/Structures/Relational/Function.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2863,
"size": 6808
} |
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.cubical.Square
open import lib.types.Group
open import lib.types.EilenbergMacLane1.Core
open import lib.types.EilenbergMacLane1.DoubleElim
module lib.types.EilenbergMacLane1.DoublePathElim where
private
emloop-emloop-eq-helper : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k}
(f g : A → B → C)
{a₀ a₁ : A} (p : a₀ == a₁)
{b₀ b₁ : B} (q : b₀ == b₁)
{u₀₀ : f a₀ b₀ == g a₀ b₀}
{u₀₁ : f a₀ b₁ == g a₀ b₁}
{u₁₀ : f a₁ b₀ == g a₁ b₀}
{u₁₁ : f a₁ b₁ == g a₁ b₁}
(sq₀₋ : Square u₀₀ (ap (f a₀) q) (ap (g a₀) q) u₀₁)
(sq₁₋ : Square u₁₀ (ap (f a₁) q) (ap (g a₁) q) u₁₁)
(sq₋₀ : Square u₀₀ (ap (λ a → f a b₀) p) (ap (λ a → g a b₀) p) u₁₀)
(sq₋₁ : Square u₀₁ (ap (λ a → f a b₁) p) (ap (λ a → g a b₁) p) u₁₁)
→ ap-comm f p q ∙v⊡ (sq₀₋ ⊡h sq₋₁)
==
(sq₋₀ ⊡h sq₁₋) ⊡v∙ ap-comm g p q
→ ↓-ap-in (λ Z → Z) (λ a → f a b₀ == g a b₀) (↓-='-from-square sq₋₀) ∙'ᵈ
↓-ap-in (λ Z → Z) (λ b → f a₁ b == g a₁ b) (↓-='-from-square sq₁₋)
==
↓-ap-in (λ Z → Z) (λ b → f a₀ b == g a₀ b) (↓-='-from-square sq₀₋) ∙ᵈ
↓-ap-in (λ Z → Z) (λ a → f a b₁ == g a b₁) (↓-='-from-square sq₋₁)
[ (λ p → u₀₀ == u₁₁ [ (λ Z → Z) ↓ p ]) ↓
ap-comm' (λ a b → f a b == g a b) p q ]
emloop-emloop-eq-helper f g idp idp sq₀₋ sq₁₋ sq₋₀ sq₋₁ r =
horiz-degen-path sq₋₀ ∙' horiz-degen-path sq₁₋
=⟨ ∙'=∙ (horiz-degen-path sq₋₀) (horiz-degen-path sq₁₋) ⟩
horiz-degen-path sq₋₀ ∙ horiz-degen-path sq₁₋
=⟨ ! (horiz-degen-path-⊡h sq₋₀ sq₁₋) ⟩
horiz-degen-path (sq₋₀ ⊡h sq₁₋)
=⟨ ap horiz-degen-path (! r) ⟩
horiz-degen-path (sq₀₋ ⊡h sq₋₁)
=⟨ horiz-degen-path-⊡h sq₀₋ sq₋₁ ⟩
horiz-degen-path sq₀₋ ∙ horiz-degen-path sq₋₁ =∎
module _ {i j} (G : Group i) (H : Group j) where
private
module G = Group G
module H = Group H
module EM₁Level₂DoublePathElim {k} {C : Type k}
{{C-level : has-level 2 C}}
(f₁ f₂ : EM₁ G → EM₁ H → C)
(embase-embase* : f₁ embase embase == f₂ embase embase)
(embase-emloop* : ∀ h →
Square embase-embase* (ap (f₁ embase) (emloop h))
(ap (f₂ embase) (emloop h)) embase-embase*)
(emloop-embase* : ∀ g →
Square embase-embase* (ap (λ x → f₁ x embase) (emloop g))
(ap (λ x → f₂ x embase) (emloop g)) embase-embase*)
(embase-emloop-comp* : ∀ h₁ h₂ →
embase-emloop* (H.comp h₁ h₂) ⊡v∙
ap (ap (f₂ embase)) (emloop-comp' H h₁ h₂)
==
ap (ap (f₁ embase)) (emloop-comp' H h₁ h₂) ∙v⊡
↓-='-square-comp (embase-emloop* h₁) (embase-emloop* h₂))
(emloop-comp-embase* : ∀ g₁ g₂ →
emloop-embase* (G.comp g₁ g₂) ⊡v∙
ap (ap (λ x → f₂ x embase)) (emloop-comp' G g₁ g₂)
==
ap (ap (λ x → f₁ x embase)) (emloop-comp' G g₁ g₂) ∙v⊡
↓-='-square-comp (emloop-embase* g₁) (emloop-embase* g₂))
(emloop-emloop* : ∀ g h →
ap-comm f₁ (emloop g) (emloop h) ∙v⊡
(embase-emloop* h ⊡h emloop-embase* g)
==
(emloop-embase* g ⊡h embase-emloop* h) ⊡v∙
ap-comm f₂ (emloop g) (emloop h))
where
private
module M =
EM₁Level₁DoubleElim G H
{P = λ x y → f₁ x y == f₂ x y}
{{λ x y → has-level-apply C-level _ _}}
embase-embase*
(λ h → ↓-='-from-square (embase-emloop* h))
(λ g → ↓-='-from-square (emloop-embase* g))
(λ h₁ h₂ →
↓-='-from-square-comp-path (emloop-comp h₁ h₂)
(embase-emloop* h₁)
(embase-emloop* h₂)
(embase-emloop* (H.comp h₁ h₂))
(embase-emloop-comp* h₁ h₂))
(λ g₁ g₂ →
↓-='-from-square-comp-path (emloop-comp g₁ g₂)
(emloop-embase* g₁)
(emloop-embase* g₂)
(emloop-embase* (G.comp g₁ g₂))
(emloop-comp-embase* g₁ g₂))
(λ g h →
emloop-emloop-eq-helper f₁ f₂
(emloop g) (emloop h)
(embase-emloop* h)
(embase-emloop* h)
(emloop-embase* g)
(emloop-embase* g)
(emloop-emloop* g h) )
open M public
| {
"alphanum_fraction": 0.4707712825,
"avg_line_length": 40.1696428571,
"ext": "agda",
"hexsha": "f21170832e0a929129dafefffbb30c392f6d4941",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "AntoineAllioux/HoTT-Agda",
"max_forks_repo_path": "core/lib/types/EilenbergMacLane1/DoublePathElim.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "AntoineAllioux/HoTT-Agda",
"max_issues_repo_path": "core/lib/types/EilenbergMacLane1/DoublePathElim.agda",
"max_line_length": 76,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "AntoineAllioux/HoTT-Agda",
"max_stars_repo_path": "core/lib/types/EilenbergMacLane1/DoublePathElim.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": 1737,
"size": 4499
} |
module Progress where
open import Data.Bool
open import Data.Empty
open import Data.Maybe hiding (Any ; All)
open import Data.Nat
open import Data.List
open import Data.List.All
open import Data.List.Any
open import Data.Product
open import Data.Unit
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
open import Typing
open import Syntax
open import Global
open import Channel
open import Values
open import Session
open import Schedule
open import ProcessSyntax
open import ProcessRun
-- resources appear in pairs
data Paired : SEntry → Set where
aon-nothing : Paired nothing
aon-all : ∀ {s} → Paired (just (s , POSNEG))
-- need lemmas for matchXAndGo ...
-- matchXandGo-preserves-paired
matchWaitAndGo-preserves-paired :
∀ {G G₁ G₂ G₁₁ G₁₂ φ G₂₁ G₂₂ Gnext tpnext}
{ss : SSplit G G₁ G₂}
{ss-cl : SSplit G₁ G₁₁ G₁₂}
{v : Val G₁₁ (TChan send!)}
{cl-κ : Cont G₁₂ φ TUnit}
{ss-GG' : SSplit G₂ G₂₁ G₂₂}
→ All Paired G
→ (tp' : ThreadPool G₂₁)
→ (tp'' : ThreadPool G₂₂)
→ matchWaitAndGo ss (ss-cl , v , cl-κ) ss-GG' tp' tp'' ≡ just (Gnext , tpnext)
→ All Paired Gnext
matchWaitAndGo-preserves-paired all-paired (tnil ina) tp'' ()
matchWaitAndGo-preserves-paired {ss-GG' = ss-GG'} all-paired (tcons ss cmd@(Fork ss₁ κ₁ κ₂) tp') tp'' match-≡
with ssplit-compose5 ss-GG' ss
... | Gi , ss-tp' , ss' =
matchWaitAndGo-preserves-paired all-paired tp' (tcons ss' cmd tp'') match-≡
matchWaitAndGo-preserves-paired {ss-GG' = ss-GG'} all-paired (tcons ss cmd@(Ready ss₁ v κ) tp') tp'' match-≡ with ssplit-compose5 ss-GG' ss
... | Gi , ss-tp' , ss' =
matchWaitAndGo-preserves-paired all-paired tp' (tcons ss' cmd tp'') match-≡
matchWaitAndGo-preserves-paired {ss-GG' = ss-GG'} all-paired (tcons ss cmd@(Halt x x₁ x₂) tp') tp'' match-≡ with ssplit-compose5 ss-GG' ss
... | Gi , ss-tp' , ss' =
matchWaitAndGo-preserves-paired all-paired tp' (tcons ss' cmd tp'') match-≡
matchWaitAndGo-preserves-paired {ss-GG' = ss-GG'} all-paired (tcons ss cmd@(New s κ) tp') tp'' match-≡ with ssplit-compose5 ss-GG' ss
... | Gi , ss-tp' , ss' =
matchWaitAndGo-preserves-paired all-paired tp' (tcons ss' cmd tp'') match-≡
matchWaitAndGo-preserves-paired {ss-GG' = ss-GG'} all-paired (tcons ss cmd@(Close ss₁ v κ) tp') tp'' match-≡ with ssplit-compose5 ss-GG' ss
... | Gi , ss-tp' , ss' =
matchWaitAndGo-preserves-paired all-paired tp' (tcons ss' cmd tp'') match-≡
matchWaitAndGo-preserves-paired {ss-GG' = ss-GG'} all-paired (tcons ss cmd@(Send ss₁ ss-args vch v κ) tp') tp'' match-≡ with ssplit-compose5 ss-GG' ss
... | Gi , ss-tp' , ss' =
matchWaitAndGo-preserves-paired all-paired tp' (tcons ss' cmd tp'') match-≡
matchWaitAndGo-preserves-paired {ss-GG' = ss-GG'} all-paired (tcons ss cmd@(Recv ss₁ vch κ) tp') tp'' match-≡ with ssplit-compose5 ss-GG' ss
... | Gi , ss-tp' , ss' =
matchWaitAndGo-preserves-paired all-paired tp' (tcons ss' cmd tp'') match-≡
matchWaitAndGo-preserves-paired {ss-GG' = ss-GG'} all-paired (tcons ss cmd@(Select ss₁ lab vch κ) tp') tp'' match-≡ with ssplit-compose5 ss-GG' ss
... | Gi , ss-tp' , ss' =
matchWaitAndGo-preserves-paired all-paired tp' (tcons ss' cmd tp'') match-≡
matchWaitAndGo-preserves-paired {ss-GG' = ss-GG'} all-paired (tcons ss cmd@(Branch ss₁ vch dcont) tp') tp'' match-≡ with ssplit-compose5 ss-GG' ss
... | Gi , ss-tp' , ss' =
matchWaitAndGo-preserves-paired all-paired tp' (tcons ss' cmd tp'') match-≡
matchWaitAndGo-preserves-paired {ss-GG' = ss-GG'} all-paired (tcons ss cmd@(NSelect ss₁ lab vch κ) tp') tp'' match-≡ with ssplit-compose5 ss-GG' ss
... | Gi , ss-tp' , ss' =
matchWaitAndGo-preserves-paired all-paired tp' (tcons ss' cmd tp'') match-≡
matchWaitAndGo-preserves-paired {ss-GG' = ss-GG'} all-paired (tcons ss cmd@(NBranch ss₁ vch dcont) tp') tp'' match-≡ with ssplit-compose5 ss-GG' ss
... | Gi , ss-tp' , ss' =
matchWaitAndGo-preserves-paired all-paired tp' (tcons ss' cmd tp'') match-≡
matchWaitAndGo-preserves-paired {ss = ss-top} {ss-cl = ss-cl} {v = VChan cl-b cl-vcr} {ss-GG' = ss-tp}
all-paired (tcons ss cmd@(Wait ss₁ (VChan w-b w-vcr) κ) tp-wl) tp-acc match-≡
with ssplit-compose6 ss ss₁
... | Gi , ss-g3gi , ss-g4g2
with ssplit-compose6 ss-tp ss-g3gi
... | Gi' , ss-g3gi' , ss-gtpacc
with ssplit-join ss-top ss-cl ss-g3gi'
... | Gchannels , Gother , ss-top' , ss-channels , ss-others
with vcr-match ss-channels cl-vcr w-vcr
matchWaitAndGo-preserves-paired {ss = ss-top} {ss-cl} {VChan cl-b cl-vcr} {ss-GG' = ss-tp} all-paired (tcons ss cmd@(Wait ss₁ (VChan w-b w-vcr) κ) tp-wl) tp-acc match-≡ | Gi , ss-g3gi , ss-g4g2 | Gi' , ss-g3gi' , ss-gtpacc | Gchannels , Gother , ss-top' , ss-channels , ss-others | nothing with ssplit-compose5 ss-tp ss
... | _ , ss-tp' , ss' =
matchWaitAndGo-preserves-paired all-paired tp-wl (tcons ss' cmd tp-acc) match-≡
matchWaitAndGo-preserves-paired {ss = ss-top} {ss-cl} {VChan cl-b cl-vcr} {ss-GG' = ss-tp} all-paired (tcons ss cmd@(Wait ss₁ (VChan w-b w-vcr) κ) tp-wl) tp-acc refl | Gi , ss-g3gi , ss-g4g2 | Gi' , ss-g3gi' , ss-gtpacc | Gchannels , Gother , ss-top' , ss-channels , ss-others | just x = {!!}
-- remains to prove All Paired Gother
step-preserves-paired : ∀ {G G' ev tp'} → All Paired G → (tp : ThreadPool G) → Original.step tp ≡ (_,_ {G'} ev tp') → All Paired G'
step-preserves-paired all-paired tp step-≡ with tp
step-preserves-paired all-paired tp refl | tnil ina = all-paired
step-preserves-paired all-paired tp refl | tcons ss (Fork ss₁ κ₁ κ₂) tp' = all-paired
step-preserves-paired all-paired tp refl | tcons ss (Ready ss₁ v κ) tp' = all-paired
step-preserves-paired all-paired tp step-≡ | tcons ss (Halt x x₁ x₂) tp' with inactive-left-ssplit ss x
step-preserves-paired all-paired tp refl | tcons ss (Halt x x₁ x₂) tp' | refl = all-paired
step-preserves-paired all-paired tp refl | tcons ss (New s κ) tp' = aon-all ∷ all-paired
step-preserves-paired all-paired tp step-≡ | tcons{G₁}{G₂} ss (Close ss-vκ v κ) tp'
with ssplit-refl-left-inactive G₂
... | G' , ina-G' , ss-GG'
with matchWaitAndGo ss (ss-vκ , v , κ) ss-GG' tp' (tnil ina-G')
step-preserves-paired all-paired tp refl | tcons {G₁} {G₂} ss (Close ss-vκ v κ) tp' | G' , ina-G' , ss-GG' | just (Gnext , tpnext) = matchWaitAndGo-preserves-paired {ss = ss}{ss-cl = ss-vκ}{v = v}{cl-κ = κ}{ss-GG'} all-paired tp' (tnil ina-G') p
where
p : matchWaitAndGo ss (ss-vκ , v , κ) ss-GG' tp' (tnil ina-G') ≡ just (Gnext , tpnext)
p = sym {!refl!}
step-preserves-paired all-paired tp refl | tcons {G₁} {G₂} ss (Close ss-vκ v κ) tp' | G' , ina-G' , ss-GG' | nothing = all-paired
step-preserves-paired all-paired tp refl | tcons ss (Wait ss₁ v κ) tp' = all-paired
step-preserves-paired all-paired tp refl | tcons ss (Send ss₁ ss-args vch v κ) tp' = all-paired
step-preserves-paired all-paired tp step-≡ | tcons{G₁}{G₂} ss (Recv ss-vκ vch κ) tp' with ssplit-refl-left-inactive G₂
... | G' , ina-G' , ss-GG' with matchSendAndGo ss (ss-vκ , vch , κ) ss-GG' tp' (tnil ina-G')
... | just (G-next , tp-next) = {!!}
step-preserves-paired all-paired tp refl | tcons {G₁} {G₂} ss (Recv ss-vκ vch κ) tp' | G' , ina-G' , ss-GG' | nothing = all-paired
step-preserves-paired all-paired tp step-≡ | tcons{G₁}{G₂} ss (Select ss-vκ lab vch κ) tp' with ssplit-refl-left-inactive G₂
... | G' , ina-G' , ss-GG' with matchBranchAndGo ss (ss-vκ , lab , vch , κ) ss-GG' tp' (tnil ina-G')
... | just (G-next , tp-next) = {!!}
step-preserves-paired all-paired tp refl | tcons {G₁} {G₂} ss (Select ss-vκ lab vch κ) tp' | G' , ina-G' , ss-GG' | nothing = all-paired
step-preserves-paired all-paired tp refl | tcons ss (Branch ss₁ vch dcont) tp' = all-paired
step-preserves-paired all-paired tp step-≡ | tcons{G₁}{G₂} ss (NSelect ss-vκ lab vch κ) tp' with ssplit-refl-left-inactive G₂
... | G' , ina-G' , ss-GG' with matchNBranchAndGo ss (ss-vκ , lab , vch , κ) ss-GG' tp' (tnil ina-G')
... | just (G-next , tp-next) = {!!}
step-preserves-paired all-paired tp refl | tcons {G₁} {G₂} ss (NSelect ss-vκ lab vch κ) tp' | G' , ina-G' , ss-GG' | nothing = all-paired
step-preserves-paired all-paired tp refl | tcons ss (NBranch ss₁ vch dcont) tp' = all-paired
-- check if the first thread can make a step
topCanStep : ∀ {G} → ThreadPool G → Set
topCanStep (tnil ina) = ⊥
topCanStep (tcons ss (Fork ss₁ κ₁ κ₂) tp) = ⊤
topCanStep (tcons ss (Ready ss₁ v κ) tp) = ⊤
topCanStep (tcons ss (Halt x x₁ x₂) tp) = ⊤
topCanStep (tcons ss (New s κ) tp) = ⊤
topCanStep (tcons{G₁}{G₂} ss (Close ss-vκ v κ) tp) with ssplit-refl-left-inactive G₂
... | G' , ina-G' , ss-GG' = Is-just (matchWaitAndGo ss (ss-vκ , v , κ) ss-GG' tp (tnil ina-G'))
topCanStep (tcons ss (Wait ss₁ v κ) tp) = ⊥
topCanStep (tcons ss (Send ss₁ ss-args vch v κ) tp) = ⊥
topCanStep (tcons{G₁}{G₂} ss (Recv ss-vκ vch κ) tp) with ssplit-refl-left-inactive G₂
... | G' , ina-G' , ss-GG' = Is-just (matchSendAndGo ss (ss-vκ , vch , κ) ss-GG' tp (tnil ina-G'))
topCanStep (tcons{G₁}{G₂} ss (Select ss-vκ lab vch κ) tp) with ssplit-refl-left-inactive G₂
... | G' , ina-G' , ss-GG' = Is-just (matchBranchAndGo ss (ss-vκ , lab , vch , κ) ss-GG' tp (tnil ina-G'))
topCanStep (tcons ss (Branch ss₁ vch dcont) tp) = ⊥
topCanStep (tcons{G₁}{G₂} ss (NSelect ss-vκ lab vch κ) tp) with ssplit-refl-left-inactive G₂
... | G' , ina-G' , ss-GG' = Is-just (matchNBranchAndGo ss (ss-vκ , lab , vch , κ) ss-GG' tp (tnil ina-G'))
topCanStep (tcons ss (NBranch ss₁ vch dcont) tp) = ⊥
tpLength : ∀ {G} → ThreadPool G → ℕ
tpLength (tnil ina) = 0
tpLength (tcons ss cmd tp) = suc (tpLength tp)
allRotations : ∀ {G} → ThreadPool G → List (ThreadPool G)
allRotations tp = nRotations (tpLength tp) tp
where
rotate : ∀ {G} → ThreadPool G → ThreadPool G
rotate (tnil ina) = tnil ina
rotate (tcons ss cmd tp) = tsnoc ss tp cmd
nRotations : ∀ {G} ℕ → ThreadPool G → List (ThreadPool G)
nRotations zero tp = []
nRotations (suc n) tp = tp ∷ nRotations n (rotate tp)
-- the thread pool can step if any command in the pool can make a step
canStep : ∀ {G} → ThreadPool G → Set
canStep tp = Any topCanStep (allRotations tp)
deadlocked : ∀ {G} → ThreadPool G → Set
deadlocked (tnil ina) = ⊥
deadlocked tp@(tcons _ _ _) = ¬ canStep tp
-- progress
| {
"alphanum_fraction": 0.6650260852,
"avg_line_length": 57.395480226,
"ext": "agda",
"hexsha": "94e19b3e56ed89c7de619146f23c686e28989952",
"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": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "peterthiemann/definitional-session",
"max_forks_repo_path": "src/Progress.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c",
"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": "peterthiemann/definitional-session",
"max_issues_repo_path": "src/Progress.agda",
"max_line_length": 319,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "peterthiemann/definitional-session",
"max_stars_repo_path": "src/Progress.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-18T08:10:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-01-19T16:33:27.000Z",
"num_tokens": 3856,
"size": 10159
} |
{-# OPTIONS --safe #-}
module Definition.Typed.Consequences.RelevanceUnicity where
open import Definition.Untyped hiding (U≢ℕ; U≢Π; U≢ne; ℕ≢Π; ℕ≢ne; Π≢ne; U≢Empty; ℕ≢Empty; Empty≢Π; Empty≢ne)
open import Definition.Untyped.Properties using (subst-Univ-either)
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.Typed.Weakening
open import Definition.Typed.Consequences.Equality
import Definition.Typed.Consequences.Inequality as Ineq
open import Definition.Typed.Consequences.Inversion
open import Definition.Typed.Consequences.Injectivity
open import Definition.Typed.Consequences.NeTypeEq
open import Definition.Typed.Consequences.Syntactic
open import Definition.Typed.Consequences.PiNorm
open import Definition.Typed.Consequences.Substitution
open import Tools.Product
open import Tools.Empty
open import Tools.Sum using (_⊎_; inj₁; inj₂)
import Tools.PropositionalEquality as PE
ℕ-relevant-term : ∀ {Γ A r} → Γ ⊢ ℕ ∷ A ^ r → Whnf A → A PE.≡ Univ ! ⁰
ℕ-relevant-term [ℕ] whnfA = let [[N]] , e = inversion-ℕ [ℕ]
in U≡A-whnf (sym (PE.subst (λ r → _ ⊢ _ ≡ _ ^ r) e [[N]])) whnfA
ℕ-relevant : ∀ {Γ r} → Γ ⊢ ℕ ^ r → r PE.≡ [ ! , ι ⁰ ]
ℕ-relevant (univ [ℕ]) = let er , el = Univ-PE-injectivity (ℕ-relevant-term [ℕ] Uₙ)
in PE.cong₂ (λ x y → [ x , ι y ]) er el
Empty-irrelevant-term : ∀ {Γ A lEmpty r} → Γ ⊢ Empty lEmpty ∷ A ^ r → Whnf A → A PE.≡ SProp lEmpty
Empty-irrelevant-term [Empty] whnfA = let [[Empty]] , e = inversion-Empty [Empty]
in U≡A-whnf (sym (PE.subst (λ r → _ ⊢ _ ≡ _ ^ r) e [[Empty]])) whnfA
Empty-irrelevant : ∀ {Γ lEmpty r} → Γ ⊢ Empty lEmpty ^ r → r PE.≡ [ % , ι lEmpty ]
Empty-irrelevant (univ [Empty]) = let er , el = Univ-PE-injectivity (Empty-irrelevant-term [Empty] Uₙ)
in PE.cong₂ (λ x y → [ x , ι y ]) er el
Univ-relevant-term : ∀ {Γ A rU lU r} → Γ ⊢ Univ rU lU ∷ A ^ r → Whnf A → A PE.≡ U ¹ × lU PE.≡ ⁰
Univ-relevant-term [U] whnfA = U≡A-whnf (sym (proj₁ (inversion-U [U]))) whnfA , proj₂ (proj₂ (inversion-U [U]))
Univ-relevant : ∀ {Γ rU lU r} → Γ ⊢ Univ rU lU ^ r → r PE.≡ [ ! , next lU ]
Univ-relevant (Uⱼ _) = PE.refl
Univ-relevant (univ [U]) = let er , el = Univ-PE-injectivity (proj₁ (Univ-relevant-term [U] Uₙ))
in PE.cong₂ (λ x y → [ x , y ]) er
(PE.trans (PE.cong ι el) (PE.cong next (PE.sym (proj₂ (Univ-relevant-term [U] Uₙ)))))
mutual
Univ-uniq′ : ∀ {Γ A T₁ T₂ r₁ r₂ l₁ l₁' l₂ l₂'} → Γ ⊢ T₁ ≡ Univ r₁ l₁ ^ [ ! , l₁' ] → Γ ⊢ T₂ ≡ Univ r₂ l₂ ^ [ ! , l₂' ]
→ next l₁ PE.≡ l₁' → next l₂ PE.≡ l₂'
→ ΠNorm A
→ Γ ⊢ A ∷ T₁ ^ [ ! , l₁' ] → Γ ⊢ A ∷ T₂ ^ [ ! , l₂' ] → r₁ PE.≡ r₂ × l₁' PE.≡ l₂'
Univ-uniq′ e₁ e₂ el₁ el₂ w (univ 0<1 x₁) (univ 0<1 x₃) =
let er₁ , _ = Uinjectivity e₁
er₂ , _ = Uinjectivity e₂
in PE.trans (PE.sym er₁) er₂ , PE.refl
Univ-uniq′ e₁ e₂ el₁ PE.refl w (ℕⱼ x) y =
let e₁′ , el₁′ = Uinjectivity e₁
e₂′ , el₂′ = Uinjectivity (trans (sym e₂) (proj₁ (inversion-ℕ y)) )
in PE.sym (PE.trans e₂′ e₁′) , PE.cong next (PE.sym el₂′)
Univ-uniq′ e₁ e₂ el₁ el₂ w (Emptyⱼ x) y =
let e₁′ , el₁′ = Uinjectivity e₁
e₂′ , el₂′ = Uinjectivity (trans (sym e₂) (proj₁ (inversion-Empty y)) )
in PE.sym (PE.trans e₂′ e₁′) , PE.trans (PE.cong next (PE.sym el₂′)) el₂
Univ-uniq′ e₁ e₂ el₁ el₂ w (Πⱼ a ▹ b ▹ x ▹ x₁) (Πⱼ a' ▹ b' ▹ y ▹ y₁) =
let er₁ , _ = Uinjectivity e₁
er₂ , _ = Uinjectivity e₂
res = Univ-uniq′ (refl (Ugenⱼ (wfTerm x₁))) (refl (Ugenⱼ (wfTerm x₁)))
PE.refl PE.refl (ΠNorm-Π w) x₁ y₁
in PE.trans (PE.sym er₁) (PE.trans (proj₁ res) er₂) , PE.refl
Univ-uniq′ e₁ e₂ el₁ el₂ (∃ₙ w) (∃ⱼ x ▹ x₁) (∃ⱼ y ▹ y₁) =
let er₁ , _ = Uinjectivity e₁
er₂ , _ = Uinjectivity e₂
_ , el = Univ-uniq w x y
in PE.trans (PE.sym er₁) er₂ , PE.cong next el
Univ-uniq′ e₁ e₂ el₁ el₂ w (var _ x) (var _ y) =
let T≡T , e = varTypeEq′ x y
_ , el = typelevel-injectivity e
⊢T≡T = PE.subst (λ T → _ ⊢ _ ≡ T ^ _) T≡T (refl (proj₁ (syntacticEq e₁)))
in proj₁ (Uinjectivity (trans (trans (sym e₁) ⊢T≡T) (PE.subst (λ lx → _ ⊢ _ ≡ _ ^ [ _ , lx ]) (PE.sym el) e₂))) , el
Univ-uniq′ e₁ e₂ el₁ el₂ (ne ()) (lamⱼ x x₁ x₂ X) y
Univ-uniq′ e₁ e₂ el₁ el₂ (ne (∘ₙ n)) (_∘ⱼ_ {G = G} x x₁) (_∘ⱼ_ {G = G₁} y y₁) =
let F≡F , rF≡rF , lF≡lF , lG≡lG , G≡G = injectivity (proj₂ (neTypeEq n x y))
r≡r , _ = Uinjectivity (trans (sym e₁) (trans (substitutionEq G≡G (substRefl (singleSubst x₁)) (wfEq F≡F))
(PE.subst (λ lx → _ ⊢ _ ≡ _ ^ [ _ , ι lx ]) (PE.sym lG≡lG) e₂)))
in r≡r , PE.cong ι lG≡lG
Univ-uniq′ e₁ e₂ el₁ el₂ (ne ()) (zeroⱼ x) y
Univ-uniq′ e₁ e₂ el₁ el₂ (ne ()) (sucⱼ X) y
Univ-uniq′ e₁ e₂ el₁ el₂ w (natrecⱼ x x₁ x₂ x₃) (natrecⱼ x₄ y y₁ y₂) = proj₁ (Uinjectivity (trans (sym e₁) e₂)) , PE.refl
Univ-uniq′ e₁ e₂ el₁ el₂ w (Emptyrecⱼ x x₁) (Emptyrecⱼ y y₁) = proj₁ (Uinjectivity (trans (sym e₁) e₂)) , PE.refl
Univ-uniq′ e₁ e₂ el₁ el₂ (ne (Idₙ x)) (Idⱼ X X₁ X₂) (Idⱼ {l = ll} Y Y₁ Y₂) =
let _ , el = Univ-uniq (ne x) X Y
er₁ , _ = Uinjectivity e₁
er₂ , _ = Uinjectivity e₂
in PE.trans (PE.sym er₁) er₂ , PE.cong next el
Univ-uniq′ e₁ e₂ el₁ el₂ (ne (Idℕₙ x)) (Idⱼ X X₁ X₂) (Idⱼ {l = ll} Y Y₁ Y₂) =
let _ , el = Univ-uniq ℕₙ X Y
er₁ , _ = Uinjectivity e₁
er₂ , _ = Uinjectivity e₂
in PE.trans (PE.sym er₁) er₂ , PE.cong next el
Univ-uniq′ e₁ e₂ el₁ el₂ (ne (Idℕ0ₙ x)) (Idⱼ X X₁ X₂) (Idⱼ {l = ll} Y Y₁ Y₂) =
let _ , el = Univ-uniq ℕₙ X Y
er₁ , _ = Uinjectivity e₁
er₂ , _ = Uinjectivity e₂
in PE.trans (PE.sym er₁) er₂ , PE.cong next el
Univ-uniq′ e₁ e₂ el₁ el₂ (ne (IdℕSₙ x)) (Idⱼ X X₁ X₂) (Idⱼ {l = ll} Y Y₁ Y₂) =
let _ , el = Univ-uniq ℕₙ X Y
er₁ , _ = Uinjectivity e₁
er₂ , _ = Uinjectivity e₂
in PE.trans (PE.sym er₁) er₂ , PE.cong next el
Univ-uniq′ e₁ e₂ el₁ el₂ (ne (IdUₙ x)) (Idⱼ X X₁ X₂) (Idⱼ {l = ll} Y Y₁ Y₂) =
let _ , el = Univ-uniq Uₙ X Y
er₁ , _ = Uinjectivity e₁
er₂ , _ = Uinjectivity e₂
in PE.trans (PE.sym er₁) er₂ , PE.cong next el
Univ-uniq′ e₁ e₂ el₁ el₂ (ne (IdUℕₙ x)) (Idⱼ X X₁ X₂) (Idⱼ {l = ll} Y Y₁ Y₂) =
let _ , el = Univ-uniq Uₙ X Y
er₁ , _ = Uinjectivity e₁
er₂ , _ = Uinjectivity e₂
in PE.trans (PE.sym er₁) er₂ , PE.cong next el
Univ-uniq′ e₁ e₂ el₁ el₂ (ne (IdUΠₙ x)) (Idⱼ X X₁ X₂) (Idⱼ {l = ll} Y Y₁ Y₂) =
let _ , el = Univ-uniq Uₙ X Y
er₁ , _ = Uinjectivity e₁
er₂ , _ = Uinjectivity e₂
in PE.trans (PE.sym er₁) er₂ , PE.cong next el
Univ-uniq′ e₁ e₂ el₁ el₂ w (castⱼ X X₁ X₂ X₃) (castⱼ y y₁ y₂ y₃) = proj₁ (Uinjectivity (trans (sym e₁) e₂)) , PE.refl
Univ-uniq′ e₁ e₂ el₁ el₂ w (conv x x₁) y = Univ-uniq′ (trans x₁ e₁) e₂ el₁ el₂ w x y
Univ-uniq′ e₁ e₂ el₁ el₂ w x (conv y y₁) = Univ-uniq′ e₁ (trans y₁ e₂) el₁ el₂ w x y
Univ-uniq : ∀ {Γ A r₁ r₂ l₁ l₂} → ΠNorm A
→ Γ ⊢ A ∷ Univ r₁ l₁ ^ [ ! , next l₁ ] → Γ ⊢ A ∷ Univ r₂ l₂ ^ [ ! , next l₂ ] → r₁ PE.≡ r₂ × l₁ PE.≡ l₂
Univ-uniq n ⊢A₁ ⊢A₂ =
let ⊢Γ = wfTerm ⊢A₁
er , el = Univ-uniq′ (refl (Ugenⱼ ⊢Γ)) (refl (Ugenⱼ ⊢Γ)) PE.refl PE.refl n ⊢A₁ ⊢A₂
in er , next-inj el
relevance-unicity′ : ∀ {Γ A r₁ r₂ l₁ l₂} → ΠNorm A → Γ ⊢ A ^ [ r₁ , l₁ ] → Γ ⊢ A ^ [ r₂ , l₂ ] → r₁ PE.≡ r₂ × l₁ PE.≡ l₂
relevance-unicity′ n (Uⱼ x) (Uⱼ x₁) = PE.refl , PE.refl
relevance-unicity′ n (Uⱼ x) (univ x₁) = let _ , _ , ¹≡⁰ = inversion-U x₁ in ⊥-elim (⁰≢¹ (PE.sym ¹≡⁰))
relevance-unicity′ n (univ x) (Uⱼ x₁) = let _ , _ , ¹≡⁰ = inversion-U x in ⊥-elim (⁰≢¹ (PE.sym ¹≡⁰))
relevance-unicity′ n (univ x) (univ x₁) = let er , el = Univ-uniq n x x₁ in er , PE.cong ι el
relevance-unicity : ∀ {Γ A r₁ r₂ l₁ l₂} → Γ ⊢ A ^ [ r₁ , l₁ ] → Γ ⊢ A ^ [ r₂ , l₂ ] → r₁ PE.≡ r₂ × l₁ PE.≡ l₂
relevance-unicity ⊢A₁ ⊢A₂ with doΠNorm ⊢A₁
... | _ with doΠNorm ⊢A₂
relevance-unicity ⊢A₁ ⊢A₂ | B , nB , ⊢B , rB | C , nC , ⊢C , rC =
let e = detΠNorm* nB nC rB rC
in relevance-unicity′ nC (PE.subst _ e ⊢B) ⊢C
-- inequalities at any relevance
U≢ℕ : ∀ {r r′ l l′ Γ} → Γ ⊢ Univ r l ≡ ℕ ^ [ r′ , l′ ] → ⊥
U≢ℕ U≡ℕ = Ineq.U≢ℕ! (PE.subst (λ rx → _ ⊢ _ ≡ _ ^ [ rx , _ ])
(proj₁ (relevance-unicity (proj₂ (syntacticEq U≡ℕ))
(univ (ℕⱼ (wfEq U≡ℕ)))))
U≡ℕ)
U≢Π : ∀ {rU lU F rF G lF lG lΠ r Γ} → Γ ⊢ Univ rU lU ≡ Π F ^ rF ° lF ▹ G ° lG ° lΠ ^ [ r , ι lΠ ] → ⊥
U≢Π U≡Π =
let r≡! , _ = relevance-unicity (proj₁ (syntacticEq U≡Π)) (Ugenⱼ (wfEq U≡Π))
in Ineq.U≢Π! (PE.subst (λ rx → _ ⊢ _ ≡ _ ^ [ rx , _ ]) r≡! U≡Π)
U≢ne : ∀ {rU lU r l K Γ} → Neutral K → Γ ⊢ Univ rU lU ≡ K ^ [ r , ι l ] → ⊥
U≢ne neK U≡K =
let r≡! , _ = relevance-unicity (proj₁ (syntacticEq U≡K)) (Ugenⱼ (wfEq U≡K))
in Ineq.U≢ne! neK (PE.subst (λ rx → _ ⊢ _ ≡ _ ^ [ rx , _ ]) r≡! U≡K)
ℕ≢Π : ∀ {F rF G lF lG r Γ} → Γ ⊢ ℕ ≡ Π F ^ rF ° lF ▹ G ° lG ° ⁰ ^ [ r , ι ⁰ ] → ⊥
ℕ≢Π ℕ≡Π =
let r≡! , _ = relevance-unicity (proj₁ (syntacticEq ℕ≡Π)) (univ (ℕⱼ (wfEq ℕ≡Π)))
in Ineq.ℕ≢Π! (PE.subst (λ rx → _ ⊢ _ ≡ _ ^ [ rx , _ ]) r≡! ℕ≡Π)
Empty≢Π : ∀ {F rF G lF lG lΠ r Γ} → Γ ⊢ Empty lΠ ≡ Π F ^ rF ° lF ▹ G ° lG ° lΠ ^ [ r , ι lΠ ] → ⊥
Empty≢Π Empty≡Π =
let r≡% , _ = relevance-unicity (proj₁ (syntacticEq Empty≡Π)) (univ (Emptyⱼ (wfEq Empty≡Π)))
in Ineq.Empty≢Π% (PE.subst (λ rx → _ ⊢ _ ≡ _ ^ [ rx , _ ]) r≡% Empty≡Π)
ℕ≢ne : ∀ {K r Γ} → Neutral K → Γ ⊢ ℕ ≡ K ^ [ r , ι ⁰ ] → ⊥
ℕ≢ne neK ℕ≡K =
let r≡! , _ = relevance-unicity (proj₁ (syntacticEq ℕ≡K)) (univ (ℕⱼ (wfEq ℕ≡K)))
in Ineq.ℕ≢ne! neK (PE.subst (λ rx → _ ⊢ _ ≡ _ ^ [ rx , _ ]) r≡! ℕ≡K)
Empty≢ne : ∀ {K r l Γ} → Neutral K → Γ ⊢ Empty l ≡ K ^ [ r , ι l ] → ⊥
Empty≢ne neK Empty≡K =
let r≡% , _ = relevance-unicity (proj₁ (syntacticEq Empty≡K)) (univ (Emptyⱼ (wfEq Empty≡K)))
in Ineq.Empty≢ne% neK (PE.subst (λ rx → _ ⊢ _ ≡ _ ^ [ rx , _ ]) r≡% Empty≡K)
-- U != Empty is given easily by relevances
U≢Empty : ∀ {Γ rU lU lEmpty r′} → Γ ⊢ Univ rU lU ≡ Empty lEmpty ^ r′ → ⊥
U≢Empty U≡Empty =
let ⊢U , ⊢Empty = syntacticEq U≡Empty
e₁ , _ = relevance-unicity ⊢U (Ugenⱼ (wfEq U≡Empty))
e₂ , _ = relevance-unicity ⊢Empty (univ (Emptyⱼ (wfEq U≡Empty)))
in !≢% (PE.trans (PE.sym e₁) e₂)
-- ℕ and Empty also by relevance
ℕ≢Empty : ∀ {Γ r l} → Γ ⊢ ℕ ≡ Empty l ^ r → ⊥
ℕ≢Empty ℕ≡Empty =
let ⊢ℕ , ⊢Empty = syntacticEq ℕ≡Empty
e₁ , _ = relevance-unicity ⊢ℕ (univ (ℕⱼ (wfEq ℕ≡Empty)))
e₂ , _ = relevance-unicity ⊢Empty (univ (Emptyⱼ (wfEq ℕ≡Empty)))
in !≢% (PE.trans (PE.sym e₁) e₂)
| {
"alphanum_fraction": 0.5527198212,
"avg_line_length": 52.3707317073,
"ext": "agda",
"hexsha": "7d635e4e25411c610c5cc3871d1c7ecaee1c5dd8",
"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/Typed/Consequences/RelevanceUnicity.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/Typed/Consequences/RelevanceUnicity.agda",
"max_line_length": 125,
"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/Typed/Consequences/RelevanceUnicity.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": 4978,
"size": 10736
} |
------------------------------------------------------------------------
-- Breadth-first labelling of trees
------------------------------------------------------------------------
-- This module just defines breadth-first labelling. For a full
-- development including a specification and proof, see BreadthFirst.
module BreadthFirstWithoutProof where
open import Codata.Musical.Notation
open import Codata.Musical.Stream
open import Data.Product
open import Tree using (Tree; leaf; node)
------------------------------------------------------------------------
-- Universe
data U : Set₁ where
tree : (a : U) → U
stream : (a : U) → U
_⊗_ : (a b : U) → U
⌈_⌉ : (A : Set) → U
El : U → Set
El (tree a) = Tree (El a)
El (stream a) = Stream (El a)
El (a ⊗ b) = El a × El b
El ⌈ A ⌉ = A
------------------------------------------------------------------------
-- Programs
infixr 5 _∷_
infixr 4 _,_
mutual
data ElP : U → Set₁ where
↓ : ∀ {a} (w : ElW a) → ElP a
fst : ∀ {a b} (p : ElP (a ⊗ b)) → ElP a
snd : ∀ {a b} (p : ElP (a ⊗ b)) → ElP b
lab : ∀ {A B} (t : Tree A) (bss : ElP (stream ⌈ Stream B ⌉)) →
ElP (tree ⌈ B ⌉ ⊗ stream ⌈ Stream B ⌉)
-- The term WHNF is a bit of a misnomer here; only recursive
-- /coinductive/ arguments are suspended (in the form of programs).
data ElW : U → Set₁ where
leaf : ∀ {a} → ElW (tree a)
node : ∀ {a}
(l : ∞ (ElP (tree a))) (x : ElW a) (r : ∞ (ElP (tree a))) →
ElW (tree a)
_∷_ : ∀ {a} (x : ElW a) (xs : ∞ (ElP (stream a))) → ElW (stream a)
_,_ : ∀ {a b} (x : ElW a) (y : ElW b) → ElW (a ⊗ b)
⌈_⌉ : ∀ {A} (x : A) → ElW ⌈ A ⌉
fstW : ∀ {a b} → ElW (a ⊗ b) → ElW a
fstW (x , y) = x
sndW : ∀ {a b} → ElW (a ⊗ b) → ElW b
sndW (x , y) = y
-- Uses the n-th stream to label the n-th level in the tree. Returns
-- the remaining stream elements (for every level).
labW : ∀ {A B} → Tree A → ElW (stream ⌈ Stream B ⌉) →
ElW (tree ⌈ B ⌉ ⊗ stream ⌈ Stream B ⌉)
labW leaf bss = (leaf , bss)
labW (node l _ r) (⌈ b ∷ bs ⌉ ∷ bss) =
(node (♯ fst x) ⌈ b ⌉ (♯ fst y) , ⌈ ♭ bs ⌉ ∷ ♯ snd y)
where
x = lab (♭ l) (♭ bss)
y = lab (♭ r) (snd x)
whnf : ∀ {a} → ElP a → ElW a
whnf (↓ w) = w
whnf (fst p) = fstW (whnf p)
whnf (snd p) = sndW (whnf p)
whnf (lab t bss) = labW t (whnf bss)
mutual
⟦_⟧W : ∀ {a} → ElW a → El a
⟦ leaf ⟧W = leaf
⟦ node l x r ⟧W = node (♯ ⟦ ♭ l ⟧P) ⟦ x ⟧W (♯ ⟦ ♭ r ⟧P)
⟦ x ∷ xs ⟧W = ⟦ x ⟧W ∷ ♯ ⟦ ♭ xs ⟧P
⟦ (x , y) ⟧W = (⟦ x ⟧W , ⟦ y ⟧W)
⟦ ⌈ x ⌉ ⟧W = x
⟦_⟧P : ∀ {a} → ElP a → El a
⟦ p ⟧P = ⟦ whnf p ⟧W
------------------------------------------------------------------------
-- Breadth-first labelling
label′ : ∀ {A B} → Tree A → Stream B →
ElP (tree ⌈ B ⌉ ⊗ stream ⌈ Stream B ⌉)
label′ t bs = lab t (↓ (⌈ bs ⌉ ∷ ♯ snd (label′ t bs)))
label : ∀ {A B} → Tree A → Stream B → Tree B
label t bs = ⟦ fst (label′ t bs) ⟧P
| {
"alphanum_fraction": 0.432705249,
"avg_line_length": 28.854368932,
"ext": "agda",
"hexsha": "f683d55ad84eb1710511e4c9232cfc1fe570b739",
"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": "BreadthFirstWithoutProof.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": "BreadthFirstWithoutProof.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": "BreadthFirstWithoutProof.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": 1204,
"size": 2972
} |
module System.IO.Transducers.Properties where
open import System.IO.Transducers.Properties.Category public
open import System.IO.Transducers.Properties.Monoidal public
open import System.IO.Transducers.Properties.LaxBraided public
open import System.IO.Transducers.Properties.Equivalences public
| {
"alphanum_fraction": 0.8686868687,
"avg_line_length": 42.4285714286,
"ext": "agda",
"hexsha": "4ece15dd542a35910489b56ca5e4b27d817a0030",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:23.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-08-10T06:12:54.000Z",
"max_forks_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ilya-fiveisky/agda-system-io",
"max_forks_repo_path": "src/System/IO/Transducers/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "ilya-fiveisky/agda-system-io",
"max_issues_repo_path": "src/System/IO/Transducers/Properties.agda",
"max_line_length": 64,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ilya-fiveisky/agda-system-io",
"max_stars_repo_path": "src/System/IO/Transducers/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-15T04:35:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-04T13:45:16.000Z",
"num_tokens": 56,
"size": 297
} |
{-# OPTIONS --without-K --rewriting #-}
module lib.types.EilenbergMacLane1 where
open import lib.types.EilenbergMacLane1.Core public
open import lib.types.EilenbergMacLane1.Recursion public
open import lib.types.EilenbergMacLane1.DoubleElim public
open import lib.types.EilenbergMacLane1.DoublePathElim public
open import lib.types.EilenbergMacLane1.FunElim public
open import lib.types.EilenbergMacLane1.PathElim public
| {
"alphanum_fraction": 0.8463356974,
"avg_line_length": 38.4545454545,
"ext": "agda",
"hexsha": "779f28da11e9ac1a5c6f631405657cde19fda41a",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "AntoineAllioux/HoTT-Agda",
"max_forks_repo_path": "core/lib/types/EilenbergMacLane1.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "AntoineAllioux/HoTT-Agda",
"max_issues_repo_path": "core/lib/types/EilenbergMacLane1.agda",
"max_line_length": 61,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "AntoineAllioux/HoTT-Agda",
"max_stars_repo_path": "core/lib/types/EilenbergMacLane1.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": 105,
"size": 423
} |
{-# OPTIONS --without-K #-}
module sets.list.core where
open import sum
import sets.vec.core as V
open import sets.nat.core
List : ∀ {i} → Set i → Set i
List A = Σ ℕ (V.Vec A)
module _ {i}{A : Set i} where
vec-to-list : ∀ {n} → V.Vec A n → List A
vec-to-list {n} xs = n , xs
[] : List A
[] = 0 , V.[]
infixr 4 _∷_
_∷_ : A → List A → List A
x ∷ (n , xs) = suc n , x V.∷ xs
| {
"alphanum_fraction": 0.5421994885,
"avg_line_length": 18.619047619,
"ext": "agda",
"hexsha": "fe39b2fa5b396e7defec9bd4345fd5f38b2909c4",
"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/list/core.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/list/core.agda",
"max_line_length": 42,
"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/list/core.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": 158,
"size": 391
} |
-- Andreas, 2013-04-06
-- Interaction point buried in postponed type checking problem
module Issue1083 where
data Bool : Set where true false : Bool
T : Bool → Set
T true = Bool → Bool
T false = Bool
postulate
f : {x : Bool} → T x
test : (x : Bool) → T x
test true = f {!!}
test false = {!!}
-- Constraints show: _10 := (_ : T _x_9) ? : Bool
-- So there is a question mark which has never been seen by the type checker.
-- It is buried in a postponed type-checking problem.
-- Interaction points should probably be created by the scope checker,
-- and then hooked up to meta variables by the type checker.
-- This is how it works now.
| {
"alphanum_fraction": 0.6857585139,
"avg_line_length": 23.9259259259,
"ext": "agda",
"hexsha": "187dd8a19dd8a274457a5e1198e4efa77ba4939d",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/interaction/Issue1083.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/interaction/Issue1083.agda",
"max_line_length": 77,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/interaction/Issue1083.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": 174,
"size": 646
} |
-- Andreas, 2020-05-16, issue #4649
-- Allow --safe flag in -I mode
{-# OPTIONS --safe #-}
data Unit : Set where
unit : Unit
test : Unit
test = {!!}
| {
"alphanum_fraction": 0.5909090909,
"avg_line_length": 14,
"ext": "agda",
"hexsha": "0ffec86606969eb91955fb2e7b3fb06738f77072",
"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/Interactive/Issue1430.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/Interactive/Issue1430.agda",
"max_line_length": 35,
"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/Interactive/Issue1430.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": 50,
"size": 154
} |
data N : Set = zero | suc (n:N)
data B : Set = true | false
data False : Set =
data True : Set = tt
F : B -> Set
F true = N
F false = B
G : (x:B) -> F x -> Set
G false _ = N
G true zero = B
G true (suc n) = N
(==) : B -> B -> Set
true == true = True
false == false = True
_ == _ = False
data Equal (x,y:B) : Set where
equal : x == y -> Equal x y
refl : (x:B) -> Equal x x
refl true = equal tt
refl false = equal tt
postulate
f : (x:B) -> (y : F x) -> G x y -> N -- Equal x true -> N
h : N
h = f _ false zero --(refl true)
| {
"alphanum_fraction": 0.5146520147,
"avg_line_length": 15.6,
"ext": "agda",
"hexsha": "e69f5dc2de7d420cbf8c3aa320489fb64515851c",
"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": "notes/papers/implicit/examples/Dangerous-Agda1.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": "notes/papers/implicit/examples/Dangerous-Agda1.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": "notes/papers/implicit/examples/Dangerous-Agda1.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": 210,
"size": 546
} |
open import Oscar.Prelude
module Oscar.Data.Constraint where
data Constraint {𝔞} {𝔄 : Ø 𝔞} (𝒶 : 𝔄) : Ø₀ where
instance ∅ : Constraint 𝒶
| {
"alphanum_fraction": 0.695035461,
"avg_line_length": 17.625,
"ext": "agda",
"hexsha": "98d5e453f3e7a0ddb36e142794c4737457b3755d",
"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/Data/Constraint.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/Data/Constraint.agda",
"max_line_length": 48,
"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/Data/Constraint.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 52,
"size": 141
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Reverse view
------------------------------------------------------------------------
module Data.List.Reverse where
open import Data.List
open import Data.Nat
import Data.Nat.Properties as Nat
open import Induction.Nat
open import Relation.Binary.PropositionalEquality
-- If you want to traverse a list from the end, then you can use the
-- reverse view of it.
infixl 5 _∶_∶ʳ_
data Reverse {A : Set} : List A → Set where
[] : Reverse []
_∶_∶ʳ_ : ∀ xs (rs : Reverse xs) (x : A) → Reverse (xs ∷ʳ x)
reverseView : ∀ {A} (xs : List A) → Reverse xs
reverseView {A} xs = <-rec Pred rev (length xs) xs refl
where
Pred : ℕ → Set
Pred n = (xs : List A) → length xs ≡ n → Reverse xs
lem : ∀ xs {x : A} → length xs <′ length (xs ∷ʳ x)
lem [] = ≤′-refl
lem (x ∷ xs) = Nat.s≤′s (lem xs)
rev : (n : ℕ) → <-Rec Pred n → Pred n
rev n rec xs eq with initLast xs
rev n rec .[] eq | [] = []
rev .(length (xs ∷ʳ x)) rec .(xs ∷ʳ x) refl | xs ∷ʳ' x
with rec (length xs) (lem xs) xs refl
rev ._ rec .([] ∷ʳ x) refl | ._ ∷ʳ' x | [] = _ ∶ [] ∶ʳ x
rev ._ rec .(ys ∷ʳ y ∷ʳ x) refl | ._ ∷ʳ' x | ys ∶ rs ∶ʳ y =
_ ∶ (_ ∶ rs ∶ʳ y) ∶ʳ x
| {
"alphanum_fraction": 0.4842578711,
"avg_line_length": 31.7619047619,
"ext": "agda",
"hexsha": "1977ce11f672caeb90809a2d215417dee9b2af6c",
"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/Data/List/Reverse.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/Data/List/Reverse.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/Data/List/Reverse.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": 454,
"size": 1334
} |
-- Andreas, 2013-02-21 issue seems to have been fixed along with issue 796
-- {-# OPTIONS -v tc.decl:10 #-}
module Issue4 where
open import Common.Equality
abstract
abstract -- a second abstract seems to have no effect
T : Set -> Set
T A = A
see-through : ∀ {A} → T A ≡ A
see-through = refl
data Ok (A : Set) : Set where
ok : T (Ok A) → Ok A
opaque : ∀ {A} → T A ≡ A
opaque = see-through
data Bad (A : Set) : Set where
bad : T (Bad A) -> Bad A
| {
"alphanum_fraction": 0.6033755274,
"avg_line_length": 18.96,
"ext": "agda",
"hexsha": "b4326e6972533b70aebe0f2633e11b1b58dfd192",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/fail/Issue4.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/fail/Issue4.agda",
"max_line_length": 74,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "test/fail/Issue4.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 158,
"size": 474
} |
-- It is recommended to use Cubical.Algebra.CommRing.Instances.Int
-- instead of this file.
{-# OPTIONS --safe #-}
module Cubical.Algebra.AbGroup.Instances.DiffInt where
open import Cubical.Foundations.Prelude
open import Cubical.HITs.SetQuotients
open import Cubical.Algebra.AbGroup.Base
open import Cubical.Data.Int.MoreInts.DiffInt
renaming (
_+_ to _+ℤ_
)
DiffℤasAbGroup : AbGroup ℓ-zero
DiffℤasAbGroup = makeAbGroup {G = ℤ}
[ (0 , 0) ]
_+ℤ_
-ℤ_
ℤ-isSet
+ℤ-assoc
(λ x → zero-identityʳ 0 x)
(λ x → -ℤ-invʳ x)
+ℤ-comm
| {
"alphanum_fraction": 0.5091623037,
"avg_line_length": 29.3846153846,
"ext": "agda",
"hexsha": "60979c9121a23e05e91a3e416d2d299a99a11751",
"lang": "Agda",
"max_forks_count": 134,
"max_forks_repo_forks_event_max_datetime": "2022-03-23T16:22:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-11-16T06:11:03.000Z",
"max_forks_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Seanpm2001-web/cubical",
"max_forks_repo_path": "Cubical/Algebra/AbGroup/Instances/DiffInt.agda",
"max_issues_count": 584,
"max_issues_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"max_issues_repo_issues_event_max_datetime": "2022-03-30T12:09:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-10-15T09:49:02.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Seanpm2001-web/cubical",
"max_issues_repo_path": "Cubical/Algebra/AbGroup/Instances/DiffInt.agda",
"max_line_length": 66,
"max_stars_count": 301,
"max_stars_repo_head_hexsha": "9acdecfa6437ec455568be4e5ff04849cc2bc13b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "FernandoLarrain/cubical",
"max_stars_repo_path": "Cubical/Algebra/AbGroup/Instances/DiffInt.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-24T02:10:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-17T18:00:24.000Z",
"num_tokens": 193,
"size": 764
} |
{-# OPTIONS --without-K --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Substitution.Introductions.Lambda {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped as U hiding (wk)
open import Definition.Untyped.Properties
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.Typed.Weakening as T hiding (wk; wkTerm; wkEqTerm)
open import Definition.Typed.RedSteps
open import Definition.LogicalRelation
open import Definition.LogicalRelation.ShapeView
open import Definition.LogicalRelation.Irrelevance
open import Definition.LogicalRelation.Weakening
open import Definition.LogicalRelation.Properties
open import Definition.LogicalRelation.Application
open import Definition.LogicalRelation.Substitution
open import Definition.LogicalRelation.Substitution.Properties
open import Definition.LogicalRelation.Substitution.Introductions.Pi
open import Tools.Product
import Tools.PropositionalEquality as PE
-- Valid lambda term construction.
lamᵛ : ∀ {F G t Γ l}
([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ])
([G] : Γ ∙ F ⊩ᵛ⟨ l ⟩ G / ([Γ] ∙″ [F]))
([t] : Γ ∙ F ⊩ᵛ⟨ l ⟩ t ∷ G / [Γ] ∙″ [F] / [G])
→ Γ ⊩ᵛ⟨ l ⟩ lam t ∷ Π F ▹ G / [Γ] / Πᵛ {F} {G} [Γ] [F] [G]
lamᵛ {F} {G} {t} {Γ} {l} [Γ] [F] [G] [t] {Δ = Δ} {σ = σ} ⊢Δ [σ] =
let ⊢F = escape (proj₁ ([F] ⊢Δ [σ]))
[liftσ] = liftSubstS {F = F} [Γ] ⊢Δ [F] [σ]
[ΠFG] = Πᵛ {F} {G} [Γ] [F] [G]
Πᵣ F′ G′ D′ ⊢F′ ⊢G′ A≡A′ [F]′ [G]′ G-ext =
extractMaybeEmbΠ (Π-elim (proj₁ ([ΠFG] ⊢Δ [σ])))
lamt : ∀ {Δ σ} (⊢Δ : ⊢ Δ) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)
→ Δ ⊩⟨ l ⟩ subst σ (lam t) ∷ subst σ (Π F ▹ G) / proj₁ ([ΠFG] ⊢Δ [σ])
lamt {Δ} {σ} ⊢Δ [σ] =
let [liftσ] = liftSubstS {F = F} [Γ] ⊢Δ [F] [σ]
[σF] = proj₁ ([F] ⊢Δ [σ])
⊢F = escape [σF]
⊢wk1F = T.wk (step id) (⊢Δ ∙ ⊢F) ⊢F
[σG] = proj₁ ([G] (⊢Δ ∙ ⊢F) [liftσ])
⊢G = escape [σG]
[σt] = proj₁ ([t] (⊢Δ ∙ ⊢F) [liftσ])
⊢t = escapeTerm [σG] [σt]
wk1t[0] = irrelevanceTerm″
PE.refl
(PE.sym (wkSingleSubstId (subst (liftSubst σ) t)))
[σG] [σG] [σt]
β-red′ = PE.subst (λ x → _ ⊢ _ ⇒ _ ∷ x)
(wkSingleSubstId (subst (liftSubst σ) G))
(β-red ⊢wk1F (T.wkTerm (lift (step id))
(⊢Δ ∙ ⊢F ∙ ⊢wk1F) ⊢t)
(var (⊢Δ ∙ ⊢F) here))
Πᵣ F′ G′ D′ ⊢F′ ⊢G′ A≡A′ [F]′ [G]′ G-ext =
extractMaybeEmbΠ (Π-elim (proj₁ ([ΠFG] ⊢Δ [σ])))
in Πₜ (lam (subst (liftSubst σ) t)) (idRedTerm:*: (lamⱼ ⊢F ⊢t)) lamₙ
(≅-η-eq ⊢F (lamⱼ ⊢F ⊢t) (lamⱼ ⊢F ⊢t) lamₙ lamₙ
(escapeTermEq [σG]
(reflEqTerm [σG]
(proj₁ (redSubstTerm β-red′ [σG] wk1t[0])))))
(λ {_} {Δ₁} {a} {b} ρ ⊢Δ₁ [a] [b] [a≡b] →
let [ρσ] = wkSubstS [Γ] ⊢Δ ⊢Δ₁ ρ [σ]
[a]′ = irrelevanceTerm′ (wk-subst F) ([F]′ ρ ⊢Δ₁)
(proj₁ ([F] ⊢Δ₁ [ρσ])) [a]
[b]′ = irrelevanceTerm′ (wk-subst F) ([F]′ ρ ⊢Δ₁)
(proj₁ ([F] ⊢Δ₁ [ρσ])) [b]
[a≡b]′ = irrelevanceEqTerm′ (wk-subst F) ([F]′ ρ ⊢Δ₁)
(proj₁ ([F] ⊢Δ₁ [ρσ])) [a≡b]
⊢F₁′ = escape (proj₁ ([F] ⊢Δ₁ [ρσ]))
⊢F₁ = escape ([F]′ ρ ⊢Δ₁)
[G]₁ = proj₁ ([G] (⊢Δ₁ ∙ ⊢F₁′)
(liftSubstS {F = F} [Γ] ⊢Δ₁ [F] [ρσ]))
[G]₁′ = irrelevanceΓ′
(PE.cong (λ x → _ ∙ x) (PE.sym (wk-subst F)))
(PE.sym (wk-subst-lift G)) [G]₁
[t]′ = irrelevanceTermΓ″
(PE.cong (λ x → _ ∙ x) (PE.sym (wk-subst F)))
(PE.sym (wk-subst-lift G))
(PE.sym (wk-subst-lift t))
[G]₁ [G]₁′
(proj₁ ([t] (⊢Δ₁ ∙ ⊢F₁′)
(liftSubstS {F = F} [Γ] ⊢Δ₁ [F] [ρσ])))
⊢a = escapeTerm ([F]′ ρ ⊢Δ₁) [a]
⊢b = escapeTerm ([F]′ ρ ⊢Δ₁) [b]
⊢t = escapeTerm [G]₁′ [t]′
G[a]′ = proj₁ ([G] ⊢Δ₁ ([ρσ] , [a]′))
G[a] = [G]′ ρ ⊢Δ₁ [a]
t[a] = irrelevanceTerm″
(PE.sym (singleSubstWkComp a σ G))
(PE.sym (singleSubstWkComp a σ t))
G[a]′ G[a]
(proj₁ ([t] ⊢Δ₁ ([ρσ] , [a]′)))
G[b]′ = proj₁ ([G] ⊢Δ₁ ([ρσ] , [b]′))
G[b] = [G]′ ρ ⊢Δ₁ [b]
t[b] = irrelevanceTerm″
(PE.sym (singleSubstWkComp b σ G))
(PE.sym (singleSubstWkComp b σ t))
G[b]′ G[b]
(proj₁ ([t] ⊢Δ₁ ([ρσ] , [b]′)))
lamt∘a≡t[a] = proj₂ (redSubstTerm (β-red ⊢F₁ ⊢t ⊢a) G[a] t[a])
G[a]≡G[b] = G-ext ρ ⊢Δ₁ [a] [b] [a≡b]
t[a]≡t[b] = irrelevanceEqTerm″
(PE.sym (singleSubstWkComp a σ t))
(PE.sym (singleSubstWkComp b σ t))
(PE.sym (singleSubstWkComp a σ G))
G[a]′ G[a]
(proj₂ ([t] ⊢Δ₁ ([ρσ] , [a]′)) ([ρσ] , [b]′)
(reflSubst [Γ] ⊢Δ₁ [ρσ] , [a≡b]′))
t[b]≡lamt∘b =
convEqTerm₂ G[a] G[b] G[a]≡G[b]
(symEqTerm G[b] (proj₂ (redSubstTerm (β-red ⊢F₁ ⊢t ⊢b)
G[b] t[b])))
in transEqTerm G[a] lamt∘a≡t[a]
(transEqTerm G[a] t[a]≡t[b] t[b]≡lamt∘b))
(λ {_} {Δ₁} {a} ρ ⊢Δ₁ [a] →
let [ρσ] = wkSubstS [Γ] ⊢Δ ⊢Δ₁ ρ [σ]
[a]′ = irrelevanceTerm′ (wk-subst F) ([F]′ ρ ⊢Δ₁)
(proj₁ ([F] ⊢Δ₁ [ρσ])) [a]
⊢F₁′ = escape (proj₁ ([F] ⊢Δ₁ [ρσ]))
⊢F₁ = escape ([F]′ ρ ⊢Δ₁)
[G]₁ = proj₁ ([G] (⊢Δ₁ ∙ ⊢F₁′)
(liftSubstS {F = F} [Γ] ⊢Δ₁ [F] [ρσ]))
[G]₁′ = irrelevanceΓ′
(PE.cong (λ x → _ ∙ x) (PE.sym (wk-subst F)))
(PE.sym (wk-subst-lift G)) [G]₁
[t]′ = irrelevanceTermΓ″
(PE.cong (λ x → _ ∙ x) (PE.sym (wk-subst F)))
(PE.sym (wk-subst-lift G))
(PE.sym (wk-subst-lift t))
[G]₁ [G]₁′
(proj₁ ([t] (⊢Δ₁ ∙ ⊢F₁′)
(liftSubstS {F = F} [Γ] ⊢Δ₁ [F] [ρσ])))
⊢a = escapeTerm ([F]′ ρ ⊢Δ₁) [a]
⊢t = escapeTerm [G]₁′ [t]′
G[a]′ = proj₁ ([G] ⊢Δ₁ ([ρσ] , [a]′))
G[a] = [G]′ ρ ⊢Δ₁ [a]
t[a] = irrelevanceTerm″ (PE.sym (singleSubstWkComp a σ G))
(PE.sym (singleSubstWkComp a σ t))
G[a]′ G[a]
(proj₁ ([t] ⊢Δ₁ ([ρσ] , [a]′)))
in proj₁ (redSubstTerm (β-red ⊢F₁ ⊢t ⊢a) G[a] t[a]))
in lamt ⊢Δ [σ]
, (λ {σ′} [σ′] [σ≡σ′] →
let [liftσ′] = liftSubstS {F = F} [Γ] ⊢Δ [F] [σ′]
Πᵣ F″ G″ D″ ⊢F″ ⊢G″ A≡A″ [F]″ [G]″ G-ext′ =
extractMaybeEmbΠ (Π-elim (proj₁ ([ΠFG] ⊢Δ [σ′])))
⊢F′ = escape (proj₁ ([F] ⊢Δ [σ′]))
[G]₁ = proj₁ ([G] (⊢Δ ∙ ⊢F) [liftσ])
[G]₁′ = proj₁ ([G] (⊢Δ ∙ ⊢F′) [liftσ′])
[σΠFG≡σ′ΠFG] = proj₂ ([ΠFG] ⊢Δ [σ]) [σ′] [σ≡σ′]
⊢t = escapeTerm [G]₁ (proj₁ ([t] (⊢Δ ∙ ⊢F) [liftσ]))
⊢t′ = escapeTerm [G]₁′ (proj₁ ([t] (⊢Δ ∙ ⊢F′) [liftσ′]))
neuVar = neuTerm ([F]′ (step id) (⊢Δ ∙ ⊢F))
(var 0) (var (⊢Δ ∙ ⊢F) here)
(~-var (var (⊢Δ ∙ ⊢F) here))
σlamt∘a≡σ′lamt∘a : ∀ {ρ Δ₁ a} → ([ρ] : ρ ∷ Δ₁ ⊆ Δ) (⊢Δ₁ : ⊢ Δ₁)
→ ([a] : Δ₁ ⊩⟨ l ⟩ a ∷ U.wk ρ (subst σ F) / [F]′ [ρ] ⊢Δ₁)
→ Δ₁ ⊩⟨ l ⟩ U.wk ρ (subst σ (lam t)) ∘ a
≡ U.wk ρ (subst σ′ (lam t)) ∘ a
∷ U.wk (lift ρ) (subst (liftSubst σ) G) [ a ]
/ [G]′ [ρ] ⊢Δ₁ [a]
σlamt∘a≡σ′lamt∘a {_} {Δ₁} {a} ρ ⊢Δ₁ [a] =
let [ρσ] = wkSubstS [Γ] ⊢Δ ⊢Δ₁ ρ [σ]
[ρσ′] = wkSubstS [Γ] ⊢Δ ⊢Δ₁ ρ [σ′]
[ρσ≡ρσ′] = wkSubstSEq [Γ] ⊢Δ ⊢Δ₁ ρ [σ] [σ≡σ′]
⊢F₁′ = escape (proj₁ ([F] ⊢Δ₁ [ρσ]))
⊢F₁ = escape ([F]′ ρ ⊢Δ₁)
⊢F₂′ = escape (proj₁ ([F] ⊢Δ₁ [ρσ′]))
⊢F₂ = escape ([F]″ ρ ⊢Δ₁)
[σF≡σ′F] = proj₂ ([F] ⊢Δ₁ [ρσ]) [ρσ′] [ρσ≡ρσ′]
[a]′ = irrelevanceTerm′ (wk-subst F) ([F]′ ρ ⊢Δ₁)
(proj₁ ([F] ⊢Δ₁ [ρσ])) [a]
[a]″ = convTerm₁ (proj₁ ([F] ⊢Δ₁ [ρσ]))
(proj₁ ([F] ⊢Δ₁ [ρσ′]))
[σF≡σ′F] [a]′
⊢a = escapeTerm ([F]′ ρ ⊢Δ₁) [a]
⊢a′ = escapeTerm ([F]″ ρ ⊢Δ₁)
(irrelevanceTerm′ (PE.sym (wk-subst F))
(proj₁ ([F] ⊢Δ₁ [ρσ′]))
([F]″ ρ ⊢Δ₁)
[a]″)
G[a]′ = proj₁ ([G] ⊢Δ₁ ([ρσ] , [a]′))
G[a]₁′ = proj₁ ([G] ⊢Δ₁ ([ρσ′] , [a]″))
G[a] = [G]′ ρ ⊢Δ₁ [a]
G[a]″ = [G]″ ρ ⊢Δ₁
(irrelevanceTerm′ (PE.sym (wk-subst F))
(proj₁ ([F] ⊢Δ₁ [ρσ′]))
([F]″ ρ ⊢Δ₁)
[a]″)
[σG[a]≡σ′G[a]] = irrelevanceEq″
(PE.sym (singleSubstWkComp a σ G))
(PE.sym (singleSubstWkComp a σ′ G))
G[a]′ G[a]
(proj₂ ([G] ⊢Δ₁ ([ρσ] , [a]′))
([ρσ′] , [a]″)
(consSubstSEq {t = a} {A = F}
[Γ] ⊢Δ₁ [ρσ] [ρσ≡ρσ′] [F] [a]′))
[G]₁ = proj₁ ([G] (⊢Δ₁ ∙ ⊢F₁′)
(liftSubstS {F = F} [Γ] ⊢Δ₁ [F] [ρσ]))
[G]₁′ = irrelevanceΓ′
(PE.cong (λ x → _ ∙ x) (PE.sym (wk-subst F)))
(PE.sym (wk-subst-lift G)) [G]₁
[G]₂ = proj₁ ([G] (⊢Δ₁ ∙ ⊢F₂′)
(liftSubstS {F = F} [Γ] ⊢Δ₁ [F] [ρσ′]))
[G]₂′ = irrelevanceΓ′
(PE.cong (λ x → _ ∙ x) (PE.sym (wk-subst F)))
(PE.sym (wk-subst-lift G)) [G]₂
[t]′ = irrelevanceTermΓ″
(PE.cong (λ x → _ ∙ x) (PE.sym (wk-subst F)))
(PE.sym (wk-subst-lift G)) (PE.sym (wk-subst-lift t))
[G]₁ [G]₁′
(proj₁ ([t] (⊢Δ₁ ∙ ⊢F₁′)
(liftSubstS {F = F} [Γ] ⊢Δ₁ [F] [ρσ])))
[t]″ = irrelevanceTermΓ″
(PE.cong (λ x → _ ∙ x) (PE.sym (wk-subst F)))
(PE.sym (wk-subst-lift G)) (PE.sym (wk-subst-lift t))
[G]₂ [G]₂′
(proj₁ ([t] (⊢Δ₁ ∙ ⊢F₂′)
(liftSubstS {F = F} [Γ] ⊢Δ₁ [F] [ρσ′])))
⊢t = escapeTerm [G]₁′ [t]′
⊢t′ = escapeTerm [G]₂′ [t]″
t[a] = irrelevanceTerm″
(PE.sym (singleSubstWkComp a σ G))
(PE.sym (singleSubstWkComp a σ t)) G[a]′ G[a]
(proj₁ ([t] ⊢Δ₁ ([ρσ] , [a]′)))
t[a]′ = irrelevanceTerm″
(PE.sym (singleSubstWkComp a σ′ G))
(PE.sym (singleSubstWkComp a σ′ t))
G[a]₁′ G[a]″
(proj₁ ([t] ⊢Δ₁ ([ρσ′] , [a]″)))
[σlamt∘a≡σt[a]] = proj₂ (redSubstTerm (β-red ⊢F₁ ⊢t ⊢a)
G[a] t[a])
[σ′t[a]≡σ′lamt∘a] =
convEqTerm₂ G[a] G[a]″ [σG[a]≡σ′G[a]]
(symEqTerm G[a]″
(proj₂ (redSubstTerm (β-red ⊢F₂ ⊢t′ ⊢a′)
G[a]″ t[a]′)))
[σt[a]≡σ′t[a]] = irrelevanceEqTerm″
(PE.sym (singleSubstWkComp a σ t))
(PE.sym (singleSubstWkComp a σ′ t))
(PE.sym (singleSubstWkComp a σ G))
G[a]′ G[a]
(proj₂ ([t] ⊢Δ₁ ([ρσ] , [a]′))
([ρσ′] , [a]″)
(consSubstSEq {t = a} {A = F}
[Γ] ⊢Δ₁ [ρσ] [ρσ≡ρσ′] [F] [a]′))
in transEqTerm G[a] [σlamt∘a≡σt[a]]
(transEqTerm G[a] [σt[a]≡σ′t[a]]
[σ′t[a]≡σ′lamt∘a])
in Πₜ₌ (lam (subst (liftSubst σ) t)) (lam (subst (liftSubst σ′) t))
(idRedTerm:*: (lamⱼ ⊢F ⊢t))
(idRedTerm:*: (conv (lamⱼ ⊢F′ ⊢t′)
(sym (≅-eq (escapeEq (proj₁ ([ΠFG] ⊢Δ [σ]))
[σΠFG≡σ′ΠFG])))))
lamₙ lamₙ
(≅-η-eq ⊢F (lamⱼ ⊢F ⊢t)
(conv (lamⱼ ⊢F′ ⊢t′)
(sym (≅-eq (escapeEq (proj₁ ([ΠFG] ⊢Δ [σ]))
[σΠFG≡σ′ΠFG]))))
lamₙ lamₙ
(escapeTermEq
(proj₁ ([G] (⊢Δ ∙ ⊢F) [liftσ]))
(irrelevanceEqTerm′
(idWkLiftSubstLemma σ G)
([G]′ (step id) (⊢Δ ∙ ⊢F) neuVar)
(proj₁ ([G] (⊢Δ ∙ ⊢F) [liftσ]))
(σlamt∘a≡σ′lamt∘a (step id) (⊢Δ ∙ ⊢F) neuVar))))
(lamt ⊢Δ [σ])
(convTerm₂ (proj₁ ([ΠFG] ⊢Δ [σ]))
(proj₁ ([ΠFG] ⊢Δ [σ′]))
[σΠFG≡σ′ΠFG]
(lamt ⊢Δ [σ′]))
σlamt∘a≡σ′lamt∘a)
-- Reducibility of η-equality under a valid substitution.
η-eqEqTerm : ∀ {f g F G Γ Δ σ l}
([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ])
([G] : Γ ∙ F ⊩ᵛ⟨ l ⟩ G / ([Γ] ∙″ [F]))
→ let [ΠFG] = Πᵛ {F} {G} [Γ] [F] [G] in
Γ ∙ F ⊩ᵛ⟨ l ⟩ wk1 f ∘ var 0 ≡ wk1 g ∘ var 0 ∷ G
/ [Γ] ∙″ [F] / [G]
→ (⊢Δ : ⊢ Δ)
([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)
→ Δ ⊩⟨ l ⟩ subst σ f ∷ Π subst σ F ▹ subst (liftSubst σ) G
/ proj₁ ([ΠFG] ⊢Δ [σ])
→ Δ ⊩⟨ l ⟩ subst σ g ∷ Π subst σ F ▹ subst (liftSubst σ) G
/ proj₁ ([ΠFG] ⊢Δ [σ])
→ Δ ⊩⟨ l ⟩ subst σ f ≡ subst σ g ∷ Π subst σ F ▹ subst (liftSubst σ) G
/ proj₁ ([ΠFG] ⊢Δ [σ])
η-eqEqTerm {f} {g} {F} {G} {Γ} {Δ} {σ} [Γ] [F] [G] [f0≡g0] ⊢Δ [σ]
(Πₜ f₁ [ ⊢t , ⊢u , d ] funcF f≡f [f] [f]₁)
(Πₜ g₁ [ ⊢t₁ , ⊢u₁ , d₁ ] funcG g≡g [g] [g]₁) =
let [d] = [ ⊢t , ⊢u , d ]
[d′] = [ ⊢t₁ , ⊢u₁ , d₁ ]
[ΠFG] = Πᵛ {F} {G} [Γ] [F] [G]
[σΠFG] = proj₁ ([ΠFG] ⊢Δ [σ])
Πᵣ F′ G′ D′ ⊢F ⊢G A≡A [F]′ [G]′ G-ext = extractMaybeEmbΠ (Π-elim [σΠFG])
[σF] = proj₁ ([F] ⊢Δ [σ])
[wk1F] = wk (step id) (⊢Δ ∙ ⊢F) [σF]
var0′ = var (⊢Δ ∙ ⊢F) here
var0 = neuTerm [wk1F] (var 0) var0′ (~-var var0′)
var0≡0 = neuEqTerm [wk1F] (var 0) (var 0) var0′ var0′ (~-var var0′)
[σG]′ = [G]′ (step id) (⊢Δ ∙ ⊢F) var0
[σG] = proj₁ ([G] (⊢Δ ∙ ⊢F) (liftSubstS {F = F} [Γ] ⊢Δ [F] [σ]))
σf0≡σg0 = escapeTermEq [σG]
([f0≡g0] (⊢Δ ∙ ⊢F)
(liftSubstS {F = F} [Γ] ⊢Δ [F] [σ]))
σf0≡σg0′ =
PE.subst₂
(λ x y → Δ ∙ subst σ F ⊢ x ≅ y ∷ subst (liftSubst σ) G)
(PE.cong₂ _∘_ (PE.trans (subst-wk f) (PE.sym (wk-subst f))) PE.refl)
(PE.cong₂ _∘_ (PE.trans (subst-wk g) (PE.sym (wk-subst g))) PE.refl)
σf0≡σg0
⊢ΠFG = escape [σΠFG]
f≡f₁′ = proj₂ (redSubst*Term d [σΠFG] (Πₜ f₁ (idRedTerm:*: ⊢u) funcF f≡f [f] [f]₁))
g≡g₁′ = proj₂ (redSubst*Term d₁ [σΠFG] (Πₜ g₁ (idRedTerm:*: ⊢u₁) funcG g≡g [g] [g]₁))
eq′ = irrelevanceEqTerm′ (cons0wkLift1-id σ G) [σG]′ [σG]
(app-congTerm [wk1F] [σG]′ (wk (step id) (⊢Δ ∙ ⊢F) [σΠFG])
(wkEqTerm (step id) (⊢Δ ∙ ⊢F) [σΠFG] f≡f₁′) var0 var0 var0≡0)
eq₁′ = irrelevanceEqTerm′ (cons0wkLift1-id σ G) [σG]′ [σG]
(app-congTerm [wk1F] [σG]′ (wk (step id) (⊢Δ ∙ ⊢F) [σΠFG])
(wkEqTerm (step id) (⊢Δ ∙ ⊢F) [σΠFG] g≡g₁′) var0 var0 var0≡0)
eq = escapeTermEq [σG] eq′
eq₁ = escapeTermEq [σG] eq₁′
in Πₜ₌ f₁ g₁ [d] [d′] funcF funcG
(≅-η-eq ⊢F ⊢u ⊢u₁ funcF funcG
(≅ₜ-trans (≅ₜ-sym eq) (≅ₜ-trans σf0≡σg0′ eq₁)))
(Πₜ f₁ [d] funcF f≡f [f] [f]₁)
(Πₜ g₁ [d′] funcG g≡g [g] [g]₁)
(λ {ρ} {Δ₁} {a} [ρ] ⊢Δ₁ [a] →
let [F]″ = proj₁ ([F] ⊢Δ₁ (wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ]))
[a]′ = irrelevanceTerm′
(wk-subst F) ([F]′ [ρ] ⊢Δ₁)
[F]″ [a]
fEq = PE.cong₂ _∘_ (PE.trans (subst-wk f) (PE.sym (wk-subst f))) PE.refl
gEq = PE.cong₂ _∘_ (PE.trans (subst-wk g) (PE.sym (wk-subst g))) PE.refl
GEq = PE.sym (PE.trans (subst-wk (subst (liftSubst σ) G))
(PE.trans (substCompEq G)
(cons-wk-subst ρ σ a G)))
f≡g = irrelevanceEqTerm″ fEq gEq GEq
(proj₁ ([G] ⊢Δ₁ (wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ] , [a]′)))
([G]′ [ρ] ⊢Δ₁ [a])
([f0≡g0] ⊢Δ₁ (wkSubstS [Γ] ⊢Δ ⊢Δ₁ [ρ] [σ] , [a]′))
[ρσΠFG] = wk [ρ] ⊢Δ₁ [σΠFG]
[f]′ : Δ ⊩⟨ _ ⟩ f₁ ∷ Π F′ ▹ G′ / [σΠFG]
[f]′ = Πₜ f₁ (idRedTerm:*: ⊢u) funcF f≡f [f] [f]₁
[ρf]′ = wkTerm [ρ] ⊢Δ₁ [σΠFG] [f]′
[g]′ : Δ ⊩⟨ _ ⟩ g₁ ∷ Π F′ ▹ G′ / [σΠFG]
[g]′ = Πₜ g₁ (idRedTerm:*: ⊢u₁) funcG g≡g [g] [g]₁
[ρg]′ = wkTerm [ρ] ⊢Δ₁ [σΠFG] [g]′
[f∘u] = appTerm ([F]′ [ρ] ⊢Δ₁) ([G]′ [ρ] ⊢Δ₁ [a]) [ρσΠFG] [ρf]′ [a]
[g∘u] = appTerm ([F]′ [ρ] ⊢Δ₁) ([G]′ [ρ] ⊢Δ₁ [a]) [ρσΠFG] [ρg]′ [a]
[tu≡fu] = proj₂ (redSubst*Term (app-subst* (wkRed*Term [ρ] ⊢Δ₁ d)
(escapeTerm ([F]′ [ρ] ⊢Δ₁) [a]))
([G]′ [ρ] ⊢Δ₁ [a]) [f∘u])
[gu≡t′u] = proj₂ (redSubst*Term (app-subst* (wkRed*Term [ρ] ⊢Δ₁ d₁)
(escapeTerm ([F]′ [ρ] ⊢Δ₁) [a]))
([G]′ [ρ] ⊢Δ₁ [a]) [g∘u])
in transEqTerm ([G]′ [ρ] ⊢Δ₁ [a]) (symEqTerm ([G]′ [ρ] ⊢Δ₁ [a]) [tu≡fu])
(transEqTerm ([G]′ [ρ] ⊢Δ₁ [a]) f≡g [gu≡t′u]))
-- Validity of η-equality.
η-eqᵛ : ∀ {f g F G Γ l}
([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ])
([G] : Γ ∙ F ⊩ᵛ⟨ l ⟩ G / ([Γ] ∙″ [F]))
→ let [ΠFG] = Πᵛ {F} {G} [Γ] [F] [G] in
Γ ⊩ᵛ⟨ l ⟩ f ∷ Π F ▹ G / [Γ] / [ΠFG]
→ Γ ⊩ᵛ⟨ l ⟩ g ∷ Π F ▹ G / [Γ] / [ΠFG]
→ Γ ∙ F ⊩ᵛ⟨ l ⟩ wk1 f ∘ var 0 ≡ wk1 g ∘ var 0 ∷ G
/ [Γ] ∙″ [F] / [G]
→ Γ ⊩ᵛ⟨ l ⟩ f ≡ g ∷ Π F ▹ G / [Γ] / [ΠFG]
η-eqᵛ {f} {g} {F} {G} [Γ] [F] [G] [f] [g] [f0≡g0] {Δ} {σ} ⊢Δ [σ] =
η-eqEqTerm {f} {g} {F} {G} [Γ] [F] [G] [f0≡g0] ⊢Δ [σ]
(proj₁ ([f] ⊢Δ [σ])) (proj₁ ([g] ⊢Δ [σ]))
| {
"alphanum_fraction": 0.3265467025,
"avg_line_length": 56.0051948052,
"ext": "agda",
"hexsha": "33b705d853e3184a62e951e12ac11a880cde15d9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "loic-p/logrel-mltt",
"max_forks_repo_path": "Definition/LogicalRelation/Substitution/Introductions/Lambda.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "loic-p/logrel-mltt",
"max_issues_repo_path": "Definition/LogicalRelation/Substitution/Introductions/Lambda.agda",
"max_line_length": 107,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "loic-p/logrel-mltt",
"max_stars_repo_path": "Definition/LogicalRelation/Substitution/Introductions/Lambda.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 8381,
"size": 21562
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.