Search is not available for this dataset
text
string | meta
dict |
---|---|
module ShouldBeAppliedToTheDatatypeParameters where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
mutual
F : Nat -> Set
F zero = Nat
F (suc n) = Foo (F n)
data Foo (A : Set) : Set where
fooI1 : F (suc zero)
| {
"alphanum_fraction": 0.6059322034,
"avg_line_length": 13.8823529412,
"ext": "agda",
"hexsha": "1b54f51a54bb32fd24859e83e93c93f68e5fbd61",
"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/ShouldBeAppliedToTheDatatypeParameters.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/ShouldBeAppliedToTheDatatypeParameters.agda",
"max_line_length": 51,
"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/ShouldBeAppliedToTheDatatypeParameters.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": 84,
"size": 236
} |
record ⊤ : Set where constructor tt
data ⊥ : Set where
open import Agda.Builtin.Size
record Delay (F : Size → Set) (i : Size) : Set where
coinductive
field force : {j : Size< i} → F j
open Delay public
data Stream (A : Set) (i : Size) : Set where
_∷_ : A → Delay (Stream A) i → Stream A i
concat : Stream ⊤ ∞ → Delay (Stream ⊥) ∞
concat (xs ∷ xss) = concat (force xss)
head : Stream ⊥ ∞ → ⊥
head (x ∷ xs) = x
units : ∀ {i} → Stream ⊤ i
units = tt ∷ λ where .force → units
false : ⊥
false = head (force (concat units))
| {
"alphanum_fraction": 0.6082862524,
"avg_line_length": 20.4230769231,
"ext": "agda",
"hexsha": "62417ef84e7c1a335fefcd587c2cfcb0b959953b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue2941.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/Fail/Issue2941.agda",
"max_line_length": 52,
"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/Fail/Issue2941.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": 192,
"size": 531
} |
-- Andreas, 2015-07-01 polarity needs to be computed for abstract defs.
-- See also issue 1599 for the same problem with positivity.
-- {-# OPTIONS -v tc.pos:10 -v tc.polarity:20 #-}
open import Common.Size
open import Common.Prelude
data D (i : Size) : Set where
c : ∀ (j : Size< i) → D i
abstract
E : Bool → Size → Set
E true i = D i
E false i = D i
cast : ∀{i b} → E b i → E b (↑ i)
cast x = x
-- should succeed
| {
"alphanum_fraction": 0.6175115207,
"avg_line_length": 20.6666666667,
"ext": "agda",
"hexsha": "e39cbad35b9d71a48feaee9f4b1380b9b226a762",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/PolarityAbstract.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/PolarityAbstract.agda",
"max_line_length": 71,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/PolarityAbstract.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": 145,
"size": 434
} |
module List.Permutation.Pair.Properties (A : Set) where
open import List.Permutation.Base A
open import List.Permutation.Base.Concatenation A
open import List.Permutation.Base.Equivalence A
open import List.Permutation.Base.Preorder A
open import List.Permutation.Pair A
open import Data.List
open import Data.Product
open import Relation.Binary.PreorderReasoning ∼-preorder
open import Algebra
open import Algebra.Structures
lemma≈∼ : {xs ys zs : List A} → xs ≈ (ys , zs) → xs ∼ (ys ++ zs)
lemma≈∼ (≈[]l zs) = refl∼
lemma≈∼ (≈[]r ys) rewrite ((proj₂ (IsMonoid.identity (Monoid.isMonoid (monoid A)))) ys) = refl∼
lemma≈∼ (≈xr {ys = ys} xs∼ys,zs') = ∼x /head (lemma++/l {xs = ys} /head) (lemma≈∼ xs∼ys,zs')
lemma≈∼ (≈xl xs∼ys',zs) = ∼x /head /head (lemma≈∼ xs∼ys',zs)
lemma≈ : {xs ys zs ws ys' zs' : List A} → xs ≈ (ys , zs) → ys ∼ ys' → zs ∼ zs' → ws ≈ (ys' , zs') → xs ∼ ws
lemma≈ {xs} {ys} {zs} {ws} {ys'} {zs'} xs∼ys,zs ys∼ys' zs∼zs' ws∼ys',zs'
= begin
xs
∼⟨ lemma≈∼ xs∼ys,zs ⟩
ys ++ zs
∼⟨ lemma++∼ ys∼ys' zs∼zs' ⟩
ys' ++ zs'
∼⟨ sym∼ (lemma≈∼ ws∼ys',zs') ⟩
ws
∎
| {
"alphanum_fraction": 0.5966608084,
"avg_line_length": 36.7096774194,
"ext": "agda",
"hexsha": "c40129b35cfef720c353ca69f92f5deb8c02a0ec",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bgbianchi/sorting",
"max_forks_repo_path": "agda/List/Permutation/Pair/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bgbianchi/sorting",
"max_issues_repo_path": "agda/List/Permutation/Pair/Properties.agda",
"max_line_length": 107,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bgbianchi/sorting",
"max_stars_repo_path": "agda/List/Permutation/Pair/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z",
"num_tokens": 474,
"size": 1138
} |
{-# OPTIONS --allow-unsolved-metas #-}
module _ where
open import Agda.Builtin.Bool
postulate
P : Set → Set
record R : Set1 where
constructor con
field
A : Set
B : Set
data D : Set1 where
con : Set → Set → D
snd : D → Set
snd (con A B) = B
-- Eliminating from an under-applied constructor shouldn't result in a
-- crash.
F : Bool → Set₁
F = {!!}
bar : let x : F true; x = R.con Bool in P (x .R.B)
bar = {!!} -- P (con Bool .R.B)
bar2 : let x : F true; x = D.con Bool in P (snd x)
bar2 = {!!} -- P (snd (con Bool))
-- These still show meta numbers because they refer to blocked
-- typechecking problems.
-- Reify could try harder to look at meta instantiations.
bar3 : let x : F true; x = D.con Bool in P (snd (x x))
bar3 = {!!} -- P (snd _23)
bar4 : let x : F true; x = (x : Bool) → Bool in P (x true)
bar4 = {!!} -- P _32
| {
"alphanum_fraction": 0.6023529412,
"avg_line_length": 20.7317073171,
"ext": "agda",
"hexsha": "90791ac64b18525785db46b695dea0f33806c46e",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "hborum/agda",
"max_forks_repo_path": "test/Succeed/UnderappliedConstructor.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "hborum/agda",
"max_issues_repo_path": "test/Succeed/UnderappliedConstructor.agda",
"max_line_length": 70,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/Succeed/UnderappliedConstructor.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": 281,
"size": 850
} |
{-# OPTIONS --without-K --erased-cubical --no-import-sorts #-}
module Soundness where
open import Prelude
open import Instruments
open import MakeTracks using (makeTrackList)
open import Motif using (motif; levels)
open import SUtil
----------------
macro
getDef : Name → Term → TC ⊤
getDef n h = do
d ← getDefinition n
t ← quoteTC d
unify h t
record Line : Type where
constructor line
field
lhs : List Name
rhs : List Name
open Line
Proof : Type
Proof = List Line
-- Get only visible constructor names
getNamesP : List (Arg Pattern) → List Name
getNamesP [] = []
getNamesP (arg (arg-info v m) (Pattern.dot t) ∷ ps) = getNamesP ps
getNamesP (arg (arg-info v m) (Pattern.var x₁) ∷ ps) = getNamesP ps
getNamesP (arg (arg-info v m) (Pattern.lit l) ∷ ps) = getNamesP ps
getNamesP (arg (arg-info v m) (Pattern.proj f) ∷ ps) = getNamesP ps
getNamesP (arg (arg-info v m) (Pattern.absurd x₁) ∷ ps) = getNamesP ps
getNamesP (arg (arg-info hidden m) (Pattern.con n _) ∷ ps) = getNamesP ps
getNamesP (arg (arg-info instance′ m) (Pattern.con n _) ∷ ps) = getNamesP ps
getNamesP (arg (arg-info visible m) (Pattern.con n _) ∷ ps) = n ∷ getNamesP ps
{-# TERMINATING #-}
getNamesT : Term → List Name
getNamesAT : Arg Term → List Name
getNamesT (con n args) = n ∷ concatMap getNamesAT args
getNamesT (def n args) = n ∷ concatMap getNamesAT args
getNamesT (var x₁ args) = concatMap getNamesAT args
getNamesT (pat-lam cs args) = concatMap getNamesAT args
getNamesT (lam v t) = []
getNamesT (pi a b) = []
getNamesT (agda-sort s) = []
getNamesT (lit l) = []
getNamesT (meta x₁ x₂) = []
getNamesT unknown = []
getNamesAT (arg i t) = getNamesT t
getNamesC : Clause → Line
getNamesC (Clause.clause tel ps t) = line (getNamesP ps) (getNamesT t)
getNamesC (Clause.absurd-clause tel ps) = line (getNamesP ps) []
getNamesD : Definition → List Line
getNamesD (function cs) = map getNamesC cs
getNamesD (data-type pars cs) = []
getNamesD (record-type c fs) = []
getNamesD (data-cons d) = []
getNamesD axiom = []
getNamesD prim-fun = []
----------------
data TopLevel : Type where
s↑ : TopLevel
s↓ : TopLevel
sc↑ : TopLevel
sc↓ : TopLevel
sct↑ : TopLevel
sct↓ : TopLevel
topLevelName : TopLevel → Name
topLevelName s↑ = quote soundness~↑
topLevelName s↓ = quote soundness~↓
topLevelName sc↑ = quote soundnessConv↑
topLevelName sc↓ = quote soundnessConv↓
topLevelName sct↑ = quote soundnessConv↑Term
topLevelName sct↓ = quote soundnessConv↓Term
isTopLevel : Name → Maybe TopLevel
isTopLevel n =
if n == quote soundness~↑ then just s↑
else if n == quote soundness~↓ then just s↓
else if n == quote soundnessConv↑ then just sc↑
else if n == quote soundnessConv↓ then just sc↓
else if n == quote soundnessConv↑Term then just sct↑
else if n == quote soundnessConv↓Term then just sct↓
else nothing
topLevelDef : TopLevel → Definition
topLevelDef s↑ = getDef soundness~↑
topLevelDef s↓ = getDef soundness~↓
topLevelDef sc↑ = getDef soundnessConv↑
topLevelDef sc↓ = getDef soundnessConv↓
topLevelDef sct↑ = getDef soundnessConv↑Term
topLevelDef sct↓ = getDef soundnessConv↓Term
topLevelProof : TopLevel → Proof
topLevelProof = getNamesD ∘ topLevelDef
---------------
-- Number of tracks to create
tracks : ℕ
tracks = 4
{-# TERMINATING #-}
-- First argument n is current level (0 is bottom level; no recursive calls allowed)
-- Second argument m is exponent for doubling speed (2^m)
proof→notes : ℕ → ℕ → TopLevel → List (List Note)
line→notes : ℕ → ℕ → Line → List (List Note)
names→notes : ℕ → ℕ → List Name → List (List Note)
-- starts with proof name
proof→notes n m t =
zipFull (2ⁿSpeed m (motif (topLevelName t)) ∷ [])
(concatMap (line→notes n m) (topLevelProof t))
-- just use rhs for now
line→notes n m (line lhs rhs) = names→notes n m rhs
names→notes _ m [] = [] ∷ []
names→notes zero m ns@(_ ∷ _) = 2ⁿSpeed m (concatMap motif ns) ∷ []
names→notes (suc k) m (n ∷ ns) with isTopLevel n
... | just t = proof→notes k (suc m) t ++ names→notes (suc k) m ns
... | nothing = (2ⁿSpeed m (motif n) ∷ []) ++ names→notes (suc k) m ns
proof→notesTop : ℕ → TopLevel → List (List Note)
proof→notesTop level = proof→notes level 0
---------------
instruments : Vec InstrumentNumber-1 maxChannels
instruments =
drawbarOrgan ∷ -- 1
piano ∷ -- 2
electricPiano1 ∷ -- 3
churchOrgan ∷ -- 4
piano ∷ -- 5
piano ∷ -- 6
piano ∷ -- 7
piano ∷ -- 8
piano ∷ -- 9
drums ∷ -- 10 (percussion)
piano ∷ -- 11
piano ∷ -- 12
piano ∷ -- 13
piano ∷ -- 14
piano ∷ -- 15
piano ∷ -- 16
[]
music : Vec (List Note) tracks
music = foldIntoVector (proof→notesTop levels s↑)
tempo : ℕ
tempo = 160
soundTracks : List MidiTrack
soundTracks = makeTrackList instruments tempo music
| {
"alphanum_fraction": 0.6486815416,
"avg_line_length": 28.8304093567,
"ext": "agda",
"hexsha": "2f201525dcde7a91c5b74009ca20c89911322162",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-11-10T04:05:31.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-11-10T04:05:31.000Z",
"max_forks_repo_head_hexsha": "5d9a1bbfbe52f55acf33d960763dce0872689c2b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "halfaya/Music",
"max_forks_repo_path": "Soundness/agda/Soundness.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5d9a1bbfbe52f55acf33d960763dce0872689c2b",
"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": "halfaya/Music",
"max_issues_repo_path": "Soundness/agda/Soundness.agda",
"max_line_length": 84,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "5d9a1bbfbe52f55acf33d960763dce0872689c2b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "halfaya/Music",
"max_stars_repo_path": "Soundness/agda/Soundness.agda",
"max_stars_repo_stars_event_max_datetime": "2020-11-10T04:05:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-11-10T04:05:28.000Z",
"num_tokens": 1603,
"size": 4930
} |
{-# OPTIONS --no-termination-check
#-}
------------------------------------------------------------------------
-- A terminating parser data type and the accompanying interpreter
------------------------------------------------------------------------
-- This code is based on "Parallel Parsing Processes" by Koen
-- Claessen.
module Parallel where
open import Parallel.Index
open import Data.Product renaming (_,_ to pair)
open import Data.Bool
open import Data.Nat
open import Data.Product.Record using (_,_)
import Data.List as List
open List using (List; []; _∷_; _++_)
import Data.Vec as Vec
open Vec using (Vec; []; _∷_) renaming (_++_ to _<+>_)
open import Category.Monad.State
open import Data.Function
open import Data.Maybe
import Relation.Binary.PropositionalEquality as PropEq
open PropEq using (_≡_; refl)
------------------------------------------------------------------------
-- Parser monad
P : Set -> (Set -> Set)
P tok = StateT (List tok) List
------------------------------------------------------------------------
-- Basic parsers (no CPS)
private
module Base where
-- returnPlus below takes a _vector_ of immediate results, since
-- otherwise the returnPlus/returnPlus case of _∣_ would not type
-- check. (Its type would have to be changed.)
--
-- (The vector could just as well have been a list, if it were not
-- for the unused module IncorrectBind below. However, documenting
-- that this list is never empty is not a bad thing, and does not
-- cost much.)
codata Parser (tok r : Set) : Index -> Set where
symbolBind : forall {i : tok -> Index} ->
((c : tok) -> Parser tok r (i c)) -> Parser tok r 0I
fail : Parser tok r 0I
returnPlus : forall {e d n} ->
Vec r (suc n) -> Parser tok r (e , d) ->
Parser tok r (true , suc d)
-- Note that the type of this return function is not suitable if you
-- want to state the monad laws (since (true , 1) is not a zero in
-- the monoid which is used here). The return function defined below
-- has a more suitable type, though.
return : forall {tok r} -> r -> Parser tok r (true , 1)
return x = returnPlus (Vec.[_] x) fail
cast : forall {tok i₁ i₂ r} ->
i₁ ≡ i₂ -> Parser tok r i₁ -> Parser tok r i₂
cast refl p = p
infixl 0 _∣_
_∣_ : forall {tok r i₁ i₂} ->
Parser tok r i₁ -> Parser tok r i₂ -> Parser tok r (i₁ ∣I i₂)
fail ∣ p₂ ~ p₂
returnPlus xs p₁ ∣ fail ~ returnPlus xs p₁
symbolBind f₁ ∣ fail ~ symbolBind f₁
symbolBind f₁ ∣ symbolBind f₂ ~ symbolBind (\c -> f₁ c ∣ f₂ c)
symbolBind f₁ ∣ returnPlus xs p₂ ~ returnPlus xs (symbolBind f₁ ∣ p₂)
returnPlus xs p₁ ∣ symbolBind f₂ ~ returnPlus xs (symbolBind f₂ ∣ p₁)
returnPlus xs₁ p₁ ∣ returnPlus xs₂ p₂ ~ returnPlus (xs₁ <+> xs₂) (p₁ ∣ p₂)
-- parse is structurally recursive over the following lexicographic
-- measure:
--
-- ⑴ The input string.
-- ⑵ The Distance index.
parse : forall {tok r e d} ->
Parser tok r (e , d) -> P tok r
parse (symbolBind f) (c ∷ s) = parse (f c) s
parse (symbolBind f) [] = []
parse fail _ = []
parse (returnPlus xs p) s =
List.map (\x -> pair x s) (Vec.toList xs) ++ parse p s
-- It may be interesting to note that it is hard to define bind
-- directly. Note that the module Incorrect is not used for
-- anything; bind is defined further down using CPS.
private
module IncorrectBind where
-- choice ≈ foldr₁ _∣_.
choice : forall {tok r i n} ->
Vec (Parser tok r i) (suc n) -> Parser tok r i
choice {i = i} =
Vec.foldr₁ (\p₁ p₂ -> cast (∣-idempotent i) (p₁ ∣ p₂))
where open IndexSemiring
-- This function is used to state the type of bind.
bind-index : forall {tok r i} ->
Parser tok r i -> Index -> Index
bind-index (symbolBind f) _ = 0I
bind-index fail _ = 0I
bind-index (returnPlus xs p) i = i
open IndexSemiring
bind-index-lemma : forall {tok r i₁} (p : Parser tok r i₁) i₂ ->
i₂ ∣I bind-index p i₂ ≡ i₂
bind-index-lemma (symbolBind f) i = proj₂ +-identity i
bind-index-lemma fail i = proj₂ +-identity i
bind-index-lemma (returnPlus xs p) i = ∣-idempotent i
-- Note that bind has a non-trivial type. This is not a
-- fundamental problem, though. The big problem is that bind is
-- not productive (in general). The recursive call p >>= g in the
-- last line is not guarded if, for instance, g = const fail, in
-- which case we have (ignoring some casts)
--
-- returnPlus xs p >>= g = p >>= g.
--
-- If furthermore p = returnPlus xs p, then we have a real
-- problem.
_>>=_ : forall {tok r₁ r₂ i₁ i₂} ->
(p₁ : Parser tok r₁ i₁) -> (r₁ -> Parser tok r₂ i₂) ->
Parser tok r₂ (bind-index p₁ i₂)
symbolBind f >>= g ~ symbolBind (\c -> f c >>= g)
fail >>= g ~ fail
returnPlus xs p >>= g ~ cast (bind-index-lemma p _)
(choice (Vec.map g xs) ∣ p >>= g)
------------------------------------------------------------------------
-- CPS transformation
-- The code below manually applies the continuation-passing monad
-- transformer to the Base parser above to improve the efficiency of
-- left-nested uses of bind. (And, in light of Base.Incorrect._>>=_,
-- to enable a well-founded definition of bind.)
data Parser (tok : Set) (i : Index) (r : Set) : Set1 where
parser : (forall {i' r'} ->
(r -> Base.Parser tok r' i') ->
Base.Parser tok r' (i ·I i')) ->
Parser tok i r
private
unP : forall {tok r i r' i'} ->
Parser tok i r ->
(r -> Base.Parser tok r' i') ->
Base.Parser tok r' (i ·I i')
unP (parser p) = p
symbol : forall {tok} -> Parser tok 0I tok
symbol = parser Base.symbolBind
fail : forall {tok r} -> Parser tok 0I r
fail = parser \k -> Base.fail
-- A problematic variant of fail. See Parallel.Lib.
problematic : forall {tok r} -> r -> Parser tok 0I r
problematic x = parser (\k -> helper (k x))
where
helper : forall {tok r' i'} ->
Base.Parser tok r' i' -> Base.Parser tok r' 0I
helper (Base.symbolBind _) = Base.fail
helper Base.fail = Base.fail
helper (Base.returnPlus _ _) = Base.fail
return : forall {tok r} -> r -> Parser tok 1I r
return x = parser \k -> k x
-- Note that _>>=_ cannot easily be given a dependent type (where the
-- second argument has type (x : r₁) -> Parser tok r₂ (i₂ x)). What
-- would the type of the result of _>>=_ be? The type would depend on
-- the input string, which is not an argument to _>>=_.
--
-- Note also that the variant _!>>=_ from Parser/RecursiveDescent.Coinductive
-- cannot (?) be implemented, since the continuation given to p cannot
-- be dependently typed.
infixl 1 _>>=_
_>>=_ : forall {tok r₁ r₂ i₁ i₂} ->
Parser tok i₁ r₁ -> (r₁ -> Parser tok i₂ r₂) ->
Parser tok (i₁ ·I i₂) r₂
_>>=_ {i₁ = i₁} {i₂} (parser p) f = parser
\{i₃} k -> Base.cast (sym $ *-assoc i₁ i₂ i₃)
(p \x -> unP (f x) k)
where open IndexSemiring
infixl 0 _∣_
_∣_ : forall {tok r i₁ i₂} ->
Parser tok i₁ r ->
Parser tok i₂ r ->
Parser tok (i₁ ∣I i₂) r
_∣_ {i₁ = i₁} {i₂ = i₂} (parser p₁) (parser p₂) =
parser \{i₃} k ->
Base.cast (sym $ proj₂ distrib i₃ i₁ i₂)
(Base._∣_ (p₁ k) (p₂ k))
where open IndexSemiring
-- Since _>>=_ has a non-dependent type it is hard to define sat
-- without using the underlying parsers in Base, and hence sat is
-- provided here.
sat : forall {tok r} ->
(tok -> Maybe r) -> Parser tok 0I r
sat {tok} {r} p = parser \k -> Base.symbolBind (\c -> ok k (p c))
where
okIndex : Index -> Maybe r -> Index
okIndex i' nothing = 0I
okIndex i' (just _) = i'
ok : forall {r' i'} ->
(r -> Base.Parser tok r' i') ->
(x : Maybe r) -> Base.Parser tok r' (okIndex i' x)
ok k nothing = Base.fail
ok k (just x) = k x
parse : forall {tok r i} ->
Parser tok i r -> P tok r
parse (parser p) = Base.parse (p Base.return)
-- A variant which only returns parses which leave no remaining input.
parse-complete : forall {tok r i} ->
Parser tok i r -> List tok -> List r
parse-complete p s =
List.map proj₁ (List.filter (List.null ∘ proj₂) (parse p s))
| {
"alphanum_fraction": 0.5725863284,
"avg_line_length": 34.4696356275,
"ext": "agda",
"hexsha": "2e8f34ecbd0d2043ef448c760a59ee801cbd2723",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "misc/Parallel.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_issues_repo_issues_event_max_datetime": "2018-01-24T16:39:37.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-01-22T22:21:41.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/parser-combinators",
"max_issues_repo_path": "misc/Parallel.agda",
"max_line_length": 77,
"max_stars_count": 7,
"max_stars_repo_head_hexsha": "b396d35cc2cb7e8aea50b982429ee385f001aa88",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yurrriq/parser-combinators",
"max_stars_repo_path": "misc/Parallel.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-22T05:35:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-12-13T05:23:14.000Z",
"num_tokens": 2467,
"size": 8514
} |
{-# OPTIONS --no-qualified-instances #-}
module NoQualifiedInstances-AnonymousInstance where
postulate
A : Set
f : {{A}} → A
postulate instance _ : A
test : A
test = f
| {
"alphanum_fraction": 0.6818181818,
"avg_line_length": 13.5384615385,
"ext": "agda",
"hexsha": "45697ef35235df0d51db1bfe46e4b0ffae5ee1a4",
"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/NoQualifiedInstances-AnonymousInstance.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/NoQualifiedInstances-AnonymousInstance.agda",
"max_line_length": 51,
"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/NoQualifiedInstances-AnonymousInstance.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": 176
} |
open import Structure.Setoid
open import Structure.Category
open import Type
module Structure.Category.Monoid
{ℓₒ ℓₘ ℓₑ}
{Obj : Type{ℓₒ}}
{Morphism : Obj → Obj → Type{ℓₘ}}
⦃ morphism-equiv : ∀{x y} → Equiv{ℓₑ}(Morphism x y) ⦄
(cat : Category(Morphism))
where
open import Logic.Predicate
open import Structure.Categorical.Properties
open import Structure.Operator.Monoid
open import Structure.Operator.Properties
open Category(cat)
-- A monoid constructed from a category for a specific object.
monoid : ∀{x} → Monoid(_∘_ {x = x})
Monoid.binary-operator monoid = binaryOperator
Associativity.proof (Monoid.associativity monoid) = Morphism.associativity(_∘_)
∃.witness (Monoid.identity-existence monoid) = id
Identityₗ.proof (Identity.left (∃.proof (Monoid.identity-existence monoid))) = Morphism.identityₗ(_∘_)(id)
Identityᵣ.proof (Identity.right (∃.proof (Monoid.identity-existence monoid))) = Morphism.identityᵣ(_∘_)(id)
| {
"alphanum_fraction": 0.7539936102,
"avg_line_length": 34.7777777778,
"ext": "agda",
"hexsha": "c2ea8cdfa4288304bd7cabcab3204e42e6990ee8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Structure/Category/Monoid.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Structure/Category/Monoid.agda",
"max_line_length": 107,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Structure/Category/Monoid.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": 287,
"size": 939
} |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.NConnected
open import lib.types.Bool
open import lib.types.Lift
open import lib.types.Nat
open import lib.types.Pointed
open import lib.types.TLevel
open import lib.types.Suspension
module lib.types.IteratedSuspension where
⊙Susp^ : ∀ {i} (n : ℕ) → Ptd i → Ptd i
⊙Susp^ O X = X
⊙Susp^ (S n) X = ⊙Susp (⊙Susp^ n X)
⊙Susp^-conn : ∀ {i} (n : ℕ) {X : Ptd i} {m : ℕ₋₂}
→ is-connected m (fst X) → is-connected (⟨ n ⟩₋₂ +2+ m) (fst (⊙Susp^ n X))
⊙Susp^-conn O cX = cX
⊙Susp^-conn (S n) cX = Susp-conn (⊙Susp^-conn n cX)
⊙Susp^-+ : ∀ {i} (m n : ℕ) {X : Ptd i}
→ ⊙Susp^ m (⊙Susp^ n X) == ⊙Susp^ (m + n) X
⊙Susp^-+ O n = idp
⊙Susp^-+ (S m) n = ap ⊙Susp (⊙Susp^-+ m n)
⊙susp^-fmap : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j}
→ fst (X ⊙→ Y) → fst (⊙Susp^ n X ⊙→ ⊙Susp^ n Y)
⊙susp^-fmap O f = f
⊙susp^-fmap (S n) f = ⊙susp-fmap (⊙susp^-fmap n f)
⊙susp^-fmap-idf : ∀ {i} (n : ℕ) (X : Ptd i)
→ ⊙susp^-fmap n (⊙idf X) == ⊙idf (⊙Susp^ n X)
⊙susp^-fmap-idf O X = idp
⊙susp^-fmap-idf (S n) X =
ap ⊙susp-fmap (⊙susp^-fmap-idf n X) ∙ ⊙susp-fmap-idf (⊙Susp^ n X)
⊙susp^-fmap-cst : ∀ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j}
→ ⊙susp^-fmap n (⊙cst {X = X} {Y = Y}) == ⊙cst
⊙susp^-fmap-cst O = idp
⊙susp^-fmap-cst (S n) = ap ⊙susp-fmap (⊙susp^-fmap-cst n)
∙ (⊙susp-fmap-cst {X = ⊙Susp^ n _})
⊙susp^-fmap-∘ : ∀ {i j k} (n : ℕ) {X : Ptd i} {Y : Ptd j} {Z : Ptd k}
(g : fst (Y ⊙→ Z)) (f : fst (X ⊙→ Y))
→ ⊙susp^-fmap n (g ⊙∘ f) == ⊙susp^-fmap n g ⊙∘ ⊙susp^-fmap n f
⊙susp^-fmap-∘ O g f = idp
⊙susp^-fmap-∘ (S n) g f =
ap ⊙susp-fmap (⊙susp^-fmap-∘ n g f)
∙ ⊙susp-fmap-∘ (⊙susp^-fmap n g) (⊙susp^-fmap n f)
⊙Sphere : (n : ℕ) → Ptd₀
⊙Sphere n = ⊙Susp^ n ⊙Bool
Sphere : (n : ℕ) → Type₀
Sphere n = fst (⊙Sphere n)
-- favonia: [S¹] has its own elim rules in Circle.agda.
⊙S⁰ = ⊙Sphere 0
⊙S¹ = ⊙Sphere 1
⊙S² = ⊙Sphere 2
⊙S³ = ⊙Sphere 3
S⁰ = Sphere 0
S¹ = Sphere 1
S² = Sphere 2
S³ = Sphere 3
| {
"alphanum_fraction": 0.5338383838,
"avg_line_length": 28.6956521739,
"ext": "agda",
"hexsha": "36f02a3632783ba57173520e1fb2044e2472462c",
"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": "core/lib/types/IteratedSuspension.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": "core/lib/types/IteratedSuspension.agda",
"max_line_length": 76,
"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": "core/lib/types/IteratedSuspension.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1055,
"size": 1980
} |
{-# OPTIONS --without-K #-}
module HoTT.Exercises.Chapter2 where
open import HoTT.Base
module Exercise1 {i} {A : 𝒰 i} where
module _ {x y z : A} (p : x == y) (q : y == z) where
-- Induction over p
_∙₁_ : x == z
_∙₁_ = =-ind D d p z q where
D : (x y : A) → x == y → 𝒰 i
D x y p = (z : A) → (q : y == z) → x == z
d : (x : A) → D x x refl
d x z q = q
-- Induction over q
_∙₂_ : x == z
_∙₂_ = =-ind D d q x p where
D : (y z : A) → y == z → 𝒰 i
D y z q = (x : A) → (p : x == y) → x == z
d : (y : A) → D y y refl
d y x p = p
-- Induction over p then q
_∙₃_ : x == z
_∙₃_ = =-ind D d p z q where
E : (x z : A) → (q : x == z) → 𝒰 i
E x z q = x == z
e : (x : A) → E x x refl
e x = refl
D : (x y : A) → x == y → 𝒰 i
D x y p = (z : A) → (q : y == z) → x == z
d : (x : A) → D x x refl
d x z q = =-ind E e q
module _ {x y z : A} (p : x == y) (q : y == z) where
prop₁₌₂ : p ∙₁ q == p ∙₂ q
prop₁₌₂ = =-ind D d p z q where
E : (y z : A) → y == z → 𝒰 i
E y z q = refl ∙₁ q == refl ∙₂ q
e : (y : A) → E y y refl
e y = refl
D : (x y : A) → x == y → 𝒰 i
D x y p = (z : A) → (q : y == z) → p ∙₁ q == p ∙₂ q
d : (x : A) → D x x refl
d x z q = =-ind E e q
prop₂₌₃ : p ∙₂ q == p ∙₃ q
prop₂₌₃ = =-ind D d p z q where
E : (y z : A) → y == z → 𝒰 i
E y z q = refl ∙₂ q == refl ∙₃ q
e : (y : A) → E y y refl
e y = refl
D : (x y : A) → x == y → 𝒰 i
D x y p = (z : A) → (q : y == z) → p ∙₂ q == p ∙₃ q
d : (x : A) → D x x refl
d x z q = =-ind E e q
prop₁₌₃ : p ∙₁ q == p ∙₃ q
prop₁₌₃ = =-ind D d p z q where
E : (y z : A) → y == z → 𝒰 i
E y z q = refl ∙₁ q == refl ∙₃ q
e : (y : A) → E y y refl
e y = refl
D : (x y : A) → x == y → 𝒰 i
D x y p = (z : A) → (q : y == z) → p ∙₁ q == p ∙₃ q
d : (x : A) → D x x refl
d x z q = =-ind E e q
module Exercise2 {i} {A : 𝒰 i} {x y z : A} {p : x == y} {q : y == z} where
open Exercise1
_ : prop₁₌₂ p q ∙ prop₂₌₃ p q == prop₁₌₃ p q
_ = =-ind D d p z q where
E : (y z : A) → y == z → 𝒰 i
E y z q = prop₁₌₂ refl q ∙ prop₂₌₃ refl q == prop₁₌₃ refl q
e : (y : A) → E y y refl
e y = refl
D : (x y : A) → x == y → 𝒰 i
D x y p = (z : A) → (q : y == z) → prop₁₌₂ p q ∙ prop₂₌₃ p q == prop₁₌₃ p q
d : (x : A) → D x x refl
d x z q = =-ind E e q
module Exercise3 {i} {A : 𝒰 i} where
open Exercise1 using (_∙₁_)
-- Induction over q then p
_∙₄_ : {x y z : A} → x == y → y == z → x == z
_∙₄_ {x} {y} {z} p q = =-ind D d q x p where
E : (x y : A) → (p : x == y) → 𝒰 i
E x y _ = x == y
e : (x : A) → E x x refl
e x = refl
D : (y z : A) → y == z → 𝒰 i
D y z q = (x : A) → (p : x == y) → x == z
d : (y : A) → D y y refl
d y x p = =-ind E e p
prop₁₌₄ : {x y z : A} (p : x == y) (q : y == z) → p ∙₁ q == p ∙₄ q
prop₁₌₄ {x} {y} {z} p q = =-ind D d p z q where
E : (y z : A) → y == z → 𝒰 i
E y z q = refl ∙₁ q == refl ∙₄ q
e : (y : A) → E y y refl
e y = refl
D : (x y : A) → x == y → 𝒰 i
D x y p = (z : A) → (q : y == z) → p ∙₁ q == p ∙₄ q
d : (x : A) → D x x refl
d x z q = =-ind E e q
module Exercise4 {i} (A : 𝒰 i) where
n-path : ℕ → 𝒰 i
n-path = ℕ-rec A (λ n P → Σ[ x ∶ P ] (Σ[ y ∶ P ] (x == y)))
module Exercise5 {i} {A B : 𝒰 i} {x y : A} {p : x == y} {f : A → B} where
open import HoTT.Identity
open import HoTT.Equivalence
_ : f x == f y ≃ transport _ p (f x) == f y
_ = g , qinv→isequiv (h , η , ε)
where
-- 2.3.6
g : f x == f y → transport _ p (f x) == f y
g = transportconst p (f x) ∙_
-- 2.3.7
h : transport _ p (f x) == f y → f x == f y
h = transportconst p (f x) ⁻¹ ∙_
η : (h ∘ g) ~ id
η q = assoc ∙ (invₗ ∙ᵣ q ∙ unitₗ ⁻¹)
ε : (g ∘ h) ~ id
ε q = assoc ∙ (invᵣ ∙ᵣ q ∙ unitₗ ⁻¹)
module Exercise6 {i} {A : 𝒰 i} {x y z : A} {p : x == y} where
open import HoTT.Equivalence
open import HoTT.Identity
_ : y == z ≃ x == z
_ = f , qinv→isequiv (g , η , ε)
where
f = p ∙_
g = p ⁻¹ ∙_
η : g ∘ f ~ id
η q = assoc ∙ (invₗ ∙ᵣ q ∙ unitₗ ⁻¹)
ε : f ∘ g ~ id
ε q = assoc ∙ (invᵣ ∙ᵣ q ∙ unitₗ ⁻¹)
module Exercise7 {i j k l} {A : 𝒰 i} {A' : 𝒰 j} {B : A → 𝒰 k} {B' : A' → 𝒰 l}
{g : A → A'} {h : {x : A} → B x → B' (g x)} where
open import HoTT.Identity
open import HoTT.Identity.Sigma
prop : {x y : Σ A B} (p : pr₁ x == pr₁ y) (q : transport B p (pr₂ x) == (pr₂ y)) →
ap (λ x → g (pr₁ x) , h (pr₂ x)) (pair⁼ {x = x} {y} (p , q)) ==
pair⁼ (ap g p , transport-ap B' g p (h (pr₂ x)) ∙ transport-∘ h p (pr₂ x) ∙ ap h q)
prop {x = _ , _} {_ , _} refl refl = refl
module Exercise8 {i j k l} {A : 𝒰 i} {B : 𝒰 j} {A' : 𝒰 k} {B' : 𝒰 l}
{g : A → A'} {h : B → B'} where
open import HoTT.Identity.Coproduct
private variable x y : A + B
f : A + B → A' + B'
f = +-rec (inl ∘ g) (inr ∘ h)
ap-gh : (p : x =+ y) → f x =+ f y
ap-gh {inl _} {inl _} (lift p) = lift (ap g p)
ap-gh {inl _} {inr _} ()
ap-gh {inr _} {inl _} ()
ap-gh {inr _} {inr _} (lift p) = lift (ap h p)
prop : (p : x =+ y) → ap f (=+-intro p) == =+-intro (ap-gh p)
prop {inl _} {inl _} (lift refl) = refl
prop {inl _} {inr _} ()
prop {inr _} {inl _} ()
prop {inr _} {inr _} (lift refl) = refl
module Exercise9 {i j k} {A : 𝒰 i} {B : 𝒰 j} where
open import HoTT.Equivalence
open import HoTT.Identity.Pi
prop₁ : {X : 𝒰 k} → (A + B → X) ≃ (A → X) × (B → X)
prop₁ {X} = f , qinv→isequiv (g , β , α)
where
f : (A + B → X) → (A → X) × (B → X)
f h = h ∘ inl , h ∘ inr
g : (A → X) × (B → X) → (A + B → X)
g (h , _) (inl a) = h a
g (_ , h) (inr b) = h b
α : f ∘ g ~ id
α (_ , _) = refl
β : g ∘ f ~ id
β _ = funext λ{(inl _) → refl ; (inr _) → refl}
prop₂ : {P : A + B → 𝒰 k} →
((x : A + B) → P x) ≃ ((a : A) → P (inl a)) × ((b : B) → P (inr b))
prop₂ {P} = f , qinv→isequiv (g , β , α)
where
f : ((x : A + B) → P x) → ((a : A) → P (inl a)) × ((b : B) → P (inr b))
f h = (h ∘ inl) , h ∘ inr
g : ((a : A) → P (inl a)) × ((b : B) → P (inr b)) → ((x : A + B) → P x)
g (h , _) (inl a) = h a
g (_ , h) (inr b) = h b
α : f ∘ g ~ id
α (_ , _) = refl
β : g ∘ f ~ id
β _ = funext λ{(inl _) → refl ; (inr _) → refl}
module Exercise10 {i j k} {A : 𝒰 i} {B : A → 𝒰 j} {C : Σ A B → 𝒰 k}
where
open import HoTT.Equivalence
_ : Σ[ x ∶ A ] Σ[ y ∶ B x ] C (x , y) ≃ Σ[ p ∶ Σ A B ] C p
_ = f , qinv→isequiv (g , η , ε)
where
f : Σ[ x ∶ A ] Σ[ y ∶ B x ] C (x , y) → Σ[ p ∶ Σ A B ] C p
f (x , y , z) = (x , y) , z
g : Σ[ p ∶ Σ A B ] C p → Σ[ x ∶ A ] Σ[ y ∶ B x ] C (x , y)
g ((x , y) , z) = x , y , z
η : g ∘ f ~ id
η (_ , _ , _) = refl
ε : f ∘ g ~ id
ε ((_ , _) , _) = refl
import HoTT.Exercises.Chapter2.Exercise11
import HoTT.Exercises.Chapter2.Exercise12
module Exercise13
where
open import HoTT.Equivalence
open import HoTT.Equivalence.Proposition
open import HoTT.Identity.Pi
open import HoTT.Identity.Sigma
not : 𝟐 → 𝟐
not = 𝟐-rec 1₂ 0₂
-- There are two possibilities for 𝟐 ≃ 𝟐, id and not. In our
-- equivalence (𝟐 ≃ 𝟐) ≃ 𝟐, we associate `id` with 0₂, and `not`
-- with 1₂. For some f : 𝟐 ≃ 𝟐, we have f 0₂ = 0₂ when f is id,
-- and f 0₂ = 1₂ when f is not, so we can use f 0₂ in the forward
-- direction.
_ : (𝟐 ≃ 𝟐) ≃ 𝟐
_ = to , qinv→isequiv (from , β , α)
where
to : 𝟐 ≃ 𝟐 → 𝟐
to (f , _) = f 0₂
from : 𝟐 → 𝟐 ≃ 𝟐
from 0₂ = id , qinv→isequiv (id , (λ _ → refl) , λ _ → refl)
from 1₂ = not , qinv→isequiv (not , 𝟐-ind _ refl refl , 𝟐-ind _ refl refl)
-- The first homotopy is easy, we just do 𝟐-induction on the
-- input to determine whether we have `id` or `not`. Once we
-- know that, it is just a matter of showing 0₂ = 0₂ or 1₂ = 1₂,
-- both of which are true by reflection.
α : to ∘ from ~ id
α = 𝟐-ind _ refl refl
-- The second homotopy is much trickier since we have to show
-- that these two complex structures are the same. The approach
-- we use is to induct on the four possibilities for f 0₂ and
-- f 1₂ (0₂ 0₂, 0₂ 1₂, 1₂ 0₂, or 1₂ 1₂). In the induction goals,
-- we require proofs that the boolean we induct on is equal
-- to f 0₂ or f 1₂ respectively. These proofs can be used
-- directly for the case where f = id or f = not. The other two
-- cases are impossible unless 0₂ = 1₂, and we can use the
-- proofs together with the equivalence inverse function and
-- homotopy to show the desired behavior of f.
β : from ∘ to ~ id
β (f , e) =
pair⁼ (𝟐-ind (λ x → x == f 0₂ → pr₁ (from x) == f)
(λ p → 𝟐-ind (λ x → x == f 1₂ → id == f)
(λ q → funext (𝟐-ind _ p (η 1₂ ⁻¹ ∙ ap g (q ⁻¹ ∙ p) ∙ η 0₂ ∙ q)))
(λ q → funext (𝟐-ind _ p q))
(f 1₂) refl)
(λ p → 𝟐-ind (λ x → x == f 1₂ → not == f)
(λ q → funext (𝟐-ind _ p q))
(λ q → funext (𝟐-ind _ p (η 0₂ ⁻¹ ∙ ap g (p ⁻¹ ∙ q) ∙ η 1₂ ∙ q)))
(f 1₂) refl)
(f 0₂) refl , isequiv-prop _ _)
where open qinv (isequiv→qinv e)
module Exercise14 {i} {A : 𝒰 i} {x : A}
where
-- In chapter 1 exercise 14, we showed that we couldn't use path
-- induction to prove (x : A) → (p : x = x) → p = reflₓ since,
-- given q : x = y, q = reflₓ is not well-typed (reflₓ : x = x,
-- while q : x = y). However, using the equality reflection rule
-- we have x ≡ y, so we can say reflₓ : x = y. Therefore, we can
-- define
--
-- C : (x s : A) → x = y → 𝒰
-- C x y q :≡ q = reflₓ
--
-- c : (x : A) → C x x reflₓ
-- c x :≡ refl {reflₓ}
--
-- Using path induction we have ind₌ C c x x p : p = reflₓ. By
-- applying the equality reflection rule again, we arrive at the
-- desired definitional equality, p ≡ reflₓ.
module Exercise15 {i j} {A : 𝒰 i} {B : A → 𝒰 j} {x y : A} {p : x == y} {u : B x}
where
_ : transport _ p == transport id (ap B p)
_ = =-ind (λ _ _ p → transport _ p == transport id (ap B p)) (λ _ → refl) p
module Exercise16 {i} {j} {A : 𝒰 i} {B : A → 𝒰 j} (f g : Π A B) where
open import HoTT.Identity
open import HoTT.Identity.Sigma
open import HoTT.Identity.Pi using (funext)
open import HoTT.Equivalence
=Π-equiv : f == g ≃ f ~ g
=Π-equiv = happly , qinv→isequiv (funext' , η , ε)
where
-- Define funext' in such a way that funext (happly refl) ≡
-- funext (λ x. refl) can cancel.
funext' : {g : Π A B} → f ~ g → f == g
funext' α = funext α ∙ funext (λ _ → refl) ⁻¹
η : funext' ∘ happly ~ id
η refl = invᵣ
ε : happly ∘ funext' ~ id
ε α = transport P p (ap happly invᵣ)
where
P : Π[ x ∶ A ] Σ[ y ∶ B x ] f x == y → 𝒰 _
P h = let α = pr₂ ∘ h in happly (funext' α) == α
-- The trick here is to use funext to simultaneously show
-- that λ x. (f x , refl) = λ x. (g x , α x). Then, we can
-- transport a path made by canceling the funext with its
-- inverse to get the desired equality.
p : (λ x → f x , refl) == (λ x → g x , α x)
p = funext λ x → pair⁼ (α x , =-ind (λ _ _ p → transport _ p refl == p) (λ _ → refl) (α x))
module Exercise17 {i} where
open import HoTT.Equivalence
open import HoTT.Equivalence.Proposition
open import HoTT.Identity.Product
open import HoTT.Identity.Sigma
open import HoTT.Identity.Universe
open import HoTT.Identity.Pi
variable
A A' B B' : 𝒰 i
P : A → 𝒰 i
P' : A' → 𝒰 i
prop : (_◆_ : 𝒰 i → 𝒰 i → 𝒰 i) → A == A' → B == B' → (A ◆ B) ≃ (A' ◆ B')
prop {A} {A'} {B} {B'} (_◆_) p q =
transport (λ{ (A' , B') → A ◆ B ≃ A' ◆ B' })
(×-pair⁼ {x = A , B} {y = A' , B'} (p , q)) reflₑ
module _ (e₁ : A ≃ A') (e₂ : B ≃ B')
where
open Iso (eqv→iso e₁) renaming (f to f₁ ; g to g₁ ; η to η₁ ; ε to ε₁)
open Iso (eqv→iso e₂) renaming (f to f₂ ; g to g₂ ; η to η₂ ; ε to ε₂)
-- (i) Proof without using univalence
prop-×' : A × B ≃ A' × B'
prop-×' = let open Iso in iso→eqv λ where
.f (a , b) → f₁ a , f₂ b
.g (a' , b') → g₁ a' , g₂ b'
.η (a , b) → ×-pair⁼ (η₁ a , η₂ b)
.ε (a' , b') → ×-pair⁼ (ε₁ a' , ε₂ b')
-- (ii) Proof using univalence (for general operator)
prop-× = prop _×_ (ua e₁) (ua e₂)
-- (iii) Proof for non-dependent type formers (→, +)
prop-→ = prop (λ A B → A → B) (ua e₁) (ua e₂)
prop-+ = prop _+_ (ua e₁) (ua e₂)
-- Proof that (i) and (ii) are equal
propᵢ₌ᵢᵢ : (e₁ : A ≃ A') (e₂ : B ≃ B') → prop-×' e₁ e₂ == prop-× e₁ e₂
propᵢ₌ᵢᵢ e₁ e₂ = ap² prop-×' (=𝒰-β e₁ ⁻¹) (=𝒰-β e₂ ⁻¹) ∙ lemma
where
lemma : prop-×' (idtoeqv (ua e₁)) (idtoeqv (ua e₂)) == prop-× e₁ e₂
lemma rewrite ua e₁ rewrite ua e₂ =
pair⁼ (funext (λ{ (a , b) → refl }) , isequiv-prop _ _)
module _ (e₁ : A ≃ A') (e₂ : (x : A') → transport (λ A' → A' → 𝒰 i) (ua e₁) P x ≃ P' x)
where
prop-dep : (_◆_ : (A : 𝒰 i) → (A → 𝒰 i) → 𝒰 i) → (A ◆ P) ≃ (A' ◆ P')
prop-dep _◆_ = transport (λ{ (A' , P') → A ◆ P ≃ A' ◆ P' })
(pair⁼ {x = A , P} {y = A' , P'} (ua e₁ , funext (ua ∘ e₂))) reflₑ
-- (iii) Proof for dependent type formers (Σ, Π)
prop-Σ = prop-dep Σ
prop-Π = prop-dep Π
module Exercise18 {i} {A : 𝒰 i} {B : A → 𝒰 i} {f g : Π A B} {H : f ~ g}
{x y : A} {p : x == y}
where
-- We first induct on p, changing our goal to
--
-- ap (transport refl) (H x) ∙ apd g refl = apd f refl ∙ H y
--
-- This reduces to
--
-- ap id (H x) ∙ refl = refl ∙ H x
--
-- Now, we just need one final induction on H x, after which our goal
-- reduces to refl : refl = refl.
_ : ap (transport _ p) (H x) ∙ apd g p == apd f p ∙ H y
_ = =-ind' (λ y p → ap (transport _ p) (H x) ∙ apd g p == apd f p ∙ H y)
(=-ind' (λ _ Hₓ → ap id Hₓ ∙ refl == refl ∙ Hₓ) refl (H x)) p
| {
"alphanum_fraction": 0.4676609781,
"avg_line_length": 34.4345679012,
"ext": "agda",
"hexsha": "3453d6f46cdcce3cd50269890b104d1c85237e09",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "michaelforney/hott",
"max_forks_repo_path": "HoTT/Exercises/Chapter2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "michaelforney/hott",
"max_issues_repo_path": "HoTT/Exercises/Chapter2.agda",
"max_line_length": 97,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "michaelforney/hott",
"max_stars_repo_path": "HoTT/Exercises/Chapter2.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6391,
"size": 13946
} |
------------------------------------------------------------------------------
-- Well-founded relation on trees
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.FOTC.Program.Mirror.TreeR where
open import FOTC.Base
open import FOTC.Data.List.WF-Relation.LT-Cons
open import FOTC.Program.Mirror.Type
------------------------------------------------------------------------------
-- Well-founded relation on trees.
-- A well-founded relation for rose trees is the lexicographical order
--
-- (t : ts) < (t' : ts') = t < t' or t ≡ t' and ts < ts'.
--
-- It seems we would not to use the first conjunct in the mirror
-- example.
TreeR : D → D → Set
TreeR t₁ t₂ = ∃[ d ] ∃[ ts₁ ] ∃[ ts₂ ]
t₁ ≡ node d ts₁
∧ t₂ ≡ node d ts₂
∧ LTC ts₁ ts₂
| {
"alphanum_fraction": 0.4411177645,
"avg_line_length": 33.4,
"ext": "agda",
"hexsha": "10003989d3299ee258b6aeed204e1c17e0cc9ac6",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/FOT/FOTC/Program/Mirror/TreeR.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "notes/FOT/FOTC/Program/Mirror/TreeR.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "notes/FOT/FOTC/Program/Mirror/TreeR.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": 225,
"size": 1002
} |
-- This file contains several ways to define localisation
-- and proves them all to be equivalent
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Experiments.LocalisationDefs where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Powerset
open import Cubical.Foundations.Transport
open import Cubical.Functions.FunExtEquiv
import Cubical.Data.Empty as ⊥
open import Cubical.Data.Bool
open import Cubical.Data.Vec
open import Cubical.Data.Sigma.Base
open import Cubical.Data.Sigma.Properties
open import Cubical.Data.FinData
open import Cubical.Relation.Nullary
open import Cubical.Relation.Binary
open import Cubical.Algebra.Group
open import Cubical.Algebra.AbGroup
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
open import Cubical.HITs.SetQuotients as SQ
open import Cubical.HITs.PropositionalTruncation as PT
open Iso
private
variable
ℓ ℓ' : Level
A : Type ℓ
record isMultClosedSubset (R' : CommRing {ℓ}) (S' : ℙ (R' .fst)) : Type ℓ where
constructor
multclosedsubset
field
containsOne : (R' .snd .CommRingStr.1r) ∈ S'
multClosed : ∀ {s t} → s ∈ S' → t ∈ S' → (R' .snd .CommRingStr._·_ s t) ∈ S'
module _ (R' : CommRing {ℓ}) (S' : ℙ (R' .fst)) (SMultClosedSubset : isMultClosedSubset R' S') where
open isMultClosedSubset
private R = R' .fst
open CommRingStr (R' .snd)
open Theory (CommRing→Ring R')
S = Σ[ s ∈ R ] (s ∈ S')
-- HIT definition
data S⁻¹R : Type ℓ where
_/ₗ_ : R → S → S⁻¹R
zd : (r₁ r₂ : R) (s s₁ s₂ : S)
→ fst s · r₁ · fst s₂ ≡ fst s · r₂ · fst s₁
→ r₁ /ₗ s₁ ≡ r₂ /ₗ s₂
trunc : isSet S⁻¹R
infixr 5 _/ₗ_
module Elim {ℓ'} {B : S⁻¹R → Type ℓ'}
(_/*_ : (r : R) (s : S) → B (r /ₗ s))
(zd* : (r₁ r₂ : R) (s s₁ s₂ : S)
→ (p : fst s · r₁ · fst s₂ ≡ fst s · r₂ · fst s₁)
→ PathP (λ i → B (zd r₁ r₂ s s₁ s₂ p i)) (r₁ /* s₁) (r₂ /* s₂))
(trunc* : (q : S⁻¹R) → isSet (B q)) where
f : (q : S⁻¹R) → B q
f (r /ₗ s) = r /* s
f (zd r₁ r₂ s s₁ s₂ p i) = zd* r₁ r₂ s s₁ s₂ p i
f (trunc q₁ q₂ x y i j) = isOfHLevel→isOfHLevelDep 2 trunc* (f q₁) (f q₂) (cong f x) (cong f y)
(trunc q₁ q₂ x y) i j
module ElimProp {ℓ'} {B : S⁻¹R → Type ℓ'} (Bprop : {q : S⁻¹R} → isProp (B q))
(_/*_ : (r : R) → (s : S) → B (r /ₗ s)) where
f : (q : S⁻¹R) → B q
f = Elim.f _/*_ (λ r₁ r₂ s s₁ s₂ p
→ toPathP (Bprop (transp (λ i → B (zd r₁ r₂ s s₁ s₂ p i)) i0 (r₁ /* s₁))
(r₂ /* s₂)))
λ q → isProp→isSet Bprop
module Rec {ℓ'} {B : Type ℓ'} (BType : isSet B)
(_/*_ : R → S → B)
(zd* : (r₁ r₂ : R) (s s₁ s₂ : S)
→ (p : fst s · r₁ · fst s₂ ≡ fst s · r₂ · fst s₁)
→ r₁ /* s₁ ≡ r₂ /* s₂)
where
f : S⁻¹R → B
f = Elim.f _/*_ zd* (λ _ → BType)
-- approach using set quotients
_≈_ : R × S → R × S → Type ℓ
(r₁ , s₁) ≈ (r₂ , s₂) = ∃[ s ∈ S ] (fst s · r₁ · fst s₂ ≡ fst s · r₂ · fst s₁)
S⁻¹R/ = (R × S) / _≈_
-- proving equivalence of the two types
φ : S⁻¹R/ → S⁻¹R
φ = SQ.rec trunc (λ (r , s) → r /ₗ s) β
where
α : ((r₁ , s₁) (r₂ , s₂) : R × S) → Σ[ s ∈ S ] (fst s · r₁ · fst s₂ ≡ fst s · r₂ · fst s₁)
→ r₁ /ₗ s₁ ≡ r₂ /ₗ s₂
α _ _ (s , p) = zd _ _ s _ _ p
β : ((r₁ , s₁) (r₂ , s₂) : R × S) → ∃[ s ∈ S ] (fst s · r₁ · fst s₂ ≡ fst s · r₂ · fst s₁)
→ r₁ /ₗ s₁ ≡ r₂ /ₗ s₂
β _ _ = PT.rec (trunc _ _) (α _ _)
ψ : S⁻¹R → S⁻¹R/
ψ (r /ₗ s) = [ r , s ]
ψ (zd r₁ r₂ s s₁ s₂ p i) = eq/ (r₁ , s₁) (r₂ , s₂) ∣ s , p ∣ i
ψ (trunc x y p q i j) = squash/ (ψ x) (ψ y) (cong ψ p) (cong ψ q) i j
η : section φ ψ
η = ElimProp.f (trunc _ _) λ _ _ → refl
ε : retract φ ψ
ε = elimProp (λ _ → squash/ _ _) λ _ → refl
S⁻¹R/≃S⁻¹R : S⁻¹R/ ≃ S⁻¹R
S⁻¹R/≃S⁻¹R = isoToEquiv (iso φ ψ η ε)
-- Set quotients but with Σ, this is the type used in Algebra.Localisation.Base
-- as this is easiest to use
_≈'_ : R × S → R × S → Type ℓ
(r₁ , s₁) ≈' (r₂ , s₂) = Σ[ s ∈ S ] (fst s · r₁ · fst s₂ ≡ fst s · r₂ · fst s₁)
S⁻¹R/' = (R × S) / _≈'_
S⁻¹R/'≃S⁻¹R/ : S⁻¹R/' ≃ S⁻¹R/
S⁻¹R/'≃S⁻¹R/ = SQ.truncRelEquiv
| {
"alphanum_fraction": 0.5659075224,
"avg_line_length": 29.5714285714,
"ext": "agda",
"hexsha": "7545dc3be0e4111573dd72968381f25f61390ede",
"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/Experiments/LocalisationDefs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"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": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/Experiments/LocalisationDefs.agda",
"max_line_length": 100,
"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/Experiments/LocalisationDefs.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1865,
"size": 4347
} |
-- Andreas, 2018-06-09, issue #2513, parsing attributes
postulate
fail : ∀ @0 A → A → A
-- Should fail.
| {
"alphanum_fraction": 0.6296296296,
"avg_line_length": 15.4285714286,
"ext": "agda",
"hexsha": "e62247dd9ebaa4005f98f8378c8d39ebaedd12a9",
"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/AttributeUnparenthesized.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/AttributeUnparenthesized.agda",
"max_line_length": 55,
"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/AttributeUnparenthesized.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": 38,
"size": 108
} |
-- Andreas, 2018-10-27, issue #3327
--
-- Test that {-# NO_UNIVERSE_CHECK #-} pragma only applies to the following definition.
module _ where
-- The following pragma should only apply to the following definition,
-- but due to a bug is actually applying to the rest of the module.
{-# NO_UNIVERSE_CHECK #-}
data ⊥ : Set where
⊥-elim : ∀{a}{A : Set a} → ⊥ → A
⊥-elim ()
-- This passes only with {-# NO_UNIVERSE_CHECK #-}:
record Type : Set where
constructor inn
field out : Set
open Type
-- The rest is Hurken's paradox.
⊥′ : Type
⊥′ = inn ((A : Type) → out A)
_⇒_ : (A B : Type) → Type
inn A ⇒ inn B = inn (A → B)
Π : (A : Type) (B : out A → Type) → Type
Π A B = inn ((x : out A) → out (B x))
¬_ : Type → Type
¬ A = A ⇒ ⊥′
P : Type → Type
P A = inn (out A → Type)
U : Type
U = inn ((X : Type) → out ((P (P X) ⇒ X) ⇒ P (P X)))
τ : out (P (P U) ⇒ U)
τ t = λ X f p → t λ x → p (f (x X f))
σ : out (U ⇒ P (P U))
σ s pu = s U (λ t → τ t) pu
Δ : out (P U)
Δ = λ y → ¬ (Π (P U) λ p → σ y p ⇒ p (τ (σ y)))
Ω : out U
Ω X t px = τ (λ p → Π U λ x → σ x p ⇒ p x) X t px
D : Type
D = Π (P U) λ p → σ Ω p ⇒ p (τ (σ Ω))
lem₁ : out (Π (P U) λ p → (Π U λ x → σ x p ⇒ p x) ⇒ p Ω)
lem₁ p H1 = H1 Ω λ x → H1 (τ (σ x))
lem₂ : out (¬ D)
lem₂ d A = lem₁ Δ (λ x H2 H3 → H3 Δ H2 λ p → H3 λ y → p (τ (σ y))) d A
lem₃ : out D
lem₃ p = lem₁ λ y → p (τ (σ y))
loop : out ⊥′
loop = λ A → lem₂ lem₃ A
absurd : ⊥
absurd = loop (inn ⊥)
| {
"alphanum_fraction": 0.5230769231,
"avg_line_length": 19.8611111111,
"ext": "agda",
"hexsha": "b4e844ead0f3b193b26e11d1fd726084abcd6e48",
"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/Issue3327.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/Issue3327.agda",
"max_line_length": 87,
"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/Issue3327.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": 615,
"size": 1430
} |
-- Properties of Fibonacci nunmbers
{-# OPTIONS --without-K --safe #-}
module Math.NumberTheory.Fibonacci.Nat.Properties where
-- agda-stdlib
open import Data.Unit using (tt)
open import Data.Sum
open import Data.Nat
open import Data.Nat.Properties
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
open import Relation.Nullary.Decidable
open import Function.Base
-- agda-misc
open import Math.NumberTheory.Fibonacci.Nat
open import Math.NumberTheory.Summation.Nat
open ≤-Reasoning
1≤fib[1+n] : ∀ n → 1 ≤ fib (suc n)
1≤fib[1+n] zero = ≤-refl
1≤fib[1+n] (suc n) = begin
1 ≤⟨ 1≤fib[1+n] n ⟩
fib (suc n) ≤⟨ m≤m+n (fib (suc n)) (fib n) ⟩
fib (suc n) + fib n ≡⟨ fib[1+n]+fib[n]≡fib[2+n] n ⟩
fib (suc (suc n)) ∎
fib[n]<fib[1+n] : ∀ n {_ : True (2 ≤? n)} → fib n < fib (suc n)
fib[n]<fib[1+n] (suc (suc zero)) {wit} = s≤s (s≤s z≤n)
fib[n]<fib[1+n] (suc (suc (suc n))) {wit} = begin-strict
fib (3 + n) <⟨ ≤-refl ⟩
1 + fib (3 + n) ≡⟨ +-comm 1 (fib (3 + n)) ⟩
fib (3 + n) + 1 ≤⟨ +-monoʳ-≤ (fib (3 + n)) (1≤fib[1+n] (suc n)) ⟩
fib (3 + n) + fib (2 + n) ≡⟨ fib[1+n]+fib[n]≡fib[2+n] (2 + n) ⟩
fib (4 + n) ∎
private
fib-mono-<-lemma : ∀ m n {_ : True (2 ≤? n)} → fib n < fib (suc m + n)
fib-mono-<-lemma zero n {wit} = fib[n]<fib[1+n] n {wit}
fib-mono-<-lemma (suc m) n@(suc (suc _)) {wit} = begin-strict
fib n <⟨ fib-mono-<-lemma m n {tt} ⟩
fib (1 + (m + n)) ≤⟨ m≤m+n (fib (1 + (m + n))) (fib (m + n)) ⟩
fib (1 + (m + n)) + fib (m + n) ≡⟨ fib[1+n]+fib[n]≡fib[2+n] (m + n) ⟩
fib (2 + (m + n)) ∎
fib-mono-< : ∀ m n {_ : True (2 ≤? m)} → m < n → fib m < fib n
fib-mono-< m n {wit} m<n = begin-strict
fib m <⟨ fib-mono-<-lemma o m {wit} ⟩
fib (1 + o + m) ≡⟨ cong fib (sym $ n≡1+o+m) ⟩
fib n ∎
where
o = n ∸ suc m
n≡1+o+m : n ≡ 1 + o + m
n≡1+o+m = trans (sym $ m+[n∸m]≡n m<n) (cong suc (+-comm m o))
private
≤⇒≡∨< : ∀ {m n} → m ≤ n → (m ≡ n) ⊎ (m < n)
≤⇒≡∨< {m} {n} m≤n with m ≟ n
... | yes m≡n = inj₁ m≡n
... | no m≢n = inj₂ (≤∧≢⇒< m≤n m≢n)
fib-mono-≤ : ∀ m n → m ≤ n → fib m ≤ fib n
fib-mono-≤ zero n m≤n = z≤n
fib-mono-≤ (suc zero) (suc n) m≤n = 1≤fib[1+n] n
fib-mono-≤ m@(suc (suc _)) n m≤n with ≤⇒≡∨< m≤n
... | inj₁ m≡n = ≤-reflexive (cong fib m≡n)
... | inj₂ m<n = <⇒≤ $ fib-mono-< m n {tt} m<n
sum-of-fib : ∀ n → Σ[ k ≤ n ] fib k ≡ fib (2 + n) ∸ 1
sum-of-fib zero = refl
sum-of-fib (suc n) = begin-equality
Σ[ k ≤ n ] fib k + fib (suc n)
≡⟨ cong (_+ fib (suc n)) $ sum-of-fib n ⟩
(fib (2 + n) ∸ 1) + fib (1 + n)
≡⟨ +-comm (fib (2 + n) ∸ 1) (fib (1 + n)) ⟩
fib (1 + n) + (fib (2 + n) ∸ 1)
≡⟨ sym $ +-∸-assoc (fib (1 + n)) (1≤fib[1+n] (suc n)) ⟩
(fib (1 + n) + fib (2 + n)) ∸ 1
≡⟨ cong (_∸ 1) $ fib[n]+fib[1+n]≡fib[2+n] (suc n) ⟩
fib (3 + n) ∸ 1
∎
| {
"alphanum_fraction": 0.4715775311,
"avg_line_length": 34.9764705882,
"ext": "agda",
"hexsha": "8f606686d43628ae3189b534a6f4e6f4dafe2e4b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rei1024/agda-misc",
"max_forks_repo_path": "Math/NumberTheory/Fibonacci/Nat/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "rei1024/agda-misc",
"max_issues_repo_path": "Math/NumberTheory/Fibonacci/Nat/Properties.agda",
"max_line_length": 80,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rei1024/agda-misc",
"max_stars_repo_path": "Math/NumberTheory/Fibonacci/Nat/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-21T00:03:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:49:42.000Z",
"num_tokens": 1426,
"size": 2973
} |
open import Nat
open import Prelude
open import core
open import contexts
open import lemmas-consistency
open import lemmas-disjointness
open import weakening
module typed-elaboration where
mutual
typed-elaboration-synth : {Γ : tctx} {e : hexp} {τ : htyp} {d : ihexp} {Δ : hctx} →
Γ ⊢ e ⇒ τ ~> d ⊣ Δ →
Δ , Γ ⊢ d :: τ
typed-elaboration-synth ESConst = TAConst
typed-elaboration-synth (ESVar x₁) = TAVar x₁
typed-elaboration-synth (ESLam x₁ ex) = TALam x₁ (typed-elaboration-synth ex)
typed-elaboration-synth (ESAp {Δ1 = Δ1} _ d x₁ x₂ x₃ x₄)
with typed-elaboration-ana x₃ | typed-elaboration-ana x₄
... | con1 , ih1 | con2 , ih2 = TAAp (TACast (weaken-ta-Δ1 d ih1) con1) (TACast (weaken-ta-Δ2 {Δ1 = Δ1} d ih2) con2)
typed-elaboration-synth (ESEHole {Γ = Γ} {u = u}) = TAEHole (ctx-top ∅ u (Γ , ⦇-⦈) refl)(STAId (λ x τ z → z))
typed-elaboration-synth (ESNEHole {Γ = Γ} {τ = τ} {u = u} {Δ = Δ} (d1 , d2) ex)
with typed-elaboration-synth ex
... | ih1 = TANEHole {Δ = Δ ,, (u , Γ , ⦇-⦈)} (ctx-top Δ u (Γ , ⦇-⦈) (d2 u (lem-domsingle _ _))) (weaken-ta-Δ1 (d1 , d2) ih1)(STAId (λ x τ₁ z → z))
typed-elaboration-synth (ESAsc x)
with typed-elaboration-ana x
... | con , ih = TACast ih con
typed-elaboration-ana : {Γ : tctx} {e : hexp} {τ τ' : htyp} {d : ihexp} {Δ : hctx} →
Γ ⊢ e ⇐ τ ~> d :: τ' ⊣ Δ →
(τ' ~ τ) × (Δ , Γ ⊢ d :: τ')
typed-elaboration-ana (EALam x₁ MAHole ex)
with typed-elaboration-ana ex
... | con , D = TCHole1 , TALam x₁ D
typed-elaboration-ana (EALam x₁ MAArr ex)
with typed-elaboration-ana ex
... | con , D = TCArr TCRefl con , TALam x₁ D
typed-elaboration-ana (EASubsume x x₁ x₂ x₃) = ~sym x₃ , typed-elaboration-synth x₂
typed-elaboration-ana (EAEHole {Γ = Γ} {u = u}) = TCRefl , TAEHole (ctx-top ∅ u (Γ , _) refl) (STAId (λ x τ z → z))
typed-elaboration-ana (EANEHole {Γ = Γ} {u = u} {τ = τ} {Δ = Δ} (d1 , d2) x)
with typed-elaboration-synth x
... | ih1 = TCRefl , TANEHole {Δ = Δ ,, (u , Γ , τ)} (ctx-top Δ u (Γ , τ) (d2 u (lem-domsingle _ _)) ) (weaken-ta-Δ1 (d1 , d2) ih1) (STAId (λ x₁ τ₁ z → z))
| {
"alphanum_fraction": 0.5667112896,
"avg_line_length": 53.3571428571,
"ext": "agda",
"hexsha": "13a8c13c72868a81b07f982ea13ff9aa39483c45",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-09-13T18:20:02.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-09-13T18:20:02.000Z",
"max_forks_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_forks_repo_path": "typed-elaboration.agda",
"max_issues_count": 54,
"max_issues_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_issues_repo_issues_event_max_datetime": "2018-11-29T16:32:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-06-29T20:53:34.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_issues_repo_path": "typed-elaboration.agda",
"max_line_length": 159,
"max_stars_count": 16,
"max_stars_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_stars_repo_path": "typed-elaboration.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-19T02:50:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-03-12T14:32:03.000Z",
"num_tokens": 935,
"size": 2241
} |
module Ag07 where
open import IO
data W (A : Set) (B : A → Set) : Set where
sup : (a : A) → (b : B a → W A B) → W A B
module WBinTree where
data Tree : Set where
Leaf : Tree
Node : Tree
data Direction : Set where
Left : Direction
Right : Direction
data Bottom : Set where
void : ∀ {A : Set} → Bottom → A
void ()
binTree : Tree → Set
binTree Leaf = Bottom
binTree Node = Direction
BinTree : Set
BinTree = W Tree binTree
leaf : BinTree
leaf = sup Leaf void
node : BinTree → BinTree → BinTree
node x y = sup Node λ {
Left → x ;
Right → y }
| {
"alphanum_fraction": 0.5867768595,
"avg_line_length": 16.8055555556,
"ext": "agda",
"hexsha": "696cc066a0c3e5149d635073d552e4d40c8d11ed",
"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/Ag07.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/Ag07.agda",
"max_line_length": 43,
"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/Ag07.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": 198,
"size": 605
} |
module Implicits.Resolution.Ambiguous.SystemFEquiv where
open import Prelude
open import Function.Equivalence using (_⇔_; equivalence)
open import Data.List.Properties
open import Relation.Binary.HeterogeneousEquality as H using ()
open import Data.Vec.Properties as VP using ()
open import Data.Vec hiding ([_])
open import Extensions.Vec
open import Data.List as List using ()
open import Data.Product hiding (map)
open import Implicits.Syntax
open import Implicits.Resolution.Ambiguous.Resolution
open import Implicits.Resolution.Embedding
open import Implicits.Resolution.Embedding.Lemmas
open import SystemF.Everything
as F using ()
⟦_⟧term→ : ∀ {ν} {Δ : ICtx ν} {r} → Δ ⊢ᵣ r → F.Term ν (List.length (List.map ⟦_⟧tp→ Δ))
⟦_⟧term→ {ν} {Δ} (r-tabs x) = F.Λ (subst (F.Term (suc ν)) (length-weaken-Δ Δ) ⟦ x ⟧term→)
⟦ r-tapp a x ⟧term→ = ⟦ x ⟧term→ F.[ ⟦ a ⟧tp→ ]
⟦_⟧term→ {Δ = Δ} (r-ivar x) =
F.var (subst Fin (sym $ length-map _ Δ) (proj₁ $ ∈⟶index (VP.List-∈⇒∈ x)))
⟦ r-iabs {a = a} x ⟧term→ = F.λ' ⟦ a ⟧tp→ ⟦ x ⟧term→
⟦ r-iapp f e ⟧term→ = ⟦ f ⟧term→ F.· ⟦ e ⟧term→
from-⊢ : ∀ {ν n t a} {Γ : F.Ctx ν n} → Γ F.⊢ t ∈ a → ⟦ Γ ⟧ctx← ⊢ᵣ ⟦ a ⟧tp←
from-⊢ (F.var x) = r-ivar (lookup-∈ x _)
from-⊢ {Γ = Γ} (F.Λ x) = r-tabs (subst (λ u → u ⊢ᵣ _) (⟦weaken⟧ctx← Γ) (from-⊢ x))
from-⊢ (F.λ' {b = b} a x) = r-iabs (from-⊢ x)
from-⊢ {Γ = Γ} (F._[_] {a = a} x b) = subst
(λ u → ⟦ Γ ⟧ctx← ⊢ᵣ u)
(sym (⟦a/sub⟧tp← a b))
(r-tapp ⟦ b ⟧tp← (from-⊢ x))
from-⊢ (a F.· b) = r-iapp (from-⊢ a) (from-⊢ b)
to-⊢ : ∀ {ν} {Δ : ICtx ν} {r} → (p : Δ ⊢ᵣ r) → ⟦ Δ ⟧ctx→ F.⊢ ⟦ p ⟧term→ ∈ ⟦ r ⟧tp→
to-⊢ {Δ = Δ} (r-tabs {r = r} p) with to-⊢ p
to-⊢ {Δ = Δ} (r-tabs {r = r} p) | x =
F.Λ (⊢subst-n (length-weaken-Δ Δ) (H.sym (⟦weaken⟧ctx→ Δ)) x)
to-⊢ (r-tapp a p) with to-⊢ p
to-⊢ {Δ = Δ} (r-tapp {r = a} b p) | x =
subst
(λ u → ⟦ Δ ⟧ctx→ F.⊢ ⟦ p ⟧term→ F.[ ⟦ b ⟧tp→ ] ∈ u)
(sym $ ⟦a/sub⟧tp→ a b)
(x F.[ ⟦ b ⟧tp→ ])
to-⊢ {Δ = Δ} {r = r} (r-ivar x) =
let i , eq = ∈⟶index (VP.List-∈⇒∈ x) in
let i' = (subst Fin (sym $ length-map _ Δ) i) in
subst (λ u → ⟦ Δ ⟧ctx→ F.⊢ (F.var i') ∈ u) (lookup⟦⟧ Δ i eq) (F.var i')
to-⊢ (r-iabs {a = a} p) = F.λ' ⟦ a ⟧tp→ (to-⊢ p)
to-⊢ (r-iapp p p₁) = (to-⊢ p) F.· (to-⊢ p₁)
equivalent : ∀ {ν} (Δ : ICtx ν) r → Δ ⊢ᵣ r ⇔ (∃ λ t → ⟦ Δ ⟧ctx→ F.⊢ t ∈ ⟦ r ⟧tp→)
equivalent Δ r = equivalence
(λ x → , (to-⊢ x))
(λ x → subst₂ (λ Δ' r' → Δ' ⊢ᵣ r') (ctx→← _) (tp→← r) (from-⊢ (proj₂ x)))
⊢subst : ∀ {ν n n'} {a a' : F.Type ν} {Γ : F.Ctx ν n} {Γ' : F.Ctx ν n'} →
n ≡ n' → a ≡ a' → Γ H.≅ Γ' →
(∃ λ t → Γ F.⊢ t ∈ a) →
∃ λ t → Γ' F.⊢ t ∈ a'
⊢subst refl refl H.refl p = p
equivalent' : ∀ {ν n} (Γ : F.Ctx ν n) r → ⟦ Γ ⟧ctx← ⊢ᵣ ⟦ r ⟧tp← ⇔ (∃ λ t → Γ F.⊢ t ∈ r)
equivalent' Γ r = equivalence
(λ x → ⊢subst
(length-map-toList (map ⟦_⟧tp← Γ)) (tp←→ r) (ctx←→ Γ) (, to-⊢ x))
(λ x → (from-⊢ (proj₂ x)))
| {
"alphanum_fraction": 0.5156685237,
"avg_line_length": 39.3424657534,
"ext": "agda",
"hexsha": "b0ab24b0eb67e95629fc8ea5c585c5b58946538d",
"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/Resolution/Ambiguous/SystemFEquiv.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/Resolution/Ambiguous/SystemFEquiv.agda",
"max_line_length": 89,
"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/Resolution/Ambiguous/SystemFEquiv.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": 1473,
"size": 2872
} |
------------------------------------------------------------------------
-- Pointed and non-pointed ω-cpos
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --safe #-}
module Omega-cpo where
open import Equality.Propositional.Cubical
open import Logical-equivalence using (_⇔_)
open import Prelude hiding (T)
open import Equivalence equality-with-J as Eq using (_≃_)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import Partiality-algebra as PA hiding (_∘_)
import Partiality-monad.Inductive.Monad.Adjunction as PA
-- Possibly non-pointed ω-cpos (with propositional ordering
-- relations).
record ω-cpo p q : Type (lsuc (p ⊔ q)) where
infix 4 _⊑_
-- Partial order axioms.
field
Carrier : Type p
_⊑_ : Carrier → Carrier → Type q
reflexivity : ∀ {x} → x ⊑ x
antisymmetry : ∀ {x y} → x ⊑ y → y ⊑ x → x ≡ y
transitivity : ∀ {x y z} → x ⊑ y → y ⊑ z → x ⊑ z
⊑-propositional : ∀ {x y} → Is-proposition (x ⊑ y)
-- Increasing sequences.
Increasing-sequence : Type (p ⊔ q)
Increasing-sequence = ∃ λ (f : ℕ → Carrier) → ∀ n → f n ⊑ f (suc n)
-- Projection functions for Increasing-sequence.
infix 30 _[_]
_[_] : Increasing-sequence → ℕ → Carrier
_[_] = proj₁
increasing : (s : Increasing-sequence) →
∀ n → (s [ n ]) ⊑ (s [ suc n ])
increasing = proj₂
-- Upper bounds.
Is-upper-bound : Increasing-sequence → Carrier → Type q
Is-upper-bound s x = ∀ n → (s [ n ]) ⊑ x
-- Upper bound axioms.
field
⨆ : Increasing-sequence → Carrier
upper-bound : ∀ s → Is-upper-bound s (⨆ s)
least-upper-bound : ∀ {s ub} → Is-upper-bound s ub → ⨆ s ⊑ ub
-- The carrier type is a set. (This lemma is analogous to
-- Theorem 11.3.9 in "Homotopy Type Theory: Univalent Foundations of
-- Mathematics" (first edition).)
Carrier-is-set : Is-set Carrier
Carrier-is-set = proj₁ $ Eq.propositional-identity≃≡
(λ x y → x ⊑ y × y ⊑ x)
(λ _ _ → ×-closure 1 ⊑-propositional ⊑-propositional)
(λ _ → reflexivity , reflexivity)
(λ x y → uncurry {B = λ _ → y ⊑ x} antisymmetry)
-- Every set can be turned into an ω-cpo.
Set→ω-cpo : ∀ {ℓ} → Set ℓ → ω-cpo ℓ ℓ
Set→ω-cpo (A , A-set) = record
{ Carrier = A
; _⊑_ = _≡_
; reflexivity = refl
; antisymmetry = const
; transitivity = trans
; ⊑-propositional = A-set
; ⨆ = (_$ 0) ∘ proj₁
; upper-bound = uncurry upper-bound
; least-upper-bound = _$ 0
}
where
upper-bound : (f : ℕ → A) → (∀ n → f n ≡ f (suc n)) →
∀ n → f n ≡ f 0
upper-bound f inc zero = refl
upper-bound f inc (suc n) =
f (suc n) ≡⟨ sym (inc n) ⟩
f n ≡⟨ upper-bound f inc n ⟩∎
f 0 ∎
-- Pointed ω-cpos.
record ω-cppo p q : Type (lsuc (p ⊔ q)) where
field
cpo : ω-cpo p q
open ω-cpo cpo public
field
least : Carrier
least⊑ : ∀ {x} → least ⊑ x
-- A pointed ω-CPO is equivalent to a partiality algebra over the
-- empty type.
ω-cppo≃ω-cppo : ∀ {p q} → ω-cppo p q ≃ PA.ω-cppo p q
ω-cppo≃ω-cppo = Eq.↔⇒≃ record
{ surjection = record
{ logical-equivalence = record
{ to = λ X → let open ω-cppo X in record
{ T = Carrier
; partiality-algebra-with = record
{ _⊑_ = _⊑_
; never = least
; now = λ ()
; ⨆ = ⨆
; antisymmetry = antisymmetry
; T-is-set-unused = Carrier-is-set
; ⊑-refl = λ _ → reflexivity
; ⊑-trans = transitivity
; never⊑ = λ _ → least⊑
; upper-bound = upper-bound
; least-upper-bound = λ _ _ → least-upper-bound
; ⊑-propositional = ⊑-propositional
}
}
; from = λ P → let open Partiality-algebra P in record
{ cpo = record
{ Carrier = T
; _⊑_ = _⊑_
; reflexivity = ⊑-refl _
; antisymmetry = antisymmetry
; transitivity = ⊑-trans
; ⊑-propositional = ⊑-propositional
; ⨆ = ⨆
; upper-bound = upper-bound
; least-upper-bound = least-upper-bound _ _
}
; least = never
; least⊑ = never⊑ _
}
}
; right-inverse-of = λ P →
let open Partiality-algebra P in
cong₂ (λ now (T-is-set : Is-set T) → record
{ T = T
; partiality-algebra-with = record
{ _⊑_ = _⊑_
; never = never
; now = now
; ⨆ = ⨆
; antisymmetry = antisymmetry
; T-is-set-unused = T-is-set
; ⊑-refl = ⊑-refl
; ⊑-trans = ⊑-trans
; never⊑ = never⊑
; upper-bound = upper-bound
; least-upper-bound = least-upper-bound
; ⊑-propositional = ⊑-propositional
}
})
(⟨ext⟩ λ ())
(H-level-propositional ext 2 _ _)
}
; left-inverse-of = λ _ → refl
}
| {
"alphanum_fraction": 0.4507140369,
"avg_line_length": 32.8114285714,
"ext": "agda",
"hexsha": "bb9b28cf5604005fc801bc6c6a3386d00911ae34",
"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/Omega-cpo.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/Omega-cpo.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/Omega-cpo.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": 1651,
"size": 5742
} |
open import Nat
open import Prelude
open import dynamics-core
open import contexts
open import lemmas-consistency
open import type-assignment-unicity
open import lemmas-progress-checks
-- taken together, the theorems in this file argue that for any expression
-- d, at most one summand of the labeled sum that results from progress may
-- be true at any time: that boxed values, indeterminates, and expressions
-- that step are pairwise disjoint.
--
-- note that as a consequence of currying and comutativity of products,
-- this means that there are three theorems to prove. in addition to those,
-- we also prove several convenince forms that combine theorems about
-- indeterminate and boxed value forms into the same statement about final
-- forms, which mirrors the mutual definition of indeterminate and final
-- and saves some redundant argumentation.
module progress-checks where
-- boxed values are not indeterminates
boxedval-not-indet : ∀{d} → d boxedval → d indet → ⊥
boxedval-not-indet (BVVal VNum) ()
boxedval-not-indet (BVVal VLam) ()
boxedval-not-indet (BVArrCast x bv) (ICastArr x₁ ind) = boxedval-not-indet bv ind
boxedval-not-indet (BVHoleCast x bv) (ICastGroundHole x₁ ind) = boxedval-not-indet bv ind
boxedval-not-indet (BVHoleCast x bv) (ICastHoleGround x₁ ind x₂) = boxedval-not-indet bv ind
boxedval-not-indet (BVVal (VInl x)) (IInl ind) = boxedval-not-indet (BVVal x) ind
boxedval-not-indet (BVVal (VInr x)) (IInr ind) = boxedval-not-indet (BVVal x) ind
boxedval-not-indet (BVInl bv) (IInl ind) = boxedval-not-indet bv ind
boxedval-not-indet (BVInr bv) (IInr ind) = boxedval-not-indet bv ind
boxedval-not-indet (BVSumCast x bv) (ICastSum x₁ ind) = boxedval-not-indet bv ind
boxedval-not-indet (BVVal (VPair x x₂)) (IPair1 ind x₁) = boxedval-not-indet (BVVal x) ind
boxedval-not-indet (BVVal (VPair x x₂)) (IPair2 x₁ ind) = boxedval-not-indet (BVVal x₂) ind
boxedval-not-indet (BVPair bv bv₁) (IPair1 ind x) = boxedval-not-indet bv ind
boxedval-not-indet (BVPair bv bv₁) (IPair2 x ind) = boxedval-not-indet bv₁ ind
boxedval-not-indet (BVProdCast x bv) (ICastProd x₁ ind) = boxedval-not-indet bv ind
-- boxed values don't step
boxedval-not-step : ∀{d} → d boxedval → (Σ[ d' ∈ ihexp ] (d ↦ d')) → ⊥
boxedval-not-step (BVVal VNum) (d' , Step FHOuter () x₃)
boxedval-not-step (BVVal VLam) (d' , Step FHOuter () x₃)
boxedval-not-step (BVArrCast x bv) (d0' , Step FHOuter (ITCastID) FHOuter) = x refl
boxedval-not-step (BVArrCast x bv) (_ , Step (FHCast x₁) x₂ (FHCast x₃)) = boxedval-not-step bv (_ , Step x₁ x₂ x₃)
boxedval-not-step (BVHoleCast () bv) (d' , Step FHOuter (ITCastID) FHOuter)
boxedval-not-step (BVHoleCast x bv) (d' , Step FHOuter (ITCastSucceed ()) FHOuter)
boxedval-not-step (BVHoleCast GArrHole bv) (_ , Step FHOuter (ITGround (MGArr x)) FHOuter) = x refl
boxedval-not-step (BVHoleCast x bv) (_ , Step (FHCast x₁) x₂ (FHCast x₃)) = boxedval-not-step bv (_ , Step x₁ x₂ x₃)
boxedval-not-step (BVHoleCast x x₁) (_ , Step FHOuter (ITExpand ()) FHOuter)
boxedval-not-step (BVHoleCast x x₁) (_ , Step FHOuter (ITCastFail x₂ () x₄) FHOuter)
boxedval-not-step (BVVal (VInl x)) (_ , Step FHOuter () x₃)
boxedval-not-step (BVVal (VInr x)) (_ , Step FHOuter () x₃)
boxedval-not-step (BVInl bv) (_ , Step FHOuter () x₂)
boxedval-not-step (BVInr bv) (_ , Step FHOuter () x₂)
boxedval-not-step (BVSumCast x bv) (_ , Step FHOuter ITCastID FHOuter) = x refl
boxedval-not-step (BVSumCast x bv) (_ , Step (FHCast x₁) x₂ (FHCast x₃)) = boxedval-not-step bv (_ , Step x₁ x₂ x₃)
boxedval-not-step (BVHoleCast GNum bv) (_ , Step FHOuter (ITGround ()) FHOuter)
boxedval-not-step (BVHoleCast GSumHole bv) (_ , Step FHOuter (ITGround (MGSum x)) FHOuter) = x refl
boxedval-not-step (BVVal (VInl x)) (_ , Step (FHInl x₁) x₂ (FHInl x₃)) = boxedval-not-step (BVVal x) (_ , Step x₁ x₂ x₃)
boxedval-not-step (BVVal (VInr x)) (_ , Step (FHInr x₁) x₂ (FHInr x₃)) = boxedval-not-step (BVVal x) (_ , Step x₁ x₂ x₃)
boxedval-not-step (BVInl bv) (_ , Step (FHInl x) x₁ (FHInl x₂)) = boxedval-not-step bv (_ , Step x x₁ x₂)
boxedval-not-step (BVInr bv) (_ , Step (FHInr x) x₁ (FHInr x₂)) = boxedval-not-step bv (_ , Step x x₁ x₂)
boxedval-not-step (BVVal (VPair x x₁)) (_ , Step (FHPair1 x₂) x₃ (FHPair1 x₄)) = boxedval-not-step (BVVal x) (_ , Step x₂ x₃ x₄)
boxedval-not-step (BVVal (VPair x x₁)) (_ , Step (FHPair2 x₂) x₃ (FHPair2 x₄)) = boxedval-not-step (BVVal x₁) (_ , (Step x₂ x₃ x₄))
boxedval-not-step (BVPair bv bv₁) (_ , Step (FHPair1 x) x₁ (FHPair1 x₂)) = boxedval-not-step bv (_ , Step x x₁ x₂)
boxedval-not-step (BVPair bv bv₁) (_ , Step (FHPair2 x) x₁ (FHPair2 x₂)) = boxedval-not-step bv₁ (_ , Step x x₁ x₂)
boxedval-not-step (BVProdCast x bv) (_ , Step FHOuter ITCastID FHOuter) = x refl
boxedval-not-step (BVProdCast x bv) (_ , Step (FHCast x₁) x₂ (FHCast x₃)) = boxedval-not-step bv (_ , Step x₁ x₂ x₃)
boxedval-not-step (BVHoleCast GProdHole bv) (_ , Step FHOuter (ITGround (MGProd x)) FHOut\er) = x refl
mutual
-- indeterminates don't step
indet-not-step : ∀{d} → d indet → (Σ[ d' ∈ ihexp ] (d ↦ d')) → ⊥
indet-not-step IEHole (d' , Step FHOuter () FHOuter)
indet-not-step (INEHole x) (d' , Step FHOuter () FHOuter)
indet-not-step (INEHole x) (_ , Step (FHNEHole x₁) x₂ (FHNEHole x₃)) = final-sub-not-trans x x₁ x₂
indet-not-step (IAp x₁ () x₂) (_ , Step FHOuter (ITLam) FHOuter)
indet-not-step (IAp x (ICastArr x₁ ind) x₂) (_ , Step FHOuter (ITApCast) FHOuter) = x _ _ _ _ _ refl
indet-not-step (IAp x ind _) (_ , Step (FHAp1 x₂) x₃ (FHAp1 x₄)) = indet-not-step ind (_ , Step x₂ x₃ x₄)
indet-not-step (IAp x ind f) (_ , Step (FHAp2 x₃) x₄ (FHAp2 x₆)) = final-not-step f (_ , Step x₃ x₄ x₆)
indet-not-step (ICastArr x ind) (d0' , Step FHOuter (ITCastID) FHOuter) = x refl
indet-not-step (ICastArr x ind) (_ , Step (FHCast x₁) x₂ (FHCast x₃)) = indet-not-step ind (_ , Step x₁ x₂ x₃)
indet-not-step (ICastGroundHole () ind) (d' , Step FHOuter (ITCastID) FHOuter)
indet-not-step (ICastGroundHole x ind) (d' , Step FHOuter (ITCastSucceed ()) FHOuter)
indet-not-step (ICastGroundHole GArrHole ind) (_ , Step FHOuter (ITGround (MGArr x₁)) FHOuter) = x₁ refl
indet-not-step (ICastGroundHole x ind) (_ , Step (FHCast x₁) x₂ (FHCast x₃)) = indet-not-step ind (_ , Step x₁ x₂ x₃)
indet-not-step (ICastHoleGround x ind ()) (d' , Step FHOuter (ITCastID ) FHOuter)
indet-not-step (ICastHoleGround x ind g) (d' , Step FHOuter (ITCastSucceed x₂) FHOuter) = x _ _ refl
indet-not-step (ICastHoleGround x ind GArrHole) (_ , Step FHOuter (ITExpand (MGArr x₂)) FHOuter) = x₂ refl
indet-not-step (ICastHoleGround x ind g) (_ , Step (FHCast x₁) x₂ (FHCast x₃)) = indet-not-step ind (_ , Step x₁ x₂ x₃)
indet-not-step (ICastGroundHole x x₁) (_ , Step FHOuter (ITExpand ()) FHOuter)
indet-not-step (ICastHoleGround x x₁ x₂) (_ , Step FHOuter (ITGround ()) FHOuter)
indet-not-step (ICastGroundHole x x₁) (_ , Step FHOuter (ITCastFail x₂ () x₄) FHOuter)
indet-not-step (ICastHoleGround x x₁ x₂) (_ , Step FHOuter (ITCastFail x₃ x₄ x₅) FHOuter) = x _ _ refl
indet-not-step (IFailedCast x x₁ x₂ x₃) (d' , Step FHOuter () FHOuter)
indet-not-step (IFailedCast x x₁ x₂ x₃) (_ , Step (FHFailedCast x₄) x₅ (FHFailedCast x₆)) = final-not-step x (_ , Step x₄ x₅ x₆)
indet-not-step (IPlus1 () x₄) (_ , Step FHOuter (ITPlus x₁) FHOuter)
indet-not-step (IPlus1 x x₄) (_ , Step (FHPlus1 x₁) x₂ (FHPlus1 x₃)) = indet-not-step x (_ , Step x₁ x₂ x₃)
indet-not-step (IPlus1 x x₄) (.(_ ·+ _) , Step (FHPlus2 x₁) x₂ (FHPlus2 x₃)) = final-not-step x₄ (_ , Step x₁ x₂ x₃)
indet-not-step (IPlus2 x ()) (_ , Step FHOuter (ITPlus x₁) FHOuter)
indet-not-step (IPlus2 x x₄) (_ , Step (FHPlus1 x₁) x₂ (FHPlus1 x₃)) = final-not-step x (_ , Step x₁ x₂ x₃)
indet-not-step (IPlus2 x x₄) (_ , Step (FHPlus2 x₁) x₂ (FHPlus2 x₃)) = indet-not-step x₄ (_ , Step x₁ x₂ x₃)
indet-not-step (IInl ind) (_ , Step FHOuter () x₂)
indet-not-step (IInl ind) (_ , Step (FHInl x) x₁ (FHInl x₂)) = indet-not-step ind (_ , Step x x₁ x₂)
indet-not-step (IInr ind) (_ , Step FHOuter () x₂)
indet-not-step (IInr ind) (_ , Step (FHInr x) x₁ (FHInr x₂)) = indet-not-step ind (_ , Step x x₁ x₂)
indet-not-step (ICase x x₁ x₂ ind) (_ , Step FHOuter ITCaseInl x₅) = x _ _ refl
indet-not-step (ICase x x₁ x₂ ind) (_ , Step FHOuter ITCaseInr x₅) = x₁ _ _ refl
indet-not-step (ICase x x₁ x₂ ind) (_ , Step FHOuter ITCaseCast x₅) = x₂ _ _ _ _ _ refl
indet-not-step (ICase x x₁ x₂ ind) (_ , Step (FHCase x₃) x₄ (FHCase x₅)) = indet-not-step ind (_ , Step x₃ x₄ x₅)
indet-not-step (ICastSum x ind) (_ , Step FHOuter ITCastID FHOuter) = x refl
indet-not-step (ICastSum x ind) (_ , Step (FHCast x₁) x₂ (FHCast x₃)) = indet-not-step ind (_ , Step x₁ x₂ x₃)
indet-not-step (ICastGroundHole GNum ind) (_ , Step FHOuter (ITGround ()) FHOuter)
indet-not-step (ICastGroundHole GSumHole ind) (_ , Step FHOuter (ITGround (MGSum x)) FHOuter) = x refl
indet-not-step (ICastHoleGround x ind GNum) (_ , Step FHOuter (ITExpand ()) FHOuter)
indet-not-step (ICastHoleGround x ind GSumHole) (_ , Step FHOuter (ITExpand (MGSum x₁)) FHOuter) = x₁ refl
indet-not-step (IPair1 ind x) (_ , Step (FHPair1 x₁) x₂ (FHPair1 x₃)) = indet-not-step ind (_ , Step x₁ x₂ x₃)
indet-not-step (IPair1 ind x) (_ , Step (FHPair2 x₁) x₂ (FHPair2 x₃)) = final-not-step x (_ , Step x₁ x₂ x₃)
indet-not-step (IPair2 x ind) (_ , Step (FHPair1 x₁) x₂ (FHPair1 x₃)) = final-not-step x (_ , Step x₁ x₂ x₃)
indet-not-step (IPair2 x ind) (_ , Step (FHPair2 x₁) x₂ (FHPair2 x₃)) = indet-not-step ind (_ , Step x₁ x₂ x₃)
indet-not-step (IFst x x₁ ind) (_ , Step FHOuter ITFstPair FHOuter) = x _ _ refl
indet-not-step (IFst x x₁ ind) (_ , Step (FHFst x₂) x₃ (FHFst x₄)) = indet-not-step ind (_ , Step x₂ x₃ x₄)
indet-not-step (ISnd x x₁ ind) (_ , Step FHOuter ITSndPair FHOuter) = x _ _ refl
indet-not-step (ISnd x x₁ ind) (_ , Step (FHSnd x₂) x₃ (FHSnd x₄)) = indet-not-step ind (_ , Step x₂ x₃ x₄)
indet-not-step (ICastGroundHole GProdHole ind) (_ , Step FHOuter (ITGround (MGProd x)) FHOuter) = x refl
indet-not-step (ICastHoleGround x ind GProdHole) (_ , Step FHOuter (ITExpand (MGProd x₁)) FHOuter) = x₁ refl
indet-not-step (IPair1 ind x) (_ , Step FHOuter () FHOuter)
indet-not-step (IPair2 x ind) (_ , Step FHOuter () FHOuter)
indet-not-step (IFst x x₁ ind) (_ , Step FHOuter ITFstCast FHOuter) = x₁ _ _ _ _ _ refl
indet-not-step (ISnd x x₁ ind) (_ , Step FHOuter ITSndCast FHOuter) = x₁ _ _ _ _ _ refl
indet-not-step (ICastProd x ind) (_ , Step FHOuter ITCastID FHOuter) = x refl
indet-not-step (ICastProd x ind) (_ , Step (FHCast x₁) x₂ (FHCast x₃)) = indet-not-step ind (_ , Step x₁ x₂ x₃)
-- final expressions don't step
final-not-step : ∀{d} → d final → Σ[ d' ∈ ihexp ] (d ↦ d') → ⊥
final-not-step (FBoxedVal x) stp = boxedval-not-step x stp
final-not-step (FIndet x) stp = indet-not-step x stp
| {
"alphanum_fraction": 0.6728735424,
"avg_line_length": 79.5899280576,
"ext": "agda",
"hexsha": "a79f50575b706fb913d8b7688d8f7afc771caaf1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-agda",
"max_forks_repo_path": "progress-checks.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazelnut-agda",
"max_issues_repo_path": "progress-checks.agda",
"max_line_length": 133,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnut-agda",
"max_stars_repo_path": "progress-checks.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4170,
"size": 11063
} |
module Metalogic.Constructive.Provability where
open import Sets.BoolSet
open import Functional
import Lvl
open import Type
-- Structural rules
record Structural {ℓ ℓₘ} {Formula : Type{ℓ}} (_⊢_ : BoolSet(Formula) → Formula → Type{ℓₘ}) : Type{ℓₘ Lvl.⊔ ℓ} where
field
assumption : ∀{Γ}{φ} → (φ ∈ Γ) → (Γ ⊢ φ)
module Propositional {ℓ ℓₘ} {Formula : Type{ℓ}} (_⊢_ : BoolSet(Formula) → Formula → Type{ℓₘ}) where
-- Rules of bottom
record Bottom : Type{ℓₘ Lvl.⊔ ℓ} where
field
⊥ : Formula
field
intro : ∀{Γ}{φ} → (Γ ⊢ φ) → ((Γ ∪ singleton(φ)) ⊢ ⊥) → (Γ ⊢ ⊥)
elim : ∀{Γ}{φ} → (⊥ ∈ Γ) → (Γ ⊢ φ)
-- Rules of top
record Top : Type{ℓₘ Lvl.⊔ ℓ} where
field
⊤ : Formula
field
intro : ∀{Γ} → (Γ ⊢ ⊤)
-- Rules of conjunction
record Conjunction : Type{ℓₘ Lvl.⊔ ℓ} where
infixl 1005 _∧_
field
_∧_ : Formula → Formula → Formula
field
intro : ∀{Γ}{φ₁ φ₂} → (Γ ⊢ φ₁) → (Γ ⊢ φ₂) → (Γ ⊢ (φ₁ ∧ φ₂))
elimₗ : ∀{Γ}{φ₁ φ₂} → (Γ ⊢ (φ₁ ∧ φ₂)) → (Γ ⊢ φ₁)
elimᵣ : ∀{Γ}{φ₁ φ₂} → (Γ ⊢ (φ₁ ∧ φ₂)) → (Γ ⊢ φ₂)
-- Rules of implication
record Implication : Type{ℓₘ Lvl.⊔ ℓ} where
infixl 1000 _⟶_
field
_⟶_ : Formula → Formula → Formula
field
intro : ∀{Γ}{φ₁ φ₂} → ((Γ ∪ singleton(φ₁)) ⊢ φ₂) → (Γ ⊢ (φ₁ ⟶ φ₂))
elim : ∀{Γ}{φ₁ φ₂} → (Γ ⊢ (φ₁ ⟶ φ₂)) → (Γ ⊢ φ₁) → (Γ ⊢ φ₂)
-- Rules of reversed implication
record Consequence : Type{ℓₘ Lvl.⊔ ℓ} where
infixl 1000 _⟵_
field
_⟵_ : Formula → Formula → Formula
field
intro : ∀{Γ}{φ₁ φ₂} → ((Γ ∪ singleton(φ₁)) ⊢ φ₂) → (Γ ⊢ (φ₂ ⟵ φ₁))
elim : ∀{Γ}{φ₁ φ₂} → (Γ ⊢ (φ₂ ⟵ φ₁)) → (Γ ⊢ φ₁) → (Γ ⊢ φ₂)
-- Rules of equivalence
record Equivalence : Type{ℓₘ Lvl.⊔ ℓ} where
infixl 1000 _⟷_
field
_⟷_ : Formula → Formula → Formula
field
intro : ∀{Γ}{φ₁ φ₂} → ((Γ ∪ singleton(φ₂)) ⊢ φ₁) → ((Γ ∪ singleton(φ₁)) ⊢ φ₂) → (Γ ⊢ (φ₁ ⟷ φ₂))
elimₗ : ∀{Γ}{φ₁ φ₂} → (Γ ⊢ (φ₁ ⟷ φ₂)) → (Γ ⊢ φ₂) → (Γ ⊢ φ₁)
elimᵣ : ∀{Γ}{φ₁ φ₂} → (Γ ⊢ (φ₁ ⟷ φ₂)) → (Γ ⊢ φ₁) → (Γ ⊢ φ₂)
-- Rules of disjunction
record Disjunction : Type{ℓₘ Lvl.⊔ ℓ} where
infixl 1004 _∨_
field
_∨_ : Formula → Formula → Formula
field
introₗ : ∀{Γ}{φ₁ φ₂} → (Γ ⊢ φ₁) → (Γ ⊢ (φ₁ ∨ φ₂))
introᵣ : ∀{Γ}{φ₁ φ₂} → (Γ ⊢ φ₂) → (Γ ⊢ (φ₁ ∨ φ₂))
elim : ∀{Γ}{φ₁ φ₂ φ₃} → (Γ ⊢ (φ₁ ∨ φ₂)) → ((Γ ∪ singleton(φ₁)) ⊢ φ₃) → ((Γ ∪ singleton(φ₂)) ⊢ φ₃) → (Γ ⊢ φ₃)
-- Rules of negation
record Negation ⦃ _ : Bottom ⦄ : Type{ℓₘ Lvl.⊔ ℓ} where
open Bottom ⦃ ... ⦄
infixl 1010 ¬_
field
¬_ : Formula → Formula
field
intro : ∀{Γ}{φ} → ((Γ ∪ singleton(φ)) ⊢ ⊥) → (Γ ⊢ (¬ φ))
elim : ∀{Γ}{φ} → (Γ ⊢ (¬ φ)) → (Γ ⊢ φ) → (Γ ⊢ ⊥)
-- A theory of constructive propositional logic expressed using natural deduction rules
record Theory : Type{ℓₘ Lvl.⊔ ℓ} where
open Structural ⦃ ... ⦄ public
open Conjunction ⦃ ... ⦄ renaming (intro to [∧]-intro ; elimₗ to [∧]-elimₗ ; elimᵣ to [∧]-elimᵣ) public
open Disjunction ⦃ ... ⦄ renaming (introₗ to [∨]-introₗ ; introᵣ to [∨]-introᵣ ; elim to [∨]-elim) public
open Implication ⦃ ... ⦄ renaming (intro to [→]-intro ; elim to [→]-elim) public
open Consequence ⦃ ... ⦄ renaming (intro to [←]-intro ; elim to [←]-elim) public
open Equivalence ⦃ ... ⦄ renaming (intro to [↔]-intro ; elimₗ to [↔]-elimₗ ; elimᵣ to [↔]-elimᵣ) public
open Negation ⦃ ... ⦄ renaming (intro to [¬]-intro ; elim to [¬]-elim) public
open Bottom ⦃ ... ⦄ renaming (intro to [⊥]-intro ; elim to [⊥]-elim) public
open Top ⦃ ... ⦄ renaming (intro to [⊤]-intro) public
field
⦃ bottom ⦄ : Bottom
⦃ top ⦄ : Top
⦃ conjunction ⦄ : Conjunction
⦃ disjunction ⦄ : Disjunction
⦃ implication ⦄ : Implication
⦃ consequence ⦄ : Consequence
⦃ equivalence ⦄ : Equivalence
⦃ negation ⦄ : Negation
module Predicate {ℓₘₗₛ ℓₘₒₛ ℓₘₗ ℓₘₒ} {Formula : Type{ℓₘₗₛ Lvl.⊔ ℓₘₒₛ}} {Domain : Type{ℓₘₒₛ}} (Proof : Formula → Type{ℓₘₗ Lvl.⊔ ℓₘₒ}) (Construct : Domain → Type{ℓₘₒ}) where
open Propositional(Proof) renaming (Theory to PropositionalTheory)
record UniversalQuantification : Type{(ℓₘₗ Lvl.⊔ ℓₘₒ) Lvl.⊔ (ℓₘₗₛ Lvl.⊔ ℓₘₒₛ)} where
field
∀ₗ : (Domain → Formula) → Formula
field
intro : ∀{P : Domain → Formula} → (∀{x : Domain} → Proof(P(x))) → Proof(∀ₗ P)
elim : ∀{P : Domain → Formula} → Proof(∀ₗ P) → (∀{x : Domain} → Proof(P(x)))
record ExistentialQuantification : Type{(ℓₘₗ Lvl.⊔ ℓₘₒ) Lvl.⊔ (ℓₘₗₛ Lvl.⊔ ℓₘₒₛ)} where
field
∃ₗ : (Domain → Formula) → Formula
field
intro : ∀{P : Domain → Formula}{a} → Proof(P(a)) → Proof(∃ₗ P)
elim : ∀{P : Domain → Formula}{Z : Formula} → (∀{x : Domain} → Proof(P(x)) → Proof(Z)) → Proof(∃ₗ P) → Proof(Z)
-- A theory of constructive predicate/(first-order) logic expressed using natural deduction rules
record Theory : Type{(ℓₘₗ Lvl.⊔ ℓₘₒ) Lvl.⊔ (ℓₘₗₛ Lvl.⊔ ℓₘₒₛ)} where
open Propositional.Theory ⦃ ... ⦄ public
open UniversalQuantification ⦃ ... ⦄ renaming (intro to [∀]-intro ; elim to [∀]-elim) public
open ExistentialQuantification ⦃ ... ⦄ renaming (intro to [∃]-intro ; elim to [∃]-elim) public
field
⦃ propositional ⦄ : PropositionalTheory
⦃ universalQuantification ⦄ : UniversalQuantification
⦃ existentialQuantification ⦄ : ExistentialQuantification
| {
"alphanum_fraction": 0.5504939627,
"avg_line_length": 35.7254901961,
"ext": "agda",
"hexsha": "6393979abb0610889784308eca6fa7b9a8f38dc0",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "old/Metalogic/Constructive/Provability.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "old/Metalogic/Constructive/Provability.agda",
"max_line_length": 171,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "old/Metalogic/Constructive/Provability.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": 2444,
"size": 5466
} |
module Function.Iteration.Order where
open import Data
open import Data.Boolean.Stmt
open import Functional renaming (id to id-fn)
open import Function.Iteration hiding (_^_)
open import Function.Iteration.Proofs
open import Logic
open import Logic.IntroInstances
open import Logic.Propositional
open import Logic.Propositional.Theorems
open import Logic.Predicate
import Lvl
open import Numeral.Natural
open import Numeral.Natural.Oper hiding (_^_)
open import Numeral.Natural.Oper.Comparisons
open import Numeral.Natural.Oper.DivMod.Proofs
open import Numeral.Natural.Oper.FlooredDivision
open import Numeral.Natural.Oper.Modulo
open import Numeral.Natural.Oper.Modulo.Proofs
open import Numeral.Natural.Relation.Divisibility
open import Numeral.Natural.Relation.Divisibility.Proofs
open import Numeral.Natural.Relation.Order.Decidable
open import Numeral.Natural.Relation.Order.Proofs
open import Numeral.Natural.Relation.Order
open import Relator.Equals using () renaming (_≡_ to _≡ₑ_ ; _≢_ to _≢ₑ_ ; [≡]-intro to [≡ₑ]-intro)
open import Structure.Setoid
open import Structure.Function.Domain
open import Structure.Function
open import Structure.Operator.Properties
open import Structure.Operator.Proofs
open import Structure.Operator
open import Structure.Relator.Properties
open import Structure.Relator.Ordering
open import Structure.Relator.Ordering.Lattice
open import Syntax.Transitivity
open import Type
open import Type.Properties.Decidable.Proofs
open import Type.Properties.Empty
open import Type.Size.Finite
private variable ℓ ℓₑ : Lvl.Level
private variable T : Type{ℓ}
module _ ⦃ equiv-T : Equiv{ℓₑ}(T) ⦄ (_▫_ : T → T → T) ⦃ op : BinaryOperator(_▫_) ⦄ {id} ⦃ ident : Identity(_▫_)(id) ⦄ ⦃ assoc : Associativity(_▫_) ⦄ where
-- Operator alias for iterated application of an operator with an element.
_^_ : T → ℕ → T
x ^ n = Function.Iteration.repeatₗ(n)(_▫_)(id)(x)
-- `FiniteOrder(x)(n)` means that the element `x` is of order `n`.
-- It is finite in the sense that it is a number and not infinite.
-- An element's order is the smallest positive integer power of x such that the result is the identity element.
data FiniteOrder (x : T) : ℕ → Stmt{ℓₑ} where
intro : ∀{n} → LE.Minimum(_≤_)(n ↦ x ^ 𝐒(n) ≡ id)(n) → FiniteOrder(x)(𝐒(n))
-- `Ord(x)` means that the element `x` has a finite order.
Ord : T → Stmt
Ord(x) = ∃(FiniteOrder(x))
-- `ord(x)` is the order of x (when it is finite).
ord : (x : T) → ⦃ _ : Ord(x) ⦄ → ℕ
ord(_) ⦃ [∃]-intro n ⦄ = n
module _ {x : T} where
-- An order is never 0 by definition.
finite-order-0 : ¬ FiniteOrder(x)(𝟎)
finite-order-0 ()
-- An element power its order is the identity element.
[^]-by-ord : ⦃ p : Ord(x) ⦄ → (x ^ ord(x) ⦃ p ⦄ ≡ id)
[^]-by-ord ⦃ [∃]-intro (𝐒(_)) ⦃ intro p ⦄ ⦄ = LE.Minimum.membership{_≤_ = _≤_}(p)
-- When an element power something is the identity element, then the power is either zero or greater/equal its order.
ord-is-minimum : ⦃ p : Ord(x) ⦄ → ∀{n} → (x ^ n ≡ id) → (n ≡ₑ 𝟎) ∨ (ord(x) ⦃ p ⦄ ≤ n)
ord-is-minimum ⦃ [∃]-intro (_) ⦃ intro p ⦄ ⦄ {𝟎} x0id = [∨]-introₗ [≡ₑ]-intro
ord-is-minimum ⦃ [∃]-intro .(𝐒 po) ⦃ intro {po} p ⦄ ⦄ {𝐒 n} xsnid = [∨]-introᵣ ([≤]-with-[𝐒] ⦃ LE.Minimum.proof{_≤_ = _≤_}(p) ⦃ xsnid ⦄ ⦄)
-- When an element power something less than its order and it is the identity element, then the power is 0.
ord-is-minimum-but-0 : ⦃ p : Ord(x) ⦄ → ∀{n} → (x ^ n ≡ id) → (n < ord(x) ⦃ p ⦄) → (n ≡ₑ 𝟎)
ord-is-minimum-but-0 ⦃ p ⦄ {𝟎} _ _ = [≡ₑ]-intro
ord-is-minimum-but-0 ⦃ p ⦄ {𝐒(n)} xnid nord with ord-is-minimum ⦃ p ⦄ {𝐒(n)} xnid
... | [∨]-introᵣ ordsn = [⊥]-elim([<]-to-[≱] nord (ordsn))
-- An order is never 0.
ord-non-zero : ⦃ p : Ord(x) ⦄ → (ord(x) ⦃ p ⦄ ≢ₑ 𝟎)
ord-non-zero ⦃ [∃]-intro 𝟎 ⦃ ⦄ ⦄ [≡ₑ]-intro
-- Iteration (_^_) distributes to the right.
-- Can also be seen as iteration preserving from addition to the operation.
[^]-by-add : ∀{a b} → ((x ^ a) ▫ (x ^ b) ≡ x ^ (a + b))
[^]-by-add {a}{b} = repeatₗ-by-sum {X = T}{_▫_}{x}{id}{a}{b}
-- Nested iterations can join to be a product.
[^]-by-product : ∀{a b} → ((((x ^ a)) ^ b) ≡ x ^ (a ⋅ b))
[^]-by-product {a}{b} = repeatₗ-by-product {X = T}{_▫_}{x}{id}{a}{b}
-- When powering a difference yields the identity element, the powered elements are the same.
[^]-by-distanceₗ : ∀{a b} → (x ^ a ≡ x ^ b) ← (x ^ (a 𝄩 b) ≡ id)
[^]-by-distanceₗ {a}{b} = repeatₗ-by-distanceₗ {X = T}{_▫_}{x}{id}{a}{b}
-- Theorems where `n` is a power which yields an identity element.
module _ {n} (n-id : (x ^ n ≡ id)) where
-- Adding something to `n` is only leaving the something behind.
[^]-by-id-add : ∀{a} → (x ^ (n + a) ≡ x ^ a)
[^]-by-id-add {a} =
x ^ (n + a) 🝖-[ symmetry(_≡_) ([^]-by-add {n}{a}) ]
(x ^ n) ▫ (x ^ a) 🝖-[ congruence₂ₗ(_▫_)(_) n-id ]
id ▫ (x ^ a) 🝖-[ identityₗ(_▫_)(id) ]
x ^ a 🝖-end
-- Multiplying something by `n` is still the identity element.
[^]-by-id-multiple : ∀{a} → (x ^ (n ⋅ a) ≡ id)
[^]-by-id-multiple {𝟎} = repeatₗ-by-0 {X = T}{_▫_}{x}{id}
[^]-by-id-multiple {𝐒(a)} =
x ^ (n + (n ⋅ a)) 🝖-[ symmetry(_≡_) ([^]-by-add {n}{n ⋅ a}) ]
(x ^ n) ▫ (x ^ (n ⋅ a)) 🝖-[ congruence₂(_▫_) n-id ([^]-by-id-multiple {a}) ]
id ▫ id 🝖-[ identityₗ(_▫_)(id) ]
id 🝖-end
-- A power yields an identity element only when it is a multiple of the order of the element.
[^]-id-when-div : ⦃ p : Ord(x) ⦄ → ∀{n} → (x ^ n ≡ id) ↔ (ord(x) ⦃ p ⦄ ∣ n)
[^]-id-when-div ⦃ p ⦄ {n} = [↔]-intro (l{n}) (r{n}) where
l : ∀{n} → (x ^ n ≡ id) ← (ord(x) ⦃ p ⦄ ∣ n)
l {.0} Div𝟎 = repeatₗ-by-0 {X = T}{_▫_}{x}{id}
l {.(ord(x) ⦃ p ⦄ + n)} (Div𝐒 {_}{n} div) =
x ^ (ord x ⦃ p ⦄ + n) 🝖-[ symmetry(_≡_) ([^]-by-add {ord(x) ⦃ p ⦄}{n}) ]
(x ^ ord x ⦃ p ⦄) ▫ (x ^ n) 🝖-[ congruence₂(_▫_) ([^]-by-ord ⦃ p ⦄) (l{n} div) ]
id ▫ id 🝖-[ identityₗ(_▫_)(id) ]
id 🝖-end
r : ∀{n} → (x ^ n ≡ id) → (ord(x) ⦃ p ⦄ ∣ n)
r {𝟎} _ = Div𝟎
r {𝐒(n)} xnid = [↔]-to-[→] mod-divisibility mod-is-0 where
open import Relator.Equals.Proofs.Equiv using ([≡]-to-equivalence)
instance
ord-non-zero-comp : IsTrue(ord(x) ⦃ p ⦄ ≢? 𝟎)
ord-non-zero-comp = [↔]-to-[→] decider-true (ord-non-zero ⦃ p ⦄)
instance
ord-positive : IsTrue(positive?(ord(x) ⦃ p ⦄))
ord-positive with ord(x) ⦃ p ⦄ | [∃]-proof p
... | 𝟎 | pp = finite-order-0 pp
... | 𝐒 _ | _ = <>
instance
ord-n-ineq : ord(x) ⦃ p ⦄ ≤ 𝐒(n)
ord-n-ineq with ord-is-minimum ⦃ p ⦄ {𝐒(n)} xnid
ord-n-ineq | [∨]-introₗ ()
ord-n-ineq | [∨]-introᵣ proof = proof
mod-is-id : x ^ (𝐒(n) mod ord(x) ⦃ p ⦄) ≡ id
mod-is-id =
x ^ (𝐒(n) mod ord(x) ⦃ p ⦄) 🝖-[ symmetry(_≡_) (identityₗ(_▫_)(id)) ]
id ▫ (x ^ (𝐒(n) mod ord(x) ⦃ p ⦄)) 🝖-[ congruence₂ₗ(_▫_)(_) (symmetry(_≡_) ([^]-by-id-multiple {ord(x) ⦃ p ⦄} ([^]-by-ord ⦃ p ⦄) {𝐒(n) ⌊/⌋ ord(x) ⦃ p ⦄})) ]
(x ^ ((ord(x) ⦃ p ⦄) ⋅ (𝐒(n) ⌊/⌋ ord(x) ⦃ p ⦄))) ▫ (x ^ (𝐒(n) mod ord(x) ⦃ p ⦄)) 🝖-[ [^]-by-add {(ord(x) ⦃ p ⦄) ⋅ (𝐒(n) ⌊/⌋ ord(x) ⦃ p ⦄)} {𝐒(n) mod ord(x) ⦃ p ⦄} ]
x ^ (((ord(x) ⦃ p ⦄) ⋅ (𝐒(n) ⌊/⌋ ord(x) ⦃ p ⦄)) + (𝐒(n) mod ord(x) ⦃ p ⦄)) 🝖-[ congruence₁(x ^_) ⦃ Relator.Equals.Proofs.Equiv.[≡]-to-function ⦄ ([≡]-to-equivalence([⌊/⌋][mod]-is-division-with-remainder-pred-commuted{𝐒(n)}{ord(x) ⦃ p ⦄})) ]
x ^ 𝐒(n) 🝖-[ xnid ]
id 🝖-end
mod-is-0 : 𝐒(n) mod ord(x) ⦃ p ⦄ ≡ 𝟎
mod-is-0 = ord-is-minimum-but-0 ⦃ p ⦄ mod-is-id mod-maxᵣ
module _ {inv} ⦃ _ : InverseFunctionᵣ(_▫_)(inv) ⦄ where
[^]-by-distanceᵣ : ∀{a b} → (x ^ a ≡ x ^ b) → (x ^ (a 𝄩 b) ≡ id)
[^]-by-distanceᵣ {a}{b} = repeatₗ-by-distanceᵣ{X = T}{_▫_}{x}{id} ⦃ cancᵣ = One.cancellationᵣ-by-associativity-inverse ⦄ {a}{b}
[^]-equal-[𝄩] : ⦃ p : Ord(x) ⦄ → ∀{a b} → (x ^ a ≡ x ^ b) ↔ (ord(x) ⦃ p ⦄ ∣ (a 𝄩 b))
[^]-equal-[𝄩] ⦃ p ⦄ {a}{b} = [↔]-transitivity ([↔]-intro ([^]-by-distanceₗ{a}{b}) ([^]-by-distanceᵣ{a}{b})) ([^]-id-when-div ⦃ p ⦄)
postulate [^]-cancellationₗ : ⦃ p : Ord(x) ⦄ → ∀{a b} → ⦃ a < ord(x) ⦃ p ⦄ ⦄ → ⦃ b < ord(x) ⦃ p ⦄ ⦄ → (x ^ a ≡ x ^ b) → (a ≡ₑ b)
-- ord(x ^ n) ≡ ord(x) / gcd(n)(ord(x))
-- (x ▫ y ≡ y ▫ x) → ord(x ▫ y) ∣ lcm(ord(x))(ord(y))
-- (∀{x} → (ord(x) ≡ 2)) → Commutativity(_▫_)
-- One element in the group can "generate" any element element in the group by repeated application of the operator.
Generator : T → Stmt
Generator(x) = Surjective(x ^_)
-- A group is cyclic when there is an element that can generate it.
Cyclic : Stmt
Cyclic = ∃(Generator)
{- TODO: Because the thing exists, there is finitely many. Search for the first one
finite-order-from-dec-existence : ⦃ Decidable(_≡_) ⦄ → ∀{a} → ∃(n ↦ (a ^ 𝐒(n) ≡ id)) → Ord(a)
finite-order-from-dec-existence {n} asnid = {!!}
-- intro (Weak.Properties.intro ⦃ asnid ⦄ {!!})
-- TODO: Assume decidable equality and use finite-order-from-dec-existence above. Existence should follow from finiteness
finite-have-order : ⦃ Finite(T) ⦄ → ∀{a} → Ord(a)
∃.witness (finite-have-order ⦃ [∃]-intro size ⦃ fin-bij ⦄ ⦄) = size
∃.proof (finite-have-order ⦃ [∃]-intro 𝟎 ⦃ [∃]-intro fin-bij ⦄ ⦄ {a = a}) with fin-bij a
... | ()
∃.proof (finite-have-order ⦃ [∃]-intro (𝐒(size)) ⦃ fin-bij ⦄ ⦄) = intro {!!}
-}
postulate cyclic-commutative : ⦃ Cyclic ⦄ → Commutativity(_▫_)
-- generator-order-size : ⦃ Finite(T) ⦄ → ∀{a} → ⦃ p : Ord(a) ⦄ → Generator(a) ↔ ((# T) ≡ₑ ord(a) ⦃ p ⦄)
-- cyclic-order-size : ⦃ Finite(T) ⦄ → ⦃ Cyclic ⦄ ↔ ∃(a ↦ (# T) ≡ₑ ord(a))
-- generator-of-power : Generator(a ^ k) ↔ Generator(a ^ gcd(ord(a))(k))
-- order-of-power : ord(a ^ k) ∣ ord(a) / gcd(ord(a),k)
{-
module _ {id} ⦃ ident : Identity(_▫_)(id) ⦄ where
open import Data.Boolean
open import Data.Boolean.Stmt
import Function.Iteration
open import Logic.Computability
open import Logic.Computability.Binary renaming (ComputablyDecidable to ComputablyDecidable2)
open import Logic
open import Numeral.Natural.Relation.Computability
-}
{-
boundedMinOr : ℕ → (ℕ → Bool) → ℕ → ℕ
boundedMinOr 𝟎 p default = default
boundedMinOr (𝐒(bound)) p default = if p(bound) then bound else (boundedMinOr bound p default)
boundedMinOr-proof : ∀{p : ℕ → Bool}{bound default : ℕ} → IsTrue(p(default)) → IsTrue(p(boundedMinOr bound p default))
min-by-bruteforce : ∀{ℓ}{P : ℕ → Stmt{ℓ}} → ⦃ comp : ComputablyDecidable(P) ⦄ → ⦃ e : ∃(P) ⦄ → ∃(Weak.Properties.MinimumOf(_≤_)(P))
∃.witness (min-by-bruteforce {P = P} ⦃ comp ⦄ ⦃ e ⦄) = boundedMinOr([∃]-witness(e)) (ComputablyDecidable.decide(comp)) ([∃]-witness(e))
Weak.Properties.MinimumOf.proof (∃.proof min-by-bruteforce) {x} ⦃ x₁ ⦄ = {!!}
ord : (x : T) → ⦃ e : FiniteOrder(x) ⦄ → ⦃ comp : ComputablyDecidable2{X = T}(_≡_) ⦄ → ℕ
ord(x) ⦃ e ⦄ ⦃ comp ⦄ = Weak.minOf(_≤_)(n ↦ x ^ 𝐒(n) ≡ id) ⦃ min-by-bruteforce ⦃ {!!} ⦄ ⦃ e ⦄ ⦄
-}
| {
"alphanum_fraction": 0.5416594492,
"avg_line_length": 49.3418803419,
"ext": "agda",
"hexsha": "a84552bbdcac9ae526ee367d6e371e9d3725dc56",
"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": "Function/Iteration/Order.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": "Function/Iteration/Order.agda",
"max_line_length": 256,
"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": "Function/Iteration/Order.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": 4659,
"size": 11546
} |
module Issue2487-4 where
open import Agda.Primitive -- this should not be consistency-checked
open import Agda.Builtin.Bool
f : Bool → Bool
f true = true
f _ = false
| {
"alphanum_fraction": 0.738372093,
"avg_line_length": 17.2,
"ext": "agda",
"hexsha": "97177800a5cf3cd7160292fd6c06e80e758a1473",
"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/Issue2487-4.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/Issue2487-4.agda",
"max_line_length": 68,
"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/Issue2487-4.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": 47,
"size": 172
} |
{-# OPTIONS --cubical --safe --postfix-projections #-}
module Relation.Nullary.Decidable.Logic where
open import Prelude
open import Data.Sum
infixl 7 _&&_
_&&_ : Dec A → Dec B → Dec (A × B)
(x && y) .does = x .does and y .does
(yes x && yes y) .why = ofʸ (x , y)
(yes x && no y) .why = ofⁿ (y ∘ snd)
(no x && y) .why = ofⁿ (x ∘ fst)
infixl 6 _||_
_||_ : Dec A → Dec B → Dec (A ⊎ B)
(x || y) .does = x .does or y .does
(yes x || y) .why = ofʸ (inl x)
(no x || yes y) .why = ofʸ (inr y)
(no x || no y) .why = ofⁿ (either x y)
! : Dec A → Dec (¬ A)
! x .does = not (x .does)
! (yes x) .why = ofⁿ (λ z → z x)
! (no x) .why = ofʸ x
| {
"alphanum_fraction": 0.5280373832,
"avg_line_length": 24.6923076923,
"ext": "agda",
"hexsha": "59564f6359f177955b4b237ae33d1c9476262f8b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Relation/Nullary/Decidable/Logic.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/combinatorics-paper",
"max_issues_repo_path": "agda/Relation/Nullary/Decidable/Logic.agda",
"max_line_length": 54,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Relation/Nullary/Decidable/Logic.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-05T15:32:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-01-05T14:07:44.000Z",
"num_tokens": 277,
"size": 642
} |
{-# OPTIONS --cubical --safe --postfix-projections #-}
module Data.Bool.Properties where
open import HLevels
open import Path
open import Data.Bool.Base
open import Data.Bool.Truth
open import Data.Unit.Properties
open import Data.Unit
open import Data.Empty
open import Data.Empty.Properties using (isProp⊥)
open import Relation.Nullary.Discrete
open import Relation.Nullary.Decidable using (Dec; does; why)
isPropT : ∀ x → isProp (T x)
isPropT false = isProp⊥
isPropT true = isProp⊤
false≢true : false ≢ true
false≢true p = subst (bool ⊤ ⊥) p tt
true≢false : true ≢ false
true≢false p = subst (bool ⊥ ⊤) p tt
discreteBool : Discrete Bool
discreteBool false y .does = not y
discreteBool true y .does = y
discreteBool false false .why = refl
discreteBool false true .why = false≢true
discreteBool true false .why = true≢false
discreteBool true true .why = refl
| {
"alphanum_fraction": 0.7523041475,
"avg_line_length": 26.303030303,
"ext": "agda",
"hexsha": "5b5d80526618d6448054f370599e66446cab7e0f",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Data/Bool/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Data/Bool/Properties.agda",
"max_line_length": 61,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Data/Bool/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 259,
"size": 868
} |
{-# OPTIONS --without-K #-}
--open import HoTT
open import homotopy.3x3.PushoutPushout
open import homotopy.3x3.Transpose
open import homotopy.3x3.Common
module homotopy.3x3.From {i} (d : Span^2 {i}) where
open Span^2 d
open M d hiding (Pushout^2)
open M (transpose d) using () renaming (A₀∙ to A∙₀; A₂∙ to A∙₂; A₄∙ to A∙₄;
module F₁∙ to F∙₁; f₁∙ to f∙₁;
module F₃∙ to F∙₃; f₃∙ to f∙₃;
v-h-span to h-v-span)
open M using (Pushout^2)
module I∙₀ = PushoutRec {D = Pushout^2 d}
(left ∘ left) (right ∘ left) (glue ∘ left)
i∙₀ : A∙₀ → Pushout^2 d
i∙₀ = I∙₀.f
module I∙₄ = PushoutRec {D = Pushout^2 d}
(left ∘ right) (right ∘ right) (glue ∘ right)
i∙₄ : A∙₄ → Pushout^2 d
i∙₄ = I∙₄.f
module E∙₂Red (c : A₂₂) where
lhs-o : _
lhs-o =
ap (i∙₄ ∘ f∙₃) (glue c)
=⟨ ap-∘ i∙₄ f∙₃ (glue c) ⟩
ap i∙₄ (ap f∙₃ (glue c))
=⟨ F∙₃.glue-β c |in-ctx (ap i∙₄) ⟩
ap i∙₄ (ap left (H₁₃ c) ∙ glue (f₂₃ c) ∙ ap right (! (H₃₃ c)))
=⟨ ap-∙∙!`∘`∘ i∙₄ left right (H₁₃ c) (glue (f₂₃ c)) (H₃₃ c) ⟩
ap (left ∘ right) (H₁₃ c) ∙ ap i∙₄ (glue (f₂₃ c)) ∙ ! (ap (right ∘ right) (H₃₃ c))
=⟨ I∙₄.glue-β (f₂₃ c) |in-ctx (λ u → ap (left ∘ right) (H₁₃ c) ∙ u ∙ ! (ap (right ∘ right) (H₃₃ c))) ⟩
ap (left ∘ right) (H₁₃ c) ∙ glue (right (f₂₃ c)) ∙ ! (ap (right ∘ right) (H₃₃ c)) ∎
rhs-o : _
rhs-o =
! (ap (left ∘ left) (H₁₁ c)) ∙ glue (left (f₂₁ c)) ∙ ap (right ∘ left) (H₃₁ c)
=⟨ ! (I∙₀.glue-β (f₂₁ c)) |in-ctx (λ u → (! (ap (left ∘ left) (H₁₁ c)) ∙ u ∙ ap (right ∘ left) (H₃₁ c))) ⟩
! (ap (left ∘ left) (H₁₁ c)) ∙ ap i∙₀ (glue (f₂₁ c)) ∙ ap (right ∘ left) (H₃₁ c)
=⟨ ! (ap-!∙∙`∘`∘ i∙₀ left right (H₁₁ c) (glue (f₂₁ c)) (H₃₁ c)) ⟩
ap i∙₀ (ap left (! (H₁₁ c)) ∙ glue (f₂₁ c) ∙ ap right (H₃₁ c))
=⟨ ! (F∙₁.glue-β c) |in-ctx (λ u → ap i∙₀ u) ⟩
ap i∙₀ (ap f∙₁ (glue c))
=⟨ ∘-ap i∙₀ f∙₁ (glue c) ⟩
ap (i∙₀ ∘ f∙₁) (glue c) ∎
T-lhs : Type _
T-lhs = right (left (f₃₀ (f₂₁ c))) == right (right (f₃₄ (f₂₃ c))) :> Pushout^2 d
lhs-i : _ == _ :> T-lhs
lhs-i =
ap (right ∘ left) (H₃₁ c) ∙ ap right (glue (f₃₂ c)) ∙ ap (right ∘ right) (H₃₃ c)
=⟨ ! (ap-∙∙`∘`∘ right left right (H₃₁ c) (glue (f₃₂ c)) (H₃₃ c)) ⟩
ap right (ap left (H₃₁ c) ∙ glue (f₃₂ c) ∙ ap right (H₃₃ c))
=⟨ ! (ap (ap right) (F₃∙.glue-β c)) ⟩
ap right (ap f₃∙ (glue c))
=⟨ ∘-ap right f₃∙ (glue c) ⟩
ap (right ∘ f₃∙) (glue c) ∎
T-rhs : Type _
T-rhs = left (left (f₁₀ (f₂₁ c))) == left (right (f₁₄ (f₂₃ c))) :> Pushout^2 d
rhs-i : _ == _ :> T-rhs
rhs-i =
ap (left ∘ f₁∙) (glue c)
=⟨ ap-∘ left f₁∙ (glue c) ⟩
ap left (ap f₁∙ (glue c))
=⟨ F₁∙.glue-β c |in-ctx (ap left) ⟩
ap left (ap left (H₁₁ c) ∙ glue (f₁₂ c) ∙ ap right (H₁₃ c))
=⟨ ap-∙∙`∘`∘ left left right (H₁₁ c) (glue (f₁₂ c)) (H₁₃ c) ⟩
(ap (left ∘ left) (H₁₁ c) ∙ ap left (glue (f₁₂ c)) ∙ ap (left ∘ right) (H₁₃ c)) ∎
coh! : (p : (_ , _ =□ _ , _)) → _
coh! = pp-coh! {A = Pushout^2 d}
{u = glue (left (f₂₁ c))}
{ap (right ∘ left) (H₃₁ c)}
{ap right (glue (f₃₂ c))}
{ap (right ∘ right) (H₃₃ c)}
{ap (left ∘ left) (H₁₁ c)}
{ap left (glue (f₁₂ c))}
{ap (left ∘ right) (H₁₃ c)}
{glue (right (f₂₃ c))}
coh : (p : (_ , _ =□ _ , _)) → _
coh = pp-coh {A = Pushout^2 d}
{p = ap left (glue (f₁₂ c))}
{ap (left ∘ right) (H₁₃ c)}
{glue (right (f₂₃ c))}
{ap (right ∘ right) (H₃₃ c)}
{ap (left ∘ left) (H₁₁ c)}
{glue (left (f₂₁ c))}
{ap (right ∘ left) (H₃₁ c)}
{ap right (glue (f₃₂ c))}
module _ (to : Pushout^2 d → Pushout^2 (transpose d)) where
ap-ap-coh! : (p : _ , _ =□ _ , _) → _
ap-ap-coh! = pp-coh! {u = ap to (glue (left (f₂₁ c)))}
{ap (to ∘ right ∘ left) (H₃₁ c)}
{ap to (ap right (glue (f₃₂ c)))}
{ap (to ∘ right ∘ right) (H₃₃ c)}
{ap (to ∘ left ∘ left) (H₁₁ c)}
{ap to (ap left (glue (f₁₂ c)))}
{ap (to ∘ left ∘ right) (H₁₃ c)}
{ap to (glue (right (f₂₃ c)))}
ap-ap-coh : (p : _ , _ =□ _ , _) → _
ap-ap-coh = pp-coh {p = ap to (ap left (glue (f₁₂ c)))}
{ap (to ∘ left ∘ right) (H₁₃ c)}
{ap to (glue (right (f₂₃ c)))}
{ap (to ∘ right ∘ right) (H₃₃ c)}
{ap (to ∘ left ∘ left) (H₁₁ c)}
{ap to (glue (left (f₂₁ c)))}
{ap (to ∘ right ∘ left) (H₃₁ c)}
{ap to (ap right (glue (f₃₂ c)))}
ap-ap-coh!-lhs-i : _
ap-ap-coh!-lhs-i = ! (ap-∙∙`∘`∘ to (right ∘ left) (right ∘ right) (H₃₁ c) (ap right (glue (f₃₂ c))) (H₃₃ c))
ap-ap-coh!-rhs-i : _
ap-ap-coh!-rhs-i = ap-∙∙`∘`∘ to (left ∘ left) (left ∘ right) (H₁₁ c) (ap left (glue (f₁₂ c))) (H₁₃ c)
ap-ap-coh!-lhs-o : _
ap-ap-coh!-lhs-o = ap-∙∙!'`∘`∘ to (left ∘ right) (right ∘ right) (H₁₃ c) (glue (right (f₂₃ c))) (H₃₃ c)
ap-ap-coh!-rhs-o : _
ap-ap-coh!-rhs-o = ! (ap-!'∙∙`∘`∘ to (left ∘ left) (right ∘ left) (H₁₁ c) (glue (left (f₂₁ c))) (H₃₁ c))
ap-ap-coh!-β : (α : _)
→ ap□ to (coh! α) == ap-ap-coh! (ap□ to α
∙□-i/ ap-ap-coh!-lhs-i
/ ap-ap-coh!-rhs-i /)
∙□-i/ ap-ap-coh!-lhs-o
/ ap-ap-coh!-rhs-o /
ap-ap-coh!-β α = ap□-coh! {g₁ = left ∘ right} {right ∘ right} {left ∘ left} {right ∘ left} to
{u = glue (left (f₂₁ c))} {H₃₁ c} {ap right (glue (f₃₂ c))} {H₃₃ c}
{H₁₁ c} {ap left (glue (f₁₂ c))} {H₁₃ c} {glue (right (f₂₃ c))}
α
open E∙₂Red
module E∙₂ = PushoutElim {d = span _ _ _ f₁₂ f₃₂} {P = λ c → i∙₀ (f∙₁ c) == i∙₄ (f∙₃ c)}
(ap left ∘ glue) (ap right ∘ glue)
(λ c → ↓-='-in (coh! c (↓-='-out (apd (glue {d = v-h-span}) (glue c))
∙□-i/ lhs-i c / rhs-i c /)
∙□-i/ lhs-o c / rhs-o c /))
e∙₂ : (c : A∙₂) → i∙₀ (f∙₁ c) == i∙₄ (f∙₃ c)
e∙₂ = E∙₂.f
module From = PushoutRec {d = h-v-span} {D = Pushout^2 d}
i∙₀ i∙₄ e∙₂
from : Pushout^2 (transpose d) → Pushout^2 d
from = From.f
from-glue-glue-β : (c : A₂₂) → ap↓ (ap from) (apd glue (glue c))
== (↓-='-in (coh! c (↓-='-out (apd (glue {d = v-h-span}) (glue c))
∙□-i/ lhs-i c / rhs-i c /)
∙□-i/ lhs-o c / rhs-o c /))
◃/ From.glue-β (left (f₁₂ c)) / ! (From.glue-β (right (f₃₂ c))) /
from-glue-glue-β c = ∘'-apd (ap from) glue (glue c)
∙ coh1 {p = apd (ap from ∘ glue) (glue c)} {From.glue-β (right (f₃₂ c))}
{From.glue-β (left (f₁₂ c))} {apd e∙₂ (glue c)}
(↓-=-out (apd From.glue-β (glue c)))
∙ (E∙₂.glue-β c |in-ctx (λ u → u ◃/ From.glue-β (left (f₁₂ c)) / ! (From.glue-β (right (f₃₂ c)))/))
| {
"alphanum_fraction": 0.4133386581,
"avg_line_length": 42.6818181818,
"ext": "agda",
"hexsha": "ab19c4e0774ba215f309e2e5dd4591921988a6e7",
"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": "homotopy/3x3/From.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": "homotopy/3x3/From.agda",
"max_line_length": 118,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "homotopy/3x3/From.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": 3360,
"size": 7512
} |
module general-util where
open import instances public
get-file-contents : (filename : string) → IO (maybe string)
get-file-contents e =
doesFileExist e >>= λ b →
if b then
(readFiniteFile e >>= λ s → return (just s))
else
return nothing
maybe-else : ∀{ℓ}{A B : Set ℓ} → B → (A → B) → maybe A → B
maybe-else y f (just x) = f x
maybe-else y f nothing = y
maybe-else' : ∀{ℓ}{A B : Set ℓ} → maybe A → B → (A → B) → B
maybe-else' m y f = maybe-else y f m
maybe-join : ∀ {a} {A : Set a} → maybe (maybe A) → maybe A
maybe-join = maybe-else nothing id
maybe-equal? : ∀ {a} {A : Set a} → (A → A → 𝔹) → (m₁ m₂ : maybe A) → 𝔹
maybe-equal? f (just x) (just x₁) = f x x₁
maybe-equal? f (just x) nothing = ff
maybe-equal? f nothing (just x) = ff
maybe-equal? f nothing nothing = tt
_maybe-or_ : ∀ {ℓ} {A : Set ℓ} → maybe A → maybe A → maybe A
(nothing maybe-or ma) = ma
(just a maybe-or ma) = just a
maybe-not : ∀ {ℓ} {A : Set ℓ} → maybe A → maybe ⊤
maybe-not (just a) = nothing
maybe-not nothing = just triv
maybe-if : 𝔹 → maybe ⊤
maybe-if tt = just triv
maybe-if ff = nothing
when : ∀ {A : Set} → 𝔹 → A → maybe A
when b a = maybe-if b >> just a
unless : ∀ {A : Set} → 𝔹 → A → maybe A
unless b a = maybe-if (~ b) >> just a
trie-lookupd : ∀ {A : Set} → trie A → string → A → A
trie-lookupd t s d with trie-lookup t s
trie-lookupd t s d | nothing = d
trie-lookupd t s d | just x = x
trie-lookup-else : ∀{A : Set} → A → trie A → string → A
trie-lookup-else d t s = trie-lookupd t s d
trie-single : ∀{A : Set} → string → A → trie A
trie-single s x = trie-insert empty-trie s x
trie-any : ∀{A : Set} → (A → 𝔹) → trie A → 𝔹
trie-cal-any : ∀{A : Set} → (A → 𝔹) → cal (trie A) → 𝔹
trie-any f (Node odata ts) = maybe-else (trie-cal-any f ts) f odata
trie-cal-any f [] = ff
trie-cal-any f ((c , t) :: cs) = trie-any f t || trie-cal-any f cs
trie-all : ∀{A : Set} → (A → 𝔹) → trie A → 𝔹
trie-all f = ~_ ∘ trie-any (~_ ∘ f)
trie-lookup𝕃 : ∀ {A : Set} → trie (𝕃 A) → string → 𝕃 A
trie-lookup𝕃 t s = trie-lookupd t s []
trie-lookup𝕃2 : ∀ {A : Set} → trie (string × 𝕃 A) → string → string × 𝕃 A
trie-lookup𝕃2 t s = trie-lookupd t s ("[nomod]" , [])
trie-lookup-string : trie string → string → string
trie-lookup-string t s = trie-lookupd t s "[not-found]"
trie-insert-append : ∀ {A : Set} → trie (𝕃 A) → string → A → trie (𝕃 A)
trie-insert-append t s a = trie-insert t s (a :: (trie-lookup𝕃 t s))
trie-insert-append2 : ∀ {A : Set} → trie (string × 𝕃 A) → string → string → A → trie (string × 𝕃 A)
trie-insert-append2 t s mn a = trie-insert t s (mn , (a :: snd (trie-lookup𝕃2 t s)))
trie-fill : ∀{A : Set} → trie A → 𝕃 (string × A) → trie A
trie-fill t ((s , a) :: vs) = trie-fill (trie-insert t s a) vs
trie-fill t [] = t
trie-empty? : ∀ {A} → trie A → 𝔹
trie-empty? t = ~ trie-nonempty t
trie-filter : ∀ {A} → (A → 𝔹) → trie A → trie A
cal-filter : ∀ {A} → (A → 𝔹) → cal (trie A) → cal (trie A)
trie-filter f (Node odata ts'@(c :: ts))
= Node odata (cal-filter f ts')
trie-filter f t@(Node (just x) [])
= if f x then t else empty-trie
trie-filter f (Node nothing [])
= empty-trie
cal-filter f [] = []
cal-filter f ((a , t) :: c)
with trie-filter f t | cal-filter f c
... | t' | c'
= if trie-empty? t then c' else (a , t') :: c'
trie-fold : ∀ {F : Set → Set} {A B : Set} → trie A →
F B → (string → A → F B → F B) → F B
trie-fold t n c = foldr (λ {(k , v) → c k v}) n (trie-mappings t)
trie-catMaybe : ∀ {A} → trie (maybe A) → trie A
cal-catMaybe : ∀ {A} → cal (trie (maybe A)) → cal (trie A)
trie-catMaybe (Node odata ts'@(t :: ts)) = Node (maybe-join odata) (cal-catMaybe ts')
trie-catMaybe (Node odata []) = maybe-else empty-trie (λ a → Node (just a) []) (maybe-join odata)
cal-catMaybe [] = []
cal-catMaybe ((c , tr) :: trs)
with trie-catMaybe tr | cal-catMaybe trs
... | tr' | trs' = if trie-empty? tr' then trs' else (c , tr') :: trs'
trie-equal? : ∀ {A : Set} → (A → A → 𝔹) → (t₁ t₂ : trie A) → 𝔹
trie-equal? {A} f t₁ t₂ =
length t₁𝕃 =ℕ length t₂𝕃
&& list-all check-elems t₁𝕃
where
t₁𝕃 = trie-mappings t₁
t₂𝕃 = trie-mappings t₂
check-elems : string × A → 𝔹
check-elems (name , dat₁) with trie-lookup t₂ name
... | nothing = ff
... | just dat₂ = f dat₁ dat₂
string-split-h : 𝕃 char → char → 𝕃 char → 𝕃 string → 𝕃 string
string-split-h [] delim str-build out = reverse ((𝕃char-to-string (reverse str-build)) :: out)
string-split-h (c :: cs) delim str-build out with (c =char delim)
... | tt = string-split-h cs delim [] ((𝕃char-to-string (reverse str-build)) :: out)
... | ff = string-split-h cs delim (c :: str-build) out
string-split : string → char → 𝕃 string
string-split str delim = string-split-h (string-to-𝕃char str) delim [] []
undo-escape-string-h : 𝕃 char → 𝕃 char → 𝕃 char
undo-escape-string-h ('\\' :: 'n' :: rest) so-far = undo-escape-string-h rest ('\n' :: so-far)
undo-escape-string-h ('\\' :: '\"' :: rest) so-far = undo-escape-string-h rest ('\"' :: so-far)
undo-escape-string-h (c :: rest) so-far = undo-escape-string-h rest (c :: so-far)
undo-escape-string-h [] so-far = reverse so-far
undo-escape-string : string → string
undo-escape-string str = 𝕃char-to-string (undo-escape-string-h (string-to-𝕃char str) [])
is-pfx : (pfx str : string) → maybe string
is-pfx pfx str = h (string-to-𝕃char pfx) (string-to-𝕃char str) where
h : 𝕃 char → 𝕃 char → maybe string
h [] cs = just (𝕃char-to-string cs)
h (cₚ :: csₚ) [] = nothing
h (cₚ :: csₚ) (cₛ :: csₛ) with cₚ =char cₛ
...| ff = nothing
...| tt = h csₚ csₛ
-- functions.agda
curry : ∀{ℓ₁ ℓ₂ ℓ₃}{A : Set ℓ₁}{B : Set ℓ₂}{C : Set ℓ₃}
→ (A × B → C) → A → B → C
curry f a b = f (a , b)
uncurry : ∀{ℓ₁ ℓ₂ ℓ₃}{A : Set ℓ₁}{B : Set ℓ₂}{C : Set ℓ₃}
→ (f : A → B → C) → (p : A × B) → C
uncurry f (a , b) = f a b
uncurry₂ : ∀{a b c d}{A : Set a}{B : Set b}{C : Set c}{D : Set d}
→ (f : A → B → C → D) → (p : A × B × C) → D
uncurry₂ f (a , b , c) = f a b c
elim-pair : ∀{ℓ₀ ℓ₁ ℓ₂}{A : Set ℓ₀}{B : Set ℓ₁}{C : Set ℓ₂}
→ A × B → (A → B → C) → C
elim-pair (a , b) f = f a b
elim-Σi : ∀ {ℓ₀ ℓ₁ ℓ₂} {A : Set ℓ₀} {B : A → Set ℓ₁} {X : Set ℓ₂}
→ Σi A B → ({a : A} → B a → X) → X
elim-Σi (, b) f = f b
elim_for : ∀ {ℓ₀ ℓ₁ ℓ₂} {A : Set ℓ₀} {B : Set ℓ₁} {X : Set ℓ₂} → A × B → (A → B → X) → X
elim (a , b) for f = f a b
infixr 0 case_ret_of_ case_of_
case_ret_of_ :
∀ {ℓ₁ ℓ₂} {A : Set ℓ₁}
(x : A) (B : A → Set ℓ₂) → ((x : A) → B x) → B x
case x ret B of f = f x
case_of_ : ∀ {a b} {A : Set a} {B : Set b} → A → (A → B) → B
case x of f = case_ret_of_ x _ f
case₂_,_of_ : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} → A → B → (A → B → C) → C
case₂ x , y of f = f x y
flip : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c}
→ (A → B → C) → (B → A → C)
flip f = λ b a → f a b
const : ∀ {a b} {A : Set a} {B : Set b} →
A → B → A
const a b = a
infixr 0 _$_
_$_ : ∀ {a b} {A : Set a} {B : Set b} → (A → B) → A → B
f $ x = f x
-- _∘_ just needs a fixity and association declaration in the IAL
infixr 9 _∘'_
_∘'_ : ∀ {a b c} {A : Set a}{B : Set b}{C : Set c}
→ (B → C) → (A → B) → A → C
g ∘' f = λ a → g (f a)
-- list.agda
take : ∀{ℓ}{A : Set ℓ} → ℕ → 𝕃 A → 𝕃 A
take 0 l = []
take (suc n) (x :: l) = x :: (take n l)
take (suc n) [] = []
drop : ∀{ℓ}{A : Set ℓ} → ℕ → 𝕃 A → 𝕃 A
drop zero xs = xs
drop (suc _) [] = []
drop (suc n) (x :: xs) = drop n xs
drop-last : ∀{ℓ}{A : Set ℓ} → ℕ → 𝕃 A → 𝕃 A
drop-last n xs = take (length xs ∸ n) xs
zip-with : ∀{ℓ₁ ℓ₂ ℓ₃}{A : Set ℓ₁}{B : Set ℓ₂}{C : Set ℓ₃}
→ (A → B → C) → 𝕃 A → 𝕃 B → 𝕃 C
zip-with f xs ys = map (uncurry f) (zip xs ys)
for_yield_ : ∀ {a b} {A : Set a} {B : Set b} → 𝕃 A → (A → B) → 𝕃 B
for xs yield f = map f xs
for_accum_use_ : ∀ {a b} {A : Set a} {B : Set b} → 𝕃 A → B → (A → B → B) → B
for xs accum n use f = foldr f n xs
foldl : ∀{ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'} → (A → B → B) → B → 𝕃 A → B
foldl f b [] = b
foldl f b (a :: as) = foldl f (f a b) as
foldr' : ∀{ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'} → B → (A → B → B) → 𝕃 A → B
foldr' = flip foldr
-- error.agda
err-guard : 𝔹 → string → error-t ⊤
err-guard tt msg = yes-error msg
err-guard ff _ = no-error triv
-- sum.agda
either-else' : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} → A ∨ B → (A → C) → (B → C) → C
either-else' (inj₁ x) f g = f x
either-else' (inj₂ y) f g = g y
either-else : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} → (A → C) → (B → C) → A ∨ B → C
either-else f g (inj₁ x) = f x
either-else f g (inj₂ y) = g y
err⊎-guard : ∀ {e} {E : Set e} → 𝔹 → E → E ∨ ⊤
err⊎-guard tt err = inj₁ err
err⊎-guard ff _ = inj₂ triv
--infixl 1 _≫⊎_
--_≫⊎_ : ∀ {E B : Set} → E ∨ ⊤ → E ∨ B → E ∨ B
--m₁ ≫⊎ m₂ = m₁ ≫=⊎ λ _ → m₂
-- Some file writing functions
data IOMode : Set where
ReadMode : IOMode
WriteMode : IOMode
AppendMode : IOMode
ReadWriteMode : IOMode
filepath = string
postulate
Handle : Set
-- IOMode : Set
openFile : filepath → IOMode -> IO Handle
closeFile : Handle -> IO ⊤
hPutStr : Handle → string → IO ⊤
hSetToLineBuffering : Handle → IO ⊤
hFlush : Handle → IO ⊤
stdout : Handle
doesDirectoryExist : filepath → IO 𝔹
{-# FOREIGN GHC import qualified System.IO #-}
{-# FOREIGN GHC import qualified Data.Text.IO #-}
{-# FOREIGN GHC import qualified System.Directory #-}
{-# COMPILE GHC Handle = type System.IO.Handle #-}
{-# COMPILE GHC IOMode = data System.IO.IOMode (System.IO.ReadMode | System.IO.WriteMode | System.IO.AppendMode | System.IO.ReadWriteMode) #-}
{-# COMPILE GHC hSetToLineBuffering = \ hdl -> System.IO.hSetBuffering hdl System.IO.LineBuffering #-}
{-# COMPILE GHC hFlush = System.IO.hFlush #-}
{-# COMPILE GHC stdout = System.IO.stdout #-}
{-# COMPILE GHC openFile = \ fp mode -> do outh <- System.IO.openFile (Data.Text.unpack fp) mode; System.IO.hSetNewlineMode outh System.IO.noNewlineTranslation; System.IO.hSetEncoding outh System.IO.utf8; return outh #-}
{-# COMPILE GHC closeFile = System.IO.hClose #-}
{-# COMPILE GHC hPutStr = Data.Text.IO.hPutStr #-}
{-# COMPILE GHC doesDirectoryExist = System.Directory.doesDirectoryExist . Data.Text.unpack #-}
clearFile : filepath → IO ⊤
clearFile fp = openFile fp WriteMode >>= λ hdl → hPutStr hdl "" >> closeFile hdl
flush : IO ⊤
flush = hFlush stdout
setToLineBuffering : IO ⊤
setToLineBuffering = hSetToLineBuffering stdout
withFile : {A : Set} → filepath → IOMode → (Handle → IO A) → IO A
withFile fp mode f = openFile fp mode >>= λ hdl → f hdl >≯ closeFile hdl
-- Coordinated Universal Time
infix 15 _utc-after_ _utc-before_
postulate
UTC : Set
getCurrentTime : IO UTC
_utc-after_ : UTC → UTC → 𝔹
_utc-before_ : UTC → UTC → 𝔹
utcToString : UTC → string
getModificationTime : filepath → IO UTC
getCurrentDirectory : IO filepath
pathSeparator : char
{-# FOREIGN GHC import qualified Data.Time.Clock #-}
{-# FOREIGN GHC import qualified Data.Time.Calendar #-}
{-# FOREIGN GHC import qualified System.FilePath #-}
{-# COMPILE GHC UTC = type Data.Time.Clock.UTCTime #-}
{-# COMPILE GHC getCurrentTime = Data.Time.Clock.getCurrentTime #-}
{-# COMPILE GHC _utc-after_ = (>) #-}
{-# COMPILE GHC _utc-before_ = (<) #-}
{-# COMPILE GHC utcToString = Data.Text.pack . show #-}
{-# COMPILE GHC getModificationTime = System.Directory.getModificationTime . Data.Text.unpack #-}
{-# COMPILE GHC getCurrentDirectory = System.Directory.getCurrentDirectory >>= return . Data.Text.pack #-}
{-# COMPILE GHC pathSeparator = System.FilePath.pathSeparator #-}
pathSeparatorString = 𝕃char-to-string [ pathSeparator ]
splitPath : filepath → 𝕃 string
splitPath = h [] [] ∘ string-to-𝕃char where
cons-if-nonempty : 𝕃 char → 𝕃 string → 𝕃 string
cons-if-nonempty [] acc = acc
cons-if-nonempty cur acc = 𝕃char-to-string (reverse cur) :: acc
h : 𝕃 string → 𝕃 char → 𝕃 char → 𝕃 string
h acc cur [] = reverse (cons-if-nonempty cur acc)
h acc cur (c :: cs) with c =char pathSeparator
...| tt = h (cons-if-nonempty cur acc) [] cs
...| ff = h acc (c :: cur) cs
joinPath : 𝕃 string → filepath
joinPath [] = ""
joinPath (x :: []) = x
joinPath (x :: xs) = x ^ pathSeparatorString ^ joinPath xs
pathIsAbsolute : filepath → 𝔹
pathIsAbsolute = maybe-else ff (λ c → (c =char '~') || (c =char pathSeparator)) ∘ (head2 ∘ string-to-𝕃char)
filepath-replace-tilde : filepath → IO (maybe filepath)
filepath-replace-tilde fp with string-to-𝕃char fp
...| '~' :: '/' :: fp-cs = getHomeDirectory >>=r λ home →
just (combineFileNames home (𝕃char-to-string fp-cs))
...| fp-cs = return nothing
-- string binary tree, for more efficient I/O printing than concatenation
data rope : Set where
_⊹⊹_ : rope → rope → rope
[[_]] : string → rope
infixl 9 _⊹⊹_
infix 9 [[_]]
[[]] : rope
[[]] = [[ "" ]]
rope-to-string : rope → string
rope-to-string = flip h "" where
h : rope → string → string
h (s₁ ⊹⊹ s₂) = h s₁ ∘ h s₂
h [[ s ]] acc = s ^ acc
rope-length : rope → ℕ
rope-length [[ s ]] = string-length s
rope-length (r₁ ⊹⊹ r₂) = rope-length r₁ + rope-length r₂
𝕃-to-rope : ∀{A : Set} → (A → rope) → string → 𝕃 A → rope
𝕃-to-rope to-rope sep [] = [[]]
𝕃-to-rope to-rope sep (x :: []) = to-rope x
𝕃-to-rope to-rope sep (x :: xs) = to-rope x ⊹⊹ [[ sep ]] ⊹⊹ 𝕃-to-rope to-rope sep xs
putStrLn : string → IO ⊤
putStrLn str = putStr str >> putStr "\n" -- >> flush
putRope : rope → IO ⊤
-- putRope = putStr ∘ rope-to-string
putRope s = h s (return triv) where
h : rope → IO ⊤ → IO ⊤
h (s₁ ⊹⊹ s₂) io = h s₁ (h s₂ io)
h [[ s ]] io = putStr s >> io
putRopeLn : rope → IO ⊤
putRopeLn s = putRope s >> putStr "\n" -- >> flush
hPutRope : Handle → rope → IO ⊤
hPutRope outh s = h s (return triv) outh where
h : rope → IO ⊤ → Handle → IO ⊤
h (s₁ ⊹⊹ s₂) io outh = h s₁ (h s₂ io outh) outh
h [[ s ]] io outh = hPutStr outh s >> io
writeRopeToFile : filepath → rope → IO ⊤
writeRopeToFile fp s = clearFile fp >> openFile fp AppendMode >>= λ hdl → hPutRope hdl s >> closeFile hdl
stringset-singleton : string → stringset
stringset-singleton x = stringset-insert empty-stringset x
set-nth : ∀ {ℓ} {X : Set ℓ} → ℕ → X → 𝕃 X → 𝕃 X
set-nth n x [] = []
set-nth zero x (x' :: xs) = x :: xs
set-nth (suc n) x (x' :: xs) = x' :: set-nth n x xs
map-fst : ∀ {ℓ₀ ℓ₁ ℓ₂} {X₀ : Set ℓ₀} {X₁ : Set ℓ₁} {X₂ : Set ℓ₂} → (X₀ → X₂) → (X₀ × X₁) → (X₂ × X₁)
map-fst f (x₀ , x₁) = (f x₀ , x₁)
map-snd : ∀ {ℓ₀ ℓ₁ ℓ₂} {X₀ : Set ℓ₀} {X₁ : Set ℓ₁} {X₂ : Set ℓ₂} → (X₁ → X₂) → (X₀ × X₁) → (X₀ × X₂)
map-snd f (x₀ , x₁) = (x₀ , f x₁)
--cons = _::_
--nil = []
--data 𝕃ᵢ (A : ℕ → Set) : ℕ → Set where
-- cons : ∀ {n} → A 0 → 𝕃ᵢ A n → 𝕃ᵢ A (suc n)
-- nil : 𝕃ᵢ A 0
--pattern _,_ = _::_
--{-# TERMINATING #-}
--𝕃ᵢ-nests : Set → ℕ → Set
--𝕃ᵢ-nests A 0 = A
--𝕃ᵢ-nests A (suc n) = 𝕃ᵢ (𝕃ᵢ-nests A) 1
--cons' : ∀ {A n} → A → 𝕃ᵢ (𝕃ᵢ-nests A) n → 𝕃ᵢ (𝕃ᵢ-nests A) (suc n)
--cons' h t = cons h t
{-
-- Syntactic sugar for Haskell-esque list construction
infixr 4 _,,_
infixr 5 [:_ _:]
[:_ = id
_:] = [_]
_,,_ : ∀ {ℓ} {A : Set ℓ} → A → 𝕃 A → 𝕃 A
_,,_ = _::_
-}
infixr 4 _⌟_
_⌟_ : ∀ {ℓ}{A : Set ℓ}{b : 𝔹} → A → if b then A else 𝕃 A → 𝕃 A
_⌟_ {b = tt} a a' = a :: a' :: []
_⌟_ {b = ff} a as = a :: as
[:_:] = id
𝕃-sugar-example = [: 0 ⌟ 1 ⌟ 2 ⌟ 3 ⌟ 4 :]
{-
postulate
ord : char → ℕ
chr : ℕ → char
{-# FOREIGN GHC import qualified Data.Char #-}
{-# COMPILE GHC ord = toInteger . Data.Char.ord #-}
{-# COMPILE GHC chr = Data.Char.chr . fromIntegral #-}
toLower : char → char
toLower c =
let n = ord c
up? = n ≥ 65 {- A -} && n ≤ 90 {- Z -} in
chr (if up? then n ∸ 32 else n)
toUpper : char → char
toUpper c =
let n = ord c
low? = n ≥ 97 {- A -} && n ≤ 122 {- Z -} in
chr (if low? then n + 32 else n)
capitalize : string → string
capitalize x with string-to-𝕃char x
...| [] = ""
...| c :: cs = 𝕃char-to-string (toUpper c :: cs)
uncapitalize : string → string
uncapitalize x with string-to-𝕃char x
...| [] = ""
...| c :: cs = 𝕃char-to-string (toLower c :: cs)
-}
| {
"alphanum_fraction": 0.57475104,
"avg_line_length": 31.7955911824,
"ext": "agda",
"hexsha": "c7469f81e3f86aa4e6cda5d3da2cc68b49bbcd9c",
"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": "9df4b85b55b57f97466242fdbb499adbd3bca893",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "zmthy/cedille",
"max_forks_repo_path": "src/general-util.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9df4b85b55b57f97466242fdbb499adbd3bca893",
"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": "zmthy/cedille",
"max_issues_repo_path": "src/general-util.agda",
"max_line_length": 220,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "9df4b85b55b57f97466242fdbb499adbd3bca893",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "zmthy/cedille",
"max_stars_repo_path": "src/general-util.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6338,
"size": 15866
} |
------------------------------------------------------------------------
-- M-types for indexed containers, defined coinductively (in Cubical
-- Agda)
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --safe --guardedness #-}
import Equality.Path as P
module Container.Indexed.Variant.M.Codata
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq
open import Prelude
open import Bijection equality-with-J using (_↔_)
open import Container.Indexed equality-with-J using (_⇾_; _∘⇾_)
open import Container.Indexed.Variant equality-with-J
hiding (Final′≃Final′)
import Container.Indexed.Variant P.equality-with-J as PC
open import Equality.Path.Isomorphisms eq
open import Equivalence equality-with-J as Eq using (_≃_)
open import Function-universe equality-with-J
open import H-level equality-with-J
private
variable
a iℓ s : Level
A I : Type a
i p q x : A
C : Container I s p
n : ℕ
-- An M-type for a given container.
--
-- This definition is similar to one in "Indexed containers" by
-- Altenkirch, Ghani, Hancock, McBride and Morris.
record M {I : Type iℓ} (C : Container I s p) (i : I) :
Type (iℓ ⊔ s ⊔ p) where
coinductive
constructor in-M
field
out-M : ⟦ C ⟧ (M C) i
open M public
-- An η-law.
η : in-M (out-M x) ≡ x
η = _↔_.from ≡↔≡ η′
where
η′ : in-M (out-M x) P.≡ x
η′ {x = x} _ .out-M = x .out-M
-- M C is, in a certain sense, a fixpoint of ⟦ C ⟧.
M-fixpoint : ⟦ C ⟧ (M C) i ≃ M C i
M-fixpoint = Eq.↔→≃ in-M out-M (λ _ → η) refl
-- A coalgebra defined using M and out-M.
M-coalgebra : (C : Container I s p) → Coalgebra C
M-coalgebra C = M C , λ _ → out-M
private
-- M-coalgebra C is a final coalgebra.
--
-- This code is based on code written by Andrea Vezzosi for the
-- cubical library.
M-final′′ : PC.Final′ (M-coalgebra C)
M-final′′ {C = C@(S ◁ P)} Y@(Q , f) = unfold , unique
where
g : Q ⇾ M C
g i q .out-M .proj₁ = f i q .proj₁
g i q .out-M .proj₂ j p = g j (f i q .proj₂ j p)
g-ok : (λ _ → out-M) ∘⇾ g P.≡ map C g ∘⇾ f
g-ok i j q .proj₁ = f j q .proj₁
g-ok i j q .proj₂ k p .out-M = g-ok i k (f j q .proj₂ k p)
unfold : Y PC.⇨ M-coalgebra C
unfold = g , g-ok
module _ (u : Y PC.⇨ M-coalgebra C) where
lemma₁ :
x P.≡ u .proj₁ i q →
x .out-M .proj₁ P.≡
(map C (u .proj₁) ∘⇾ f) i q .proj₁
lemma₁ {i = i} {x = x} {q = q} eq =
x .out-M .proj₁ P.≡⟨ P.cong (λ x → x .out-M .proj₁) eq ⟩
u .proj₁ i q .out-M .proj₁ P.≡⟨ P.cong (λ f → f i q .proj₁) (u .proj₂) ⟩∎
(map C (u .proj₁) ∘⇾ f) i q .proj₁ ∎
lemma₂ :
(eq : x P.≡ u .proj₁ i q) →
P.[ (λ l → P (lemma₁ eq l) ⇾ M C) ]
x .out-M .proj₂ ≡
(map C (u .proj₁) ∘⇾ f) i q .proj₂
lemma₂ {i = i} {x = x} {q = q} eq =
x .out-M .proj₂ P.≡⟨ P.hcong (λ x → x .out-M .proj₂) eq ⟩[ (λ p → P p ⇾ M C) ]
u .proj₁ i q .out-M .proj₂ P.≡⟨ P.hcong (λ f → f i q .proj₂) (u .proj₂) ⟩∎h
(map C (u .proj₁) ∘⇾ f) i q .proj₂ ∎
unique′ : ∀ i q x → x P.≡ u .proj₁ i q → x P.≡ g i q
unique′ _ _ _ eq j .out-M .proj₁ = lemma₁ eq j
unique′ i q x eq j .out-M .proj₂ k p =
unique′ k (f i q .proj₂ k p₁) (x .out-M .proj₂ k p₀) lemma₂′ j
where
lem₁ = lemma₁ eq
p₀ : P (lem₁ P.0̲) k
p₁ : P (lem₁ P.1̲) k
p₀ = P.transport (λ l → P (lem₁ (P.min j (P.- l))) k) (P.- j) p
p₁ = P.transport (λ l → P (lem₁ (P.max j l )) k) j p
p₀≡p₁ : P.[ (λ l → P (lem₁ l) k) ] p₀ ≡ p₁
p₀≡p₁ = P.elim¹
(λ eq →
∀ p →
P.[ (λ l → eq l) ]
P.transport (λ l → eq (P.min j (P.- l))) (P.- j) p ≡
P.transport (λ l → eq (P.max j l )) j p)
(λ p →
P.transport (λ _ → P (x .out-M .proj₁) k) (P.- j) p P.≡⟨ P.cong (_$ p) $ P.transport-refl (P.- j) ⟩
p P.≡⟨ P.cong (_$ p) $ P.sym $ P.transport-refl j ⟩∎
P.transport (λ _ → P (x .out-M .proj₁) k) j p ∎)
(P.cong (λ s → P s k) lem₁)
p
lemma₂′ :
x .out-M .proj₂ k p₀ P.≡
(map C (u .proj₁) ∘⇾ f) i q .proj₂ k p₁
lemma₂′ l = lemma₂ eq l k (p₀≡p₁ l)
unique : unfold .proj₁ P.≡ u .proj₁
unique =
P.⟨ext⟩ λ _ → P.⟨ext⟩ λ _ → P.sym $
unique′ _ _ _ P.refl
-- Finality expressed using equality is equivalent to finality
-- expressed using paths.
Final′≃Final′ :
(X : Coalgebra C) →
Final′ X ≃ PC.Final′ X
Final′≃Final′ X =
(∀ Y → ∃ λ (m : Y ⇨ X) → (m′ : Y ⇨ X) → proj₁ m ≡ proj₁ m′) ↔⟨ (∀-cong ext λ _ →
Σ-cong (lemma _) λ _ →
Π-cong ext (lemma _) λ _ →
≡↔≡) ⟩□
(∀ Y → ∃ λ (m : Y PC.⇨ X) → (m′ : Y PC.⇨ X) → proj₁ m P.≡ proj₁ m′) □
where
lemma : ∀ Y → (Y ⇨ X) ↔ (Y PC.⇨ X)
lemma Y = ∃-cong λ _ → ≡↔≡
-- M-coalgebra C is a final coalgebra.
--
-- The lemma M-final′′ is based on code written by Andrea Vezzosi for
-- the cubical library.
M-final′ :
(C : Container I s p) →
Final′ (M-coalgebra C)
M-final′ C = _≃_.from (Final′≃Final′ (M-coalgebra C)) M-final′′
| {
"alphanum_fraction": 0.469358585,
"avg_line_length": 32.9235294118,
"ext": "agda",
"hexsha": "5e539b1179b9b3e1dc5433256496372c21f0f475",
"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/Container/Indexed/Variant/M/Codata.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/Container/Indexed/Variant/M/Codata.agda",
"max_line_length": 116,
"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/Container/Indexed/Variant/M/Codata.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": 2109,
"size": 5597
} |
{-# OPTIONS --without-K --exact-split #-}
module rings where
import abelian-groups
open abelian-groups public
has-mul-Ab :
{ l1 : Level} (A : Ab l1) → UU l1
has-mul-Ab A =
Σ ( has-associative-bin-op (set-Ab A))
( λ μ →
( is-unital (pair (set-Ab A) μ)) ×
( ( (a b c : type-Ab A) →
Id (pr1 μ a (add-Ab A b c)) (add-Ab A (pr1 μ a b) (pr1 μ a c))) ×
( (a b c : type-Ab A) →
Id (pr1 μ (add-Ab A a b) c) (add-Ab A (pr1 μ a c) (pr1 μ b c)))))
Ring : (l1 : Level) → UU (lsuc l1)
Ring l1 = Σ (Ab l1) has-mul-Ab
{- Basic infrastructure of rings -}
ab-Ring : {l1 : Level} → Ring l1 → Ab l1
ab-Ring R = pr1 R
group-Ring :
{l : Level} (R : Ring l) → Group l
group-Ring R = group-Ab (ab-Ring R)
set-Ring :
{l : Level} (R : Ring l) → UU-Set l
set-Ring R = set-Ab (ab-Ring R)
type-Ring :
{l : Level} (R : Ring l) → UU l
type-Ring R = type-Ab (ab-Ring R)
is-set-type-Ring :
{l : Level} (R : Ring l) → is-set (type-Ring R)
is-set-type-Ring R = is-set-type-Ab (ab-Ring R)
associative-add-Ring :
{l : Level} (R : Ring l) → has-associative-bin-op (set-Ring R)
associative-add-Ring R = associative-add-Ab (ab-Ring R)
add-Ring :
{l : Level} (R : Ring l) → type-Ring R → type-Ring R → type-Ring R
add-Ring R = add-Ab (ab-Ring R)
is-associative-add-Ring :
{l : Level} (R : Ring l) (x y z : type-Ring R) →
Id (add-Ring R (add-Ring R x y) z) (add-Ring R x (add-Ring R y z))
is-associative-add-Ring R = is-associative-add-Ab (ab-Ring R)
additive-semi-group-Ring :
{l : Level} (R : Ring l) → Semi-Group l
additive-semi-group-Ring R = semi-group-Ab (ab-Ring R)
is-group-additive-semi-group-Ring :
{l : Level} (R : Ring l) → is-group (additive-semi-group-Ring R)
is-group-additive-semi-group-Ring R = is-group-Ab (ab-Ring R)
has-zero-Ring :
{l : Level} (R : Ring l) → is-unital (additive-semi-group-Ring R)
has-zero-Ring R = has-zero-Ab (ab-Ring R)
zero-Ring :
{l : Level} (R : Ring l) → type-Ring R
zero-Ring R = zero-Ab (ab-Ring R)
left-zero-law-add-Ring :
{l : Level} (R : Ring l) (x : type-Ring R) →
Id (add-Ring R (zero-Ring R) x) x
left-zero-law-add-Ring R = left-zero-law-Ab (ab-Ring R)
right-zero-law-add-Ring :
{l : Level} (R : Ring l) (x : type-Ring R) →
Id (add-Ring R x (zero-Ring R)) x
right-zero-law-add-Ring R = right-zero-law-Ab (ab-Ring R)
has-negatives-Ring :
{l : Level} (R : Ring l) →
is-group' (additive-semi-group-Ring R) (has-zero-Ring R)
has-negatives-Ring R = has-negatives-Ab (ab-Ring R)
neg-Ring :
{l : Level} (R : Ring l) → type-Ring R → type-Ring R
neg-Ring R = neg-Ab (ab-Ring R)
left-negative-law-Ring :
{l : Level} (R : Ring l) (x : type-Ring R) →
Id (add-Ring R (neg-Ring R x) x) (zero-Ring R)
left-negative-law-Ring R = left-negative-law-Ab (ab-Ring R)
right-negative-law-Ring :
{l : Level} (R : Ring l) (x : type-Ring R) →
Id (add-Ring R x (neg-Ring R x)) (zero-Ring R)
right-negative-law-Ring R = right-negative-law-Ab (ab-Ring R)
is-commutative-add-Ring :
{l : Level} (R : Ring l) (x y : type-Ring R) →
Id (add-Ring R x y) (add-Ring R y x)
is-commutative-add-Ring R = is-commutative-add-Ab (ab-Ring R)
has-associative-mul-Ring :
{l : Level} (R : Ring l) → has-associative-bin-op (set-Ring R)
has-associative-mul-Ring R = pr1 (pr2 R)
mul-Ring :
{l : Level} (R : Ring l) → type-Ring R → type-Ring R → type-Ring R
mul-Ring R = pr1 (has-associative-mul-Ring R)
is-associative-mul-Ring :
{l : Level} (R : Ring l) (x y z : type-Ring R) →
Id (mul-Ring R (mul-Ring R x y) z) (mul-Ring R x (mul-Ring R y z))
is-associative-mul-Ring R = pr2 (has-associative-mul-Ring R)
multiplicative-semi-group-Ring :
{l : Level} (R : Ring l) → Semi-Group l
multiplicative-semi-group-Ring R =
pair (set-Ring R) (has-associative-mul-Ring R)
is-unital-Ring :
{l : Level} (R : Ring l) → is-unital (multiplicative-semi-group-Ring R)
is-unital-Ring R = pr1 (pr2 (pr2 R))
multiplicative-monoid-Ring :
{l : Level} (R : Ring l) → Monoid l
multiplicative-monoid-Ring R =
pair (multiplicative-semi-group-Ring R) (is-unital-Ring R)
unit-Ring :
{l : Level} (R : Ring l) → type-Ring R
unit-Ring R = unit-Monoid (multiplicative-monoid-Ring R)
left-unit-law-mul-Ring :
{l : Level} (R : Ring l) (x : type-Ring R) →
Id (mul-Ring R (unit-Ring R) x) x
left-unit-law-mul-Ring R = left-unit-law-Monoid (multiplicative-monoid-Ring R)
right-unit-law-mul-Ring :
{l : Level} (R : Ring l) (x : type-Ring R) →
Id (mul-Ring R x (unit-Ring R)) x
right-unit-law-mul-Ring R = right-unit-law-Monoid (multiplicative-monoid-Ring R)
left-distributive-law-mul-add-Ring :
{l : Level} (R : Ring l) (x y z : type-Ring R) →
Id ( mul-Ring R x (add-Ring R y z))
( add-Ring R (mul-Ring R x y) (mul-Ring R x z))
left-distributive-law-mul-add-Ring R =
pr1 (pr2 (pr2 (pr2 R)))
right-distributive-law-mul-add-Ring :
{l : Level} (R : Ring l) (x y z : type-Ring R) →
Id ( mul-Ring R (add-Ring R x y) z)
( add-Ring R (mul-Ring R x z) (mul-Ring R y z))
right-distributive-law-mul-add-Ring R =
pr2 (pr2 (pr2 (pr2 R)))
{- Ring homomorphisms -}
preserves-mul-hom-Ab :
{l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) →
hom-Ab (ab-Ring R1) (ab-Ring R2) → UU (l1 ⊔ l2)
preserves-mul-hom-Ab R1 R2 f =
(x y : type-Ring R1) →
Id ( map-hom-Ab (ab-Ring R1) (ab-Ring R2) f (mul-Ring R1 x y))
( mul-Ring R2
( map-hom-Ab (ab-Ring R1) (ab-Ring R2) f x)
( map-hom-Ab (ab-Ring R1) (ab-Ring R2) f y))
is-prop-preserves-mul-hom-Ab :
{l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) →
( f : hom-Ab (ab-Ring R1) (ab-Ring R2)) →
is-prop (preserves-mul-hom-Ab R1 R2 f)
is-prop-preserves-mul-hom-Ab R1 R2 f =
is-prop-Π
( λ x →
is-prop-Π
( λ y →
is-set-type-Ring R2
( map-hom-Ab (ab-Ring R1) (ab-Ring R2) f (mul-Ring R1 x y))
( mul-Ring R2
( map-hom-Ab (ab-Ring R1) (ab-Ring R2) f x)
( map-hom-Ab (ab-Ring R1) (ab-Ring R2) f y))))
preserves-unit-hom-Ab :
{l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) →
hom-Ab (ab-Ring R1) (ab-Ring R2) → UU l2
preserves-unit-hom-Ab R1 R2 f =
Id (map-hom-Ab (ab-Ring R1) (ab-Ring R2) f (unit-Ring R1)) (unit-Ring R2)
is-prop-preserves-unit-hom-Ab :
{l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) →
( f : hom-Ab (ab-Ring R1) (ab-Ring R2)) →
is-prop (preserves-unit-hom-Ab R1 R2 f)
is-prop-preserves-unit-hom-Ab R1 R2 f =
is-set-type-Ring R2
( map-hom-Ab (ab-Ring R1) (ab-Ring R2) f (unit-Ring R1))
( unit-Ring R2)
is-ring-homomorphism-hom-Ab :
{l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) →
( f : hom-Ab (ab-Ring R1) (ab-Ring R2)) → UU (l1 ⊔ l2)
is-ring-homomorphism-hom-Ab R1 R2 f =
preserves-mul-hom-Ab R1 R2 f × preserves-unit-hom-Ab R1 R2 f
is-prop-is-ring-homomorphism-hom-Ab :
{l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) →
( f : hom-Ab (ab-Ring R1) (ab-Ring R2)) →
is-prop (is-ring-homomorphism-hom-Ab R1 R2 f)
is-prop-is-ring-homomorphism-hom-Ab R1 R2 f =
is-prop-prod
( is-prop-preserves-mul-hom-Ab R1 R2 f)
( is-prop-preserves-unit-hom-Ab R1 R2 f)
hom-Ring :
{l1 l2 : Level} (R1 : Ring l1) (R : Ring l2) → UU (l1 ⊔ l2)
hom-Ring R1 R2 =
Σ (hom-Ab (ab-Ring R1) (ab-Ring R2)) (is-ring-homomorphism-hom-Ab R1 R2)
{- Basic infrastructure for ring homomorphisms. -}
hom-Ab-hom-Ring :
{l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) →
hom-Ring R1 R2 → hom-Ab (ab-Ring R1) (ab-Ring R2)
hom-Ab-hom-Ring R1 R2 = pr1
map-hom-Ring :
{l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) →
hom-Ring R1 R2 → type-Ring R1 → type-Ring R2
map-hom-Ring R1 R2 f =
map-hom-Ab (ab-Ring R1) (ab-Ring R2) (hom-Ab-hom-Ring R1 R2 f)
preserves-add-hom-Ring :
{l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) →
(f : hom-Ring R1 R2) →
preserves-add (ab-Ring R1) (ab-Ring R2) (map-hom-Ring R1 R2 f)
preserves-add-hom-Ring R1 R2 f =
preserves-add-Ab (ab-Ring R1) (ab-Ring R2) (hom-Ab-hom-Ring R1 R2 f)
preserves-mul-hom-Ring :
{l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) →
(f : hom-Ring R1 R2) → preserves-mul-hom-Ab R1 R2 (hom-Ab-hom-Ring R1 R2 f)
preserves-mul-hom-Ring R1 R2 f = pr1 (pr2 f)
preserves-unit-hom-Ring :
{l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) →
(f : hom-Ring R1 R2) → preserves-unit-hom-Ab R1 R2 (hom-Ab-hom-Ring R1 R2 f)
preserves-unit-hom-Ring R1 R2 f = pr2 (pr2 f)
is-ring-homomorphism-hom-Ring :
{l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) →
(f : hom-Ring R1 R2) →
prod ( preserves-mul-hom-Ab R1 R2 (hom-Ab-hom-Ring R1 R2 f))
( preserves-unit-hom-Ab R1 R2 (hom-Ab-hom-Ring R1 R2 f))
is-ring-homomorphism-hom-Ring R1 R2 f =
pair ( preserves-mul-hom-Ring R1 R2 f)
( preserves-unit-hom-Ring R1 R2 f)
{- We characterize the identity type of ring homomorphisms -}
htpy-hom-Ring :
{l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) →
hom-Ring R1 R2 → hom-Ring R1 R2 → UU (l1 ⊔ l2)
htpy-hom-Ring R1 R2 f g = map-hom-Ring R1 R2 f ~ map-hom-Ring R1 R2 g
reflexive-htpy-hom-Ring :
{l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) →
(f : hom-Ring R1 R2) → htpy-hom-Ring R1 R2 f f
reflexive-htpy-hom-Ring R1 R2 f = refl-htpy
htpy-hom-Ring-eq :
{l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) →
(f g : hom-Ring R1 R2) → Id f g → htpy-hom-Ring R1 R2 f g
htpy-hom-Ring-eq R1 R2 f .f refl = reflexive-htpy-hom-Ring R1 R2 f
is-contr-total-htpy-hom-Ring :
{l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) →
is-contr (Σ (hom-Ring R1 R2) (htpy-hom-Ring R1 R2 f))
is-contr-total-htpy-hom-Ring R1 R2 f =
is-contr-total-Eq-substructure
( is-contr-total-htpy-hom-Ab
( ab-Ring R1)
( ab-Ring R2)
( hom-Ab-hom-Ring R1 R2 f))
( is-prop-is-ring-homomorphism-hom-Ab R1 R2)
( hom-Ab-hom-Ring R1 R2 f)
( reflexive-htpy-hom-Ring R1 R2 f)
( is-ring-homomorphism-hom-Ring R1 R2 f)
is-equiv-htpy-hom-Ring-eq :
{l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f g : hom-Ring R1 R2) →
is-equiv (htpy-hom-Ring-eq R1 R2 f g)
is-equiv-htpy-hom-Ring-eq R1 R2 f =
fundamental-theorem-id f
( reflexive-htpy-hom-Ring R1 R2 f)
( is-contr-total-htpy-hom-Ring R1 R2 f)
( htpy-hom-Ring-eq R1 R2 f)
equiv-htpy-hom-Ring-eq :
{l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f g : hom-Ring R1 R2) →
Id f g ≃ htpy-hom-Ring R1 R2 f g
equiv-htpy-hom-Ring-eq R1 R2 f g =
pair
( htpy-hom-Ring-eq R1 R2 f g)
( is-equiv-htpy-hom-Ring-eq R1 R2 f g)
eq-htpy-hom-Ring :
{l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f g : hom-Ring R1 R2) →
htpy-hom-Ring R1 R2 f g → Id f g
eq-htpy-hom-Ring R1 R2 f g =
inv-is-equiv (is-equiv-htpy-hom-Ring-eq R1 R2 f g)
is-set-hom-Ring :
{l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → is-set (hom-Ring R1 R2)
is-set-hom-Ring R1 R2 =
is-trunc-succ-subtype
( neg-one-𝕋)
( is-prop-is-ring-homomorphism-hom-Ab R1 R2)
( is-set-hom-Ab (ab-Ring R1) (ab-Ring R2))
{- We define the categorical structure of rings -}
preserves-mul-id-hom-Ring :
{l : Level} (R : Ring l) → preserves-mul-hom-Ab R R (id-hom-Ab (ab-Ring R))
preserves-mul-id-hom-Ring R x y = refl
preserves-unit-id-hom-Ring :
{l : Level} (R : Ring l) → preserves-unit-hom-Ab R R (id-hom-Ab (ab-Ring R))
preserves-unit-id-hom-Ring R = refl
is-ring-homomorphism-id-hom-Ring :
{l : Level} (R : Ring l) → is-ring-homomorphism-hom-Ab R R (id-hom-Ab (ab-Ring R))
is-ring-homomorphism-id-hom-Ring R =
pair (preserves-mul-id-hom-Ring R) (preserves-unit-id-hom-Ring R)
id-hom-Ring :
{l : Level} (R : Ring l) → hom-Ring R R
id-hom-Ring R = pair (id-hom-Ab (ab-Ring R)) (is-ring-homomorphism-id-hom-Ring R)
hom-Ab-comp-hom-Ring :
{ l1 l2 l3 : Level} (R1 : Ring l1) (R2 : Ring l2) (R3 : Ring l3) →
( g : hom-Ring R2 R3) (f : hom-Ring R1 R2) →
hom-Ab (ab-Ring R1) (ab-Ring R3)
hom-Ab-comp-hom-Ring R1 R2 R3 g f =
comp-hom-Ab
( ab-Ring R1)
( ab-Ring R2)
( ab-Ring R3)
( hom-Ab-hom-Ring R2 R3 g)
( hom-Ab-hom-Ring R1 R2 f)
preserves-mul-comp-hom-Ring :
{ l1 l2 l3 : Level} (R1 : Ring l1) (R2 : Ring l2) (R3 : Ring l3) →
( g : hom-Ring R2 R3) (f : hom-Ring R1 R2) →
preserves-mul-hom-Ab R1 R3 (hom-Ab-comp-hom-Ring R1 R2 R3 g f)
preserves-mul-comp-hom-Ring R1 R2 R3 g f x y =
( ap (map-hom-Ring R2 R3 g) (preserves-mul-hom-Ring R1 R2 f x y)) ∙
( preserves-mul-hom-Ring R2 R3 g
( map-hom-Ring R1 R2 f x)
( map-hom-Ring R1 R2 f y))
preserves-unit-comp-hom-Ring :
{ l1 l2 l3 : Level} (R1 : Ring l1) (R2 : Ring l2) (R3 : Ring l3) →
( g : hom-Ring R2 R3) (f : hom-Ring R1 R2) →
preserves-unit-hom-Ab R1 R3 (hom-Ab-comp-hom-Ring R1 R2 R3 g f)
preserves-unit-comp-hom-Ring R1 R2 R3 g f =
( ap (map-hom-Ring R2 R3 g) (preserves-unit-hom-Ring R1 R2 f)) ∙
( preserves-unit-hom-Ring R2 R3 g)
is-ring-homomorphism-comp-hom-Ring :
{ l1 l2 l3 : Level} (R1 : Ring l1) (R2 : Ring l2) (R3 : Ring l3) →
( g : hom-Ring R2 R3) (f : hom-Ring R1 R2) →
is-ring-homomorphism-hom-Ab R1 R3 (hom-Ab-comp-hom-Ring R1 R2 R3 g f)
is-ring-homomorphism-comp-hom-Ring R1 R2 R3 g f =
pair ( preserves-mul-comp-hom-Ring R1 R2 R3 g f)
( preserves-unit-comp-hom-Ring R1 R2 R3 g f)
comp-hom-Ring :
{ l1 l2 l3 : Level} (R1 : Ring l1) (R2 : Ring l2) (R3 : Ring l3) →
hom-Ring R2 R3 → hom-Ring R1 R2 → hom-Ring R1 R3
comp-hom-Ring R1 R2 R3 g f =
pair ( hom-Ab-comp-hom-Ring R1 R2 R3 g f)
( is-ring-homomorphism-comp-hom-Ring R1 R2 R3 g f)
{- We prove the laws of a category for Rings -}
is-associative-comp-hom-Ring :
{ l1 l2 l3 l4 : Level}
( R1 : Ring l1) (R2 : Ring l2) (R3 : Ring l3) (R4 : Ring l4) →
( h : hom-Ring R3 R4) (g : hom-Ring R2 R3) (f : hom-Ring R1 R2) →
Id (comp-hom-Ring R1 R2 R4 (comp-hom-Ring R2 R3 R4 h g) f)
(comp-hom-Ring R1 R3 R4 h (comp-hom-Ring R1 R2 R3 g f))
is-associative-comp-hom-Ring R1 R2 R3 R4 h g f =
eq-htpy-hom-Ring R1 R4
( comp-hom-Ring R1 R2 R4 (comp-hom-Ring R2 R3 R4 h g) f)
( comp-hom-Ring R1 R3 R4 h (comp-hom-Ring R1 R2 R3 g f))
( refl-htpy)
left-unit-law-comp-hom-Ring :
{ l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) →
Id (comp-hom-Ring R1 R2 R2 (id-hom-Ring R2) f) f
left-unit-law-comp-hom-Ring R1 R2 f =
eq-htpy-hom-Ring R1 R2
( comp-hom-Ring R1 R2 R2 (id-hom-Ring R2) f)
( f)
( refl-htpy)
right-unit-law-comp-hom-Ring :
{ l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) →
Id (comp-hom-Ring R1 R1 R2 f (id-hom-Ring R1)) f
right-unit-law-comp-hom-Ring R1 R2 f =
eq-htpy-hom-Ring R1 R2
( comp-hom-Ring R1 R1 R2 f (id-hom-Ring R1))
( f)
( refl-htpy)
{- We show that the forgetful map ab-Ring is a functor -}
id-law-ab-Ring :
{ l1 : Level} (R1 : Ring l1) →
Id (hom-Ab-hom-Ring R1 R1 (id-hom-Ring R1)) (id-hom-Ab (ab-Ring R1))
id-law-ab-Ring R1 =
eq-htpy-hom-Ab
( ab-Ring R1)
( ab-Ring R1)
( refl-htpy)
comp-law-ab-Ring :
{ l1 l2 l3 : Level} (R1 : Ring l1) (R2 : Ring l2) (R3 : Ring l3) →
( g : hom-Ring R2 R3) (f : hom-Ring R1 R2) →
Id ( hom-Ab-hom-Ring R1 R3 (comp-hom-Ring R1 R2 R3 g f))
( comp-hom-Ab
( ab-Ring R1)
( ab-Ring R2)
( ab-Ring R3)
( hom-Ab-hom-Ring R2 R3 g)
( hom-Ab-hom-Ring R1 R2 f))
comp-law-ab-Ring R1 R2 R3 g f =
eq-htpy-hom-Ab
( ab-Ring R1)
( ab-Ring R3)
( refl-htpy)
{- We introduce ring isomorphisms -}
is-iso-hom-Ring :
{ l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) →
hom-Ring R1 R2 → UU (l1 ⊔ l2)
is-iso-hom-Ring R1 R2 f =
Σ ( hom-Ring R2 R1)
( λ g →
( Id (comp-hom-Ring R2 R1 R2 f g) (id-hom-Ring R2)) ×
( Id (comp-hom-Ring R1 R2 R1 g f) (id-hom-Ring R1)))
{- Infrastructure for invertible ring homomorphisms -}
inv-is-iso-hom-Ring :
{ l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) →
is-iso-hom-Ring R1 R2 f → hom-Ring R2 R1
inv-is-iso-hom-Ring R1 R2 f = pr1
is-sec-inv-is-iso-hom-Ring :
{ l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) →
( is-iso-f : is-iso-hom-Ring R1 R2 f) →
Id (comp-hom-Ring R2 R1 R2 f (inv-is-iso-hom-Ring R1 R2 f is-iso-f))
(id-hom-Ring R2)
is-sec-inv-is-iso-hom-Ring R1 R2 f is-iso-f = pr1 (pr2 is-iso-f)
is-retr-inv-is-iso-hom-Ring :
{ l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) →
( is-iso-f : is-iso-hom-Ring R1 R2 f) →
Id (comp-hom-Ring R1 R2 R1 (inv-is-iso-hom-Ring R1 R2 f is-iso-f) f)
(id-hom-Ring R1)
is-retr-inv-is-iso-hom-Ring R1 R2 f is-iso-f = pr2 (pr2 is-iso-f)
inv-map-is-iso-hom-Ring :
{ l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) →
is-iso-hom-Ring R1 R2 f → type-Ring R2 → type-Ring R1
inv-map-is-iso-hom-Ring R1 R2 f is-iso-f =
map-hom-Ring R2 R1 (inv-is-iso-hom-Ring R1 R2 f is-iso-f)
is-sec-inv-map-is-iso-hom-Ring :
{ l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) →
( is-iso-f : is-iso-hom-Ring R1 R2 f) →
( (map-hom-Ring R1 R2 f) ∘ (inv-map-is-iso-hom-Ring R1 R2 f is-iso-f)) ~ id
is-sec-inv-map-is-iso-hom-Ring R1 R2 f is-iso-f =
htpy-hom-Ring-eq R2 R2
( comp-hom-Ring R2 R1 R2 f (inv-is-iso-hom-Ring R1 R2 f is-iso-f))
( id-hom-Ring R2)
( is-sec-inv-is-iso-hom-Ring R1 R2 f is-iso-f)
is-retr-inv-map-is-iso-hom-Ring :
{ l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) →
( is-iso-f : is-iso-hom-Ring R1 R2 f) →
( (inv-map-is-iso-hom-Ring R1 R2 f is-iso-f) ∘ (map-hom-Ring R1 R2 f)) ~ id
is-retr-inv-map-is-iso-hom-Ring R1 R2 f is-iso-f =
htpy-hom-Ring-eq R1 R1
( comp-hom-Ring R1 R2 R1 (inv-is-iso-hom-Ring R1 R2 f is-iso-f) f)
( id-hom-Ring R1)
( is-retr-inv-is-iso-hom-Ring R1 R2 f is-iso-f)
{- Being invertible is a property -}
is-prop-is-iso-hom-Ring' :
{ l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) →
is-prop' (is-iso-hom-Ring R1 R2 f)
is-prop-is-iso-hom-Ring' R1 R2 f inv-f inv-f' =
eq-subtype
( λ g →
is-prop-prod
( is-set-hom-Ring R2 R2 (comp-hom-Ring R2 R1 R2 f g) (id-hom-Ring R2))
( is-set-hom-Ring R1 R1 (comp-hom-Ring R1 R2 R1 g f) (id-hom-Ring R1)))
( eq-htpy-hom-Ring R2 R1
( inv-is-iso-hom-Ring R1 R2 f inv-f)
( inv-is-iso-hom-Ring R1 R2 f inv-f')
( λ x →
( inv
( ap ( map-hom-Ring R2 R1 (pr1 inv-f))
( is-sec-inv-map-is-iso-hom-Ring R1 R2 f inv-f' x))) ∙
( is-retr-inv-map-is-iso-hom-Ring R1 R2 f inv-f
( map-hom-Ring R2 R1 (pr1 inv-f') x))))
is-prop-is-iso-hom-Ring :
{ l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) →
is-prop (is-iso-hom-Ring R1 R2 f)
is-prop-is-iso-hom-Ring R1 R2 f =
is-prop-is-prop' (is-prop-is-iso-hom-Ring' R1 R2 f)
iso-Ring :
{ l1 l2 : Level} → Ring l1 → Ring l2 → UU (l1 ⊔ l2)
iso-Ring R1 R2 = Σ (hom-Ring R1 R2) (is-iso-hom-Ring R1 R2)
hom-iso-Ring :
{ l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) →
iso-Ring R1 R2 → hom-Ring R1 R2
hom-iso-Ring R1 R2 = pr1
is-iso-hom-iso-Ring :
{ l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) →
( f : iso-Ring R1 R2) → is-iso-hom-Ring R1 R2 (hom-iso-Ring R1 R2 f)
is-iso-hom-iso-Ring R1 R2 = pr2
inv-hom-iso-Ring :
{ l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) →
iso-Ring R1 R2 → hom-Ring R2 R1
inv-hom-iso-Ring R1 R2 f =
inv-is-iso-hom-Ring R1 R2
( hom-iso-Ring R1 R2 f)
( is-iso-hom-iso-Ring R1 R2 f)
is-iso-id-hom-Ring :
{ l1 : Level} (R1 : Ring l1) → is-iso-hom-Ring R1 R1 (id-hom-Ring R1)
is-iso-id-hom-Ring R1 =
pair ( id-hom-Ring R1)
( pair
( left-unit-law-comp-hom-Ring R1 R1 (id-hom-Ring R1))
( left-unit-law-comp-hom-Ring R1 R1 (id-hom-Ring R1)))
id-iso-Ring :
{ l1 : Level} (R1 : Ring l1) → iso-Ring R1 R1
id-iso-Ring R1 = pair (id-hom-Ring R1) (is-iso-id-hom-Ring R1)
iso-eq-Ring :
{ l : Level} (R1 R2 : Ring l) → Id R1 R2 → iso-Ring R1 R2
iso-eq-Ring R1 .R1 refl = id-iso-Ring R1
{- We first show that a ring homomorphism is an isomorphism if and only if
the underlying homomorphism of abelian groups is an isomorphism. -}
is-iso-hom-Ab-hom-Ring :
{ l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) →
hom-Ring R1 R2 → UU (l1 ⊔ l2)
is-iso-hom-Ab-hom-Ring R1 R2 f =
is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) (hom-Ab-hom-Ring R1 R2 f)
is-iso-hom-Ab-is-iso-hom-Ring :
{ l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) →
is-iso-hom-Ring R1 R2 f →
is-iso-hom-Ab-hom-Ring R1 R2 f
is-iso-hom-Ab-is-iso-hom-Ring R1 R2 f is-iso-f =
pair ( hom-Ab-hom-Ring R2 R1 (inv-is-iso-hom-Ring R1 R2 f is-iso-f))
( pair
( ap ( hom-Ab-hom-Ring R2 R2)
( is-sec-inv-is-iso-hom-Ring R1 R2 f is-iso-f))
( ap ( hom-Ab-hom-Ring R1 R1)
( is-retr-inv-is-iso-hom-Ring R1 R2 f is-iso-f)))
abstract
preserves-mul-inv-is-iso-hom-Ab :
{ l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) →
( f : hom-Ab (ab-Ring R1) (ab-Ring R2)) →
( is-iso-f : is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f) →
( pres-mul-f : preserves-mul-hom-Ab R1 R2 f) →
preserves-mul-hom-Ab R2 R1
( inv-is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f is-iso-f)
preserves-mul-inv-is-iso-hom-Ab R1 R2 f is-iso-f pres-mul-f x y =
( inv
( ap
( map-inv-is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f is-iso-f)
( ( pres-mul-f
( map-inv-is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f is-iso-f x)
( map-inv-is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f is-iso-f y)) ∙
( ( ap ( mul-Ring R2
( map-hom-Ab (ab-Ring R1) (ab-Ring R2) f
( map-inv-is-iso-hom-Ab
( ab-Ring R1)
( ab-Ring R2)
f is-iso-f x)))
( is-sec-map-inv-is-iso-hom-Ab
( ab-Ring R1)
( ab-Ring R2)
( f)
( is-iso-f)
( y))) ∙
( ap ( λ z → mul-Ring R2 z y)
( is-sec-map-inv-is-iso-hom-Ab
( ab-Ring R1)
( ab-Ring R2)
( f)
( is-iso-f)
( x))))))) ∙
( is-retr-map-inv-is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f is-iso-f
( mul-Ring R1
( map-inv-is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f is-iso-f x)
( map-inv-is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f is-iso-f y)))
preserves-unit-inv-is-iso-hom-Ab :
{ l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2)
( f : hom-Ab (ab-Ring R1) (ab-Ring R2)) →
( is-iso-f : is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f)
( pres-unit-f : preserves-unit-hom-Ab R1 R2 f) →
preserves-unit-hom-Ab R2 R1
( inv-is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f is-iso-f)
preserves-unit-inv-is-iso-hom-Ab R1 R2 f is-iso-f pres-unit-f =
( inv
( ap
( map-inv-is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f is-iso-f)
( pres-unit-f))) ∙
( is-retr-map-inv-is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f is-iso-f
( unit-Ring R1))
is-ring-homomorphism-inv-is-iso-hom-Ab :
{ l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2)
( f : hom-Ab (ab-Ring R1) (ab-Ring R2)) →
( is-iso-f : is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f) →
( is-ring-hom-f : is-ring-homomorphism-hom-Ab R1 R2 f) →
is-ring-homomorphism-hom-Ab R2 R1
( inv-is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f is-iso-f)
is-ring-homomorphism-inv-is-iso-hom-Ab
R1 R2 f is-iso-f (pair pres-mul-f pres-unit-f) =
pair
( preserves-mul-inv-is-iso-hom-Ab R1 R2 f is-iso-f pres-mul-f)
( preserves-unit-inv-is-iso-hom-Ab R1 R2 f is-iso-f pres-unit-f)
inv-hom-Ring-is-iso-hom-Ab :
{ l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) (f : hom-Ring R1 R2) →
( is-iso-f : is-iso-hom-Ab
( ab-Ring R1)
( ab-Ring R2)
( hom-Ab-hom-Ring R1 R2 f)) →
hom-Ring R2 R1
inv-hom-Ring-is-iso-hom-Ab R1 R2 f is-iso-f =
pair
( inv-is-iso-hom-Ab
( ab-Ring R1)
( ab-Ring R2)
( hom-Ab-hom-Ring R1 R2 f)
( is-iso-f))
( is-ring-homomorphism-inv-is-iso-hom-Ab R1 R2
( hom-Ab-hom-Ring R1 R2 f)
( is-iso-f)
( is-ring-homomorphism-hom-Ring R1 R2 f))
abstract
is-iso-hom-Ring-is-iso-hom-Ab :
{ l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2)
( f : hom-Ring R1 R2) →
is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) (hom-Ab-hom-Ring R1 R2 f) →
is-iso-hom-Ring R1 R2 f
is-iso-hom-Ring-is-iso-hom-Ab R1 R2 f is-iso-f =
pair
( inv-hom-Ring-is-iso-hom-Ab R1 R2 f is-iso-f)
( pair
( eq-htpy-hom-Ring R2 R2
( comp-hom-Ring R2 R1 R2 f
( inv-hom-Ring-is-iso-hom-Ab R1 R2 f is-iso-f))
( id-hom-Ring R2)
( htpy-hom-Ab-eq (ab-Ring R2) (ab-Ring R2)
( hom-Ab-hom-Ring R2 R2
( comp-hom-Ring R2 R1 R2 f
( inv-hom-Ring-is-iso-hom-Ab R1 R2 f is-iso-f)))
( id-hom-Ab (ab-Ring R2))
( is-sec-inv-is-iso-hom-Ab
( ab-Ring R1)
( ab-Ring R2)
( hom-Ab-hom-Ring R1 R2 f)
( is-iso-f))))
( eq-htpy-hom-Ring R1 R1
( comp-hom-Ring R1 R2 R1
( inv-hom-Ring-is-iso-hom-Ab R1 R2 f is-iso-f)
( f))
( id-hom-Ring R1)
( htpy-hom-Ab-eq (ab-Ring R1) (ab-Ring R1)
( hom-Ab-hom-Ring R1 R1
( comp-hom-Ring R1 R2 R1
( inv-hom-Ring-is-iso-hom-Ab R1 R2 f is-iso-f)
( f)))
( id-hom-Ab (ab-Ring R1))
( is-retr-inv-is-iso-hom-Ab
( ab-Ring R1)
( ab-Ring R2)
( hom-Ab-hom-Ring R1 R2 f)
( is-iso-f)))))
iso-Ab-Ring :
{ l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) → UU (l1 ⊔ l2)
iso-Ab-Ring R1 R2 =
Σ ( iso-Ab (ab-Ring R1) (ab-Ring R2))
( λ f →
is-ring-homomorphism-hom-Ab R1 R2
( hom-iso-Ab (ab-Ring R1) (ab-Ring R2) f))
iso-Ab-iso-Ab-Ring :
{ l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) →
iso-Ab-Ring R1 R2 → iso-Ab (ab-Ring R1) (ab-Ring R2)
iso-Ab-iso-Ab-Ring R1 R2 = pr1
iso-Ab-iso-Ring :
{ l1 l2 : Level} (R1 : Ring l1) (R2 : Ring l2) →
iso-Ring R1 R2 → iso-Ab (ab-Ring R1) (ab-Ring R2)
iso-Ab-iso-Ring R1 R2 f =
pair ( hom-Ab-hom-Ring R1 R2 (hom-iso-Ring R1 R2 f))
( is-iso-hom-Ab-is-iso-hom-Ring R1 R2
( hom-iso-Ring R1 R2 f)
( is-iso-hom-iso-Ring R1 R2 f))
equiv-iso-Ab-iso-Ring :
{ l1 : Level} (R1 : Ring l1) (R2 : Ring l1) →
(iso-Ring R1 R2) ≃ (iso-Ab-Ring R1 R2)
equiv-iso-Ab-iso-Ring R1 R2 =
( ( ( inv-equiv
( equiv-Σ-assoc
( hom-Ab (ab-Ring R1) (ab-Ring R2))
( is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2))
( λ f → is-ring-homomorphism-hom-Ab R1 R2 (pr1 f)))) ∘e
( equiv-tot
( λ f →
equiv-swap-prod
( is-ring-homomorphism-hom-Ab R1 R2 f)
( is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) f)))) ∘e
( equiv-Σ-assoc
( hom-Ab (ab-Ring R1) (ab-Ring R2))
( is-ring-homomorphism-hom-Ab R1 R2)
( λ f → is-iso-hom-Ab (ab-Ring R1) (ab-Ring R2) (pr1 f)))) ∘e
( equiv-total-subtype
( is-prop-is-iso-hom-Ring R1 R2)
( λ f →
is-prop-is-iso-hom-Ab
( ab-Ring R1)
( ab-Ring R2)
( hom-Ab-hom-Ring R1 R2 f))
( is-iso-hom-Ab-is-iso-hom-Ring R1 R2)
( is-iso-hom-Ring-is-iso-hom-Ab R1 R2))
abstract
is-contr-total-iso-Ring :
{ l : Level} (R : Ring l) → is-contr (Σ (Ring l) (iso-Ring R))
is-contr-total-iso-Ring {l} R =
is-contr-equiv
( Σ (Ring l) (iso-Ab-Ring R))
( equiv-tot (equiv-iso-Ab-iso-Ring R))
( is-contr-total-Eq-structure
( λ A μ f →
is-ring-homomorphism-hom-Ab R (pair A μ) (hom-iso-Ab (ab-Ring R) A f))
( is-contr-total-iso-Ab (ab-Ring R))
( pair (ab-Ring R) (id-iso-Ab (ab-Ring R)))
( is-contr-total-Eq-structure
( λ μ H pres-mul → Id (unit-Ring R) (pr1 (pr1 H)))
( is-contr-total-Eq-substructure
( is-contr-total-Eq-Π
( λ x m → (y : type-Ring R) → Id (mul-Ring R x y) (m y))
( λ x → is-contr-total-htpy (mul-Ring R x))
( mul-Ring R))
( λ μ → is-prop-Π (λ x → is-prop-Π (λ y → is-prop-Π (λ z →
is-set-type-Ring R (μ (μ x y) z) (μ x (μ y z))))))
( mul-Ring R)
( λ x y → refl)
( is-associative-mul-Ring R))
( pair (pair (mul-Ring R) (is-associative-mul-Ring R)) (λ x y → refl))
( is-contr-total-Eq-substructure
( is-contr-total-Eq-substructure
( is-contr-total-path (unit-Ring R))
( λ x →
is-prop-prod
( is-prop-Π (λ y → is-set-type-Ring R (mul-Ring R x y) y))
( is-prop-Π (λ y → is-set-type-Ring R (mul-Ring R y x) y)))
( unit-Ring R)
( refl)
( pair (left-unit-law-mul-Ring R) (right-unit-law-mul-Ring R)))
( λ u →
is-prop-prod
( is-prop-Π (λ x → is-prop-Π (λ y → is-prop-Π (λ z →
is-set-type-Ring R
( mul-Ring R x (add-Ring R y z))
( add-Ring R (mul-Ring R x y) (mul-Ring R x z))))))
( is-prop-Π (λ x → is-prop-Π (λ y → is-prop-Π (λ z →
is-set-type-Ring R
( mul-Ring R (add-Ring R x y) z)
( add-Ring R (mul-Ring R x z) (mul-Ring R y z)))))))
( is-unital-Ring R)
( refl)
( pair
( left-distributive-law-mul-add-Ring R)
( right-distributive-law-mul-add-Ring R)))))
is-equiv-iso-eq-Ring :
{ l : Level} (R S : Ring l) → is-equiv (iso-eq-Ring R S)
is-equiv-iso-eq-Ring R =
fundamental-theorem-id R
( id-iso-Ring R)
( is-contr-total-iso-Ring R)
( iso-eq-Ring R)
eq-iso-Ring :
{ l : Level} (R S : Ring l) → iso-Ring R S → Id R S
eq-iso-Ring R S = inv-is-equiv (is-equiv-iso-eq-Ring R S)
| {
"alphanum_fraction": 0.5688128976,
"avg_line_length": 35.7963855422,
"ext": "agda",
"hexsha": "1292ca68b3d38cf9795bced0d4a570bdc7aeee2e",
"lang": "Agda",
"max_forks_count": 30,
"max_forks_repo_forks_event_max_datetime": "2022-03-16T00:33:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-26T09:08:57.000Z",
"max_forks_repo_head_hexsha": "1e1f8def50f9359928e52ebb2ee53ed1166487d9",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "UlrikBuchholtz/HoTT-Intro",
"max_forks_repo_path": "Agda/rings.agda",
"max_issues_count": 8,
"max_issues_repo_head_hexsha": "1e1f8def50f9359928e52ebb2ee53ed1166487d9",
"max_issues_repo_issues_event_max_datetime": "2020-10-16T15:27:01.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-18T04:16:04.000Z",
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "UlrikBuchholtz/HoTT-Intro",
"max_issues_repo_path": "Agda/rings.agda",
"max_line_length": 84,
"max_stars_count": 333,
"max_stars_repo_head_hexsha": "1e1f8def50f9359928e52ebb2ee53ed1166487d9",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Intro",
"max_stars_repo_path": "Agda/rings.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T23:50:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-09-26T08:33:30.000Z",
"num_tokens": 12617,
"size": 29711
} |
module Everything where
import Tuple
import Inductive
import Inductive.Examples.Empty
import Inductive.Examples.Unit
import Inductive.Examples.Sum
import Inductive.Examples.Product
import Inductive.Examples.Nat
import Inductive.Examples.Ord
import Inductive.Examples.List
import Inductive.Examples.BinTree
| {
"alphanum_fraction": 0.8668831169,
"avg_line_length": 22,
"ext": "agda",
"hexsha": "c4d909bd21d8a927dccd1cd3b404b98c91f0ba1b",
"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": "dc157acda597a2c758e82b5637e4fd6717ccec3f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mr-ohman/general-induction",
"max_forks_repo_path": "Everything.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "dc157acda597a2c758e82b5637e4fd6717ccec3f",
"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": "mr-ohman/general-induction",
"max_issues_repo_path": "Everything.agda",
"max_line_length": 33,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "dc157acda597a2c758e82b5637e4fd6717ccec3f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mr-ohman/general-induction",
"max_stars_repo_path": "Everything.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 71,
"size": 308
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import cohomology.Theory
open import groups.ExactSequence
open import groups.HomSequence
module cw.cohomology.GridLongExactSequence {i} (CT : CohomologyTheory i)
{X Y Z : Ptd i} (n : ℤ) (f : X ⊙→ Y) (g : Y ⊙→ Z) where
open CohomologyTheory CT
open import cohomology.PtdMapSequence CT
open import cw.cohomology.CofiberGrid (fst f) (fst g)
open import cw.cohomology.GridPtdMap f g
{-
X --> Y ----> Z
| |
v v
Y/X --> Z/X
| this |
v one v
1 ---> Z/Y
-}
private
⊙D-span : ⊙Span
⊙D-span = ⊙span Y/X Z Y (⊙cfcod' f) g
⊙D : Ptd i
⊙D = ⊙Pushout ⊙D-span
Y/X-to-D : Y/X ⊙→ ⊙D
Y/X-to-D = B/A-to-D , idp
open import cohomology.LongExactSequence CT n Y/X-to-D
⊙E : Ptd i
⊙E = ⊙Cofiber (⊙left ⊙D-span)
Z/Y-to-E : Z/Y ⊙→ ⊙E
Z/Y-to-E = C/B-to-E , idp
Z/X-to-D : Z/X ⊙→ ⊙D
Z/X-to-D = C/A-to-D , idp
grid-co∂ : C n Y/X →ᴳ C (succ n) Z/Y
grid-co∂ = record {f = CEl-fmap (succ n) Z/Y-to-E ∘ GroupHom.f co∂ ; pres-comp = lemma} where
abstract lemma = ∘-pres-comp (C-fmap (succ n) Z/Y-to-E) co∂
C-grid-cofiber-seq : HomSequence (C n Z/X) (C (succ n) Y/X)
C-grid-cofiber-seq =
C n Z/X →⟨ C-fmap n Y/X-to-Z/X ⟩ᴳ
C n Y/X →⟨ grid-co∂ ⟩ᴳ
C (succ n) Z/Y →⟨ C-fmap (succ n) Z/X-to-Z/Y ⟩ᴳ
C (succ n) Z/X →⟨ C-fmap (succ n) Y/X-to-Z/X ⟩ᴳ
C (succ n) Y/X ⊣|ᴳ
private
C-cofiber-seq-to-C-grid-cofiber-seq :
HomSeqMap C-cofiber-seq C-grid-cofiber-seq
(C-fmap n Z/X-to-D) (idhom _)
C-cofiber-seq-to-C-grid-cofiber-seq =
C-fmap n Z/X-to-D ↓⟨ comm-sqrᴳ (λ d → ! (C-fmap-idf n _)
∙ (C-comm-square n B/A-to-C/A-comm-square □$ᴳ d)) ⟩ᴳ
idhom _ ↓⟨ comm-sqrᴳ (λ _ → idp) ⟩ᴳ
C-fmap (succ n) Z/Y-to-E ↓⟨ C-comm-square (succ n) C/A-to-C/B-comm-square ⟩ᴳ
C-fmap (succ n) Z/X-to-D ↓⟨ comm-sqrᴳ (λ d → ! (C-fmap-idf (succ n) _)
∙ (C-comm-square (succ n) B/A-to-C/A-comm-square □$ᴳ d)) ⟩ᴳ
idhom _ ↓|ᴳ
C-cofiber-seq-equiv-C-grid-cofiber-seq :
HomSeqEquiv C-cofiber-seq C-grid-cofiber-seq
(C-fmap n Z/X-to-D) (idhom _)
C-cofiber-seq-equiv-C-grid-cofiber-seq =
C-cofiber-seq-to-C-grid-cofiber-seq ,
CEl-isemap n Z/X-to-D C/A-to-D-is-equiv ,
idf-is-equiv _ ,
CEl-isemap (succ n) Z/Y-to-E C/B-to-E-is-equiv ,
CEl-isemap (succ n) Z/X-to-D C/A-to-D-is-equiv ,
idf-is-equiv _
abstract
C-grid-cofiber-seq-is-exact : is-exact-seq C-grid-cofiber-seq
C-grid-cofiber-seq-is-exact = seq-equiv-preserves-exact
C-cofiber-seq-equiv-C-grid-cofiber-seq C-cofiber-seq-is-exact
C-grid-cofiber-exact-seq : ExactSequence (C n Z/X) (C (succ n) Y/X)
C-grid-cofiber-exact-seq = C-grid-cofiber-seq , C-grid-cofiber-seq-is-exact
| {
"alphanum_fraction": 0.5586515308,
"avg_line_length": 32.3,
"ext": "agda",
"hexsha": "662036d75eb4b5708929715f8609c355de54a5b9",
"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": "theorems/cw/cohomology/GridLongExactSequence.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": "theorems/cw/cohomology/GridLongExactSequence.agda",
"max_line_length": 107,
"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": "theorems/cw/cohomology/GridLongExactSequence.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1150,
"size": 2907
} |
------------------------------------------------------------------------
-- A compiler
------------------------------------------------------------------------
open import Prelude
import Lambda.Syntax
module Lambda.Compiler
{Name : Type}
(open Lambda.Syntax Name)
(def : Name → Tm 1)
where
open import Equality.Propositional
open import Tactic.By.Propositional
open import List equality-with-J using (_++_)
open import Vec.Data equality-with-J
open import Lambda.Virtual-machine.Instructions Name
private
module C = Closure Code
module T = Closure Tm
-- The compiler takes an argument of type In-tail-context. The value
-- "true" means that the term is in a tail context. (I have based the
-- definition of tail context on the one in Section 4.5 of "Revised⁵
-- Report on the Algorithmic Language Scheme" by Abelson et al.) The
-- value "false" means that no such information is present.
--
-- The compiler compiles calls claimed to be in a tail context in a
-- special way.
In-tail-context : Type
In-tail-context = Bool
-- The compiler (which takes a code continuation).
mutual
comp : ∀ {n} → In-tail-context → Tm n → Code n → Code n
comp _ (var x) c = var x ∷ c
comp _ (lam t) c = clo (comp-body t) ∷ c
comp _ (t₁ · t₂) c = comp false t₁ (comp false t₂ (app ∷ c))
comp true (call f t) c = comp false t (tcl f ∷ c)
comp false (call f t) c = comp false t (cal f ∷ c)
comp _ (con b) c = con b ∷ c
comp tc (if t₁ t₂ t₃) c =
comp false t₁ (bra (comp tc t₂ []) (comp tc t₃ []) ∷ c)
comp-body : ∀ {n} → Tm (suc n) → Code (suc n)
comp-body t = comp true t (ret ∷ [])
-- Compiler for named definitions.
comp-name : Name → Code 1
comp-name f = comp-body (def f)
-- Top-level compiler.
--
-- Note that the top-level expression is not assumed to be in a tail
-- context. Tail calls do not push a return frame on the stack. The
-- idea is to reuse an existing return frame, and the virtual machine
-- starts with an empty stack (which does not contain any return
-- frames).
comp₀ : Tm 0 → Code 0
comp₀ t = comp false t []
-- Environments and values can also be compiled.
mutual
comp-env : ∀ {n} → T.Env n → C.Env n
comp-env [] = []
comp-env (v ∷ ρ) = comp-val v ∷ comp-env ρ
comp-val : T.Value → C.Value
comp-val (T.lam t ρ) = C.lam (comp-body t) (comp-env ρ)
comp-val (T.con b) = C.con b
-- Indexing commutes with compilation.
comp-index : ∀ {n} (ρ : T.Env n) (x : Fin n) →
index (comp-env ρ) x ≡ comp-val (index ρ x)
comp-index (v ∷ ρ) fzero = refl
comp-index (v ∷ ρ) (fsuc i) = comp-index ρ i
-- The function comp tc t commutes with _++ c₂.
comp-++ :
∀ {n} tc (t : Tm n) {c₁ c₂ : Code n} →
comp tc t c₁ ++ c₂ ≡ comp tc t (c₁ ++ c₂)
comp-++ _ (var x) = refl
comp-++ _ (lam t) = refl
comp-++ true (call f t) = comp-++ _ t
comp-++ false (call f t) = comp-++ _ t
comp-++ _ (con b) = refl
comp-++ _ (if t₁ t₂ t₃) = comp-++ _ t₁
comp-++ _ (t₁ · t₂) {c₁} {c₂} =
comp false t₁ (comp false t₂ (app ∷ c₁)) ++ c₂ ≡⟨ comp-++ _ t₁ ⟩
comp false t₁ (comp false t₂ (app ∷ c₁) ++ c₂) ≡⟨ by (comp-++ _ t₂) ⟩∎
comp false t₁ (comp false t₂ (app ∷ c₁ ++ c₂)) ∎
| {
"alphanum_fraction": 0.576582085,
"avg_line_length": 30.858490566,
"ext": "agda",
"hexsha": "dbacb84d6db284c2a86db4327af90125c9ba1f8e",
"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": "dec8cd2d2851340840de25acb0feb78f7b5ffe96",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/definitional-interpreters",
"max_forks_repo_path": "src/Lambda/Compiler.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96",
"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/definitional-interpreters",
"max_issues_repo_path": "src/Lambda/Compiler.agda",
"max_line_length": 73,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/definitional-interpreters",
"max_stars_repo_path": "src/Lambda/Compiler.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1061,
"size": 3271
} |
module Bin-laws where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; sym; cong)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; step-≡; _∎)
open import Data.Nat using (ℕ; zero; suc; _+_; _*_)
open import Induction′ using (+-suc; +-identityʳ; +-comm; +-assoc)
-- 2進数の表現
data Bin : Set where
⟨⟩ : Bin
_O : Bin → Bin
_I : Bin → Bin
-- 2進数のインクリメント
inc : Bin → Bin
inc ⟨⟩ = ⟨⟩ I
inc (b O) = b I
inc (b I) = inc b O
-- 自然数から2進数への変換
to : ℕ → Bin
to zero = ⟨⟩ O
to (suc n) = inc (to n)
-- 2進数から自然数への変換
from : Bin → ℕ
from ⟨⟩ = zero
from (b O) = 2 * (from b)
from (b I) = 2 * (from b) + 1
2*n≡n+n : ∀ (n : ℕ) → 2 * n ≡ n + n
2*n≡n+n n =
begin
2 * n
≡⟨⟩
n + (1 * n)
≡⟨⟩
n + (n + (0 * n))
≡⟨⟩
n + (n + 0)
≡⟨ cong (n +_) (+-identityʳ n) ⟩
n + n
∎
+-suc-suc : ∀ (m n : ℕ) → (suc m) + (suc n) ≡ suc (suc (m + n))
+-suc-suc m n =
begin
(suc m) + (suc n)
≡⟨ +-suc (suc m) n ⟩
suc ((suc m) + n)
≡⟨ cong suc (sym (+-assoc 1 m n)) ⟩
suc (suc (m + n))
∎
-- 変換の前後どちらでインクリメントしても結果は等しい
from∘inc≡suc∘from : ∀ (b : Bin) → from (inc b) ≡ suc (from b)
from∘inc≡suc∘from ⟨⟩ =
begin
from (inc ⟨⟩)
≡⟨⟩
from (⟨⟩ I)
≡⟨⟩
suc zero
≡⟨⟩
suc (from ⟨⟩)
∎
from∘inc≡suc∘from (b O) =
begin
from (inc (b O))
≡⟨⟩
from (b I)
≡⟨⟩
2 * (from b) + 1
≡⟨⟩
from (b O) + 1
≡⟨ +-suc (from (b O)) zero ⟩
suc (from (b O) + zero)
≡⟨ cong suc (+-identityʳ (from (b O))) ⟩
suc (from (b O))
∎
from∘inc≡suc∘from (b I) =
begin
from (inc (b I))
≡⟨⟩
from ((inc b) O)
≡⟨⟩
2 * (from (inc b))
≡⟨ cong (2 *_) (from∘inc≡suc∘from b) ⟩
2 * (suc (from b))
≡⟨ 2*n≡n+n (suc (from b)) ⟩
(suc (from b)) + (suc (from b))
≡⟨ +-suc-suc (from b) (from b) ⟩
suc (suc ((from b) + (from b)))
≡⟨ cong (λ 2*fromb → suc (suc 2*fromb)) (sym (2*n≡n+n (from b))) ⟩
suc (suc (2 * (from b)))
≡⟨ cong suc (+-comm 1 (2 * (from b))) ⟩
suc (2 * (from b) + 1)
≡⟨⟩
suc (from (b I))
∎
-- to∘from : ∀ (b : Bin) → to (from b) ≡ b
-- to∘from ⟨⟩ = {!!} -- (to zero) が (⟨⟩ O) にエンコードされるため成り立たない
-- to∘from (b O) = {!!}
-- to∘from (b I) = {!!}
from∘to : ∀ (n : ℕ) → from (to n) ≡ n
from∘to zero =
begin
from (to zero)
≡⟨⟩
from (⟨⟩ O)
≡⟨⟩
2 * (from ⟨⟩)
≡⟨⟩
2 * zero
≡⟨⟩
zero
∎
from∘to (suc n) =
begin
from (to (suc n))
≡⟨⟩
from (inc (to n))
≡⟨ from∘inc≡suc∘from (to n) ⟩
suc (from (to n))
≡⟨ cong suc (from∘to n) ⟩
suc n
∎
| {
"alphanum_fraction": 0.4582664526,
"avg_line_length": 18.8787878788,
"ext": "agda",
"hexsha": "8dff0bd2bbde90268be9abcd037d73fe04a1dd20",
"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/induction/Bin-laws.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/induction/Bin-laws.agda",
"max_line_length": 68,
"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/induction/Bin-laws.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": 1337,
"size": 2492
} |
-- Previously Agda accepted invalid module names when no module header
-- was given.
| {
"alphanum_fraction": 0.7764705882,
"avg_line_length": 28.3333333333,
"ext": "agda",
"hexsha": "6ebaad00e822a6f9ffb824fcca7e67ca6cea16bf",
"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/_.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/_.agda",
"max_line_length": 70,
"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/_.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": 17,
"size": 85
} |
module RandomAccessList.General.Redundant where
open import RandomAccessList.General.Core
open import Data.Nat
Redundant : Set → ℕ → Set
Redundant A = General A 0 2
cons : ∀ {n A} → A → Redundant A n → Redundant A n
cons a [] = ?
cons a (∺ x x₁ x₂ xs) = ?
| {
"alphanum_fraction": 0.6884615385,
"avg_line_length": 20,
"ext": "agda",
"hexsha": "5a9aa70a42d618af4eb142a0249729f9fcff9733",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/numeral",
"max_forks_repo_path": "legacy/RandomAccessList/General/Redundant.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"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/numeral",
"max_issues_repo_path": "legacy/RandomAccessList/General/Redundant.agda",
"max_line_length": 50,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/numeral",
"max_stars_repo_path": "legacy/RandomAccessList/General/Redundant.agda",
"max_stars_repo_stars_event_max_datetime": "2015-04-23T15:58:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-23T15:58:28.000Z",
"num_tokens": 86,
"size": 260
} |
module RMonads.RMonadMorphs where
open import Library
open import Functors
open import Categories
open import RMonads
open Fun
open RMonad
record RMonadMorph {a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}{J : Fun C D}
(M M' : RMonad J) : Set (a ⊔ b ⊔ c ⊔ d) where
constructor rmonadmorph
open Cat D
field morph : ∀ {X} → Hom (T M X) (T M' X)
lawη : ∀ {X} → comp morph (η M {X}) ≅ η M' {X}
lawbind : ∀ {X Y}{k : Hom (OMap J X) (T M Y)} →
comp (morph {Y}) (bind M k)
≅
comp (bind M' (comp (morph {Y}) k)) (morph {X})
RMonadMorphEq : ∀{a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}{J : Fun C D}
{M M' : RMonad J}(α α' : RMonadMorph M M') ->
(λ {X} -> RMonadMorph.morph α {X}) ≅ (λ {X} -> RMonadMorph.morph α' {X}) →
α ≅ α'
RMonadMorphEq (rmonadmorph m lη lbind) (rmonadmorph .m lη' lbind') refl =
cong₂ (rmonadmorph m)
(iext λ _ → hir refl)
(iext λ _ → iext λ _ → iext λ _ → hir refl)
IdRMonadMorph : ∀{a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}{J : Fun C D}
(M : RMonad J) → RMonadMorph M M
IdRMonadMorph {D = D} M = rmonadmorph
iden
idl
(trans idl (trans (cong (bind M) (sym idl)) (sym idr)))
where open Cat D
CompRMonadMorph : ∀{a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}{J : Fun C D}
{M M' M'' : RMonad J} →
RMonadMorph M' M'' → RMonadMorph M M' → RMonadMorph M M''
CompRMonadMorph {D = D}{M'' = M''}
(rmonadmorph f lawηf lawbindf)
(rmonadmorph g lawηg lawbindg) =
rmonadmorph
(comp f g)
(trans ass (trans (cong (comp f) lawηg) lawηf))
\ {_ _ k} -> trans
ass
(trans (cong (comp f) lawbindg)
(trans (trans (sym ass)
(cong (λ f → comp f g)
(trans (lawbindf {k = comp g k})
(cong (λ g → comp (bind M'' g) f)
(sym ass)))))
ass))
where open Cat D
idr : ∀{a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}{J : Fun C D}{M M' : RMonad J}
(f : RMonadMorph M M') → CompRMonadMorph f (IdRMonadMorph _) ≅ f
idr {D = D} f = RMonadMorphEq _ _ (iext λ _ → Cat.idr D)
idl : ∀{a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}{J : Fun C D}{M M' : RMonad J}
(f : RMonadMorph M M') → CompRMonadMorph (IdRMonadMorph _) f ≅ f
idl {D = D} f = RMonadMorphEq _ _ (iext λ _ → Cat.idl D)
ass : ∀{a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}
{J : Fun C D}{M M' M'' M''' : RMonad J}
(f : RMonadMorph M'' M''')(g : RMonadMorph M' M'')(h : RMonadMorph M M') →
CompRMonadMorph (CompRMonadMorph f g) h
≅
CompRMonadMorph f (CompRMonadMorph g h)
ass {D = D} f g h = RMonadMorphEq _ _ (iext λ _ → Cat.ass D)
| {
"alphanum_fraction": 0.5112091143,
"avg_line_length": 35.8026315789,
"ext": "agda",
"hexsha": "e0a25a0d555a4ac27025270e905f8fb415eb27d6",
"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": "RMonads/RMonadMorphs.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": "RMonads/RMonadMorphs.agda",
"max_line_length": 78,
"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": "RMonads/RMonadMorphs.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": 1094,
"size": 2721
} |
---------------------------------------------------------------------------
-- The gcd is greatest that any common divisor
---------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
open import LTC-PCF.Base
open import LTC-PCF.Data.Nat.Divisibility.NotBy0
open import LTC-PCF.Data.Nat.Inequalities
open import LTC-PCF.Data.Nat.Type
module LTC-PCF.Program.GCD.Partial.GreatestAnyCommonDivisor
(x∣Sy→x≤Sy : ∀ {m n} → N m → N n → m ∣ (succ₁ n) → m ≤ succ₁ n)
(0∤x : ∀ {n} → ¬ (zero ∣ n))
where
open import LTC-PCF.Program.GCD.Partial.Definitions
---------------------------------------------------------------------------
-- Knowing that gcd is a common divisor of m and n and that any other
-- common divisor of m and n divides it, we can prove that gcd is the
-- largest common divisor.
-- It requires the totality of gcd, ie. N gcd.
gcdGACD : ∀ {m n gcd} → N gcd → CD m n gcd → Divisible m n gcd → GACD m n gcd
gcdGACD nzero (0∣m , _) = ⊥-elim (0∤x 0∣m)
gcdGACD (nsucc {gcd} Ngcd) _ =
λ Divisible-mnSgcd c Nc CDmnc → x∣Sy→x≤Sy Nc Ngcd
(Divisible-mnSgcd c Nc CDmnc)
| {
"alphanum_fraction": 0.5151975684,
"avg_line_length": 39.8787878788,
"ext": "agda",
"hexsha": "0e1f9dfb331e8140010a7fa11b30235421adef7b",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/LTC-PCF/Program/GCD/Partial/GreatestAnyCommonDivisor.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/LTC-PCF/Program/GCD/Partial/GreatestAnyCommonDivisor.agda",
"max_line_length": 77,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/LTC-PCF/Program/GCD/Partial/GreatestAnyCommonDivisor.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": 367,
"size": 1316
} |
{-# OPTIONS --without-K --safe #-}
module Algebra.Linear where
open import Algebra.Linear.Core public
open import Algebra.Linear.Construct public
open import Algebra.Linear.Morphism public
open import Algebra.Linear.Structures public
| {
"alphanum_fraction": 0.7755102041,
"avg_line_length": 27.2222222222,
"ext": "agda",
"hexsha": "18271ec96129fb954a4206fe709dd02717173474",
"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.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.agda",
"max_line_length": 44,
"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.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": 47,
"size": 245
} |
{-# OPTIONS --without-K #-}
module SymmetricMonoidalCategory where
open import Level
open import Categories.Category using (Category)
open import Categories.Monoidal using (Monoidal)
open import Categories.Monoidal.Braided using (Braided; module Braided)
open import Categories.NaturalIsomorphism using (module NaturalIsomorphism)
open import Categories.NaturalTransformation using (id; _∘₁_; _≡_)
------------------------------------------------------------------------------
-- Definition
record SymmetricMonoidalCategory {o ℓ e} {ℂ : Category o ℓ e} {Mℂ : Monoidal ℂ}
(BMℂ : Braided Mℂ) : Set (suc (o ⊔ ℓ ⊔ e)) where
open Braided BMℂ using (braid)
open NaturalIsomorphism braid using () renaming (F⇒G to x⊗y⇒y⊗x; F⇐G to y⊗x⇒x⊗y)
field
symmetry : y⊗x⇒x⊗y ∘₁ x⊗y⇒y⊗x ≡ id
------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.6013745704,
"avg_line_length": 36.375,
"ext": "agda",
"hexsha": "84fd0caf644e21a78550077ce889ffebe38bac64",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "Univalence/Obsolete/SymmetricMonoidalCategory.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "Univalence/Obsolete/SymmetricMonoidalCategory.agda",
"max_line_length": 82,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "Univalence/Obsolete/SymmetricMonoidalCategory.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 264,
"size": 873
} |
module Generic.Lib.Data.Sum where
open import Data.Sum hiding (swap) renaming (map to smap) hiding (map₁; map₂) public
| {
"alphanum_fraction": 0.7666666667,
"avg_line_length": 30,
"ext": "agda",
"hexsha": "82221be2f16df73bdcfda933d699418eb14cd105",
"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": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "turion/Generic",
"max_forks_repo_path": "src/Generic/Lib/Data/Sum.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"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": "turion/Generic",
"max_issues_repo_path": "src/Generic/Lib/Data/Sum.agda",
"max_line_length": 84,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "turion/Generic",
"max_stars_repo_path": "src/Generic/Lib/Data/Sum.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 32,
"size": 120
} |
-- Display whether or not the timeout was hit when using auto -l.
module Issue945 where
data ⊥ : Set where
¬_ : Set → Set
¬ A = A → ⊥
record ∃ {A : Set} (P : A → Set) : Set where
constructor _,_
field witness : A
proof : P witness
-- Exhaustive
lem₁ : ∀ {A : Set} (P : A → Set) (x : A) → (∀ x → ¬ P x) → (∀ x → P x) → ⊥
lem₁ A = {!-l -t 1!}
-- Timeout
lem₂ : ∀ {A} (P : A → Set) (x : A) → (∀ x → ¬ P x) → (∀ x → P x) → ∃ P → ⊥
lem₂ P a e = {!-l -t 1!}
| {
"alphanum_fraction": 0.4798301486,
"avg_line_length": 22.4285714286,
"ext": "agda",
"hexsha": "7c96f3531b2354ae6a5c8fcc914ae3a89f4d9cf2",
"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/Issue945.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/Issue945.agda",
"max_line_length": 74,
"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/Issue945.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": 199,
"size": 471
} |
open import Everything
module Test.Class where
record ℭlass
{ℓ}
{𝔢}
{CONSTRAINTS : Ø 𝔢}
(constraints : CONSTRAINTS)
: Ø ↑̂ ℓ
where
constructor ∁
field
type : Ø ℓ
private
record SET-CLASS
⦃ _ : Constraint constraints ⦄
: Ø ℓ
where
constructor ∁
field ⋆ : type
open SET-CLASS public
class : Ø _
class = SET-CLASS
method : ⦃ _ : class ⦄ → type
method ⦃ ⌶ ⦄ = SET-CLASS.⋆ ⌶
mkClass : ∀
{ℓ}
{𝔢}
{CONSTRAINTS : Ø 𝔢}
(constraints : CONSTRAINTS)
→ Ø ℓ
→ ℭlass constraints
mkClass constraints set-method = ∁ set-method
module Unit-Unit/Unit/Unit
{𝔬} (𝔒 : Ø 𝔬)
= ℭlass (mkClass 𝔒 𝔒)
module PropSingle-Unit/Unit/Unit
{𝔬} {𝔒 : Ø 𝔬}
{𝔭} (𝔓 : 𝔒 → Ø 𝔭)
(x : 𝔒)
= Unit-Unit/Unit/Unit (𝔓 x)
module Prop-Unit/Unit/Unit
{𝔬} {𝔒 : Ø 𝔬}
{𝔭} (𝔓 : 𝔒 → Ø 𝔭)
where
private module M = PropSingle-Unit/Unit/Unit 𝔓
class = ∀ {x} → M.class x
type = ∀ x → M.type x
method = λ ⦃ _ : class ⦄ x → M.method x
module RelSingle-Unit/Unit/Unit
{𝔬} {𝔒 : Ø 𝔬}
{𝔯} (ℜ : 𝔒 → 𝔒 → Ø 𝔯)
(x : 𝔒)
= Unit-Unit/Unit/Unit (ℜ x x)
module Rel-Unit/Unit/Unit
{𝔬} {𝔒 : Ø 𝔬}
{𝔯} (ℜ : 𝔒 → 𝔒 → Ø 𝔯)
where
private module M = RelSingle-Unit/Unit/Unit ℜ
class = ∀ {x} → M.class x
type = ∀ x → M.type x
method = λ ⦃ _ : class ⦄ x → M.method x
module Prop-Rel-Unit/Unit/Unit
{𝔬} {𝔒 : Ø 𝔬}
{𝔭} (𝔓 : 𝔒 → Ø 𝔭)
= Rel-Unit/Unit/Unit (Extension 𝔓)
module UnitLevel-Unit/Unit/Unit
{𝔬} (𝔒 : Ø 𝔬) (𝔯 : Ł)
where
private module M = Rel-Unit/Unit/Unit {𝔒 = 𝔒} {𝔯 = 𝔯}
class = ∀ {ℜ} → M.class ℜ
type = ∀ {ℜ} → M.type ℜ
method : ⦃ _ : class ⦄ → type
method ⦃ ⌶ ⦄ {ℜ = ℜ} = M.method ℜ ⦃ ⌶ {ℜ} ⦄ -- FIXME
module RelSingle-RelSingle/Rel/RelSingle
{𝔬} {𝔒 : Ø 𝔬}
{𝔯} (ℜ : 𝔒 → 𝔒 → Ø 𝔯)
(x : 𝔒)
= ℭlass (mkClass ℜ (ℜ x x))
module Rel-RelSingle/Rel/RelSingle
{𝔬} {𝔒 : Ø 𝔬}
{𝔯} (ℜ : 𝔒 → 𝔒 → Ø 𝔯)
where
private module M = RelSingle-RelSingle/Rel/RelSingle ℜ
class = ∀ {x} → M.class x
type = ∀ {x} → M.type x
method = λ ⦃ _ : class ⦄ {x} → M.method x
module Prop-Rel-RelSingle/Rel/RelSingle
{𝔬} {𝔒 : Ø 𝔬}
{𝔭} (𝔓 : 𝔒 → Ø 𝔭)
= Rel-RelSingle/Rel/RelSingle (Extension 𝔓)
module All-Prop-Rel-RelSingle/Rel/RelSingle (𝔬 𝔭 : Ł) where
private module M = Prop-Rel-RelSingle/Rel/RelSingle
class = ∀ {𝔒 : Ø 𝔬} {𝔓 : 𝔒 → Ø 𝔭} → M.class 𝔓
type = ∀ {𝔒 : Ø 𝔬} {𝔓 : 𝔒 → Ø 𝔭} → M.type 𝔓
method : ⦃ _ : class ⦄ → type
method {𝔓 = 𝔓} = M.method 𝔓
module UnitLevel-RelSingle/Rel/RelSingle
{𝔬} (𝔒 : Ø 𝔬) (𝔯 : Ł)
where
private module M = Rel-RelSingle/Rel/RelSingle {𝔒 = 𝔒} {𝔯 = 𝔯}
class = ∀ {ℜ} → M.class ℜ
type = ∀ {ℜ} → M.type ℜ
method : ⦃ _ : class ⦄ → type
method {ℜ = ℜ} = M.method ℜ
module PropSingle-PropSingle/Prop/PropSingle
{𝔬} {𝔒 : Ø 𝔬}
{𝔭} (𝔓 : 𝔒 → Ø 𝔭)
(x : 𝔒)
where
open ℭlass (mkClass 𝔓 (𝔓 x)) public
module Prop-PropSingle/Prop/PropSingle
{𝔬} {𝔒 : Ø 𝔬}
{𝔭} (𝔓 : 𝔒 → Ø 𝔭)
where
private module M = PropSingle-PropSingle/Prop/PropSingle 𝔓
class = ∀ {x} → M.class x
type = ∀ x → M.type x
method = λ ⦃ _ : class ⦄ x → M.method x
module Asymmetric
ℓ
(𝔓' : ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔭} (𝔓 : 𝔒 → Ø 𝔭) (x : 𝔒) → 𝔓 x → Ø ℓ)
where
module U = Unit-Unit/Unit/Unit
test-class' : ⦃ _ : ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔭} {𝔓 : 𝔒 → Ø 𝔭} {x : 𝔒} {y : 𝔓 x} → U.class (𝔓' 𝔓 x y) ⦄ → ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔭} {𝔓 : 𝔒 → Ø 𝔭} {x : 𝔒} {y : 𝔓 x} → U.class (𝔓' 𝔓 x y)
test-class' = !
module Symmetric
ℓ
(𝔓' : ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔭} (𝔓 : 𝔒 → Ø 𝔭) (x : 𝔒) → 𝔓 x → 𝔓 x → Ø ℓ)
where
module U = Unit-Unit/Unit/Unit
test-class' : ⦃ _ : ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔭} {𝔓 : 𝔒 → Ø 𝔭} {x : 𝔒} {y z : 𝔓 x} → U.class (𝔓' 𝔓 x y z → 𝔓' 𝔓 x y z) ⦄ → ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔭} {𝔓 : 𝔒 → Ø 𝔭} {x : 𝔒} {y z : 𝔓 x} → U.class (𝔓' 𝔓 x y z → 𝔓' 𝔓 x y z)
test-class' ⦃ ⌶ ⦄ = !
module V {𝔬} (𝔒 : Ø 𝔬) = ℭlass (mkClass 𝔒 (𝔒 → 𝔒))
test-classV : ⦃ _ : ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔭} {𝔓 : 𝔒 → Ø 𝔭} {x : 𝔒} {y z : 𝔓 x} → V.class (𝔓' 𝔓 x y z) ⦄ → ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔭} {𝔓 : 𝔒 → Ø 𝔭} {x : 𝔒} {y z : 𝔓 x} → V.class (𝔓' 𝔓 x y z)
test-classV ⦃ ⌶ ⦄ = !
test-methodV : ⦃ _ : ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔭} {𝔓 : 𝔒 → Ø 𝔭} {x : 𝔒} {y z : 𝔓 x} → V.class (𝔓' 𝔓 x y z) ⦄ → ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔭} {𝔓 : 𝔒 → Ø 𝔭} {x : 𝔒} {y z : 𝔓 x} → V.type (𝔓' 𝔓 x y z)
test-methodV ⦃ ⌶ ⦄ = V.method _
module W {𝔬} {𝔒 : Ø 𝔬} (p : 𝔒) = ℭlass (mkClass p 𝔒)
test-classW : ⦃ _ : ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔭} {𝔓 : 𝔒 → Ø 𝔭} {x : 𝔒} {y z : 𝔓 x} {p : 𝔓' 𝔓 x y z} → W.class p ⦄ → ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔭} {𝔓 : 𝔒 → Ø 𝔭} {x : 𝔒} {y z : 𝔓 x} {p : 𝔓' 𝔓 x y z} → W.class p
test-classW ⦃ ⌶ ⦄ = magic
test-methodW : ⦃ _ : ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔭} {𝔓 : 𝔒 → Ø 𝔭} {x : 𝔒} {y z : 𝔓 x} {p : 𝔓' 𝔓 x y z} → W.class p ⦄ → ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔭} {𝔓 : 𝔒 → Ø 𝔭} {x : 𝔒} {y z : 𝔓 x} {p : 𝔓' 𝔓 x y z} → W.type p
test-methodW {p = p} = W.method p
module Prop-
{𝔬} {𝔒 : Ø 𝔬}
{𝔭} (𝔓 : 𝔒 → Ø 𝔭)
where
module -Unit/Unit/Unit where
module V = Prop-Unit/Unit/Unit 𝔓
module H = Prop-Unit/Unit/Unit
module X = Unit-Unit/Unit/Unit
test-class' : ⦃ _ : {𝔓 : 𝔒 → Ø 𝔭} → H.class 𝔓 ⦄ → {𝔓 : 𝔒 → Ø 𝔭} → H.class 𝔓
test-class' ⦃ ⌶ ⦄ {𝔓 = 𝔓} = magic -- ⌶ {𝔓 = 𝔓} -- FIXME
test-class : ⦃ _ : V.class ⦄ → V.class
test-class = !
test-method-V : ⦃ _ : V.class ⦄ → V.type
test-method-V = V.method
test-method-H : ⦃ _ : V.class ⦄ → V.type
test-method-H = H.method _
test-method-X : ⦃ _ : V.class ⦄ → V.type
test-method-X _ = X.method _ -- FIXME
module -PropSingle/Prop/PropSingle where
module V = Prop-PropSingle/Prop/PropSingle 𝔓
module H = Prop-PropSingle/Prop/PropSingle
module X = PropSingle-PropSingle/Prop/PropSingle
test-class' : ⦃ _ : {𝔓 : 𝔒 → Ø 𝔭} → H.class 𝔓 ⦄ → {𝔓 : 𝔒 → Ø 𝔭} → H.class 𝔓
test-class' ⦃ ⌶ ⦄ = magic
test-class : ⦃ _ : V.class ⦄ → V.class
test-class = !
test-method-V : ⦃ _ : V.class ⦄ → V.type
test-method-V = V.method
test-method-H : ⦃ _ : V.class ⦄ → V.type
test-method-H = H.method _
test-method-X : ⦃ _ : V.class ⦄ → V.type
test-method-X _ = X.method _ _ -- FIXME
module Rel-
{𝔬} {𝔒 : Ø 𝔬}
{𝔯} (ℜ : 𝔒 → 𝔒 → Ø 𝔯)
where
module -Unit/Unit/Unit where
module V = Rel-Unit/Unit/Unit ℜ
module H = Rel-Unit/Unit/Unit
module X = Unit-Unit/Unit/Unit
test-class : ⦃ _ : V.class ⦄ → V.class
test-class = !
test-method-V : ⦃ _ : V.class ⦄ → V.type
test-method-V = V.method
test-method-H : ⦃ _ : V.class ⦄ → V.type
test-method-H = H.method ℜ -- FIXME
test-method-X : ⦃ _ : V.class ⦄ → V.type
test-method-X _ = X.method _ -- FIXME
module -RelSingle/Rel/RelSingle where
module V = Rel-RelSingle/Rel/RelSingle ℜ
module H = Rel-RelSingle/Rel/RelSingle
module X = RelSingle-RelSingle/Rel/RelSingle
test-class : ⦃ _ : V.class ⦄ → V.class
test-class = !
test-method-V : ⦃ _ : V.class ⦄ → V.type
test-method-V = V.method
test-method-H : ⦃ _ : V.class ⦄ → V.type
test-method-H = H.method _
test-method-X : ⦃ _ : V.class ⦄ → V.type
test-method-X = X.method _ _
module Prop-Rel-
{𝔬} {𝔒 : Ø 𝔬}
{𝔭} (𝔓 : 𝔒 → Ø 𝔭)
where
module -Unit/Unit/Unit where
module V = Prop-Rel-Unit/Unit/Unit 𝔓
module H = Prop-Rel-Unit/Unit/Unit
module X = RelSingle-Unit/Unit/Unit
test-class' : ⦃ _ : ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔭} {𝔓 : 𝔒 → Ø 𝔭} → H.class 𝔓 ⦄ → ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔭} {𝔓 : 𝔒 → Ø 𝔭} → H.class 𝔓
test-class' ⦃ ⌶ ⦄ {ℜ} = magic -- ! -- FIXME
test-class : ⦃ _ : V.class ⦄ → V.class
test-class = !
test-method-V : ⦃ _ : V.class ⦄ → V.type
test-method-V ⦃ ⌶ ⦄ = magic
test-method-H : ⦃ _ : V.class ⦄ → V.type
test-method-H ⦃ ⌶ ⦄ = magic -- H.method _
test-method-X : ⦃ _ : V.class ⦄ → V.type
test-method-X ⦃ ⌶ ⦄ = magic -- X.method _ _
module -RelSingle/Rel/RelSingle where
module V = Prop-Rel-RelSingle/Rel/RelSingle 𝔓
module H = Prop-Rel-RelSingle/Rel/RelSingle
module X = RelSingle-RelSingle/Rel/RelSingle
test-class' : ⦃ _ : ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔭} {𝔓 : 𝔒 → Ø 𝔭} → H.class 𝔓 ⦄ → ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔭} (𝔓 : 𝔒 → Ø 𝔭) → H.class 𝔓
test-class' ⦃ ⌶ ⦄ = !
test-class : ⦃ _ : V.class ⦄ → V.class
test-class = !
test-method-V : ⦃ _ : V.class ⦄ → V.type
test-method-V ⦃ ⌶ ⦄ = magic -- V.method
test-method-H : ⦃ _ : V.class ⦄ → V.type
test-method-H ⦃ ⌶ ⦄ = magic -- H.method _
test-method-X : ⦃ _ : V.class ⦄ → V.type
test-method-X ⦃ ⌶ ⦄ = magic -- FIXME
module UnitLevel-
{𝔬} (𝔒 : Ø 𝔬) ℓ
where
module -Unit/Unit/Unit where
module V = UnitLevel-Unit/Unit/Unit 𝔒 ℓ
module H = UnitLevel-Unit/Unit/Unit
module X = RelSingle-Unit/Unit/Unit
test-class : ⦃ _ : V.class ⦄ → V.class
test-class ⦃ ⌶ ⦄ {ℜ} = ⌶ {ℜ} -- FIXME
test-method-V : ⦃ _ : V.class ⦄ → V.type
test-method-V ⦃ ⌶ ⦄ {ℜ} = magic
test-method-H : ⦃ _ : V.class ⦄ → V.type
test-method-H ⦃ ⌶ ⦄ {ℜ} = magic -- H.method _
test-method-X : ⦃ _ : V.class ⦄ → V.type
test-method-X ⦃ ⌶ ⦄ {ℜ} x = magic -- X.method _ _
module -RelSingle/Rel/RelSingle where
module V = UnitLevel-RelSingle/Rel/RelSingle 𝔒 ℓ
module H = UnitLevel-RelSingle/Rel/RelSingle
module X = RelSingle-RelSingle/Rel/RelSingle
test-class : ⦃ _ : V.class ⦄ → V.class
test-class = !
test-method-V : ⦃ _ : V.class ⦄ → V.type
test-method-V ⦃ ⌶ ⦄ {ℜ} = magic -- V.method
test-method-H : ⦃ _ : V.class ⦄ → V.type
test-method-H ⦃ ⌶ ⦄ {ℜ} = magic -- H.method _
test-method-X : ⦃ _ : V.class ⦄ → V.type
test-method-X ⦃ ⌶ ⦄ {ℜ} = X.method ℜ _ -- FIXME
module Rel-Extension
{𝔬} {𝔒 : Ø 𝔬}
{𝔭} (𝔓 : 𝔒 → Ø 𝔭)
(let ℜ = Extension 𝔓)
where
module -Unit/Unit/Unit where
module V = Rel-Unit/Unit/Unit ℜ
module H = Rel-Unit/Unit/Unit
module X = Unit-Unit/Unit/Unit
test-class' : ⦃ _ : ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔭} {𝔓 : 𝔒 → Ø 𝔭} (let ℜ = Extension 𝔓) → H.class ℜ ⦄ → ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔭} {𝔓 : 𝔒 → Ø 𝔭} (let ℜ = Extension 𝔓) → H.class ℜ
test-class' ⦃ ⌶ ⦄ {𝔓 = 𝔓} = magic -- ⌶ {𝔓 = 𝔓} -- FIXME
test-class : ⦃ _ : V.class ⦄ → V.class
test-class = !
test-method-V : ⦃ _ : V.class ⦄ → V.type
test-method-V = V.method
test-method-H : ⦃ _ : V.class ⦄ → V.type
test-method-H = H.method ℜ -- FIXME
test-method-X : ⦃ _ : V.class ⦄ → V.type
test-method-X _ = X.method _ -- FIXME
module -RelSingle/Rel/RelSingle where
module V = Rel-RelSingle/Rel/RelSingle ℜ
module H = Rel-RelSingle/Rel/RelSingle
module X = RelSingle-RelSingle/Rel/RelSingle
test-class' : ⦃ _ : ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔭} {𝔓 : 𝔒 → Ø 𝔭} (let ℜ = Extension 𝔓) → H.class ℜ ⦄ → ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔭} {𝔓 : 𝔒 → Ø 𝔭} (let ℜ = Extension 𝔓) → H.class ℜ
test-class' ⦃ ⌶ ⦄ = ! -- !
test-class'' : ⦃ _ : ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔭} {𝔓 : 𝔒 → Ø 𝔭} (let ℜ = λ x _ → 𝔓 x) → H.class ℜ ⦄ → ∀ {𝔬} {𝔒 : Ø 𝔬} {𝔭} {𝔓 : 𝔒 → Ø 𝔭} (let ℜ = λ x _ → 𝔓 x) → H.class ℜ
test-class'' ⦃ ⌶ ⦄ = ! -- !
test-class : ⦃ _ : V.class ⦄ → V.class
test-class = !
test-method-V : ⦃ _ : V.class ⦄ → V.type
test-method-V = V.method
test-method-H : ⦃ _ : V.class ⦄ → V.type
test-method-H = H.method _
test-method-X : ⦃ _ : V.class ⦄ → V.type
test-method-X = X.method _ _
module AllUnitTest where
test : ⦃ I : ∀ {𝔬} {𝔒 : Ø 𝔬} → Unit-Unit/Unit/Unit.class 𝔒 ⦄ → ∀ {𝔬} {𝔒 : Ø 𝔬} → Unit-Unit/Unit/Unit.class 𝔒
test = !
module AllTest
{𝔬} {𝔒 : Ø 𝔬}
{𝔭}
where
testProp : ⦃ I : {𝔓 : 𝔒 → Ø 𝔭} → Prop-PropSingle/Prop/PropSingle.class 𝔓 ⦄ → {𝔓 : 𝔒 → Ø 𝔭} → Prop-PropSingle/Prop/PropSingle.class 𝔓
testProp = !
testUnitProp : ⦃ I : {𝔓 : 𝔒 → Ø 𝔭} → Prop-Unit/Unit/Unit.class 𝔓 ⦄ → {𝔓 : 𝔒 → Ø 𝔭} → Prop-Unit/Unit/Unit.class 𝔓
testUnitProp ⦃ I ⦄ {𝔓} = I {𝔓}
module SinglePropTest
{𝔬} {𝔒 : Ø 𝔬}
{𝔭} (𝔓 : 𝔒 → Ø 𝔭)
where
testProp : ⦃ _ : Prop-PropSingle/Prop/PropSingle.class 𝔓 ⦄ → Prop-PropSingle/Prop/PropSingle.class 𝔓
testProp = !
testUnitProp : ⦃ _ : Prop-Unit/Unit/Unit.class 𝔓 ⦄ → Prop-Unit/Unit/Unit.class 𝔓
testUnitProp = !
module SingleRelTest
{𝔬} {𝔒 : Ø 𝔬}
{𝔯} (ℜ : 𝔒 → 𝔒 → Ø 𝔯)
where
testProp : ⦃ _ : Rel-RelSingle/Rel/RelSingle.class ℜ ⦄ → Rel-RelSingle/Rel/RelSingle.class ℜ
testProp = !
testUnit : ⦃ _ : Rel-Unit/Unit/Unit.class ℜ ⦄ → Rel-Unit/Unit/Unit.class ℜ
testUnit = !
| {
"alphanum_fraction": 0.53565808,
"avg_line_length": 33.4432132964,
"ext": "agda",
"hexsha": "a591b331f8d91d0293147db1df4af12d6295471d",
"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/Test/Class.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/Test/Class.agda",
"max_line_length": 205,
"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/Test/Class.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6154,
"size": 12073
} |
{-# OPTIONS --without-K --safe #-}
-- The category of Sets is Monoidal
module Categories.Category.Monoidal.Instance.Sets where
open import Level
open import Data.Product using (Σ; _×_; _,_; proj₁; proj₂; uncurry; map; <_,_>)
open import Data.Sum using (_⊎_; inj₁; inj₂; [_,_]′)
open import Data.Unit using (⊤)
open import Relation.Binary.PropositionalEquality
open import Function.Inverse using (module Inverse; _↔_)
open import Function.Related.TypeIsomorphisms
open import Function.Equality using () renaming (_⟨$⟩_ to fun)
open import Function using (_$_)
open import Categories.Category.Instance.Sets
open import Categories.Category.Monoidal
open import Categories.Functor.Bifunctor
open import Categories.Category.Instance.SingletonSet
open import Categories.Category.Instance.EmptySet
import Categories.Morphism as Morphism
import Categories.Category.Cartesian as Cartesian
import Categories.Category.Cocartesian as Cocartesian
open import Data.Sum.Properties
-- Sets is a Monoidal Category with × as Bifunctor
module Product {o : Level} where
private
S = Sets o
open Cartesian S
Sets-has-all : BinaryProducts
Sets-has-all = record { product = λ {A} {B} → record
{ A×B = A × B
; π₁ = proj₁
; π₂ = proj₂
; ⟨_,_⟩ = <_,_>
; project₁ = refl
; project₂ = refl
; unique = λ p₁ p₂ {x} → sym (cong₂ _,_ (p₁ {x}) (p₂ {x}))
} }
Sets-is : Cartesian
Sets-is = record { terminal = SingletonSet-⊤ ; products = Sets-has-all }
private
module Cart = Cartesian.Cartesian Sets-is
Sets-Monoidal : Monoidal S
Sets-Monoidal = Cart.monoidal
module Coproduct {o : Level} where
private
S = Sets o
open Cocartesian S
Sets-has-all : BinaryCoproducts
Sets-has-all = record { coproduct = λ {A} {B} → record
{ A+B = A ⊎ B
; i₁ = inj₁
; i₂ = inj₂
; [_,_] = [_,_]′
; inject₁ = refl
; inject₂ = refl
; unique = λ { i₁ i₂ {inj₁ x} → sym (i₁ {x}) ; i₁ i₂ {inj₂ y} → sym (i₂ {y})} -- stdlib?
} }
Sets-is : Cocartesian
Sets-is = record { initial = EmptySet-⊥ ; coproducts = Sets-has-all }
private
module Cocart = Cocartesian.Cocartesian Sets-is
Sets-Monoidal : Monoidal S
Sets-Monoidal = Cocart.+-monoidal
| {
"alphanum_fraction": 0.6815920398,
"avg_line_length": 28.3461538462,
"ext": "agda",
"hexsha": "0dcc7d05a46eccb4d28928a509b02248bfa9ebc3",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bblfish/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Monoidal/Instance/Sets.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bblfish/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Monoidal/Instance/Sets.agda",
"max_line_length": 92,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bblfish/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Monoidal/Instance/Sets.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 673,
"size": 2211
} |
-- Andreas, 2016-12-15, issue #2341
-- `with` needs to abstract also in sort of target type.
-- {-# OPTIONS -v tc.with:100 #-}
open import Agda.Primitive
test : ∀ a → Set (lsuc a)
test a with a
... | w = Set w
| {
"alphanum_fraction": 0.6244131455,
"avg_line_length": 19.3636363636,
"ext": "agda",
"hexsha": "c989c0535aee9a84dc825eaba17f677301f2129b",
"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/Issue2341with.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/Issue2341with.agda",
"max_line_length": 56,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue2341with.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": 71,
"size": 213
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Propositional equality
------------------------------------------------------------------------
-- This file contains some core definitions which are reexported by
-- Relation.Binary.PropositionalEquality.
module Relation.Binary.PropositionalEquality.Core where
open import Level
open import Relation.Binary.Core
open import Relation.Binary.Consequences.Core
------------------------------------------------------------------------
-- Some properties
sym : ∀ {a} {A : Set a} → Symmetric (_≡_ {A = A})
sym refl = refl
trans : ∀ {a} {A : Set a} → Transitive (_≡_ {A = A})
trans refl eq = eq
subst : ∀ {a p} {A : Set a} → Substitutive (_≡_ {A = A}) p
subst P refl p = p
resp₂ : ∀ {a ℓ} {A : Set a} (∼ : Rel A ℓ) → ∼ Respects₂ _≡_
resp₂ _∼_ = subst⟶resp₂ _∼_ subst
isEquivalence : ∀ {a} {A : Set a} → IsEquivalence (_≡_ {A = A})
isEquivalence = record
{ refl = refl
; sym = sym
; trans = trans
}
| {
"alphanum_fraction": 0.512745098,
"avg_line_length": 27.5675675676,
"ext": "agda",
"hexsha": "cd2e308f4372b0d5147ab32f2b4ee57a740cc502",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Relation/Binary/PropositionalEquality/Core.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Relation/Binary/PropositionalEquality/Core.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Relation/Binary/PropositionalEquality/Core.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": 273,
"size": 1020
} |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Bool
open import lib.types.Lift
open import lib.types.Paths
open import lib.types.Pointed
open import lib.types.Wedge
open import lib.cubical.Square
module lib.types.BigWedge where
module _ {i j} {A : Type i} where
private
data #BigWedge-aux (X : A → Ptd j) : Type (lmax i j) where
#bwbase : #BigWedge-aux X
#bwin : (a : A) → fst (X a) → #BigWedge-aux X
data #BigWedge (X : A → Ptd j) : Type (lmax i j) where
#bigwedge : #BigWedge-aux X → (Unit → Unit) → #BigWedge X
BigWedge : (A → Ptd j) → Type (lmax i j)
BigWedge X = #BigWedge X
bwbase : {X : A → Ptd j} → BigWedge X
bwbase = #bigwedge #bwbase _
bwin : {X : A → Ptd j} → (a : A) → fst (X a) → BigWedge X
bwin a x = #bigwedge (#bwin a x) _
⊙BigWedge : (A → Ptd j) → Ptd (lmax i j)
⊙BigWedge X = ⊙[ BigWedge X , bwbase ]
postulate -- HIT
bwglue : {X : A → Ptd j} → (a : A) → bwbase {X} == bwin a (snd (X a))
⊙bwin : {X : A → Ptd j} → (a : A) → fst (X a ⊙→ ⊙BigWedge X)
⊙bwin a = (bwin a , ! (bwglue a))
module BigWedgeElim {X : A → Ptd j} {k} {P : BigWedge X → Type k}
(base* : P bwbase)
(in* : (a : A) (x : fst (X a)) → P (bwin a x))
(glue* : (a : A) → base* == in* a (snd (X a)) [ P ↓ bwglue a ]) where
f : Π (BigWedge X) P
f = f-aux phantom where
f-aux : Phantom glue* → Π (BigWedge X) P
f-aux phantom (#bigwedge #bwbase _) = base*
f-aux phantom (#bigwedge (#bwin a x) _) = in* a x
postulate -- HIT
glue-β : (a : A) → apd f (bwglue a) == glue* a
open BigWedgeElim public using () renaming (f to BigWedge-elim)
module BigWedgeRec {X : A → Ptd j} {k} {C : Type k}
(base* : C)
(in* : (a : A) → fst (X a) → C)
(glue* : (a : A) → base* == in* a (snd (X a))) where
private
module M = BigWedgeElim base* in* (λ c → ↓-cst-in (glue* c))
f : BigWedge X → C
f = M.f
glue-β : (a : A) → ap f (bwglue a) == glue* a
glue-β a = apd=cst-in {f = f} (M.glue-β a)
{- A BigWedge indexed by Bool is just a binary Wedge -}
module _ {i} (Pick : Lift {j = i} Bool → Ptd i) where
BigWedge-Bool-equiv :
BigWedge Pick ≃ Wedge (Pick (lift true)) (Pick (lift false))
BigWedge-Bool-equiv = equiv f g f-g g-f
where
module F = BigWedgeRec {X = Pick}
{C = Wedge (Pick (lift true)) (Pick (lift false))}
(winl (snd (Pick (lift true))))
(λ {(lift true) → winl; (lift false) → winr})
(λ {(lift true) → idp; (lift false) → wglue})
module G = WedgeRec {X = Pick (lift true)} {Y = Pick (lift false)}
{C = BigWedge Pick}
(bwin (lift true))
(bwin (lift false))
(! (bwglue (lift true)) ∙ bwglue (lift false))
f = F.f
g = G.f
f-g : ∀ w → f (g w) == w
f-g = Wedge-elim
(λ _ → idp)
(λ _ → idp)
(↓-∘=idf-in f g $
ap f (ap g wglue)
=⟨ ap (ap f) G.glue-β ⟩
ap f (! (bwglue (lift true)) ∙ bwglue (lift false))
=⟨ ap-∙ f (! (bwglue (lift true))) (bwglue (lift false)) ⟩
ap f (! (bwglue (lift true))) ∙ ap f (bwglue (lift false))
=⟨ ap-! f (bwglue (lift true))
|in-ctx (λ w → w ∙ ap f (bwglue (lift false))) ⟩
! (ap f (bwglue (lift true))) ∙ ap f (bwglue (lift false))
=⟨ F.glue-β (lift true)
|in-ctx (λ w → ! w ∙ ap f (bwglue (lift false))) ⟩
ap f (bwglue (lift false))
=⟨ F.glue-β (lift false) ⟩
wglue ∎)
g-f : ∀ bw → g (f bw) == bw
g-f = BigWedge-elim
(! (bwglue (lift true)))
(λ {(lift true) → λ _ → idp; (lift false) → λ _ → idp})
(λ {(lift true) → ↓-∘=idf-from-square g f $
ap (ap g) (F.glue-β (lift true)) ∙v⊡
bl-square (bwglue (lift true));
(lift false) → ↓-∘=idf-from-square g f $
(ap (ap g) (F.glue-β (lift false)) ∙ G.glue-β) ∙v⊡
lt-square (! (bwglue (lift true))) ⊡h vid-square})
BigWedge-Bool-⊙path :
⊙BigWedge Pick == ⊙Wedge (Pick (lift true)) (Pick (lift false))
BigWedge-Bool-⊙path = ⊙ua (⊙≃-in BigWedge-Bool-equiv idp)
| {
"alphanum_fraction": 0.5204678363,
"avg_line_length": 32.3149606299,
"ext": "agda",
"hexsha": "6b900d0a9e5f6b69f53d14e5d1ea21f3689546be",
"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": "core/lib/types/BigWedge.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": "core/lib/types/BigWedge.agda",
"max_line_length": 73,
"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": "core/lib/types/BigWedge.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1631,
"size": 4104
} |
{-# OPTIONS --allow-incomplete-matches #-}
module Issue3295.Incomplete where
open import Agda.Builtin.Nat
f : Nat → Nat
f zero = zero
| {
"alphanum_fraction": 0.7226277372,
"avg_line_length": 15.2222222222,
"ext": "agda",
"hexsha": "8c47f022513259b5622cfb5b9ddbd9d95ddb8328",
"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/Issue3295/Incomplete.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/Issue3295/Incomplete.agda",
"max_line_length": 42,
"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/Issue3295/Incomplete.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": 37,
"size": 137
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.RingSolver.EvaluationHomomorphism where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat using (ℕ)
open import Cubical.Data.FinData
open import Cubical.Data.Vec
open import Cubical.Algebra.RingSolver.RawRing
open import Cubical.Algebra.RingSolver.AlmostRing renaming (⟨_⟩ to ⟨_⟩ᵣ)
open import Cubical.Algebra.RingSolver.HornerForms
private
variable
ℓ : Level
module HomomorphismProperties (R : AlmostRing {ℓ}) where
private
νR = AlmostRing→RawRing R
open AlmostRing R
open Theory R
open IteratedHornerOperations νR
evalHom+0 : (n : ℕ) (P : IteratedHornerForms νR n) (xs : Vec ⟨ νR ⟩ n)
→ eval n (0ₕ +ₕ P) xs ≡ eval n P xs
evalHom+0 ℕ.zero (const x) [] = +Lid _
evalHom+0 (ℕ.suc n) P xs = refl
eval0H : (n : ℕ) (xs : Vec ⟨ νR ⟩ n)
→ eval {R = νR} n 0ₕ xs ≡ 0r
eval0H .ℕ.zero [] = refl
eval0H .(ℕ.suc _) (x ∷ xs) = refl
eval1ₕ : (n : ℕ) (xs : Vec ⟨ νR ⟩ n)
→ eval {R = νR} n 1ₕ xs ≡ 1r
eval1ₕ .ℕ.zero [] = refl
eval1ₕ (ℕ.suc n) (x ∷ xs) =
eval (ℕ.suc n) 1ₕ (x ∷ xs) ≡⟨ refl ⟩
eval (ℕ.suc n) (0H ·X+ 1ₕ) (x ∷ xs) ≡⟨ refl ⟩
eval {R = νR} (ℕ.suc n) 0H (x ∷ xs) · x + eval n 1ₕ xs ≡⟨ cong (λ u → u · x + eval n 1ₕ xs)
(eval0H _ (x ∷ xs)) ⟩
0r · x + eval n 1ₕ xs ≡⟨ cong (λ u → 0r · x + u)
(eval1ₕ _ xs) ⟩
0r · x + 1r ≡⟨ cong (λ u → u + 1r)
(0LeftAnnihilates _) ⟩
0r + 1r ≡⟨ +Lid _ ⟩
1r ∎
-evalDist :
(n : ℕ) (P : IteratedHornerForms νR n) (xs : Vec ⟨ νR ⟩ n)
→ eval n (-ₕ P) xs ≡ - eval n P xs
-evalDist .ℕ.zero (const x) [] = refl
-evalDist n 0H xs =
eval n (-ₕ 0H) xs ≡⟨ eval0H n xs ⟩
0r ≡⟨ sym 0IsSelfinverse ⟩
- 0r ≡⟨ cong -_ (sym (eval0H n xs)) ⟩
- eval n 0H xs ∎
-evalDist .(ℕ.suc _) (P ·X+ Q) (x ∷ xs) =
eval (ℕ.suc _) (-ₕ (P ·X+ Q)) (x ∷ xs)
≡⟨ refl ⟩
eval (ℕ.suc _) ((-ₕ P) ·X+ (-ₕ Q)) (x ∷ xs)
≡⟨ refl ⟩
(eval (ℕ.suc _) (-ₕ P) (x ∷ xs)) · x + eval _ (-ₕ Q) xs
≡⟨ cong (λ u → u · x + eval _ (-ₕ Q) xs) (-evalDist _ P _) ⟩
(- eval (ℕ.suc _) P (x ∷ xs)) · x + eval _ (-ₕ Q) xs
≡⟨ cong (λ u → (- eval (ℕ.suc _) P (x ∷ xs)) · x + u) (-evalDist _ Q _) ⟩
(- eval (ℕ.suc _) P (x ∷ xs)) · x + - eval _ Q xs
≡⟨ cong (λ u → u + - eval _ Q xs) (sym (-Comm· _ _)) ⟩
- (eval (ℕ.suc _) P (x ∷ xs)) · x + - eval _ Q xs
≡⟨ sym (-Dist+ _ _) ⟩
- ((eval (ℕ.suc _) P (x ∷ xs)) · x + eval _ Q xs)
≡⟨ refl ⟩
- eval (ℕ.suc _) (P ·X+ Q) (x ∷ xs) ∎
+Homeval :
(n : ℕ) (P Q : IteratedHornerForms νR n) (xs : Vec ⟨ νR ⟩ n)
→ eval n (P +ₕ Q) xs ≡ (eval n P xs) + (eval n Q xs)
+Homeval .ℕ.zero (const x) (const y) [] = refl
+Homeval n 0H Q xs =
eval n (0H +ₕ Q) xs ≡⟨ refl ⟩
eval n Q xs ≡⟨ sym (+Lid _) ⟩
0r + eval n Q xs ≡⟨ cong (λ u → u + eval n Q xs) (sym (eval0H n xs)) ⟩
eval n 0H xs + eval n Q xs ∎
+Homeval .(ℕ.suc _) (P ·X+ Q) 0H xs =
eval (ℕ.suc _) ((P ·X+ Q) +ₕ 0H) xs ≡⟨ refl ⟩
eval (ℕ.suc _) (P ·X+ Q) xs ≡⟨ sym (+Rid _) ⟩
eval (ℕ.suc _) (P ·X+ Q) xs + 0r
≡⟨ cong (λ u → eval (ℕ.suc _) (P ·X+ Q) xs + u) (sym (eval0H _ xs)) ⟩
eval (ℕ.suc _) (P ·X+ Q) xs + eval (ℕ.suc _) 0H xs ∎
+Homeval .(ℕ.suc _) (P ·X+ Q) (S ·X+ T) (x ∷ xs) =
eval (ℕ.suc _) ((P ·X+ Q) +ₕ (S ·X+ T)) (x ∷ xs)
≡⟨ refl ⟩
eval (ℕ.suc _) ((P +ₕ S) ·X+ (Q +ₕ T)) (x ∷ xs)
≡⟨ refl ⟩
(eval (ℕ.suc _) (P +ₕ S) (x ∷ xs)) · x + eval _ (Q +ₕ T) xs
≡⟨ cong (λ u → (eval (ℕ.suc _) (P +ₕ S) (x ∷ xs)) · x + u) (+Homeval _ Q T xs) ⟩
(eval (ℕ.suc _) (P +ₕ S) (x ∷ xs)) · x + (eval _ Q xs + eval _ T xs)
≡⟨ cong (λ u → u · x + (eval _ Q xs + eval _ T xs)) (+Homeval (ℕ.suc _) P S (x ∷ xs)) ⟩
(eval (ℕ.suc _) P (x ∷ xs) + eval (ℕ.suc _) S (x ∷ xs)) · x
+ (eval _ Q xs + eval _ T xs)
≡⟨ cong (λ u → u + (eval _ Q xs + eval _ T xs)) (·DistL+ _ _ _) ⟩
(eval (ℕ.suc _) P (x ∷ xs)) · x + (eval (ℕ.suc _) S (x ∷ xs)) · x
+ (eval _ Q xs + eval _ T xs)
≡⟨ +ShufflePairs _ _ _ _ ⟩
((eval (ℕ.suc _) P (x ∷ xs)) · x + eval _ Q xs)
+ ((eval (ℕ.suc _) S (x ∷ xs)) · x + eval _ T xs)
≡⟨ refl ⟩
eval (ℕ.suc _) (P ·X+ Q) (x ∷ xs)
+ eval (ℕ.suc _) (S ·X+ T) (x ∷ xs) ∎
⋆Homeval : (n : ℕ)
(r : IteratedHornerForms νR n)
(P : IteratedHornerForms νR (ℕ.suc n)) (x : ⟨ νR ⟩) (xs : Vec ⟨ νR ⟩ n)
→ eval (ℕ.suc n) (r ⋆ P) (x ∷ xs) ≡ eval n r xs · eval (ℕ.suc n) P (x ∷ xs)
⋆0LeftAnnihilates :
(n : ℕ) (P : IteratedHornerForms νR (ℕ.suc n)) (xs : Vec ⟨ νR ⟩ (ℕ.suc n))
→ eval (ℕ.suc n) (0ₕ ⋆ P) xs ≡ 0r
·Homeval : (n : ℕ) (P Q : IteratedHornerForms νR n) (xs : Vec ⟨ νR ⟩ n)
→ eval n (P ·ₕ Q) xs ≡ (eval n P xs) · (eval n Q xs)
⋆0LeftAnnihilates n 0H xs = eval0H (ℕ.suc n) xs
⋆0LeftAnnihilates n (P ·X+ Q) (x ∷ xs) =
eval (ℕ.suc n) (0ₕ ⋆ (P ·X+ Q)) (x ∷ xs) ≡⟨ refl ⟩
eval (ℕ.suc n) ((0ₕ ⋆ P) ·X+ (0ₕ ·ₕ Q)) (x ∷ xs) ≡⟨ refl ⟩
(eval (ℕ.suc n) (0ₕ ⋆ P) (x ∷ xs)) · x + eval n (0ₕ ·ₕ Q) xs
≡⟨ cong (λ u → (u · x) + eval _ (0ₕ ·ₕ Q) _) (⋆0LeftAnnihilates n P (x ∷ xs)) ⟩
0r · x + eval n (0ₕ ·ₕ Q) xs
≡⟨ cong (λ u → u + eval _ (0ₕ ·ₕ Q) _) (0LeftAnnihilates _) ⟩
0r + eval n (0ₕ ·ₕ Q) xs
≡⟨ +Lid _ ⟩
eval n (0ₕ ·ₕ Q) xs
≡⟨ ·Homeval n 0ₕ Q _ ⟩
eval n 0ₕ xs · eval n Q xs
≡⟨ cong (λ u → u · eval n Q xs) (eval0H _ xs) ⟩
0r · eval n Q xs
≡⟨ 0LeftAnnihilates _ ⟩
0r ∎
⋆Homeval n r 0H x xs =
eval (ℕ.suc n) (r ⋆ 0H) (x ∷ xs) ≡⟨ refl ⟩
0r ≡⟨ sym (0RightAnnihilates _) ⟩
eval n r xs · 0r ≡⟨ refl ⟩
eval n r xs · eval {R = νR} (ℕ.suc n) 0H (x ∷ xs) ∎
⋆Homeval n r (P ·X+ Q) x xs =
eval (ℕ.suc n) (r ⋆ (P ·X+ Q)) (x ∷ xs) ≡⟨ refl ⟩
eval (ℕ.suc n) ((r ⋆ P) ·X+ (r ·ₕ Q)) (x ∷ xs) ≡⟨ refl ⟩
(eval (ℕ.suc n) (r ⋆ P) (x ∷ xs)) · x + eval n (r ·ₕ Q) xs
≡⟨ cong (λ u → u · x + eval n (r ·ₕ Q) xs) (⋆Homeval n r P x xs) ⟩
(eval n r xs · eval (ℕ.suc n) P (x ∷ xs)) · x + eval n (r ·ₕ Q) xs
≡⟨ cong (λ u → (eval n r xs · eval (ℕ.suc n) P (x ∷ xs)) · x + u) (·Homeval n r Q xs) ⟩
(eval n r xs · eval (ℕ.suc n) P (x ∷ xs)) · x + eval n r xs · eval n Q xs
≡⟨ cong (λ u → u + eval n r xs · eval n Q xs) (sym (·Assoc _ _ _)) ⟩
eval n r xs · (eval (ℕ.suc n) P (x ∷ xs) · x) + eval n r xs · eval n Q xs
≡⟨ sym (·DistR+ _ _ _) ⟩
eval n r xs · ((eval (ℕ.suc n) P (x ∷ xs) · x) + eval n Q xs)
≡⟨ refl ⟩
eval n r xs · eval (ℕ.suc n) (P ·X+ Q) (x ∷ xs) ∎
combineCases :
(n : ℕ) (Q : IteratedHornerForms νR n) (P S : IteratedHornerForms νR (ℕ.suc n))
(xs : Vec ⟨ νR ⟩ (ℕ.suc n))
→ eval (ℕ.suc n) ((P ·X+ Q) ·ₕ S) xs ≡ eval (ℕ.suc n) (((P ·ₕ S) ·X+ 0ₕ) +ₕ (Q ⋆ S)) xs
combineCases n Q P S (x ∷ xs) with (P ·ₕ S)
... | 0H =
eval (ℕ.suc n) (Q ⋆ S) (x ∷ xs) ≡⟨ sym (+Lid _) ⟩
0r + eval (ℕ.suc n) (Q ⋆ S) (x ∷ xs) ≡⟨ cong (λ u → u + eval _ (Q ⋆ S) (x ∷ xs)) lemma ⟩
eval (ℕ.suc n) (0H ·X+ 0ₕ) (x ∷ xs)
+ eval (ℕ.suc n) (Q ⋆ S) (x ∷ xs) ≡⟨ sym (+Homeval (ℕ.suc n)
(0H ·X+ 0ₕ) (Q ⋆ S) (x ∷ xs)) ⟩
eval (ℕ.suc n) ((0H ·X+ 0ₕ) +ₕ (Q ⋆ S)) (x ∷ xs) ∎
where lemma : 0r ≡ eval (ℕ.suc n) (0H ·X+ 0ₕ) (x ∷ xs)
lemma = 0r
≡⟨ sym (+Rid _) ⟩
0r + 0r
≡⟨ cong (λ u → u + 0r) (sym (0LeftAnnihilates _)) ⟩
0r · x + 0r
≡⟨ cong (λ u → 0r · x + u) (sym (eval0H _ xs)) ⟩
0r · x + eval n 0ₕ xs
≡⟨ cong (λ u → u · x + eval n 0ₕ xs) (sym (eval0H _ (x ∷ xs))) ⟩
eval {R = νR} (ℕ.suc n) 0H (x ∷ xs) · x + eval n 0ₕ xs
≡⟨ refl ⟩
eval (ℕ.suc n) (0H ·X+ 0ₕ) (x ∷ xs) ∎
... | (_ ·X+ _) = refl
·Homeval .ℕ.zero (const x) (const y) [] = refl
·Homeval (ℕ.suc n) 0H Q xs =
eval (ℕ.suc n) (0H ·ₕ Q) xs ≡⟨ eval0H _ xs ⟩
0r ≡⟨ sym (0LeftAnnihilates _) ⟩
0r · eval (ℕ.suc n) Q xs ≡⟨ cong (λ u → u · eval _ Q xs) (sym (eval0H _ xs)) ⟩
eval (ℕ.suc n) 0H xs · eval (ℕ.suc n) Q xs ∎
·Homeval (ℕ.suc n) (P ·X+ Q) S (x ∷ xs) =
eval (ℕ.suc n) ((P ·X+ Q) ·ₕ S) (x ∷ xs)
≡⟨ combineCases n Q P S (x ∷ xs) ⟩
eval (ℕ.suc n) (((P ·ₕ S) ·X+ 0ₕ) +ₕ (Q ⋆ S)) (x ∷ xs)
≡⟨ +Homeval (ℕ.suc n) ((P ·ₕ S) ·X+ 0ₕ) (Q ⋆ S) (x ∷ xs) ⟩
eval (ℕ.suc n) ((P ·ₕ S) ·X+ 0ₕ) (x ∷ xs) + eval (ℕ.suc n) (Q ⋆ S) (x ∷ xs)
≡⟨ refl ⟩
(eval (ℕ.suc n) (P ·ₕ S) (x ∷ xs) · x + eval n 0ₕ xs)
+ eval (ℕ.suc n) (Q ⋆ S) (x ∷ xs)
≡⟨ cong (λ u → u + eval (ℕ.suc n) (Q ⋆ S) (x ∷ xs))
((eval (ℕ.suc n) (P ·ₕ S) (x ∷ xs) · x + eval n 0ₕ xs)
≡⟨ cong (λ u → eval (ℕ.suc n) (P ·ₕ S) (x ∷ xs) · x + u) (eval0H _ xs) ⟩
(eval (ℕ.suc n) (P ·ₕ S) (x ∷ xs) · x + 0r)
≡⟨ +Rid _ ⟩
(eval (ℕ.suc n) (P ·ₕ S) (x ∷ xs) · x)
≡⟨ cong (λ u → u · x) (·Homeval (ℕ.suc n) P S (x ∷ xs)) ⟩
((eval (ℕ.suc n) P (x ∷ xs) · eval (ℕ.suc n) S (x ∷ xs)) · x)
≡⟨ sym (·Assoc _ _ _) ⟩
(eval (ℕ.suc n) P (x ∷ xs) · (eval (ℕ.suc n) S (x ∷ xs) · x))
≡⟨ cong (λ u → eval (ℕ.suc n) P (x ∷ xs) · u) (·Comm _ _) ⟩
(eval (ℕ.suc n) P (x ∷ xs) · (x · eval (ℕ.suc n) S (x ∷ xs)))
≡⟨ ·Assoc _ _ _ ⟩
(eval (ℕ.suc n) P (x ∷ xs) · x) · eval (ℕ.suc n) S (x ∷ xs)
∎) ⟩
(eval (ℕ.suc n) P (x ∷ xs) · x) · eval (ℕ.suc n) S (x ∷ xs)
+ eval (ℕ.suc n) (Q ⋆ S) (x ∷ xs)
≡⟨ cong (λ u → (eval (ℕ.suc n) P (x ∷ xs) · x) · eval (ℕ.suc n) S (x ∷ xs) + u)
(⋆Homeval n Q S x xs) ⟩
(eval (ℕ.suc n) P (x ∷ xs) · x) · eval (ℕ.suc n) S (x ∷ xs)
+ eval n Q xs · eval (ℕ.suc n) S (x ∷ xs)
≡⟨ sym (·DistL+ _ _ _) ⟩
((eval (ℕ.suc n) P (x ∷ xs) · x) + eval n Q xs) · eval (ℕ.suc n) S (x ∷ xs)
≡⟨ refl ⟩
eval (ℕ.suc n) (P ·X+ Q) (x ∷ xs) · eval (ℕ.suc n) S (x ∷ xs) ∎
| {
"alphanum_fraction": 0.4155148096,
"avg_line_length": 46.4410480349,
"ext": "agda",
"hexsha": "2ea1a5f038cc03043aae2d312093de28a5fd66b7",
"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/Algebra/RingSolver/EvaluationHomomorphism.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"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": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/Algebra/RingSolver/EvaluationHomomorphism.agda",
"max_line_length": 102,
"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/Algebra/RingSolver/EvaluationHomomorphism.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5109,
"size": 10635
} |
module z where
-- http://www.cse.chalmers.se/~ulfn/papers/afp08/tutorial.pdf
{-
Dependently Typed Programming in Agda
Ulf Norell1 : Chalmers University, Gothenburg : [email protected]
James Chapman : Institute of Cybernetics, Tallinn : [email protected]
------------------------------------------------------------------------------
1 Introduction
In Hindley-Milner languages (Haskell, ML) : separation between types and values.
Dependently typed : types can contain (depend on) arbitrary values and
appear as arguments and results of ordinary functions
Dependent types enables types to talk about values,
so can encode properties of values as types
whose elements are proofs that the property is true.
So dependently typed programming language can be used as a logic.
To be consistent programs must be total.
------------------------------------------------------------------------------
2 BASICS
based on intuitionistic type theory[4]
--------------------------------------------------
2.1 DATATYPES AND PATTERN MATCHING
-}
data Bool : Set where
true : Bool
false : Bool
{-
type of Bool is
- Set, the type of small types
- There is hierarchy of increasingly large types
- type of Set is Set1, whose type is Set2, ...
-}
not : Bool → Bool
not true = false
not false = true
data Nat : Set where
zero : Nat
suc : Nat → Nat
{-# BUILTIN NATURAL Nat #-}
_+_ : Nat → Nat → Nat
zero + m = m
suc n + m = suc (n + m)
infixl 40 _+_
_*_ : Nat → Nat → Nat
zero * m = zero
suc n * m = m + n * m
infixl 60 _*_
{-
functions must not crash and must terminate
recursive calls have to be made on structurally smaller arguments
mixfix via _ : args where the underscores are
-}
_or_ : Bool → Bool → Bool
false or x = x
true or _ = true -- uses wildcard pattern on "don't care" args
infixr 20 _or_
-- polymorphic function over type A
if_then_else_ : {A : Set} → Bool → A → A → A
if true then x else y = x
if false then x else y = y
infix 5 if_then_else_
-- types parameterize by other types
data List (A : Set) : Set where
[] : List A
_::_ : A → List A → List A
infixr 40 _::_
-- liberal naming policy enables naming above
data _⋆ (α : Set) : Set where
ε : α ⋆
_C_ : α → α ⋆ → α ⋆
{-
whitespace important
--------------------------------------------------
2.2 DEPENDENT FUNCTIONS
result type depends on VALUE of an arg
(x : A) → B for the
type of functions
- given : arg x of type A
- returns : result of type B
- where x may appear in B
special case is when x itself is a type, e.g.,
-}
identity : (A : Set) → A → A
identity A x = x
zero’ : Nat
zero’ = identity Nat zero
{-
identity is a dependent function
- given
- a type argument A and
- an element of A
- returns
- the element
This is how polymorphic functions are encoded in Agda.
example : function which takes a dependent function and applies it to an argument:
-}
apply : (A : Set) (B : A → Set) → ((x : A) → B x) → (a : A) → B a
apply A B f a = f a
{-
shorthand for dependent function types:
(x : A) (y : B) → C
for (x : A) → (y : B) → C
(x y : A) → B
for (x : A) (y : A) → B
elements of dependent function types are lambda terms which may carry explicit type info
alternative ways to identity
identity function above are:
-}
identity2 : (A : Set) → A → A
identity2 = \A x → x
identity3 : (A : Set) → A → A
identity3 = \(A : Set) (x : A) → x
identity4 : (A : Set) → A → A
identity4 = \(A : Set) x → x
{-
--------------------------------------------------
2.3 IMPLICIT ARGUMENTS
Previous section showed how dependent functions taking types as
arguments used to model polymorphic types.
But it is not necessary to say at which point it is applied - that can be inferred.
The identity functions above explicitly provide the type argument.
Avoid explicit type arg via implicit arguments using {}
-}
id : {A : Set} → A → A
id x = x
true’ : Bool
true’ = id true
{-
No restrictions on what arguments can be made implicit.
Not guarantees that an implicit argument can be inferred.
E.g., make 2nd arg of identity function implicit as well:
-}
silly : {A : Set} {x : A} → A -- but type checker cannot figure out 2nd arg
silly {_} {x} = x
false’ : Bool
false’ = silly {x = false} -- must provide via named implicit application syntax f {v}
-- must use name if not in order
-- type checker fills in term
-- will not search, only looks at typing constraints and performs unification
one : Nat
one = identity _ (suc zero)
-- example of inferring the typing constraints
_◦_ : {A : Set}{B : A → Set}{C : (x : A) → B x → Set}
(f : {x : A}(y : B x) → C x y)(g : (x : A) → B x)
(x : A) → C x (g x)
(f ◦ g) x = f (g x)
plus-two = suc ◦ suc
-- other functions
map : {A B : Set} → (A → B) → List A → List B
map f [] = []
map f (x :: xs) = f x :: map f xs
_++_ : {A : Set} → List A → List A → List A
[] ++ ys = ys
(x :: xs) ++ ys = x :: (xs ++ ys)
{-
--------------------------------------------------
-- 2.4 DATATYPE FAMILIES
So far, only used dependent types is to represent polymorphism
-}
data Vec (A : Set) : Nat → Set where
[] : Vec A zero
_::_ : {n : Nat} → A → Vec A n → Vec A (suc n)
{-
type of Vec A is Nat → Set
- means that Vec A is a family of types indexed by natural numbers
- for each Nat n, Vec A n is a type
- [] constructs an element in Vec A zero
- _::_ constructs an element in Vec A (suc n) for some n
distinction between parameters and indices of a datatype
- parameterised by type A
- indexed over Nat
type of _::_ is a dependent function type
- 1st arg is an implicit Nat n
- returns type that depends on n 'suc n'
same constructor names for Vec as for List
- constructor names are not required to be distinct between different datatypes
-}
-- safe head
head : {A : Set} {n : Nat} → Vec A (suc n) → A
head (x :: xs) = x
tail : {A : Set} {n : Nat} → Vec A (suc n) → Vec A n
tail (x :: xs) = xs
{-
rule for when to include a particular case is:
if it is type correct you have to include it
-}
--------------------------------------------------
-- DOT PATTERNS : indicate value of an arg deduced by type checking, not pattern matching
vmap : {A B : Set} {n : Nat} → (A → B) → Vec A n → Vec B n
vmap f [] = []
vmap f (x :: xs) = f x :: vmap f xs
{-
map on Vec is exactly the same map on List
only change is the type
behind the scenes, what happens with the length argument when pattern matching
to see, define new versions of Vec and vmap with fewer implicit arguments:
-}
data Vec2 (A : Set) : Nat → Set where
nil : Vec2 A zero
cons : (n : Nat) → A → Vec2 A n → Vec2 A (suc n)
vmap2 : {A B : Set} (n : Nat) → (A → B) → Vec2 A n → Vec2 B n
vmap2 .zero f nil = nil
vmap2 .(suc n) f (cons n x xs) = cons n (f x) (vmap2 n f xs)
{-
pattern matching on list argument reveals its length
- if nil then zero
- if cons then suc n
to indicate value of an arg deduced by type checking,
rather than observed by pattern matching,
it is prefixed by a dot (.)
could choose to define vmap by first pattern matching on the length rather than on the list
-}
vmap3 : {A B : Set} (n : Nat) → (A → B) → Vec2 A n → Vec2 B n
vmap3 zero f nil = nil
vmap3 (suc n) f (cons .n x xs) = cons n (f x) (vmap3 n f xs)
{-
rule for when arg should be dotted:
- if there is a unique type correct value for the argument it should be dotted
above, the terms under the dots were valid patterns
- in general they can be arbitrary terms
e.g.,
-}
data Image_el_ {A B : Set}(f : A → B) : B → Set where
im : (x : A) → Image f el f x
{-
only way to construct an element in the image of f
is to pick an argument x and apply f to x
knowing that a particular y is in the image of f enables computing the inverse of f on y:
-}
inv : {A B : Set} (f : A → B) (y : B) → Image f el y → A
inv f .(f x) (im x) = x
{-
--------------------------------------------------
ABSURD PATTERNS
-}
-- family of numbers smaller than a given natural number
data Fin : Nat → Set where
fzero : {n : Nat} → Fin (suc n) -- smaller than suc n for any n
fsuc : {n : Nat} → Fin n → Fin (suc n) -- if i smaller than n then fsuc i is smaller than suc n
-- Now way to construct a Fin smaller than zero.
-- When no possible constructor patterns for a given argument
-- then pattern match with absurd pattern ()
magic : {A : Set} → Fin zero → A
magic ()
{-
Using absurd pattern means no need to give a right hand side,
since no way anyting could given as an arg that would match.
Seems the clause not needed, that checker could tell.
But a case can only be omitted if no type correct way of writing it.
'magic a' has a type correct left hand side
absurd pattern can only be used if there are no valid constructor patterns for the arg.
It is not enough that there are no closed inhabitants of the type.
E.g.,
-}
data Empty : Set where
empty : Fin zero → Empty
{-
Args of type Empty cannot be matched with absurd pattern,
since there is a valid constructor pattern: 'empty x'
So must write:
-}
magic’ : {A : Set} → Empty → A
magic’ (empty ()) -- magic’ () -- not accepted
-- Extract ith element of the list (starting from 0):
-- Turns a list into a function from indices to elements.
_!_ : {n : Nat} {A : Set} → Vec A n → Fin n → A
[] ! ()
(x :: xs) ! fzero = x
(x :: xs) ! (fsuc i) = xs ! i
{-
types ensure no danger of indexing outside the list
reflected in use of absurd in empty case : no possible values for the index
-}
-- constructing a list given a function from indices to elements
tabulate : {n : Nat} {A : Set} → (Fin n → A) → Vec A n
tabulate {zero} f = []
tabulate {suc n} f = f fzero :: tabulate (f ◦ fsuc) -- recursive call implicitly gets 'n'
{-
tabulate is defined by recursion over the length of the result list,
even though it is an implicit argument.
In general, no correspondance between implicit data and computationally irrelevant data.
------------------------------------------------------------------------------
-- 2.5 PROGRAMS AS PROOFS
Type system can represent propositions as types whose elements are proofs of the proposition.
-}
data False : Set where -- datatype with no constructors
record True : Set where -- record type with no fields
-- has a single element : the empty record
{-
Could have defined True as datatype with a single element.
But using record def lets checker know there is a unique element of True
and will fill in any implicit arguments of type True with this element.
exploited in trivial:
-}
trivial : True
trivial = _
trivial' : True
trivial' = record {}
{-
where right hand is underscore,
instead of explicitly writing 'record {}'
The 'False' and 'True' propositions enable working with decidable propositions.
Can model decidable propositions as booleans and define
-}
-- takes a VALUE of type Bool
-- returns a Set (i.e., a TYPE)
isTrue : Bool → Set
isTrue true = True
isTrue false = False
isFalse : Bool → Set
isFalse x = isTrue (not x)
{-
isTrue b is the type of proofs that b equals true.
This technique enables defining safe list lookup function in a different way,
working on simply typed lists and numbers.
-}
-- takes Nat VALUES
-- returns Bool VALUES
_<_ : Nat → Nat → Bool
_ < zero = false
zero < suc n = true
suc m < suc n = m < n
length : {A : Set} → List A → Nat
length [] = zero
length (x :: xs) = suc (length xs)
-- |
-- v
lookup : {A : Set} (xs : List A) (n : Nat) → isTrue (n < length xs) → A
lookup [] n ()
lookup (x :: xs) zero p = x
lookup (x :: xs) (suc n) p = lookup xs n p
{-
Rather than there being no index into the empty list,
there is no proof that a number n is smaller than zero.
In this example, using indexed types to capture the precondition,
as done in '_!_' above, is a little bit nicer,
since do not have to pass an explicit proof object
as done in 'lookup' above.
When properties cannot be easily captured by indexed types, this is a useful alternative.
--------------------------------------------------
DEFINE PROPOSITIONS USING DATATYPE FAMILIES
-}
-- family of proofs of “being equal to x”
-- specify the type by giving it two args
-- type can only be constructed when the two args reduce to the same thing
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x -- only inhabited at index x where the single proof is refl
-- another exampla
-- compare to def of '_<_' above
data _≤_ : Nat → Nat → Set where
leq-zero : {n : Nat} → zero ≤ n
leq-suc : {m n : Nat} → m ≤ n → suc m ≤ suc n
{-
advantage of this approach
- PATTERN MATCH ON PROOF OBJECT
- makes proving properties of _≤_ easier
- e.g.,
-}
leq-trans : {l m n : Nat} → l ≤ m → m ≤ n → l ≤ n
leq-trans leq-zero _ = leq-zero
leq-trans (leq-suc p) (leq-suc q) = leq-suc (leq-trans p q)
{-
------------------------------------------------------------------------------
-- 2.6 WITH : PATTERN MATCH ON RESULT OF INTERMEDIATE COMPUTATION
Haskell : done on right hand side using case
when matching expression in dependently typed language, learn
- shape of expression
- things about other expressions
- e.g., matching 'Vec A n' reveals info about n
- not captured by usual case expression
to pattern match on an expression e in the def of fun f
- abstract f over value of e
- effectively adding another argument to f
- can then be matched on in usual way
-}
min : Nat → Nat → Nat
min x y with x < y
min x y | true = x
min x y | false = y
{-
Can abstract over multiple expressions at same time, separated by vertical bars.
Can nest with abstractions.
When matching on arg using WITH, no need to match on args again:
- use ...
-}
filter : {A : Set} → (A → Bool) → List A → List A
filter p [] = []
filter p (x :: xs) with p x
... | true = x :: filter p xs
... | false = filter p xs
{-
Example of revealing info via matching.
Compare numbers for equality.
Instead of returning boolean,
return proof of equality or
explanation of why they are not equal.
-}
data _≠_ : Nat → Nat → Set where
z≠s : {n : Nat} → zero ≠ suc n -- different if one is zero and other suc
s≠z : {n : Nat} → suc n ≠ zero -- vice versa
s≠s : {m n : Nat} → m ≠ n → suc m ≠ suc n -- both suc but their predecessors are different
data Equal? (n m : Nat) : Set where
eq : n ≡ m → Equal? n m
neq : n ≠ m → Equal? n m
-- now function that returns the explanation
equal? : (n m : Nat) → Equal? n m
-- Equal? zero zero
-- zero ≡ zero
equal? zero zero = eq refl
equal? zero (suc _) = neq z≠s
equal? (suc _) zero = neq s≠z
equal? (suc n) (suc m) with equal? n m -- matching on proof reveals if predecessors are equal
equal? (suc _) (suc _) | eq refl = eq refl
-- Equal? (suc n) (suc m)
-- suc n ≠ suc m
-- n ≠ m
equal? (suc _) (suc _) | neq p = neq (s≠s p)
{-
using WITH : expression is abstracted from entire context
means that if expression occurs in type of arg to function or in result type,
occurrence is replaced by the with-argument on the left hand side.
e.g., prove 'filter' only removes some elements
-}
-- to make a sublist, each element can either be dropped or kept
infix 20 _⊆_
data _⊆_ {A : Set} : List A → List A → Set where
stop : [] ⊆ []
drop : forall {xs y ys} → xs ⊆ ys → xs ⊆ y :: ys
keep : forall {x xs ys} → xs ⊆ ys → x :: xs ⊆ x :: ys
{-
When checker can infer type of an arg in fun type, then can use forall:
– forall {x y} a b → A shorthand for {x : _} {y : _} (a : _) (b : _) → A
-}
-- proof that filter computes a sublist of its argument:
lem-filter : {A : Set} (p : A → Bool) (xs : List A)
→ filter p xs ⊆ xs
lem-filter p [] = stop
lem-filter p (x :: xs) with p x
... | true = keep (lem-filter p xs)
... | false = drop (lem-filter p xs)
{-
to prove lem-filter p (x :: xs)
need to prove : (filter p (x :: xs) | p x) ⊆ x :: xs
when abstracting over p x it will be abstracted from goal type, giving
lem-filter p (x :: xs) with p x
... | px = ?
where p x has been replaced by px in the goal type
(filter p (x :: xs) | px) ⊆ x :: xs
match px reduce call to filter
lem-filter p (x :: xs) with p x
... | true = ? {- x :: filter p xs ⊆ x :: xs -}
... | false = ? {- filter p xs ⊆ x :: xs -}
Sometimes WITH useful to abstract over expr that will not be matched,
e.g., expect expr to be instantiated by matching on something else
-}
lem-plus-zero : (n : Nat) → n + zero ≡ n
lem-plus-zero zero = refl
lem-plus-zero (suc n) with n + zero | lem-plus-zero n
... | _ | refl = refl -- suc n ≡ suc n
{-
In suc ("step" case) : match on induction hypothesis : n + zero ≡ n
to prove suc n + zero ≡ suc n
but n + zero does not unify with n
so abstract over n + zero, calling it _,
left with the induction hypothesis m ≡ n and goal suc m ≡ suc n
Now match on induction hypothesis, instantiating _ to n
--------------------------------------------------
-- 2.7 Modules TODO
--------------------------------------------------
-- 2.8 Records
-}
record Point : Set where
field
x : Nat
y : Nat
mkPoint : Nat → Nat → Point
mkPoint a b = record { x = a; y = b }
{-
field projections via module of the same name.
- parameterised by element of record type
- contains projection functions for the fields
- i.e.,
module Point (p : Point) where
x : Nat
y : Nat
- can be used as is or instantiated to a particular record
-}
getX : Point → Nat
getX = Point.x
abs2 : Point → Nat
abs2 p = let open Point p in x * x + y * y
-- TODO pattern match on records
-- can add functions to the module of a record
record Monad (M : Set → Set) : Set1 where
field
return : {A : Set} → A → M A
_>>=_ : {A B : Set} → M A → (A → M B) → M B
mapM : {A B : Set} → (A → M B) → List A → M (List B)
mapM f [] = return []
mapM f (x :: xs) = f x >>= \y →
mapM f xs >>= \ys →
return (y :: ys)
mapM’ : {M : Set → Set}
→ Monad M
→ {A B : Set}
→ (A → M B)
→ List A
→ M (List B)
mapM’ Mon f xs = Monad.mapM Mon f xs
--------------------------------------------------
-- 2.9 Exercises
-------------------------
-- Exercise 2.1. Matrix transposition
-- inner vectors are rows
Matrix : Set → Nat → Nat → Set
Matrix A n m = Vec (Vec A n) m
-- (a) function to compute vector containing n copies of element x
vec : {n : Nat} {A : Set} → A → Vec A n
vec {zero} x = []
vec {suc n} x = x :: vec {n} x
vecTest : Vec Nat 3
vecTest = vec zero
-- (b) point-wise application of vector of functions to vector of arguments
infixl 90 _$_
_$_ : {n : Nat} {A B : Set} → Vec (A → B) n → Vec A n → Vec B n
_$_ [] [] = []
_$_ (f :: fs) (x :: xs) = f x :: fs $ xs
$TestInputFs : Vec (Nat → Nat) 2
$TestInputFs = (_+ 1) :: (_* 2) :: []
$TestInputXs : Vec Nat 2
$TestInputXs = 0 :: 2 :: []
$TestOutput : Vec Nat 2
$TestOutput = 1 :: 4 :: []
$Test : $TestInputFs $ $TestInputXs ≡ $TestOutput
$Test = refl
-- (c) matrix transposition in terms of 'vec' and _$_
transpose : forall {A n m} → Matrix A n m → Matrix A m n
transpose [] = vec []
transpose (xs :: xss) = (vmap _::_ xs) $ (transpose xss)
transposeTestInput : Matrix Nat 2 3
transposeTestInput = r1 :: r2 :: r3 :: []
where
r1 = 1 :: 2 :: []
r2 = 3 :: 4 :: []
r3 = 5 :: 6 :: []
transposeTestOuput : Matrix Nat 3 2
transposeTestOuput = r1 :: r2 :: []
where
r1 = 1 :: 3 :: 5 :: []
r2 = 2 :: 4 :: 6 :: []
transposeTest : transpose transposeTestInput ≡ transposeTestOuput
transposeTest = refl
-------------------------
-- Exercise 2.2. Vector lookup
-- function composition
_∘_ : ∀ {A B C : Set} → (B → C) → (A → B) → (A → C)
(g ∘ f) x = g (f x)
-- prove 'tabulate' and '!' are each other’s inverses
-- (a) relatively easy
lem-!-tab : ∀ {A n}
→ (f : Fin n → A) → (i : Fin n)
→ ((tabulate f) ! i) ≡ f i
lem-!-tab f fzero = refl -- (tabulate f ! fzero) ≡ f fzero
lem-!-tab f (fsuc i) = lem-!-tab (f ∘ fsuc) i -- (tabulate f ! fsuc i) ≡ f (fsuc i)
-- (b) trickier
lem-tab-! : forall {A n}
→ (xs : Vec A n)
→ tabulate (xs !_) ≡ xs
lem-tab-! [] = refl
lem-tab-! (x :: xs) -- tabulate (_!_ (x :: xs)) ≡ (x :: xs)
with tabulate (xs !_) | lem-tab-! xs
... | _y | refl = refl -- (x :: _y) ≡ (x :: xs)
-- ^ ^
-- Vec A n _y ≡ xs
-------------------------
-- Exercise 2.3. Sublists (see def above)
-- (a) prove reflexivity and transitivity of ⊆
-- need to name implicits since the interesting one does not come first
⊆-refl : {A : Set} {xs : List A}
→ xs ⊆ xs
⊆-refl {xs = []} = stop
⊆-refl {xs = x :: xss} = keep (⊆-refl { xs = xss })
{-
[] [] []
[] [] [z]
[] [z] [z]
[z] [z] [z]
[z] [z] [z,z]
[z] [z,z] [z,z]
[z,z] [z,z] [z,z]
-}
⊆-trans : {A : Set} {xs ys zs : List A}
→ xs ⊆ ys
→ ys ⊆ zs
→ xs ⊆ zs
-- [] [] []
⊆-trans stop stop = stop
-- [] [] [z]
-- [z] [z] [z,z]
⊆-trans xy (drop yz) = drop (⊆-trans xy yz)
-- [] [z] [z]
-- [z] [z,z] [z,z]
⊆-trans (drop xy) (keep yz) = drop (⊆-trans xy yz)
-- [z] [z] [z]
⊆-trans (keep xy) (keep yz) = keep (⊆-trans xy yz)
⊆-trans' : {A : Set} {xs ys zs : List A}
→ xs ⊆ ys
→ ys ⊆ zs
→ xs ⊆ zs
⊆-trans' stop stop = stop
⊆-trans' stop (drop yz) = drop (⊆-trans' stop yz)
⊆-trans' (drop xy) (drop yz) = drop (⊆-trans' (drop xy) yz)
⊆-trans' (drop xy) (keep yz) = drop (⊆-trans' xy yz)
⊆-trans' (keep xy) (drop yz) = drop (⊆-trans' (keep xy) yz)
⊆-trans' (keep xy) (keep yz) = keep (⊆-trans' xy yz)
-- sublist TYPE of a specific list (compare to existing sublist RELATION above)
infixr 30 _:::_
data SubList {A : Set} : List A → Set where
[] : SubList []
_:::_ : forall x {xs} → SubList xs → SubList (x :: xs)
skip : forall {x xs} → SubList xs → SubList (x :: xs)
-- (b) extract list corresponding to a sublist
forget : {A : Set} {xs : List A}
→ SubList xs
→ List A
forget [] = []
forget (x ::: s) = x :: forget s
forget (skip s) = forget s
-- (c) prove SubList is a sublist in the sense of ⊆
lem-forget : {A : Set} {xs : List A}
→ (zs : SubList xs)
→ forget zs ⊆ xs
lem-forget [] = stop
lem-forget (x ::: zs) = keep (lem-forget zs)
lem-forget (skip zs) = drop (lem-forget zs)
-- (d) alternative def of filter : satisfies sublist property by construction
filter' : {A : Set}
→ (A → Bool) → (xs : List A)
→ SubList xs
filter' p [] = []
filter' p (x :: xs) with p x
... | true = x ::: filter' p xs
... | false = skip (filter' p xs)
-- (e) complement of a sublist
complement : {A : Set} {xs : List A}
→ SubList xs
→ SubList xs
complement [] = []
complement (x ::: xs) = skip (complement xs)
complement (skip {x} xs) = x ::: complement xs
module ComplementTest where
ll : List Nat
ll = 1 :: 2 :: 3 :: 4 :: []
p1 : Nat → Bool
p1 2 = true
p1 3 = true
p1 4 = true
p1 _ = false
p2 : Nat → Bool
p2 2 = true
p2 4 = true
p2 _ = false
sl1 : SubList ll
sl1 = filter' p1 ll
sl2 : SubList ll
sl2 = filter' p2 ll
sl1Test : sl1 ≡ skip (2 ::: 3 ::: 4 ::: [])
sl1Test = refl
sl2Test : sl2 ≡ skip (2 ::: skip (4 ::: []))
sl2Test = refl
c1 : SubList ll
c1 = complement sl1
c2 : SubList ll
c2 = complement sl2
cTest1 : c1 ≡ 1 ::: skip (skip (skip []))
cTest1 = refl
cTest2 : c2 ≡ 1 ::: skip (3 ::: skip [])
cTest2 = refl
-- https://medium.com/@angerman/powersets-in-haskell-1df9684db52a
-- (f) compute all sublists of a given list
sublists : {A : Set}
→ (xs : List A)
→ List (SubList xs)
sublists [] = [] :: []
sublists (x :: xs) = map (x :::_) (sublists xs) ++ (map skip (sublists xs))
-- 2^3 elements - expected output MUST be in same element ORDER as function result
sublistsTest : sublists (1 :: 2 :: 3 :: []) ≡
(1 ::: 2 ::: 3 ::: []) ::
(1 ::: 2 ::: skip []) ::
(1 ::: skip (3 ::: [])) ::
(1 ::: skip (skip [])) ::
skip (2 ::: 3 ::: []) ::
skip (2 ::: skip []) ::
skip (skip (3 ::: [])) ::
skip (skip (skip [])) ::
[]
sublistsTest = refl
{-
------------------------------------------------------------------------------
3 Programming Techniques : VIEWS and UNIVERSE constructions
--------------------------------------------------
3.1 VIEWS
matching can reveal info about term being matched AND terms INSIDE the type matched term
VIEW[5]: datatypes whose purpose is to reveal info about its indices
to use a view, define a view function
- computes an element of the view for arbitrary indices
-}
-- view datatype expressing
-- any Nat can be expressed as 2k or 2k + 1 for some k
-- element of Parity n says if n is even or odd and what k is
data Parity : Nat → Set where
even : (k : Nat) → Parity (k * 2)
odd : (k : Nat) → Parity (1 + k * 2)
parity : (n : Nat) → Parity n
parity zero = even zero
parity (suc n) with parity n
... | even k = odd k
... | odd k = even (suc k)
{-
parity (suc .(k * 2)) | even k = odd k
parity (suc .(1 + k * 2)) | odd k = even (suc k)
-}
half : Nat → Nat
half n with parity n
... | even k = k
... | odd k = k
{-
-- Note that k is bound in the pattern for the view,
-- not in the dotted pattern for the natural number.
half .(k * 2) | even k = k
half .(1 + k * 2) | odd k = k
-}
-------------------------
-- FINDING AN ELEMENT IN A LIST
-- given predicate and list
-- returns if P holds for all elements
-- A proof of All P xs is a list of proofs of P x for each element x of xs.
-- P does not have to be a decidable predicate.
infixr 30 _:all:_
data All {A : Set} (P : A → Set) : List A → Set where
all[] : All P []
_:all:_ : forall {x xs} → P x → All P xs → All P (x :: xs)
-- to turn a decidable predicate into a general predicate, define:
satisfies : {A : Set} → (A → Bool) → A → Set
satisfies p x = isTrue (p x)
-------------------------
-- exercise : use All to prove 2nd part of correctness of filter
-- - all elements of result satisfies the predicate
-- All (satisfies p) (filter p xs)
-- https://www.javaer101.com/en/article/18631037.html
{-
open import Relation.Binary.PropositionalEquality
filter-lem-b : {A : Set} → (p : A → Bool) → (xs : List A) → All (satisfies p) (filter p xs)
filter-lem-b p [] = vacuo
filter-lem-b p (x :: xs) with p x | inspect p x
... | true | [ eq ] = holds _ _ (subst isTrue (sym eq) _) (filter-lem-b p xs)
... | false | [ eq ] = filter-lem-b p xs
-}
-- https://stackoverflow.com/questions/38572464/agda-type-isnt-simplified-in-with-block
lem-all-filter : {A : Set}
→ (p : A → Bool) → (xs : List A)
→ All (satisfies p) (filter p xs)
lem-all-filter p [] = all[]
-- isTrue (p x)
lem-all-filter p (x :: xs) with p x | λ (y : satisfies p x) → y :all: lem-all-filter p xs
-- onTrue : (y : True) → All (λ x₁ → isTrue (p x₁)) (x :: filter p xs)
... | true | onTrue = onTrue _
... | false | _ = lem-all-filter p xs
-------------------------
-- VIEWS ON LISTS
-- given : decidable predicate on elements of list
-- find element in list that satisfies predicate,
-- or else all elements satifies negation of the predicate
data Find {A : Set} (p : A → Bool) : List A → Set where
-- does NOT specify which element to use as a witness in the found case.
-- (If the view was always to return first (or last) matching element,
-- force elements of xs (or ys) to satisfy the negation of p.)
found : (xs : List A) → (y : A) → satisfies p y → (ys : List A)
→ Find p (xs ++ y :: ys)
not-found : forall {xs} → All (satisfies (not ◦ p)) xs
→ Find p xs
-- view function computing an element of Find p xs for any p and xs
-- 1st attempt
{-
find1 : {A : Set} (p : A → Bool) (xs : List A) → Find p xs
find1 p [] = not-found all[]
find1 p (x :: xs) with p x
-- Need to return found on first match.
-- ({ }) is isTrue (p x), even though already matched on p x and found out that it was true.
-- Problem : when abstracting over p x did not know that needed to use the found constructor,
-- so there were no p x to abstract over.
-- WITH does not remember connection between the with-term and the pattern.
... | true = found [] x {! !} xs
... | false = {! !}
-}
{-
A solution : make this connection explicit with a proof object.
Do NOT abstract over the term itself
- instead rather over arbitrary term of same type
AND a proof that it is equal to the original term
-}
-- type of elements of type A AND proofs they are equal to some given x in A
data Inspect {A : Set} (x : A) : Set where
it : (y : A) → x ≡ y → Inspect x
-- construct an element of Inspect x by picking x as thing which is equal to x.
inspect : {A : Set} → (x : A) → Inspect x
inspect x = it x refl
-- lemmas
trueIsTrue : {x : Bool} → x ≡ true → isTrue x
falseIsFalse : {x : Bool} → x ≡ false → isFalse x
trueIsTrue refl = _
falseIsFalse refl = _
{-
now define find by abstracting over inspect (p x) rather than p x
provide either a proof of p x == true or a proof of p x == false
- can be use in args to 'found' and 'not-found
-}
find : {A : Set}
→ (p : A → Bool) → (xs : List A)
→ Find p xs
find p [] = not-found all[]
find p (x :: xs) with inspect (p x)
-- When p x is true, inspect (p x) matches 'it true prf' where prf : p x == true.
-- Use lemma to turn into proof of isTrue (p x) needed by 3rd arg of 'found'
... | it true prf = found [] x (trueIsTrue prf) xs
... | it false prf with find p xs
find p (x :: ._) | it false _ | found xs y py ys = found (x :: xs) y py ys
-- p x is false : use lemma
find p (x :: xs) | it false prf | not-found npxs = not-found (falseIsFalse prf :all: npxs)
-------------------------
-- INDEXING INTO A LIST
{-
Previously showed two ways of safely indexing into a list.
Both cases used type system to guarantee the index didn’t point outside the list.
In situations where there is no control over value of index (i.e., it might be outside)
a solution is to wrap result of lookup in MAYBE, but MAYBE provides no info.
-}
-- type of proofs that an element x is in a list xs.
data _∈_ {A : Set} (x : A) : List A → Set where
hd : forall {xs} → x ∈ x :: xs -- 1st el is a member
tl : forall {y xs} → x ∈ xs → x ∈ y :: xs -- any el in tail is member
-- Given proof of x ∈ xs, compute index where x occurs.
-- Count number of tls in proof.
index : forall {A} {x : A} {xs} → x ∈ xs → Nat
index hd = zero
index (tl p) = suc (index p)
-- view on Nat with respect to list
data Lookup {A : Set} (xs : List A) : Nat → Set where
inside : (x : A) → (p : x ∈ xs) → Lookup xs (index p)
outside : (m : Nat) → Lookup xs (length xs + m)
{-
When n is valid, get element at that position and guarantee that element is returned.
No way for 'lookup' to cheat.
When n is outside, get out-of-bounds proof showing by how much.
-}
-- now, guaranteed 'lookup' function
_!'_ : {A : Set}
→ (xs : List A) → (n : Nat)
→ Lookup xs n
[] !' n = outside n
(x :: xs) !' zero = inside x hd
(x :: xs) !' suc n with xs !' n
... | inside y p = inside y (tl p)
(x :: xs) !' suc .(length xs + n) | outside n = outside n
{-
(x :: xs) !' suc .(index p) | inside y p = inside y (tl p)
(x :: xs) !' suc .(length xs + n) | outside n = outside n
-}
--------------------------------------------------
-- TYPE CHECKER FOR λ-CALCULUS
| {
"alphanum_fraction": 0.5756652574,
"avg_line_length": 28.568383659,
"ext": "agda",
"hexsha": "222e4655c4d6a46f92aa762b4649477c2cdc122b",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z",
"max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_forks_repo_path": "agda/paper/2008-Ulf_Norell_and_Chapman-Dependently_Typed_Programming_in_Agda/z.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_issues_repo_path": "agda/paper/2008-Ulf_Norell_and_Chapman-Dependently_Typed_Programming_in_Agda/z.agda",
"max_line_length": 98,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_stars_repo_path": "agda/paper/2008-Ulf_Norell_and_Chapman-Dependently_Typed_Programming_in_Agda/z.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z",
"num_tokens": 9827,
"size": 32168
} |
{-# OPTIONS --cubical --safe #-}
module Cubical.HITs.Localization.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.PathSplitEquiv
open isPathSplitEquiv
module _ {ℓα ℓs ℓt} {A : Type ℓα} {S : A → Type ℓs} {T : A → Type ℓt} where
isLocal : ∀ (F : ∀ α → S α → T α) {ℓ} (X : Type ℓ) → Type _
isLocal F X = ∀ α → isPathSplitEquiv (λ (g : T α → X) → g ∘ F α)
data Localize (F : ∀ α → S α → T α) {ℓ} (X : Type ℓ) : Type (ℓ-max ℓ (ℓ-max ℓα (ℓ-max ℓs ℓt))) where
∣_∣ : X → Localize F X
-- (_∘ F α) : (T α → Localize F X) → (S α → Localize F X) is a path-split equivalence ∀ α
ext : ∀ α → (S α → Localize F X) → (T α → Localize F X)
isExt : ∀ α (f : S α → Localize F X) (s : S α) → ext α f (F α s) ≡ f s
≡ext : ∀ α (g h : T α → Localize F X) → ((s : S α) → g (F α s) ≡ h (F α s)) → ((t : T α) → g t ≡ h t)
≡isExt : ∀ α g h (p : (s : S α) → g (F α s) ≡ h (F α s)) (s : S α) → ≡ext α g h p (F α s) ≡ p s
isLocal-Localize : ∀ (F : ∀ α → S α → T α) {ℓ} (X : Type ℓ) → isLocal F (Localize F X)
fst (sec (isLocal-Localize F X α)) f t = ext α f t
snd (sec (isLocal-Localize F X α)) f i s = isExt α f s i
fst (secCong (isLocal-Localize F X α) g h) p i t = ≡ext α g h (funExt⁻ p) t i
snd (secCong (isLocal-Localize F X α) g h) p i j t = ≡isExt α g h (funExt⁻ p) t i j
| {
"alphanum_fraction": 0.5430847212,
"avg_line_length": 51.1481481481,
"ext": "agda",
"hexsha": "dbf08134fc9d95501c48fa4e8dd6a72d0faea350",
"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": "cefeb3669ffdaea7b88ae0e9dd258378418819ca",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "borsiemir/cubical",
"max_forks_repo_path": "Cubical/HITs/Localization/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca",
"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": "borsiemir/cubical",
"max_issues_repo_path": "Cubical/HITs/Localization/Base.agda",
"max_line_length": 107,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "borsiemir/cubical",
"max_stars_repo_path": "Cubical/HITs/Localization/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 616,
"size": 1381
} |
module Oscar.Category.SemigroupoidAction where
open import Oscar.Category.Action
open import Oscar.Category.Setoid
open import Oscar.Category.Semigroupoid
open import Oscar.Function
open import Oscar.Level
module _ {𝔊𝔬 𝔊𝔪 𝔊𝔮} (semigroupoid : Semigroupoid 𝔊𝔬 𝔊𝔪 𝔊𝔮) where
open Semigroupoid semigroupoid
module _ {𝔄𝔬 𝔄𝔮} (action : Action ⋆ 𝔄𝔬 𝔄𝔮) where
open Action action
record IsSemigroupoidAction
(_◂_ : ∀ {x y} → x ↦ y → ↥ x → ↥ y)
: Set (𝔊𝔬 ⊔ 𝔊𝔪 ⊔ 𝔊𝔮 ⊔ 𝔄𝔬 ⊔ 𝔄𝔮)
where
field
extensionality :
∀ {x} {s₁ s₂ : ↥ x} →
s₁ ≋ s₂ →
∀ {y} {f₁ f₂ : x ↦ y} →
(let instance _ = IsSetoid↦) →
f₁ ≋ f₂ → f₁ ◂ s₁ ≋ f₂ ◂ s₂
associativity :
∀ {x}
(s : ↥ x)
{y}
(f : x ↦ y)
{z}
(g : y ↦ z) →
(g ∙ f) ◂ s ≋ g ◂ (f ◂ s)
open IsSemigroupoidAction ⦃ … ⦄ public
record SemigroupoidAction 𝔊𝔬 𝔊𝔪 𝔊𝔮 𝔄𝔬 𝔄𝔮 : Set (lsuc (𝔊𝔬 ⊔ 𝔊𝔪 ⊔ 𝔊𝔮 ⊔ 𝔄𝔬 ⊔ 𝔄𝔮)) where
constructor [_/_]
field
semigroupoid : Semigroupoid 𝔊𝔬 𝔊𝔪 𝔊𝔮
open Semigroupoid semigroupoid public
field
action : Action ⋆ 𝔄𝔬 𝔄𝔮
open Action action public
field
_◂_ : ∀ {x y} → x ↦ y → ↥ x → ↥ y
⦃ isSemigroupoidAction ⦄ : IsSemigroupoidAction semigroupoid action _◂_
| {
"alphanum_fraction": 0.5657186779,
"avg_line_length": 25.5098039216,
"ext": "agda",
"hexsha": "70e6fa6348d1be77a996d67069e6cd67749f5e3f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-2/Oscar/Category/SemigroupoidAction.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-2/Oscar/Category/SemigroupoidAction.agda",
"max_line_length": 84,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-2/Oscar/Category/SemigroupoidAction.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 593,
"size": 1301
} |
{-# NON_TERMINATING #-}
mutual
record R : Set where
inductive
field
x : T
T : Set
T = T → R
| {
"alphanum_fraction": 0.5130434783,
"avg_line_length": 9.5833333333,
"ext": "agda",
"hexsha": "b7fbdd822623127c27e3bfd3bda62f467aa08f26",
"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/BadInductionRecursion4.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/BadInductionRecursion4.agda",
"max_line_length": 23,
"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/BadInductionRecursion4.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": 39,
"size": 115
} |
open import Everything
module Test.SurjidentityI where
module _
{𝔬₁} {𝔒₁ : Ø 𝔬₁}
{𝔯₁} (_∼₁_ : 𝔒₁ → 𝔒₁ → Ø 𝔯₁)
{𝔬₂} {𝔒₂ : Ø 𝔬₂}
{𝔯₂} (_∼₂_ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂)
(_∼₂2_ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂)
{𝔯₂'} (_∼₂'_ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂')
{ℓ₂} (_∼̇₂_ : ∀ {x y} → x ∼₂ y → x ∼₂ y → Ø ℓ₂)
(_∼̇₂'_ : ∀ {x y} → x ∼₂' y → x ∼₂' y → Ø ℓ₂)
(_∼̇₂2_ : ∀ {x y} → x ∼₂2 y → x ∼₂2 y → Ø ℓ₂)
where
postulate
instance `𝓢urjection : Surjection.class 𝔒₁ 𝔒₂
instance `𝓢urjectivity : Smap!.class _∼₁_ _∼₂_
instance `𝓢urjectextensivity : Smap!.class _∼₁_ _∼₂'_
instance `𝓢urjectivity2 : Smap!.class _∼₁_ _∼₂2_
instance `𝓡eflexivity₁ : Reflexivity.class _∼₁_
instance `𝓡eflexivity₂ : Reflexivity.class _∼₂_
instance `𝓡eflexivity₂' : Reflexivity.class _∼₂'_
instance `𝓡eflexivity₂2 : Reflexivity.class _∼₂2_
instance `𝒮urjidentity : Surjidentity!.class _∼₁_ _∼₂_ _∼̇₂_
instance `𝒮urjidentity' : Surjidentity!.class _∼₁_ _∼₂'_ _∼̇₂'_
instance `𝒮urjidentity2 : Surjidentity!.class _∼₁_ _∼₂2_ _∼̇₂2_
test-surj : Surjidentity!.type _∼₁_ _∼₂_ _∼̇₂_
test-surj = surjidentity
| {
"alphanum_fraction": 0.6014171833,
"avg_line_length": 35.28125,
"ext": "agda",
"hexsha": "c7f95b8d6369cf7773decba0c5528f399ffbe2c2",
"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/Test/SurjidentityI.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/Test/SurjidentityI.agda",
"max_line_length": 67,
"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/Test/SurjidentityI.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 593,
"size": 1129
} |
data Nat : Set where
zero : Nat
suc : Nat → Nat
data ⊥ : Set where
⊥-elim : {A : Set} → ⊥ → A
⊥-elim = λ where ()
⊥-elim₂ : {A : Set} → ⊥ → A → A
⊥-elim₂ = λ where () _
⊥-elim₃ : {A : Set} → A → ⊥ → A
⊥-elim₃ = λ where _ ()
data D : Set where
c₁ : ⊥ → D
c₂ : D
Parses : D → Set₁
Parses = λ where
c₂ → Set
(c₁ ())
Does-not-parse : D → Set₁
Does-not-parse = λ where
(c₁ ())
c₂ → Set
| {
"alphanum_fraction": 0.4795180723,
"avg_line_length": 13.8333333333,
"ext": "agda",
"hexsha": "49c6dd59e051b7995e3be948b971f8be6f474d41",
"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/Issue2586.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/Issue2586.agda",
"max_line_length": 31,
"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/Issue2586.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": 194,
"size": 415
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Natural number types and operations requiring the axiom K.
------------------------------------------------------------------------
{-# OPTIONS --with-K --safe #-}
module Data.Nat.WithK where
open import Data.Nat.Base
open import Relation.Binary.PropositionalEquality.WithK
≤″-erase : ∀ {m n} → m ≤″ n → m ≤″ n
≤″-erase (less-than-or-equal eq) = less-than-or-equal (≡-erase eq)
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 0.18
erase = ≤″-erase
{-# WARNING_ON_USAGE erase
"Warning: erase was deprecated in v0.18.
Please use ≤″-erase instead."
#-}
| {
"alphanum_fraction": 0.4660633484,
"avg_line_length": 29.4666666667,
"ext": "agda",
"hexsha": "3c3c75068adacbf08452251160a23edffa96daf8",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Nat/WithK.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Nat/WithK.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Nat/WithK.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 176,
"size": 884
} |
{-# OPTIONS --safe --warning=error #-}
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import LogicalFormulae
open import Logic.PropositionalLogic
open import Functions.Definition
open import Numbers.Naturals.Naturals
open import Vectors
open import Boolean.Definition
module Logic.PropositionalAxiomsTautology where
axiomKTaut : {a : _} {A : Set a} (P Q : Propositions A) → Tautology (implies P (implies Q P))
axiomKTaut P Q v with inspect (Valuation.v v P)
axiomKTaut P Q v | BoolTrue with≡ pT with inspect (Valuation.v v Q)
axiomKTaut P Q v | BoolTrue with≡ pT | BoolTrue with≡ qT = Valuation.vImplicationT v (Valuation.vImplicationT v pT)
axiomKTaut P Q v | BoolTrue with≡ pT | BoolFalse with≡ qF = Valuation.vImplicationT v (Valuation.vImplicationVacuous v qF)
axiomKTaut P Q v | BoolFalse with≡ pF = Valuation.vImplicationVacuous v pF
axiomSTaut : {a : _} {A : Set a} (P Q R : Propositions A) → Tautology (implies (implies P (implies Q R)) (implies (implies P Q) (implies P R)))
axiomSTaut P Q R v with inspect (Valuation.v v P)
axiomSTaut P Q R v | BoolTrue with≡ pT with inspect (Valuation.v v Q)
axiomSTaut P Q R v | BoolTrue with≡ pT | BoolTrue with≡ qT with inspect (Valuation.v v R)
axiomSTaut P Q R v | BoolTrue with≡ pT | BoolTrue with≡ qT | BoolTrue with≡ rT = Valuation.vImplicationT v (Valuation.vImplicationT v (Valuation.vImplicationT v rT))
axiomSTaut P Q R v | BoolTrue with≡ pT | BoolTrue with≡ qT | BoolFalse with≡ rF = Valuation.vImplicationVacuous v (Valuation.vImplicationF v pT (Valuation.vImplicationF v qT rF))
axiomSTaut P Q R v | BoolTrue with≡ pT | BoolFalse with≡ qF = Valuation.vImplicationT v (Valuation.vImplicationVacuous v (Valuation.vImplicationF v pT qF))
axiomSTaut P Q R v | BoolFalse with≡ pF = Valuation.vImplicationT v (Valuation.vImplicationT v (Valuation.vImplicationVacuous v pF))
excludedMiddleTaut : {a : _} {A : Set a} (P : Propositions A) → Tautology (implies (prNot (prNot P)) P)
excludedMiddleTaut P v with inspect (Valuation.v v P)
excludedMiddleTaut P v | BoolTrue with≡ pT = Valuation.vImplicationT v pT
excludedMiddleTaut P v | BoolFalse with≡ pF = Valuation.vImplicationVacuous v (Valuation.vImplicationF v (Valuation.vImplicationVacuous v pF) (Valuation.vFalse v))
propositionalAxiomsTautology : {a : _} {A : Set a} (x : Sg ThreeElements (indexAxiom A)) → Tautology (IsSubset.ofElt propositionalAxioms x)
propositionalAxiomsTautology (One , (fst ,, snd)) = axiomKTaut fst snd
propositionalAxiomsTautology (Two , record { one = one ; two = two ; three = three }) = axiomSTaut one two three
propositionalAxiomsTautology (Three , b) = excludedMiddleTaut b
| {
"alphanum_fraction": 0.7563567362,
"avg_line_length": 69.3421052632,
"ext": "agda",
"hexsha": "90c30892206eef26e678d1e7838542b569f76414",
"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": "Logic/PropositionalAxiomsTautology.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": "Logic/PropositionalAxiomsTautology.agda",
"max_line_length": 178,
"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": "Logic/PropositionalAxiomsTautology.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": 892,
"size": 2635
} |
-- Andreas, 2016-11-18, issue #2174
-- report and test case by Nisse
postulate
F : Set → Set → Set
G : Set
G = {!!}
-- WAS: giving first F ? and then F ? ? lead to one of the metas not goalified.
-- Should succeed now, see script Issue2174a.sh
| {
"alphanum_fraction": 0.652,
"avg_line_length": 19.2307692308,
"ext": "agda",
"hexsha": "15711945a7081c66158211e882f3810229060c15",
"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/Issue2174a.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/Issue2174a.agda",
"max_line_length": 79,
"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/Issue2174a.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": 81,
"size": 250
} |
{-# OPTIONS --without-K #-}
module algebra.group.classifying where
open import level
open import algebra.group.core
open import algebra.group.morphism
open import equality.core
open import function.isomorphism
open import pointed.core
open import sets.unit
open import sum
open import hott.level.core
open import hott.loop.core
open import hott.truncation.core
open import hott.equivalence
module _ {i}(G : Set i) ⦃ gG : IsGroup G ⦄ where
open import algebra.group.gset G
open IsGroup ⦃ ... ⦄
-- G as a G-Set
G' : GSet i
G' = (G , GisGSet)
-- G as a pointed set
G* : PSet i
G* = (G , e)
𝑩 : Set (lsuc i)
𝑩 = Σ (GSet i) λ X → Trunc 1 (X ≡ G')
base : 𝑩
base = (G' , [ refl ])
𝑩* : PSet (lsuc i)
𝑩* = (𝑩 , base)
𝑩-Ω : (base ≡ base) ≅ G
𝑩-Ω = begin
(base ≡ base)
≅⟨ sym≅ Σ-split-iso ⟩
( Σ (G' ≡ G') λ p
→ subst (λ X → Trunc 1 (X ≡ G')) p [ refl ] ≡ [ refl ] )
≅⟨ (Σ-ap-iso refl≅ λ p → contr-⊤-iso (Trunc-level 1 _ _)) ·≅ ×-right-unit ⟩
(G' ≡ G')
≅⟨ GSet-univalence G ⦃ xG = GisGSet ⦄ G ⦃ yG = GisGSet ⦄ ⟩
( Σ (GSetMorphism G ⦃ xG = GisGSet ⦄ G ⦃ yG = GisGSet ⦄) λ { (f , _)
→ weak-equiv f } )
≅⟨ (Σ-ap-iso' (GSet-repr-iso is-set ⦃ xG = GisGSet ⦄) λ _ → refl≅) ⟩
( Σ G λ { g → weak-equiv (λ x → x * g) } )
≅⟨ ( Σ-ap-iso refl≅ λ g → contr-⊤-iso ( lem g , h1⇒prop (we-h1 _) _ ) )
·≅ ×-right-unit ⟩
G
∎
where
open ≅-Reasoning
lem : (g : G) → weak-equiv (λ x → x * g)
lem g = proj₂ (≅'⇒≈ (≅⇒≅' (right-translation-iso g)))
| {
"alphanum_fraction": 0.5423620026,
"avg_line_length": 26.406779661,
"ext": "agda",
"hexsha": "8080addbbc42186e13d759d761bca281fa5aab5d",
"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/algebra/group/classifying.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/algebra/group/classifying.agda",
"max_line_length": 79,
"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/algebra/group/classifying.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": 684,
"size": 1558
} |
{-# OPTIONS -v treeless.opt:20 #-}
module _ where
open import Agda.Builtin.Nat using (_<_)
open import Common.Prelude
open import Common.Integer
-- Should compile to
-- λ a b → case a of
-- "neg" → 0 - b
-- _ → b
match-on-lit : String → Integer → Integer
match-on-lit "neg" x with x
... | pos (suc n) = negsuc n
... | pos 0 = pos 0
... | negsuc n = pos (suc n)
match-on-lit _ x = x
-- This doesn't compile as nicely, since the match on "neg"
-- ends up between the match on the int and the nat (not sure why).
match-on-lit₂ : String → Integer → Integer
match-on-lit₂ "neg" (pos (suc n)) = negsuc n
match-on-lit₂ "neg" (negsuc n) = pos (suc n)
match-on-lit₂ _ x = x
-- Should compile to a flat case
nested-match : Integer → String
nested-match (pos 0) = "zero"
nested-match (pos 1) = "one"
nested-match (pos (suc (suc n))) = "lots"
nested-match (negsuc 0) = "minus one"
nested-match (negsuc 1) = "minus two"
nested-match (negsuc (suc (suc n))) = "minus lots"
data Diff : Set where
less : Nat → Diff
equal : Diff
greater : Nat → Diff
compareNat : Nat → Nat → Diff
compareNat a b with a < b
... | true = less (b ∸ suc a)
... | false with b < a
... | true = greater (a ∸ suc b)
... | false = equal
{-# INLINE compareNat #-}
-- Should compile to 0 - a
neg : Nat → Integer
neg zero = pos zero
neg (suc a) = negsuc a
{-# INLINE neg #-}
-- Should compile to a - b
_-N_ : Nat → Nat → Integer
a -N b with compareNat a b
... | less k = negsuc k
... | equal = pos (a ∸ b)
... | greater k = pos (suc k)
{-# INLINE _-N_ #-}
-- Should compile to a + b
_+Z_ : Integer → Integer → Integer
pos a +Z pos b = pos (a + b)
pos a +Z negsuc b = a -N suc b
negsuc a +Z pos b = b -N suc a
negsuc a +Z negsuc b = negsuc (suc a + b)
{-# INLINE _+Z_ #-}
-- Should compile to a * b
_*Z_ : Integer → Integer → Integer
pos a *Z pos b = pos (a * b)
pos a *Z negsuc b = neg (a * suc b)
negsuc a *Z pos b = neg (suc a * b)
negsuc a *Z negsuc b = pos (suc a * suc b)
{-# INLINE _*Z_ #-}
printInt : Integer → IO Unit
printInt x = putStrLn (intToString x)
main : IO Unit
main = printInt (match-on-lit "neg" (pos 42))
,, printInt (match-on-lit₂ "neg" (pos 42))
,, putStrLn (nested-match (negsuc 5))
| {
"alphanum_fraction": 0.5725840783,
"avg_line_length": 27.6352941176,
"ext": "agda",
"hexsha": "31eced17eb01e560599933b828a6c1f5c8aa9a24",
"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/Compiler/simple/CompileNumbers.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/Compiler/simple/CompileNumbers.agda",
"max_line_length": 67,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Compiler/simple/CompileNumbers.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": 799,
"size": 2349
} |
{-# OPTIONS --cubical --no-import-sorts #-}
module Spaces where
open import Agda.Primitive renaming (_⊔_ to ℓ-max; lsuc to ℓ-suc; lzero to ℓ-zero)
private
variable
ℓ ℓ' ℓ'' : Level
open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc)
open import Cubical.Structures.CommRing
open import Cubical.Relation.Nullary.Base -- ¬_
open import Cubical.Relation.Binary.Base
open import Cubical.Data.Sum.Base renaming (_⊎_ to infixr 4 _⊎_)
open import Cubical.Data.Sigma.Base renaming (_×_ to infixr 4 _×_)
open import Cubical.Data.Empty renaming (elim to ⊥-elim) -- `⊥` and `elim`
-- open import Cubical.Structures.Poset
open import Cubical.Foundations.Function
open import Cubical.Structures.Ring
open import Cubical.Structures.AbGroup
open import Cubical.Foundations.Logic renaming (¬_ to ¬ᵖ_)
open import Function.Base using (_∋_)
-- open import Function.Reasoning using (∋-syntax)
open import Function.Base using (it) -- instance search
{-
| name | carrier | module | metric | norm | inner | basis | cauchy |
|-----------------------------------------|---------|--------|--------|------|-------|-------|--------|
| VectorSpace | any | K | | | | | |
| FiniteDimVectorSpace | any | K | | | | ✓ | |
| NormedVectorSpace | any | K | (✓) | ✓ | | | |
| FiniteDimNormedVectorSpace | any | K | (✓) | ✓ | | ✓ | |
| CompleteNormedVectorSpace | any | K | (✓) | ✓ | | | ✓ |
| FiniteDimCompleteNormedVectorSpace | any | K | (✓) | ✓ | | ✓ | ✓ |
| InnerProductSpace | any | K | (✓) | (✓) | ✓ | | |
| FiniteDimInnerProductSpace | any | K | (✓) | (✓) | ✓ | ✓ | |
| CompleteInnerProductSpace | any | K | (✓) | (✓) | ✓ | | ✓ |
| FiniteDimCompleteInnerProductSpace | any | K | (✓) | (✓) | ✓ | ✓ | ✓ |
| FiniteDimCompleteInnerProductSpaceOverℝ | ℝ | ℝ | (✓) | (✓) | ✓ | ✓ | ✓ |
-}
| {
"alphanum_fraction": 0.4712692967,
"avg_line_length": 53,
"ext": "agda",
"hexsha": "64059a98a27a50e28175aa8cc02eaea8186d2864",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mchristianl/synthetic-reals",
"max_forks_repo_path": "agda/Spaces.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mchristianl/synthetic-reals",
"max_issues_repo_path": "agda/Spaces.agda",
"max_line_length": 103,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mchristianl/synthetic-reals",
"max_stars_repo_path": "agda/Spaces.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-19T12:15:21.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-31T18:15:26.000Z",
"num_tokens": 716,
"size": 2332
} |
{-# OPTIONS --cubical --no-import-sorts #-}
open import Bundles
module Properties.AlmostOrderedField {ℓ ℓ'} (AOF : AlmostOrderedField {ℓ} {ℓ'}) where
open import Agda.Primitive renaming (_⊔_ to ℓ-max; lsuc to ℓ-suc; lzero to ℓ-zero)
private
variable
ℓ'' : Level
open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc)
open import Cubical.Relation.Nullary.Base -- ¬_
open import Cubical.Relation.Binary.Base
open import Cubical.Data.Sum.Base renaming (_⊎_ to infixr 4 _⊎_)
open import Cubical.Data.Sigma.Base renaming (_×_ to infixr 4 _×_)
open import Cubical.Data.Empty renaming (elim to ⊥-elim) -- `⊥` and `elim`
open import Function.Base using (_∋_)
open import Function.Base using (it) -- instance search
import MoreLogic
open MoreLogic.Reasoning
import MoreAlgebra
-- Lemma 4.1.11.
-- In the presence of the first five axioms of Definition 4.1.10, conditions (†) and (∗) are together equivalent to the condition that for all x, y, z : F,
-- 1. x ≤ y ⇔ ¬(y < x),
-- 2. x # y ⇔ (x < y) ∨ (y < x)
-- 3. x ≤ y ⇔ x + z ≤ y + z,
-- 4. x < y ⇔ x + z < y + z,
-- 5. 0 < x + y ⇒ 0 < x ∨ 0 < y,
-- 6. x < y ≤ z ⇒ x < z,
-- 7. x ≤ y < z ⇒ x < z,
-- 8. x ≤ y ∧ 0 ≤ z ⇒ x z ≤ y z,
-- 9. 0 < z ⇒ (x < y ⇔ x z < y z),
-- 10. 0 < 1.
open AlmostOrderedField AOF renaming (Carrier to F)
import Cubical.Structures.Ring
open Cubical.Structures.Ring.Theory (record {AlmostOrderedField AOF})
open MoreAlgebra.Properties.Group (record {AlmostOrderedField AOF renaming (+-isGroup to isGroup )})
-- NOTE: ported from Cubical.Structures.Group.GroupLemmas
-- NOTE: these versions differ from the Group-versions because they are defined w.r.t. an appartness relation _#_ that is not present for the Group
simplR : {a b : F} (c : F) {{_ : c # 0f}} → a · c ≡ b · c → a ≡ b
simplR {a} {b} c {{_}} a·c≡b·c =
a ≡⟨ sym (fst (·-identity a)) ∙ cong (a ·_) (sym (·-rinv c it)) ∙ ·-assoc _ _ _ ⟩
(a · c) · (c ⁻¹ᶠ) ≡⟨ cong (_· c ⁻¹ᶠ) a·c≡b·c ⟩
(b · c) · (c ⁻¹ᶠ) ≡⟨ sym (·-assoc _ _ _) ∙ cong (b ·_) (·-rinv c it) ∙ fst (·-identity b) ⟩
b ∎
·-preserves-≡ʳ : {a b : F} (c : F) {{_ : c # 0f}} → a · c ≡ b · c → a ≡ b
·-preserves-≡ʳ = simplR
-- ·-linv-unique : (x y : F) (x·y≡1 : (x ·₁ y) ≡ 1f) → x ≡ (y ⁻¹ᶠ₁)
module _ (x y : F) (x·y≡1 : x · y ≡ 1f) where
y#0 = snd (·-inv-back _ _ x·y≡1) -- duplicated inhabitant (see notes)
instance _ = y # 0f ∋ y#0
import Cubical.Structures.Group
-- NOTE: ported from Cubical.Structures.Group.GroupLemmas
abstract
·-linv-unique' : Σ[ p ∈ y # 0f ] (x ≡ _⁻¹ᶠ y {{p}})
·-linv-unique' = it , (
x · y ≡ 1f ⇒⟨ transport (λ i → x · y ≡ ·-linv y it (~ i)) ⟩
x · y ≡ y ⁻¹ᶠ · y ⇒⟨ simplR _ ⟩
x ≡ y ⁻¹ᶠ ◼) x·y≡1
·-linv-unique : (x y : F) → ((x · y) ≡ 1f) → Σ[ p ∈ y # 0f ] x ≡ (_⁻¹ᶠ y {{p}})
·-linv-unique = ·-linv-unique'
-- ⁻¹ᶠ-involutive : (x : F) (z#0 : x #' 0f) → ((x ⁻¹ᶠ₁) ⁻¹ᶠ₁) ≡ x
module _ (z : F) (z#0 : z # 0f) where
private
instance _ = z#0
z⁻¹ = z ⁻¹ᶠ -- NOTE: interestingly, the instance argument is not applied and y remains normalized in terms of z
-- so we get `y : {{ _ : z #' 0f }} → F` here
z⁻¹#0 = snd (·-inv-back z z⁻¹ (·-rinv z it))
-- NOTE: for some reason I get "There are instances whose type is still unsolved when checking that the expression it has type z #' 0f"
-- typing `y : F` did not help much. therefore this goes in two lines
instance _ = z⁻¹#0
z⁻¹⁻¹ = z⁻¹ ⁻¹ᶠ
-- NOTE: this should be similar to `right-helper` + `-involutive`
⁻¹ᶠ-involutive : (z ⁻¹ᶠ) ⁻¹ᶠ ≡ z
⁻¹ᶠ-involutive = (
z⁻¹⁻¹ ≡⟨ sym (fst (·-identity _)) ⟩
z⁻¹⁻¹ · 1f ≡⟨ (λ i → z⁻¹⁻¹ · ·-linv _ it (~ i)) ⟩
z⁻¹⁻¹ · (z⁻¹ · z) ≡⟨ ·-assoc _ _ _ ⟩
(z⁻¹⁻¹ · z⁻¹) · z ≡⟨ (λ i → ·-linv z⁻¹ it i · z) ⟩
1f · z ≡⟨ snd (·-identity _) ⟩
z ∎)
module forward -- 6. ⇒ 1. 2. 3. 4. 5.
-- 6. (†)
(+-<-extensional : ∀ w x y z → (x + y) < (z + w) → (x < z) ⊎ (y < w))
-- 6. (∗)
(·-preserves-< : ∀ x y z → 0f < z → x < y → (x · z) < (y · z))
where
-- abstract
-- 1. x ≤ y ⇔ ¬(y < x),
item-1 : ∀ x y → x ≤ y → ¬(y < x)
item-1 = λ _ _ x≤y → x≤y -- holds definitionally
item-1-back : ∀ x y → ¬(y < x) → x ≤ y
item-1-back = λ _ _ ¬[y<x] → ¬[y<x]
-- 2. x # y ⇔ (x < y) ∨ (y < x)
item-2 : ∀ x y → x # y → (x < y) ⊎ (y < x)
item-2 = λ _ _ x#y → x#y -- holds definitionally
item-2-back : ∀ x y → (x < y) ⊎ (y < x) → x # y
item-2-back = λ _ _ [x<y]⊎[y<x] → [x<y]⊎[y<x] -- holds definitionally
-- NOTE: just a plain copy of the previous proof
+-preserves-< : ∀ a b x → a < b → a + x < b + x
+-preserves-< a b x a<b = (
a < b ⇒⟨ transport (λ i → sym (fst (+-identity a)) i < sym (fst (+-identity b)) i) ⟩
a + 0f < b + 0f ⇒⟨ transport (λ i → a + sym (+-rinv x) i < b + sym (+-rinv x) i) ⟩
a + (x - x) < b + (x - x) ⇒⟨ transport (λ i → +-assoc a x (- x) i < +-assoc b x (- x) i) ⟩
(a + x) - x < (b + x) - x ⇒⟨ +-<-extensional (- x) (a + x) (- x) (b + x) ⟩
(a + x < b + x) ⊎ (- x < - x) ⇒⟨ (λ{ (inl a+x<b+x) → a+x<b+x -- somehow ⊥-elim needs a hint in the next line
; (inr -x<-x ) → ⊥-elim {A = λ _ → (a + x < b + x)} (<-irrefl (- x) -x<-x) }) ⟩
a + x < b + x ◼) a<b
+-preserves-<-back : ∀ x y z → x + z < y + z → x < y
+-preserves-<-back x y z =
( x + z < y + z ⇒⟨ +-preserves-< _ _ (- z) ⟩
(x + z) - z < (y + z) - z ⇒⟨ transport (λ i → +-assoc x z (- z) (~ i) < +-assoc y z (- z) (~ i)) ⟩
x + (z - z) < y + (z - z) ⇒⟨ transport (λ i → x + +-rinv z i < y + +-rinv z i) ⟩
x + 0f < y + 0f ⇒⟨ transport (λ i → fst (+-identity x) i < fst (+-identity y) i) ⟩
x < y ◼)
-- 3. x ≤ y ⇔ x + z ≤ y + z,
item-3 : ∀ x y z → x ≤ y → x + z ≤ y + z
item-3 x y z = (
x ≤ y ⇒⟨ (λ z → z) ⟩ -- unfold the definition
(y < x → ⊥) ⇒⟨ (λ f → f ∘ (+-preserves-<-back y x z) ) ⟩
(y + z < x + z → ⊥) ⇒⟨ (λ z → z) ⟩ -- refold the definition
x + z ≤ y + z ◼)
item-3-back : ∀ x y z → x + z ≤ y + z → x ≤ y
item-3-back x y z = (
x + z ≤ y + z ⇒⟨ (λ z → z) ⟩ -- unfold the definition
(y + z < x + z → ⊥) ⇒⟨ (λ f p → f (+-preserves-< y x z p)) ⟩ -- just a variant of the above
(y < x → ⊥) ⇒⟨ (λ z → z) ⟩ -- refold the definition
x ≤ y ◼)
-- 4. x < y ⇔ x + z < y + z,
item-4 : ∀ x y z → x < y → x + z < y + z
item-4 = +-preserves-<
item-4-back : ∀ x y z → x + z < y + z → x < y
item-4-back = +-preserves-<-back
-- 5. 0 < x + y ⇒ 0 < x ∨ 0 < y,
item-5 : ∀ x y → 0f < x + y → (0f < x) ⊎ (0f < y)
item-5 x y = (
(0f < x + y) ⇒⟨ transport (λ i → fst (+-identity 0f) (~ i) < x + y) ⟩
(0f + 0f < x + y) ⇒⟨ +-<-extensional y 0f 0f x ⟩
(0f < x) ⊎ (0f < y) ◼)
-- 6. x < y ≤ z ⇒ x < z,
item-6 : ∀ x y z → x < y → y ≤ z → x < z
item-6 x y z x<y y≤z = (
x < y ⇒⟨ +-preserves-< _ _ _ ⟩
x + z < y + z ⇒⟨ transport (λ i → x + z < +-comm y z i) ⟩
x + z < z + y ⇒⟨ +-<-extensional y x z z ⟩
(x < z) ⊎ (z < y) ⇒⟨ (λ{ (inl x<z) → x<z
; (inr z<y) → ⊥-elim (y≤z z<y) }) ⟩
x < z ◼) x<y
-- 7. x ≤ y < z ⇒ x < z,
item-7 : ∀ x y z → x ≤ y → y < z → x < z
item-7 x y z x≤y = ( -- very similar to the previous one
y < z ⇒⟨ +-preserves-< y z x ⟩
y + x < z + x ⇒⟨ transport (λ i → +-comm y x i < z + x) ⟩
x + y < z + x ⇒⟨ +-<-extensional x x y z ⟩
(x < z) ⊎ (y < x) ⇒⟨ (λ{ (inl x<z) → x<z
; (inr y<x) → ⊥-elim (x≤y y<x)}) ⟩
x < z ◼)
item-10 : 0f < 1f
module _ (z : F) (0<z : 0f < z) where
private
instance _ = z # 0f ∋ inr 0<z
z⁻¹ = z ⁻¹ᶠ
z⁻¹#0 = snd (·-inv-back z z⁻¹ (·-rinv z it))
abstract
⁻¹ᶠ-preserves-sign : 0f < z ⁻¹ᶠ
⁻¹ᶠ-preserves-sign with z⁻¹#0
... | inl z⁻¹<0 = (
z⁻¹ < 0f ⇒⟨ ·-preserves-< _ _ z 0<z ⟩
z⁻¹ · z < 0f · z ⇒⟨ transport (λ i → ·-linv z it i < 0-leftNullifies z i) ⟩
1f < 0f ⇒⟨ <-trans _ _ _ item-10 ⟩
0f < 0f ⇒⟨ <-irrefl _ ⟩
⊥ ⇒⟨ ⊥-elim ⟩ _ ◼) z⁻¹<0
... | inr 0<z⁻¹ = 0<z⁻¹
-- 8. x ≤ y ∧ 0 ≤ z ⇒ x z ≤ y z,
item-8 : ∀ x y z → x ≤ y → 0f ≤ z → x · z ≤ y · z
-- For item 8, suppose x ≤ y and 0 ≤ z and yz < xz.
item-8 x y z x≤y 0≤z y·z<x·z = let
-- Then 0 < z (x − y) by (†),
i = ( y · z < x · z ⇒⟨ transport (λ i → ·-comm y z i < ·-comm x z i) ⟩
z · y < z · x ⇒⟨ +-preserves-< _ _ _ ⟩
(z · y) - (z · y) < (z · x) - (z · y ) ⇒⟨ transport (cong₂ _<_ (+-rinv (z · y))
( λ i → (z · x) + sym (-commutesWithRight-· z y) i )) ⟩
0f < (z · x) + (z · (- y)) ⇒⟨ transport (cong₂ _<_ refl (sym (fst (dist z x (- y))))) ⟩ -- [XX]
0f < z · (x - y) ◼) y·z<x·z
instance _ = z · (x - y) # 0f ∋ inr i
-- and so, being apart from 0, z (x − y) has a multiplicative inverse w.
w = (z · (x - y)) ⁻¹ᶠ
ii : 1f ≡ (z · (x - y)) · w
ii = sym (·-rinv _ _)
-- Hence z itself has a multiplicative inverse w (x − y),
iii : 1f ≡ z · ((x - y) · w)
iii = transport (λ i → 1f ≡ ·-assoc z (x - y) w (~ i)) ii
instance z#0f = z # 0f ∋ fst (·-inv-back _ _ (sym iii))
-- and so 0 < z ∨ z < 0, where the latter case contradicts the assumption 0 ≤ z, so that we have 0 < z.
instance _ = 0f < z ∋ case z#0f of λ where
(inl z<0) → ⊥-elim (0≤z z<0)
(inr 0<z) → 0<z
-- Now w (x − y) has multiplicative inverse z, so it is apart from 0,
iv : (x - y) · w # 0f
iv = snd (·-inv-back _ _ (sym iii))
-- that is (0 < w (x − y)) ∨ (w (x − y) < 0).
in case iv of λ where
-- By (∗), from 0 < w (x − y) and yz < xz we get yzw (x − y) < xzw (x − y), so y < x, contradicting our assumption that x ≤ y.
(inr 0<[x-y]·w) → (
y · z < x · z ⇒⟨ ·-preserves-< _ _ _ 0<[x-y]·w ⟩
(y · z) · ((x - y) · w) < (x · z) · ((x - y) · w) ⇒⟨ transport (λ i →
(·-assoc y z ((x - y) · w)) (~ i)
< (·-assoc x z ((x - y) · w)) (~ i)) ⟩
y · (z · ((x - y) · w)) < x · (z · ((x - y) · w)) ⇒⟨ transport (λ i →
y · (iii (~ i)) < x · (iii (~ i))) ⟩
y · 1f < x · 1f ⇒⟨ transport (cong₂ _<_
(fst (·-identity y)) (fst (·-identity x))) ⟩
y < x ⇒⟨ x≤y ⟩
⊥ ◼) y·z<x·z
-- In the latter case, from (∗) we get zw (x − y) < 0, i.e.
-- 1 < 0 which contradicts item 10, so that we have 0 < w (x − y).
(inl p) → (
(x - y) · w < 0f ⇒⟨ ·-preserves-< _ _ _ it ⟩
((x - y) · w) · z < 0f · z ⇒⟨ transport (cong₂ _<_ (·-comm _ _) (0-leftNullifies z)) ⟩
z · ((x - y) · w) < 0f ⇒⟨ ( transport λ i → iii (~ i) < 0f) ⟩
1f < 0f ⇒⟨ <-trans _ _ _ item-10 ⟩
0f < 0f ⇒⟨ <-irrefl _ ⟩
⊥ ◼) p
-- 9. 0 < z ⇒ (x < y ⇔ x z < y z),
item-9 : ∀ x y z → 0f < z → (x < y → x · z < y · z)
item-9 = ·-preserves-<
item-9-back : ∀ x y z → 0f < z → (x · z < y · z → x < y)
-- For the other direction of item 9, assume 0 < z and xz < yz,
item-9-back x y z 0<z x·z<y·z = let
instance _ = ( x · z < y · z ⇒⟨ +-preserves-< _ _ _ ⟩
(x · z) - (x · z) < (y · z) - (x · z) ⇒⟨ transport (cong₂ _<_ (+-rinv (x · z)) refl) ⟩
0f < (y · z) - (x · z) ◼) x·z<y·z
_ = (y · z) - (x · z) # 0f ∋ inr it
-- so that yz − xz has a multiplicative inverse w,
w = ((y · z) - (x · z)) ⁻¹ᶠ
o = ( (y · z) - ( x · z) ≡⟨ ( λ i → (y · z) + (-commutesWithLeft-· x z) (~ i)) ⟩
(y · z) + ((- x) · z) ≡⟨ sym (snd (dist y (- x) z)) ⟩
(y - x) · z ∎)
instance _ = (y - x) · z # 0f ∋ transport (λ i → o i # 0f) it
-- and so z itself has multiplicative inverse w (y − x).
1≡z·[w·[y-x]] = γ
iii = 1≡z·[w·[y-x]]
1≡[w·[y-x]]·z : 1f ≡ (w · (y - x)) · z
1≡[w·[y-x]]·z = transport (λ i → 1f ≡ ·-comm z (w · (y - x)) i) 1≡z·[w·[y-x]]
-- Then since 0 < z and xz < yz, by (∗), we get xzw (y − x) < yzw (y − x), and hence x < y.
instance _ = z # 0f ∋ inr 0<z
z⁻¹ = w · (y - x)
z⁻¹≡w·[y-x] : z ⁻¹ᶠ ≡ (w · (y - x))
z⁻¹≡w·[y-x] = let tmp = sym (snd (·-linv-unique (w · (y - x)) z (sym 1≡[w·[y-x]]·z)))
in transport (cong (λ z#0 → _⁻¹ᶠ z {{z#0}} ≡ (w · (y - x))) (#-isProp z 0f _ _)) tmp
0<z⁻¹ : 0f < z ⁻¹ᶠ
0<z⁻¹ = ⁻¹ᶠ-preserves-sign z 0<z
instance _ = 0f < w · (y - x) ∋ transport (λ i → 0f < z⁻¹≡w·[y-x] i) 0<z⁻¹
-- instance _ = 0f < z⁻¹ ∋ ?
in ( x · z < y · z ⇒⟨ ·-preserves-< _ _ z⁻¹ it ⟩
(x · z) · z⁻¹ < (y · z) · z⁻¹ ⇒⟨ transport (λ i → ·-assoc x z z⁻¹ (~ i) < ·-assoc y z z⁻¹ (~ i)) ⟩
x · (z · z⁻¹) < y · (z · z⁻¹) ⇒⟨ transport (λ i → x · iii (~ i) < y · iii (~ i)) ⟩
x · 1f < y · 1f ⇒⟨ transport (cong₂ _<_ (fst (·-identity x)) (fst (·-identity y))) ⟩
x < y ◼) x·z<y·z
where
abstract -- NOTE: `abstract` is only allowed in `where` blocks and `where` blocks are not allowed in `let` blocks
γ =
let -- NOTE: for some reason the instance resolution does only work in let-blocks
-- I get a "Terms marked as eligible for instance search should end with a name, so `instance' is ignored here. when checking the definition of my-instance"
instance my-instance = ( x · z < y · z ⇒⟨ +-preserves-< _ _ _ ⟩
(x · z) - (x · z) < (y · z) - (x · z) ⇒⟨ transport (cong₂ _<_ (+-rinv (x · z)) refl) ⟩
0f < (y · z) - (x · z) ◼) x·z<y·z
_ = (y · z) - (x · z) # 0f ∋ inr it
-- so that yz − xz has a multiplicative inverse w,
w = ((y · z) - (x · z)) ⁻¹ᶠ
o = ( (y · z) - ( x · z) ≡⟨ ( λ i → (y · z) + (-commutesWithLeft-· x z) (~ i)) ⟩
(y · z) + ((- x) · z) ≡⟨ sym (snd (dist y (- x) z)) ⟩
(y - x) · z ∎)
instance _ = (y - x) · z # 0f ∋ transport (λ i → o i # 0f) it
in (
1f ≡⟨ (λ i → ·-linv ((y · z) - (x · z)) it (~ i)) ⟩
w · ((y · z) - (x · z)) ≡⟨ (λ i → w · o i) ⟩
w · ((y - x) · z) ≡⟨ (λ i → w · ·-comm (y - x) z i ) ⟩
w · (z · (y - x)) ≡⟨ (λ i → ·-assoc w z (y - x) i) ⟩
(w · z) · (y - x) ≡⟨ (λ i → ·-comm w z i · (y - x)) ⟩
(z · w) · (y - x) ≡⟨ (λ i → ·-assoc z w (y - x) (~ i)) ⟩
z · (w · (y - x)) ∎)
-- 10. 0 < 1.
item-10 with snd (·-inv-back _ _ (fst (·-identity 1f)))
-- For item 10, since 1 has multiplicative inverse 1, it is apart from 0, hence 0 < 1 ∨ 1 < 0.
... | inl 1<0 =
-- If 1 < 0 then by item 4 we have 0 < −1 and so by (∗) we get 0 < (−1) · (−1), that is, 0 < 1, so by transitivity 1 < 1, contradicting irreflexivity of <.
(1f < 0f ⇒⟨ +-preserves-< 1f 0f (- 1f) ⟩
1f - 1f < 0f - 1f ⇒⟨ transport (λ i → +-rinv 1f i < snd (+-identity (- 1f)) i) ⟩
0f < - 1f ⇒⟨ ( λ 0<-1 → ·-preserves-< 0f (- 1f) (- 1f) 0<-1 0<-1) ⟩
0f · (- 1f) < (- 1f) · (- 1f) ⇒⟨ transport (cong₂ _<_ (0-leftNullifies (- 1f)) refl) ⟩
0f < (- 1f) · (- 1f) ⇒⟨ transport (λ i → 0f < -commutesWithRight-· (- 1f) (1f) i ) ⟩
0f < -((- 1f) · 1f )⇒⟨ transport (λ i → 0f < -commutesWithLeft-· (- 1f) 1f (~ i)) ⟩
0f < (-(- 1f))· 1f ⇒⟨ transport (λ i → 0f < -involutive 1f i · 1f) ⟩
0f < 1f · 1f ⇒⟨ transport (λ i → 0f < fst (·-identity 1f) i) ⟩
0f < 1f ⇒⟨ <-trans _ _ _ 1<0 ⟩
1f < 1f ⇒⟨ <-irrefl 1f ⟩
⊥ ⇒⟨ ⊥-elim ⟩ _ ◼) 1<0
... | inr 0<1 = 0<1
-- Conversely, assume the 10 listed items—in particular, items 4, 5 and 9.
module back -- 1. 2. 3. 4. 5. ⇒ 6.
-- (item-1 : ∀ x y → x ≤ y → ¬(y < x))
-- (item-1-back : ∀ x y → ¬(y < x) → x ≤ y)
-- (item-2 : ∀ x y → x # y → (x < y) ⊎ (y < x))
-- (item-2-back : ∀ x y → (x < y) ⊎ (y < x) → x # y)
-- (item-3 : ∀ x y z → x ≤ y → x + z ≤ y + z)
-- (item-3-back : ∀ x y z → x + z ≤ y + z → x ≤ y)
(item-4 : ∀ x y z → x < y → x + z < y + z)
-- (item-4-back : ∀ x y z → x + z < y + z → x < y)
(item-5 : ∀ x y → 0f < x + y → (0f < x) ⊎ (0f < y))
-- (item-6 : ∀ x y z → x < y → y ≤ z → x < z)
-- (item-7 : ∀ x y z → x ≤ y → y < z → x < z)
-- (item-8 : ∀ x y z → x ≤ y → 0f ≤ z → x · z ≤ y · z)
(item-9 : ∀ x y z → 0f < z → (x < y → x · z < y · z))
-- (item-9-back : ∀ x y z → 0f < z → (x · z < y · z → x < y))
-- (item-10 : 0f < 1f)
where
item-4' : ∀ x y → 0f < x - y → y < x
item-4' x y = (
0f < x - y ⇒⟨ item-4 0f (x + (- y)) y ⟩
0f + y < (x - y) + y ⇒⟨ transport (λ i → snd (+-identity y) i < sym (+-assoc x (- y) y) i) ⟩
y < x + (- y + y) ⇒⟨ transport (λ i → y < x + snd (+-inv y) i) ⟩
y < x + 0f ⇒⟨ transport (λ i → y < fst (+-identity x) i) ⟩
y < x ◼)
lemma : ∀ x y z w → (z + w) + ((- x) + (- y)) ≡ (z - x) + (w - y)
lemma x y z w = (
-- NOTE: there has to be a shorter way to to this kind of calculations ...
-- also I got not much introspection while creating the paths
(z + w) + ((- x) + (- y)) ≡⟨ ( λ i → +-assoc z w ((- x) + (- y)) (~ i)) ⟩
(z + ( w + ((- x) + (- y)))) ≡⟨ ( λ i → z + (+-assoc w (- x) (- y) i)) ⟩
(z + ((w + (- x)) + (- y))) ≡⟨ ( λ i → z + ((+-comm w (- x) i) + (- y)) ) ⟩
(z + (((- x) + w) + (- y))) ≡⟨ ( λ i → z + (+-assoc (- x) w (- y) (~ i))) ⟩
(z + (( - x) + (w - y))) ≡⟨ ( λ i → +-assoc z (- x) (w - y) i ) ⟩
(z - x) + (w - y) ∎)
-- 6. (†)
-- In order to show (†), suppose x + y < z + w.
-- So, by item 4, we get (x + y) − (x + y) < (z + w) − (x + y), that is, 0 < (z − x) + (w − y).
-- By item 5, (0 < z − x) ∨ (0 < w − y), and so by item 4 in either case, we get x < z ∨ y < w.
+-<-extensional : ∀ w x y z → (x + y) < (z + w) → (x < z) ⊎ (y < w)
+-<-extensional w x y z = (
(x + y) < (z + w) ⇒⟨ item-4 (x + y) (z + w) (- (x + y)) ⟩
(x + y) - (x + y) < (z + w) - (x + y)
⇒⟨ transport (λ i → +-rinv (x + y) i < (z + w) + (-isDistributive x y) (~ i)) ⟩
0f < (z + w) + ((- x) + (- y)) ⇒⟨ transport (λ i → 0f < lemma x y z w i) ⟩
0f < (z - x) + (w - y) ⇒⟨ item-5 (z - x) (w - y) ⟩
(0f < z - x) ⊎ (0f < w - y) ⇒⟨ (λ{ (inl p) → inl (item-4' z x p)
; (inr p) → inr (item-4' w y p)}) ⟩
( x < z ) ⊎ ( y < w ) ◼)
-- 6. (∗)
·-preserves-< : ∀ x y z → 0f < z → x < y → (x · z) < (y · z)
·-preserves-< = item-9
| {
"alphanum_fraction": 0.386171754,
"avg_line_length": 51.1943734015,
"ext": "agda",
"hexsha": "0f8bf55c0755294412a3675cba54bdc186b7a9d2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mchristianl/synthetic-reals",
"max_forks_repo_path": "agda/Properties/AlmostOrderedField.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mchristianl/synthetic-reals",
"max_issues_repo_path": "agda/Properties/AlmostOrderedField.agda",
"max_line_length": 168,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mchristianl/synthetic-reals",
"max_stars_repo_path": "agda/Properties/AlmostOrderedField.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-19T12:15:21.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-31T18:15:26.000Z",
"num_tokens": 8763,
"size": 20017
} |
module Oscar.Property.Transitivity where
open import Oscar.Level
record Transitivity {𝔬} {⋆ : Set 𝔬} {𝔮} (_↦_ : ⋆ → ⋆ → Set 𝔮) : Set (𝔬 ⊔ 𝔮) where
field
transitivity : ∀ {x y} → x ↦ y → ∀ {z} → y ↦ z → x ↦ z
open Transitivity ⦃ … ⦄ public
| {
"alphanum_fraction": 0.578313253,
"avg_line_length": 22.6363636364,
"ext": "agda",
"hexsha": "48363258b6938b7702c260ff19078c59c27fbf9f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-2/Oscar/Property/Transitivity.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-2/Oscar/Property/Transitivity.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-2/Oscar/Property/Transitivity.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 113,
"size": 249
} |
------------------------------------------------------------------------
-- Sums (disjoint unions)
------------------------------------------------------------------------
module Data.Sum where
open import Data.Function
open import Data.Maybe.Core
------------------------------------------------------------------------
-- Definition
infixr 1 _⊎_
data _⊎_ (A B : Set) : Set where
inj₁ : (x : A) → A ⊎ B
inj₂ : (y : B) → A ⊎ B
------------------------------------------------------------------------
-- Functions
[_,_] : ∀ {A B} {C : A ⊎ B → Set} →
((x : A) → C (inj₁ x)) → ((x : B) → C (inj₂ x)) →
((x : A ⊎ B) → C x)
[ f , g ] (inj₁ x) = f x
[ f , g ] (inj₂ y) = g y
[_,_]′ : ∀ {A B C : Set} → (A → C) → (B → C) → (A ⊎ B → C)
[_,_]′ = [_,_]
map : ∀ {a b c d} → (a → c) → (b → d) → (a ⊎ b → c ⊎ d)
map f g = [ inj₁ ∘ f , inj₂ ∘ g ]
infixr 1 _-⊎-_
_-⊎-_ : ∀ {a b} → (a → b → Set) → (a → b → Set) → (a → b → Set)
f -⊎- g = f -[ _⊎_ ]₁- g
isInj₁ : ∀ {A B} → A ⊎ B → Maybe A
isInj₁ (inj₁ x) = just x
isInj₁ (inj₂ y) = nothing
isInj₂ : ∀ {A B} → A ⊎ B → Maybe B
isInj₂ (inj₁ x) = nothing
isInj₂ (inj₂ y) = just y
| {
"alphanum_fraction": 0.3301225919,
"avg_line_length": 24.8260869565,
"ext": "agda",
"hexsha": "368865f009e2ee55e5520c85cf3f57397f8eddfa",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z",
"max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "isabella232/Lemmachine",
"max_forks_repo_path": "vendor/stdlib/src/Data/Sum.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/Lemmachine",
"max_issues_repo_path": "vendor/stdlib/src/Data/Sum.agda",
"max_line_length": 72,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "vendor/stdlib/src/Data/Sum.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z",
"num_tokens": 441,
"size": 1142
} |
-- Andreas, 2019-04-10, issue #3683 reported by akaposi.
-- Regression in the termination checker introduced together
-- with collecting function calls also in the type signatures
-- (fix of #1556).
data A : Set
data B : A → Set
data A where
a : A
f : B a → A
data B where
module _
(A' : Set)(B' : A' → Set)
(a' : A')(f' : B' a' → A')
where
mutual
elimA : (x : A) → A'
elimA a = a'
elimA (f y) = f' (elimB a y)
-- Call elimA (f y) --> elimB a y
-- Call elimB x y --> elimA x in the type signature
elimB : (x : A) (y : B x) → B' (elimA x)
elimB x ()
-- With counting calls in the type signature as well, we get
--
-- elimA (f _) --> elimB a _ --> elimA a
--
-- which does not pass the naive termination checker, since
-- `a` and `f _` are unrelated in size.
--
-- However a more sophisticated type checker (Hyvernat)
-- will see that the composed call
--
-- elimA (f _) --> elimA a
--
-- is not idempotent; it cannot be composed with itself.
--
-- Thus, it is to be discounted during termination checking.
--
-- Verdict: this test case should pass.
| {
"alphanum_fraction": 0.6086956522,
"avg_line_length": 23,
"ext": "agda",
"hexsha": "6199201ef0befc0f8236c2352923196d1a4eb1e2",
"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/Issue3683.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/Issue3683.agda",
"max_line_length": 61,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue3683.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": 349,
"size": 1104
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of operations on the Colist type
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe --sized-types #-}
module Codata.Colist.Properties where
open import Size
open import Codata.Thunk using (Thunk; force)
open import Codata.Conat
open import Codata.Colist
open import Codata.Colist.Bisimilarity
open import Function
open import Relation.Binary.PropositionalEquality as Eq
-- Functor laws
module _ {a} {A : Set a} where
map-identity : ∀ (as : Colist A ∞) {i} → i ⊢ map id as ≈ as
map-identity [] = []
map-identity (a ∷ as) = Eq.refl ∷ λ where .force → map-identity (as .force)
module _ {a b c} {A : Set a} {B : Set b} {C : Set c} where
map-map-fusion : ∀ (f : A → B) (g : B → C) as {i} → i ⊢ map g (map f as) ≈ map (g ∘ f) as
map-map-fusion f g [] = []
map-map-fusion f g (a ∷ as) = Eq.refl ∷ λ where .force → map-map-fusion f g (as .force)
| {
"alphanum_fraction": 0.5525554484,
"avg_line_length": 31.4242424242,
"ext": "agda",
"hexsha": "109b3e6161052a90f8309a05d19fb391684bfe76",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Codata/Colist/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Codata/Colist/Properties.agda",
"max_line_length": 90,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Codata/Colist/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 295,
"size": 1037
} |
module BadCon where
data D : Set where
d : D
data E : Set where
d : E
postulate
F : D -> Set
test : (x : D) -> F x
test = d
-- Bad error (unbound de Bruijn index):
-- the constructor d does not construct an element of F @0
-- when checking that the expression d has type (x : D) → F x
| {
"alphanum_fraction": 0.6317567568,
"avg_line_length": 16.4444444444,
"ext": "agda",
"hexsha": "502bd5777ce4691db5f0bc463f8e08cf9f5c2850",
"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/BadCon.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/BadCon.agda",
"max_line_length": 61,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/BadCon.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": 96,
"size": 296
} |
{-# OPTIONS --copatterns --sized-types #-}
module Streams where
open import Size
open import Function
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as P
open ≡-Reasoning
open import Data.List using (List; module List; []; _∷_; _++_; length)
open import Data.Nat using (ℕ; zero; suc)
open import Data.Product using (_,_; _×_; proj₁; proj₂)
-- | Streams (with size annotations to ease definitions).
record Stream {i : Size} (A : Set) : Set where
coinductive
constructor _∷_
field
hd : A
tl : ∀ {j : Size< i} → Stream {j} A
open Stream public
-- | Stream equality is bisimilarity
record _~_ {A : Set} (s t : Stream A) : Set where
coinductive
field
hd~ : hd s ≡ hd t
tl~ : (tl s) ~ (tl t)
open _~_ public
-- | Functoriality
map : ∀ {i A B} (f : A → B) (s : Stream {i} A) → Stream {i} B
hd (map f s) = f (hd s)
tl (map {i} f s) {j} = map {j} f (tl s {j})
-- | Coalgebra structure
str-out : ∀{A} → Stream A → A × Stream A
str-out s = (hd s , tl s)
-- | (Weak) Finality
corec : ∀ {A X : Set} → (X → A × X) → (∀ {i} → X → Stream {i} A)
hd (corec f x) = proj₁ (f x)
tl (corec f x) = corec f (proj₂ (f x))
-- | Direct access to elements
_<_> : ∀{A} → Stream A → ℕ → A
s < 0 > = hd s
s < suc n > = (tl s) < n >
-- | Correctness of bisimlarity
~→pw-equal : ∀{A} {s t : Stream A} →
s ~ t → ∀ n → s < n > ≡ t < n >
~→pw-equal p zero = hd~ p
~→pw-equal p (suc n) = ~→pw-equal (tl~ p) n
-- | The usual definition of a bisimulation on streams.
Is-Bisim : ∀{A} → Rel (Stream A) _ → Set
Is-Bisim _R_ = ∀ x y → x R y → hd x ≡ hd y × (tl x) R (tl y)
-- | If R is a bisimulation then all elements related by R are bisimilar.
ex-bisimulation→bisim : ∀{A R} → Is-Bisim {A} R → ∀ {x y} → R x y → x ~ y
hd~ (ex-bisimulation→bisim p {x} {y} xRy) = proj₁ (p x y xRy)
tl~ (ex-bisimulation→bisim p {x} {y} xRy) =
ex-bisimulation→bisim p (proj₂ (p x y xRy))
-- | Generalised bisimulations between arbitrary stream coalgebras.
Is-Bisim' : ∀{A X Y : Set} → (c : X → A × X) (d : Y → A × Y) → REL X Y _ → Set
Is-Bisim' c d _R_ = ∀ x y → x R y →
proj₁ (c x) ≡ proj₁ (d y) ×
(proj₂ (c x)) R (proj₂ (d y))
ex-bisimulation→bisim' : ∀{A X Y R c d} → Is-Bisim' {A} {X} {Y} c d R →
∀ {x y} → R x y → corec c x ~ corec d y
hd~ (ex-bisimulation→bisim' p {x} {y} xRy) = proj₁ (p x y xRy)
tl~ (ex-bisimulation→bisim' p {x} {y} xRy) =
ex-bisimulation→bisim' p (proj₂ (p x y xRy))
~trans : ∀{A} {r s t : Stream A} → r ~ s → s ~ t → r ~ t
hd~ (~trans p q) = trans (hd~ p) (hd~ q)
tl~ (~trans p q) = ~trans (tl~ p) (tl~ q)
~sym : ∀{A} {s t : Stream A} → s ~ t → t ~ s
hd~ (~sym p) = sym (hd~ p)
tl~ (~sym p) = ~sym (tl~ p)
| {
"alphanum_fraction": 0.5514223195,
"avg_line_length": 31.8837209302,
"ext": "agda",
"hexsha": "38bcf1cdd210992af05d43eb9ad3aaea4a0fed01",
"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": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hbasold/Sandbox",
"max_forks_repo_path": "Streams/Streams-old.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"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": "hbasold/Sandbox",
"max_issues_repo_path": "Streams/Streams-old.agda",
"max_line_length": 78,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hbasold/Sandbox",
"max_stars_repo_path": "Streams/Streams-old.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1099,
"size": 2742
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Greatest common divisor
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Nat.GCD where
open import Data.Nat
open import Data.Nat.Divisibility
open import Data.Nat.GCD.Lemmas
open import Data.Nat.Properties using (+-suc)
open import Data.Product
open import Function
open import Induction
open import Induction.Nat using (<′-Rec; <′-recBuilder)
open import Induction.Lexicographic
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as P using (_≡_; subst)
open import Relation.Nullary using (Dec; yes; no)
------------------------------------------------------------------------
-- Greatest common divisor
module GCD where
-- Specification of the greatest common divisor (gcd) of two natural
-- numbers.
record GCD (m n gcd : ℕ) : Set where
constructor is
field
-- The gcd is a common divisor.
commonDivisor : gcd ∣ m × gcd ∣ n
-- All common divisors divide the gcd, i.e. the gcd is the
-- greatest common divisor according to the partial order _∣_.
greatest : ∀ {d} → d ∣ m × d ∣ n → d ∣ gcd
open GCD public
-- The gcd is unique.
unique : ∀ {d₁ d₂ m n} → GCD m n d₁ → GCD m n d₂ → d₁ ≡ d₂
unique d₁ d₂ = ∣-antisym (GCD.greatest d₂ (GCD.commonDivisor d₁))
(GCD.greatest d₁ (GCD.commonDivisor d₂))
-- The gcd relation is "symmetric".
sym : ∀ {d m n} → GCD m n d → GCD n m d
sym g = is (swap $ GCD.commonDivisor g) (GCD.greatest g ∘ swap)
-- The gcd relation is "reflexive".
refl : ∀ {n} → GCD n n n
refl = is (∣-refl , ∣-refl) proj₁
-- The GCD of 0 and n is n.
base : ∀ {n} → GCD 0 n n
base {n} = is (n ∣0 , ∣-refl) proj₂
-- If d is the gcd of n and k, then it is also the gcd of n and
-- n + k.
step : ∀ {n k d} → GCD n k d → GCD n (n + k) d
step g with GCD.commonDivisor g
step {n} {k} {d} g | (d₁ , d₂) = is (d₁ , ∣m∣n⇒∣m+n d₁ d₂) greatest′
where
greatest′ : ∀ {d′} → d′ ∣ n × d′ ∣ n + k → d′ ∣ d
greatest′ (d₁ , d₂) = GCD.greatest g (d₁ , ∣m+n∣m⇒∣n d₂ d₁)
open GCD public using (GCD) hiding (module GCD)
------------------------------------------------------------------------
-- Calculating the gcd
-- The calculation also proves Bézout's lemma.
module Bézout where
module Identity where
-- If m and n have greatest common divisor d, then one of the
-- following two equations is satisfied, for some numbers x and y.
-- The proof is "lemma" below (Bézout's lemma).
--
-- (If this identity was stated using integers instead of natural
-- numbers, then it would not be necessary to have two equations.)
data Identity (d m n : ℕ) : Set where
+- : (x y : ℕ) (eq : d + y * n ≡ x * m) → Identity d m n
-+ : (x y : ℕ) (eq : d + x * m ≡ y * n) → Identity d m n
-- Various properties about Identity.
sym : ∀ {d} → Symmetric (Identity d)
sym (+- x y eq) = -+ y x eq
sym (-+ x y eq) = +- y x eq
refl : ∀ {d} → Identity d d d
refl = -+ 0 1 P.refl
base : ∀ {d} → Identity d 0 d
base = -+ 0 1 P.refl
private
infixl 7 _⊕_
_⊕_ : ℕ → ℕ → ℕ
m ⊕ n = 1 + m + n
step : ∀ {d n k} → Identity d n k → Identity d n (n + k)
step {d} (+- x y eq) with compare x y
step {d} (+- .x .x eq) | equal x = +- (2 * x) x (lem₂ d x eq)
step {d} (+- .x .(x ⊕ i) eq) | less x i = +- (2 * x ⊕ i) (x ⊕ i) (lem₃ d x eq)
step {d} {n} (+- .(y ⊕ i) .y eq) | greater y i = +- (2 * y ⊕ i) y (lem₄ d y n eq)
step {d} (-+ x y eq) with compare x y
step {d} (-+ .x .x eq) | equal x = -+ (2 * x) x (lem₅ d x eq)
step {d} (-+ .x .(x ⊕ i) eq) | less x i = -+ (2 * x ⊕ i) (x ⊕ i) (lem₆ d x eq)
step {d} {n} (-+ .(y ⊕ i) .y eq) | greater y i = -+ (2 * y ⊕ i) y (lem₇ d y n eq)
open Identity public using (Identity; +-; -+) hiding (module Identity)
module Lemma where
-- This type packs up the gcd, the proof that it is a gcd, and the
-- proof that it satisfies Bézout's identity.
data Lemma (m n : ℕ) : Set where
result : (d : ℕ) (g : GCD m n d) (b : Identity d m n) → Lemma m n
-- Various properties about Lemma.
sym : Symmetric Lemma
sym (result d g b) = result d (GCD.sym g) (Identity.sym b)
base : ∀ d → Lemma 0 d
base d = result d GCD.base Identity.base
refl : ∀ d → Lemma d d
refl d = result d GCD.refl Identity.refl
stepˡ : ∀ {n k} → Lemma n (suc k) → Lemma n (suc (n + k))
stepˡ {n} {k} (result d g b) =
subst (Lemma n) (+-suc n k) $
result d (GCD.step g) (Identity.step b)
stepʳ : ∀ {n k} → Lemma (suc k) n → Lemma (suc (n + k)) n
stepʳ = sym ∘ stepˡ ∘ sym
open Lemma public using (Lemma; result) hiding (module Lemma)
-- Bézout's lemma proved using some variant of the extended
-- Euclidean algorithm.
lemma : (m n : ℕ) → Lemma m n
lemma m n = build [ <′-recBuilder ⊗ <′-recBuilder ] P gcd (m , n)
where
P : ℕ × ℕ → Set
P (m , n) = Lemma m n
gcd : ∀ p → (<′-Rec ⊗ <′-Rec) P p → P p
gcd (zero , n ) rec = Lemma.base n
gcd (suc m , zero ) rec = Lemma.sym (Lemma.base (suc m))
gcd (suc m , suc n ) rec with compare m n
gcd (suc m , suc .m ) rec | equal .m = Lemma.refl (suc m)
gcd (suc m , suc .(suc (m + k))) rec | less .m k =
-- "gcd (suc m) (suc k)"
Lemma.stepˡ $ proj₁ rec (suc k) (lem₁ k m)
gcd (suc .(suc (n + k)) , suc n) rec | greater .n k =
-- "gcd (suc k) (suc n)"
Lemma.stepʳ $ proj₂ rec (suc k) (lem₁ k n) (suc n)
-- Bézout's identity can be recovered from the GCD.
identity : ∀ {m n d} → GCD m n d → Identity d m n
identity {m} {n} g with lemma m n
... | result d g′ b with GCD.unique g g′
... | P.refl = b
-- Calculates the gcd of the arguments.
gcd : (m n : ℕ) → ∃ λ d → GCD m n d
gcd m n with Bézout.lemma m n
... | Bézout.result d g _ = (d , g)
-- gcd as a proposition is decidable
gcd? : (m n d : ℕ) → Dec (GCD m n d)
gcd? m n d with gcd m n
... | d′ , p with d′ ≟ d
... | no ¬g = no (¬g ∘ GCD.unique p)
... | yes g = yes (subst (GCD m n) g p)
| {
"alphanum_fraction": 0.5179102143,
"avg_line_length": 32.4517766497,
"ext": "agda",
"hexsha": "418b444311ad02b6946c0f08fdcfbdea94a6ad88",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Nat/GCD.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Nat/GCD.agda",
"max_line_length": 91,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Nat/GCD.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2231,
"size": 6393
} |
------------------------------------------------------------------------------
-- Properties of the Collatz function
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.Collatz.PropertiesI where
open import Common.FOL.Relation.Binary.EqReasoning
open import FOTC.Base
open import FOTC.Base.PropertiesI
open import FOTC.Data.Nat
open import FOTC.Data.Nat.PropertiesI
open import FOTC.Data.Nat.UnaryNumbers
open import FOTC.Data.Nat.UnaryNumbers.TotalityI
open import FOTC.Program.Collatz.Collatz
open import FOTC.Program.Collatz.Data.Nat
open import FOTC.Program.Collatz.Data.Nat.PropertiesI
------------------------------------------------------------------------------
collatzCong : ∀ {m n} → m ≡ n → collatz m ≡ collatz n
collatzCong refl = refl
helper : ∀ {n} → N n → collatz (2' ^ succ₁ n) ≡ collatz (2' ^ n)
helper nzero =
collatz (2' ^ 1') ≡⟨ collatzCong (x^1≡x 2-N) ⟩
collatz 2' ≡⟨ collatz-even 2-Even ⟩
collatz (div 2' 2') ≡⟨ collatzCong (div-x-x≡1 2-N S≢0) ⟩
collatz (1') ≡⟨ collatzCong (sym (^-0 2')) ⟩
collatz (2' ^ 0') ∎
helper (nsucc {n} Nn) =
collatz (2' ^ succ₁ (succ₁ n))
≡⟨ collatzCong prf ⟩
collatz (succ₁ (succ₁ (2' ^ succ₁ (succ₁ n) ∸ 2')))
≡⟨ collatz-even (x-Even→SSx-Even
(∸-N (^-N 2-N (nsucc (nsucc Nn))) 2-N)
(∸-Even (^-N 2-N (nsucc (nsucc Nn))) 2-N
(2^[x+1]-Even (nsucc Nn)) 2-Even)) ⟩
collatz (div (succ₁ (succ₁ ((2' ^ succ₁ (succ₁ n)) ∸ 2'))) 2')
≡⟨ collatzCong (divLeftCong (sym prf)) ⟩
collatz (div (2' ^ succ₁ (succ₁ n)) 2')
≡⟨ collatzCong (div-2^[x+1]-2≡2^x (nsucc Nn)) ⟩
collatz (2' ^ succ₁ n) ∎
where
prf : 2' ^ succ₁ (succ₁ n) ≡ succ₁ (succ₁ (2' ^ succ₁ (succ₁ n) ∸ 2'))
prf = (+∸2 (^-N 2-N (nsucc (nsucc Nn)))
(2^x≢0 (nsucc (nsucc Nn)))
(2^[x+1]≢1 (nsucc Nn)))
collatz-2^x : ∀ {n} → N n → collatz (2' ^ n) ≡ 1'
collatz-2^x nzero =
collatz (2' ^ 0') ≡⟨ collatzCong (^-0 2') ⟩
collatz 1' ≡⟨ collatz-1 ⟩
1' ∎
collatz-2^x (nsucc {n} Nn) =
collatz (2' ^ succ₁ n) ≡⟨ helper Nn ⟩
collatz (2' ^ n) ≡⟨ collatz-2^x Nn ⟩
1' ∎
| {
"alphanum_fraction": 0.4991680532,
"avg_line_length": 36.4242424242,
"ext": "agda",
"hexsha": "12d28ebf93e1652d4e8cc01df6c3534bacf69fda",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Program/Collatz/PropertiesI.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Program/Collatz/PropertiesI.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": "src/fot/FOTC/Program/Collatz/PropertiesI.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": 892,
"size": 2404
} |
{-# OPTIONS --without-K #-}
module sets.unit where
record ⊤ : Set where
constructor tt
⊤-elim : (P : ⊤ → Set) → P tt → (x : ⊤) → P x
⊤-elim P ptt tt = ptt
| {
"alphanum_fraction": 0.5465838509,
"avg_line_length": 16.1,
"ext": "agda",
"hexsha": "b4af1d1832676bb7d346943f53bb256a6e48ae19",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-02-26T06:17:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-11T17:19:12.000Z",
"max_forks_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "HoTT/M-types",
"max_forks_repo_path": "sets/unit.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_issues_repo_issues_event_max_datetime": "2015-02-11T15:20:34.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-11T11:14:59.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "HoTT/M-types",
"max_issues_repo_path": "sets/unit.agda",
"max_line_length": 45,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "HoTT/M-types",
"max_stars_repo_path": "sets/unit.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z",
"num_tokens": 64,
"size": 161
} |
-- Andreas, 2015-09-12
open import Common.Product
open import Common.Equality
module _ (A : Set) where
mutual
X : A × A → A
X = _
test : (x y : A × A) → X (proj₁ x , proj₁ y) ≡ proj₁ x
test _ _ = refl
-- This worked even before the fix of #1316,
-- since _ record variables are expanded (see #473).
| {
"alphanum_fraction": 0.6314102564,
"avg_line_length": 18.3529411765,
"ext": "agda",
"hexsha": "3c46d1935bb1439dc08ea8db72b873ec1cdfcec4",
"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/Issue1645.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/Issue1645.agda",
"max_line_length": 56,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue1645.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": 312
} |
------------------------------------------------------------------------
-- Some substitution lemmas
------------------------------------------------------------------------
open import Atom
module Substitution (atoms : χ-atoms) where
open import Equality.Propositional
open import Prelude hiding (const)
open import Bag-equivalence equality-with-J using (_∈_)
open import Chi atoms
open χ-atoms atoms
private
variable
c : Const
e e′ e″ : Exp
x y : Var
xs : List Var
-- Some simplification lemmas for the substitution functions.
var-step-≡ : x ≡ y → var y [ x ← e ] ≡ e
var-step-≡ {x = x} {y = y} x≡y with x V.≟ y
… | yes _ = refl
… | no x≢y = ⊥-elim (x≢y x≡y)
var-step-≢ : x ≢ y → var y [ x ← e ] ≡ var y
var-step-≢ {x = x} {y = y} x≢y with x V.≟ y
… | no _ = refl
… | yes x≡y = ⊥-elim (x≢y x≡y)
lambda-step-≡ : x ≡ y → lambda y e [ x ← e′ ] ≡ lambda y e
lambda-step-≡ {x = x} {y = y} x≡y with x V.≟ y
… | yes _ = refl
… | no x≢y = ⊥-elim (x≢y x≡y)
lambda-step-≢ :
x ≢ y → lambda y e [ x ← e′ ] ≡ lambda y (e [ x ← e′ ])
lambda-step-≢ {x = x} {y = y} x≢y with x V.≟ y
… | no _ = refl
… | yes x≡y = ⊥-elim (x≢y x≡y)
rec-step-≡ : x ≡ y → rec y e [ x ← e′ ] ≡ rec y e
rec-step-≡ {x = x} {y = y} x≡y with x V.≟ y
… | yes _ = refl
… | no x≢y = ⊥-elim (x≢y x≡y)
rec-step-≢ :
x ≢ y → rec y e [ x ← e′ ] ≡ rec y (e [ x ← e′ ])
rec-step-≢ {x = x} {y = y} x≢y with x V.≟ y
… | no _ = refl
… | yes x≡y = ⊥-elim (x≢y x≡y)
branch-step-∈ :
x ∈ xs →
branch c xs e [ x ← e′ ]B ≡ branch c xs e
branch-step-∈ {x = x} {xs = xs} x∈xs with V.member x xs
… | yes _ = refl
… | no x∉xs = ⊥-elim (x∉xs x∈xs)
branch-step-∉ :
¬ x ∈ xs →
branch c xs e [ x ← e′ ]B ≡ branch c xs (e [ x ← e′ ])
branch-step-∉ {x = x} {xs = xs} x∉xs with V.member x xs
… | no _ = refl
… | yes x∈xs = ⊥-elim (x∉xs x∈xs)
-- A "fusion" lemma.
mutual
fusion : ∀ e → e [ x ← e′ ] [ x ← e″ ] ≡ e [ x ← e′ [ x ← e″ ] ]
fusion (apply e₁ e₂) =
cong₂ apply (fusion e₁) (fusion e₂)
fusion {x = x} {e′ = e′} {e″ = e″} (lambda y e) with x V.≟ y
… | yes _ = refl
… | no _ =
lambda y (e [ x ← e′ ] [ x ← e″ ]) ≡⟨ cong (lambda _) $ fusion e ⟩∎
lambda y (e [ x ← e′ [ x ← e″ ] ]) ∎
fusion (case e bs) =
cong₂ case (fusion e) (fusion-B⋆ bs)
fusion {x = x} {e′ = e′} {e″ = e″} (rec y e) with x V.≟ y
… | yes _ = refl
… | no _ =
rec y (e [ x ← e′ ] [ x ← e″ ]) ≡⟨ cong (rec _) $ fusion e ⟩∎
rec y (e [ x ← e′ [ x ← e″ ] ]) ∎
fusion {x = x} {e″ = e″} (var y) with x V.≟ y
… | yes _ = refl
… | no x≢y =
var y [ x ← e″ ] ≡⟨ var-step-≢ x≢y ⟩∎
var y ∎
fusion (const c es) =
cong (const c) (fusion-⋆ es)
fusion-B :
∀ b → b [ x ← e′ ]B [ x ← e″ ]B ≡ b [ x ← e′ [ x ← e″ ] ]B
fusion-B {x = x} {e′ = e′} {e″ = e″} (branch c xs e)
with V.member x xs
… | yes x∈xs =
branch c xs e [ x ← e″ ]B ≡⟨ branch-step-∈ x∈xs ⟩∎
branch c xs e ∎
… | no x∉xs =
branch c xs (e [ x ← e′ ]) [ x ← e″ ]B ≡⟨ branch-step-∉ x∉xs ⟩
branch c xs (e [ x ← e′ ] [ x ← e″ ]) ≡⟨ cong (branch _ _) $ fusion e ⟩∎
branch c xs (e [ x ← e′ [ x ← e″ ] ]) ∎
fusion-⋆ :
∀ es → es [ x ← e′ ]⋆ [ x ← e″ ]⋆ ≡ es [ x ← e′ [ x ← e″ ] ]⋆
fusion-⋆ [] = refl
fusion-⋆ (e ∷ es) = cong₂ _∷_ (fusion e) (fusion-⋆ es)
fusion-B⋆ :
∀ bs → bs [ x ← e′ ]B⋆ [ x ← e″ ]B⋆ ≡ bs [ x ← e′ [ x ← e″ ] ]B⋆
fusion-B⋆ [] = refl
fusion-B⋆ (b ∷ bs) = cong₂ _∷_ (fusion-B b) (fusion-B⋆ bs)
| {
"alphanum_fraction": 0.4354148845,
"avg_line_length": 27.8333333333,
"ext": "agda",
"hexsha": "aac822ce4934eb4869ef1372d1a85a44b1987f2f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/chi",
"max_forks_repo_path": "src/Substitution.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_issues_repo_issues_event_max_datetime": "2020-06-08T11:08:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-05-21T23:29:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/chi",
"max_issues_repo_path": "src/Substitution.agda",
"max_line_length": 78,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/chi",
"max_stars_repo_path": "src/Substitution.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-20T16:27:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:07.000Z",
"num_tokens": 1610,
"size": 3507
} |
module Base where
postulate String : Set
Char : Set
{-# BUILTIN STRING String #-}
{-# BUILTIN CHAR Char #-}
data Unit : Set where
unit : Unit
{-# COMPILED_DATA Unit () #-}
data Bool : Set where
true : Bool
false : Bool
data False : Set where
record True : Set where
IsTrue : Bool -> Set
IsTrue true = True
IsTrue false = False
{-# COMPILED_DATA Bool True False #-}
infixr 40 _::_
data List (A : Set) : Set where
[] : List A
_::_ : A -> List A -> List A
{-# COMPILED_DATA List [] (:) #-}
data _×_ (A B : Set) : Set where
_,_ : A -> B -> A × B
{-# COMPILED_DATA _×_ (,) #-} | {
"alphanum_fraction": 0.5823817292,
"avg_line_length": 16.5675675676,
"ext": "agda",
"hexsha": "033ab393102d71e087c33df99983c8b493e5606d",
"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": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/fileIO/Base.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/outdated-and-incorrect/fileIO/Base.agda",
"max_line_length": 37,
"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/outdated-and-incorrect/fileIO/Base.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": 193,
"size": 613
} |
module Base.Partial where
open import Data.String using (String)
open import Base.Free using (Free)
record Partial (S : Set) (P : S → Set) : Set₁ where
field
undefined : {A : Set} → Free S P A
error : {A : Set} → String → Free S P A
open Partial ⦃ ... ⦄ public
| {
"alphanum_fraction": 0.625,
"avg_line_length": 23.3333333333,
"ext": "agda",
"hexsha": "3aafa1f5f52d4da2e59ea308ee41dadd824225d5",
"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/Partial.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/Partial.agda",
"max_line_length": 51,
"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/Partial.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": 87,
"size": 280
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- A bunch of properties
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Bool.Properties where
open import Algebra.Bundles
open import Data.Bool.Base
open import Data.Empty
open import Data.Product
open import Data.Sum.Base
open import Function.Base
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence
using (_⇔_; equivalence; module Equivalence)
open import Level using (Level; 0ℓ)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality hiding ([_])
open import Relation.Nullary using (ofʸ; ofⁿ; does; proof; yes; no)
open import Relation.Nullary.Decidable using (True)
import Relation.Unary as U
open import Algebra.Definitions {A = Bool} _≡_
open import Algebra.Structures {A = Bool} _≡_
open ≡-Reasoning
private
variable
a b : Level
A : Set a
B : Set b
------------------------------------------------------------------------
-- Properties of _≡_
infix 4 _≟_
_≟_ : Decidable {A = Bool} _≡_
true ≟ true = yes refl
false ≟ false = yes refl
true ≟ false = no λ()
false ≟ true = no λ()
≡-setoid : Setoid 0ℓ 0ℓ
≡-setoid = setoid Bool
≡-decSetoid : DecSetoid 0ℓ 0ℓ
≡-decSetoid = decSetoid _≟_
------------------------------------------------------------------------
-- Properties of _≤_
-- Relational properties
≤-reflexive : _≡_ ⇒ _≤_
≤-reflexive refl = b≤b
≤-refl : Reflexive _≤_
≤-refl = ≤-reflexive refl
≤-trans : Transitive _≤_
≤-trans b≤b p = p
≤-trans f≤t b≤b = f≤t
≤-antisym : Antisymmetric _≡_ _≤_
≤-antisym b≤b _ = refl
≤-minimum : Minimum _≤_ false
≤-minimum false = b≤b
≤-minimum true = f≤t
≤-maximum : Maximum _≤_ true
≤-maximum false = f≤t
≤-maximum true = b≤b
≤-total : Total _≤_
≤-total false b = inj₁ (≤-minimum b)
≤-total true b = inj₂ (≤-maximum b)
infix 4 _≤?_
_≤?_ : Decidable _≤_
false ≤? b = yes (≤-minimum b)
true ≤? false = no λ ()
true ≤? true = yes b≤b
≤-irrelevant : Irrelevant _≤_
≤-irrelevant {_} f≤t f≤t = refl
≤-irrelevant {false} b≤b b≤b = refl
≤-irrelevant {true} b≤b b≤b = refl
-- Structures
≤-isPreorder : IsPreorder _≡_ _≤_
≤-isPreorder = record
{ isEquivalence = isEquivalence
; reflexive = ≤-reflexive
; trans = ≤-trans
}
≤-isPartialOrder : IsPartialOrder _≡_ _≤_
≤-isPartialOrder = record
{ isPreorder = ≤-isPreorder
; antisym = ≤-antisym
}
≤-isTotalOrder : IsTotalOrder _≡_ _≤_
≤-isTotalOrder = record
{ isPartialOrder = ≤-isPartialOrder
; total = ≤-total
}
≤-isDecTotalOrder : IsDecTotalOrder _≡_ _≤_
≤-isDecTotalOrder = record
{ isTotalOrder = ≤-isTotalOrder
; _≟_ = _≟_
; _≤?_ = _≤?_
}
-- Bundles
≤-poset : Poset 0ℓ 0ℓ 0ℓ
≤-poset = record
{ isPartialOrder = ≤-isPartialOrder
}
≤-preorder : Preorder 0ℓ 0ℓ 0ℓ
≤-preorder = record
{ isPreorder = ≤-isPreorder
}
≤-totalOrder : TotalOrder 0ℓ 0ℓ 0ℓ
≤-totalOrder = record
{ isTotalOrder = ≤-isTotalOrder
}
≤-decTotalOrder : DecTotalOrder 0ℓ 0ℓ 0ℓ
≤-decTotalOrder = record
{ isDecTotalOrder = ≤-isDecTotalOrder
}
------------------------------------------------------------------------
-- Properties of _<_
-- Relational properties
<-irrefl : Irreflexive _≡_ _<_
<-irrefl refl ()
<-asym : Asymmetric _<_
<-asym f<t ()
<-trans : Transitive _<_
<-trans f<t ()
<-transʳ : Trans _≤_ _<_ _<_
<-transʳ b≤b f<t = f<t
<-transˡ : Trans _<_ _≤_ _<_
<-transˡ f<t b≤b = f<t
<-cmp : Trichotomous _≡_ _<_
<-cmp false false = tri≈ (λ()) refl (λ())
<-cmp false true = tri< f<t (λ()) (λ())
<-cmp true false = tri> (λ()) (λ()) f<t
<-cmp true true = tri≈ (λ()) refl (λ())
infix 4 _<?_
_<?_ : Decidable _<_
false <? false = no (λ())
false <? true = yes f<t
true <? _ = no (λ())
<-resp₂-≡ : _<_ Respects₂ _≡_
<-resp₂-≡ = subst (_ <_) , subst (_< _)
<-irrelevant : Irrelevant _<_
<-irrelevant f<t f<t = refl
-- Structures
<-isStrictPartialOrder : IsStrictPartialOrder _≡_ _<_
<-isStrictPartialOrder = record
{ isEquivalence = isEquivalence
; irrefl = <-irrefl
; trans = <-trans
; <-resp-≈ = <-resp₂-≡
}
<-isStrictTotalOrder : IsStrictTotalOrder _≡_ _<_
<-isStrictTotalOrder = record
{ isEquivalence = isEquivalence
; trans = <-trans
; compare = <-cmp
}
-- Bundles
<-strictPartialOrder : StrictPartialOrder 0ℓ 0ℓ 0ℓ
<-strictPartialOrder = record
{ isStrictPartialOrder = <-isStrictPartialOrder
}
<-strictTotalOrder : StrictTotalOrder 0ℓ 0ℓ 0ℓ
<-strictTotalOrder = record
{ isStrictTotalOrder = <-isStrictTotalOrder
}
------------------------------------------------------------------------
-- Properties of _∨_
∨-assoc : Associative _∨_
∨-assoc true y z = refl
∨-assoc false y z = refl
∨-comm : Commutative _∨_
∨-comm true true = refl
∨-comm true false = refl
∨-comm false true = refl
∨-comm false false = refl
∨-identityˡ : LeftIdentity false _∨_
∨-identityˡ _ = refl
∨-identityʳ : RightIdentity false _∨_
∨-identityʳ false = refl
∨-identityʳ true = refl
∨-identity : Identity false _∨_
∨-identity = ∨-identityˡ , ∨-identityʳ
∨-zeroˡ : LeftZero true _∨_
∨-zeroˡ _ = refl
∨-zeroʳ : RightZero true _∨_
∨-zeroʳ false = refl
∨-zeroʳ true = refl
∨-zero : Zero true _∨_
∨-zero = ∨-zeroˡ , ∨-zeroʳ
∨-inverseˡ : LeftInverse true not _∨_
∨-inverseˡ false = refl
∨-inverseˡ true = refl
∨-inverseʳ : RightInverse true not _∨_
∨-inverseʳ x = ∨-comm x (not x) ⟨ trans ⟩ ∨-inverseˡ x
∨-inverse : Inverse true not _∨_
∨-inverse = ∨-inverseˡ , ∨-inverseʳ
∨-idem : Idempotent _∨_
∨-idem false = refl
∨-idem true = refl
∨-sel : Selective _∨_
∨-sel false y = inj₂ refl
∨-sel true y = inj₁ refl
∨-isMagma : IsMagma _∨_
∨-isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = cong₂ _∨_
}
∨-magma : Magma 0ℓ 0ℓ
∨-magma = record
{ isMagma = ∨-isMagma
}
∨-isSemigroup : IsSemigroup _∨_
∨-isSemigroup = record
{ isMagma = ∨-isMagma
; assoc = ∨-assoc
}
∨-semigroup : Semigroup 0ℓ 0ℓ
∨-semigroup = record
{ isSemigroup = ∨-isSemigroup
}
∨-isBand : IsBand _∨_
∨-isBand = record
{ isSemigroup = ∨-isSemigroup
; idem = ∨-idem
}
∨-band : Band 0ℓ 0ℓ
∨-band = record
{ isBand = ∨-isBand
}
∨-isSemilattice : IsSemilattice _∨_
∨-isSemilattice = record
{ isBand = ∨-isBand
; comm = ∨-comm
}
∨-semilattice : Semilattice 0ℓ 0ℓ
∨-semilattice = record
{ isSemilattice = ∨-isSemilattice
}
∨-isMonoid : IsMonoid _∨_ false
∨-isMonoid = record
{ isSemigroup = ∨-isSemigroup
; identity = ∨-identity
}
∨-isCommutativeMonoid : IsCommutativeMonoid _∨_ false
∨-isCommutativeMonoid = record
{ isMonoid = ∨-isMonoid
; comm = ∨-comm
}
∨-commutativeMonoid : CommutativeMonoid 0ℓ 0ℓ
∨-commutativeMonoid = record
{ isCommutativeMonoid = ∨-isCommutativeMonoid
}
∨-isIdempotentCommutativeMonoid :
IsIdempotentCommutativeMonoid _∨_ false
∨-isIdempotentCommutativeMonoid = record
{ isCommutativeMonoid = ∨-isCommutativeMonoid
; idem = ∨-idem
}
∨-idempotentCommutativeMonoid : IdempotentCommutativeMonoid 0ℓ 0ℓ
∨-idempotentCommutativeMonoid = record
{ isIdempotentCommutativeMonoid = ∨-isIdempotentCommutativeMonoid
}
------------------------------------------------------------------------
-- Properties of _∧_
∧-assoc : Associative _∧_
∧-assoc true y z = refl
∧-assoc false y z = refl
∧-comm : Commutative _∧_
∧-comm true true = refl
∧-comm true false = refl
∧-comm false true = refl
∧-comm false false = refl
∧-identityˡ : LeftIdentity true _∧_
∧-identityˡ _ = refl
∧-identityʳ : RightIdentity true _∧_
∧-identityʳ false = refl
∧-identityʳ true = refl
∧-identity : Identity true _∧_
∧-identity = ∧-identityˡ , ∧-identityʳ
∧-zeroˡ : LeftZero false _∧_
∧-zeroˡ _ = refl
∧-zeroʳ : RightZero false _∧_
∧-zeroʳ false = refl
∧-zeroʳ true = refl
∧-zero : Zero false _∧_
∧-zero = ∧-zeroˡ , ∧-zeroʳ
∧-inverseˡ : LeftInverse false not _∧_
∧-inverseˡ false = refl
∧-inverseˡ true = refl
∧-inverseʳ : RightInverse false not _∧_
∧-inverseʳ x = ∧-comm x (not x) ⟨ trans ⟩ ∧-inverseˡ x
∧-inverse : Inverse false not _∧_
∧-inverse = ∧-inverseˡ , ∧-inverseʳ
∧-idem : Idempotent _∧_
∧-idem false = refl
∧-idem true = refl
∧-sel : Selective _∧_
∧-sel false y = inj₁ refl
∧-sel true y = inj₂ refl
∧-distribˡ-∨ : _∧_ DistributesOverˡ _∨_
∧-distribˡ-∨ true y z = refl
∧-distribˡ-∨ false y z = refl
∧-distribʳ-∨ : _∧_ DistributesOverʳ _∨_
∧-distribʳ-∨ x y z = begin
(y ∨ z) ∧ x ≡⟨ ∧-comm (y ∨ z) x ⟩
x ∧ (y ∨ z) ≡⟨ ∧-distribˡ-∨ x y z ⟩
x ∧ y ∨ x ∧ z ≡⟨ cong₂ _∨_ (∧-comm x y) (∧-comm x z) ⟩
y ∧ x ∨ z ∧ x ∎
∧-distrib-∨ : _∧_ DistributesOver _∨_
∧-distrib-∨ = ∧-distribˡ-∨ , ∧-distribʳ-∨
∨-distribˡ-∧ : _∨_ DistributesOverˡ _∧_
∨-distribˡ-∧ true y z = refl
∨-distribˡ-∧ false y z = refl
∨-distribʳ-∧ : _∨_ DistributesOverʳ _∧_
∨-distribʳ-∧ x y z = begin
(y ∧ z) ∨ x ≡⟨ ∨-comm (y ∧ z) x ⟩
x ∨ (y ∧ z) ≡⟨ ∨-distribˡ-∧ x y z ⟩
(x ∨ y) ∧ (x ∨ z) ≡⟨ cong₂ _∧_ (∨-comm x y) (∨-comm x z) ⟩
(y ∨ x) ∧ (z ∨ x) ∎
∨-distrib-∧ : _∨_ DistributesOver _∧_
∨-distrib-∧ = ∨-distribˡ-∧ , ∨-distribʳ-∧
∧-abs-∨ : _∧_ Absorbs _∨_
∧-abs-∨ true y = refl
∧-abs-∨ false y = refl
∨-abs-∧ : _∨_ Absorbs _∧_
∨-abs-∧ true y = refl
∨-abs-∧ false y = refl
∨-∧-absorptive : Absorptive _∨_ _∧_
∨-∧-absorptive = ∨-abs-∧ , ∧-abs-∨
∧-isMagma : IsMagma _∧_
∧-isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = cong₂ _∧_
}
∧-magma : Magma 0ℓ 0ℓ
∧-magma = record
{ isMagma = ∧-isMagma
}
∧-isSemigroup : IsSemigroup _∧_
∧-isSemigroup = record
{ isMagma = ∧-isMagma
; assoc = ∧-assoc
}
∧-semigroup : Semigroup 0ℓ 0ℓ
∧-semigroup = record
{ isSemigroup = ∧-isSemigroup
}
∧-isBand : IsBand _∧_
∧-isBand = record
{ isSemigroup = ∧-isSemigroup
; idem = ∧-idem
}
∧-band : Band 0ℓ 0ℓ
∧-band = record
{ isBand = ∧-isBand
}
∧-isSemilattice : IsSemilattice _∧_
∧-isSemilattice = record
{ isBand = ∧-isBand
; comm = ∧-comm
}
∧-semilattice : Semilattice 0ℓ 0ℓ
∧-semilattice = record
{ isSemilattice = ∧-isSemilattice
}
∧-isMonoid : IsMonoid _∧_ true
∧-isMonoid = record
{ isSemigroup = ∧-isSemigroup
; identity = ∧-identity
}
∧-isCommutativeMonoid : IsCommutativeMonoid _∧_ true
∧-isCommutativeMonoid = record
{ isMonoid = ∧-isMonoid
; comm = ∧-comm
}
∧-commutativeMonoid : CommutativeMonoid 0ℓ 0ℓ
∧-commutativeMonoid = record
{ isCommutativeMonoid = ∧-isCommutativeMonoid
}
∧-isIdempotentCommutativeMonoid :
IsIdempotentCommutativeMonoid _∧_ true
∧-isIdempotentCommutativeMonoid = record
{ isCommutativeMonoid = ∧-isCommutativeMonoid
; idem = ∧-idem
}
∧-idempotentCommutativeMonoid : IdempotentCommutativeMonoid 0ℓ 0ℓ
∧-idempotentCommutativeMonoid = record
{ isIdempotentCommutativeMonoid = ∧-isIdempotentCommutativeMonoid
}
∨-∧-isSemiring : IsSemiring _∨_ _∧_ false true
∨-∧-isSemiring = record
{ isSemiringWithoutAnnihilatingZero = record
{ +-isCommutativeMonoid = ∨-isCommutativeMonoid
; *-isMonoid = ∧-isMonoid
; distrib = ∧-distrib-∨
}
; zero = ∧-zero
}
∨-∧-isCommutativeSemiring
: IsCommutativeSemiring _∨_ _∧_ false true
∨-∧-isCommutativeSemiring = record
{ isSemiring = ∨-∧-isSemiring
; *-comm = ∧-comm
}
∨-∧-commutativeSemiring : CommutativeSemiring 0ℓ 0ℓ
∨-∧-commutativeSemiring = record
{ _+_ = _∨_
; _*_ = _∧_
; 0# = false
; 1# = true
; isCommutativeSemiring = ∨-∧-isCommutativeSemiring
}
∧-∨-isSemiring : IsSemiring _∧_ _∨_ true false
∧-∨-isSemiring = record
{ isSemiringWithoutAnnihilatingZero = record
{ +-isCommutativeMonoid = ∧-isCommutativeMonoid
; *-isMonoid = ∨-isMonoid
; distrib = ∨-distrib-∧
}
; zero = ∨-zero
}
∧-∨-isCommutativeSemiring
: IsCommutativeSemiring _∧_ _∨_ true false
∧-∨-isCommutativeSemiring = record
{ isSemiring = ∧-∨-isSemiring
; *-comm = ∨-comm
}
∧-∨-commutativeSemiring : CommutativeSemiring 0ℓ 0ℓ
∧-∨-commutativeSemiring = record
{ _+_ = _∧_
; _*_ = _∨_
; 0# = true
; 1# = false
; isCommutativeSemiring = ∧-∨-isCommutativeSemiring
}
∨-∧-isLattice : IsLattice _∨_ _∧_
∨-∧-isLattice = record
{ isEquivalence = isEquivalence
; ∨-comm = ∨-comm
; ∨-assoc = ∨-assoc
; ∨-cong = cong₂ _∨_
; ∧-comm = ∧-comm
; ∧-assoc = ∧-assoc
; ∧-cong = cong₂ _∧_
; absorptive = ∨-∧-absorptive
}
∨-∧-lattice : Lattice 0ℓ 0ℓ
∨-∧-lattice = record
{ isLattice = ∨-∧-isLattice
}
∨-∧-isDistributiveLattice : IsDistributiveLattice _∨_ _∧_
∨-∧-isDistributiveLattice = record
{ isLattice = ∨-∧-isLattice
; ∨-distribʳ-∧ = ∨-distribʳ-∧
}
∨-∧-distributiveLattice : DistributiveLattice 0ℓ 0ℓ
∨-∧-distributiveLattice = record
{ isDistributiveLattice = ∨-∧-isDistributiveLattice
}
∨-∧-isBooleanAlgebra : IsBooleanAlgebra _∨_ _∧_ not true false
∨-∧-isBooleanAlgebra = record
{ isDistributiveLattice = ∨-∧-isDistributiveLattice
; ∨-complementʳ = ∨-inverseʳ
; ∧-complementʳ = ∧-inverseʳ
; ¬-cong = cong not
}
∨-∧-booleanAlgebra : BooleanAlgebra 0ℓ 0ℓ
∨-∧-booleanAlgebra = record
{ isBooleanAlgebra = ∨-∧-isBooleanAlgebra
}
------------------------------------------------------------------------
-- Properties of _xor_
xor-is-ok : ∀ x y → x xor y ≡ (x ∨ y) ∧ not (x ∧ y)
xor-is-ok true y = refl
xor-is-ok false y = sym (∧-identityʳ _)
xor-∧-commutativeRing : CommutativeRing 0ℓ 0ℓ
xor-∧-commutativeRing = commutativeRing
where
import Algebra.Properties.BooleanAlgebra as BA
open BA ∨-∧-booleanAlgebra
open XorRing _xor_ xor-is-ok
------------------------------------------------------------------------
-- Miscellaneous other properties
not-involutive : Involutive not
not-involutive true = refl
not-involutive false = refl
not-injective : ∀ {x y} → not x ≡ not y → x ≡ y
not-injective {false} {false} nx≢ny = refl
not-injective {true} {true} nx≢ny = refl
not-¬ : ∀ {x y} → x ≡ y → x ≢ not y
not-¬ {true} refl ()
not-¬ {false} refl ()
¬-not : ∀ {x y} → x ≢ y → x ≡ not y
¬-not {true} {true} x≢y = ⊥-elim (x≢y refl)
¬-not {true} {false} _ = refl
¬-not {false} {true} _ = refl
¬-not {false} {false} x≢y = ⊥-elim (x≢y refl)
⇔→≡ : {x y z : Bool} → x ≡ z ⇔ y ≡ z → x ≡ y
⇔→≡ {true } {true } hyp = refl
⇔→≡ {true } {false} {true } hyp = sym (Equivalence.to hyp ⟨$⟩ refl)
⇔→≡ {true } {false} {false} hyp = Equivalence.from hyp ⟨$⟩ refl
⇔→≡ {false} {true } {true } hyp = Equivalence.from hyp ⟨$⟩ refl
⇔→≡ {false} {true } {false} hyp = sym (Equivalence.to hyp ⟨$⟩ refl)
⇔→≡ {false} {false} hyp = refl
T-≡ : ∀ {x} → T x ⇔ x ≡ true
T-≡ {false} = equivalence (λ ()) (λ ())
T-≡ {true} = equivalence (const refl) (const _)
T-not-≡ : ∀ {x} → T (not x) ⇔ x ≡ false
T-not-≡ {false} = equivalence (const refl) (const _)
T-not-≡ {true} = equivalence (λ ()) (λ ())
T-∧ : ∀ {x y} → T (x ∧ y) ⇔ (T x × T y)
T-∧ {true} {true} = equivalence (const (_ , _)) (const _)
T-∧ {true} {false} = equivalence (λ ()) proj₂
T-∧ {false} {_} = equivalence (λ ()) proj₁
T-∨ : ∀ {x y} → T (x ∨ y) ⇔ (T x ⊎ T y)
T-∨ {true} {_} = equivalence inj₁ (const _)
T-∨ {false} {true} = equivalence inj₂ (const _)
T-∨ {false} {false} = equivalence inj₁ [ id , id ]
T-irrelevant : U.Irrelevant T
T-irrelevant {true} _ _ = refl
T? : U.Decidable T
does (T? b) = b
proof (T? true ) = ofʸ _
proof (T? false) = ofⁿ λ()
T?-diag : ∀ b → T b → True (T? b)
T?-diag true _ = _
push-function-into-if : ∀ (f : A → B) x {y z} →
f (if x then y else z) ≡ (if x then f y else f z)
push-function-into-if _ true = refl
push-function-into-if _ false = refl
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 0.15
∧-∨-distˡ = ∧-distribˡ-∨
{-# WARNING_ON_USAGE ∧-∨-distˡ
"Warning: ∧-∨-distˡ was deprecated in v0.15.
Please use ∧-distribˡ-∨ instead."
#-}
∧-∨-distʳ = ∧-distribʳ-∨
{-# WARNING_ON_USAGE ∧-∨-distʳ
"Warning: ∧-∨-distʳ was deprecated in v0.15.
Please use ∧-distribʳ-∨ instead."
#-}
distrib-∧-∨ = ∧-distrib-∨
{-# WARNING_ON_USAGE distrib-∧-∨
"Warning: distrib-∧-∨ was deprecated in v0.15.
Please use ∧-distrib-∨ instead."
#-}
∨-∧-distˡ = ∨-distribˡ-∧
{-# WARNING_ON_USAGE ∨-∧-distˡ
"Warning: ∨-∧-distˡ was deprecated in v0.15.
Please use ∨-distribˡ-∧ instead."
#-}
∨-∧-distʳ = ∨-distribʳ-∧
{-# WARNING_ON_USAGE ∨-∧-distʳ
"Warning: ∨-∧-distʳ was deprecated in v0.15.
Please use ∨-distribʳ-∧ instead."
#-}
∨-∧-distrib = ∨-distrib-∧
{-# WARNING_ON_USAGE ∨-∧-distrib
"Warning: ∨-∧-distrib was deprecated in v0.15.
Please use ∨-distrib-∧ instead."
#-}
∨-∧-abs = ∨-abs-∧
{-# WARNING_ON_USAGE ∨-∧-abs
"Warning: ∨-∧-abs was deprecated in v0.15.
Please use ∨-abs-∧ instead."
#-}
∧-∨-abs = ∧-abs-∨
{-# WARNING_ON_USAGE ∧-∨-abs
"Warning: ∧-∨-abs was deprecated in v0.15.
Please use ∧-abs-∨ instead."
#-}
not-∧-inverseˡ = ∧-inverseˡ
{-# WARNING_ON_USAGE not-∧-inverseˡ
"Warning: not-∧-inverseˡ was deprecated in v0.15.
Please use ∧-inverseˡ instead."
#-}
not-∧-inverseʳ = ∧-inverseʳ
{-# WARNING_ON_USAGE not-∧-inverseʳ
"Warning: not-∧-inverseʳ was deprecated in v0.15.
Please use ∧-inverseʳ instead."
#-}
not-∧-inverse = ∧-inverse
{-# WARNING_ON_USAGE not-∧-inverse
"Warning: not-∧-inverse was deprecated in v0.15.
Please use ∧-inverse instead."
#-}
not-∨-inverseˡ = ∨-inverseˡ
{-# WARNING_ON_USAGE not-∨-inverseˡ
"Warning: not-∨-inverseˡ was deprecated in v0.15.
Please use ∨-inverseˡ instead."
#-}
not-∨-inverseʳ = ∨-inverseʳ
{-# WARNING_ON_USAGE not-∨-inverseʳ
"Warning: not-∨-inverseʳ was deprecated in v0.15.
Please use ∨-inverseʳ instead."
#-}
not-∨-inverse = ∨-inverse
{-# WARNING_ON_USAGE not-∨-inverse
"Warning: not-∨-inverse was deprecated in v0.15.
Please use ∨-inverse instead."
#-}
isCommutativeSemiring-∨-∧ = ∨-∧-isCommutativeSemiring
{-# WARNING_ON_USAGE isCommutativeSemiring-∨-∧
"Warning: isCommutativeSemiring-∨-∧ was deprecated in v0.15.
Please use ∨-∧-isCommutativeSemiring instead."
#-}
commutativeSemiring-∨-∧ = ∨-∧-commutativeSemiring
{-# WARNING_ON_USAGE commutativeSemiring-∨-∧
"Warning: commutativeSemiring-∨-∧ was deprecated in v0.15.
Please use ∨-∧-commutativeSemiring instead."
#-}
isCommutativeSemiring-∧-∨ = ∧-∨-isCommutativeSemiring
{-# WARNING_ON_USAGE isCommutativeSemiring-∧-∨
"Warning: isCommutativeSemiring-∧-∨ was deprecated in v0.15.
Please use ∧-∨-isCommutativeSemiring instead."
#-}
commutativeSemiring-∧-∨ = ∧-∨-commutativeSemiring
{-# WARNING_ON_USAGE commutativeSemiring-∧-∨
"Warning: commutativeSemiring-∧-∨ was deprecated in v0.15.
Please use ∧-∨-commutativeSemiring instead."
#-}
isBooleanAlgebra = ∨-∧-isBooleanAlgebra
{-# WARNING_ON_USAGE isBooleanAlgebra
"Warning: isBooleanAlgebra was deprecated in v0.15.
Please use ∨-∧-isBooleanAlgebra instead."
#-}
booleanAlgebra = ∨-∧-booleanAlgebra
{-# WARNING_ON_USAGE booleanAlgebra
"Warning: booleanAlgebra was deprecated in v0.15.
Please use ∨-∧-booleanAlgebra instead."
#-}
commutativeRing-xor-∧ = xor-∧-commutativeRing
{-# WARNING_ON_USAGE commutativeRing-xor-∧
"Warning: commutativeRing-xor-∧ was deprecated in v0.15.
Please use xor-∧-commutativeRing instead."
#-}
proof-irrelevance = T-irrelevant
{-# WARNING_ON_USAGE proof-irrelevance
"Warning: proof-irrelevance was deprecated in v0.15.
Please use T-irrelevant instead."
#-}
-- Version 1.0
T-irrelevance = T-irrelevant
{-# WARNING_ON_USAGE T-irrelevance
"Warning: T-irrelevance was deprecated in v1.0.
Please use T-irrelevant instead."
#-}
| {
"alphanum_fraction": 0.6129162666,
"avg_line_length": 24.8293601004,
"ext": "agda",
"hexsha": "09c588ebd806d47f73ca911639132dac46864bfb",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/Bool/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/Bool/Properties.agda",
"max_line_length": 73,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/Bool/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 8079,
"size": 19789
} |
------------------------------------------------------------------------
-- A definitional interpreter
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
module Lambda.Simplified.Delay-monad.Interpreter where
open import Equality.Propositional
open import Prelude
open import Monad equality-with-J
open import Vec.Function equality-with-J
open import Delay-monad
open import Delay-monad.Bisimilarity
open import Delay-monad.Monad
open import Lambda.Simplified.Syntax
open Closure Tm
------------------------------------------------------------------------
-- The interpreter
infix 10 _∙_
mutual
⟦_⟧ : ∀ {i n} → Tm n → Env n → Delay Value i
⟦ var x ⟧ ρ = return (ρ x)
⟦ ƛ t ⟧ ρ = return (ƛ t ρ)
⟦ t₁ · t₂ ⟧ ρ = ⟦ t₁ ⟧ ρ >>= λ v₁ →
⟦ t₂ ⟧ ρ >>= λ v₂ →
v₁ ∙ v₂
_∙_ : ∀ {i} → Value → Value → Delay Value i
ƛ t₁ ρ ∙ v₂ = later λ { .force → ⟦ t₁ ⟧ (cons v₂ ρ) }
------------------------------------------------------------------------
-- An example
-- The semantics of Ω is the non-terminating computation never.
Ω-loops : ∀ {i} → [ i ] ⟦ Ω ⟧ nil ∼ never
Ω-loops = later λ { .force → Ω-loops }
| {
"alphanum_fraction": 0.4681555004,
"avg_line_length": 25.7234042553,
"ext": "agda",
"hexsha": "902d4d8ba8de5f0312bebee12c256a9e6b7045dc",
"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/Lambda/Simplified/Delay-monad/Interpreter.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/Lambda/Simplified/Delay-monad/Interpreter.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/Lambda/Simplified/Delay-monad/Interpreter.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": 330,
"size": 1209
} |
module Serializer.VecBool where
open import Data.Fin hiding (_+_)
open import Data.Nat
open import Data.Vec
open import Data.Bool
open import Function using (_∘_ ; _$_ ; _∋_ ; id ; const)
open import Function.Bijection
open import Function.Injection
open import Function.Surjection
open import Function.Equality using (_⟶_ ; _⟨$⟩_ ; Π )
open import Function.LeftInverse hiding (_∘_)
open import Relation.Binary
open import Relation.Binary.EqReasoning
open import Relation.Binary.PropositionalEquality using (_≡_ ; refl ; cong ; setoid )
import Relation.Binary.Indexed as I
open import Serializer
open import Helper.Fin
open import Serializer.Bool
open Serializer.Serializer {{...}}
2^ : ℕ -> ℕ
2^ zero = 1
2^ (suc b) = 2 * 2^ b
--fromVec : ∀ {a n} {A : Set a} -> Vec A n -> Fin n
fromVec : ∀ {n} -> Vec Bool n -> Fin (2^ n)
fromVec {zero} [] = zero
fromVec {suc n} (x ∷ x₁) = × 2 (2^ n) (from x) (fromVec x₁)
toVec` : ∀ {n} -> Fin (2^ n) -> Vec Bool n
toVec` {zero} x = []
toVec` {suc n} x with ⨂ 2 (2^ n) x
toVec` {suc n} .(× 2 (2^ n) i j) | is× i j = (to i) ∷ (toVec` j)
vec-from-cong : ∀ {n} -> Setoid._≈_ (setoid (Vec Bool n)) I.=[ fromVec ]⇒ Setoid._≈_ (setoid (Fin (2^ n)))
vec-from-cong refl = refl
vec-from-preserves-eq : ∀ {n} -> setoid (Vec Bool n) ⟶ setoid (Fin (2^ n))
vec-from-preserves-eq = record { _⟨$⟩_ = fromVec ; cong = vec-from-cong }
vec-from-injective : ∀ {n} -> Injective (vec-from-preserves-eq {n})
vec-from-injective {zero} {[]} {[]} p with fromVec []
... | p2 = refl
vec-from-injective {suc n} {x ∷ x₁} {y ∷ y₁} p with (⨂ 2 (2^ n) (fromVec (x ∷ x₁))) | (⨂ 2 (2^ n) (fromVec (y ∷ y₁)))
... | a1 | b2 with vec-from-injective {n} {x₁} {y₁}
... | c with c (×-equal₁ {x₁ = (fromBool x)} {x₂ = (fromBool y)} p) | (×-equal₂ {x₁ = (fromBool x)} {x₂ = (fromBool y)} p)
... | p1 | p2 with from-bool-injective p2
vec-from-injective {suc n} {x ∷ x₁} {.x ∷ .x₁} p | a1 | b2 | c | refl | p2 | refl = refl
vec-from-surjective : ∀ {n} -> Surjective (vec-from-preserves-eq {n})
vec-from-surjective {n} = record { from = preserves-eq-inv ; right-inverse-of = (inv {n}) }
where
cong-inverse : ∀ {n} -> Setoid._≈_ (setoid (Fin (2^ n))) I.=[ toVec` ]⇒ Setoid._≈_ (setoid (Vec Bool n))
cong-inverse refl = refl
preserves-eq-inv : ∀ {n} -> setoid (Fin (2^ n)) ⟶ setoid (Vec Bool n)
preserves-eq-inv = record { _⟨$⟩_ = toVec` ; cong = cong-inverse }
inv : ∀ {n} -> (preserves-eq-inv {n}) RightInverseOf (vec-from-preserves-eq {n})
inv {zero} zero = refl
inv {zero} (suc ())
inv {suc n₁} x with ⨂ 2 (2^ n₁) x
inv {suc n₁} .(× 2 (2^ n₁) i j) | is× i j
rewrite (Surjective.right-inverse-of (Bijective.surjective (Bijection.bijective (bijection {Bool})))) i | (inv {n₁} j) = refl
| {
"alphanum_fraction": 0.6098360656,
"avg_line_length": 40.3676470588,
"ext": "agda",
"hexsha": "d4143e3f431b72a7273a1dc08b2f73d4c45cf623",
"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": "cb95986b772b7a01195619be5e8e590f2429c759",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mathijsb/generic-in-agda",
"max_forks_repo_path": "Serializer/VecBool.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "cb95986b772b7a01195619be5e8e590f2429c759",
"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": "mathijsb/generic-in-agda",
"max_issues_repo_path": "Serializer/VecBool.agda",
"max_line_length": 131,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "cb95986b772b7a01195619be5e8e590f2429c759",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mathijsb/generic-in-agda",
"max_stars_repo_path": "Serializer/VecBool.agda",
"max_stars_repo_stars_event_max_datetime": "2016-08-04T16:05:24.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-06-09T09:59:27.000Z",
"num_tokens": 1039,
"size": 2745
} |
{-# OPTIONS --without-K #-}
open import HoTT
module homotopy.PushoutComm where
-- How do I prevent [to] from being exported?
private
module _ {i j k} (s : Span {i} {j} {k}) where
open Span s
flip : Span
flip = span B A C g f
to : Pushout s → Pushout flip
to = To.f module M where
module To = PushoutRec right left (λ (c : C) → ! (glue c))
open M public
private
module _ {i j k} (s : Span {i} {j} {k}) where
to-to-flip : (x : Pushout (flip s)) → to s (to (flip s) x) == x
to-to-flip = Pushout-elim (λ _ → idp) (λ _ → idp)
(λ c → ↓-∘=idf-in (to s) (to (flip s))
(ap (to s) (ap (to (flip s)) (glue c)) =⟨ To.glue-β (flip s) c |in-ctx ap (to s) ⟩
ap (to s) (! (glue c)) =⟨ ap-! (to s) (glue c) ⟩
! (ap (to s) (glue c)) =⟨ To.glue-β s c |in-ctx ! ⟩
! (! (glue c)) =⟨ !-! (glue c) ⟩
glue c ∎))
module _ {i j k} (s : Span {i} {j} {k}) where
Pushout-comm : Pushout s ≃ Pushout (flip s)
Pushout-comm = equiv (to s) (to (flip s)) (to-to-flip s) (to-to-flip (flip s))
| {
"alphanum_fraction": 0.4990875912,
"avg_line_length": 27.4,
"ext": "agda",
"hexsha": "c65e70a7ad08ab058b11e68fc905b48ef6107c49",
"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/homotopy/PushoutComm.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/homotopy/PushoutComm.agda",
"max_line_length": 90,
"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/homotopy/PushoutComm.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 432,
"size": 1096
} |
module Extensions.ListFirstFunctional where
open import Prelude hiding (_⊔_)
open import Level
private
lemma : ∀ {a b} {A : Set a} {P : A → Set b} (decP : ∀ a → (Dec $ P a)) v {x y} →
any decP (x List.∷ v) ≡ yes (there {x = x} y) → ¬ P x
lemma decP v {x} {y} eq p with decP x
lemma decP v () p | yes _
lemma decP v eq p | no ¬p = ¬p p
-- first is functionally defined as the element matched by 'any'
First : ∀ {a b} {A : Set a} {P : A → Set b} (decP : ∀ a → (Dec $ P a)) → List A → Set (a ⊔ b)
First f v = ∃ λ m → any f v ≡ yes m
private
There : ∀ {a b} {A : Set a} {P : A → Set b} {f v} → (f : First {P = P} f v) → Set
There (here px , _) = ⊥
There (there _ , _) = ⊤
head-first : ∀ {a b} {A : Set a} {P : A → Set b} {f v} → First {P = P} f v → A
head-first (here {x} _ , _) = x
head-first (there {x} _ , _) = x
-- we can recover the negative evidence even though Any does not "save it" for there-instances
there⟶¬x' : ∀ {a b} {A : Set a} {P : A → Set b} {decP v} →
(f : First {P = P} decP v) → {x : There f} → ¬ P (head-first f)
there⟶¬x' (here px , proj₂) {x = ()}
there⟶¬x' {P = P} {decP = decP} (there {x = x'} {xs = xs} tail , proj₂) px with lemma decP xs
there⟶¬x' {P = P} {decP = decP} (there {x = x'} {xs = xs} tail , proj₂) px | ¬px = ¬px proj₂ px
| {
"alphanum_fraction": 0.5130305287,
"avg_line_length": 41.96875,
"ext": "agda",
"hexsha": "2e3ac8301d278f34f08820d90270c386b77aa02d",
"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/Extensions/ListFirstFunctional.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/Extensions/ListFirstFunctional.agda",
"max_line_length": 95,
"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/Extensions/ListFirstFunctional.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": 537,
"size": 1343
} |
------------------------------------------------------------------------------
-- Testing the translation of definitions
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module Definition07b where
open import Common.FOL
postulate
P : D → Set
-- We test the translation of a definition where we need to erase
-- proof terms.
foo : ∀ {a} → P a → P a → a ≡ a
foo {a} Pa₁ Pa₂ = bar
where
c : D
c = a
{-# ATP definition c #-}
postulate bar : c ≡ a
{-# ATP prove bar #-}
| {
"alphanum_fraction": 0.4410480349,
"avg_line_length": 24.5357142857,
"ext": "agda",
"hexsha": "27222d6e101d801ee0f2f78e6862830b2d8fc3e9",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z",
"max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/apia",
"max_forks_repo_path": "issues/Issue81/Definition07b.agda",
"max_issues_count": 121,
"max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/apia",
"max_issues_repo_path": "issues/Issue81/Definition07b.agda",
"max_line_length": 78,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/apia",
"max_stars_repo_path": "issues/Issue81/Definition07b.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z",
"num_tokens": 149,
"size": 687
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import homotopy.FinWedge
module homotopy.Bouquet where
Rose : ∀ {i} (I : Type i) → Type i
Rose I = BigWedge {A = I} (λ _ → ⊙S¹)
Bouquet-family : ∀ {i} (I : Type i) (m : ℕ) → (I → Ptd₀)
Bouquet-family I m _ = ⊙Sphere m
Bouquet : ∀ {i} (I : Type i) (m : ℕ) → Type i
Bouquet I m = BigWedge (Bouquet-family I m)
⊙Bouquet : ∀ {i} (I : Type i) (m : ℕ) → Ptd i
⊙Bouquet I m = ⊙BigWedge (Bouquet-family I m)
BouquetLift-family : ∀ {i} (I : Type i) (m : ℕ) → (I → Ptd i)
BouquetLift-family {i} I m _ = ⊙Lift {j = i} (⊙Sphere m)
BouquetLift : ∀ {i} (I : Type i) (m : ℕ) → Type i
BouquetLift {i} I m = BigWedge (BouquetLift-family I m)
⊙BouquetLift : ∀ {i} (I : Type i) (m : ℕ) → Ptd i
⊙BouquetLift {i} I m = ⊙BigWedge (BouquetLift-family I m)
FinBouquetLift-family : ∀ {i} (I m : ℕ) → (Fin I → Ptd i)
FinBouquetLift-family {i} I m _ = ⊙Lift {j = i} (⊙Sphere m)
⊙FinBouquetLift : ∀ {i} (I m : ℕ) → Ptd i
⊙FinBouquetLift I m = ⊙FinWedge (FinBouquetLift-family I m)
FinBouquet-family : (I m : ℕ) → (Fin I → Ptd₀)
FinBouquet-family I m _ = ⊙Sphere m
FinBouquet : (I m : ℕ) → Type₀
FinBouquet I m = FinWedge (FinBouquet-family I m)
⊙FinBouquet : (I m : ℕ) → Ptd₀
⊙FinBouquet I m = ⊙FinWedge (FinBouquet-family I m)
| {
"alphanum_fraction": 0.6089341693,
"avg_line_length": 29.6744186047,
"ext": "agda",
"hexsha": "21eaba1fcbd948f687b22b7c8e98dcd7fc6069b4",
"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/homotopy/Bouquet.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/homotopy/Bouquet.agda",
"max_line_length": 61,
"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/homotopy/Bouquet.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": 587,
"size": 1276
} |
module Data.Nat.Extra where
open import Data.Nat
open import Data.Bool
isZero : ℕ → Bool
isZero 0 = true
isZero (suc _) = false
| {
"alphanum_fraction": 0.7307692308,
"avg_line_length": 14.4444444444,
"ext": "agda",
"hexsha": "40af58dd8e2eabc63adbc5f03de4707eeb1f7fd0",
"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/Data/Nat/Extra.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/Data/Nat/Extra.agda",
"max_line_length": 27,
"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/Data/Nat/Extra.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": 42,
"size": 130
} |
module Tactic.Nat.Exp where
open import Prelude
Var = Nat
Env : Set → Set
Env Atom = Atom → Nat
infixl 6 _⟨+⟩_
infixl 7 _⟨*⟩_
data Exp (Atom : Set) : Set where
var : (x : Atom) → Exp Atom
lit : (n : Nat) → Exp Atom
_⟨+⟩_ _⟨*⟩_ : (e e₁ : Exp Atom) → Exp Atom
⟦_⟧e : ∀ {Atom} → Exp Atom → Env Atom → Nat
⟦ var x ⟧e ρ = ρ x
⟦ lit n ⟧e ρ = n
⟦ e₁ ⟨+⟩ e₂ ⟧e ρ = ⟦ e₁ ⟧e ρ + ⟦ e₂ ⟧e ρ
⟦ e₁ ⟨*⟩ e₂ ⟧e ρ = ⟦ e₁ ⟧e ρ * ⟦ e₂ ⟧e ρ
| {
"alphanum_fraction": 0.5148741419,
"avg_line_length": 18.2083333333,
"ext": "agda",
"hexsha": "4a327fa6a00ed5ae98e0a2f9cb9766ca3d7d9bd4",
"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/Tactic/Nat/Exp.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/Tactic/Nat/Exp.agda",
"max_line_length": 44,
"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/Tactic/Nat/Exp.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": 231,
"size": 437
} |
module DTGP.State where
open import Data.Product
infixl 1 _>>=_ _=<<_
data State (S A : Set) : Set where
state : (S → A × S) → State S A
runState : ∀ {S A} → State S A → S → A × S
runState (state f) = f
return : ∀ {S A} → A → State S A
return a = state (λ s → a , s)
_>>=_ : {S A B : Set} → State S A → (A → State S B) → State S B
state h >>= f = state λ s →
let a,newState = h s
stateg = f (proj₁ a,newState)
in
runState stateg (proj₂ a,newState)
_=<<_ : {S A B : Set} → (A → State S B) → State S A → State S B
f =<< stateh = stateh >>= f
| {
"alphanum_fraction": 0.550802139,
"avg_line_length": 22.44,
"ext": "agda",
"hexsha": "4cee58c2cdc13cac4749c2630e3907bbb84e7a66",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:53:14.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-04-17T02:02:58.000Z",
"max_forks_repo_head_hexsha": "31d79242908f2d80ea8e0c02931f4fdc5a3e5d1f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "larrytheliquid/dtgp",
"max_forks_repo_path": "src/DTGP/State.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "31d79242908f2d80ea8e0c02931f4fdc5a3e5d1f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/dtgp",
"max_issues_repo_path": "src/DTGP/State.agda",
"max_line_length": 63,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "31d79242908f2d80ea8e0c02931f4fdc5a3e5d1f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/dtgp",
"max_stars_repo_path": "src/DTGP/State.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-19T21:39:58.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-20T16:46:00.000Z",
"num_tokens": 217,
"size": 561
} |
open import Nat
open import Prelude
open import List
open import Hazelnut-core
module Hazelnut-checks where
-----------------------------------------------------------------------------
-- these theorems aren't listed in the draft, but have been discussed
-- since submission. broadly speaking, they act as sanity checks on the
-- rules. if these properties can't be proven for any extensions to the
-- language, then the rules are not good.
-----------------------------------------------------------------------------
-- movement doesn't change the term other than moving the focus around.
moveerase : {e e' : ê} {δ : direction} {t : τ̇} →
(e + move δ +>e e') →
(e ◆e) == (e' ◆e)
moveerase EMAscFirstChild = refl
moveerase EMAscParent1 = refl
moveerase EMAscParent2 = refl
moveerase EMAscNextSib = refl
moveerase EMAscPrevSib = refl
moveerase EMLamFirstChild = refl
moveerase EMLamParent = refl
moveerase EMPlusFirstChild = refl
moveerase EMPlusParent1 = refl
moveerase EMPlusParent2 = refl
moveerase EMPlusNextSib = refl
moveerase EMPlusPrevSib = refl
moveerase EMApFirstChild = refl
moveerase EMApParent1 = refl
moveerase EMApParent2 = refl
moveerase EMApNextSib = refl
moveerase EMApPrevSib = refl
moveerase EMFHoleFirstChild = refl
moveerase EMFHoleParent = refl
-- describes lists of action whose semantics are composable
data iterok : Set where
-- iterates a list of actions that can be composed
data iterate : iterok → ê → ê → Set where
--constructability
mutual
constructable1 : {Γ : ·ctx} {e : ê} {t : τ̇} →
(wt : Γ ⊢ (e ◆e) => t) →
Σ[ αs ∈ iterok ]
(Σ[ e' ∈ ê ] ((iterate αs (▹ <||> ◃) e') ×
((e ◆e) == (e' ◆e))))
constructable1 = {!!}
constructable2 : {Γ : ·ctx} {e : ê} {t : τ̇} →
(wt : Γ ⊢ (e ◆e) <= t) →
Σ[ αs ∈ iterok ]
(Σ[ e' ∈ ê ] ((iterate αs (▹ <||> ◃) e') ×
((e ◆e) == (e' ◆e))))
constructable2 = {!!}
--reachability
mutual
reachable1 : {Γ : ·ctx} {e e' : ê} {t : τ̇}
(wt : Γ ⊢ (e ◆e) <= t) →
(wt' : Γ ⊢ (e' ◆e) <= t) →
(p : (e ◆e) == (e' ◆e)) →
Σ[ αs ∈ iterok ] (iterate αs e e')
reachable1 = {!!}
reachable2 : {Γ : ·ctx} {e e' : ê} {t : τ̇}
(wt : Γ ⊢ (e ◆e) => t) →
(wt' : Γ ⊢ (e' ◆e) => t) →
(p : (e ◆e) == (e' ◆e)) →
Σ[ αs ∈ iterok ] (iterate αs e e')
reachable2 = {!!}
| {
"alphanum_fraction": 0.4871794872,
"avg_line_length": 34.9480519481,
"ext": "agda",
"hexsha": "3033241692107d6a9b0fe7c7479f72fcf1f5631c",
"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": "86a755ca6749e080f9a03287e34d1cda889f1edb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ivoysey/agda-tfp16",
"max_forks_repo_path": "Hazelnut-checks.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "86a755ca6749e080f9a03287e34d1cda889f1edb",
"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": "ivoysey/agda-tfp16",
"max_issues_repo_path": "Hazelnut-checks.agda",
"max_line_length": 79,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "86a755ca6749e080f9a03287e34d1cda889f1edb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ivoysey/agda-tfp16",
"max_stars_repo_path": "Hazelnut-checks.agda",
"max_stars_repo_stars_event_max_datetime": "2016-04-14T02:19:58.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-04-09T13:35:22.000Z",
"num_tokens": 861,
"size": 2691
} |
-- Typing contexts and environments
module Syntax.Context where
open import Syntax.Types
open import Relation.Binary using (IsPreorder)
open import Relation.Binary.PropositionalEquality hiding ([_])
open import Data.Sum
-- | Data types
-- A type judgement with temporal qualifiers:
-- a type is either inhabited now, or always
data Judgement : Set where
_now : Type -> Judgement
_always : Type -> Judgement
infixl 60 _now
infixl 60 _always
-- Typing context as a list of types
data Context : Set where
∙ : Context
_,_ : Context -> Judgement -> Context
infixl 50 _,_
-- | Context operations and predicates
-- Singleton context
[_] : Judgement -> Context
[ A ] = ∙ , A
-- Concatenation of contexts
_⌊⌋_ : Context -> Context -> Context
Γ ⌊⌋ ∙ = Γ
Γ ⌊⌋ (Γ′ , A) = (Γ ⌊⌋ Γ′) , A
infixl 45 _⌊⌋_
-- Type in the middle of a context
_⌊_⌋_ : Context -> Judgement -> Context -> Context
Γ ⌊ A ⌋ Γ′ = Γ , A ⌊⌋ Γ′
infixl 45 _⌊_⌋_
-- Stabilise the context by filtering out the stable types
_ˢ : Context -> Context
∙ ˢ = ∙
(Γ , A now) ˢ = Γ ˢ
(Γ , A always) ˢ = Γ ˢ , A always
infixl 60 _ˢ
-- Predicate for context membership
data _∈_ : Judgement -> Context -> Set where
top : ∀{Γ A} -> A ∈ Γ , A
pop : ∀{Γ A B} -> A ∈ Γ -> A ∈ Γ , B
infix 35 _∈_
-- Predicate for context subset relation
data _⊆_ : Context -> Context -> Set where
refl : ∀{Γ} -> Γ ⊆ Γ
keep : ∀{Γ Γ′ A} -> Γ ⊆ Γ′ -> Γ , A ⊆ Γ′ , A
drop : ∀{Γ Γ′ A} -> Γ ⊆ Γ′ -> Γ ⊆ Γ′ , A
infix 30 _⊆_
-- || Context lemmas
-- | Element and subcontext relations
-- Element of a subset is an element of a set.
∈-⊆-monotone : ∀{Γ Γ′ A} -> Γ ⊆ Γ′ -> A ∈ Γ -> A ∈ Γ′
∈-⊆-monotone refl e = e
∈-⊆-monotone (keep p) top = top
∈-⊆-monotone (keep p) (pop e) = pop (∈-⊆-monotone p e)
∈-⊆-monotone (drop p) e = pop (∈-⊆-monotone p e)
-- Subset relation is reflexive
⊆-refl-eq : ∀{Γ Γ′} -> Γ ≡ Γ′ -> Γ ⊆ Γ′
⊆-refl-eq refl = refl
-- Subset relation is transitive
⊆-trans : ∀{Γ Δ Ξ} -> Γ ⊆ Δ -> Δ ⊆ Ξ -> Γ ⊆ Ξ
⊆-trans refl c2 = c2
⊆-trans c1 refl = c1
⊆-trans c1 (drop c2) = drop (⊆-trans c1 c2)
⊆-trans (keep c1) (keep c2) = keep (⊆-trans c1 c2)
⊆-trans (drop c1) (keep c2) = drop (⊆-trans c1 c2)
-- Subset relation is a preorder
⊆-po : IsPreorder _≡_ _⊆_
⊆-po = record
{ isEquivalence = isEquivalence
; reflexive = ⊆-refl-eq
; trans = ⊆-trans
}
-- | Concatenation
-- Concatenation of two contexts is a superset of one of the contexts
Γ⊆Γ⌊⌋Δ : ∀(Γ Δ : Context) -> Γ ⊆ Γ ⌊⌋ Δ
Γ⊆Γ⌊⌋Δ Γ ∙ = refl
Γ⊆Γ⌊⌋Δ Γ (Δ , x) = drop (Γ⊆Γ⌊⌋Δ Γ Δ)
-- Concatenation of two contexts is associative
⌊⌋-assoc : ∀(Γ Δ Ξ : Context) -> (Γ ⌊⌋ Δ) ⌊⌋ Ξ ≡ Γ ⌊⌋ (Δ ⌊⌋ Ξ)
⌊⌋-assoc Γ Δ ∙ = refl
⌊⌋-assoc Γ Δ (Ξ , C) = cong (_, C) (⌊⌋-assoc Γ Δ Ξ)
-- Concatenation of two spliced contexts is associative
⌊A⌋-assoc : ∀(Γ Δ Ξ : Context) A B -> (Γ ⌊ A ⌋ Δ) ⌊ B ⌋ Ξ ≡ Γ ⌊ A ⌋ (Δ ⌊ B ⌋ Ξ)
⌊A⌋-assoc Γ Δ ∙ A B = refl
⌊A⌋-assoc Γ Δ (Ξ , C) A B = cong (_, C) (⌊A⌋-assoc Γ Δ Ξ A B)
-- | Stabilisation
-- Stabilised context is a subset of the full context
Γˢ⊆Γ : ∀ Γ -> Γ ˢ ⊆ Γ
Γˢ⊆Γ ∙ = refl
Γˢ⊆Γ (Γ , A now) = drop (Γˢ⊆Γ Γ)
Γˢ⊆Γ (Γ , A always) = keep (Γˢ⊆Γ Γ)
-- Stabilised spliced context is subset of full spliced context
Γˢ⊆Γ-mid : ∀ (Γ Γ′ : Context) {A} -> Γ ˢ ⌊ A ⌋ Γ′ ˢ ⊆ Γ ⌊ A ⌋ Γ′
Γˢ⊆Γ-mid Γ ∙ = keep (Γˢ⊆Γ Γ)
Γˢ⊆Γ-mid Γ (Γ′ , B now) = drop (Γˢ⊆Γ-mid Γ Γ′)
Γˢ⊆Γ-mid Γ (Γ′ , B always) = keep (Γˢ⊆Γ-mid Γ Γ′)
-- Stabilisation is idempotent
ˢ-idemp : ∀ Γ -> Γ ˢ ˢ ≡ Γ ˢ
ˢ-idemp ∙ = refl
ˢ-idemp (Γ , A now) = ˢ-idemp Γ
ˢ-idemp (Γ , A always) rewrite ˢ-idemp Γ = refl
-- Stabilisation preserves concatenation
ˢ-pres-⌊⌋ : ∀ (Γ Γ′ : Context) -> (Γ ⌊⌋ Γ′) ˢ ≡ Γ ˢ ⌊⌋ Γ′ ˢ
ˢ-pres-⌊⌋ Γ ∙ = refl
ˢ-pres-⌊⌋ Γ (Γ′ , A now) = ˢ-pres-⌊⌋ Γ Γ′
ˢ-pres-⌊⌋ Γ (Γ′ , A always) rewrite ˢ-pres-⌊⌋ Γ Γ′ = refl
-- Stabilisation preserves subcontext relation
ˢ-⊆-monotone : ∀{Γ Γ′} -> Γ ⊆ Γ′ -> Γ ˢ ⊆ Γ′ ˢ
ˢ-⊆-monotone refl = refl
ˢ-⊆-monotone (keep {Γ} {Γ′} {A now} s) = ˢ-⊆-monotone s
ˢ-⊆-monotone (keep {Γ} {Γ′} {A always} s) = keep (ˢ-⊆-monotone s)
ˢ-⊆-monotone (drop {Γ} {Γ′} {A now} s) = ˢ-⊆-monotone s
ˢ-⊆-monotone (drop {Γ} {Γ′} {A always} s) = drop (ˢ-⊆-monotone s)
-- The context of stable variables can be stabilised
ˢ-∈-always : ∀{Γ A} -> A always ∈ Γ -> A always ∈ Γ ˢ
ˢ-∈-always {.(_ , _ always)} top = top
ˢ-∈-always {Γ , B now} (pop e) = ˢ-∈-always e
ˢ-∈-always {Γ , B always} (pop e) = pop (ˢ-∈-always e)
-- | Other lemmas
-- If B ∈ Γ ⌊ A ⌋ Γ′ then either B is equal to A, or B is in Γ ⌊⌋ Γ′
var-disjoint : ∀(Γ Γ′ : Context) {A B} -> B ∈ Γ ⌊ A ⌋ Γ′ -> (B ≡ A) ⊎ (B ∈ Γ ⌊⌋ Γ′)
var-disjoint Γ ∙ top = inj₁ refl
var-disjoint Γ ∙ (pop e) = inj₂ e
var-disjoint Γ (Γ′ , C) top = inj₂ top
var-disjoint Γ (Γ′ , C) (pop e) with var-disjoint Γ Γ′ e
var-disjoint Γ (Γ′ , C) (pop e) | inj₁ B≡A = inj₁ B≡A
var-disjoint Γ (Γ′ , C) (pop e) | inj₂ y = inj₂ (pop y)
| {
"alphanum_fraction": 0.5718692165,
"avg_line_length": 29.2951807229,
"ext": "agda",
"hexsha": "6cee085a0d0a6968791a2b8bfb4b4a90554a6fd7",
"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": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DimaSamoz/temporal-type-systems",
"max_forks_repo_path": "src/Syntax/Context.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"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": "DimaSamoz/temporal-type-systems",
"max_issues_repo_path": "src/Syntax/Context.agda",
"max_line_length": 84,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DimaSamoz/temporal-type-systems",
"max_stars_repo_path": "src/Syntax/Context.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-04T09:33:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-05-31T20:37:04.000Z",
"num_tokens": 2445,
"size": 4863
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Prelude
open import LibraBFT.Base.Types
import LibraBFT.Yasm.Base as LYB
-- This module defines a model of a distributed system, parameterized by
-- SystemParameters, which establishes various application-dependent types,
-- handlers, etc. The model supports a set of peers executing handlers in
-- response to messages received; these handlers can update the peer's
-- local state and/or send additional messages. The model also enables
-- "cheat" steps, which can send arbitrary messages, except that they are
-- constrained to prevent a cheat step from introducing a new signature for
-- an "honest" public key. The module also contains some structures for
-- proving properties of executions of the modeled system.
module LibraBFT.Yasm.System
(ℓ-EC : Level)
(EpochConfig : Set ℓ-EC)
(epochId : EpochConfig → EpochId)
(authorsN : EpochConfig → ℕ)
(parms : LYB.SystemParameters ℓ-EC EpochConfig epochId authorsN)
where
data InitStatus : Set where
uninitd : InitStatus
initd : InitStatus
open import LibraBFT.Yasm.Base ℓ-EC EpochConfig epochId authorsN
open SystemParameters parms
open import LibraBFT.Yasm.AvailableEpochs PeerId ℓ-EC EpochConfig epochId authorsN
using (AvailableEpochs) renaming (lookup'' to EC-lookup)
import LibraBFT.Yasm.AvailableEpochs PeerId ℓ-EC EpochConfig epochId authorsN as AE
open import Util.FunctionOverride PeerId _≟PeerId_
open import LibraBFT.Base.PKCS
SenderMsgPair : Set
SenderMsgPair = PeerId × Msg
SentMessages : Set
SentMessages = List SenderMsgPair
-- The model supports sending messages that contain some fields that are
-- /not/ covered by the message's signature. Therefore, given a message
-- with a verifiable signature, it is possible for a propositionally
-- different message that verifies against the same signature to have been
-- sent before, which is captured by the following definition.
record MsgWithSig∈ (pk : PK)(sig : Signature)(pool : SentMessages) : Set where
constructor mkMsgWithSig∈
field
msgWhole : Msg
msgPart : Part
msg⊆ : msgPart ⊂Msg msgWhole
msgSender : PeerId
msg∈pool : (msgSender , msgWhole) ∈ pool
msgSigned : WithVerSig pk msgPart
msgSameSig : ver-signature msgSigned ≡ sig
open MsgWithSig∈ public
postulate -- TODO-1: prove it
MsgWithSig∈? : ∀ {pk} {sig} {pool} → Dec (MsgWithSig∈ pk sig pool)
MsgWithSig∈-++ʳ : ∀{pk sig pool ms} → MsgWithSig∈ pk sig pool → MsgWithSig∈ pk sig (ms ++ pool)
MsgWithSig∈-++ʳ {ms = pre} msig = record
{ msgWhole = msgWhole msig
; msgPart = msgPart msig
; msg⊆ = msg⊆ msig
; msg∈pool = Any-++ʳ pre (msg∈pool msig)
; msgSigned = msgSigned msig
; msgSameSig = msgSameSig msig
}
MsgWithSig∈-++ˡ : ∀{pk sig pool ms} → MsgWithSig∈ pk sig ms → MsgWithSig∈ pk sig (ms ++ pool)
MsgWithSig∈-++ˡ {ms = pre} msig = record
{ msgWhole = msgWhole msig
; msgPart = msgPart msig
; msg⊆ = msg⊆ msig
; msg∈pool = Any-++ˡ (msg∈pool msig)
; msgSigned = msgSigned msig
; msgSameSig = msgSameSig msig
}
MsgWithSig∈-transp : ∀{pk sig pool pool'}
→ (mws : MsgWithSig∈ pk sig pool)
→ (msgSender mws , msgWhole mws) ∈ pool'
→ MsgWithSig∈ pk sig pool'
MsgWithSig∈-transp msig ∈pool' = record
{ msgWhole = msgWhole msig
; msgPart = msgPart msig
; msg⊆ = msg⊆ msig
; msg∈pool = ∈pool'
; msgSigned = msgSigned msig
; msgSameSig = msgSameSig msig
}
-- * Forbidding the Forging of Signatures
--
-- Whenever our reasoning must involve digital signatures, it is standard
-- to talk about EUF-CMA resistant signature schemes. Informally, this captures
-- signatures schemes that cannot be compromised by certain adversaries.
-- Formally, it means that for any probabilistic-polynomial-time adversary 𝓐,
-- and some security parameter k:
--
-- Pr[ EUF-CMA(k) ] ≤ ε(k) for ε a negigible function.
--
-- EUF-CMA is defined as:
--
-- EUF-CMA(k): | O(m):
-- L ← ∅ | σ ← Sign(sk , m)
-- (pk, sk) ← Gen(k) | L ← L ∪ { m }
-- (m , σ) ← 𝓐ᴼ(pk) | return σ
-- return (Verify(pk, m, σ) ∧ m ∉ L) |
--
-- This says that 𝓐 cannot create a message that has /not yet been signed/ and
-- forge a signature for it. The list 'L' keeps track of the messages that 𝓐
-- asked to be signed by the oracle.
--
-- Because the probability of the adversary to win the EUF-CMA(k) game
-- approaches 0 as k increases; it is reasonable to assume that winning
-- the game is /impossible/ for realistic security parameters.
--
-- EUF-CMA security is incorporated into our model by constraining messages
-- sent by a cheat step to ensure that for every verifiably signed part of
-- such a message, if there is a signature on the part, then it is either for
-- a dishonest public key (in which cases it's secret key may have been leaked),
-- or a message has been sent with the same signature before (in which case the
-- signature is simply being "replayed" from a previous message).
--
-- Dishonest (or "cheat") messages are those that are not the result of
-- a /handle/ or /init/ call, but rather are the result of a /cheat/ step.
--
-- A part of a cheat message can contain a verifiable signature only if it
-- is for a dishonest public key, or a message with the same signature has
-- been sent before (a cheater can "reuse" an honest signature sent
-- before; it just can't produce a new one). Note that this constraint
-- precludes a peer sending a message that contains a new verifiable
-- signature for an honest PK, even if the PK is the peer's own PK for
-- some epoch (implying that the peer possesses the associated secret
-- key). In other words, a peer that is honest for a given epoch (by
-- virtue of being a member of that epoch and being assigned an honest PK
-- for the epoch), cannot send a message for that epoch using a cheat
-- step.
CheatPartConstraint : SentMessages → Part → Set
CheatPartConstraint pool m = ∀{pk} → (ver : WithVerSig pk m)
→ Meta-Dishonest-PK pk
⊎ MsgWithSig∈ pk (ver-signature ver) pool
-- The only constraints on messages sent by cheat steps are that:
-- * the sender is not an honest member in the epoch of any part of the message
-- * the signature on any part of the message satisfies CheatCanSign, meaning
-- that it is not a new signature for an honest public key
CheatMsgConstraint : SentMessages → Msg → Set
CheatMsgConstraint pool m = ∀{part} → part ⊂Msg m → CheatPartConstraint pool part
-- * The System State
--
-- A system consists in a partial map from PeerId to PeerState, a pool
-- of sent messages and a number of available epochs.
record SystemState (e : ℕ) : Set ℓ-EC where
field
peerStates : PeerId → PeerState
initialised : PeerId → InitStatus
msgPool : SentMessages -- All messages ever sent
availEpochs : AvailableEpochs e
open SystemState public
initialState : SystemState 0
initialState = record
{ peerStates = const initPS
; initialised = const uninitd
; msgPool = []
; availEpochs = []
}
-- Convenience function for appending an epoch to the system state
pushEpoch : ∀{e} → EpochConfigFor e → SystemState e → SystemState (suc e)
pushEpoch 𝓔 st = record
{ peerStates = peerStates st
; initialised = initialised st
; msgPool = msgPool st
; availEpochs = AE.append 𝓔 (availEpochs st)
}
-- * Small Step Semantics
--
-- The small step semantics are divided into three datatypes:
--
-- i) StepPeerState executes a step through init or handle
-- ii) StepPeer executes a step through StepPeerState or cheat
-- iii) Step transitions the system state by a StepPeer or by
-- bringing a new epoch into existence
-- The pre and post states of Honest peers are related iff
data StepPeerState {e}(pid : PeerId)(𝓔s : AvailableEpochs e)(pool : SentMessages)
(peerInits : PeerId → InitStatus) (ps : PeerState) :
(PeerId → InitStatus) → (PeerState × List Msg) → Set where
-- The peer receives an "initialization package"; for now, this consists
-- of the actual EpochConfig for the epoch being initialized. Later, we
-- may move to a more general scheme, enabled by assuming a function
-- 'render : InitPackage -> EpochConfig'.
step-init : ∀ (ix : Fin e)
→ StepPeerState pid 𝓔s pool peerInits ps ⟦ peerInits , pid ← initd ⟧ (init pid (AE.lookup' 𝓔s ix) ps)
-- The peer processes a message in the pool
step-msg : ∀{m}
→ m ∈ pool
→ peerInits pid ≡ initd
→ StepPeerState pid 𝓔s pool peerInits ps peerInits (handle pid (proj₂ m) ps)
-- The pre-state of the suplied PeerId is related to the post-state and list of output messages iff:
data StepPeer {e}(pre : SystemState e) : PeerId → PeerState → List Msg → Set where
-- it can be obtained by a handle or init call.
step-honest : ∀{pid st outs init'}
→ StepPeerState pid (availEpochs pre) (msgPool pre) (initialised pre) (peerStates pre pid) init' (st , outs)
→ StepPeer pre pid st outs
-- or the peer decides to cheat. CheatMsgConstraint ensures it cannot
-- forge signatures by honest peers. Cheat steps do not modify peer
-- state: these are maintained exclusively by the implementation
-- handlers.
step-cheat : ∀{pid}
→ (fm : SentMessages → PeerState → Msg)
→ let m = fm (msgPool pre) (peerStates pre pid)
in CheatMsgConstraint (msgPool pre) m
→ StepPeer pre pid (peerStates pre pid) (m ∷ [])
isCheat : ∀ {e pre pid ms outs} → StepPeer {e} pre pid ms outs → Set
isCheat (step-honest _) = ⊥
isCheat (step-cheat _ _) = Unit
-- Computes the post-sysstate for a given step-peer.
StepPeer-post : ∀{e pid st' outs}{pre : SystemState e}
→ StepPeer pre pid st' outs → SystemState e
StepPeer-post {e} {pid} {st'} {outs} {pre} _ = record pre
{ peerStates = ⟦ peerStates pre , pid ← st' ⟧
; msgPool = List-map (pid ,_) outs ++ msgPool pre
}
StepPeer-post-lemma : ∀{e pid st' outs}{pre : SystemState e}
→ (pstep : StepPeer pre pid st' outs)
→ st' ≡ peerStates (StepPeer-post pstep) pid
StepPeer-post-lemma pstep = sym override-target-≡
cheatStepDNMPeerStates : ∀{e pid st' outs}{pre : SystemState e}
→ (theStep : StepPeer pre pid st' outs)
→ isCheat theStep
→ peerStates (StepPeer-post theStep) ≡ peerStates pre
cheatStepDNMPeerStates {pid = pid} {pre = pre} (step-cheat _ _) _
= overrideSameVal-correct-ext {f = peerStates pre} {pid}
cheatStepDNMPeerStates₁ : ∀{e pid pid' st' outs}{pre : SystemState e}
→ (theStep : StepPeer pre pid st' outs)
→ isCheat theStep
→ peerStates (StepPeer-post theStep) pid' ≡ peerStates pre pid'
cheatStepDNMPeerStates₁ {_} {pid} {pid'} (step-cheat fm x₁) x
= overrideSameVal-correct pid pid'
data Step : ∀{e e'} → SystemState e → SystemState e' → Set ℓ-EC where
step-epoch : ∀{e}{pre : SystemState e}
→ (𝓔 : EpochConfigFor e)
-- TODO-3: Eventually, we'll condition this step to only be
-- valid when peers on the previous epoch have agreed that 𝓔
-- is the new one. → ∃EnoughValidCommitMsgsFor pre 𝓔
→ Step pre (pushEpoch 𝓔 pre)
step-peer : ∀{e pid st' outs}{pre : SystemState e}
→ (pstep : StepPeer pre pid st' outs)
→ Step pre (StepPeer-post pstep)
msgs-stable : ∀ {e e'} {pre : SystemState e} {post : SystemState e'} {m}
→ (theStep : Step pre post)
→ m ∈ msgPool pre
→ m ∈ msgPool post
msgs-stable (step-epoch _) m∈ = m∈
msgs-stable (step-peer {pid = pid} {outs = outs} _) m∈ = Any-++ʳ (List-map (pid ,_) outs) m∈
peersRemainInitialized : ∀ {pid} {e e'} {pre : SystemState e} {post : SystemState e'}
→ (theStep : Step pre post)
→ initialised pre pid ≡ initd
→ initialised post pid ≡ initd
peersRemainInitialized (step-epoch _) isInitd = isInitd
peersRemainInitialized {pid} (step-peer step) isInitd
with step
... | step-cheat _ _ = isInitd
... | step-honest {pidS} {st} {outs} stp
with pid ≟PeerId pidS
...| yes refl = isInitd
...| no imp = isInitd
-- not used yet, but some proofs could probably be cleaned up using this,
-- e.g., prevVoteRnd≤-pred-step in Impl.VotesOnce
sendMessages-target : ∀ {m : SenderMsgPair} {sm : SentMessages} {ml : List SenderMsgPair}
→ ¬ (m ∈ sm)
→ m ∈ (ml ++ sm)
→ m ∈ ml
sendMessages-target {ml = ml} ¬m∈sm m∈++
with Any-++⁻ ml m∈++
...| inj₁ m∈ml = m∈ml
...| inj₂ m∈sm = ⊥-elim (¬m∈sm m∈sm)
step-epoch-does-not-send : ∀ {e} (pre : SystemState e) (𝓔 : EpochConfigFor e)
→ msgPool (pushEpoch 𝓔 pre) ≡ msgPool pre
step-epoch-does-not-send _ _ = refl
-- * Reflexive-Transitive Closure
data Step* : ∀{e e'} → SystemState e → SystemState e' → Set ℓ-EC where
step-0 : ∀{e}{pre : SystemState e}
→ Step* pre pre
step-s : ∀{e e' e''}{fst : SystemState e}{pre : SystemState e'}{post : SystemState e''}
→ Step* fst pre
→ Step pre post
→ Step* fst post
ReachableSystemState : ∀{e} → SystemState e → Set ℓ-EC
ReachableSystemState = Step* initialState
eventProcessorPostSt : ∀ {pid s' s outs init'} {e} {st : SystemState e}
→ (r : ReachableSystemState st)
→ (stP : StepPeerState pid (availEpochs st) (msgPool st) (initialised st)
(peerStates st pid) init' (s' , outs))
→ peerStates (StepPeer-post {pre = st} (step-honest stP)) pid ≡ s
→ s ≡ s'
eventProcessorPostSt _ _ ps≡s = trans (sym ps≡s) override-target-≡
Step*-mono : ∀{e e'}{st : SystemState e}{st' : SystemState e'}
→ Step* st st' → e ≤ e'
Step*-mono step-0 = ≤-refl
Step*-mono (step-s tr (step-peer _)) = Step*-mono tr
Step*-mono (step-s tr (step-epoch _)) = ≤-step (Step*-mono tr)
MsgWithSig∈-Step* : ∀{e e' sig pk}{st : SystemState e}{st' : SystemState e'}
→ Step* st st'
→ MsgWithSig∈ pk sig (msgPool st)
→ MsgWithSig∈ pk sig (msgPool st')
MsgWithSig∈-Step* step-0 msig = msig
MsgWithSig∈-Step* (step-s tr (step-epoch _)) msig
= MsgWithSig∈-Step* tr msig
MsgWithSig∈-Step* (step-s tr (step-peer ps)) msig
= MsgWithSig∈-++ʳ (MsgWithSig∈-Step* tr msig)
MsgWithSig∈-Step*-part : ∀{e e' sig pk}{st : SystemState e}{st' : SystemState e'}
→ (tr : Step* st st')
→ (msig : MsgWithSig∈ pk sig (msgPool st))
→ msgPart msig ≡ msgPart (MsgWithSig∈-Step* tr msig)
MsgWithSig∈-Step*-part step-0 msig = refl
MsgWithSig∈-Step*-part (step-s tr (step-epoch _)) msig
= MsgWithSig∈-Step*-part tr msig
MsgWithSig∈-Step*-part (step-s tr (step-peer ps)) msig
= MsgWithSig∈-Step*-part tr msig
MsgWithSig∈-Step*-sender : ∀{e e' sig pk}{st : SystemState e}{st' : SystemState e'}
→ (tr : Step* st st')
→ (msig : MsgWithSig∈ pk sig (msgPool st))
→ msgSender msig ≡ msgSender (MsgWithSig∈-Step* tr msig)
MsgWithSig∈-Step*-sender step-0 msig = refl
MsgWithSig∈-Step*-sender (step-s tr (step-epoch _)) msig
= MsgWithSig∈-Step*-sender tr msig
MsgWithSig∈-Step*-sender (step-s tr (step-peer ps)) msig
= MsgWithSig∈-Step*-sender tr msig
------------------------------------------
-- Type synonym to express a relation over system states;
SystemStateRel : (∀{e e'} → SystemState e → SystemState e' → Set ℓ-EC) → Set (ℓ+1 ℓ-EC)
SystemStateRel P = ∀{e e'}{st : SystemState e}{st' : SystemState e'} → P st st' → Set ℓ-EC
-- Just like Data.List.Any maps a predicate over elements to a predicate over lists,
-- Any-step maps a relation over steps to a relation over steps in a trace.
data Any-Step (P : SystemStateRel Step) : SystemStateRel Step* where
step-here : ∀{e e' e''}{fst : SystemState e}{pre : SystemState e'}{post : SystemState e''}
→ (cont : Step* fst pre)
→ {this : Step pre post}(prf : P this)
→ Any-Step P (step-s cont this)
step-there : ∀{e e' e''}{fst : SystemState e}{pre : SystemState e'}{post : SystemState e''}
→ {cont : Step* fst pre}
→ {this : Step pre post}
→ (prf : Any-Step P cont)
→ Any-Step P (step-s cont this)
Any-Step-⇒ : ∀ {P Q : SystemStateRel Step}
→ (∀ {e e'}{pre : SystemState e}{post : SystemState e'} → (x : Step pre post) → P {e} {e'} x → Q {e} {e'} x)
→ ∀ {e e' fst lst} {tr : Step* {e} {e'} fst lst}
→ Any-Step P tr
→ Any-Step Q tr
Any-Step-⇒ p⇒q (step-here cont {this} prf) = step-here cont (p⇒q this prf)
Any-Step-⇒ p⇒q (step-there anyStep) = step-there (Any-Step-⇒ p⇒q anyStep)
Any-Step-elim
: ∀{e₀ e₁}{st₀ : SystemState e₀}{st₁ : SystemState e₁}{P : SystemStateRel Step}{Q : Set ℓ-EC}
→ {r : Step* st₀ st₁}
→ (P⇒Q : ∀{d d'}{s : SystemState d}{s' : SystemState d'}{st : Step s s'}
→ P st → Step* s' st₁ → Q)
→ Any-Step P r → Q
Any-Step-elim P⇒Q (step-here cont prf)
= P⇒Q prf step-0
Any-Step-elim P⇒Q (step-there {this = this} f)
= Any-Step-elim (λ p s → P⇒Q p (step-s s this)) f
------------------------------------------
module _ (P : ∀{e} → SystemState e → Set) where
Step*-Step-fold : (∀{e}{st : SystemState e}
→ ReachableSystemState st
→ (𝓔 : EpochConfigFor e)
→ P st
→ P (pushEpoch 𝓔 st))
→ (∀{e pid st' outs}{st : SystemState e}
→ ReachableSystemState st
→ (pstep : StepPeer st pid st' outs)
→ P st
→ P (StepPeer-post pstep))
→ P initialState
→ ∀{e}{st : SystemState e}
→ (tr : ReachableSystemState st) → P st
Step*-Step-fold fe fs p₀ step-0 = p₀
Step*-Step-fold fe fs p₀ (step-s tr (step-epoch 𝓔)) = fe tr 𝓔 (Step*-Step-fold fe fs p₀ tr)
Step*-Step-fold fe fs p₀ (step-s tr (step-peer p)) = fs tr p (Step*-Step-fold fe fs p₀ tr)
| {
"alphanum_fraction": 0.6109979633,
"avg_line_length": 44.6363636364,
"ext": "agda",
"hexsha": "4aed98737d2fd903b59c1c48c0f76673612034b3",
"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": "34e4627855fb198665d0c98f377403a906ba75d7",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "haroldcarr/bft-consensus-agda",
"max_forks_repo_path": "LibraBFT/Yasm/System.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "34e4627855fb198665d0c98f377403a906ba75d7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "haroldcarr/bft-consensus-agda",
"max_issues_repo_path": "LibraBFT/Yasm/System.agda",
"max_line_length": 123,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "34e4627855fb198665d0c98f377403a906ba75d7",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "haroldcarr/bft-consensus-agda",
"max_stars_repo_path": "LibraBFT/Yasm/System.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5583,
"size": 19149
} |
open import Data.Bool hiding (if_then_else_)
open import Data.Empty
open import Data.List
open import Data.List.Properties
open import Data.Maybe
open import Data.Product
open import Data.Sum
open import Data.Unit
open import Relation.Binary.PropositionalEquality hiding (Extensionality ; [_])
open import Relation.Nullary
open import Relation.Nullary.Negation
module EffectAnnotations where
open import Axiom.Extensionality.Propositional
open import Axiom.UniquenessOfIdentityProofs
-- ASSUMING FUNCTION EXTENSIONALITY
postulate
fun-ext : ∀ {a b} → Extensionality a b
ifun-ext : ∀ {a b} → ExtensionalityImplicit a b
-- SIGNAL AND INTERRUPT NAMES
postulate Σₛ : Set
-- SIGNAL AND INTERRUPT NAMES HAVE DECIDABLE EQUALITY
postulate decₛ : (op op' : Σₛ) → Dec (op ≡ op')
if_≡_then_else_ : {A : Set} → Σₛ → Σₛ → A → A → A
if op ≡ op' then x else y with decₛ op op'
... | yes p = x
... | no ¬p = y
ite-≡ : {A : Set}
{op : Σₛ}
{x y : A} →
-----------------------------
if op ≡ op then x else y ≡ x
ite-≡ {A} {op} with decₛ op op
ite-≡ {A} {op} | yes p =
refl
ite-≡ {A} {op} | no ¬p =
⊥-elim (¬p refl)
ite-≢ : {A : Set}
{op op' : Σₛ}
{x y : A} →
op ≢ op' →
------------------------------
if op ≡ op' then x else y ≡ y
ite-≢ {A} {op} {op'} p with decₛ op op'
ite-≢ {A} {op} {op'} p | yes q =
⊥-elim (p q)
ite-≢ {A} {op} {op'} p | no ¬q =
refl
-- EFFECT ANNOTATIONS FOR OUTGOING SIGNALS (O) AND INTERRUPT HANDLERS (I)
mutual
data O : Set where
omap : (Σₛ → Maybe ⊤) → O
data I : Set where
imap : (Σₛ → Maybe (O × I)) → I
-- EMPTY EFFECT ANNOTATIONS
∅ₒ : O
∅ₒ = omap (λ _ → nothing)
∅ᵢ : I
∅ᵢ = imap (λ _ → nothing)
-- UNION OF EFFECT ANNOTATIONS
∪ₒ-aux' : (o o' : Maybe ⊤) → Maybe ⊤
∪ₒ-aux' nothing o' = o'
∪ₒ-aux' (just tt) o' = just tt
∪ₒ-aux : (o o' : Σₛ → Maybe ⊤) → Σₛ → Maybe ⊤
∪ₒ-aux o o' op =
∪ₒ-aux' (o op) (o' op)
_∪ₒ_ : O → O → O
(omap o) ∪ₒ (omap o') =
omap (∪ₒ-aux o o')
mutual
∪ᵢ-aux : (i i' : Σₛ → Maybe (O × I)) → Σₛ → Maybe (O × I)
∪ᵢ-aux i i' op =
∪ᵢ-aux' (i op) (i' op)
∪ᵢ-aux' : (oi oi' : Maybe (O × I)) → Maybe (O × I)
∪ᵢ-aux' nothing oi' =
oi'
∪ᵢ-aux' (just oi'') nothing =
just oi''
∪ᵢ-aux' (just (o'' , (imap i''))) (just (o''' , (imap i'''))) =
just (o'' ∪ₒ o''' , imap (∪ᵢ-aux i'' i'''))
_∪ᵢ_ : I → I → I
(imap i) ∪ᵢ (imap i') =
imap (∪ᵢ-aux i i')
-- SETTING THE VALUE OF EFFECT ANNOTATION AT A SPECIFIC INTERRUPT NAME
_[_↦_]ᵢ : I → Σₛ → Maybe (O × I) → I
(imap i) [ op ↦ v ]ᵢ =
imap (λ op' → if op ≡ op' then v else i op')
-- ACTION OF INTERRUPTS ON EFFECT ANNOTATIONS
infix 40 _↓ₑ_
↓ₑ-auxₒ : Σₛ → Maybe (O × I) → O → O
↓ₑ-auxₒ op nothing o =
o
↓ₑ-auxₒ op (just (o' , i')) o =
o ∪ₒ o'
↓ₑ-auxᵢ : Σₛ → Maybe (O × I) → I → I
↓ₑ-auxᵢ op nothing i =
i
↓ₑ-auxᵢ op (just (o' , i')) i =
(i [ op ↦ nothing ]ᵢ) ∪ᵢ i'
_↓ₑ_ : Σₛ → O × I → O × I
op ↓ₑ (omap o , imap i) =
(↓ₑ-auxₒ op (i op) (omap o) , ↓ₑ-auxᵢ op (i op) (imap i))
-- GENERALISED ACTION OF INTERRUPTS ON EFFECT ANNOTATIONS
_↓↓ₑ_ : List Σₛ → O × I → O × I
[] ↓↓ₑ (o , i) =
(o , i)
(op ∷ ops) ↓↓ₑ (o , i) =
op ↓ₑ (ops ↓↓ₑ (o , i))
↓↓ₑ-act : {o : O}
{i : I} →
(ops ops' : List Σₛ) →
------------------------------------------------------
(ops ++ ops') ↓↓ₑ (o , i) ≡ ops ↓↓ₑ (ops' ↓↓ₑ (o , i))
↓↓ₑ-act [] ops' =
refl
↓↓ₑ-act (op ∷ ops) ops' =
cong (λ oi → op ↓ₑ oi) (↓↓ₑ-act ops ops')
-- CHECKING THE CONTENTS OF EFFECT ANNOTATIONS
_∈ₒ_ : Σₛ → O → Set
op ∈ₒ (omap o) =
o op ≡ just tt
lkpᵢ : Σₛ → I → Maybe (O × I)
lkpᵢ op (imap i) = i op
-- SUBTYPING RELATIONS FOR EFFECT ANNOTATIONS
_⊑ₒ_ : O → O → Set
o ⊑ₒ o' = (op : Σₛ) → op ∈ₒ o → op ∈ₒ o'
data _⊑ᵢ_ (i i' : I) : Set where
rel : ((op : Σₛ) → {o : O} → {i'' : I} → lkpᵢ op i ≡ just (o , i'') →
Σ[ o' ∈ O ] Σ[ i''' ∈ I ] (lkpᵢ op i' ≡ just (o' , i''') × o ⊑ₒ o' × i'' ⊑ᵢ i''')) →
i ⊑ᵢ i'
-- SUBTYPING RELATIONS ARE PREORDERS
⊑ₒ-refl : {o : O} →
---------
o ⊑ₒ o
⊑ₒ-refl =
λ op p → p
⊑ₒ-trans : {o o' o'' : O} →
o ⊑ₒ o' →
o' ⊑ₒ o'' →
----------------
o ⊑ₒ o''
⊑ₒ-trans p q =
λ op r → q op (p op r)
⊑ᵢ-refl : {i : I} →
---------
i ⊑ᵢ i
⊑ᵢ-refl {imap i} =
rel (λ op {o'} → λ { {imap i'} → λ p → ⊑ᵢ-refl-aux (i op) p })
where
⊑ᵢ-refl-aux : (oi : Maybe (O × I)) →
----------------------------------------------------------------------------------
{o' : O} {i' : Σₛ → Maybe (O × I)} →
oi ≡ just (o' , imap i') →
Σ[ o'' ∈ O ] Σ[ i'' ∈ I ] (oi ≡ just (o'' , i'') × (o' ⊑ₒ o'') × (imap i' ⊑ᵢ i''))
⊑ᵢ-refl-aux (just .(o' , imap i')) {o'} {i'} refl =
o' , (imap i' , (refl , (⊑ₒ-refl , ⊑ᵢ-refl {imap i'})))
⊑ᵢ-trans : {i i' i'' : I} →
i ⊑ᵢ i' →
i' ⊑ᵢ i'' →
-----------------
i ⊑ᵢ i''
⊑ᵢ-trans {i} {i'} {i''} (rel p) (rel q) =
rel (λ op {o} {j} r → ⊑ᵢ-trans-aux o j op (p op r))
where
⊑ᵢ-trans-aux' : (o : O) → (j : I) → (op : Σₛ) →
(o' : O) → (j' : I) → lkpᵢ op i' ≡ just (o' , j') → (o ⊑ₒ o') → (j ⊑ᵢ j') →
Σ[ o'' ∈ O ] Σ[ j'' ∈ I ] (lkpᵢ op i'' ≡ just (o'' , j'') × (o' ⊑ₒ o'') × (j' ⊑ᵢ j'')) →
Σ[ o'' ∈ O ] Σ[ j'' ∈ I ] (lkpᵢ op i'' ≡ just (o'' , j'') × (o ⊑ₒ o'') × (j ⊑ᵢ j''))
⊑ᵢ-trans-aux' o j op o' j' r' s t (o'' , j'' , r'' , s' , t') =
o'' , j'' , r'' , ⊑ₒ-trans s s' , ⊑ᵢ-trans t t'
⊑ᵢ-trans-aux : (o : O) → (j : I) → (op : Σₛ) →
Σ[ o' ∈ O ] Σ[ j' ∈ I ] (lkpᵢ op i' ≡ just (o' , j') × (o ⊑ₒ o') × (j ⊑ᵢ j')) →
Σ[ o'' ∈ O ] Σ[ j'' ∈ I ] (lkpᵢ op i'' ≡ just (o'' , j'') × (o ⊑ₒ o'') × (j ⊑ᵢ j''))
⊑ᵢ-trans-aux o j op (o' , j' , r' , s , t) =
⊑ᵢ-trans-aux' o j op o' j' r' s t (q op r')
-- SUBTYPING RELATIONS ARE PROOF-IRRELEVANT
≡-uip : {X : Set}
{x x' : X} →
(p q : x ≡ x') →
----------------
p ≡ q
≡-uip refl refl = refl
⊑ₒ-irrelevant : {o o' : O}
(p q : o ⊑ₒ o') →
-----------------
p ≡ q
⊑ₒ-irrelevant {omap o} {omap o'} p q =
fun-ext (λ op → fun-ext (λ r → ⊑ₒ-irrelevant-aux r))
where
⊑ₒ-irrelevant-aux : {op : Σₛ} →
(r : op ∈ₒ (omap o)) →
----------------------
p op r ≡ q op r
⊑ₒ-irrelevant-aux {op} r with p op r | q op r
... | s | t = ≡-uip s t
⊑ᵢ-irrelevant : {i i' : I}
(p q : i ⊑ᵢ i') →
-----------------
p ≡ q
⊑ᵢ-irrelevant {imap i} {imap i'} (rel p) (rel q) =
cong (λ r → rel r) (fun-ext (λ op → ifun-ext (λ {o''} → ifun-ext (λ {i''} → fun-ext (λ r → ⊑ᵢ-irrelevant-aux r)))))
where
⊑ᵢ-irrelevant-aux : {op : Σₛ}
{o'' : O}
{i'' : I} →
(r : i op ≡ just (o'' , i'')) →
-------------------------------
p op r ≡ q op r
⊑ᵢ-irrelevant-aux {op} r with p op r | q op r
... | o''' , i''' , s , s' , s'' | o'''' , i'''' , t , t' , t'' with trans (sym s) t
... | refl with ⊑ₒ-irrelevant s' t'
... | refl with ⊑ᵢ-irrelevant s'' t''
... | refl with ≡-uip s t
... | refl = refl
-- LEFT UNIT FOR UNIONS OF EFFECT ANNOTATIONS
∪ₒ-lunit : (o : O) →
-----------
∅ₒ ∪ₒ o ≡ o
∪ₒ-lunit (omap o) =
cong omap (fun-ext ∪ₒ-lunit-aux)
where
∪ₒ-lunit-aux : (op : Σₛ) →
----------------------------------
∪ₒ-aux (λ _ → nothing) o op ≡ o op
∪ₒ-lunit-aux op with o op
... | nothing =
refl
... | just _ =
refl
∪ᵢ-lunit : (i : I) →
-----------
∅ᵢ ∪ᵢ i ≡ i
∪ᵢ-lunit (imap i) = cong imap (fun-ext ∪ᵢ-lunit-aux)
where
∪ᵢ-lunit-aux : (op : Σₛ) →
----------------------------------
∪ᵢ-aux (λ _ → nothing) i op ≡ i op
∪ᵢ-lunit-aux op with i op
... | nothing =
refl
... | just _ =
refl
-- LEFT AND RIGHT INCLUSIONS INTO UNIONS OF EFFECT ANNOTATIONS
∪ₒ-inl : {o o' : O} →
-------------
o ⊑ₒ (o ∪ₒ o')
∪ₒ-inl {omap o} {omap o'} op with o op | o' op
... | nothing | nothing = λ p → p
... | nothing | just tt = λ _ → refl
... | just tt | nothing = λ p → p
... | just tt | just tt = λ p → p
∪ₒ-inr : {o o' : O} →
-------------
o' ⊑ₒ (o ∪ₒ o')
∪ₒ-inr {omap o} {omap o'} op with o op | o' op
... | nothing | nothing = λ p → p
... | nothing | just tt = λ p → p
... | just tt | nothing = λ _ → refl
... | just tt | just tt = λ p → p
∪ᵢ-inl : {i i' : I} →
-------------
i ⊑ᵢ (i ∪ᵢ i')
∪ᵢ-inl {imap i} {imap i'} =
rel (λ op → ∪ᵢ-inl-aux (i op) (i' op))
where
∪ᵢ-inl-aux : (oi oi' : Maybe (O × I)) →
{o : O} {i'' : I} →
oi ≡ just (o , i'') →
Σ[ o' ∈ O ] Σ[ i''' ∈ I ] (∪ᵢ-aux' oi oi' ≡ just (o' , i''') × (o ⊑ₒ o') × (i'' ⊑ᵢ i'''))
∪ᵢ-inl-aux (just .(o , i'')) nothing {o} {i''} refl =
o , i'' , refl , ⊑ₒ-refl , ⊑ᵢ-refl
∪ᵢ-inl-aux (just .(o , imap i'')) (just (o' , imap i''')) {o} {imap i''} refl =
o ∪ₒ o' , imap (∪ᵢ-aux i'' i''') , refl , ∪ₒ-inl , ∪ᵢ-inl
∪ᵢ-inr : {i i' : I} →
-------------
i' ⊑ᵢ (i ∪ᵢ i')
∪ᵢ-inr {imap i} {imap i'} =
rel (λ op → ∪ᵢ-inr-aux (i op) (i' op))
where
∪ᵢ-inr-aux : (oi oi' : Maybe (O × I)) →
{o : O} {i'' : I} →
oi' ≡ just (o , i'') →
Σ[ o' ∈ O ] Σ[ i''' ∈ I ] (∪ᵢ-aux' oi oi' ≡ just (o' , i''') × (o ⊑ₒ o') × (i'' ⊑ᵢ i'''))
∪ᵢ-inr-aux nothing (just .(o , i'')) {o} {i''} refl =
o , i'' , refl , ⊑ₒ-refl , ⊑ᵢ-refl
∪ᵢ-inr-aux (just (o' , imap i''')) (just .(o , imap i'')) {o} {imap i''} refl =
o' ∪ₒ o , imap (∪ᵢ-aux i''' i'') , refl , ∪ₒ-inr , ∪ᵢ-inr
-- COPAIRING FOR UNIONS OF EFFECT ANNOTATIONS
∪ₒ-copair : {o o' o'' : O} →
o ⊑ₒ o'' →
o' ⊑ₒ o'' →
----------------
(o ∪ₒ o') ⊑ₒ o''
∪ₒ-copair {omap o} {omap o'} {omap o''} p q op =
∪ₒ-copair-aux (p op) (q op)
where
∪ₒ-copair-aux : (p : op ∈ₒ (omap o) → op ∈ₒ (omap o'')) →
(q : op ∈ₒ (omap o') → op ∈ₒ (omap o'')) →
---------------------------------------------
op ∈ₒ (omap (∪ₒ-aux o o')) → op ∈ₒ (omap o'')
∪ₒ-copair-aux p q with o op | o' op
... | nothing | nothing = q
... | nothing | just tt = q
... | just tt | nothing = p
... | just tt | just tt = p
inj-just : {X : Set} {x x' : X} → just x ≡ just x' → x ≡ x'
inj-just refl = refl
inj-pair₁ : {X Y : Set} {x x' : X} {y y' : Y} → (x , y) ≡ (x' , y') → x ≡ x'
inj-pair₁ refl = refl
inj-pair₂ : {X Y : Set} {x x' : X} {y y' : Y} → (x , y) ≡ (x' , y') → y ≡ y'
inj-pair₂ refl = refl
∪ᵢ-copair : {i i' i'' : I} →
i ⊑ᵢ i'' →
i' ⊑ᵢ i'' →
----------------
(i ∪ᵢ i') ⊑ᵢ i''
∪ᵢ-copair {imap i} {imap i'} {imap i''} (rel p) (rel q) =
rel (λ op {o'''} {i'''} r → ∪ᵢ-copair-aux op o''' i''' (i op) (i' op) (i'' op) refl refl refl r)
where
∪ᵢ-copair-aux : (op : Σₛ) →
(o''' : O) →
(i''' : I)
(oi oi' oi'' : Maybe (O × I)) →
(oi ≡ i op) →
(oi' ≡ i' op) →
(oi'' ≡ i'' op) →
(r : ∪ᵢ-aux' oi oi' ≡ just (o''' , i''')) →
Σ[ o' ∈ O ] Σ[ i'''' ∈ I ] (oi'' ≡ just (o' , i'''') × (o''' ⊑ₒ o') × (i''' ⊑ᵢ i''''))
∪ᵢ-copair-aux op o''' i''' nothing (just oi') nothing r s t u with trans t (proj₁ (proj₂ (proj₂ (q op (trans (sym s) u)))))
... | ()
∪ᵢ-copair-aux op o''' i''' nothing (just oi') (just oi'') r s t u =
proj₁ (q op (trans (sym s) u)) ,
proj₁ (proj₂ (q op (trans (sym s) u))) ,
trans t (proj₁ (proj₂ (proj₂ (q op (trans (sym s) u))))) ,
proj₁ (proj₂ (proj₂ (proj₂ (q op (trans (sym s) u))))) ,
proj₂ (proj₂ (proj₂ (proj₂ (q op (trans (sym s) u)))))
∪ᵢ-copair-aux op o''' i''' (just oi) nothing oi'' r s t u =
proj₁ (p op (trans (sym r) u)) ,
proj₁ (proj₂ (p op (trans (sym r) u))) ,
trans t (proj₁ (proj₂ (proj₂ (p op (trans (sym r) u))))) ,
proj₁ (proj₂ (proj₂ (proj₂ (p op (trans (sym r) u))))) ,
proj₂ (proj₂ (proj₂ (proj₂ (p op (trans (sym r) u)))))
∪ᵢ-copair-aux op o''' i'''
(just (omap o'''' , imap i''''))
(just (omap o''''' , imap i'''''))
nothing r s t u
with trans t (proj₁ (proj₂ (proj₂ (p op (sym r)))))
... | ()
∪ᵢ-copair-aux op o''' i'''
(just (omap o'''' , imap i''''))
(just (omap o''''' , imap i'''''))
(just (omap o'''''' , imap i''''''))
r s t u =
omap o'''''' ,
imap i'''''' ,
refl ,
subst (λ o → o ⊑ₒ omap o'''''')
(inj-pair₁ (inj-just u))
(∪ₒ-copair (subst (λ o → omap o'''' ⊑ₒ o)
(inj-pair₁ (inj-just (sym (trans t (proj₁ (proj₂ (proj₂ (p op (sym r)))))))))
(proj₁ (proj₂ (proj₂ (proj₂ (p op (sym r)))))))
(subst (λ o → omap o''''' ⊑ₒ o)
(inj-pair₁ (inj-just (sym (trans t (proj₁ (proj₂ (proj₂ (q op (sym s)))))))))
(proj₁ (proj₂ (proj₂ (proj₂ (q op (sym s)))))))) ,
subst (λ i → i ⊑ᵢ imap i'''''')
(inj-pair₂ (inj-just u))
(∪ᵢ-copair (subst (λ i → imap i'''' ⊑ᵢ i)
(inj-pair₂ (inj-just (sym (trans t (proj₁ (proj₂ (proj₂ (p op (sym r)))))))))
(proj₂ (proj₂ (proj₂ (proj₂ (p op (sym r)))))))
(subst (λ i → imap i''''' ⊑ᵢ i)
(inj-pair₂ (inj-just (sym (trans t (proj₁ (proj₂ (proj₂ (q op (sym s)))))))))
(proj₂ (proj₂ (proj₂ (proj₂ (q op (sym s))))))))
-- FUNCTORIALITY OF UNIONS OF EFFECT ANNOTATIONS
∪ₒ-fun : {o o' o'' o''' : O} →
o ⊑ₒ o'' →
o' ⊑ₒ o''' →
--------------------------
(o ∪ₒ o') ⊑ₒ (o'' ∪ₒ o''')
∪ₒ-fun p q =
∪ₒ-copair (⊑ₒ-trans p ∪ₒ-inl) (⊑ₒ-trans q ∪ₒ-inr)
∪ᵢ-fun : {i i' i'' i''' : I} →
i ⊑ᵢ i'' →
i' ⊑ᵢ i''' →
--------------------------
(i ∪ᵢ i') ⊑ᵢ (i'' ∪ᵢ i''')
∪ᵢ-fun p q =
∪ᵢ-copair (⊑ᵢ-trans p ∪ᵢ-inl) (⊑ᵢ-trans q ∪ᵢ-inr)
-- UNIONS OF INTERRUPT ANNOTATIONS ARE GIVEN BY POINTWISE UNIONS
∪ᵢ-∪ₒ : {op : Σₛ}
{o'' o''' o'''' : O}
{i i' i'' i''' i'''' : I} →
lkpᵢ op (i ∪ᵢ i') ≡ just (o'' , i'') →
lkpᵢ op i ≡ just (o''' , i''') →
lkpᵢ op i' ≡ just (o'''' , i'''') →
---------------------------------------
o'' ≡ o''' ∪ₒ o''''
∪ᵢ-∪ₒ {op} {o''} {o'''} {o''''} {imap i} {imap i'} p q r with i op | i' op
∪ᵢ-∪ₒ {op} {.(o''' ∪ₒ o'''')} {o'''} {o''''} {imap i} {imap i'} {_} {imap i'''} {imap i''''}
refl refl refl | just .(o''' , imap i''') | just .(o'''' , imap i'''') =
refl
∪ᵢ-∪ᵢ : {op : Σₛ}
{o'' o''' o'''' : O}
{i i' i'' i''' i'''' : I} →
lkpᵢ op (i ∪ᵢ i') ≡ just (o'' , i'') →
lkpᵢ op i ≡ just (o''' , i''') →
lkpᵢ op i' ≡ just (o'''' , i'''') →
---------------------------------------
i'' ≡ i''' ∪ᵢ i''''
∪ᵢ-∪ᵢ {op} {o''} {o'''} {o''''} {imap i} {imap i'} p q r with i op | i' op
∪ᵢ-∪ᵢ {op} {.(o''' ∪ₒ o'''')} {o'''} {o''''} {imap i} {imap i'} {_} {imap i'''} {imap i''''}
refl refl refl | just .(o''' , imap i''') | just .(o'''' , imap i'''') =
refl
-- INCLUSION INTO ACTED UPON EFFECT ANNOTATION
{- LEMMA 3.1 (1) -}
↓ₑ-⊑ₒ : {o : O}
{i : I}
{op : Σₛ} →
--------------------------
o ⊑ₒ proj₁ (op ↓ₑ (o , i))
↓ₑ-⊑ₒ {omap o} {imap i} {op} op' p with i (op)
... | nothing = p
... | just (o' , i') = ∪ₒ-inl op' p
{- LEMMA 3.1 (2) - the O part -}
↓ₑ-⊑ₒ-o' : {o o' : O}
{i i' : I}
{op : Σₛ} →
lkpᵢ op i ≡ just (o' , i') →
---------------------------
o' ⊑ₒ proj₁ (op ↓ₑ (o , i))
↓ₑ-⊑ₒ-o' {omap o} {omap o'} {imap i} {imap i'} {op} p with i (op)
↓ₑ-⊑ₒ-o' {omap o} {omap o'} {imap i} {imap i'} {op} refl | just .(omap o' , imap i') =
↓ₑ-⊑ₒ-o'-aux
where
↓ₑ-⊑ₒ-o'-aux : (op' : Σₛ) → o' op' ≡ just tt → ∪ₒ-aux o o' op' ≡ just tt
↓ₑ-⊑ₒ-o'-aux op' p with o op'
↓ₑ-⊑ₒ-o'-aux op' p | nothing = p
↓ₑ-⊑ₒ-o'-aux op' p | just tt = refl
{- LEMMA 3.1 (2) - the I part -}
↓ₑ-⊑ₒ-i' : {o o' : O}
{i i' : I}
{op : Σₛ} →
lkpᵢ op i ≡ just (o' , i') →
---------------------------
i' ⊑ᵢ proj₂ (op ↓ₑ (o , i))
↓ₑ-⊑ₒ-i' {omap o} {omap o'} {imap i} {imap i'} {op} p with i (op)
↓ₑ-⊑ₒ-i' {omap o} {omap o'} {imap i} {imap i'} {op} refl | just .(omap o' , imap i') =
rel ↓ₑ-⊑ₒ-i'-aux
where
↓ₑ-⊑ₒ-i'-aux : (op' : Σₛ) {o'' : O} {i'' : I} →
i' op' ≡ just (o'' , i'') →
Σ[ o''' ∈ O ] Σ[ i''' ∈ I ] (∪ᵢ-aux (λ op' → if op ≡ op' then nothing else i op') i' op' ≡ just (o''' , i''') ×
(o'' ⊑ₒ o''') × (i'' ⊑ᵢ i'''))
↓ₑ-⊑ₒ-i'-aux op' {o''} {i''} p with decₛ op op'
↓ₑ-⊑ₒ-i'-aux op' {o''} {i''} p | yes refl with i' (op)
↓ₑ-⊑ₒ-i'-aux op' {o''} {i''} refl | yes refl | just .(o'' , i'') =
o'' , (i'' , refl , (⊑ₒ-refl , ⊑ᵢ-refl))
↓ₑ-⊑ₒ-i'-aux op' {o''} {i''} p | no ¬q with i (op') | i' (op')
↓ₑ-⊑ₒ-i'-aux op' {o''} {i''} refl | no ¬q | nothing | just .(o'' , i'') =
o'' , (i'' , refl , (⊑ₒ-refl , ⊑ᵢ-refl))
↓ₑ-⊑ₒ-i'-aux op' {o''} {imap i''} refl | no ¬q | just (o''' , (imap i''')) | just .(o'' , (imap i'')) =
(o''' ∪ₒ o'') , (imap (∪ᵢ-aux i''' i'') , (refl , (∪ₒ-inr , ∪ᵢ-inr)))
-- EFFECT ANNOTATION OF AN INTERRUPT THAT WAS NOT ACTED WITH
{- LEMMA 3.1 (3) -}
lkpᵢ-↓ₑ-neq : {o o' : O}
{i i' : I} {op op' : Σₛ} →
¬ op ≡ op' →
lkpᵢ op' i ≡ just (o' , i') →
-------------------------------------------------------------------------------------------------------
Σ[ o'' ∈ O ] Σ[ i'' ∈ I ] (lkpᵢ op' (proj₂ (op ↓ₑ (o , i))) ≡ just (o'' , i'') × o' ⊑ₒ o'' × i' ⊑ᵢ i'')
lkpᵢ-↓ₑ-neq {omap o} {o'} {imap i} {imap i'} {op} {op'} p q with i (op)
... | nothing =
o' , imap i' , q , ⊑ₒ-refl , ⊑ᵢ-refl
lkpᵢ-↓ₑ-neq {omap o} {o'} {imap i} {imap i'} {op} {op'} p q | just (o'' , imap i'') with decₛ op op'
... | yes r with p r
... | ()
lkpᵢ-↓ₑ-neq {omap o} {o'} {imap i} {imap i'} {op} {op'} p q | just (o'' , imap i'') | no ¬r with i (op') | i'' (op')
lkpᵢ-↓ₑ-neq {omap o} {.o'''} {imap i} {imap i'} {op} {op'} p refl |
just (o'' , imap i'') | no ¬r | just (o''' , .(imap i')) | nothing =
o''' , imap i' , refl , ⊑ₒ-refl , ⊑ᵢ-refl
... | just (o''' , imap i''') | just (o'''' , imap i'''') with q
lkpᵢ-↓ₑ-neq {omap o} {.o'''} {imap i} {imap .i'''} {op} {op'} p q |
just (o'' , imap i'') | no ¬r | just (o''' , imap i''') | just (o'''' , imap i'''') | refl =
(o''' ∪ₒ o'''') , (imap i''') ∪ᵢ (imap i'''') , refl , ∪ₒ-inl , ∪ᵢ-inl
-- NEXT DEFINED EFFECT ANNOTATION UNDER SUBTYPING EFFECT ANNOTATIONS
lkpᵢ-nextₒ : {o'' : O} {i i' i'' : I} {op : Σₛ} →
i ⊑ᵢ i' → lkpᵢ op i ≡ just (o'' , i'') → O
lkpᵢ-nextₒ {o''} {i} {i'} {i''} {op} (rel p) q =
proj₁ (p op q)
lkpᵢ-nextᵢ : {o'' : O} {i i' i'' : I} {op : Σₛ} →
i ⊑ᵢ i' → lkpᵢ op i ≡ just (o'' , i'') → I
lkpᵢ-nextᵢ {o''} {i} {i'} {i''} {op} (rel p) q =
proj₁ (proj₂ (p op q))
lkpᵢ-next-eq : {o'' : O} {i i' i'' : I} {op : Σₛ} →
(p : i ⊑ᵢ i') →
(q : lkpᵢ op i ≡ just (o'' , i'')) →
------------------------------------------------
lkpᵢ op i' ≡ just (lkpᵢ-nextₒ p q , lkpᵢ-nextᵢ p q)
lkpᵢ-next-eq {o''} {i} {i'} {i''} {op} (rel p) q =
proj₁ (proj₂ (proj₂ (p op q)))
lkpᵢ-next-⊑ₒ : {o'' : O} {i i' i'' : I} {op : Σₛ} →
(p : i ⊑ᵢ i') →
(q : lkpᵢ op i ≡ just (o'' , i'')) →
-----------------------------------
o'' ⊑ₒ lkpᵢ-nextₒ p q
lkpᵢ-next-⊑ₒ {o''} {i} {i'} {i''} {op} (rel p) q =
proj₁ (proj₂ (proj₂ (proj₂ (p op q))))
lkpᵢ-next-⊑ᵢ : {o'' : O} {i i' i'' : I} {op : Σₛ} →
(p : i ⊑ᵢ i') →
(q : lkpᵢ op i ≡ just (o'' , i'')) →
-----------------------------------
i'' ⊑ᵢ lkpᵢ-nextᵢ p q
lkpᵢ-next-⊑ᵢ {o''} {i} {i'} {i''} {op} (rel p) q =
proj₂ (proj₂ (proj₂ (proj₂ (p op q))))
-- ACTION OF INTERRUPTS ON EFFECT ANNOTATIONS IS MONOTONIC
mutual
↓ₑ-monotonicₒ : {o o' : O}
{i i' : I}
{op : Σₛ} →
o ⊑ₒ o' →
i ⊑ᵢ i' →
------------------------------------------------
proj₁ (op ↓ₑ (o , i)) ⊑ₒ proj₁ (op ↓ₑ (o' , i'))
↓ₑ-monotonicₒ {omap o} {omap o'} {imap i} {imap i'} {op} p (rel q) =
↓ₑ-monotonicₒ-aux (i op) (i' op) refl refl
where
↓ₑ-monotonicₒ-aux : (oi oi' : Maybe (O × I)) →
i op ≡ oi →
i' op ≡ oi' →
----------------------------
↓ₑ-auxₒ op oi (omap o)
⊑ₒ
↓ₑ-auxₒ op oi' (omap o')
↓ₑ-monotonicₒ-aux nothing nothing r s =
p
↓ₑ-monotonicₒ-aux nothing (just (omap o''' , imap i''')) r s =
⊑ₒ-trans p ∪ₒ-inl
↓ₑ-monotonicₒ-aux (just (omap o'' , imap i'')) nothing r s with trans (sym s) (proj₁ (proj₂ (proj₂ (q op r))))
... | ()
↓ₑ-monotonicₒ-aux (just (omap o'' , imap i'')) (just (omap o''' , imap i''')) r s with trans (sym s) (proj₁ (proj₂ (proj₂ (q op r))))
... | t =
∪ₒ-fun p (⊑ₒ-trans (proj₁ (proj₂ (proj₂ (proj₂ (q op r)))))
(subst (λ o → o ⊑ₒ omap o''') (inj-pair₁ (inj-just t)) ⊑ₒ-refl))
↓ₑ-monotonicᵢ : {o o' : O}
{i i' : I}
{op : Σₛ} →
o ⊑ₒ o' →
i ⊑ᵢ i' →
------------------------------------------------
proj₂ (op ↓ₑ (o , i)) ⊑ᵢ proj₂ (op ↓ₑ (o' , i'))
↓ₑ-monotonicᵢ {omap o} {omap o'} {imap i} {imap i'} {op} p (rel q) =
↓ₑ-monotonicᵢ-aux (i op) (i' op) refl refl
where
↓ₑ-monotonicᵢ-aux : (oi oi' : Maybe (O × I)) →
oi ≡ i op →
oi' ≡ i' op →
-----------------------------------------
↓ₑ-auxᵢ op oi (imap i)
⊑ᵢ
↓ₑ-auxᵢ op oi' (imap i')
↓ₑ-monotonicᵢ-aux nothing nothing r s =
rel q
↓ₑ-monotonicᵢ-aux nothing (just (omap o''' , imap i''')) r s =
⊑ᵢ-trans (rel (λ op' {o''''} {i''''} t → ↓ₑ-monotonicᵢ-aux' op' o'''' i'''' t))
(∪ᵢ-inl {(imap i') [ op ↦ nothing ]ᵢ} {imap i'''})
where
↓ₑ-monotonicᵢ-aux' : (op' : Σₛ) →
(o'''' : O) →
(i'''' : I) →
i op' ≡ just (o'''' , i'''') →
--------------------------------------------------------------------
Σ[ o''''' ∈ O ] Σ[ i''''' ∈ I ]
((if op ≡ op' then nothing else i' op') ≡ just (o''''' , i''''') ×
(o'''' ⊑ₒ o''''') × (i'''' ⊑ᵢ i'''''))
↓ₑ-monotonicᵢ-aux' op' o'''' i'''' t with decₛ op op'
↓ₑ-monotonicᵢ-aux' op' o'''' i'''' t | yes refl with trans r t
... | ()
↓ₑ-monotonicᵢ-aux' op' o'''' i'''' t | no ¬u =
lkpᵢ-nextₒ (rel q) t ,
lkpᵢ-nextᵢ (rel q) t ,
lkpᵢ-next-eq (rel q) t ,
lkpᵢ-next-⊑ₒ (rel q) t ,
lkpᵢ-next-⊑ᵢ (rel q) t
↓ₑ-monotonicᵢ-aux (just (omap o'' , imap i'')) nothing r s with trans s (proj₁ (proj₂ (proj₂ (q op (sym r)))))
... | ()
↓ₑ-monotonicᵢ-aux (just (omap o'' , imap i'')) (just (omap o''' , imap i''')) r s =
∪ᵢ-fun {_}
{imap i''}
{_}
{imap i'''}
(rel λ op' {o''''} {i''''} t → ↓ₑ-monotonicᵢ-aux' op' o'''' i'''' t)
(subst (λ i → imap i'' ⊑ᵢ i)
(sym (inj-pair₂ (inj-just (trans s (proj₁ (proj₂ (proj₂ (q op (sym r)))))))))
(proj₂ (proj₂ (proj₂ (proj₂ (q op (sym r)))))))
where
↓ₑ-monotonicᵢ-aux' : (op' : Σₛ) →
(o'''' : O) →
(i'''' : I) →
lkpᵢ op' (imap i [ op ↦ nothing ]ᵢ) ≡ just (o'''' , i'''') →
--------------------------
Σ[ o''''' ∈ O ] Σ[ i''''' ∈ I ]
(lkpᵢ op' (imap i' [ op ↦ nothing ]ᵢ)
≡ just (o''''' , i''''') ×
(o'''' ⊑ₒ o''''') × (i'''' ⊑ᵢ i'''''))
↓ₑ-monotonicᵢ-aux' op' o'''' i'''' t with decₛ op op'
↓ₑ-monotonicᵢ-aux' op' o'''' i'''' t | no ¬u =
lkpᵢ-nextₒ (rel q) t ,
lkpᵢ-nextᵢ (rel q) t ,
lkpᵢ-next-eq (rel q) t ,
lkpᵢ-next-⊑ₒ (rel q) t ,
lkpᵢ-next-⊑ᵢ (rel q) t
-- GENERALISED ACTION OF INTERRUPTS ON EFFECT ANNOTATIONS IS MONOTONIC
mutual
↓↓ₑ-monotonicₒ : {o o' : O}
{i i' : I} →
(ops : List Σₛ) →
o ⊑ₒ o' →
i ⊑ᵢ i' →
----------------------------------------------------
proj₁ (ops ↓↓ₑ (o , i)) ⊑ₒ proj₁ (ops ↓↓ₑ (o' , i'))
↓↓ₑ-monotonicₒ {omap o} {omap o'} {imap i} {imap i'} [] p q =
p
↓↓ₑ-monotonicₒ (op ∷ ops) p q =
↓ₑ-monotonicₒ (↓↓ₑ-monotonicₒ ops p q) (↓↓ₑ-monotonicᵢ ops p q)
↓↓ₑ-monotonicᵢ : {o o' : O}
{i i' : I} →
(ops : List Σₛ) →
o ⊑ₒ o' →
i ⊑ᵢ i' →
----------------------------------------------------
proj₂ (ops ↓↓ₑ (o , i)) ⊑ᵢ proj₂ (ops ↓↓ₑ (o' , i'))
↓↓ₑ-monotonicᵢ [] p q = q
↓↓ₑ-monotonicᵢ (op ∷ ops) p q =
↓ₑ-monotonicᵢ (↓↓ₑ-monotonicₒ ops p q) (↓↓ₑ-monotonicᵢ ops p q)
-- INCLUSION INTO GENERALLY ACTED UPON EFFECT ANNOTATION
↓↓ₑ-⊑ₒ : {o : O}
{i : I} →
(ops : List Σₛ) →
--------------------------
o ⊑ₒ proj₁ (ops ↓↓ₑ (o , i))
↓↓ₑ-⊑ₒ [] =
⊑ₒ-refl
↓↓ₑ-⊑ₒ (op ∷ ops) =
⊑ₒ-trans (↓↓ₑ-⊑ₒ ops) (↓ₑ-⊑ₒ {op = op})
-- A PATH OF INTERRUPT NAMES THAT REVEALS THE GIVEN SIGNAL IN AN EFFECT ANNOTATION
data _`at_`in_,_ (op : Σₛ) : List Σₛ → O → I → Set where
stop : {o : O}
{i : I} →
op ∈ₒ o →
-------------------
op `at [] `in o , i
next : {o o' : O}
{i i' : I}
{op' : Σₛ}
{ops : List Σₛ} →
lkpᵢ op' i ≡ just (o' , i') →
op `at ops `in o' , i' →
-----------------------------
op `at (op' ∷ ops) `in o , i
-- ACTING ON AN ANNOTATION WITH EMPTY SIGNALS PART JUST REVEALS THE INNER LAYER IF THE INTERRUPTS MATCH
↓ₑ-∅-↦-≡ : {op : Σₛ}
{o : O}
{i : I} →
-----------------------------
op ↓ₑ (∅ₒ , imap (λ op' → if op' ≡ op then just (o , i) else nothing))
≡
(o , i)
↓ₑ-∅-↦-≡ {op} {o} {i} with decₛ op op
↓ₑ-∅-↦-≡ {op} {omap o} {i} | yes refl =
cong₂ (λ x y → x , y)
(∪ₒ-lunit (omap o))
(trans (cong (λ i' → i' ∪ᵢ i) ↓ₑ-∅-↦-≡-aux) (∪ᵢ-lunit i))
where
↓ₑ-∅-↦-≡-aux : imap (λ op' → if op ≡ op' then nothing else (if op' ≡ op then just (omap o , i) else nothing))
≡
∅ᵢ
↓ₑ-∅-↦-≡-aux = cong imap (fun-ext ↓ₑ-∅-↦-≡-aux-aux)
where
↓ₑ-∅-↦-≡-aux-aux : (op' : Σₛ) →
---------------------------------------------------------------------------------
(if op ≡ op' then nothing else (if op' ≡ op then just (omap o , i) else nothing))
≡
nothing
↓ₑ-∅-↦-≡-aux-aux op' with decₛ op op'
... | yes refl =
refl
... | no ¬p =
ite-≢ (λ q → ¬p (sym q))
↓ₑ-∅-↦-≡ {op} {o} {i} | no ¬p =
⊥-elim (¬p refl)
-- ACTING ON AN ANNOTATION WITH EMPTY SIGNALS IS IDEMPOTENT IF THE INTERRUPTS DO NOT MATCH
↓ₑ-∅-↦-≢ : {op op' : Σₛ}
{o : O}
{i : I} →
op ≢ op' →
-----------------------------
op' ↓ₑ (∅ₒ , imap (λ op'' → if op'' ≡ op then just (o , i) else nothing))
≡
(∅ₒ , imap (λ op'' → if op'' ≡ op then just (o , i) else nothing))
↓ₑ-∅-↦-≢ {op} {op'} p with decₛ op' op
↓ₑ-∅-↦-≢ {op} {.op} p | yes refl =
⊥-elim (p refl)
↓ₑ-∅-↦-≢ {op} {op'} p | no ¬q =
refl
-- A MINIMAL EFFECT ANNOTATION SUCH THAT A GIVEN PATH OF INTERRUPTS REVEALS THE GIVEN SIGNAL NAME
mutual
⦃⦃_↦_⦄⦄ₒ : List Σₛ → Σₛ → O
⦃⦃ [] ↦ op ⦄⦄ₒ =
omap (λ op' → if op ≡ op' then just tt else nothing)
⦃⦃ op' ∷ ops ↦ op ⦄⦄ₒ =
∅ₒ
⦃⦃_↦_⦄⦄ᵢ : List Σₛ → Σₛ → I
⦃⦃ [] ↦ op ⦄⦄ᵢ =
∅ᵢ
⦃⦃ op' ∷ ops ↦ op ⦄⦄ᵢ =
imap (λ op'' → if op'' ≡ op' then just (⦃⦃ ops ↦ op ⦄⦄ₒ , ⦃⦃ ops ↦ op ⦄⦄ᵢ) else nothing)
-- IF THERE IS A PATH TO A SIGNAL IN AN EFFECT ANNOTATION, THE MINIMAL EFFECT ANNOTATION IS INCLUDED IN IT
mutual
`at-minₒ : {op : Σₛ}
{ops : List Σₛ}
{o : O}
{i : I} →
op `at ops `in o , i →
----------------------
⦃⦃ ops ↦ op ⦄⦄ₒ ⊑ₒ o
`at-minₒ {op} {_} {omap o} (stop p) op' with decₛ op op'
`at-minₒ {.op'} {.[]} {omap o} (stop p) op' | yes refl =
λ _ → p
`at-minₒ {op} {.[]} {omap o} (stop p) op'' | no ¬q =
λ ()
`at-minₒ (next p q) op'' =
λ ()
`at-minᵢ : {op : Σₛ}
{ops : List Σₛ}
{o : O}
{i : I} →
op `at ops `in o , i →
----------------------
⦃⦃ ops ↦ op ⦄⦄ᵢ ⊑ᵢ i
`at-minᵢ (stop p) =
rel (λ op'' → λ ())
`at-minᵢ {op} (next {o} {o'} {i} {i'} {op'} {ops} p q) =
rel (λ op'' {o''} {i''} r → `at-minᵢ-aux r)
where
`at-minᵢ-aux : {op'' : Σₛ}
{o'' : O}
{i'' : I} →
lkpᵢ op'' ⦃⦃ op' ∷ ops ↦ op ⦄⦄ᵢ ≡ just (o'' , i'') →
---------------------------------------------------
Σ[ o''' ∈ O ]
Σ[ i''' ∈ I ]
(lkpᵢ op'' i ≡ just (o''' , i''') ×
(o'' ⊑ₒ o''') ×
(i'' ⊑ᵢ i'''))
`at-minᵢ-aux {op''} p with decₛ op'' op'
`at-minᵢ-aux {op'} refl | yes refl =
o' , i' , p , `at-minₒ q , `at-minᵢ q
-- SUBPATHS OF (INTERRUPT) NAMES
data _⊆_ : List Σₛ → List Σₛ → Set where
[] : {ops' : List Σₛ} →
----------------
[] ⊆ ops'
∷-≡ : {op : Σₛ}
{ops ops' : List Σₛ} →
ops ⊆ ops' →
------------------------
(op ∷ ops) ⊆ (op ∷ ops')
∷-≢ : {op op' : Σₛ}
{ops ops' : List Σₛ} →
op ≢ op' →
(op ∷ ops) ⊆ ops' →
-------------------------
(op ∷ ops) ⊆ (op' ∷ ops')
mutual
∷-≢-swap : {op op' : Σₛ}
{ops ops' : List Σₛ} →
op ≢ op' →
(op ∷ ops) ⊆ (op' ∷ op ∷ ops') →
--------------------------------
(op ∷ ops) ⊆ (op ∷ op' ∷ ops')
∷-≢-swap {op} {.op} {ops} {ops'} p (∷-≡ q) =
∷-≡ q
∷-≢-swap {op} {op'} {ops} {ops'} p (∷-≢ q (∷-≡ r)) =
∷-≡ (∷-∷ r)
∷-≢-swap {op} {op'} {ops} {ops'} p (∷-≢ q (∷-≢ r s)) =
⊥-elim (r refl)
∷-∷ : {op' : Σₛ}
{ops : List Σₛ} →
{ops' : List Σₛ} →
ops ⊆ ops' →
-------------------
ops ⊆ (op' ∷ ops')
∷-∷ [] = []
∷-∷ {op'} (∷-≡ {op} p) with decₛ op op'
∷-∷ {.op} (∷-≡ {op} p) | yes refl =
∷-≡ (∷-∷ p)
∷-∷ {op'} (∷-≡ {op} p) | no ¬q =
∷-≢ ¬q (∷-≡ p)
∷-∷ {op'} (∷-≢ {op} {op''} p q) with decₛ op op'
∷-∷ {.op} (∷-≢ {op} {op''} p q) | yes refl = ∷-≢-swap p (∷-≢ p (∷-∷ q))
∷-∷ {op'} (∷-≢ {op} {op''} p q) | no ¬r = ∷-≢ ¬r (∷-≢ p q)
-- IF A SUBPATH OF INTERRUPTS REVEALS A SIGNAL, THEN ACTING WITH THE WHOLE PATH ALSO REVEALS IT
⊆-↓↓ : {op : Σₛ}
{ops ops' : List Σₛ} →
ops ⊆ ops' →
---------------------------------------------------------------
op ∈ₒ proj₁ (reverse ops' ↓↓ₑ (⦃⦃ ops ↦ op ⦄⦄ₒ , ⦃⦃ ops ↦ op ⦄⦄ᵢ))
⊆-↓↓ {op} {ops} {ops'} [] =
(↓↓ₑ-⊑ₒ (reverse ops')) op ⊆-↓↓-aux
where
⊆-↓↓-aux : (if op ≡ op then just tt else nothing) ≡ just tt
⊆-↓↓-aux with decₛ op op
⊆-↓↓-aux | yes refl =
refl
⊆-↓↓-aux | no ¬p =
⊥-elim (¬p refl)
⊆-↓↓ {op} (∷-≡ {op'} {ops} {ops'} p) =
subst (λ ops'' → op ∈ₒ proj₁ (ops'' ↓↓ₑ (⦃⦃ (op' ∷ ops) ↦ op ⦄⦄ₒ , ⦃⦃ (op' ∷ ops) ↦ op ⦄⦄ᵢ)))
(sym (unfold-reverse op' ops'))
(subst (λ oi → op ∈ₒ proj₁ oi)
(sym (↓↓ₑ-act (reverse ops') [ op' ]))
(subst (λ oi → op ∈ₒ proj₁ (reverse ops' ↓↓ₑ oi))
(sym ↓ₑ-∅-↦-≡)
(⊆-↓↓ p)))
⊆-↓↓ {op} (∷-≢ {op'} {op''} {ops} {ops'} p q) =
subst (λ ops'' → op ∈ₒ proj₁ (ops'' ↓↓ₑ (⦃⦃ (op' ∷ ops) ↦ op ⦄⦄ₒ , ⦃⦃ (op' ∷ ops) ↦ op ⦄⦄ᵢ)))
(sym (unfold-reverse op'' ops'))
(subst (λ oi → op ∈ₒ proj₁ oi)
(sym (↓↓ₑ-act (reverse ops') [ op'' ]))
(subst (λ oi → op ∈ₒ proj₁ (reverse ops' ↓↓ₑ oi))
(sym (↓ₑ-∅-↦-≢ p))
(⊆-↓↓ q)))
-- IF A PATH REVEALS A SIGNAL IN A UNION OF EFFECT ANNOTATIONS, THE PATH REVEALS THE SIGNAL IN ONE OF THE SUMMANDS
`at-⊎ : {op : Σₛ}
{ops : List Σₛ}
{o o' : O}
{i i' : I} →
op `at ops `in (o ∪ₒ o') , (i ∪ᵢ i') →
-------------------------------------------------
(op `at ops `in o , i) ⊎ (op `at ops `in o' , i')
`at-⊎ {op} {ops} {omap o} {omap o'} {i} {i'} (stop p) =
`at-⊎-aux p (o op) (o' op) refl refl
where
`at-⊎-aux : (∪ₒ-aux o o' op ≡ just tt) →
(t t' : Maybe ⊤) →
o op ≡ t →
o' op ≡ t' →
-----------------------------------------------------------
(op `at ops `in omap o , i) ⊎ (op `at ops `in omap o' , i')
`at-⊎-aux p nothing nothing q r with o op | o' op
`at-⊎-aux () nothing nothing q r | nothing | nothing
`at-⊎-aux p nothing nothing q () | nothing | just tt
`at-⊎-aux p nothing (just tt) q r =
inj₂ (stop r)
`at-⊎-aux p (just tt) t' q r =
inj₁ (stop q)
`at-⊎ {op} {_} {o} {o'} {imap i} {imap i'} (next {o''} {o'''} {i''} {i'''} {op'} {ops} p q) =
`at-⊎-aux p q (i op') (i' op') refl refl
where
`at-⊎-aux : ∪ᵢ-aux i i' op' ≡ just (o''' , i''') →
op `at ops `in o''' , i''' →
(oi oi' : Maybe (O × I)) →
i op' ≡ oi →
i' op' ≡ oi' →
---------------------------------------------------------------------------
(op `at (op' ∷ ops) `in o , imap i) ⊎ (op `at (op' ∷ ops) `in o' , imap i')
`at-⊎-aux p q nothing nothing r s with i op' | i' op'
`at-⊎-aux () q nothing nothing r s | nothing | nothing
`at-⊎-aux p q nothing nothing r () | nothing | just _
`at-⊎-aux p q nothing (just (o'''' , i'''')) r s =
inj₂ (next (trans (sym (`at-⊎-aux-aux r s)) p) q)
where
`at-⊎-aux-aux : i op' ≡ nothing →
i' op' ≡ just (o'''' , i'''') →
-------------------------------
∪ᵢ-aux i i' op' ≡ i' op'
`at-⊎-aux-aux r s with i op' | i' op'
`at-⊎-aux-aux r s | nothing | just _ =
refl
`at-⊎-aux p q (just (o'''' , i'''')) nothing r s =
inj₁ (next (trans (sym (`at-⊎-aux-aux r s)) p) q)
where
`at-⊎-aux-aux : i op' ≡ just (o'''' , i'''') →
i' op' ≡ nothing →
-------------------------------
∪ᵢ-aux i i' op' ≡ i op'
`at-⊎-aux-aux r s with i op' | i' op'
`at-⊎-aux-aux r s | just _ | nothing =
refl
`at-⊎-aux p q (just (o'''' , i'''')) (just (o''''' , i''''')) r s
with ∪ᵢ-∪ₒ {i = imap i} {i' = imap i'} p r s | ∪ᵢ-∪ᵢ {i = imap i} {i' = imap i'} p r s
... | refl | refl with `at-⊎ q
... | inj₁ t =
inj₁ (next r t)
... | inj₂ t =
inj₂ (next s t)
-- IF ACTING WITH A PATH REVEALS A SIGNAL, THEN THERE IS A SUBPATH TO THAT SIGNAL
↓↓-⊆-rw : (o : O)
(i : I)
(op : Σₛ)
(ops : List Σₛ) →
----------------------------------------------------------------
reverse (op ∷ ops) ↓↓ₑ (o , i) ≡ reverse ops ↓↓ₑ (op ↓ₑ (o , i))
↓↓-⊆-rw o i op ops =
trans (cong (λ ops' → ops' ↓↓ₑ (o , i)) (unfold-reverse op ops))
(↓↓ₑ-act (reverse ops) [ op ])
↓↓-⊆ : {op : Σₛ} →
(ops : List Σₛ) →
{o : O}
{i : I} →
op ∈ₒ proj₁ (reverse ops ↓↓ₑ (o , i)) →
----------------------------------------------------------
Σ[ ops' ∈ List Σₛ ] (ops' ⊆ ops × (op `at ops' `in o , i))
↓↓-⊆ [] p =
[] , [] , stop p
↓↓-⊆ {op} (op' ∷ ops) {omap o} {imap i} p rewrite ↓↓-⊆-rw (omap o) (imap i) op' ops =
↓↓-⊆-aux (i op') refl
where
↓↓-⊆-aux : (oi : Maybe (O × I)) →
i op' ≡ oi →
----------------------------------------------------------------------------
Σ[ ops' ∈ List Σₛ ] (ops' ⊆ (op' ∷ ops) × (op `at ops' `in omap o , imap i))
↓↓-⊆-aux nothing q with ↓↓-⊆ ops p
... | ops' , r , s rewrite q =
ops' , ∷-∷ r , s
↓↓-⊆-aux (just (omap o' , imap i')) q with ↓↓-⊆ ops p
... | ops' , r , s rewrite q with `at-⊎ {o = omap o} {o' = omap o'} {i' = imap i'} s
... | inj₁ t =
↓↓-⊆-aux-aux ops' r t
where
↓↓-⊆-aux-aux : (ops' : List Σₛ) →
ops' ⊆ ops →
(op `at ops' `in omap o , ((imap i) [ op' ↦ nothing ]ᵢ)) →
-------------------------------------------------------------------------------
Σ[ ops'' ∈ List Σₛ ] (ops'' ⊆ (op' ∷ ops) × (op `at ops'' `in omap o , imap i))
↓↓-⊆-aux-aux [] r (stop t) =
[] , [] , stop t
↓↓-⊆-aux-aux (op'' ∷ ops'') r (next t u) with decₛ op' op''
... | no ¬v =
op'' ∷ ops'' , ∷-≢ (λ w → ¬v (sym w)) r , next t u
... | inj₂ t =
op' ∷ ops' , ∷-≡ r , next q t
-- ENVELOPING THE EFFECT ANNOTATION REDUCTION WITH MLTIPLE INTERRUPT ACTIONS
{- LEMMA 4.5 -}
↓↓ₑ-⊑ₒ-act : {o : O}
{i : I} →
(ops : List Σₛ) →
(op : Σₛ) →
----------------------------------------------------------
proj₁ (ops ↓↓ₑ (o , i)) ⊑ₒ proj₁ (ops ↓↓ₑ (op ↓ₑ (o , i)))
↓↓ₑ-⊑ₒ-act {o} {i} ops op op' p rewrite sym (reverse-involutive ops) with ↓↓-⊆ (reverse ops) p
... | ops' , q , r with ⊆-↓↓ {op'} (∷-∷ {op} q)
... | s with ↓↓ₑ-monotonicₒ (reverse (op ∷ reverse ops)) (`at-minₒ r) (`at-minᵢ r) op' s
... | t rewrite ↓↓-⊆-rw o i op (reverse ops) | reverse-involutive ops = t
| {
"alphanum_fraction": 0.3599627607,
"avg_line_length": 31.7689848122,
"ext": "agda",
"hexsha": "16a5e22cd0bacdfb5aa31b8df2de85cd4d5ec2db",
"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": "71ebed9f90a3eb37ae6cd209457bae23a4d122d1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "danelahman/aeff-agda",
"max_forks_repo_path": "EffectAnnotations.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "71ebed9f90a3eb37ae6cd209457bae23a4d122d1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "danelahman/aeff-agda",
"max_issues_repo_path": "EffectAnnotations.agda",
"max_line_length": 139,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "71ebed9f90a3eb37ae6cd209457bae23a4d122d1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "danelahman/aeff-agda",
"max_stars_repo_path": "EffectAnnotations.agda",
"max_stars_repo_stars_event_max_datetime": "2021-03-22T22:48:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-17T00:15:00.000Z",
"num_tokens": 16691,
"size": 39743
} |
{-# OPTIONS --postfix-projections #-}
{-# OPTIONS --rewriting #-}
-- A Beth model for normalization by evaluation
open import Library
module NbeModel (Base : Set) (B⦅_⦆ : Base → Set) where
import Formulas ; open module Form = Formulas Base hiding (Mon)
import Derivations ; open module Der = Derivations Base
import Interpretation; open module Intp = Interpretation Base B⦅_⦆
-- Form of Kripke predicates into a set S
KPred' : (S : Set) → Set₁
KPred' S = ∀ Γ → (C⦅ Γ ⦆ → S) → Set
-- Form of Kripke predicate on functions into type A
-- KPred A = ∀ Γ → Fun Γ A → Set
KPred : (A : Form) → Set₁
KPred A = KPred' T⦅ A ⦆
-- Pointwise inclusion of Kripke predicates
Sub : ∀ A (P Q : KPred A) → Set
Sub A P Q = ∀{Γ f} → P Γ f → Q Γ f
⟨_⟩_↪_ : ∀ A (P Q : KPred A) → Set
⟨ A ⟩ P ↪ Q = ∀{Γ f} → P Γ f → Q Γ f
_↪_ : ∀{A} (P Q : KPred A) → Set
P ↪ Q = ∀{Γ f} → P Γ f → Q Γ f
-- Conv generalizes _↪_ to move to a new proposition.
Conv : ∀{S T : Set} (f : S → T) (P : KPred' S) (Q : KPred' T) → Set
Conv {S} f P Q = ∀ {Γ} {g : C⦅ Γ ⦆ → S} (p : P Γ g) → Q Γ (f ∘ g)
⟪_⟫_↪_ = Conv
⟪_⟫₂_↪_↪_ : ∀{R S T : Set} (f : R → S → T) (𝓡 : KPred' R) (𝓢 : KPred' S) (𝓣 : KPred' T) → Set
⟪ f ⟫₂ 𝓡 ↪ 𝓢 ↪ 𝓣 = ∀{Γ g h} → 𝓡 Γ g → 𝓢 Γ h → 𝓣 Γ (λ γ → f (g γ) (h γ))
-- Statement of monotonicity for Kripke predicates
Mon : ∀{S} (𝓐 : KPred' S) → Set
Mon {S} 𝓐 = ∀ {Γ Δ} (τ : Δ ≤ Γ) {f : Fun' Γ S} → 𝓐 Γ f → 𝓐 Δ (f ∘ R⦅ τ ⦆)
-- Image under evaluation of a neutral term
NeImg : ∀ A → KPred A
NeImg A Γ f = ∃ λ (t : Ne Γ A) → Ne⦅ t ⦆ ≡ f
-- Image under evaluation of a normal term
NfImg : ∀ A → KPred A
NfImg A Γ f = ∃ λ (t : Nf Γ A) → Nf⦅ t ⦆ ≡ f
-- Being an image is Kripke (monotone in weakening)
-- ∀ (f : Fun Γ A) (τ : Δ ≤ Γ) → Img Γ A f → Img Δ A (f ∘ R⦅ τ ⦆)
monNeImg : ∀{A} → Mon (NeImg A)
monNeImg τ (t , refl) = monNe τ t , natD τ (ne[ t ])
monNfImg : ∀{A} → Mon (NfImg A)
monNfImg τ (t , refl) = monNf τ t , natD τ nf[ t ]
-- Extending the constructions of neutral and normal forms to images of such.
-- Neutrals of base type are normal
iNe : ∀{P} → NeImg (Atom P) ↪ NfImg (Atom P)
iNe (t , eq) = ne t , eq
-- Variables are neutral
iHyp : ∀{Γ A} (x : Hyp A Γ) → NeImg A Γ H⦅ x ⦆
iHyp x = (hyp x , refl)
-- Abstraction operates on normal forms
iImpI : ∀{Γ A B f} → NfImg B (Γ ∙ A) f → NfImg (A ⇒ B) Γ (curry f)
iImpI (t , eq) = impI t , cong curry eq
-- Application of a neutral is neutral
-- iImpE : NeImg (A ⇒ B) Γ f → NfImg A Γ g → NeImg B Γ (apply f g)
iImpE : ∀{A B} → ⟪ _$_ ⟫₂ NeImg (A ⇒ B) ↪ NfImg A ↪ NeImg B
iImpE (t , eq) (u , eq') = (impE t u , cong₂ apply eq eq')
-- Empty tuple is normal
iTrueI : ∀{Γ f} → NfImg True Γ f
iTrueI = trueI , refl
-- Pairing operates on normal forms
iAndI : ∀{A B} → ⟪ _,_ ⟫₂ NfImg A ↪ NfImg B ↪ NfImg (A ∧ B)
iAndI (t , eq) (u , eq') = andI t u , cong₂ <_,_> eq eq'
-- Projection of a neutral is neutral
iAndE₁ : ∀{A B} → ⟪ proj₁ ⟫ NeImg (A ∧ B) ↪ NeImg A
iAndE₁ (t , eq) = andE₁ t , cong (proj₁ ∘_) eq
iAndE₂ : ∀{A B} → ⟪ proj₂ ⟫ NeImg (A ∧ B) ↪ NeImg B
iAndE₂ (t , eq) = andE₂ t , cong (proj₂ ∘_) eq
-- Injections operate on normal forms
iOrI₁ : ∀{A B} → ⟪ inj₁ ⟫ NfImg A ↪ NfImg (A ∨ B)
iOrI₁ (t , eq) = orI₁ t , cong (inj₁ ∘_) eq
iOrI₂ : ∀{A B} → ⟪ inj₂ ⟫ NfImg B ↪ NfImg (A ∨ B)
iOrI₂ (t , eq) = orI₂ t , cong (inj₂ ∘_) eq
-- Case splitting forms:
iOrE : ∀{Γ A B C f g h}
→ NeImg (A ∨ B) Γ f
→ NfImg C (Γ ∙ A) g
→ NfImg C (Γ ∙ B) h
→ NfImg C Γ (caseof f g h)
iOrE (t , eqt) (u , equ) (v , eqv) = orE t u v , cong₃ caseof eqt equ eqv
iFalseE : ∀{C} → ⟪ ⊥-elim ⟫ NeImg False ↪ NfImg C
iFalseE (t , eq) = falseE t , cong (⊥-elim ∘_) eq
-- For falseE, we can get the stronger:
iFalseE' : ∀{Γ C f}
→ Ne Γ False
→ NfImg C Γ (⊥-elim ∘ f)
iFalseE' t = falseE t , ⊥-elim-ext
-- Cover A (P : KPred A) : KPred A is an extension of Kripke predicate P
-- (on functions into A) by case trees (whose leaves satisfy P).
data Cover (A : Form) (P : KPred A) (Δ : Cxt) : (f : Fun Δ A) → Set where
return : ∀{f} (p : P Δ f) → Cover A P Δ f
falseC : (t : Ne Δ False) → Cover A P Δ (⊥-elim ∘ Ne⦅ t ⦆)
orC : ∀{C D} (t : Ne Δ (C ∨ D))
{g} (cg : Cover A P (Δ ∙ C) g)
{h} (ch : Cover A P (Δ ∙ D) h) → Cover A P Δ (caseof Ne⦅ t ⦆ g h)
-- Cover is monotone in P
mapC : ∀{A} {P Q : KPred A} (P⊂Q : ⟨ A ⟩ P ↪ Q) → ⟨ A ⟩ Cover A P ↪ Cover A Q
mapC P⊂Q (return p) = return (P⊂Q p)
mapC P⊂Q (falseC t) = falseC t
mapC P⊂Q (orC t cg ch) = orC t (mapC P⊂Q cg) (mapC P⊂Q ch)
-- Case trees can be composed, which makes Cover A a monad
-- in the category of kripke predicates KPred A and their embeddings
-- ⟨ A ⟩.
joinC : ∀{A} {P : KPred A} → ⟨ A ⟩ Cover A (Cover A P) ↪ Cover A P
joinC (return c) = c
joinC (falseC t) = falseC t
joinC (orC t cg ch) = orC t (joinC cg) (joinC ch)
-- Weakening covers (Cover preserves Kripke)
-- (τ : Δ ≤ Γ) → Cover A Γ P f → Cover A Δ P (f ∘ R⦅ τ ⦆)
monC : ∀{A} {P : KPred A} (monP : Mon P) → Mon (Cover A P)
monC monP τ (return p) = return (monP τ p)
monC monP τ (falseC t) = subst (Cover _ _ _) ⊥-elim-ext (falseC (monNe τ t))
monC monP τ (orC t cg ch) = orC (monNe τ t) (monC monP (lift τ) cg) (monC monP (lift τ) ch)
-- REWRITE monD-ne natD
-- Converting covers to a new target proposition
-- A (simple) converter for covers (pointwise in the context)
convC : ∀{A B} (g : T⦅ A ⦆ → T⦅ B ⦆) {P Q} (P⊂Q : ⟪ g ⟫ P ↪ Q) → ⟪ g ⟫ Cover A P ↪ Cover B Q
convC g P⊂Q (return p) = return (P⊂Q p)
convC g P⊂Q (falseC t) = subst (Cover _ _ _) ⊥-elim-ext (falseC t)
convC g P⊂Q (orC t cg ch) = subst (Cover _ _ _) (caseof-perm g {Ne⦅ t ⦆})
(orC t (convC g P⊂Q cg) (convC g P⊂Q ch))
-- A general converter going to a new target proposition and an extended context at the same time.
-- (subsumes mapC, monC, convC).
record Converter A B (P : KPred A) (Q : KPred B) {Γ₀ Δ₀} (τ₀ : Δ₀ ≤ Γ₀) : Set where
field
-- Conversion functional
φ : ∀ {Γ Δ} (δ : Δ ≤ Δ₀) (τ : Δ ≤ Γ) → Fun Γ A → Fun Δ B
-- φ distributes over case
φ-case : ∀ {Γ Δ} (δ : Δ ≤ Δ₀) (τ : Δ ≤ Γ) →
∀ C D (f : Fun Γ (C ∨ D)) (g : Fun (Γ ∙ C) A) (h : Fun (Γ ∙ D) A)
→ caseof (f ∘ R⦅ τ ⦆) (φ (weak δ) (lift {C} τ) g)
(φ (weak δ) (lift {D} τ) h) ≡ φ δ τ (caseof f g h)
-- φ transports from P to Q
P⊂Q : ∀{Γ Δ} (δ : Δ ≤ Δ₀) (τ : Δ ≤ Γ) {f} → P Γ f → Q Δ (φ δ τ f)
-- The conversion is implemented by recursion over the case tree
module _ A B (P : KPred A) (Q : KPred B) {Γ₀ Δ₀} (τ₀ : Δ₀ ≤ Γ₀)
(conv : Converter A B P Q τ₀) (open Converter conv) where
convCov : ∀{Γ Δ} (δ : Δ ≤ Δ₀) (τ : Δ ≤ Γ) {f} → Cover A P Γ f → Cover B Q Δ (φ δ τ f)
convCov {Γ} {Δ} δ τ (return p) = return (P⊂Q δ τ p)
convCov {Γ} {Δ} δ τ (falseC t) = subst (Cover _ _ _) ⊥-elim-ext (falseC (monNe τ t))
convCov {Γ} {Δ} δ τ (orC {C} {D} t {g} cg {h} ch) =
subst (Cover _ _ _)
(φ-case δ τ C D Ne⦅ t ⦆ g h)
(orC (monNe τ t)
(convCov (weak δ) (lift {C} τ) cg)
(convCov (weak δ) (lift {D} τ) ch))
-- Just for documentation:
where
τC = lift {C} τ
cg' : Cover B Q (Δ ∙ C) (φ (weak δ) τC g)
cg' = convCov (weak δ) τC cg
τD = lift {D} τ
ch' : Cover B Q (Δ ∙ D) (φ (weak δ) τD h)
ch' = convCov (weak δ) τD ch
c' : Cover B Q Δ (caseof (Ne⦅ t ⦆ ∘ R⦅ τ ⦆) (φ (weak δ) τC g) (φ (weak δ) τD h))
c' = orC (monNe τ t) cg' ch'
-- Implementations in terms of convCov (all need monotonicity of P)
-- Cover is monotone in P
mapCᶜ : ∀{A} {P Q : KPred A} (monP : Mon P) (P⊂Q : ⟨ A ⟩ P ↪ Q) → ⟨ A ⟩ Cover A P ↪ Cover A Q
mapCᶜ {A} {P} {Q} monP P⊂Q {Γ} {f} c = convCov A A P Q id≤ conv id≤ id≤ c
where
conv : Converter A A P Q ( id≤ {Γ})
conv = record
{ φ = λ δ τ f → f ∘ R⦅ τ ⦆
; φ-case = λ δ τ C D f g h → refl
; P⊂Q = λ δ τ ⟦f⟧ → P⊂Q (monP τ ⟦f⟧)
}
-- Weakening Covers
monCᶜ : ∀{A} {P : KPred A} (monP : Mon P) → Mon (Cover A P)
monCᶜ {A} {P} monP {Γ} {Δ} τ {f} c = convCov A A P P id≤ conv id≤ τ c
where
conv : Converter A A P P id≤
conv = record
{ φ = λ δ τ f → f ∘ R⦅ τ ⦆
; φ-case = λ δ τ C D f g h → refl
; P⊂Q = λ δ τ ⟦f⟧ → monP τ ⟦f⟧
}
-- A converter for covers (pointwise in the context)
convCᶜ : ∀{A B} (g : T⦅ A ⦆ → T⦅ B ⦆) {P Q} (monP : Mon P) (P⊂Q : ⟪ g ⟫ P ↪ Q) → ⟪ g ⟫ Cover A P ↪ Cover B Q
convCᶜ {A} {B} g₀ {P} {Q} monP P⊂Q {Γ} {f} p = convCov A B P Q id≤ conv id≤ id≤ p
where
conv : Converter A B P Q id≤
conv = record
{ φ = λ δ τ f → g₀ ∘ f ∘ R⦅ τ ⦆
; φ-case = λ δ τ C D f g h → caseof-perm g₀ {f ∘ R⦅ τ ⦆}
; P⊂Q = λ δ τ ⟦f⟧ → P⊂Q (monP τ ⟦f⟧)
}
-- Syntactic paste:
-- a case tree over normal forms is a normal form.
pasteNf : ∀{A} → ⟨ A ⟩ Cover A (NfImg A) ↪ NfImg A
pasteNf (return t) = t
pasteNf (falseC t) = iFalseE (t , refl)
pasteNf (orC t cg ch) = iOrE (t , refl) (pasteNf cg) (pasteNf ch)
-- Bicartesian closure of KPred
-- Semantic absurdity type (initial object)
Absurd : KPred False
Absurd _ _ = ⊥
-- Semantic disjunction type (coproduct)
data Disj A B (⟦A⟧ : KPred A) (⟦B⟧ : KPred B) Γ : Fun Γ (A ∨ B) → Set where
left : {g : Fun Γ A} (⟦g⟧ : ⟦A⟧ Γ g) → Disj _ _ _ _ _ (inj₁ ∘ g)
right : {h : Fun Γ B} (⟦h⟧ : ⟦B⟧ Γ h) → Disj _ _ _ _ _ (inj₂ ∘ h)
monDisj : ∀{A B ⟦A⟧ ⟦B⟧} (monA : Mon ⟦A⟧) (monB : Mon ⟦B⟧) → Mon (Disj A B ⟦A⟧ ⟦B⟧)
monDisj monA monB τ (left ⟦g⟧) = left (monA τ ⟦g⟧)
monDisj monA monB τ (right ⟦h⟧) = right (monB τ ⟦h⟧)
-- Semantic truth type (terminal object)
Truth : KPred True
Truth _ _ = ⊤
-- Semantic conjunction type (product)
Conj : ∀ A B (⟦A⟧ : KPred A) (⟦B⟧ : KPred B) → KPred (A ∧ B)
Conj A B ⟦A⟧ ⟦B⟧ Γ f = ⟦A⟧ Γ (proj₁ ∘ f) × ⟦B⟧ Γ (proj₂ ∘ f)
-- Semantic implication type (exponential)
Imp : ∀ A B (⟦A⟧ : KPred A) (⟦B⟧ : KPred B) → KPred (A ⇒ B)
Imp A B ⟦A⟧ ⟦B⟧ Γ f = ∀{Δ} (τ : Δ ≤ Γ) {a : Fun Δ A} (⟦a⟧ : ⟦A⟧ Δ a) → ⟦B⟧ Δ (kapp A B f τ a)
-- The Beth model
T⟦_⟧ : (A : Form) → KPred A
T⟦ Atom P ⟧ = NfImg (Atom P)
T⟦ True ⟧ = Truth
T⟦ False ⟧ = Cover False Absurd
T⟦ A ∨ B ⟧ = Cover (A ∨ B) (Disj A B (T⟦ A ⟧) (T⟦ B ⟧))
T⟦ A ∧ B ⟧ = Conj A B T⟦ A ⟧ T⟦ B ⟧
T⟦ A ⇒ B ⟧ = Imp A B T⟦ A ⟧ T⟦ B ⟧
-- Monotonicity of semantics
-- (τ : Δ ≤ Γ) → T⟦ A ⟧ Γ f → T⟦ A ⟧ Δ (f ∘ R⦅ τ ⦆)
monT : ∀ A → Mon T⟦ A ⟧
monT (Atom P) = monNfImg
monT True = _
monT False = monC λ _ ()
monT (A ∨ B) = monC (monDisj (monT A) (monT B))
monT (A ∧ B) τ = monT A τ ×̇ monT B τ
monT (A ⇒ B) τ f σ = f (σ • τ)
-- Reflection / reification
mutual
reflect : ∀ A → ⟨ A ⟩ NeImg A ↪ T⟦ A ⟧
reflect (Atom P) = iNe
reflect True = _
reflect False (t , _) = subst (Cover _ _ _) ⊥-elim-ext (falseC t)
-- x : A ∨ B is reflected as case(x, y. inl y, z. inr z)
-- Need a proof of caseof x inj₁ inj₂ = x
reflect (A ∨ B) (t , refl) = subst (Cover _ _ _) (caseof-eta Ne⦅ t ⦆)
(orC t (return (left (reflect A (iHyp top))))
(return (right (reflect B (iHyp top)))))
reflect (A ∧ B) i = reflect A (iAndE₁ i) , reflect B (iAndE₂ i)
reflect (A ⇒ B) i τ a = reflect B (iImpE (monNeImg τ i) (reify A a))
reify : ∀ A → ⟨ A ⟩ T⟦ A ⟧ ↪ NfImg A
reify (Atom P) = id
reify True _ = iTrueI
reify False = pasteNf ∘ mapC λ()
reify (A ∨ B) = pasteNf ∘ mapC reifyDisj
reify (A ∧ B) (a , b) = iAndI (reify A a) (reify B b)
reify (A ⇒ B) ⟦f⟧ = iImpI (reify B (⟦f⟧ (weak id≤) (reflect A (iHyp top))))
reifyDisj : ∀{A B} → ⟨ A ∨ B ⟩ Disj A B T⟦ A ⟧ T⟦ B ⟧ ↪ NfImg (A ∨ B)
reifyDisj {A} {B} (left ⟦g⟧) = iOrI₁ (reify A ⟦g⟧)
reifyDisj {A} {B} (right ⟦h⟧) = iOrI₂ (reify B ⟦h⟧)
-- Semantic paste
paste : ∀ A → ⟨ A ⟩ Cover A (T⟦ A ⟧) ↪ T⟦ A ⟧
paste (Atom P) = pasteNf
paste True = _
paste False = joinC
paste (A ∨ B) = joinC
paste (A ∧ B) = < paste A ∘ convC proj₁ proj₁ , paste B ∘ convC proj₂ proj₂ >
paste (A ⇒ B) {Γ₀} {f} c {Δ₀} τ₀ {a} ⟦a⟧ = paste B (convCov (A ⇒ B) B P Q τ₀ record{Conv} id≤ τ₀ c)
where
P = Imp A B T⟦ A ⟧ T⟦ B ⟧
Q = T⟦ B ⟧
module Conv where
φ : ∀ {Γ Δ} (δ : Δ ≤ Δ₀) (τ : Δ ≤ Γ) → Fun Γ (A ⇒ B) → Fun Δ B
φ δ τ f = kapp A B f τ (a ∘ R⦅ δ ⦆)
P⊂Q : ∀ {Γ Δ} (δ : Δ ≤ Δ₀) (τ : Δ ≤ Γ) {f} → P Γ f → Q Δ (φ δ τ f)
P⊂Q δ τ ⟦f⟧ = ⟦f⟧ τ (monT A δ ⟦a⟧)
φ-case : ∀ {Γ Δ} (δ : Δ ≤ Δ₀) (τ : Δ ≤ Γ) →
∀ C D (f : Fun Γ (C ∨ D)) (g : Fun (Γ ∙ C) (A ⇒ B)) (h : Fun (Γ ∙ D) (A ⇒ B))
→ caseof (f ∘ R⦅ τ ⦆) (φ (weak δ) (lift {C} τ) g)
(φ (weak δ) (lift {D} τ) h) ≡ φ δ τ (caseof f g h)
φ-case δ τ C D f g h = caseof-kapply f g h R⦅ τ ⦆ (a ∘ R⦅ δ ⦆)
-- Fundamental theorem
-- Extension of T⟦_⟧ to contexts
G⟦_⟧ : ∀ Γ → KPred' C⦅ Γ ⦆
G⟦ ε ⟧ Δ ρ = ⊤
G⟦ Γ ∙ A ⟧ Δ ρ = G⟦ Γ ⟧ Δ (proj₁ ∘ ρ) × T⟦ A ⟧ Δ (proj₂ ∘ ρ)
-- monG : ∀{Γ Δ Φ ρ} (τ : Φ ≤ Δ) → G⟦ Γ ⟧ Δ ρ → G⟦ Γ ⟧ Φ (ρ ∘ R⦅ τ ⦆)
monG : ∀{Γ} → Mon G⟦ Γ ⟧
monG {ε} τ _ = _
monG {Γ ∙ A} τ (γ , a) = monG τ γ , monT A τ a
-- Variable case
-- fundH : (x : Hyp A Γ) (γ : G⟦ Γ ⟧ Δ ρ) → T⟦ A ⟧ Δ (H⦅ x ⦆ ∘ ρ)
fundH : ∀{Γ A} (x : Hyp A Γ) → ⟪ H⦅ x ⦆ ⟫ G⟦ Γ ⟧ ↪ T⟦ A ⟧
fundH top = proj₂
fundH (pop x) = fundH x ∘ proj₁
-- orE case
orElim : ∀ E {Γ A B}
{f} (⟦f⟧ : T⟦ A ∨ B ⟧ Γ f)
{g} (⟦g⟧ : T⟦ A ⇒ E ⟧ Γ g)
{h} (⟦h⟧ : T⟦ B ⇒ E ⟧ Γ h) →
T⟦ E ⟧ Γ (caseof f (uncurry g) (uncurry h))
orElim E {Γ₀} {A} {B} ⟦f⟧ {g} ⟦g⟧ {h} ⟦h⟧ = paste E
(convCov (A ∨ B) E P Q {Γ₀} id≤ record{Conv} id≤ id≤ ⟦f⟧)
where
P = Disj A B T⟦ A ⟧ T⟦ B ⟧
Q = T⟦ E ⟧
module Conv where
φ : ∀ {Γ Δ} (δ : Δ ≤ Γ₀) (τ : Δ ≤ Γ) → Fun Γ (A ∨ B) → Fun Δ E
φ δ τ f = caseof (f ∘ R⦅ τ ⦆) (uncurry (g ∘ R⦅ δ ⦆)) (uncurry (h ∘ R⦅ δ ⦆ ))
P⊂Q : ∀{Γ Δ} (δ : Δ ≤ Γ₀) (τ : Δ ≤ Γ) {f} → P Γ f → Q Δ (φ δ τ f)
P⊂Q δ τ (left ⟦a⟧) = ⟦g⟧ δ (monT A τ ⟦a⟧)
P⊂Q δ τ (right ⟦b⟧) = ⟦h⟧ δ (monT B τ ⟦b⟧)
φ-case : ∀ {Γ Δ} (δ : Δ ≤ Γ₀) (τ : Δ ≤ Γ) →
∀ C D (k : Fun Γ (C ∨ D)) (i : Fun (Γ ∙ C) (A ∨ B)) (j : Fun (Γ ∙ D) (A ∨ B)) →
caseof (k ∘ R⦅ τ ⦆) (φ (weak δ) (lift {C} τ) i)
(φ (weak δ) (lift {D} τ) j)
≡ φ δ τ (caseof k i j)
φ-case δ τ C D k i j =
caseof-swap
(k ∘ R⦅ τ ⦆)
(uncurry (curry i ∘ R⦅ τ ⦆))
(uncurry (curry j ∘ R⦅ τ ⦆))
(g ∘ R⦅ δ ⦆)
(h ∘ R⦅ δ ⦆)
-- A lemma for the falseE case
falseElim : ∀ A → ⟪ ⊥-elim ⟫ T⟦ False ⟧ ↪ T⟦ A ⟧
falseElim A = paste A ∘ convC ⊥-elim ⊥-elim
-- The fundamental theorem
-- fund : ∀{A Γ} (t : Γ ⊢ A) {Δ ρ} (γ : G⟦ Γ ⟧ Δ ρ) → T⟦ A ⟧ Δ (D⦅ t ⦆ ∘ ρ)
fund : ∀{A Γ} (t : Γ ⊢ A) → ⟪ D⦅ t ⦆ ⟫ G⟦ Γ ⟧ ↪ T⟦ A ⟧
fund (hyp x) = fundH x
fund (impI t) γ τ a = fund t (monG τ γ , a)
fund (impE t u) γ = fund t γ id≤ (fund u γ)
fund (andI t u) = < fund t , fund u >
fund (andE₁ t) = proj₁ ∘ fund t
fund (andE₂ t) = proj₂ ∘ fund t
fund (orI₁ t) γ = return (left (fund t γ))
fund (orI₂ t) γ = return (right (fund t γ))
fund {A} (orE t u v) γ = orElim A (fund t γ)
(λ τ a → fund u (monG τ γ , a))
(λ τ b → fund v (monG τ γ , b))
fund {A} (falseE t) γ = falseElim A (fund t γ)
fund trueI γ = _
-- Identity environment
ide : ∀ Γ → G⟦ Γ ⟧ Γ id
ide ε = _
ide (Γ ∙ A) = monG (weak id≤) (ide Γ) , reflect A (iHyp top)
-- Normalization by evaluation
norm : ∀{Γ A} (t : Γ ⊢ A) → NfImg A Γ D⦅ t ⦆
norm t = reify _ (fund t (ide _))
-- -}
-- -}
| {
"alphanum_fraction": 0.5033867396,
"avg_line_length": 32.0542797495,
"ext": "agda",
"hexsha": "e6278107ff71b14259b276b720e4151c0ddec866",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-02-25T20:39:03.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-11-13T16:01:46.000Z",
"max_forks_repo_head_hexsha": "9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "andreasabel/ipl",
"max_forks_repo_path": "src/NbeModel.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "andreasabel/ipl",
"max_issues_repo_path": "src/NbeModel.agda",
"max_line_length": 108,
"max_stars_count": 19,
"max_stars_repo_head_hexsha": "9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "andreasabel/ipl",
"max_stars_repo_path": "src/NbeModel.agda",
"max_stars_repo_stars_event_max_datetime": "2021-04-27T19:10:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-05-16T08:08:51.000Z",
"num_tokens": 7394,
"size": 15354
} |
--------------------------------------------------------------------------------
-- This is part of Agda Inference Systems
{-# OPTIONS --sized-types #-}
open import Relation.Nullary
open import Relation.Nullary.Decidable
open import Data.Nat
open import Data.Vec
open import Data.Fin
open import Data.Product
open import Data.Sum
open import Data.Bool
open import Data.Unit
open import Data.Empty
open import Relation.Binary.PropositionalEquality
open import Relation.Binary.Construct.Closure.ReflexiveTransitive
open import Size
open import Codata.Thunk
open import Axiom.ExcludedMiddle
open import Level renaming (zero to ∅ ; suc to ++)
open import is-lib.SInfSys as IS
open import Examples.Lambda.Lambda
open import Examples.Lambda.BigStep renaming (U to BigStepU)
open import Examples.Lambda.SmallStep
module Examples.Lambda.Proofs where
Spec : BigStepU → Set
Spec (e , res x) = e ⇒* term x
Spec (e , div) = ∀{i} → ⇒∞ e i
{- Soundness -}
Spec-val : BigStepU → Set
Spec-val (e , v) = ∀{v'} → v ≡ res v' → Spec (e , v)
Spec-closed : ISClosed (BigStepIS ∪ BigStepCOIS) Spec-val
Spec-closed (inj₁ VAL) _ _ refl = ε
Spec-closed (inj₁ APP) _ prem refl =
let s-e1 = prem zero refl in
let s-e2 = prem (suc zero) refl in
let s-subst = prem (suc (suc zero)) refl in
let subst = IS.fold (β , _ , refl , λ ()) in
inj-l-app _ (prem zero refl) ◅◅ inj-r-app _ (prem (suc zero) refl) ◅◅ subst ◅ prem (suc (suc zero)) refl
Spec-closed (inj₂ COA) s_ _ ()
⇓ᵢ-to-⇒* : ∀{e v} → e ⇓ᵢ v → Spec-val (e , v)
⇓ᵢ-to-⇒* = ind[ BigStepIS ∪ BigStepCOIS ] Spec-val Spec-closed
bs-sound-v : ∀{e v} → (∀{i} → (e ⇓ (res v)) i) → e ⇒* (term v)
bs-sound-v r = ⇓ᵢ-to-⇒* (sfcoind-to-ind r) refl
subject-red-⇓ : ∀{e e' v} → (∀{i} → (e ⇓ v) i) → e ⇒ e' → (∀{i} → (e' ⇓ v) i)
subject-red-⇓ bs (fold (β , (e , v) , eq , _)) with bs
subject-red-⇓ bs (fold (β , (e , v) , () , _)) | sfold (VAL , (lambda x , _) , refl , prem)
subject-red-⇓ bs (fold (β , (e , lambda x) , refl , _)) | sfold (APP , ((.(lambda e) , _ , .(lambda x) , v , _) , _) , refl , prem)
with val-⇓-≡ (prem zero .force) | val-⇓-≡ (prem (suc zero) .force)
subject-red-⇓ bs (fold (β , (e , lambda x) , refl , _)) | sfold (APP , ((.(lambda e) , .e , .(lambda x) , .(lambda x) , _) , _) , refl , prem) | refl | refl = prem (suc (suc zero)) .force
subject-red-⇓ bs (fold (β , (e , v) , refl , _)) | sfold (L-DIV , _ , refl , prem) = ⊥-elim (val-not-reduce⇓ (prem zero .force))
subject-red-⇓ bs (fold (β , (e , v) , refl , _)) | sfold (R-DIV , _ , refl , prem) = ⊥-elim (val-not-reduce⇓ (prem (suc zero) .force))
subject-red-⇓ bs (fold (L-APP , c , eq , _)) with bs
subject-red-⇓ bs (fold (L-APP , _ , () , _)) | sfold (VAL , (lambda _ , _) , refl , _)
subject-red-⇓ bs (fold (L-APP , (e1 , e1' , e2) , refl , pr)) | sfold (APP , ((.e1 , e1'' , .e2 , lambda _ , _) , ind) , refl , prem) =
let rec = subject-red-⇓ (prem zero .force) (pr zero) in
let prems = λ{zero → rec ; (suc zero) → prem (suc zero) .force ; (suc (suc zero)) → prem (suc (suc zero)) .force} in
apply-sfcoind APP _ prems
subject-red-⇓ bs (fold (L-APP , (e1 , e1' , e2) , refl , pr)) | sfold (L-DIV , ((.e1 , .e2) , ind) , refl , prem) =
let rec = subject-red-⇓ (prem zero .force) (pr zero) in
apply-sfcoind L-DIV _ λ{zero → rec}
subject-red-⇓ bs (fold (L-APP , (e1 , e1' , e2) , refl , pr)) | sfold (R-DIV , ((.e1 , .e2 , lambda v) , ind) , refl , prem) =
let rec = subject-red-⇓ (prem zero .force) (pr zero) in
let prems = λ{zero → rec ; (suc zero) → prem (suc zero) .force} in
apply-sfcoind R-DIV _ prems
subject-red-⇓ bs (fold (R-APP , (lambda _ , e2 , e2') , eq , pr)) with bs
subject-red-⇓ bs (fold (R-APP , (lambda _ , _ , _) , refl , _)) | sfold (VAL , (lambda _ , _) , () , _)
subject-red-⇓ bs (fold (R-APP , (lambda e1 , e2 , e2') , refl , pr)) | sfold (APP , ((.(lambda _) , e1' , .e2 , lambda _ , _) , ind) , refl , prem)
with val-⇓-≡ (prem zero .force)
subject-red-⇓ bs (fold (R-APP , (lambda e1 , e2 , e2') , refl , pr)) | sfold (APP , ((.(lambda e1) , .e1 , .e2 , lambda _ , _) , ind) , refl , prem) | refl =
let rec = subject-red-⇓ (prem (suc zero) .force) (pr zero) in
let prems = λ{zero → prem zero .force ; (suc zero) → rec ; (suc (suc zero)) → prem (suc (suc zero)) .force} in
apply-sfcoind APP _ prems
subject-red-⇓ bs (fold (R-APP , (lambda _ , e2 , e2') , refl , _)) | sfold (L-DIV , ((.(lambda _) , .e2) , _) , refl , prem) = ⊥-elim (val-not-reduce⇓ (prem zero .force))
subject-red-⇓ bs (fold (R-APP , (lambda e , e2 , e2') , refl , pr)) | sfold (R-DIV , ((.(lambda e) , .e2 , v) , ind) , refl , prem) with val-⇓-≡ (prem zero .force)
subject-red-⇓ bs (fold (R-APP , (lambda e , e2 , e2') , refl , pr)) | sfold (R-DIV , ((.(lambda e) , .e2 , .(lambda e)) , ind) , refl , prem) | refl =
let rec = subject-red-⇓ (prem (suc zero) .force) (pr zero) in
let prems = λ{zero → prem zero .force ; (suc zero) → rec} in
apply-sfcoind R-DIV _ prems
progress : ∀{e} →(∀{i} → (e ⇓ div) i) → Σ[ e' ∈ Term 0 ] (e ⇒ e')
progress {e} bs with bs
progress bs | sfold (APP , _ , refl , prem) with bs-sound-v (prem zero .force)
progress bs | sfold (APP , ((_ , e1' , _ , _ , .div) , _) , refl , prem) | ε with bs-sound-v (prem (suc zero) .force)
progress bs | sfold (APP , ((.(lambda e1') , e1' , _ , v , .div) , _) , refl , prem) | ε | ε =
_ , apply-ind β _ λ ()
progress bs | sfold (APP , ((.(lambda e1') , e1' , e2 , _ , .div) , _) , refl , prem) | ε | x ◅ _ =
app (lambda e1') _ , apply-ind R-APP _ λ{zero → x}
progress bs | sfold (APP , ((e1 , _ , e2 , _ , .div) , _) , refl , prem) | x ◅ _ =
app _ e2 , apply-ind L-APP _ λ{zero → x}
progress bs | sfold (L-DIV , ((e1 , e2) , _) , refl , prem) =
let e1' , e1⇒e1' = progress (prem zero .force) in
app e1' e2 , apply-ind L-APP _ λ{zero → e1⇒e1'}
progress bs | sfold (R-DIV , ((e1 , e2 , v) , _) , refl , prem) with bs-sound-v (prem zero .force)
progress bs | sfold (R-DIV , ((.(term _) , e2 , (lambda e)) , _) , refl , prem) | ε =
let e2' , e2⇒e2' = progress (prem (suc zero) .force) in
app (lambda e) e2' , apply-ind R-APP _ λ{zero → e2⇒e2'}
progress bs | sfold (R-DIV , ((e1 , e2 , (lambda e)) , _) , refl , prem) | x ◅ _ =
app _ e2 , apply-ind L-APP _ λ{zero → x}
bs-sound-∞ : ∀{e} → (∀{i} → (e ⇓ div) i) → (∀{i} → ⇒∞ e i)
bs-sound-∞ bs with progress bs
... | e' , ss = step ss λ where .force → bs-sound-∞ (subject-red-⇓ bs ss)
bs-sound : ∀{e v} → (∀{i} → (e ⇓ v) i) → Spec (e , v)
bs-sound {_} {res _} = bs-sound-v
bs-sound {_} {div} = bs-sound-∞
{- Completeness -}
inv-app : ∀{e1 e2 v} → (app e1 e2) ⇓ᵢ (res v) →
Σ[ e1' ∈ Term 1 ] Σ[ e2' ∈ Value ]
(e1 ⇓ᵢ res (lambda e1')) ×
(e2 ⇓ᵢ (res e2')) ×
(subst-0 e1' (term e2') ⇓ᵢ res v)
-- Using consistency of inductive interpretation
inv-app bs with ind-postfix bs
inv-app bs | inj₁ VAL , lambda _ , () , _
inv-app bs | inj₁ APP , _ , refl , pr = _ , _ , pr zero , pr (suc zero) , pr (suc (suc zero))
inv-app bs | inj₂ COA , _ , () , _
subject-exp : ∀{e e' v} → e ⇒ e' → e' ⇓ᵢ v → e ⇓ᵢ v
subject-exp {.(app (lambda e1) (term v))} {_} {v'} (fold (β , (e1 , v) , refl , _)) bs =
let prem-e1 = IS.fold (inj₁ VAL , lambda e1 , refl , λ ()) in
let prem-e2 = IS.fold (inj₁ VAL , v , refl , λ ()) in
let prems = λ{zero → prem-e1 ; (suc zero) → prem-e2 ; (suc (suc zero)) → bs} in
apply-ind (inj₁ APP) _ prems
subject-exp {.(app e1 e2)} {.(app e1' e2)} {res x} (fold (L-APP , (e1 , e1' , e2) , refl , pr)) bs =
let e1'' , e2' , bs-e1' , bs-e2 , bs-subst = inv-app bs in
let prems = λ{zero → subject-exp (pr zero) bs-e1' ; (suc zero) → bs-e2 ; (suc (suc zero)) → bs-subst} in
apply-ind (inj₁ APP) _ prems
subject-exp {.(app e1 e2)} {.(app e1' e2)} {div} (fold (L-APP , (e1 , e1' , e2) , refl , pr)) bs =
apply-ind (inj₂ COA) _ λ ()
subject-exp {.(app (term v) e2)} {.(app (term v) e2')} {res x} (fold (R-APP , (v , e2 , e2') , refl , pr)) bs =
let e1' , e2'' , bs-e1 , bs-e2' , bs-subst = inv-app bs in
let prems = λ{zero → bs-e1 ; (suc zero) → subject-exp (pr zero) bs-e2' ; (suc (suc zero)) → bs-subst} in
apply-ind (inj₁ APP) _ prems
subject-exp {.(app (term v) e2)} {.(app (term v) e2')} {div} (fold (R-APP , (v , e2 , e2') , refl , _)) bs =
apply-ind (inj₂ COA) _ λ ()
bounded-v : ∀{e v} → e ⇒* term v → e ⇓ᵢ res v
bounded-v ε = apply-ind (inj₁ VAL) _ λ ()
bounded-v (x ◅ ss) = subject-exp x (bounded-v ss)
bounded-∞ : ∀{e} → (∀{i} → ⇒∞ e i) → e ⇓ᵢ div
bounded-∞ {e} ss = apply-ind (inj₂ COA) _ λ ()
bounded : ∀{e v} → Spec (e , v) → e ⇓ᵢ v
bounded {_} {res _} = bounded-v
bounded {_} {div} = bounded-∞
get-prem-cons : ∀{e1 e2 v} → app e1 e2 ⇒* (term v) →
Σ[ e1' ∈ Term 1 ] Σ[ e2' ∈ Value ]
(e1 ⇒* lambda e1') ×
(e2 ⇒* term e2') ×
(subst-0 e1' (term e2') ⇒* (term v))
get-prem-cons {.(lambda e1)} {.(term v)} {lambda _} (fold (β , (e1 , v) , refl , _) ◅ ss) =
e1 , v , ε , ε , ss
get-prem-cons {.e1} {.e2} {lambda _} (fold (L-APP , (e1 , e1' , e2) , refl , pr) ◅ ss) =
let e1'' , e2' , rec-e1' , rec-e2 , rec-subst = get-prem-cons ss in
e1'' , e2' , pr zero ◅ rec-e1' , rec-e2 , rec-subst
get-prem-cons {.(term v)} {.e2} {lambda _} (fold (R-APP , (v , e2 , e2') , refl , pr) ◅ ss) =
let e1' , e2'' , rec-e1 , rec-e2' , rec-subst = get-prem-cons ss in
e1' , e2'' , rec-e1 , pr zero ◅ rec-e2' , rec-subst
consistent-v : ∀{e v} → e ⇒* term v → IS.ISF[ BigStepIS ] Spec (e , res v)
consistent-v {.(lambda _)} {lambda _} ε = VAL , _ , refl , λ ()
consistent-v {lambda _} {lambda _} (x ◅ ss) = ⊥-elim (val-not-reduce⇒ x)
consistent-v {app e1 e2} {lambda _} (x ◅ ss) =
let e1' , e2' , e1⇒* , e2⇒* , subst⇒* = get-prem-cons (x ◅ ss) in
let prems = λ{zero → e1⇒* ; (suc zero) → e2⇒* ; (suc (suc zero)) → subst⇒*} in
APP , (e1 , e1' , e2 , e2' , _) , refl , prems
postulate
excluded-middle : ExcludedMiddle ∅
lemma-divergence : ∀{e1 e2} → (∀{i} → ⇒∞ (app e1 e2) i) →
(∀{i} → ⇒∞ e1 i) ⊎
e1 ConvergesSS × (∀{i} → ⇒∞ e2 i) ⊎
Σ[ t1 ∈ Term 1 ] Σ[ v ∈ Value ] (e1 ⇒* lambda t1) × (e2 ⇒* term v) × (∀{i} → ⇒∞ (subst-0 t1 (term v)) i)
lemma-divergence {e1} {e2} ss with excluded-middle {e1 ConvergesSS}
lemma-divergence {e1} {e2} ss | no ¬e1-conv = inj₁ (div-app-l-not-conv ss ¬e1-conv)
lemma-divergence {e1} {e2} ss | yes e1-conv with excluded-middle {e2 ConvergesSS}
lemma-divergence {e1} {e2} ss | yes e1-conv | no ¬e2-conv =
inj₂ (inj₁ (e1-conv , div-app-r-not-conv ss (proj₂ e1-conv) ¬e2-conv))
lemma-divergence {e1} {e2} ss | yes (lambda _ , red-e1) | yes (_ , red-e2) =
inj₂ (inj₂ (_ , _ , ( red-e1 , red-e2 , app-subst-⇒∞₁ red-e1 red-e2 ss)))
consistent-∞ : ∀{e} → (∀{i} → ⇒∞ e i) → IS.ISF[ BigStepIS ] Spec (e , div)
consistent-∞ {e} ss with ss
consistent-∞ {lambda e} ss | step x _ = ⊥-elim (val-not-reduce⇒ x)
consistent-∞ {app e₁ e₂} ss | step x x₁ with lemma-divergence (step x x₁)
consistent-∞ {app e₁ e₂} ss | step x x₁ | inj₁ e1-div =
L-DIV , _ , refl , λ{zero → e1-div}
consistent-∞ {app e₁ e₂} ss | step x x₁ | inj₂ (inj₁ (e1-conv , e2-div)) =
R-DIV , _ , refl , λ{zero → proj₂ e1-conv ; (suc zero) → e2-div}
consistent-∞ {app e₁ e₂} ss | step x x₁ | inj₂ (inj₂ (_ , _ , red-e1 , red-e2 , subst-div)) =
APP , _ , refl , λ{zero → red-e1 ; (suc zero) → red-e2 ; (suc (suc zero)) → subst-div}
consistent : ∀{e v} → Spec (e , v) → IS.ISF[ BigStepIS ] Spec (e , v)
consistent {_} {res _} = consistent-v
consistent {_} {div} = consistent-∞
complete : ∀{e v} → Spec (e , v) → (∀{i} → (e ⇓ v) i)
complete = bounded-scoind[ BigStepIS , BigStepCOIS ] Spec bounded consistent | {
"alphanum_fraction": 0.543167913,
"avg_line_length": 54.9906542056,
"ext": "agda",
"hexsha": "ccd82eab8df23d5e296cc6df41b362b5f618d3b7",
"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": "b9043f99e4bf7211db4066a7a943401d127f0c8f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "LcicC/inference-systems-agda",
"max_forks_repo_path": "Examples/Lambda/Proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b9043f99e4bf7211db4066a7a943401d127f0c8f",
"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": "LcicC/inference-systems-agda",
"max_issues_repo_path": "Examples/Lambda/Proofs.agda",
"max_line_length": 189,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "b9043f99e4bf7211db4066a7a943401d127f0c8f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "LcicC/inference-systems-agda",
"max_stars_repo_path": "Examples/Lambda/Proofs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-25T15:48:52.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-03-10T15:53:47.000Z",
"num_tokens": 4947,
"size": 11768
} |
{-# OPTIONS --cubical --safe #-}
module Container.Polynomial where
open import Prelude hiding (id; const; _×_; Π; _⊎_; Σ; _∘_; ⊤; ⊥)
open import Data.Unit.UniversePolymorphic
open import Data.Empty.UniversePolymorphic
import Prelude as P
open import Container
module _ {s p : Level} where
id : Container s p
id .fst = ⊤
id .snd _ = ⊤
const : Type s → Container s p
const X .fst = X
const X .snd _ = ⊥
infixr 9 _∘_
_∘_ : ∀ {s₁ s₂ p₁ p₂} → Container s₁ p₁ → Container s₂ p₂ →
Container (s₁ ℓ⊔ s₂ ℓ⊔ p₁) (p₁ ℓ⊔ p₂)
(C₁ ∘ C₂) .fst = ⟦ C₁ ⟧ (fst C₂)
(C₁ ∘ C₂) .snd cx = ∃ x × (snd C₂ P.∘ snd cx) x
infixr 2 _×_
_×_ : ∀ {s₁ s₂ p₁ p₂} → Container s₁ p₁ → Container s₂ p₂ →
Container (s₁ ℓ⊔ s₂) (p₁ ℓ⊔ p₂)
(C₁ × C₂) .fst = fst C₁ P.× fst C₂
(C₁ × C₂) .snd = P.uncurry λ s₁ s₂ → (snd C₁ s₁) P.⊎ (snd C₂ s₂)
Π : ∀ {i s p} (I : Type i) → (I → Container s p) → Container (i ℓ⊔ s) (i ℓ⊔ p)
Π I C .fst = ∀ i → fst (C i)
Π I C .snd = λ s → ∃ i × snd (C i) (s i)
infix 0 const[_]⟶_
const[_]⟶_ : ∀ {i s p} → Type i → Container s p → Container (i ℓ⊔ s) (i ℓ⊔ p)
const[ X ]⟶ C = Π X (P.const C)
infixr 1 _⊎_
_⊎_ : ∀ {s₁ s₂ p} → Container s₁ p → Container s₂ p → Container (s₁ ℓ⊔ s₂) p
(C₁ ⊎ C₂) .fst = (fst C₁ P.⊎ fst C₂)
(C₁ ⊎ C₂) .snd = either (snd C₁) (snd C₂)
Σ : ∀ {i s p} (I : Type i) → (I → Container s p) → Container (i ℓ⊔ s) p
Σ I C .fst = ∃ i × fst (C i)
Σ I C .snd s = snd (C (fst s)) (snd s)
| {
"alphanum_fraction": 0.5589060309,
"avg_line_length": 25.9272727273,
"ext": "agda",
"hexsha": "d524d203cc582dc5b18725af7f9f00b23bd4a0cd",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Container/Polynomial.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Container/Polynomial.agda",
"max_line_length": 78,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Container/Polynomial.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 687,
"size": 1426
} |
module Data.Collection.Core.Properties where
-- open import Data.List public using (List; []; _∷_)
-- open import Data.String public using (String; _≟_)
-- open import Level using (zero)
--
-- open import Function using (flip)
-- open import Relation.Nullary
-- open import Relation.Nullary.Negation
-- open import Relation.Nullary.Decidable renaming (map to mapDec; map′ to mapDec′)
-- open import Relation.Unary
-- open import Relation.Binary
-- open import Relation.Binary.PropositionalEquality
| {
"alphanum_fraction": 0.7575150301,
"avg_line_length": 35.6428571429,
"ext": "agda",
"hexsha": "2f4128c059f745d163a9439810b4ba6c9fa46e3d",
"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/Core/Properties.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/Core/Properties.agda",
"max_line_length": 83,
"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/Core/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 115,
"size": 499
} |
{-
Mathematical Foundations of Programming (G54FOP)
Nicolai Kraus
Lecture 3, 7 Feb 2018
====================
INTRODUCTION TO AGDA
====================
Your G54FPP project could involve Agda. If you want.
Btw, text in {- -} is a comment. So is text after --.
links to help you install and learn Agda:
http://wiki.portal.chalmers.se/agda/pmwiki.php
http://agda.readthedocs.io/en/latest/getting-started/index.html
https://github.com/agda/agda
Agda standard library:
https://github.com/agda/agda-stdlib
Some key combinations, where C is ctrl,
i.e. C-c C-l means:
press control and keep it pressed,
press and release c,
press and release l,
release control.
C-c C-l load file, replace ? by hole
C-c C-, show goal
C-c C-. show goal and input type
C-c C-n normalise expression
C-c C-space give current hole input to Agda
see links above for more
I recommend using a monospace font.
-}
module lec3FOP where
data ℕ : Set where -- type: \bN
zero : ℕ
suc : ℕ → ℕ -- type: \to or \->
-- (or just use ->)
infix 6 _+_
_+_ : ℕ → ℕ → ℕ -- the arguments go where _ is
zero + n = n
(suc m) + n = suc (m + n)
{- type of equalities on natural numbers *which
we need to prove*. Some equalities can be hard
to prove, so we cannot assume that Agda would
find them automatically! -}
infix 3 _==_
data _==_ : (m n : ℕ) → Set where
refl : {m : ℕ} → m == m
suc-lem : {m n : ℕ} → m == n → suc m == suc n
suc-lem refl = refl
+-is-associative : (k m n : ℕ)
→ k + (m + n) == (k + m) + n
+-is-associative zero m n = refl
+-is-associative (suc k) m n =
suc-lem (+-is-associative k m n)
{- Next: implement the language of expressions
from the lecture
This language was given by a BNF:
E:= t | f | z | s E | p E | iz E | if E then E else E
-}
data Expr : Set where
t : Expr
f : Expr
z : Expr
s : Expr → Expr
p : Expr → Expr
iz : Expr → Expr
if_then_else_ : Expr → Expr → Expr → Expr
-- denotational semantics from last week:
-- ⟦_⟧ : Expr → S type: \[[_\]]
-- S was {True, False, 0, 1, 2, ..., ⊥}
data Bool : Set where
True : Bool
False : Bool
data S : Set where
bool : Bool → S
number : ℕ → S
⊥ : S
-- Here we go:
⟦_⟧ : Expr → S
⟦ t ⟧ = bool True
⟦ f ⟧ = bool False
⟦ z ⟧ = number zero
⟦ s e ⟧ with ⟦ e ⟧
⟦ s e ⟧ | number n = number (suc n)
⟦ s e ⟧ | _ = ⊥
⟦ _ ⟧ = ⊥ -- not what we want, but
-- at least Agda accepts it.
-- Exercise: complete this definition.
| {
"alphanum_fraction": 0.5553477936,
"avg_line_length": 22.8547008547,
"ext": "agda",
"hexsha": "d45f472054c1a807febf77b7ffd2a473b9e08ead",
"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": "b65516ce0fdc5fc98604cbcff3ef8ae704d59049",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/FOP2018",
"max_forks_repo_path": "agda/lec3FOP.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b65516ce0fdc5fc98604cbcff3ef8ae704d59049",
"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/FOP2018",
"max_issues_repo_path": "agda/lec3FOP.agda",
"max_line_length": 65,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b65516ce0fdc5fc98604cbcff3ef8ae704d59049",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nicolaikraus/FOP2018",
"max_stars_repo_path": "agda/lec3FOP.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 886,
"size": 2674
} |
------------------------------------------------------------------------------
-- Common definitions
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module Common.DefinitionsI where
open import Common.FOL.FOL using ( ¬_ ; D )
open import Common.FOL.Relation.Binary.PropositionalEquality using ( _≡_ )
-- We add 3 to the fixities of the Agda standard library 0.8.1 (see
-- Relation/Binary/Core.agda).
infix 7 _≢_
------------------------------------------------------------------------------
-- Inequality.
_≢_ : D → D → Set
x ≢ y = ¬ x ≡ y
| {
"alphanum_fraction": 0.422459893,
"avg_line_length": 32.5217391304,
"ext": "agda",
"hexsha": "d620a198c144b8dc6d90cecf8950279f2f01fb34",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/Common/DefinitionsI.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/Common/DefinitionsI.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": "src/fot/Common/DefinitionsI.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": 149,
"size": 748
} |
{-# OPTIONS --without-K #-}
module Model.Stream where
open import Model.Size as MS using
( Size ; Sizes ; _≤_ ; _<_ ; ≤-IsProp ; ≤-trans ; nat )
open import Model.Type.Core
open import Util.HoTT.FunctionalExtensionality
open import Util.HoTT.HLevel
open import Util.Prelude
import Data.Nat.Properties as ℕ
open Size
Colist : Size → Set
Colist n = ∀ m → nat m ≤ n → ℕ
abstract
Colist-≡⁺ : ∀ {n} {xs ys : Colist n}
→ (∀ m m≤n → xs m m≤n ≡ ys m m≤n)
→ xs ≡ ys
Colist-≡⁺ eq = funext λ m → funext λ m≤n → eq m m≤n
Colist-≡⁻ : ∀ {n} {xs ys : Colist n}
→ xs ≡ ys
→ ∀ m m≤n₀ m≤n₁ → xs m m≤n₀ ≡ ys m m≤n₁
Colist-≡⁻ {xs = xs} refl m m≤n₀ m≤n₁ = cong (xs m) (≤-IsProp _ _)
Colist-IsSet : ∀ {n} → IsSet (Colist n)
Colist-IsSet = ∀-IsSet λ m → ∀-IsSet λ m≤n → ℕ.≡-irrelevant
castColist : ∀ {n m} → n ≤ m → Colist m → Colist n
castColist n≤m xs k k≤n = xs k go
where abstract go = ≤-trans k≤n n≤m
Stream : ⟦Type⟧ Sizes
Stream = record
{ ObjHSet = λ n → HLevel⁺ (Colist n) Colist-IsSet
; eqHProp = λ {n} {n′} _ xs ys
→ ∀-HProp ℕ λ m → ∀-HProp (nat m ≤ n) λ m≤n → ∀-HProp (nat m ≤ n′) λ m≤n′
→ HLevel⁺ (xs m m≤n ≡ ys m m≤n′) ℕ.≡-irrelevant
; eq-refl = λ x m m≤n m≤n′ → cong (x m) (≤-IsProp _ _)
}
cons : ∀ {n} → ℕ → (∀ m → m < n → Colist m) → Colist n
cons x xs zero _ = x
cons x xs (suc k) Sk≤n = xs (nat k) go k MS.≤-refl
where abstract go = MS.Sn≤m→n<m Sk≤n
head : ∀ {n} → Colist n → ℕ
head xs = xs 0 MS.0≤n
tail : ∀ {n} → Colist n → ∀ m → m < n → Colist m
tail xs m m<n k k≤m = xs (suc k) go
where abstract go = MS.n<m→Sn≤m (MS.≤→<→< k≤m m<n)
abstract
cons-≡⁺ : ∀ {n n′ i i′ is is′}
→ i ≡ i′
→ (∀ m (m<n : m < n) (m<n′ : m < n′) k k≤m
→ is m m<n k k≤m ≡ is′ m m<n′ k k≤m)
→ ∀ m m<n m<n′
→ cons i is m m<n ≡ cons i′ is′ m m<n′
cons-≡⁺ i≡i′ is≡is′ zero m<n₀ m<n₁ = i≡i′
cons-≡⁺ {is′ = is′} i≡i′ is≡is′ (suc m) m<n m<n′
= trans (is≡is′ (nat m) (MS.Sn≤m→n<m m<n) (MS.Sn≤m→n<m m<n′) m MS.≤-refl)
(cong (λ p → is′ _ p _ _) (MS.<-IsProp _ _))
head-≡⁺ : ∀ {n n′ is is′}
→ (∀ m (m≤n : nat m ≤ n) (m≤n′ : nat m ≤ n′) → is m m≤n ≡ is′ m m≤n′)
→ head is ≡ head is′
head-≡⁺ is≡is′ = is≡is′ 0 MS.0≤n MS.0≤n
tail-≡⁺ : ∀ {n n′ is is′}
→ (∀ m (m≤n : nat m ≤ n) (m≤n′ : nat m ≤ n′)
→ is m m≤n ≡ is′ m m≤n′)
→ ∀ m m′ m<n m′<n′ k k≤m k≤m′
→ tail is m m<n k k≤m ≡ tail is′ m′ m′<n′ k k≤m′
tail-≡⁺ {is′ = is′} is≡is′ m m′ m<n m′<n′ k k≤m k≤m′
= trans (is≡is′ (suc k) _ (MS.n<m→Sn≤m (MS.≤→<→< k≤m′ m′<n′)))
(cong (is′ (suc k)) (≤-IsProp _ _))
| {
"alphanum_fraction": 0.4967067028,
"avg_line_length": 27.4574468085,
"ext": "agda",
"hexsha": "19c29a94e773c659e0e3550e921ddea456233e05",
"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": "104cddc6b65386c7e121c13db417aebfd4b7a863",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JLimperg/msc-thesis-code",
"max_forks_repo_path": "src/Model/Stream.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JLimperg/msc-thesis-code",
"max_issues_repo_path": "src/Model/Stream.agda",
"max_line_length": 79,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JLimperg/msc-thesis-code",
"max_stars_repo_path": "src/Model/Stream.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-26T06:37:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-04-13T21:31:17.000Z",
"num_tokens": 1324,
"size": 2581
} |
------------------------------------------------------------------------
-- Some cancellation lemmas
------------------------------------------------------------------------
open import Atom
module Cancellation (atoms : χ-atoms) where
open import Equality.Propositional
open import Prelude hiding (const)
open import Chi atoms
open import Values atoms
cancel-const :
∀ {c₁ c₂ es₁ es₂} →
Exp.const c₁ es₁ ≡ const c₂ es₂ →
c₁ ≡ c₂ × es₁ ≡ es₂
cancel-const refl = refl , refl
cancel-lambda :
∀ {x₁ x₂ e₁ e₂} →
Exp.lambda x₁ e₁ ≡ lambda x₂ e₂ →
x₁ ≡ x₂ × e₁ ≡ e₂
cancel-lambda refl = refl , refl
cancel-rec :
∀ {x₁ x₂ e₁ e₂} →
Exp.rec x₁ e₁ ≡ rec x₂ e₂ →
x₁ ≡ x₂ × e₁ ≡ e₂
cancel-rec refl = refl , refl
cancel-apply :
∀ {e₁₁ e₁₂ e₂₁ e₂₂} →
Exp.apply e₁₁ e₂₁ ≡ apply e₁₂ e₂₂ →
e₁₁ ≡ e₁₂ × e₂₁ ≡ e₂₂
cancel-apply refl = refl , refl
cancel-case :
∀ {e₁ e₂ bs₁ bs₂} →
Exp.case e₁ bs₁ ≡ case e₂ bs₂ →
e₁ ≡ e₂ × bs₁ ≡ bs₂
cancel-case refl = refl , refl
cancel-var :
∀ {x₁ x₂} →
Exp.var x₁ ≡ var x₂ → x₁ ≡ x₂
cancel-var refl = refl
cancel-branch :
∀ {c₁ c₂ xs₁ xs₂ e₁ e₂} →
Br.branch c₁ xs₁ e₁ ≡ branch c₂ xs₂ e₂ →
c₁ ≡ c₂ × xs₁ ≡ xs₂ × e₁ ≡ e₂
cancel-branch refl = refl , refl , refl
| {
"alphanum_fraction": 0.5553745928,
"avg_line_length": 22.3272727273,
"ext": "agda",
"hexsha": "ef75d091b763bb2030a88f90f271e0431491ce00",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/chi",
"max_forks_repo_path": "src/Cancellation.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_issues_repo_issues_event_max_datetime": "2020-06-08T11:08:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-05-21T23:29:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/chi",
"max_issues_repo_path": "src/Cancellation.agda",
"max_line_length": 72,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/chi",
"max_stars_repo_path": "src/Cancellation.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-20T16:27:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:07.000Z",
"num_tokens": 462,
"size": 1228
} |
{-# OPTIONS --safe #-}
{-
This file models "ZF - powerset" in cubical agda, via a cumulative hierarchy, in the sense given
in the HoTT book §10.5 "The cumulative hierarchy".
A great amount of inspiration is taken from the Coq implementations found in
Jérémy Ledent, Modeling set theory in homotopy type theory, code of which can be found online at
https://github.com/jledent/vset
-}
module Cubical.HITs.CumulativeHierarchy.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Path
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv using (fiber)
open import Cubical.Functions.Logic
open import Cubical.Data.Sigma
open import Cubical.HITs.PropositionalTruncation as P hiding (elim; elim2)
import Cubical.HITs.PropositionalTruncation.Monad as PropMonad
private
variable
ℓ ℓ' : Level
infix 5 _∈_
-- set up the basic hierarchy definition and _∈_ as recursive, higher inductive types
data V (ℓ : Level) : Type (ℓ-suc ℓ)
_∈_ : (S T : V ℓ) → hProp (ℓ-suc ℓ)
eqImage : {X Y : Type ℓ} (ix : X → V ℓ) (iy : Y → V ℓ) → Type (ℓ-suc ℓ)
eqImage {X = X} {Y = Y} ix iy = (∀ (a : X) → ∥ fiber iy (ix a) ∥₁) ⊓′
(∀ (b : Y) → ∥ fiber ix (iy b) ∥₁)
data V ℓ where
sett : (X : Type ℓ) → (X → V ℓ) → V ℓ
seteq : (X Y : Type ℓ) (ix : X → V ℓ) (iy : Y → V ℓ) (eq : eqImage ix iy) → sett X ix ≡ sett Y iy
setIsSet : isSet (V ℓ)
A ∈ sett X ix = ∥ Σ[ i ∈ X ] (ix i ≡ A) ∥ₚ
A ∈ seteq X Y ix iy (f , g) i =
⇔toPath {P = A ∈ sett X ix} {Q = A ∈ sett Y iy}
(λ ax → do (x , xa) ← ax ; (y , ya) ← f x ; ∣ y , ya ∙ xa ∣₁)
(λ ay → do (y , ya) ← ay ; (x , xa) ← g y ; ∣ x , xa ∙ ya ∣₁) i
where open PropMonad
A ∈ setIsSet a b p q i j = isSetHProp (A ∈ a) (A ∈ b) (λ j → A ∈ p j) (λ j → A ∈ q j) i j
-- setup a general eliminator into h-sets
record ElimSet {Z : (s : V ℓ) → Type ℓ'}
(isSetZ : ∀ s → isSet (Z s)) : Type (ℓ-max ℓ' (ℓ-suc ℓ)) where
field
ElimSett :
∀ (X : Type ℓ) (ix : X → V ℓ)
-- ^ the structural parts of the set
→ (rec : ∀ x → Z (ix x))
-- ^ a recursor into the elements
→ Z (sett X ix)
ElimEq :
∀ (X₁ X₂ : Type ℓ) (ix₁ : X₁ → V ℓ) (ix₂ : X₂ → V ℓ) (eq : eqImage ix₁ ix₂)
-- ^ the structural parts of the seteq path
→ (rc₁ : ∀ x₁ → Z (ix₁ x₁)) (rc₂ : ∀ x₂ → Z (ix₂ x₂))
-- ^ recursors into the elements
→ ((x₁ : X₁) → ∃[ (x₂ , p) ∈ fiber ix₂ (ix₁ x₁) ] PathP (λ i → Z (p i)) (rc₂ x₂) (rc₁ x₁))
→ ((x₂ : X₂) → ∃[ (x₁ , p) ∈ fiber ix₁ (ix₂ x₂) ] PathP (λ i → Z (p i)) (rc₁ x₁) (rc₂ x₂))
-- ^ proofs that the recursors have equal images
→ PathP (λ i → Z (seteq X₁ X₂ ix₁ ix₂ eq i)) (ElimSett X₁ ix₁ rc₁) (ElimSett X₂ ix₂ rc₂)
module _ {Z : (s : V ℓ) → Type ℓ'} {isSetZ : ∀ s → isSet (Z s)} (E : ElimSet isSetZ) where
open ElimSet E
elim : (s : V ℓ) → Z s
elim (sett X ix) = ElimSett X ix (elim ∘ ix)
elim (seteq X₁ X₂ ix₁ ix₂ eq i) =
ElimEq X₁ X₂ ix₁ ix₂ eq (elim ∘ ix₁) (elim ∘ ix₂) rec₁→₂ rec₂→₁ i
where
rec₁→₂ :
∀ (x₁ : X₁)
→ ∃[ (x₂ , p) ∈ fiber ix₂ (ix₁ x₁) ] PathP (λ i → Z (p i)) (elim (ix₂ x₂)) (elim (ix₁ x₁))
rec₂→₁ :
∀ (x₂ : X₂)
→ ∃[ (x₁ , p) ∈ fiber ix₁ (ix₂ x₂) ] PathP (λ i → Z (p i)) (elim (ix₁ x₁)) (elim (ix₂ x₂))
-- using a local definition of Prop.rec satisfies the termination checker
rec₁→₂ x₁ = localRec₁ (eq .fst x₁) where
localRec₁ :
∥ fiber ix₂ (ix₁ x₁) ∥₁
→ ∃[ (x₂ , p) ∈ fiber ix₂ (ix₁ x₁) ] PathP (λ i → Z (p i)) (elim (ix₂ x₂)) (elim (ix₁ x₁))
localRec₁ ∣ x₂ , xx ∣₁ = ∣ (x₂ , xx) , (λ i → elim (xx i)) ∣₁
localRec₁ (squash₁ x y i) = squash₁ (localRec₁ x) (localRec₁ y) i
rec₂→₁ x₂ = localRec₂ (eq .snd x₂) where
localRec₂ :
∥ fiber ix₁ (ix₂ x₂) ∥₁
→ ∃[ (x₁ , p) ∈ fiber ix₁ (ix₂ x₂) ] PathP (λ i → Z (p i)) (elim (ix₁ x₁)) (elim (ix₂ x₂))
localRec₂ ∣ x₁ , xx ∣₁ = ∣ (x₁ , xx) , (λ i → elim (xx i)) ∣₁
localRec₂ (squash₁ x y i) = squash₁ (localRec₂ x) (localRec₂ y) i
elim (setIsSet S T x y i j) = isProp→PathP propPathP (cong elim x) (cong elim y) i j where
propPathP : (i : I) → isProp (PathP (λ j → Z (setIsSet S T x y i j)) (elim S) (elim T))
propPathP _ = subst isProp (sym (PathP≡Path _ _ _)) (isSetZ _ _ _)
-- eliminator into propositions
elimProp : {Z : (s : V ℓ) → Type ℓ'} (isPropZ : ∀ s → isProp (Z s))
→ ((X : Type ℓ) → (ix : X → V ℓ) → (∀ x → Z (ix x)) → Z (sett X ix))
→ (s : V ℓ) → Z s
elimProp isPropZ algz (sett X ix) = algz X ix (λ x → elimProp isPropZ algz (ix x))
elimProp isPropZ algz (seteq X Y ix iy eq i) =
isProp→PathP (λ i → isPropZ (seteq X Y ix iy eq i))
(algz X ix (elimProp isPropZ algz ∘ ix))
(algz Y iy (elimProp isPropZ algz ∘ iy)) i
elimProp isPropZ algz (setIsSet S T x y i j) =
isProp→SquareP (λ i j → isPropZ (setIsSet S T x y i j))
(λ _ → elimProp isPropZ algz S)
(λ _ → elimProp isPropZ algz T)
(cong (elimProp isPropZ algz) x)
(cong (elimProp isPropZ algz) y) i j
-- eliminator for two sets at once
record Elim2Set {Z : (s t : V ℓ) → Type ℓ'}
(isSetZ : ∀ s t → isSet (Z s t)) : Type (ℓ-max ℓ' (ℓ-suc ℓ)) where
field
ElimSett2 :
∀ (X : Type ℓ) (ix : X → V ℓ) (Y : Type ℓ) (iy : Y → V ℓ)
-- ^ the structural parts of the set
→ (rec : ∀ x y → Z (ix x) (iy y))
-- ^ a recursor into the elements
→ Z (sett X ix) (sett Y iy)
-- path when the the first argument deforms along seteq and the second argument is held constant
ElimEqFst :
∀ (X₁ X₂ : Type ℓ) (ix₁ : X₁ → V ℓ) (ix₂ : X₂ → V ℓ) (eq : eqImage ix₁ ix₂)
-- ^ the structural parts of the seteq path
→ (Y : Type ℓ) (iy : Y → V ℓ)
-- ^ the second argument held constant
→ (rec₁ : ∀ x₁ y → Z (ix₁ x₁) (iy y)) (rec₂ : ∀ x₂ y → Z (ix₂ x₂) (iy y))
-- ^ recursors into the elements
→ (rec₁→₂ : (x₁ : X₁)
→ ∃[ (x₂ , p) ∈ fiber ix₂ (ix₁ x₁) ]
PathP (λ i → ∀ y → Z (p i) (iy y)) (λ y → rec₂ x₂ y) (λ y → rec₁ x₁ y))
→ (rec₂→₁ : (x₂ : X₂)
→ ∃[ (x₁ , p) ∈ fiber ix₁ (ix₂ x₂) ]
PathP (λ i → ∀ y → Z (p i) (iy y)) (λ y → rec₁ x₁ y) (λ y → rec₂ x₂ y))
-- ^ proofs that the recursors have equal images
→ PathP (λ i → Z (seteq X₁ X₂ ix₁ ix₂ eq i) (sett Y iy))
(ElimSett2 X₁ ix₁ Y iy rec₁)
(ElimSett2 X₂ ix₂ Y iy rec₂)
-- path when the the second argument deforms along seteq and the first argument is held constant
ElimEqSnd :
∀ (X : Type ℓ) (ix : X → V ℓ)
-- ^ the first argument held constant
→ (Y₁ Y₂ : Type ℓ) (iy₁ : Y₁ → V ℓ) (iy₂ : Y₂ → V ℓ) → (eq : eqImage iy₁ iy₂)
-- ^ the structural parts of the seteq path
→ (rec₁ : ∀ x y₁ → Z (ix x) (iy₁ y₁)) (rec₂ : ∀ x y₂ → Z (ix x) (iy₂ y₂))
-- ^ recursors into the elements
→ (rec₁→₂ : (y₁ : Y₁)
→ ∃[ (y₂ , p) ∈ fiber iy₂ (iy₁ y₁) ]
PathP (λ i → ∀ x → Z (ix x) (p i)) (λ x → rec₂ x y₂) (λ x → rec₁ x y₁))
→ (rec₂→₁ : (y₂ : Y₂)
→ ∃[ (y₁ , p) ∈ fiber iy₁ (iy₂ y₂) ]
PathP (λ i → ∀ x → Z (ix x) (p i)) (λ x → rec₁ x y₁) (λ x → rec₂ x y₂))
-- ^ proofs that the recursors have equal images
→ PathP (λ i → Z (sett X ix) (seteq Y₁ Y₂ iy₁ iy₂ eq i))
(ElimSett2 X ix Y₁ iy₁ rec₁)
(ElimSett2 X ix Y₂ iy₂ rec₂)
module _ {Z : (s t : V ℓ) → Type ℓ'} {isSetZ : ∀ s t → isSet (Z s t)} (E : Elim2Set isSetZ) where
open Elim2Set E
open ElimSet
elim2 : (s t : V ℓ) → Z s t
elim2 = elim pElim where
open PropMonad
isSetPElim : ∀ s → isSet (∀ t → Z s t)
isSetPElim s = isSetΠ (isSetZ s)
eliminatorImplX : (X : Type ℓ) (ix : X → V ℓ)
→ (rec : ∀ x y → Z (ix x) y)
→ ElimSet (λ t → isSetZ (sett X ix) t)
ElimSett (eliminatorImplX X ix rec) Y iy _ =
ElimSett2 X ix Y iy (λ x → rec x ∘ iy)
ElimEq (eliminatorImplX X ix rec) Y₁ Y₂ iy₁ iy₂ eq _ _ _ _ =
ElimEqSnd X ix Y₁ Y₂ iy₁ iy₂ eq (λ x → rec x ∘ iy₁) (λ x → rec x ∘ iy₂) rec₁→₂ rec₂→₁
where
rec₁→₂ :
∀ (y₁ : Y₁)
→ ∃[ (y₂ , p) ∈ fiber iy₂ (iy₁ y₁) ]
PathP (λ i → ∀ x → Z (ix x) (p i)) (λ x → rec x (iy₂ y₂)) (λ x → rec x (iy₁ y₁))
rec₂→₁ :
∀ (y₂ : Y₂)
→ ∃[ (y₁ , p) ∈ fiber iy₁ (iy₂ y₂) ]
PathP (λ i → ∀ x → Z (ix x) (p i)) (λ x → rec x (iy₁ y₁)) (λ x → rec x (iy₂ y₂))
rec₁→₂ y₁ = do (y₂ , yy) ← fst eq y₁ ; ∣ (y₂ , yy) , (λ i x → rec x (yy i)) ∣₁
rec₂→₁ y₂ = do (y₁ , yy) ← snd eq y₂ ; ∣ (y₁ , yy) , (λ i x → rec x (yy i)) ∣₁
elimImplS :
∀ (X : Type ℓ) (ix : X → V ℓ)
→ (∀ x t₂ → Z (ix x) t₂)
→ (t : V ℓ) → Z (sett X ix) t
elimImplS X ix rec = elim (eliminatorImplX X ix rec)
elimImplSExt :
∀ (X₁ X₂ : Type ℓ) (ix₁ : X₁ → V ℓ) (ix₂ : X₂ → V ℓ) → (eq : eqImage ix₁ ix₂)
→ (rec₁ : ∀ x₁ t₂ → Z (ix₁ x₁) t₂) (rec₂ : ∀ x₂ t₂ → Z (ix₂ x₂) t₂)
→ ((x₁ : X₁) → ∃[ (x₂ , p) ∈ fiber ix₂ (ix₁ x₁) ]
PathP (λ i → ∀ t → Z (p i) t) (rec₂ x₂) (rec₁ x₁))
→ ((x₂ : X₂) → ∃[ (x₁ , p) ∈ fiber ix₁ (ix₂ x₂) ]
PathP (λ i → ∀ t → Z (p i) t) (rec₁ x₁) (rec₂ x₂))
→ (t : V ℓ)
→ PathP (λ i → Z (seteq X₁ X₂ ix₁ ix₂ eq i) t)
(elimImplS X₁ ix₁ rec₁ t)
(elimImplS X₂ ix₂ rec₂ t)
elimImplSExt X₁ X₂ ix₁ ix₂ eq rec₁ rec₂ rec₁→₂ rec₂→₁ =
elimProp propPathP (λ Y iy _ → elimImplSExtT Y iy)
where
propPathP : (t : V ℓ)
→ isProp (PathP (λ i → Z (seteq X₁ X₂ ix₁ ix₂ eq i) t)
(elimImplS X₁ ix₁ rec₁ t)
(elimImplS X₂ ix₂ rec₂ t))
propPathP _ = subst isProp (sym (PathP≡Path _ _ _)) (isSetZ _ _ _ _)
elimImplSExtT : (Y : Type ℓ) (iy : Y → V ℓ) → _ {- the appropriate path type -}
elimImplSExtT Y iy =
ElimEqFst X₁ X₂ ix₁ ix₂ eq Y iy (λ x₁ y → rec₁ x₁ (iy y))
(λ x₂ y → rec₂ x₂ (iy y)) rec₁→₂Impl rec₂→₁Impl
where
rec₁→₂Impl :
∀ (x₁ : X₁)
→ ∃[ (x₂ , p) ∈ fiber ix₂ (ix₁ x₁) ]
PathP (λ i → ∀ y → Z (p i) (iy y)) (λ y → rec₂ x₂ (iy y)) (λ y → rec₁ x₁ (iy y))
rec₂→₁Impl :
∀ (x₂ : X₂)
→ ∃[ (x₁ , p) ∈ fiber ix₁ (ix₂ x₂) ]
PathP (λ i → ∀ y → Z (p i) (iy y)) (λ y → rec₁ x₁ (iy y)) (λ y → rec₂ x₂ (iy y))
rec₁→₂Impl x₁ = do ((x₂ , xx) , rx) ← rec₁→₂ x₁ ; ∣ (x₂ , xx) , (λ i y → rx i (iy y)) ∣₁
rec₂→₁Impl x₂ = do ((x₁ , xx) , rx) ← rec₂→₁ x₂ ; ∣ (x₁ , xx) , (λ i y → rx i (iy y)) ∣₁
pElim : ElimSet isSetPElim
ElimSett pElim = elimImplS
ElimEq pElim X₁ X₂ ix₁ ix₂ eq rec₁ rec₂ rec₁→₂ rec₂→₁ i t =
elimImplSExt X₁ X₂ ix₁ ix₂ eq rec₁ rec₂ rec₁→₂ rec₂→₁ t i
| {
"alphanum_fraction": 0.5106730857,
"avg_line_length": 45.8708333333,
"ext": "agda",
"hexsha": "f16be78c745784b6db5bfd23db6cefe259041637",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/HITs/CumulativeHierarchy/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/HITs/CumulativeHierarchy/Base.agda",
"max_line_length": 100,
"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/HITs/CumulativeHierarchy/Base.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": 4475,
"size": 11009
} |
{-# OPTIONS --safe #-}
{-
This is inspired by/copied from:
https://github.com/agda/agda-stdlib/blob/master/src/Tactic/MonoidSolver.agda
Boilerplate code for calling the ring solver is constructed automatically
with agda's reflection features.
-}
module Cubical.Algebra.RingSolver.ReflectionSolving where
open import Cubical.Foundations.Prelude hiding (Type)
open import Cubical.Functions.Logic
open import Agda.Builtin.Reflection hiding (Type)
open import Agda.Builtin.String
open import Cubical.Reflection.Base
open import Cubical.Data.Maybe
open import Cubical.Data.Sigma
open import Cubical.Data.List
open import Cubical.Data.Nat.Literals
open import Cubical.Data.Int.Base hiding (abs)
open import Cubical.Data.Int using (fromNegℤ; fromNatℤ)
open import Cubical.Data.Nat using (ℕ) renaming (_+_ to _+ℕ_)
open import Cubical.Data.FinData using () renaming (zero to fzero; suc to fsuc)
open import Cubical.Data.Bool
open import Cubical.Data.Bool.SwitchStatement
open import Cubical.Data.Vec using (Vec) renaming ([] to emptyVec; _∷_ to _∷vec_) public
open import Cubical.Algebra.RingSolver.AlgebraExpression
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.RingSolver.RawAlgebra
open import Cubical.Algebra.RingSolver.IntAsRawRing
open import Cubical.Algebra.RingSolver.CommRingSolver renaming (solve to ringSolve)
private
variable
ℓ : Level
_==_ = primQNameEquality
{-# INLINE _==_ #-}
record VarInfo : Type ℓ-zero where
field
varName : String
varType : Arg Term
index : ℕ
{-
`getLastTwoArgsOf` maps a term 'def n (z₁ ∷ … ∷ zₙ ∷ x ∷ y ∷ [])' to the pair '(x,y)'
non-visible arguments are ignored.
-}
getLastTwoArgsOf : Name → Term → Maybe (Term × Term)
getLastTwoArgsOf n' (def n xs) =
if n == n'
then go xs
else nothing
where
go : List (Arg Term) → Maybe (Term × Term)
go (varg x ∷ varg y ∷ []) = just (x , y)
go (x ∷ xs) = go xs
go _ = nothing
getLastTwoArgsOf n' _ = nothing
{-
`getArgs` maps a term 'x ≡ y' to the pair '(x,y)'
-}
getArgs : Term → Maybe (Term × Term)
getArgs = getLastTwoArgsOf (quote PathP)
firstVisibleArg : List (Arg Term) → Maybe Term
firstVisibleArg [] = nothing
firstVisibleArg (varg x ∷ l) = just x
firstVisibleArg (x ∷ l) = firstVisibleArg l
{-
If the solver needs to be applied during equational reasoning,
the right hand side of the equation to solve cannot be given to
the solver directly. The folllowing function extracts this term y
from a more complex expression as in:
x ≡⟨ solve ... ⟩ (y ≡⟨ ... ⟩ z ∎)
-}
getRhs : Term → Maybe Term
getRhs reasoningToTheRight@(def n xs) =
if n == (quote _∎)
then firstVisibleArg xs
else (if n == (quote _≡⟨_⟩_)
then firstVisibleArg xs
else nothing)
getRhs _ = nothing
private
solverCallAsTerm : Term → Arg Term → Term → Term → Term
solverCallAsTerm R varList lhs rhs =
def
(quote ringSolve)
(varg R ∷ varg lhs ∷ varg rhs
∷ varList
∷ varg (def (quote refl) []) ∷ [])
solverCallWithLambdas : ℕ → List VarInfo → Term → Term → Term → Term
solverCallWithLambdas n varInfos R lhs rhs =
encloseWithIteratedLambda
(map VarInfo.varName varInfos)
(solverCallAsTerm R (variableList (rev varInfos)) lhs rhs)
where
encloseWithIteratedLambda : List String → Term → Term
encloseWithIteratedLambda (varName ∷ xs) t = lam visible (abs varName (encloseWithIteratedLambda xs t))
encloseWithIteratedLambda [] t = t
variableList : List VarInfo → Arg Term
variableList [] = varg (con (quote emptyVec) [])
variableList (varInfo ∷ varInfos)
= varg (con (quote _∷vec_) (varg (var (VarInfo.index varInfo) []) ∷ (variableList varInfos) ∷ []))
solverCallByVarIndices : ℕ → List ℕ → Term → Term → Term → Term
solverCallByVarIndices n varIndices R lhs rhs =
solverCallAsTerm R (variableList (rev varIndices)) lhs rhs
where
variableList : List ℕ → Arg Term
variableList [] = varg (con (quote emptyVec) [])
variableList (varIndex ∷ varIndices)
= varg (con (quote _∷vec_) (varg (var (varIndex) []) ∷ (variableList varIndices) ∷ []))
module pr (R : CommRing ℓ) {n : ℕ} where
private
νR = CommRing→RawℤAlgebra R
open CommRingStr (snd R)
0' : Expr ℤAsRawRing (fst R) n
0' = K 0
1' : Expr ℤAsRawRing (fst R) n
1' = K 1
module _ (cring : Term) where
private
νR = def (quote CommRing→RawℤAlgebra) (varg cring ∷ [])
open pr
`0` : List (Arg Term) → Term
`0` [] = def (quote 0') (varg cring ∷ [])
`0` (varg fstcring ∷ xs) = `0` xs
`0` (harg _ ∷ xs) = `0` xs
`0` _ = unknown
`1` : List (Arg Term) → Term
`1` [] = def (quote 1') (varg cring ∷ [])
`1` (varg fstcring ∷ xs) = `1` xs
`1` (harg _ ∷ xs) = `1` xs
`1` _ = unknown
mutual
`_·_` : List (Arg Term) → Term
`_·_` (harg _ ∷ xs) = `_·_` xs
`_·_` (varg _ ∷ varg x ∷ varg y ∷ []) =
con
(quote _·'_) (varg (buildExpression x) ∷ varg (buildExpression y) ∷ [])
`_·_` _ = unknown
`_+_` : List (Arg Term) → Term
`_+_` (harg _ ∷ xs) = `_+_` xs
`_+_` (varg _ ∷ varg x ∷ varg y ∷ []) =
con
(quote _+'_) (varg (buildExpression x) ∷ varg (buildExpression y) ∷ [])
`_+_` _ = unknown
`-_` : List (Arg Term) → Term
`-_` (harg _ ∷ xs) = `-_` xs
`-_` (varg _ ∷ varg x ∷ []) =
con
(quote -'_) (varg (buildExpression x) ∷ [])
`-_` _ = unknown
K' : List (Arg Term) → Term
K' xs = con (quote K) xs
finiteNumberAsTerm : ℕ → Term
finiteNumberAsTerm ℕ.zero = con (quote fzero) []
finiteNumberAsTerm (ℕ.suc n) = con (quote fsuc) (varg (finiteNumberAsTerm n) ∷ [])
buildExpression : Term → Term
buildExpression (var index _) = con (quote ∣) (varg (finiteNumberAsTerm index) ∷ [])
buildExpression t@(def n xs) =
switch (n ==_) cases
case (quote CommRingStr.0r) ⇒ `0` xs break
case (quote CommRingStr.1r) ⇒ `1` xs break
case (quote CommRingStr._·_) ⇒ `_·_` xs break
case (quote CommRingStr._+_) ⇒ `_+_` xs break
case (quote (CommRingStr.-_)) ⇒ `-_` xs break
default⇒ (K' xs)
buildExpression t@(con n xs) =
switch (n ==_) cases
case (quote CommRingStr.0r) ⇒ `0` xs break
case (quote CommRingStr.1r) ⇒ `1` xs break
case (quote CommRingStr._·_) ⇒ `_·_` xs break
case (quote CommRingStr._+_) ⇒ `_+_` xs break
case (quote (CommRingStr.-_)) ⇒ `-_` xs break
default⇒ (K' xs)
buildExpression t = unknown
toAlgebraExpression : Maybe (Term × Term) → Maybe (Term × Term)
toAlgebraExpression nothing = nothing
toAlgebraExpression (just (lhs , rhs)) = just (buildExpression lhs , buildExpression rhs)
private
adjustDeBruijnIndex : (n : ℕ) → Term → Term
adjustDeBruijnIndex n (var k args) = var (k +ℕ n) args
adjustDeBruijnIndex n _ = unknown
extractVarIndices : Maybe (List Term) → Maybe (List ℕ)
extractVarIndices (just ((var index _) ∷ l)) with extractVarIndices (just l)
... | just indices = just (index ∷ indices)
... | nothing = nothing
extractVarIndices (just []) = just []
extractVarIndices _ = nothing
getVarsAndEquation : Term → Maybe (List VarInfo × Term)
getVarsAndEquation t =
let
(rawVars , equationTerm) = extractVars t
maybeVars = addIndices (length rawVars) rawVars
in map-Maybe (_, equationTerm) maybeVars
where
extractVars : Term → List (String × Arg Term) × Term
extractVars (pi argType (abs varName t)) with extractVars t
... | xs , equation
= (varName , argType) ∷ xs , equation
extractVars equation = [] , equation
addIndices : ℕ → List (String × Arg Term) → Maybe (List VarInfo)
addIndices ℕ.zero [] = just []
addIndices (ℕ.suc countVar) ((varName , argType) ∷ list) =
map-Maybe (λ varList → record { varName = varName ; varType = argType ; index = countVar }
∷ varList)
(addIndices countVar list)
addIndices _ _ = nothing
toListOfTerms : Term → Maybe (List Term)
toListOfTerms (con c []) = if (c == (quote [])) then just [] else nothing
toListOfTerms (con c (varg t ∷ varg s ∷ args)) with toListOfTerms s
... | just terms = if (c == (quote _∷_)) then just (t ∷ terms) else nothing
... | nothing = nothing
toListOfTerms (con c (harg t ∷ args)) = toListOfTerms (con c args)
toListOfTerms _ = nothing
solve-macro : Term → Term → TC Unit
solve-macro cring hole =
do
hole′ ← inferType hole >>= normalise
just (varInfos , equation) ← returnTC (getVarsAndEquation hole′)
where
nothing
→ typeError (strErr "Something went wrong when getting the variable names in "
∷ termErr hole′ ∷ [])
{-
The call to the ring solver will be inside a lamba-expression.
That means, that we have to adjust the deBruijn-indices of the variables in 'cring'
-}
adjustedCring ← returnTC (adjustDeBruijnIndex (length varInfos) cring)
just (lhs , rhs) ← returnTC (toAlgebraExpression adjustedCring (getArgs equation))
where
nothing
→ typeError(
strErr "Error while trying to build ASTs for the equation " ∷
termErr equation ∷ [])
let solution = solverCallWithLambdas (length varInfos) varInfos adjustedCring lhs rhs
unify hole solution
solveInPlace-macro : Term → Term → Term → TC Unit
solveInPlace-macro cring varsToSolve hole =
do
equation ← inferType hole >>= normalise
just varIndices ← returnTC (extractVarIndices (toListOfTerms varsToSolve))
where
nothing
→ typeError(
strErr "Error reading variables to solve " ∷
termErr varsToSolve ∷ [])
just (lhs , rhs) ← returnTC (toAlgebraExpression cring (getArgs equation))
where
nothing
→ typeError(
strErr "Error while trying to build ASTs for the equation " ∷
termErr equation ∷ [])
let solution = solverCallByVarIndices (length varIndices) varIndices cring lhs rhs
unify hole solution
solveEqReasoning-macro : Term → Term → Term → Term → Term → TC Unit
solveEqReasoning-macro lhs cring varsToSolve reasoningToTheRight hole =
do
just varIndices ← returnTC (extractVarIndices (toListOfTerms varsToSolve))
where
nothing
→ typeError(
strErr "Error reading variables to solve " ∷
termErr varsToSolve ∷ [])
just rhs ← returnTC (getRhs reasoningToTheRight)
where
nothing
→ typeError(
strErr "Failed to extract right hand side of equation to solve from " ∷
termErr reasoningToTheRight ∷ [])
just (lhsAST , rhsAST) ← returnTC (toAlgebraExpression cring (just (lhs , rhs)))
where
nothing
→ typeError(
strErr "Error while trying to build ASTs from " ∷
termErr lhs ∷ strErr " and " ∷ termErr rhs ∷ [])
let solverCall = solverCallByVarIndices (length varIndices) varIndices cring lhsAST rhsAST
unify hole (def (quote _≡⟨_⟩_) (varg lhs ∷ varg solverCall ∷ varg reasoningToTheRight ∷ []))
macro
solve : Term → Term → TC _
solve = solve-macro
solveInPlace : Term → Term → Term → TC _
solveInPlace = solveInPlace-macro
infixr 2 _≡⟨solveIn_withVars_⟩_
_≡⟨solveIn_withVars_⟩_ : Term → Term → Term → Term → Term → TC Unit
_≡⟨solveIn_withVars_⟩_ = solveEqReasoning-macro
fromℤ : (R : CommRing ℓ) → ℤ → fst R
fromℤ = scalar
| {
"alphanum_fraction": 0.6165275459,
"avg_line_length": 35.7611940299,
"ext": "agda",
"hexsha": "b7c2c4b910057c6b6e7a33cce049772825cfb754",
"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": "b1d105aeeab1ba9888394c6a919b99a476390b7b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ecavallo/cubical",
"max_forks_repo_path": "Cubical/Algebra/RingSolver/ReflectionSolving.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b1d105aeeab1ba9888394c6a919b99a476390b7b",
"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": "ecavallo/cubical",
"max_issues_repo_path": "Cubical/Algebra/RingSolver/ReflectionSolving.agda",
"max_line_length": 109,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "b1d105aeeab1ba9888394c6a919b99a476390b7b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ecavallo/cubical",
"max_stars_repo_path": "Cubical/Algebra/RingSolver/ReflectionSolving.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-20T11:56:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-20T11:56:18.000Z",
"num_tokens": 3569,
"size": 11980
} |
open import Nat
open import Prelude
open import List
open import judgemental-erase
open import moveerase
open import statics-checks
open import statics-core
module aasubsume-min where
-- this predicate on derivations of actions bans the cases that induce
-- non-determinism.
mutual
aasubmin-synth : ∀{Γ e t α e' t'} → (Γ ⊢ e => t ~ α ~> e' => t') → Set
aasubmin-synth (SAZipAsc1 x) = aasubmin-ana x
aasubmin-synth (SAZipLam2 x x₁ x₂ d) = aasubmin-synth d
aasubmin-synth (SAZipApArr x x₁ x₂ d x₃) = aasubmin-synth d
aasubmin-synth (SAZipApAna x x₁ x₂) = aasubmin-ana x₂
aasubmin-synth (SAZipPlus1 x) = aasubmin-ana x
aasubmin-synth (SAZipPlus2 x) = aasubmin-ana x
aasubmin-synth (SAZipNEHole x x₁ d) = aasubmin-synth d
aasubmin-synth (SAZipPair1 x x₁ d x₂) = aasubmin-synth d
aasubmin-synth (SAZipPair2 x x₁ x₂ d) = aasubmin-synth d
aasubmin-synth (SAZipFst x x₁ x₂ x₃ d) = aasubmin-synth d
aasubmin-synth (SAZipSnd x x₁ x₂ x₃ d) = aasubmin-synth d
aasubmin-synth _ = ⊤
aasubmin-ana : ∀{Γ e α e' t} → (Γ ⊢ e ~ α ~> e' ⇐ t) → Set
aasubmin-ana (AASubsume x x₁ SAConAsc x₃) = ⊥
aasubmin-ana (AASubsume x x₁ SAConInl x₃) = ⊥
aasubmin-ana (AASubsume x x₁ SAConInr x₃) = ⊥
aasubmin-ana (AASubsume x x₁ (SAConLam x₃) x₄) = ⊥
aasubmin-ana (AASubsume EETop SEHole (SAConCase1 a b c) x₄) = ⊥
aasubmin-ana (AASubsume x x₁ s x₃) = aasubmin-synth s
aasubmin-ana (AAZipLam x₁ x₂ d) = aasubmin-ana d
aasubmin-ana (AAZipInl x y) = aasubmin-ana y
aasubmin-ana (AAZipInr x y) = aasubmin-ana y
aasubmin-ana (AAZipCase1 a b c d e f g h) = aasubmin-synth e
aasubmin-ana (AAZipCase2 a b c d e) = aasubmin-ana e
aasubmin-ana (AAZipCase3 a b c d f) = aasubmin-ana f
aasubmin-ana _ = ⊤
-- the minimization predicate propagates through subsumption rules
min-ana-lem : ∀{e e' e◆ Γ t t' t'' α} {a : erase-e e e◆}
{b : Γ ⊢ e◆ => t'} {c : t ~ t''} →
(d : Γ ⊢ e => t' ~ α ~> e' => t'') →
aasubmin-ana (AASubsume a b d c) →
aasubmin-synth d
min-ana-lem (SAMove x) min = <>
min-ana-lem (SADel) min = <>
min-ana-lem (SAConAsc) min = <>
min-ana-lem (SAConVar p) min = <>
min-ana-lem (SAConLam x₁) min = <>
min-ana-lem (SAConApArr x) min = <>
min-ana-lem (SAConApOtw x) min = <>
min-ana-lem (SAConNumlit) min = <>
min-ana-lem (SAConPlus1 x) min = <>
min-ana-lem (SAConPlus2 x) min = <>
min-ana-lem (SAConNEHole) min = <>
min-ana-lem (SAFinish x) min = <>
min-ana-lem (SAZipAsc1 x) min = min
min-ana-lem (SAZipAsc2 x x₁ x₂ x₃) min = <>
min-ana-lem (SAZipApArr x x₁ x₂ c x₃) min = min
min-ana-lem (SAZipApAna x x₁ x₂) min = min
min-ana-lem (SAZipPlus1 x) min = min
min-ana-lem (SAZipPlus2 x) min = min
min-ana-lem (SAZipNEHole x x₁ c) min = min
min-ana-lem SAConInl _ = <>
min-ana-lem SAConInr _ = <>
min-ana-lem (SAConCase1 x₁ x₂ x₃) _ = <>
min-ana-lem (SAConCase2 x₁ x₂ x₃) _ = <>
min-ana-lem SAConPair _ = <>
min-ana-lem (SAConFst1 pr) _ = <>
min-ana-lem (SAConFst2 inc) _ = <>
min-ana-lem (SAConSnd1 pr) _ = <>
min-ana-lem (SAConSnd2 inc) _ = <>
min-ana-lem (SAZipPair1 x x₁ x₂ x₃) min = min
min-ana-lem (SAZipPair2 x x₁ x₂ x₃) min = min
min-ana-lem (SAZipFst x x₁ x₂ x₃ x₄) min = min
min-ana-lem (SAZipSnd x x₁ x₂ x₃ x₄) min = min
min-ana-lem (SAZipLam1 x x₁ x₂ x₃ x₄ x₅) min = min
min-ana-lem (SAZipLam2 x x₁ x₂ x₃) min = min
-- any derivation of an action can be minimized to avoid this cases that
-- induce non-determinism.
mutual
min-synth : ∀{Γ e t α e' t'} →
(d : Γ ⊢ e => t ~ α ~> e' => t') →
Σ[ e'' ∈ zexp ] Σ[ d' ∈ Γ ⊢ e => t ~ α ~> e'' => t' ] aasubmin-synth d'
min-synth (SAMove x) = _ , SAMove x , <>
min-synth SADel = _ , SADel , <>
min-synth SAConAsc = _ , SAConAsc , <>
min-synth (SAConVar p) = _ , SAConVar p , <>
min-synth (SAConLam x₁) = _ , SAConLam x₁ , <>
min-synth (SAConApArr x) = _ , SAConApArr x , <>
min-synth (SAConApOtw x) = _ , SAConApOtw x , <>
min-synth SAConNumlit = _ , SAConNumlit , <>
min-synth (SAConPlus1 x) = _ , SAConPlus1 x , <>
min-synth (SAConPlus2 x) = _ , SAConPlus2 x , <>
min-synth SAConNEHole = _ , SAConNEHole , <>
min-synth (SAFinish x) = _ , SAFinish x , <>
min-synth (SAZipAsc2 x x₁ x₂ x₃) = _ , SAZipAsc2 x x₁ x₂ x₃ , <>
min-synth (SAZipAsc1 x) with min-ana x
... | _ , a , b = _ , SAZipAsc1 a , b
min-synth (SAZipApArr x x₁ x₂ d x₃) with min-synth d
... | _ , a , b = _ , (SAZipApArr x x₁ x₂ a x₃) , b
min-synth (SAZipApAna x x₁ x₂) with min-ana x₂
... | _ , a , b = _ , SAZipApAna x x₁ a , b
min-synth (SAZipPlus1 x) with min-ana x
... | _ , a , b = _ , SAZipPlus1 a , b
min-synth (SAZipPlus2 x) with min-ana x
... | _ , a , b = _ , SAZipPlus2 a , b
min-synth (SAZipNEHole x x₁ d) with min-synth d
... | _ , a , b = _ , SAZipNEHole x x₁ a , b
min-synth SAConInl = _ , SAConInl , <>
min-synth SAConInr = _ , SAConInr , <>
min-synth (SAConCase1 a b c) = _ , SAConCase1 a b c , <>
min-synth (SAConCase2 a b c) = _ , SAConCase2 a b c , <>
min-synth SAConPair = _ , SAConPair , <>
min-synth (SAConFst1 pr) = _ , SAConFst1 pr , <>
min-synth (SAConFst2 inc) = _ , SAConFst2 inc , <>
min-synth (SAConSnd1 pr) = _ , SAConSnd1 pr , <>
min-synth (SAConSnd2 inc) = _ , SAConSnd2 inc , <>
min-synth (SAZipPair1 x x₁ d x₃) with min-synth d
... | _ , a , b = _ , (SAZipPair1 x x₁ a x₃) , b
min-synth (SAZipPair2 x x₁ x₂ d) with min-synth d
... | _ , a , b = _ , (SAZipPair2 x x₁ x₂ a) , b
min-synth (SAZipFst x x₁ x₂ x₃ d) with min-synth d
... | _ , a , b = _ , (SAZipFst x x₁ x₂ x₃ a) , b
min-synth (SAZipSnd x x₁ x₂ x₃ d) with min-synth d
... | _ , a , b = _ , (SAZipSnd x x₁ x₂ x₃ a) , b
min-synth (SAZipLam1 x x₁ x₂ x₃ x₄ x₅) = _ , SAZipLam1 x x₁ x₂ x₃ x₄ x₅ , <>
min-synth (SAZipLam2 x x₁ x₂ d) with min-synth d
... | _ , a , b = _ , SAZipLam2 x x₁ x₂ a , b
min-ana : ∀{Γ e α e' t} →
(d : Γ ⊢ e ~ α ~> e' ⇐ t) →
Σ[ e'' ∈ zexp ] Σ[ d' ∈ Γ ⊢ e ~ α ~> e'' ⇐ t ] aasubmin-ana d'
min-ana (AASubsume {Γ = Γ} x x₁ (SAMove x₂) x₃) = _ , AAMove x₂ , <>
min-ana (AASubsume x x₁ (SADel) x₃) = _ , AADel , <>
min-ana (AASubsume {Γ = Γ} {t = t} {t' = t'} x x₁ SAConAsc x₃) =
_ , AAConAsc {Γ = Γ} {t = t} , <>
min-ana (AASubsume x x₁ (SAConVar p) x₃) = _ , AASubsume x x₁ (SAConVar p) x₃ , <>
min-ana (AASubsume EETop SEHole (SAConLam x₃) TCRefl) = _ , AAConLam1 x₃ MAArr , <>
min-ana (AASubsume EETop SEHole (SAConLam x₃) TCHole2) = _ , AAConLam1 x₃ MAHole , <>
min-ana (AASubsume EETop SEHole (SAConLam x₃) (TCArr x₄ x₅)) = _ , AAConLam1 x₃ MAArr , <>
min-ana (AASubsume x x₁ (SAConApArr x₂) x₃) =
_ , AASubsume x x₁ (SAConApArr x₂) x₃ , <>
min-ana (AASubsume x x₁ (SAConApOtw x₂) x₃) =
_ , AASubsume x x₁ (SAConApOtw x₂) x₃ , <>
min-ana (AASubsume x x₁ SAConNumlit x₃) = _ , AASubsume x x₁ SAConNumlit x₃ , <>
min-ana (AASubsume x x₁ (SAConPlus1 x₂) x₃) =
_ , AASubsume x x₁ (SAConPlus1 x₂) x₃ , <>
min-ana (AASubsume x x₁ (SAConPlus2 x₂) x₃) =
_ , AASubsume x x₁ (SAConPlus2 x₂) x₃ , <>
min-ana (AASubsume x x₁ (SAConNEHole) x₃) =
_ , AASubsume x x₁ (SAConNEHole) x₃ , <>
min-ana (AASubsume x x₁ (SAFinish x₂) x₃) = _ , AASubsume x x₁ (SAFinish x₂) x₃ , <>
min-ana (AASubsume x x₁ (SAZipAsc2 x₂ x₃ x₄ x₅) x₆) =
_ , AASubsume x x₁ (SAZipAsc2 x₂ x₃ x₄ x₅) x₆ , <>
min-ana (AASubsume x x₁ (SAZipAsc1 x₂) x₃) with min-ana x₂
... | a , b , c = _ , AASubsume x x₁ (SAZipAsc1 b) x₃ , c
min-ana (AASubsume x x₁ (SAZipApArr x₂ x₃ x₄ x₅ x₆) x₇) with min-synth x₅
... | a , b , c = _ , AASubsume x x₁ (SAZipApArr x₂ x₃ x₄ b x₆) x₇ , c
min-ana (AASubsume x x₁ (SAZipApAna x₂ x₃ x₄) x₅) with min-ana x₄
... | a , b , c = _ , AASubsume x x₁ (SAZipApAna x₂ x₃ b) x₅ , c
min-ana (AASubsume x x₁ (SAZipPlus1 x₂) x₃) with min-ana x₂
... | a , b , c = _ , AASubsume x x₁ (SAZipPlus1 b) x₃ , c
min-ana (AASubsume x x₁ (SAZipPlus2 x₂) x₃) with min-ana x₂
... | a , b , c = _ , AASubsume x x₁ (SAZipPlus2 b) x₃ , c
min-ana (AASubsume x x₁ (SAZipNEHole x₂ x₃ x₄) x₅) with min-synth x₄
... | a , b , c = _ , AASubsume x x₁ (SAZipNEHole x₂ x₃ b) x₅ , c
min-ana (AASubsume EETop SEHole (SAConCase1 a b c) z) =
_ , AAConCase a b , <>
min-ana (AASubsume EETop (SAsc x₁) (SAConCase1 a b c) z) =
_ , AASubsume EETop (SAsc x₁) (SAConCase1 a b c) z , <>
min-ana (AASubsume EETop (SVar x₁) (SAConCase1 a b c) z) =
_ , AASubsume EETop (SVar x₁) (SAConCase1 a b c) z , <>
min-ana (AASubsume EETop (SLam x x₁) (SAConCase1 x₂ x₄ x₅) x₃) =
_ , AASubsume EETop (SLam x x₁) (SAConCase1 x₂ x₄ x₅) x₃ , <>
min-ana (AASubsume EETop (SAp y₁ x₁ x₂) (SAConCase1 a b c) z) =
_ , AASubsume EETop (SAp y₁ x₁ x₂) (SAConCase1 a b c) z , <>
min-ana (AASubsume EETop SNum (SAConCase1 a b c) z) =
_ , AASubsume EETop SNum (SAConCase1 a b c) z , <>
min-ana (AASubsume EETop (SPlus x₁ x₂) (SAConCase1 a b c) z) =
_ , AASubsume EETop (SPlus x₁ x₂) (SAConCase1 a b c) z , <>
min-ana (AASubsume EETop (SNEHole y₁) (SAConCase1 a b c) z) =
_ , AASubsume EETop (SNEHole y₁) (SAConCase1 a b c) z , <>
min-ana (AASubsume EETop (SPair x₁ x₆) (SAConCase1 x₂ x₄ x₅) x₃) =
_ , (AASubsume EETop (SPair x₁ x₆) (SAConCase1 x₂ x₄ x₅) x₃) , <>
min-ana (AASubsume EETop (SFst x x₁) (SAConCase1 x₂ x₃ x₄) x₅) =
_ , AASubsume EETop (SFst x x₁) (SAConCase1 x₂ x₃ x₄) x₅ , <>
min-ana (AASubsume EETop (SSnd x x₁) (SAConCase1 x₂ x₃ x₄) x₅) =
_ , AASubsume EETop (SSnd x x₁) (SAConCase1 x₂ x₃ x₄) x₅ , <>
min-ana (AASubsume x y (SAConCase2 a b c) z) =
_ , AASubsume x y (SAConCase2 a b c) z , <>
min-ana (AAMove x) = _ , AAMove x , <>
min-ana AADel = _ , AADel , <>
min-ana AAConAsc = _ , AAConAsc , <>
min-ana (AAConVar x₁ p) = _ , AAConVar x₁ p , <>
min-ana (AAConLam1 x₁ x₂) = _ , AAConLam1 x₁ x₂ , <>
min-ana (AAConLam2 x₁ x₂) = _ , AAConLam2 x₁ x₂ , <>
min-ana (AAConNumlit x) = _ , AAConNumlit x , <>
min-ana (AAFinish x) = _ , AAFinish x , <>
min-ana (AAZipLam x₁ x₂ d) with min-ana d
... | a , b , c = _ , AAZipLam x₁ x₂ b , c
min-ana (AASubsume x x₁ SAConInl TCRefl) = _ , AAConInl1 MSSum , <>
min-ana (AASubsume x x₁ SAConInl TCHole2) = _ , AAConInl1 MSHole , <>
min-ana (AASubsume x x₁ SAConInl (TCSum x₃ x₄)) = _ , AAConInl1 MSSum , <>
min-ana (AASubsume x x₁ SAConInr TCRefl) = _ , AAConInr1 MSSum , <>
min-ana (AASubsume x x₁ SAConInr TCHole2) = _ , AAConInr1 MSHole , <>
min-ana (AASubsume x x₁ SAConInr (TCSum x₃ x₄)) = _ , AAConInr1 MSSum , <>
min-ana (AAConInl1 x) = _ , AAConInl1 x , <>
min-ana (AAConInl2 x) = _ , AAConInl2 x , <>
min-ana (AAConInr1 x) = _ , AAConInr1 x , <>
min-ana (AAConInr2 x) = _ , AAConInr2 x , <>
min-ana (AAConCase x₁ x₂) = _ , AAConCase x₁ x₂ , <>
min-ana (AAZipInl x x₁) with min-ana x₁
... | a , b , c = _ , AAZipInl x b , c
min-ana (AAZipInr x x₁) with min-ana x₁
... | a , b , c = _ , AAZipInr x b , c
min-ana (AAZipCase1 x₁ x₂ x₃ x₄ x₅ x₆ x₇ x₈) with min-synth x₅
... | a , b , c = _ , AAZipCase1 x₁ x₂ x₃ x₄ b x₆ x₇ x₈ , c
min-ana (AAZipCase2 x₁ x₂ x₃ x₄ x₅) with min-ana x₅
... | a , b , c = _ , AAZipCase2 x₁ x₂ x₃ x₄ b , c
min-ana (AAZipCase3 x₁ x₂ x₃ x₄ x₆) with min-ana x₆
... | a , b , c = _ , AAZipCase3 x₁ x₂ x₃ x₄ b , c
min-ana (AASubsume x x₁ (SAZipLam1 x₂ x₄ x₅ x₆ x₇ x₈) x₃) =
_ , AASubsume x x₁ (SAZipLam1 x₂ x₄ x₅ x₆ x₇ x₈) x₃ , <>
min-ana (AASubsume x x₁ (SAZipLam2 x₂ x₄ x₅ x₆) x₃) with min-synth x₆
... | a , b , c = _ , AASubsume x x₁ (SAZipLam2 x₂ x₄ x₅ b) x₃ , c
min-ana (AASubsume x x₁ SAConPair x₃) =
_ , AASubsume x x₁ SAConPair x₃ , <>
min-ana (AASubsume x x₁ (SAConFst1 x₂) x₃) = _ , AASubsume x x₁ (SAConFst1 x₂) x₃ , <>
min-ana (AASubsume x x₁ (SAConFst2 x₂) x₃) =
_ , AASubsume x x₁ (SAConFst2 x₂) x₃ , <>
min-ana (AASubsume x x₁ (SAConSnd1 x₂) x₃) = _ , AASubsume x x₁ (SAConSnd1 x₂) x₃ , <>
min-ana (AASubsume x x₁ (SAConSnd2 x₂) x₃) =
_ , AASubsume x x₁ (SAConSnd2 x₂) x₃ , <>
min-ana (AASubsume x x₁ (SAZipPair1 x₂ x₃ x₄ x₅) x₆) with min-synth x₄
... | a , b , c = _ , (AASubsume x x₁ (SAZipPair1 x₂ x₃ b x₅) x₆) , c
min-ana (AASubsume x x₁ (SAZipPair2 x₂ x₃ x₄ x₅) x₆) with min-synth x₅
... | a , b , c = _ , AASubsume x x₁ (SAZipPair2 x₂ x₃ x₄ b) x₆ , c
min-ana (AASubsume x x₁ (SAZipFst x₂ x₃ x₄ x₅ x₆) x₇) with min-synth x₆
... | a , b , c = _ , AASubsume x x₁ (SAZipFst x₂ x₃ x₄ x₅ b) x₇ , c
min-ana (AASubsume x x₁ (SAZipSnd x₂ x₃ x₄ x₅ x₆) x₇) with min-synth x₆
... | a , b , c = _ , AASubsume x x₁ (SAZipSnd x₂ x₃ x₄ x₅ b) x₇ , c
-- these theorems argue that if a derivation is already subsumption
-- minimal than the minimzer does not change the resultant
-- expression--that it's conservative in this sense. they do not argue
-- that the derivation that's computed is itself the same as the input
-- derivation.
mutual
min-fixed-synth : ∀{Γ e t α e' t'} →
(d : Γ ⊢ e => t ~ α ~> e' => t') →
aasubmin-synth d →
e' == π1 (min-synth d)
min-fixed-synth (SAMove x) min = refl
min-fixed-synth SADel min = refl
min-fixed-synth SAConAsc min = refl
min-fixed-synth (SAConVar p) min = refl
min-fixed-synth (SAConLam x₁) min = refl
min-fixed-synth (SAConApArr x) min = refl
min-fixed-synth (SAConApOtw x) min = refl
min-fixed-synth SAConNumlit min = refl
min-fixed-synth (SAConPlus1 x) min = refl
min-fixed-synth (SAConPlus2 x) min = refl
min-fixed-synth SAConNEHole min = refl
min-fixed-synth (SAFinish x) min = refl
min-fixed-synth (SAZipAsc1 x) min with min-fixed-ana x min
... | qq with min-ana x
... | (e'' , d' , min') = ap1 (λ q → q ·:₁ _) qq
min-fixed-synth (SAZipAsc2 x x₁ x₂ x₃) min = refl
min-fixed-synth (SAZipApArr x x₁ x₂ d x₃) min with min-fixed-synth d min
... | qq with min-synth d
... | (e'' , d' , min') = ap1 (λ q → q ∘₁ _) qq
min-fixed-synth (SAZipApAna x x₁ x₂) min with min-fixed-ana x₂ min
... | qq with min-ana x₂
... | (e'' , _ , _) = ap1 (λ q → _ ∘₂ q) qq
min-fixed-synth (SAZipPlus1 x) min with min-fixed-ana x min
... | qq with min-ana x
... | (e'' , _ , _) = ap1 (λ q → q ·+₁ _) qq
min-fixed-synth (SAZipPlus2 x) min with min-fixed-ana x min
... | qq with min-ana x
... | (e'' , _ , _) = ap1 (λ q → _ ·+₂ q) qq
min-fixed-synth (SAZipNEHole x x₁ d) min with min-fixed-synth d min
... | qq with min-synth d
... | (e'' , _ , _) = ap1 ⦇⌜_⌟⦈[ _ ] qq
min-fixed-synth SAConInl min = refl
min-fixed-synth SAConInr min = refl
min-fixed-synth (SAConCase1 x₁ x₂ x₃) min = refl
min-fixed-synth (SAConCase2 x₁ x₂ x₃) min = refl
min-fixed-synth SAConPair min = refl
min-fixed-synth (SAConFst1 x₁) min = refl
min-fixed-synth (SAConFst2 x₁) min = refl
min-fixed-synth (SAConSnd1 x₁) min = refl
min-fixed-synth (SAConSnd2 x₁) min = refl
min-fixed-synth (SAZipPair1 x x₁ d x₃) min with min-fixed-synth d min
... | qq = ap1 (λ q → ⟨ q , _ ⟩₁) qq
min-fixed-synth (SAZipPair2 x x₁ x₂ d) min with min-fixed-synth d min
... | qq = ap1 (λ q → ⟨ _ , q ⟩₂) qq
min-fixed-synth (SAZipFst x x₁ x₂ x₃ d) min with min-fixed-synth d min
... | qq = ap1 (λ q → fst q) qq
min-fixed-synth (SAZipSnd x x₁ x₂ x₃ d) min with min-fixed-synth d min
... | qq = ap1 (λ q → snd q) qq
min-fixed-synth (SAZipLam1 x x₁ x₂ x₃ x₄ x₅) min = refl
min-fixed-synth (SAZipLam2 x x₁ x₂ d) min with min-fixed-synth d min
... | qq = ap1 (λ q → ·λ _ ·[ _ ]₂ q) qq
min-fixed-ana : ∀{Γ e t α e' } →
(d : Γ ⊢ e ~ α ~> e' ⇐ t) →
aasubmin-ana d →
e' == π1 (min-ana d)
min-fixed-ana (AASubsume x x₁ (SAMove x₂) x₃) min = refl
min-fixed-ana (AASubsume x x₁ SADel x₃) min = refl
min-fixed-ana (AASubsume x x₁ SAConAsc x₃) min = abort min
min-fixed-ana (AASubsume x₁ x₂ (SAConVar p) x₃) min = refl
min-fixed-ana (AASubsume x₁ x₂ (SAConLam x₃) x₄) min = abort min
min-fixed-ana (AASubsume x x₁ (SAConApArr x₂) x₃) min = refl
min-fixed-ana (AASubsume x x₁ (SAConApOtw x₂) x₃) min = refl
min-fixed-ana (AASubsume x x₁ SAConNumlit x₃) min = refl
min-fixed-ana (AASubsume x x₁ (SAConPlus1 x₂) x₃) min = refl
min-fixed-ana (AASubsume x x₁ (SAConPlus2 x₂) x₃) min = refl
min-fixed-ana (AASubsume x x₁ SAConNEHole x₃) min = refl
min-fixed-ana (AASubsume x x₁ (SAFinish x₂) x₃) min = refl
min-fixed-ana (AASubsume x x₁ (SAZipAsc1 x₂) x₃) min with min-fixed-ana x₂ min
... | qq with min-ana x₂
... | (e'' , _ , _) = ap1 (λ q → q ·:₁ _) qq
min-fixed-ana (AASubsume x x₁ (SAZipAsc2 x₂ x₃ x₄ x₅) x₆) min = refl
min-fixed-ana (AASubsume x x₁ (SAZipApArr x₂ x₃ x₄ x₅ x₆) x₇) min with min-fixed-synth x₅ min
... | qq with min-synth x₅
... | (e'' , d' , min') = ap1 (λ q → q ∘₁ _) qq
min-fixed-ana (AASubsume x x₁ (SAZipApAna x₂ x₃ x₄) x₅) min with min-fixed-ana x₄ min
... | qq with min-ana x₄
... | (e'' , _ , _) = ap1 (λ q → _ ∘₂ q) qq
min-fixed-ana (AASubsume x x₁ (SAZipPlus1 x₂) x₃) min with min-fixed-ana x₂ min
... | qq with min-ana x₂
... | (e'' , _ , _) = ap1 (λ q → q ·+₁ _) qq
min-fixed-ana (AASubsume x x₁ (SAZipPlus2 x₂) x₃) min with min-fixed-ana x₂ min
... | qq with min-ana x₂
... | (e'' , _ , _) = ap1 (λ q → _ ·+₂ q) qq
min-fixed-ana (AASubsume x x₁ (SAZipNEHole x₂ x₃ x₄) x₅) min with min-fixed-synth x₄ min
... | qq with min-synth x₄
... | (e'' , _ , _) = ap1 ⦇⌜_⌟⦈[ _ ] qq
min-fixed-ana (AAMove x) min = refl
min-fixed-ana AADel min = refl
min-fixed-ana AAConAsc min = refl
min-fixed-ana (AAConVar x₁ p) min = refl
min-fixed-ana (AAConLam1 x₁ x₂) min = refl
min-fixed-ana (AAConLam2 x₁ x₂) min = refl
min-fixed-ana (AAConNumlit x) min = refl
min-fixed-ana (AAFinish x) min = refl
min-fixed-ana (AAZipLam x₁ x₂ d) min with min-fixed-ana d min
... | qq with min-ana d
... | (e'' , _ , _) = ap1 (λ q → ·λ _ q) qq
min-fixed-ana (AASubsume x x₁ SAConInl x₃) min = abort min
min-fixed-ana (AASubsume x x₁ SAConInr x₃) min = abort min
min-fixed-ana (AASubsume EETop (SAsc x₁) (SAConCase1 x₃ x₄ x₅) x₆) min = refl
min-fixed-ana (AASubsume EETop (SVar x₁) (SAConCase1 x₃ x₄ x₅) x₆) min = refl
min-fixed-ana (AASubsume EETop (SLam x x₁) (SAConCase1 x₂ x₄ x₅) x₃) min = refl
min-fixed-ana (AASubsume EETop (SPair x₁ x₆) (SAConCase1 x₂ x₄ x₅) x₃) min = refl
min-fixed-ana (AASubsume EETop (SAp x₂ x₁ x₃) (SAConCase1 x₄ x₅ x₆) x₇) min = refl
min-fixed-ana (AASubsume EETop SNum (SAConCase1 x₃ x₄ x₅) x₆) min = refl
min-fixed-ana (AASubsume EETop (SPlus x₁ x₂) (SAConCase1 x₃ x₄ x₅) x₆) min = refl
min-fixed-ana (AASubsume EETop SEHole (SAConCase1 x₃ x₄ x₅) x₆) min = abort min
min-fixed-ana (AASubsume EETop (SNEHole x₂) (SAConCase1 x₃ x₄ x₅) x₆) min = refl
min-fixed-ana (AASubsume EETop (SFst x x₁) (SAConCase1 x₃ x₄ x₅) x₆) min = refl
min-fixed-ana (AASubsume EETop (SSnd x x₁) (SAConCase1 x₃ x₄ x₅) x₆) min = refl
min-fixed-ana (AASubsume x₁ x₂ (SAConCase2 x₃ x₄ x₅) x₆) min = refl
min-fixed-ana (AAConInl1 x) min = refl
min-fixed-ana (AAConInl2 x) min = refl
min-fixed-ana (AAConInr1 x) min = refl
min-fixed-ana (AAConInr2 x) min = refl
min-fixed-ana (AAConCase x₁ x₂) min = refl
min-fixed-ana (AAZipInl x d) min with min-fixed-ana d min
... | qq with min-ana d
... | (e'' , _ , _) = ap1 inl qq
min-fixed-ana (AAZipInr x d) min with min-fixed-ana d min
... | qq with min-ana d
... | (e'' , _ , _) = ap1 inr qq
min-fixed-ana (AAZipCase1 x₁ x₂ x₃ x₄ x₅ x₆ x₇ x₈) min with min-fixed-synth x₅ min
... | qq with min-synth x₅
... | (e'' , _ , _) = ap1 (λ q → case₁ q _ _ _ _) qq
min-fixed-ana (AAZipCase2 x₁ x₂ x₃ x₄ d) min with min-fixed-ana d min
... | qq with min-ana d
... | (e'' , _ , _) = ap1 (λ q → case₂ _ _ q _ _) qq
min-fixed-ana (AAZipCase3 x₁ x₂ x₃ x₄ d) min with min-fixed-ana d min
... | qq with min-ana d
... | (e'' , _ , _) = ap1 (λ q → case₃ _ _ _ _ q) qq
min-fixed-ana (AASubsume x x₁ SAConPair x₃) min = refl
min-fixed-ana (AASubsume x x₁ (SAConFst1 x₂) x₃) min = refl
min-fixed-ana (AASubsume x x₁ (SAConFst2 x₂) x₃) min = refl
min-fixed-ana (AASubsume x x₁ (SAConSnd1 x₂) x₃) min = refl
min-fixed-ana (AASubsume x x₁ (SAConSnd2 x₂) x₃) min = refl
min-fixed-ana (AASubsume x x₁ (SAZipPair1 x₂ x₄ d x₆) x₃) min with min-fixed-synth d min
... | qq = ap1 (λ q → ⟨ q , _ ⟩₁) qq
min-fixed-ana (AASubsume x x₁ (SAZipPair2 x₂ x₄ x₅ d) x₃) min with min-fixed-synth d min
... | qq = ap1 (λ q → ⟨ _ , q ⟩₂) qq
min-fixed-ana (AASubsume x x₁ (SAZipFst x₂ x₄ x₅ x₆ d) x₃) min with min-fixed-synth d min
... | qq = ap1 (λ q → fst q) qq
min-fixed-ana (AASubsume x x₁ (SAZipSnd x₂ x₄ x₅ x₆ d) x₃) min with min-fixed-synth d min
... | qq = ap1 (λ q → snd q) qq
min-fixed-ana (AASubsume x x₁ (SAZipLam1 x₂ x₄ x₅ x₆ x₇ x₈) x₃) min = refl
min-fixed-ana (AASubsume x x₁ (SAZipLam2 x₂ x₄ x₅ d) x₃) min with min-fixed-synth d min
... | qq = ap1 (λ q → ·λ _ ·[ _ ]₂ q) qq
| {
"alphanum_fraction": 0.5954478027,
"avg_line_length": 52.7432762836,
"ext": "agda",
"hexsha": "da1eacd537e410a13198e61e56e6de22b9f9d454",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-agda",
"max_forks_repo_path": "aasubsume-min.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazelnut-agda",
"max_issues_repo_path": "aasubsume-min.agda",
"max_line_length": 97,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnut-agda",
"max_stars_repo_path": "aasubsume-min.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 9807,
"size": 21572
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.