Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
390 commits
Select commit Hold shift + click to select a range
057a842
moved definition
thomasporter522 Jul 18, 2023
fd4f528
fixed issue in core premise
thomasporter522 Jul 18, 2023
b230a2a
added hctx wf
thomasporter522 Jul 18, 2023
731a25b
restructure and complete wf-ta
thomasporter522 Jul 18, 2023
c229750
completed current headers of lemmas-wf
thomasporter522 Jul 18, 2023
29ee41f
removed copied code
thomasporter522 Jul 18, 2023
7f041e1
updated downstream effects
thomasporter522 Jul 18, 2023
d486673
updated downstream effects
thomasporter522 Jul 18, 2023
1d1e6a1
updated downstream effects
thomasporter522 Jul 18, 2023
6b3d04b
Edits for new syntax/premises.
Crazycolorz5 Jul 18, 2023
221df68
updated to reflect upstream changes
thomasporter522 Jul 18, 2023
ffe5baa
Merge branch 'master' of https://github.com/hazelgrove/hazelnut-polym…
thomasporter522 Jul 18, 2023
d462259
not sure ...
thomasporter522 Jul 18, 2023
07a6d29
More updating to new rules/syntax.
Crazycolorz5 Jul 18, 2023
6b14681
progress on progress
thomasporter522 Jul 18, 2023
f7832bd
Merge branch 'master' of https://github.com/hazelgrove/hazelnut-polym…
thomasporter522 Jul 18, 2023
8d1deab
added canonical indet forms for forall
thomasporter522 Jul 18, 2023
05d15b1
progress on progress
thomasporter522 Jul 19, 2023
08d925a
Lemmas about contexts and substitution in them.
Crazycolorz5 Jul 19, 2023
e0457cd
Finish the lambda case for lemma-tysubst.
Crazycolorz5 Jul 19, 2023
481a8df
Puzzling over how to make the induction stronger.
Crazycolorz5 Jul 19, 2023
2f8a257
Generalize type context operations as maps on contexts and add change…
Crazycolorz5 Jul 20, 2023
409f41d
Some partial work.
Crazycolorz5 Jul 20, 2023
9d10c6f
Add back in binding names.
Crazycolorz5 Jul 20, 2023
5c2bfd9
Update some files to new convention.
Crazycolorz5 Jul 20, 2023
cf10cb4
Same as prev.
Crazycolorz5 Jul 20, 2023
59c6ce0
Fix type substitution.
Crazycolorz5 Jul 20, 2023
1c25b32
All prereqs for pres.
Crazycolorz5 Jul 24, 2023
a86e416
remove apartness from TATLam.
Crazycolorz5 Jul 24, 2023
6775e63
More work on wf lemmas.
Crazycolorz5 Jul 25, 2023
40d6fc6
added back analytic TLam
thomasporter522 Jul 25, 2023
889ac9a
added back analytic TLam
thomasporter522 Jul 25, 2023
662708f
added back analytic TLam
thomasporter522 Jul 25, 2023
19af3f7
More work on lemmas-wf
Crazycolorz5 Jul 25, 2023
5cb9f3b
Some partial work.
Crazycolorz5 Jul 20, 2023
f924d0f
working on update
thomasporter522 Jul 25, 2023
08365d7
Merge branch 'master' of https://github.com/hazelgrove/hazelnut-polym…
thomasporter522 Jul 25, 2023
c45fb9b
Finish lemmas-well-formed.
Crazycolorz5 Jul 25, 2023
b84fa7e
updated
thomasporter522 Jul 25, 2023
5f2f133
updated
thomasporter522 Jul 25, 2023
2500a40
added premise to ana-TLam completed elab-unicity
thomasporter522 Jul 25, 2023
da2ab3a
clean up
thomasporter522 Jul 25, 2023
eec5ab3
added type contexts to hole contexts
thomasporter522 Jul 25, 2023
60c3a26
updated to reflect type holes
thomasporter522 Jul 25, 2023
bb37fb9
updated to reflect type holes
thomasporter522 Jul 25, 2023
66fc896
trying to make necessary incr-typ lemmata
thomasporter522 Jul 25, 2023
ecebedb
completed necessary lemmata
thomasporter522 Jul 26, 2023
7cd4f39
added ana-TLam case
thomasporter522 Jul 26, 2023
d1b54b9
some cases in progress
thomasporter522 Jul 27, 2023
9ddb603
More work on preservation; substitution into different data.
Crazycolorz5 Jul 28, 2023
f2730bf
progress on progress
thomasporter522 Jul 28, 2023
aa99ff9
hole context well formed initial
thomasporter522 Aug 1, 2023
c9c5fe5
Merge branch 'master' into newtypbindings
Crazycolorz5 Aug 1, 2023
5c87e4f
progress on hole-ctx-wf
thomasporter522 Aug 1, 2023
2e47257
Fix a few remaining conflicts.
Crazycolorz5 Aug 1, 2023
3de1396
Some progress towards fixing everything
Crazycolorz5 Aug 1, 2023
092eae5
added type environments
thomasporter522 Aug 1, 2023
c2e1816
updated substitution typing
thomasporter522 Aug 1, 2023
d9012c9
updated type substitution
thomasporter522 Aug 1, 2023
ba9dbef
updated to reflect typ env
thomasporter522 Aug 1, 2023
096aec2
updated to reflect typ env
thomasporter522 Aug 1, 2023
9a8d9e5
trying to implement typ env
thomasporter522 Aug 1, 2023
2243846
Some work on canonical indet forms.
Crazycolorz5 Aug 2, 2023
ea9010f
Fix indet forms aside from impossible cases.
Crazycolorz5 Aug 2, 2023
7b4f112
finish cif
Crazycolorz5 Aug 2, 2023
26c9679
Finish prereqs to progress.
Crazycolorz5 Aug 2, 2023
66e1d3f
updated hole type subst
thomasporter522 Aug 7, 2023
dfda663
updated hole type subst
thomasporter522 Aug 7, 2023
64551a4
updated to reflect updated hole type subst
thomasporter522 Aug 7, 2023
db64693
wf-ta and type subst
thomasporter522 Aug 7, 2023
6ffcd1a
Work on lemma for the lemma for pres
Crazycolorz5 Aug 7, 2023
b1816ba
progress complete relative to ta-wf
thomasporter522 Aug 7, 2023
352f843
updating subst typing
thomasporter522 Aug 7, 2023
eb59330
Resolve merge uop to pres and prog
Crazycolorz5 Aug 7, 2023
b7ec94b
Merge branch 'newtypbindings'
Crazycolorz5 Aug 7, 2023
5005b06
delete empty file
thomasporter522 Aug 7, 2023
373719d
fix variable mismatch
thomasporter522 Aug 7, 2023
716caae
working on typsub-wf
thomasporter522 Aug 7, 2023
c47b7de
added type contexts to contraction
thomasporter522 Aug 7, 2023
53f0e0c
progress on progress
thomasporter522 Aug 7, 2023
42a1b99
Disallow unsolved metas.
Crazycolorz5 Aug 8, 2023
21099df
Weakening
Crazycolorz5 Aug 8, 2023
1436d27
Change STASubst to allow mixed ordering of type var substitution and …
Crazycolorz5 Aug 8, 2023
63ad275
lemmas-subst-ta
Crazycolorz5 Aug 8, 2023
8d78f13
progress complete
thomasporter522 Aug 8, 2023
b48fda0
Merge branch 'master' of https://github.com/hazelgrove/hazelnut-polym…
thomasporter522 Aug 8, 2023
e4bc2c3
updated disjointness
thomasporter522 Aug 8, 2023
03cff1a
updated holes disjoint checks
thomasporter522 Aug 8, 2023
5f45120
updated lemmas freshness
thomasporter522 Aug 8, 2023
6427d68
added holes to lemmas matching - needs alpha equiv
thomasporter522 Aug 8, 2023
730bbe0
Add predicates for type variable uniqueness.
Crazycolorz5 Aug 8, 2023
03bb3d5
working on elaborability
thomasporter522 Aug 8, 2023
10f94bd
Merge branch 'master' of https://github.com/hazelgrove/hazelnut-polym…
thomasporter522 Aug 8, 2023
52fe83a
tidying core
thomasporter522 Aug 8, 2023
1ffe711
MOre work on pres.
Crazycolorz5 Aug 10, 2023
1859e59
revised core rules to deal with type variables
thomasporter522 Aug 10, 2023
db06a8a
alpha equivalence
thomasporter522 Aug 10, 2023
373b8a7
alpha equivalence
thomasporter522 Aug 10, 2023
933bcf6
Merge branch 'master' of https://github.com/hazelgrove/hazelnut-polym…
thomasporter522 Aug 10, 2023
24327df
alpha consistency
thomasporter522 Aug 10, 2023
41282d1
Open consistency to outer scope.
Crazycolorz5 Aug 10, 2023
dacd128
Fix typo in ConsistArr.
Crazycolorz5 Aug 10, 2023
522fd53
Some work on lemmas-consistency.
Crazycolorz5 Aug 10, 2023
b398bdc
Work towards tysubst lemma
Crazycolorz5 Aug 11, 2023
63a19b8
updated canonical indeterminate forms
thomasporter522 Aug 11, 2023
e4f5043
fixed boxedval definitions to use consistency
thomasporter522 Aug 11, 2023
de2fea2
updated cast rules with alpha equivalence
thomasporter522 Aug 11, 2023
50913cf
updated lemmas progress checks
thomasporter522 Aug 11, 2023
3565f5d
replaced consistency w/ alpha equiv in failed cast
thomasporter522 Aug 11, 2023
bfc110f
Work on lemma-subst-subst and the STA rules.
Crazycolorz5 Aug 11, 2023
7750afb
Update preservation to include constructors for alpha equiv
Crazycolorz5 Aug 15, 2023
ebf458a
work on canonical boxed forms
thomasporter522 Aug 15, 2023
1efaf94
core rule change
thomasporter522 Aug 15, 2023
d2c2dc6
Merge branch 'master' of https://github.com/hazelgrove/hazelnut-polym…
thomasporter522 Aug 15, 2023
6968cda
Edits to tysubst
Crazycolorz5 Aug 15, 2023
4c188cc
fixed order in canonical boxed form
thomasporter522 Aug 18, 2023
d0d1965
updated for alpha equiv
thomasporter522 Aug 18, 2023
f7a6ef7
added symmetry and decidability of alpha equiv
thomasporter522 Aug 18, 2023
60ddc24
progress restored
thomasporter522 Aug 18, 2023
ddb875d
Add apply-typenv-env
Crazycolorz5 Aug 24, 2023
786752b
propsed substitution typing
thomasporter522 Aug 24, 2023
6339d77
added removal from contexts
thomasporter522 Aug 24, 2023
d9437dd
Lots of good work on lemma-tysubst
Crazycolorz5 Aug 28, 2023
d56b7de
More on tysubst.
Crazycolorz5 Aug 29, 2023
1b9e88a
lemmas for type variable unbound logic.
Crazycolorz5 Aug 29, 2023
ec13478
Finish the variable disjointness part of lemma-tysubst.
Crazycolorz5 Aug 29, 2023
2bdce99
Merge branch 'master' of https://github.com/hazelgrove/hazelnut-polym…
thomasporter522 Aug 30, 2023
163fbaa
added substitution typing caveat
thomasporter522 Aug 30, 2023
d86aa31
progress restored
thomasporter522 Aug 30, 2023
2997172
Add consistency lemma needed for pres.
Crazycolorz5 Aug 31, 2023
1f241c5
Work on tysubst.
Crazycolorz5 Sep 6, 2023
bff1cda
WOrk on alpha equivalence consequences.
Crazycolorz5 Sep 7, 2023
8dd68f4
Add condition I think captures what we need for the IH of alpha trans…
Crazycolorz5 Sep 7, 2023
484b4a1
Restructure preservation proof to be up to alpha.
Crazycolorz5 Sep 7, 2023
839f095
Organize some things around.
Crazycolorz5 Sep 8, 2023
1914f0f
Split lemmas between files.
Crazycolorz5 Sep 8, 2023
2919daa
Some proofs for lemmas in wf.
Crazycolorz5 Sep 8, 2023
e83cb37
Finish all lemmas in typ-subst and well-formed.
Crazycolorz5 Sep 9, 2023
c51b4fc
Some work towards fixing pres.
Crazycolorz5 Sep 9, 2023
662dae6
Some work towards correcting |-alpha-sub
Crazycolorz5 Sep 9, 2023
7e1f26d
Add a symmentrical case.
Crazycolorz5 Sep 9, 2023
4040d30
Some progress towards subst-ta being up to alpha.
Crazycolorz5 Sep 14, 2023
551bb3c
lemmas-subst-ta up to alpha.
Crazycolorz5 Sep 15, 2023
d608174
Some work in type binder disjoint in subst-ta.
Crazycolorz5 Sep 15, 2023
2845d24
alpha transitivity
thomasporter522 Sep 15, 2023
2939f02
Merge branch 'master' of https://github.com/hazelgrove/hazelnut-polym…
thomasporter522 Sep 15, 2023
bb08c73
Push all remaining holes into lemmas.
Crazycolorz5 Sep 16, 2023
238788c
fixed progress
thomasporter522 Jan 22, 2024
6e9c4d0
beginning parametricity
thomasporter522 Jan 23, 2024
8f97d51
increment on parametricity
thomasporter522 Jan 23, 2024
d13db28
beginning graduality
thomasporter522 Jan 23, 2024
6f624a7
graduality 1 complete except for hole names
thomasporter522 Jan 23, 2024
a39e526
graduality 1 complete
thomasporter522 Jan 23, 2024
0adddf6
renamed file, new defs
thomasporter522 Jan 23, 2024
1c9b664
work on graduality2
thomasporter522 Jan 23, 2024
64b5907
core with all fill-and-resume machinery removed, and binder sets
thomasporter522 Jan 25, 2024
fad52ae
Type binder disjointness work.
Crazycolorz5 Sep 29, 2023
ff773d6
Some ordering changes.
Crazycolorz5 Jan 23, 2024
0e35119
Some hole containing.
Crazycolorz5 Jan 29, 2024
b57ed53
graduality and core update
thomasporter522 Jan 30, 2024
4ae02e5
Merge branch 'master' of https://github.com/hazelgrove/hazelnut-polym…
thomasporter522 Jan 30, 2024
dec100d
work on simple lemmas and graduality
thomasporter522 Jan 30, 2024
5af44b1
tidying
thomasporter522 Jan 30, 2024
b9cf1ac
cast calculus precision needs extension
thomasporter522 Jan 30, 2024
26e74d7
Add comment in parametricity.
Crazycolorz5 Jan 30, 2024
9f62c7f
introducing: meet
thomasporter522 Feb 1, 2024
71c37c6
Merge branch 'master' of https://github.com/hazelgrove/hazelnut-polym…
thomasporter522 Feb 1, 2024
b5f6e5e
debruijn definitions
thomasporter522 Feb 1, 2024
7c20e14
updated debruijn core
thomasporter522 Feb 1, 2024
cbf18d8
progress on graduality
thomasporter522 Feb 1, 2024
aa013a8
refined debruijn logic
thomasporter522 Feb 2, 2024
edeabc8
debruijn progress
thomasporter522 Feb 2, 2024
9de632d
debruijn index work
thomasporter522 Feb 4, 2024
6d36ec1
debruijn index work
thomasporter522 Feb 5, 2024
490315d
debruijn index work
thomasporter522 Feb 6, 2024
1a1fc7e
debruijn index work
thomasporter522 Feb 6, 2024
995f2b9
completed substitution lemma
thomasporter522 Feb 6, 2024
08c3be3
work on typed-elaboration
thomasporter522 Feb 6, 2024
30be67b
completed typed elaboration
thomasporter522 Feb 6, 2024
5b5d6f4
change matching logic
thomasporter522 Feb 6, 2024
2eaaf3f
progress on graduality
thomasporter522 Feb 6, 2024
70008cb
progress on graduality
thomasporter522 Feb 7, 2024
46505e9
completed elaboration graduality
thomasporter522 Feb 7, 2024
334885a
work on preservation
thomasporter522 Feb 7, 2024
1b7e9a5
work on preservation
thomasporter522 Feb 7, 2024
82b3357
work on preservation
thomasporter522 Feb 16, 2024
9153a56
Parametricity up to binders unique
Crazycolorz5 Feb 16, 2024
600e612
Merge remote-tracking branch 'refs/remotes/origin/master'
Crazycolorz5 Feb 16, 2024
ab3239d
work on preservation
thomasporter522 Feb 17, 2024
5cec6f4
updated gitignore
thomasporter522 Feb 17, 2024
fe8b5d8
struggling with preservation
thomasporter522 Feb 18, 2024
548d436
work on preservation
thomasporter522 Feb 18, 2024
51e8132
completed debruijn progress. Used to be 750 lines (including canonica…
thomasporter522 Feb 19, 2024
8ee1f29
a silly idea about the definition of shift
thomasporter522 Feb 19, 2024
138087b
undo the silly idea
thomasporter522 Feb 19, 2024
b0f56e0
work on preservation
thomasporter522 Feb 19, 2024
5208f31
combined context variant
thomasporter522 Feb 20, 2024
65a2362
big push
thomasporter522 Feb 21, 2024
a8a128f
debruijn parametricity11 up to preservation
thomasporter522 Feb 21, 2024
da77bf8
redefine substitution
thomasporter522 Feb 21, 2024
b0ace12
Almost complete parametricity22
Crazycolorz5 Feb 21, 2024
eb5abb1
Make the termination checker happy.
Crazycolorz5 Feb 22, 2024
acfb8ea
Remove wt premise where I can.
Crazycolorz5 Feb 22, 2024
3fa020d
Some notes and caveats.
Crazycolorz5 Feb 22, 2024
02f0a89
final cleanup
thomasporter522 Feb 22, 2024
1c74f22
Merge branch 'master' of https://github.com/hazelgrove/hazelnut-polym…
thomasporter522 Feb 22, 2024
c73e4ba
trouble with unicity
thomasporter522 Feb 22, 2024
60537e9
elaboration unicity
thomasporter522 Feb 22, 2024
ebfc01c
Complete preservation
Crazycolorz5 Feb 22, 2024
3d6834a
debruijn theorem 1
thomasporter522 Feb 22, 2024
c397b66
Merge branch 'master' of https://github.com/hazelgrove/hazelnut-polym…
thomasporter522 Feb 22, 2024
a1ce9d9
final cleanup (I think I mean it this time)
thomasporter522 Feb 22, 2024
5b04072
complete progress
thomasporter522 Feb 28, 2024
9e319d2
new branch
thomasporter522 Feb 28, 2024
ad57809
branch cleanup
thomasporter522 Feb 28, 2024
55e28f9
Minimal accurate Readme
thomasporter522 Feb 28, 2024
a84cfc4
typing subst up to subsub
thomasporter522 Feb 28, 2024
cc63250
all outstanding obligations, including preservation, complete
thomasporter522 Feb 29, 2024
a95e59d
random victory fiddling
thomasporter522 Feb 29, 2024
db56f0a
begin cast insertion
thomasporter522 Feb 29, 2024
93a8dc8
update and readme
thomasporter522 Apr 18, 2024
a674261
improved readme
thomasporter522 Apr 18, 2024
9bf7549
cleanup
thomasporter522 Apr 18, 2024
a9992d3
Update README.md
thomasporter522 Apr 30, 2024
9db6237
Update README.md
thomasporter522 May 1, 2024
4d81e5f
Update README.md
thomasporter522 May 1, 2024
12a981e
Update README.md
thomasporter522 May 1, 2024
e251193
Update README.md
Crazycolorz5 May 1, 2024
3c5f3b3
Update README.md
Crazycolorz5 May 1, 2024
e72c3c5
A lot of work on parametricity lemmas.
Crazycolorz5 May 3, 2024
0627d53
Add missing file.
Crazycolorz5 May 3, 2024
b3b3b8a
Fill a few lemmas.
Crazycolorz5 May 3, 2024
c8a80e1
Separate files.
Crazycolorz5 May 3, 2024
9c0e9a6
rename file.
Crazycolorz5 May 3, 2024
0564e5e
Fix typos to make buildable.
Crazycolorz5 May 3, 2024
55159ff
Some gluing.
Crazycolorz5 May 3, 2024
377ff79
Finish hole cast case of one sided lemma.
Crazycolorz5 May 3, 2024
0032dbe
Finish one-sided lemma.
Crazycolorz5 May 3, 2024
58a00ab
Fill most of the lemmas.
Crazycolorz5 May 4, 2024
f66919f
Change to fit with new type signatures.
Crazycolorz5 May 4, 2024
6f22f54
Some work on 2nd param lemma.
Crazycolorz5 May 4, 2024
bce53a4
Rename files and add links in readme.
Crazycolorz5 May 7, 2024
94f172c
Port a few files from old for use.
Crazycolorz5 May 7, 2024
3ada456
Add corollary 3
Crazycolorz5 May 7, 2024
8de01b0
Update README.md
Crazycolorz5 May 7, 2024
22c5e37
Do some cleaning up.
Crazycolorz5 May 8, 2024
7a0a68a
work on substitution lemma
thomasporter522 May 8, 2024
a834bf8
substitution lemmas done
thomasporter522 May 11, 2024
3948d96
Fix some mismatched named.
Crazycolorz5 Jun 16, 2024
7de6513
Add missing cases for parametricity21-lemma-ctx for ITLam.
Crazycolorz5 Jun 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
*.agdai
debruijn/no-positivity-core-type.agda
debruijn/no-positivity-core-exp.agda
debruijn/no-positivity-core.agda
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ run cabal update
run cabal install alex
run cabal install happy
run cabal install Agda-2.5.4.2
# Warning: Agda version may be out of date
copy . .
cmd ["agda" , "-v", "2" , "all.agda"]
112 changes: 112 additions & 0 deletions Nat.agda
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,115 @@ module Nat where
natEQ (1+ x) (1+ y) with natEQ x y
natEQ (1+ x) (1+ .x) | Inl refl = Inl refl
... | Inr b = Inr (λ x₁ → b (1+inj x y x₁))

natEQrefl : {x : Nat} -> natEQ x x == Inl refl
natEQrefl {x} with natEQ x x
... | Inl refl = refl
... | Inr neq = abort (neq refl)

natEQneq : {x y : Nat} -> (neq : ((x == y) → ⊥)) -> natEQ x y == Inr neq
natEQneq {x} {y} neq with natEQ x y
... | Inl refl = abort (neq refl)
... | Inr neq' = inr-inj (funext (λ eq → abort (neq eq)))
where
inr-inj : ∀{a a'} -> a == a' -> Inr a == Inr a'
inr-inj eq rewrite eq = refl

data _<_ : Nat → Nat → Set where
LTZ : ∀{n} -> Z < 1+ n
LTS : ∀{n m} -> n < m -> 1+ n < 1+ m

natLT : (n m : Nat) -> ((n < m) + ¬(n < m))
natLT Z Z = Inr (λ ())
natLT Z (1+ n) = Inl LTZ
natLT (1+ n) Z = Inr (λ ())
natLT (1+ n) (1+ m) with natLT n m
... | Inl p = Inl (LTS p)
... | Inr p = Inr (\{(LTS p') -> p p'})

lt-1+ : {x : Nat} -> x < 1+ x
lt-1+ {Z} = LTZ
lt-1+ {1+ x'} = LTS lt-1+

lt-ne : {x y : Nat} -> x < y -> (x == y) → ⊥
lt-ne LTZ = \ ()
lt-ne (LTS {n} {m} p) = \eq -> lt-ne p ((1+inj n m eq))

lt-antisym : {x y : Nat} -> x < y -> y < x -> ⊥
lt-antisym LTZ = λ ()
lt-antisym (LTS p) (LTS p') = lt-antisym p p'

lt-gtz : {x y : Nat} -> y < x -> Σ[ z ∈ Nat ] (x == 1+ z)
lt-gtz (LTZ {n}) = n , refl
lt-gtz (LTS {n} {m} p) = let p1 , p2 = lt-gtz p in 1+ p1 , foo p2
where
foo : {x y : Nat} -> x == y -> 1+ x == 1+ y
foo eq rewrite eq = refl

lt-1+-inj : {x y : Nat} -> 1+ x < 1+ y -> x < y
lt-1+-inj (LTS p) = p

lt-trans-1+ : {x y z : Nat} -> x < y -> y < z -> 1+ x < z
lt-trans-1+ LTZ (LTS LTZ) = LTS LTZ
lt-trans-1+ LTZ (LTS (LTS p)) = LTS LTZ
lt-trans-1+ (LTS p) (LTS p') = LTS (lt-trans-1+ p p')

lt-right-incr : {x y : Nat} -> x < y -> x < 1+ y
lt-right-incr LTZ = LTZ
lt-right-incr (LTS p) = LTS (lt-right-incr p)

lt-trans : {x y z : Nat} -> x < y -> y < z -> x < z
lt-trans LTZ (LTS p) = LTZ
lt-trans (LTS p) (LTS p') = lt-right-incr (lt-trans-1+ p p')

lt-right-incr-neq : {x y : Nat} -> x < 1+ y -> ((x == y) -> ⊥) -> x < y
lt-right-incr-neq {y = 0} LTZ d = abort (d refl)
lt-right-incr-neq {y = (1+ y')} LTZ d = LTZ
lt-right-incr-neq {y = 0} (LTS ()) d
lt-right-incr-neq {x = (1+ x')} {y = (1+ y')} (LTS a) d = LTS (lt-right-incr-neq {x = x'} {y = y'} a λ x → d (foo x))
where
foo : {a b : Nat} -> a == b -> (1+ a) == (1+ b)
foo eq rewrite eq = refl

lt-lte-is-lt : {a b c : Nat} -> (a < b) -> (b < (1+ c)) -> (a < c)
lt-lte-is-lt {a = Z} {c = Z} lt LTZ = lt
lt-lte-is-lt {a = Z} {c = Z} lt (LTS ())
lt-lte-is-lt {a = Z} {c = 1+ c} lt lte = LTZ
lt-lte-is-lt {a = 1+ a} {c = Z} lt LTZ = lt
lt-lte-is-lt {a = 1+ a} {c = Z} lt (LTS ())
lt-lte-is-lt {a = 1+ a} {b = 1+ b} {c = 1+ c} (LTS lt) (LTS lte) = LTS (lt-lte-is-lt lt lte)

trichotomy : (a b : Nat) -> (a < b + b < a + a == b)
trichotomy Z Z = Inr (Inr refl)
trichotomy (1+ a) Z = Inr (Inl LTZ)
trichotomy Z (1+ b) = Inl LTZ
trichotomy (1+ a) (1+ b) with trichotomy a b
... | Inl x = Inl (LTS x)
... | Inr (Inl x) = Inr (Inl (LTS x))
... | Inr (Inr x) rewrite x = Inr (Inr refl)

trichotomy-lemma : {a b : Nat} -> (a == b → ⊥) -> (a < b → ⊥) -> (b < a)
trichotomy-lemma {a = a} {b = b} neq nlt with trichotomy a b
... | Inl x = abort (nlt x)
... | Inr (Inl x) = x
... | Inr (Inr x) = abort (neq x)

_nat+_ : (n m : Nat) → Nat
Z nat+ n = n
(1+ n) nat+ m = 1+ (n nat+ m)

nat+Z : (n : Nat) → n nat+ Z == n
nat+Z Z = refl
nat+Z (1+ n) rewrite nat+Z n = refl

nat+1+ : (n m : Nat) → n nat+ 1+ m == 1+ (n nat+ m)
nat+1+ Z m = refl
nat+1+ (1+ n) m rewrite nat+1+ n m = refl

nat+assoc : (n m l : Nat) → n nat+ (m nat+ l) == (n nat+ m) nat+ l
nat+assoc Z m l = refl
nat+assoc (1+ n) m l rewrite nat+assoc n m l = refl

nat+comm : (n m : Nat) → n nat+ m == m nat+ n
nat+comm Z m rewrite nat+Z m = refl
nat+comm (1+ n) m rewrite nat+1+ m n rewrite nat+comm n m = refl
15 changes: 14 additions & 1 deletion Prelude.agda
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ module Prelude where
abort : ∀ {C : Set} → ⊥ → C
abort ()

-- negation
open import Agda.Primitive using (Level)
¬_ : ∀ {ℓ : Level} → Set ℓ → Set ℓ
¬ A = A → ⊥

-- unit
data ⊤ : Set where
<> : ⊤
Expand Down Expand Up @@ -43,7 +48,7 @@ module Prelude where

-- disequality
_≠_ : {l : Level} {A : Set l} → (a b : A) → Set l
a ≠ b = (a == b) → ⊥
a ≠ b = ¬ (a == b)

{-# BUILTIN EQUALITY _==_ #-}

Expand Down Expand Up @@ -91,3 +96,11 @@ module Prelude where
-- non-equality is commutative
flip : {A : Set} {x y : A} → (x == y → ⊥) → (y == x → ⊥)
flip neq eq = neq (! eq)

-- equality is symmetric
sym : {A : Set} {x y : A} → (x == y) → (y == x)
sym refl = refl

-- bi-implication
_↔_ : {l1 : Level} {l2 : Level} → (Set l1) → (Set l2) → Set (lmax l1 l2)
a ↔ b = (a → b) × (b → a)
Loading