quox/tests/Tests/Equal.idr

631 lines
24 KiB
Idris
Raw Normal View History

2022-04-27 14:06:39 -04:00
module Tests.Equal
2023-02-11 12:15:50 -05:00
import Quox.Equal
2023-03-31 17:43:25 -04:00
import Quox.Typechecker
import Control.Monad.ST
2023-02-11 12:15:50 -05:00
import public TypingImpls
2022-04-27 14:06:39 -04:00
import TAP
2023-03-31 17:43:25 -04:00
import Quox.EffExtra
2023-05-01 21:06:25 -04:00
import AstExtra
2022-04-27 14:06:39 -04:00
2023-04-01 13:16:43 -04:00
defGlobals : Definitions
2023-02-10 15:40:44 -05:00
defGlobals = fromList
[("A", mkPostulate GZero (^TYPE 0)),
("B", mkPostulate GZero (^TYPE 0)),
("a", mkPostulate GAny (^FT "A" 0)),
("a'", mkPostulate GAny (^FT "A" 0)),
("b", mkPostulate GAny (^FT "B" 0)),
("f", mkPostulate GAny (^Arr One (^FT "A" 0) (^FT "A" 0))),
("id", mkDef GAny (^Arr One (^FT "A" 0) (^FT "A" 0)) (^LamY "x" (^BVT 0))),
("eq-AB", mkPostulate GZero (^Eq0 (^TYPE 0) (^FT "A" 0) (^FT "B" 0))),
2023-11-02 13:14:22 -04:00
("two", mkDef GAny (^NAT) (^Succ (^Succ (^Zero))))]
2023-05-01 21:06:25 -04:00
2023-08-24 13:55:57 -04:00
parameters (label : String) (act : Eff Equal ())
2023-04-01 13:16:43 -04:00
{default defGlobals globals : Definitions}
testEq : Test
2023-05-01 21:06:25 -04:00
testEq = test label $ runEqual globals act
2022-04-27 14:06:39 -04:00
testNeq : Test
testNeq = testThrows label (const True) $ runTC globals act $> "ok"
2022-04-27 14:06:39 -04:00
2023-05-01 21:06:25 -04:00
parameters (ctx : TyContext d n)
subT, equalT : {default SOne sg : SQty} ->
Term d n -> Term d n -> Term d n -> Eff TC ()
subT ty s t {sg} = lift $ Term.sub noLoc ctx sg ty s t
equalT ty s t {sg} = lift $ Term.equal noLoc ctx sg ty s t
2023-08-24 13:55:57 -04:00
equalTy : Term d n -> Term d n -> Eff TC ()
2023-05-01 21:06:25 -04:00
equalTy s t = lift $ Term.equalType noLoc ctx s t
2022-04-27 14:06:39 -04:00
subE, equalE : {default SOne sg : SQty} ->
Elim d n -> Elim d n -> Eff TC ()
subE e f {sg} = lift $ Elim.sub noLoc ctx sg e f
equalE e f {sg} = lift $ Elim.equal noLoc ctx sg e f
2022-04-27 14:06:39 -04:00
export
tests : Test
tests = "equality & subtyping" :- [
2023-02-12 15:30:08 -05:00
note #""s{t,…}" for term substs; "sp,…›" for dim substs"#,
note #""0=1𝒥" means that 𝒥 holds in an inconsistent dim context"#,
2023-09-17 13:10:46 -04:00
note "binds before ∥ are globals, after it are BVs",
"universes" :- [
2023-02-12 15:30:08 -05:00
testEq "★₀ = ★₀" $
2023-05-01 21:06:25 -04:00
equalT empty (^TYPE 1) (^TYPE 0) (^TYPE 0),
2023-02-12 15:30:08 -05:00
testNeq "★₀ ≠ ★₁" $
2023-05-01 21:06:25 -04:00
equalT empty (^TYPE 2) (^TYPE 0) (^TYPE 1),
2023-02-12 15:30:08 -05:00
testNeq "★₁ ≠ ★₀" $
2023-05-01 21:06:25 -04:00
equalT empty (^TYPE 2) (^TYPE 1) (^TYPE 0),
testEq "★₀ <: ★₀" $
2023-05-01 21:06:25 -04:00
subT empty (^TYPE 1) (^TYPE 0) (^TYPE 0),
testEq "★₀ <: ★₁" $
2023-05-01 21:06:25 -04:00
subT empty (^TYPE 2) (^TYPE 0) (^TYPE 1),
testNeq "★₁ ≮: ★₀" $
2023-05-01 21:06:25 -04:00
subT empty (^TYPE 2) (^TYPE 1) (^TYPE 0)
],
2023-03-26 10:15:19 -04:00
"function types" :- [
2023-05-01 21:06:25 -04:00
note "cumulativity",
testEq "0.★₀ → ★₀ = 0.★₀ → ★₀" $
let tm = ^Arr Zero (^TYPE 0) (^TYPE 0) in
equalT empty (^TYPE 1) tm tm,
testEq "0.★₀ → ★₀ <: 0.★₀ → ★₀" $
let tm = ^Arr Zero (^TYPE 0) (^TYPE 0) in
subT empty (^TYPE 1) tm tm,
testNeq "0.★₁ → ★₀ ≠ 0.★₀ → ★₀" $
let tm1 = ^Arr Zero (^TYPE 1) (^TYPE 0)
tm2 = ^Arr Zero (^TYPE 0) (^TYPE 0) in
equalT empty (^TYPE 2) tm1 tm2,
testEq "1.★₁ → ★₀ <: 1.★₀ → ★₀" $
let tm1 = ^Arr One (^TYPE 1) (^TYPE 0)
tm2 = ^Arr One (^TYPE 0) (^TYPE 0) in
subT empty (^TYPE 2) tm1 tm2,
testEq "1.★₀ → ★₀ <: 1.★₀ → ★₁" $
let tm1 = ^Arr One (^TYPE 0) (^TYPE 0)
tm2 = ^Arr One (^TYPE 0) (^TYPE 1) in
subT empty (^TYPE 2) tm1 tm2,
testEq "1.★₀ → ★₀ <: 1.★₀ → ★₁" $
let tm1 = ^Arr One (^TYPE 0) (^TYPE 0)
tm2 = ^Arr One (^TYPE 0) (^TYPE 1) in
subT empty (^TYPE 2) tm1 tm2,
testEq "1.A → B = 1.A → B" $
2023-05-21 14:09:34 -04:00
let tm = ^Arr One (^FT "A" 0) (^FT "B" 0) in
2023-05-01 21:06:25 -04:00
equalT empty (^TYPE 0) tm tm,
testEq "1.A → B <: 1.A → B" $
2023-05-21 14:09:34 -04:00
let tm = ^Arr One (^FT "A" 0) (^FT "B" 0) in
2023-05-01 21:06:25 -04:00
subT empty (^TYPE 0) tm tm,
2023-02-12 15:30:08 -05:00
note "incompatible quantities",
2023-05-01 21:06:25 -04:00
testNeq "1.★₀ → ★₀ ≠ 0.★₀ → ★₁" $
let tm1 = ^Arr Zero (^TYPE 0) (^TYPE 0)
tm2 = ^Arr Zero (^TYPE 0) (^TYPE 1) in
equalT empty (^TYPE 2) tm1 tm2,
testNeq "0.A → B ≠ 1.A → B" $
2023-05-21 14:09:34 -04:00
let tm1 = ^Arr Zero (^FT "A" 0) (^FT "B" 0)
tm2 = ^Arr One (^FT "A" 0) (^FT "B" 0) in
2023-05-01 21:06:25 -04:00
equalT empty (^TYPE 0) tm1 tm2,
testNeq "0.A → B ≮: 1.A → B" $
2023-05-21 14:09:34 -04:00
let tm1 = ^Arr Zero (^FT "A" 0) (^FT "B" 0)
tm2 = ^Arr One (^FT "A" 0) (^FT "B" 0) in
2023-05-01 21:06:25 -04:00
subT empty (^TYPE 0) tm1 tm2,
testEq "0=1 ⊢ 0.A → B = 1.A → B" $
2023-05-21 14:09:34 -04:00
let tm1 = ^Arr Zero (^FT "A" 0) (^FT "B" 0)
tm2 = ^Arr One (^FT "A" 0) (^FT "B" 0) in
2023-05-01 21:06:25 -04:00
equalT empty01 (^TYPE 0) tm1 tm2,
todo "dependent function types"
],
"lambda" :- [
2023-05-01 21:06:25 -04:00
testEq "λ x ⇒ x = λ x ⇒ x" $
2023-05-21 14:09:34 -04:00
equalT empty (^Arr One (^FT "A" 0) (^FT "A" 0))
2023-05-01 21:06:25 -04:00
(^LamY "x" (^BVT 0))
(^LamY "x" (^BVT 0)),
testEq "λ x ⇒ x <: λ x ⇒ x" $
2023-05-21 14:09:34 -04:00
subT empty (^Arr One (^FT "A" 0) (^FT "A" 0))
2023-05-01 21:06:25 -04:00
(^LamY "x" (^BVT 0))
(^LamY "x" (^BVT 0)),
testEq "λ x ⇒ x = λ y ⇒ y" $
2023-05-21 14:09:34 -04:00
equalT empty (^Arr One (^FT "A" 0) (^FT "A" 0))
2023-05-01 21:06:25 -04:00
(^LamY "x" (^BVT 0))
(^LamY "y" (^BVT 0)),
testEq "λ x ⇒ x <: λ y ⇒ y" $
2023-05-21 14:09:34 -04:00
subT empty (^Arr One (^FT "A" 0) (^FT "A" 0))
2023-05-01 21:06:25 -04:00
(^LamY "x" (^BVT 0))
(^LamY "y" (^BVT 0)),
testNeq "λ x y ⇒ x ≠ λ x y ⇒ y" $
equalT empty
2023-05-21 14:09:34 -04:00
(^Arr One (^FT "A" 0) (^Arr One (^FT "A" 0) (^FT "A" 0)))
2023-05-01 21:06:25 -04:00
(^LamY "x" (^LamY "y" (^BVT 1)))
(^LamY "x" (^LamY "y" (^BVT 0))),
testEq "λ x ⇒ a = λ x ⇒ a (Y vs N)" $
equalT empty
2023-05-21 14:09:34 -04:00
(^Arr Zero (^FT "B" 0) (^FT "A" 0))
(^LamY "x" (^FT "a" 0))
(^LamN (^FT "a" 0)),
2023-05-01 21:06:25 -04:00
testEq "λ x ⇒ f x = f (η)" $
equalT empty
2023-05-21 14:09:34 -04:00
(^Arr One (^FT "A" 0) (^FT "A" 0))
(^LamY "x" (E $ ^App (^F "f" 0) (^BVT 0)))
(^FT "f" 0)
],
2023-01-26 13:54:46 -05:00
"eq type" :- [
2023-02-12 15:30:08 -05:00
testEq "(★₀ ≡ ★₀ : ★₁) = (★₀ ≡ ★₀ : ★₁)" $
2023-05-01 21:06:25 -04:00
let tm = ^Eq0 (^TYPE 1) (^TYPE 0) (^TYPE 0) in
equalT empty (^TYPE 2) tm tm,
2023-02-12 15:30:08 -05:00
testEq "A ≔ ★₁ ⊢ (★₀ ≡ ★₀ : ★₁) = (★₀ ≡ ★₀ : A)"
{globals = fromList [("A", mkDef GZero (^TYPE 2) (^TYPE 1))]} $
2023-05-01 21:06:25 -04:00
equalT empty (^TYPE 2)
(^Eq0 (^TYPE 1) (^TYPE 0) (^TYPE 0))
2023-05-21 14:09:34 -04:00
(^Eq0 (^FT "A" 0) (^TYPE 0) (^TYPE 0)),
2023-02-25 09:24:45 -05:00
todo "dependent equality types"
2023-01-26 13:54:46 -05:00
],
2023-02-12 15:30:08 -05:00
"equalities and uip" :-
2023-04-01 13:16:43 -04:00
let refl : Term d n -> Term d n -> Elim d n
2023-05-01 21:06:25 -04:00
refl a x = ^Ann (^DLam (SN x)) (^Eq0 a x x)
2023-02-11 12:15:50 -05:00
in
[
2023-05-01 21:06:25 -04:00
note #"refl A x is an abbreviation for "(δ i ⇒ x)(x ≡ x : A)""#,
testEq "refl A a = refl A a" $
2023-05-21 14:09:34 -04:00
equalE empty
(refl (^FT "A" 0) (^FT "a" 0))
(refl (^FT "A" 0) (^FT "a" 0)),
2023-02-12 15:30:08 -05:00
testEq "p : (a ≡ a' : A), q : (a ≡ a' : A) ∥ ⊢ p = q (free)"
2023-02-11 12:15:50 -05:00
{globals =
let def = mkPostulate GZero
2023-05-21 14:09:34 -04:00
(^Eq0 (^FT "A" 0) (^FT "a" 0) (^FT "a'" 0))
2023-05-01 21:06:25 -04:00
in defGlobals `mergeLeft` fromList [("p", def), ("q", def)]} $
2023-05-21 14:09:34 -04:00
equalE empty (^F "p" 0) (^F "q" 0),
2023-02-12 15:30:08 -05:00
testEq "∥ x : (a ≡ a' : A), y : (a ≡ a' : A) ⊢ x = y (bound)" $
2023-05-21 14:09:34 -04:00
let ty : forall n. Term 0 n :=
^Eq0 (^FT "A" 0) (^FT "a" 0) (^FT "a'" 0) in
2023-03-15 10:54:51 -04:00
equalE (extendTyN [< (Any, "x", ty), (Any, "y", ty)] empty)
2023-05-01 21:06:25 -04:00
(^BV 0) (^BV 1),
2023-02-12 15:30:08 -05:00
2023-05-01 21:06:25 -04:00
testEq "∥ x : (a ≡ a' : A) ∷ Type 0, y : [ditto] ⊢ x = y" $
2023-04-01 13:16:43 -04:00
let ty : forall n. Term 0 n :=
2023-05-21 14:09:34 -04:00
E $ ^Ann (^Eq0 (^FT "A" 0) (^FT "a" 0) (^FT "a'" 0)) (^TYPE 0) in
2023-03-15 10:54:51 -04:00
equalE (extendTyN [< (Any, "x", ty), (Any, "y", ty)] empty)
2023-05-01 21:06:25 -04:00
(^BV 0) (^BV 1),
2023-02-12 15:30:08 -05:00
testEq "E ≔ a ≡ a' : A, EE ≔ E ∥ x : EE, y : EE ⊢ x = y"
{globals = defGlobals `mergeLeft` fromList
[("E", mkDef GZero (^TYPE 0)
2023-05-21 14:09:34 -04:00
(^Eq0 (^FT "A" 0) (^FT "a" 0) (^FT "a'" 0))),
("EE", mkDef GZero (^TYPE 0) (^FT "E" 0))]} $
2023-05-21 14:09:34 -04:00
equalE
(extendTyN [< (Any, "x", ^FT "EE" 0), (Any, "y", ^FT "EE" 0)] empty)
2023-05-01 21:06:25 -04:00
(^BV 0) (^BV 1),
2023-02-12 15:30:08 -05:00
testEq "E ≔ a ≡ a' : A, EE ≔ E ∥ x : EE, y : E ⊢ x = y"
{globals = defGlobals `mergeLeft` fromList
[("E", mkDef GZero (^TYPE 0)
2023-05-21 14:09:34 -04:00
(^Eq0 (^FT "A" 0) (^FT "a" 0) (^FT "a'" 0))),
("EE", mkDef GZero (^TYPE 0) (^FT "E" 0))]} $
2023-05-21 14:09:34 -04:00
equalE
(extendTyN [< (Any, "x", ^FT "EE" 0), (Any, "y", ^FT "E" 0)] empty)
2023-05-01 21:06:25 -04:00
(^BV 0) (^BV 1),
2023-02-12 15:30:08 -05:00
testEq "E ≔ a ≡ a' : A ∥ x : E, y : E ⊢ x = y"
{globals = defGlobals `mergeLeft` fromList
[("E", mkDef GZero (^TYPE 0)
2023-05-21 14:09:34 -04:00
(^Eq0 (^FT "A" 0) (^FT "a" 0) (^FT "a'" 0)))]} $
equalE (extendTyN [< (Any, "x", ^FT "E" 0), (Any, "y", ^FT "E" 0)] empty)
2023-05-01 21:06:25 -04:00
(^BV 0) (^BV 1),
2023-02-12 15:30:08 -05:00
testEq "E ≔ a ≡ a' : A ∥ x : (E×E), y : (E×E) ⊢ x = y"
{globals = defGlobals `mergeLeft` fromList
[("E", mkDef GZero (^TYPE 0)
2023-05-21 14:09:34 -04:00
(^Eq0 (^FT "A" 0) (^FT "a" 0) (^FT "a'" 0)))]} $
let ty : forall n. Term 0 n := ^Sig (^FT "E" 0) (SN $ ^FT "E" 0) in
2023-03-15 10:54:51 -04:00
equalE (extendTyN [< (Any, "x", ty), (Any, "y", ty)] empty)
2023-05-01 21:06:25 -04:00
(^BV 0) (^BV 1),
2023-02-12 15:30:08 -05:00
2023-05-01 21:06:25 -04:00
testEq "E ≔ a ≡ a' : A, W ≔ E × E ∥ x : W, y : E×E ⊢ x = y"
2023-02-12 15:30:08 -05:00
{globals = defGlobals `mergeLeft` fromList
[("E", mkDef GZero (^TYPE 0)
2023-05-21 14:09:34 -04:00
(^Eq0 (^FT "A" 0) (^FT "a" 0) (^FT "a'" 0))),
("W", mkDef GZero (^TYPE 0) (^And (^FT "E" 0) (^FT "E" 0)))]} $
equalE
2023-05-21 14:09:34 -04:00
(extendTyN [< (Any, "x", ^FT "W" 0),
(Any, "y", ^And (^FT "E" 0) (^FT "E" 0))] empty)
2023-05-01 21:06:25 -04:00
(^BV 0) (^BV 1)
2023-02-11 12:15:50 -05:00
],
2023-01-26 13:54:46 -05:00
"term closure" :- [
2023-05-01 21:06:25 -04:00
note "bold numbers for de bruijn indices",
testEq "𝟎{} = 𝟎 : A" $
2023-05-21 14:09:34 -04:00
equalT (extendTy Any "x" (^FT "A" 0) empty)
(^FT "A" 0)
2023-05-01 21:06:25 -04:00
(CloT (Sub (^BVT 0) id))
(^BVT 0),
testEq "𝟎{a} = a : A" $
2023-05-21 14:09:34 -04:00
equalT empty (^FT "A" 0)
(CloT (Sub (^BVT 0) (^F "a" 0 ::: id)))
(^FT "a" 0),
2023-05-01 21:06:25 -04:00
testEq "𝟎{a,b} = a : A" $
2023-05-21 14:09:34 -04:00
equalT empty (^FT "A" 0)
(CloT (Sub (^BVT 0) (^F "a" 0 ::: ^F "b" 0 ::: id)))
(^FT "a" 0),
2023-05-01 21:06:25 -04:00
testEq "𝟏{a,b} = b : A" $
2023-05-21 14:09:34 -04:00
equalT empty (^FT "A" 0)
(CloT (Sub (^BVT 1) (^F "a" 0 ::: ^F "b" 0 ::: id)))
(^FT "b" 0),
2023-05-01 21:06:25 -04:00
testEq "(λy ⇒ 𝟏){a} = λy ⇒ a : 0.B → A (N)" $
2023-05-21 14:09:34 -04:00
equalT empty (^Arr Zero (^FT "B" 0) (^FT "A" 0))
(CloT (Sub (^LamN (^BVT 0)) (^F "a" 0 ::: id)))
(^LamN (^FT "a" 0)),
2023-05-01 21:06:25 -04:00
testEq "(λy ⇒ 𝟏){a} = λy ⇒ a : 0.B → A (Y)" $
2023-05-21 14:09:34 -04:00
equalT empty (^Arr Zero (^FT "B" 0) (^FT "A" 0))
(CloT (Sub (^LamY "y" (^BVT 1)) (^F "a" 0 ::: id)))
(^LamY "y" (^FT "a" 0))
],
2023-02-12 15:30:08 -05:00
"term d-closure" :- [
2023-05-01 21:06:25 -04:00
testEq "★₀0 = ★₀ : ★₁" $
equalT (extendDim "𝑗" empty)
(^TYPE 1) (DCloT (Sub (^TYPE 0) (^K Zero ::: id))) (^TYPE 0),
testEq "(δ i ⇒ a)0 = (δ i ⇒ a) : (a ≡ a : A)" $
equalT (extendDim "𝑗" empty)
2023-05-21 14:09:34 -04:00
(^Eq0 (^FT "A" 0) (^FT "a" 0) (^FT "a" 0))
(DCloT (Sub (^DLamN (^FT "a" 0)) (^K Zero ::: id)))
(^DLamN (^FT "a" 0)),
2023-02-12 15:30:08 -05:00
note "it is hard to think of well-typed terms with big dctxs"
],
"free var" :-
let au_bu = fromList
[("A", mkDef GAny (^TYPE 1) (^TYPE 0)),
("B", mkDef GAny (^TYPE 1) (^TYPE 0))]
au_ba = fromList
[("A", mkDef GAny (^TYPE 1) (^TYPE 0)),
("B", mkDef GAny (^TYPE 1) (^FT "A" 0))]
in [
2023-02-12 15:30:08 -05:00
testEq "A = A" $
2023-05-21 14:09:34 -04:00
equalE empty (^F "A" 0) (^F "A" 0),
2023-02-12 15:30:08 -05:00
testNeq "A ≠ B" $
2023-05-21 14:09:34 -04:00
equalE empty (^F "A" 0) (^F "B" 0),
2023-02-12 15:30:08 -05:00
testEq "0=1 ⊢ A = B" $
2023-05-21 14:09:34 -04:00
equalE empty01 (^F "A" 0) (^F "B" 0),
2023-02-12 15:30:08 -05:00
testEq "A : ★₁ ≔ ★₀ ⊢ A = (★₀ ∷ ★₁)" {globals = au_bu} $
2023-05-21 14:09:34 -04:00
equalE empty (^F "A" 0) (^Ann (^TYPE 0) (^TYPE 1)),
2023-05-01 21:06:25 -04:00
testEq "A : ★₁ ≔ ★₀ ⊢ A = ★₀" {globals = au_bu} $
2023-05-21 14:09:34 -04:00
equalT empty (^TYPE 1) (^FT "A" 0) (^TYPE 0),
2023-02-12 15:30:08 -05:00
testEq "A ≔ ★₀, B ≔ ★₀ ⊢ A = B" {globals = au_bu} $
2023-05-21 14:09:34 -04:00
equalE empty (^F "A" 0) (^F "B" 0),
2023-02-12 15:30:08 -05:00
testEq "A ≔ ★₀, B ≔ A ⊢ A = B" {globals = au_ba} $
2023-05-21 14:09:34 -04:00
equalE empty (^F "A" 0) (^F "B" 0),
testEq "A <: A" $
2023-05-21 14:09:34 -04:00
subE empty (^F "A" 0) (^F "A" 0),
testNeq "A ≮: B" $
2023-05-21 14:09:34 -04:00
subE empty (^F "A" 0) (^F "B" 0),
testEq "A : ★₃ ≔ ★₀, B : ★₃ ≔ ★₂ ⊢ A <: B"
{globals = fromList [("A", mkDef GAny (^TYPE 3) (^TYPE 0)),
("B", mkDef GAny (^TYPE 3) (^TYPE 2))]} $
2023-05-21 14:09:34 -04:00
subE empty (^F "A" 0) (^F "B" 0),
2023-02-12 15:30:08 -05:00
note "(A and B in different universes)",
testEq "A : ★₁ ≔ ★₀, B : ★₃ ≔ ★₂ ⊢ A <: B"
{globals = fromList [("A", mkDef GAny (^TYPE 1) (^TYPE 0)),
("B", mkDef GAny (^TYPE 3) (^TYPE 2))]} $
2023-05-21 14:09:34 -04:00
subE empty (^F "A" 0) (^F "B" 0),
testEq "0=1 ⊢ A <: B" $
2023-05-21 14:09:34 -04:00
subE empty01 (^F "A" 0) (^F "B" 0)
],
"bound var" :- [
2023-05-01 21:06:25 -04:00
note "bold numbers for de bruijn indices",
testEq "𝟎 = 𝟎" $
equalE (extendTy Any "A" (^TYPE 0) empty) (^BV 0) (^BV 0),
testEq "𝟎 <: 𝟎" $
subE (extendTy Any "A" (^TYPE 0) empty) (^BV 0) (^BV 0),
testNeq "𝟎𝟏" $
equalE (extendTyN [< (Any, "A", ^TYPE 0), (Any, "B", ^TYPE 0)] empty)
(^BV 0) (^BV 1),
testNeq "𝟎 ≮: 𝟏" $
subE (extendTyN [< (Any, "A", ^TYPE 0), (Any, "B", ^TYPE 0)] empty)
(^BV 0) (^BV 1),
testEq "0=1 ⊢ 𝟎 = 𝟏" $
equalE (extendTyN [< (Any, "A", ^TYPE 0), (Any, "B", ^TYPE 0)] empty01)
(^BV 0) (^BV 1)
],
"application" :- [
2023-05-01 21:06:25 -04:00
testEq "f a = f a" $
2023-05-21 14:09:34 -04:00
equalE empty (^App (^F "f" 0) (^FT "a" 0)) (^App (^F "f" 0) (^FT "a" 0)),
2023-05-01 21:06:25 -04:00
testEq "f a <: f a" $
2023-05-21 14:09:34 -04:00
subE empty (^App (^F "f" 0) (^FT "a" 0)) (^App (^F "f" 0) (^FT "a" 0)),
2023-05-01 21:06:25 -04:00
testEq "(λ x ⇒ x ∷ 1.A → A) a = ((a ∷ A) ∷ A) (β)" $
equalE empty
2023-05-21 14:09:34 -04:00
(^App (^Ann (^LamY "x" (^BVT 0)) (^Arr One (^FT "A" 0) (^FT "A" 0)))
(^FT "a" 0))
(^Ann (E $ ^Ann (^FT "a" 0) (^FT "A" 0)) (^FT "A" 0)),
2023-05-01 21:06:25 -04:00
testEq "(λ x ⇒ x ∷ A ⊸ A) a = a (βυ)" $
equalE empty
2023-05-21 14:09:34 -04:00
(^App (^Ann (^LamY "x" (^BVT 0)) (^Arr One (^FT "A" 0) (^FT "A" 0)))
(^FT "a" 0))
(^F "a" 0),
2023-05-01 21:06:25 -04:00
testEq "((λ g ⇒ g a) ∷ 1.(1.A → A) → A) f = ((λ y ⇒ f y) ∷ 1.A → A) a # β↘↙" $
2023-05-21 14:09:34 -04:00
let a = ^FT "A" 0; a2a = ^Arr One a a; aa2a = ^Arr One a2a a in
equalE empty
2023-05-21 14:09:34 -04:00
(^App (^Ann (^LamY "g" (E $ ^App (^BV 0) (^FT "a" 0))) aa2a)
(^FT "f" 0))
(^App (^Ann (^LamY "y" (E $ ^App (^F "f" 0) (^BVT 0))) a2a)
(^FT "a" 0)),
2023-05-01 21:06:25 -04:00
testEq "((λ x ⇒ x) ∷ 1.A → A) a <: a" $
subE empty
2023-05-21 14:09:34 -04:00
(^App (^Ann (^LamY "x" (^BVT 0)) (^Arr One (^FT "A" 0) (^FT "A" 0)))
(^FT "a" 0))
(^F "a" 0),
2023-05-01 21:06:25 -04:00
note "id : A ⊸ A ≔ λ x ⇒ x",
2023-05-21 14:09:34 -04:00
testEq "id a = a" $ equalE empty (^App (^F "id" 0) (^FT "a" 0)) (^F "a" 0),
testEq "id a <: a" $ subE empty (^App (^F "id" 0) (^FT "a" 0)) (^F "a" 0)
],
2023-03-05 06:18:15 -05:00
"dim application" :- [
testEq "eq-AB @0 = eq-AB @0" $
2023-05-01 21:06:25 -04:00
equalE empty
2023-05-21 14:09:34 -04:00
(^DApp (^F "eq-AB" 0) (^K Zero))
(^DApp (^F "eq-AB" 0) (^K Zero)),
2023-03-05 06:18:15 -05:00
testNeq "eq-AB @0 ≠ eq-AB @1" $
2023-05-01 21:06:25 -04:00
equalE empty
2023-05-21 14:09:34 -04:00
(^DApp (^F "eq-AB" 0) (^K Zero))
(^DApp (^F "eq-AB" 0) (^K One)),
2023-03-05 06:18:15 -05:00
testEq "𝑖 | ⊢ eq-AB @𝑖 = eq-AB @𝑖" $
2023-05-01 21:06:25 -04:00
equalE
(extendDim "𝑖" empty)
2023-05-21 14:09:34 -04:00
(^DApp (^F "eq-AB" 0) (^BV 0))
(^DApp (^F "eq-AB" 0) (^BV 0)),
2023-03-05 06:18:15 -05:00
testNeq "𝑖 | ⊢ eq-AB @𝑖 ≠ eq-AB @0" $
2023-05-01 21:06:25 -04:00
equalE (extendDim "𝑖" empty)
2023-05-21 14:09:34 -04:00
(^DApp (^F "eq-AB" 0) (^BV 0))
(^DApp (^F "eq-AB" 0) (^K Zero)),
2023-03-05 06:18:15 -05:00
testEq "𝑖, 𝑖=0 | ⊢ eq-AB @𝑖 = eq-AB @0" $
2023-05-01 21:06:25 -04:00
equalE (eqDim (^BV 0) (^K Zero) $ extendDim "𝑖" empty)
2023-05-21 14:09:34 -04:00
(^DApp (^F "eq-AB" 0) (^BV 0))
(^DApp (^F "eq-AB" 0) (^K Zero)),
2023-03-05 06:18:15 -05:00
testNeq "𝑖, 𝑖=1 | ⊢ eq-AB @𝑖 ≠ eq-AB @0" $
2023-05-01 21:06:25 -04:00
equalE (eqDim (^BV 0) (^K One) $ extendDim "𝑖" empty)
2023-05-21 14:09:34 -04:00
(^DApp (^F "eq-AB" 0) (^BV 0))
(^DApp (^F "eq-AB" 0) (^K Zero)),
2023-03-05 06:18:15 -05:00
testNeq "𝑖, 𝑗 | ⊢ eq-AB @𝑖 ≠ eq-AB @𝑗" $
2023-05-01 21:06:25 -04:00
equalE (extendDim "𝑗" $ extendDim "𝑖" empty)
2023-05-21 14:09:34 -04:00
(^DApp (^F "eq-AB" 0) (^BV 1))
(^DApp (^F "eq-AB" 0) (^BV 0)),
2023-03-05 06:18:15 -05:00
testEq "𝑖, 𝑗, 𝑖=𝑗 | ⊢ eq-AB @𝑖 = eq-AB @𝑗" $
2023-05-01 21:06:25 -04:00
equalE (eqDim (^BV 0) (^BV 1) $ extendDim "𝑗" $ extendDim "𝑖" empty)
2023-05-21 14:09:34 -04:00
(^DApp (^F "eq-AB" 0) (^BV 1))
(^DApp (^F "eq-AB" 0) (^BV 0)),
testEq "𝑖, 𝑗, 𝑖=0, 𝑗=0 | ⊢ eq-AB @𝑖 = eq-AB @𝑗" $
2023-05-01 21:06:25 -04:00
equalE
(eqDim (^BV 0) (^K Zero) $ eqDim (^BV 1) (^K Zero) $
extendDim "𝑗" $ extendDim "𝑖" empty)
2023-05-21 14:09:34 -04:00
(^DApp (^F "eq-AB" 0) (^BV 1))
(^DApp (^F "eq-AB" 0) (^BV 0)),
2023-03-05 06:18:15 -05:00
testEq "0=1 | ⊢ eq-AB @𝑖 = eq-AB @𝑗" $
2023-05-01 21:06:25 -04:00
equalE (extendDim "𝑗" $ extendDim "𝑖" empty01)
2023-05-21 14:09:34 -04:00
(^DApp (^F "eq-AB" 0) (^BV 1))
(^DApp (^F "eq-AB" 0) (^BV 0)),
2023-05-01 21:06:25 -04:00
testEq "eq-AB @0 = A" $
2023-05-21 14:09:34 -04:00
equalE empty (^DApp (^F "eq-AB" 0) (^K Zero)) (^F "A" 0),
2023-05-01 21:06:25 -04:00
testEq "eq-AB @1 = B" $
2023-05-21 14:09:34 -04:00
equalE empty (^DApp (^F "eq-AB" 0) (^K One)) (^F "B" 0),
2023-05-01 21:06:25 -04:00
testEq "((δ i ⇒ a) ∷ a ≡ a : A) @0 = a" $
2023-03-05 06:18:15 -05:00
equalE empty
2023-05-21 14:09:34 -04:00
(^DApp (^Ann (^DLamN (^FT "a" 0))
(^Eq0 (^FT "A" 0) (^FT "a" 0) (^FT "a" 0)))
2023-05-01 21:06:25 -04:00
(^K Zero))
2023-05-21 14:09:34 -04:00
(^F "a" 0),
2023-05-01 21:06:25 -04:00
testEq "((δ i ⇒ a) ∷ a ≡ a : A) @0 = ((δ i ⇒ a) ∷ a ≡ a : A) @1" $
2023-03-05 06:18:15 -05:00
equalE empty
2023-05-21 14:09:34 -04:00
(^DApp (^Ann (^DLamN (^FT "a" 0))
(^Eq0 (^FT "A" 0) (^FT "a" 0) (^FT "a" 0)))
2023-05-01 21:06:25 -04:00
(^K Zero))
2023-05-21 14:09:34 -04:00
(^DApp (^Ann (^DLamN (^FT "a" 0))
(^Eq0 (^FT "A" 0) (^FT "a" 0) (^FT "a" 0)))
2023-05-01 21:06:25 -04:00
(^K One))
2023-03-05 06:18:15 -05:00
],
2023-01-26 13:54:46 -05:00
2023-02-12 15:30:08 -05:00
"annotation" :- [
2023-05-01 21:06:25 -04:00
testEq "(λ x ⇒ f x) ∷ 1.A → A = f ∷ 1.A → A" $
equalE empty
2023-05-21 14:09:34 -04:00
(^Ann (^LamY "x" (E $ ^App (^F "f" 0) (^BVT 0)))
(^Arr One (^FT "A" 0) (^FT "A" 0)))
(^Ann (^FT "f" 0) (^Arr One (^FT "A" 0) (^FT "A" 0))),
2023-05-01 21:06:25 -04:00
testEq "f ∷ 1.A → A = f" $
equalE empty
2023-05-21 14:09:34 -04:00
(^Ann (^FT "f" 0) (^Arr One (^FT "A" 0) (^FT "A" 0)))
(^F "f" 0),
2023-05-01 21:06:25 -04:00
testEq "(λ x ⇒ f x) ∷ 1.A → A = f" $
equalE empty
2023-05-21 14:09:34 -04:00
(^Ann (^LamY "x" (E $ ^App (^F "f" 0) (^BVT 0)))
(^Arr One (^FT "A" 0) (^FT "A" 0)))
(^F "f" 0)
2023-02-12 15:30:08 -05:00
],
2023-03-26 18:08:48 -04:00
"natural type" :- [
2023-11-02 13:14:22 -04:00
testEq " = " $ equalTy empty (^NAT) (^NAT),
testEq " = : ★₀" $ equalT empty (^TYPE 0) (^NAT) (^NAT),
testEq " = : ★₆₉" $ equalT empty (^TYPE 69) (^NAT) (^NAT),
testNeq " ≠ {}" $ equalTy empty (^NAT) (^enum []),
testEq "0=1 ⊢ = {}" $ equalTy empty01 (^NAT) (^enum [])
2023-03-26 18:08:48 -04:00
],
2023-03-26 10:15:19 -04:00
"natural numbers" :- [
2023-11-02 13:14:22 -04:00
testEq "0 = 0" $ equalT empty (^NAT) (^Zero) (^Zero),
2023-03-26 10:15:19 -04:00
testEq "succ two = succ two" $
2023-11-02 13:14:22 -04:00
equalT empty (^NAT) (^Succ (^FT "two" 0)) (^Succ (^FT "two" 0)),
2023-03-26 10:15:19 -04:00
testNeq "succ two ≠ two" $
2023-11-02 13:14:22 -04:00
equalT empty (^NAT) (^Succ (^FT "two" 0)) (^FT "two" 0),
2023-05-01 21:06:25 -04:00
testNeq "0 ≠ 1" $
2023-11-02 13:14:22 -04:00
equalT empty (^NAT) (^Zero) (^Succ (^Zero)),
2023-05-01 21:06:25 -04:00
testEq "0=1 ⊢ 0 = 1" $
2023-11-02 13:14:22 -04:00
equalT empty01 (^NAT) (^Zero) (^Succ (^Zero))
2023-03-26 10:15:19 -04:00
],
"natural elim" :- [
testEq "caseω 0 return {a,b} of {zero ⇒ 'a; succ _ ⇒ 'b} = 'a" $
equalT empty
2023-05-01 21:06:25 -04:00
(^enum ["a", "b"])
2023-11-02 13:14:22 -04:00
(E $ ^CaseNat Any Zero (^Ann (^Zero) (^NAT))
2023-05-01 21:06:25 -04:00
(SN $ ^enum ["a", "b"])
(^Tag "a")
(SN $ ^Tag "b"))
(^Tag "a"),
2023-03-26 10:15:19 -04:00
testEq "caseω 1 return {a,b} of {zero ⇒ 'a; succ _ ⇒ 'b} = 'b" $
equalT empty
2023-05-01 21:06:25 -04:00
(^enum ["a", "b"])
2023-11-02 13:14:22 -04:00
(E $ ^CaseNat Any Zero (^Ann (^Succ (^Zero)) (^NAT))
2023-05-01 21:06:25 -04:00
(SN $ ^enum ["a", "b"])
(^Tag "a")
(SN $ ^Tag "b"))
(^Tag "b"),
2023-03-26 10:15:19 -04:00
testEq "caseω 4 return of {0 ⇒ 0; succ n ⇒ n} = 3" $
equalT empty
2023-11-02 13:14:22 -04:00
(^NAT)
(E $ ^CaseNat Any Zero (^Ann (^Nat 4) (^NAT))
2023-11-02 13:14:22 -04:00
(SN $ ^NAT)
2023-05-01 21:06:25 -04:00
(^Zero)
(SY [< "n", ^BN Unused] $ ^BVT 1))
(^Nat 3)
2023-03-26 10:15:19 -04:00
],
todo "pair types",
"pairs" :- [
testEq "('a, 'b) = ('a, 'b) : {a} × {b}" $
equalT empty
2023-05-01 21:06:25 -04:00
(^And (^enum ["a"]) (^enum ["b"]))
(^Pair (^Tag "a") (^Tag "b"))
(^Pair (^Tag "a") (^Tag "b")),
2023-03-26 10:15:19 -04:00
testNeq "('a, 'b) ≠ ('b, 'a) : {a,b} × {a,b}" $
equalT empty
2023-05-01 21:06:25 -04:00
(^And (^enum ["a", "b"]) (^enum ["a", "b"]))
(^Pair (^Tag "a") (^Tag "b"))
(^Pair (^Tag "b") (^Tag "a")),
2023-03-26 10:15:19 -04:00
testEq "0=1 ⊢ ('a, 'b) = ('b, 'a) : {a,b} × {a,b}" $
equalT empty01
2023-05-01 21:06:25 -04:00
(^And (^enum ["a", "b"]) (^enum ["a", "b"]))
(^Pair (^Tag "a") (^Tag "b"))
(^Pair (^Tag "b") (^Tag "a")),
2023-03-26 10:15:19 -04:00
testEq "0=1 ⊢ ('a, 'b) = ('b, 'a) : " $
equalT empty01
2023-11-02 13:14:22 -04:00
(^NAT)
2023-05-01 21:06:25 -04:00
(^Pair (^Tag "a") (^Tag "b"))
(^Pair (^Tag "b") (^Tag "a"))
2023-03-26 10:15:19 -04:00
],
todo "pair elim",
todo "enum types",
todo "enum",
todo "enum elim",
2023-09-17 13:10:46 -04:00
"box types" :- [
testEq "[1.A] = [1.A] : ★" $
equalT empty
(^TYPE 0)
(^BOX One (^FT "A" 0))
(^BOX One (^FT "A" 0)),
testNeq "[1.A] ≠ [ω.A] : ★" $
equalT empty
(^TYPE 0)
(^BOX One (^FT "A" 0))
(^BOX Any (^FT "A" 0)),
testNeq "[1.A] ≠ [1.B] : ★" $
equalT empty
(^TYPE 0)
(^BOX One (^FT "A" 0))
(^BOX One (^FT "B" 0)),
testNeq "[1.A] ≠ A : ★" $
equalT empty
(^TYPE 0)
(^BOX One (^FT "A" 0))
(^FT "A" 0),
testEq "0=1 ⊢ [1.A] = [1.B] : ★" $
equalT empty01
(^TYPE 0)
(^BOX One (^FT "A" 0))
(^BOX One (^FT "B" 0))
],
"boxes" :- [
testEq "[a] = [a] : [ω.A]" $
equalT empty
(^BOX Any (^FT "A" 0))
(^Box (^FT "a" 0))
(^Box (^FT "a" 0)),
testNeq "[a] ≠ [a'] : [ω.A]" $
equalT empty
(^BOX Any (^FT "A" 0))
(^Box (^FT "a" 0))
(^Box (^FT "a'" 0)),
testEq "ω.x : [ω.A] ⊢ x = [case1 b return A of {[y] ⇒ y}] : [ω.A]" $
equalT (ctx [< ("x", ^BOX Any (^FT "A" 0))])
(^BOX Any (^FT "A" 0))
(^BVT 0)
(^Box (E $ ^CaseBox One (^BV 0) (SN $ ^FT "A" 0) (SY [< "y"] (^BVT 0))))
],
2023-03-31 13:11:35 -04:00
2023-02-12 15:30:08 -05:00
"elim closure" :- [
2023-05-01 21:06:25 -04:00
note "bold numbers for de bruijn indices",
testEq "𝟎{a} = a" $
2023-05-21 14:09:34 -04:00
equalE empty (CloE (Sub (^BV 0) (^F "a" 0 ::: id))) (^F "a" 0),
2023-05-01 21:06:25 -04:00
testEq "𝟏{a} = 𝟎" $
2023-05-21 14:09:34 -04:00
equalE (extendTy Any "x" (^FT "A" 0) empty)
(CloE (Sub (^BV 1) (^F "a" 0 ::: id))) (^BV 0)
2023-02-12 15:30:08 -05:00
],
2023-02-12 15:30:08 -05:00
"elim d-closure" :- [
2023-05-01 21:06:25 -04:00
note "bold numbers for de bruijn indices",
2023-03-05 06:18:15 -05:00
note "0·eq-AB : (A ≡ B : ★₀)",
2023-05-01 21:06:25 -04:00
testEq "(eq-AB @𝟎)0 = eq-AB @0" $
equalE empty
2023-05-21 14:09:34 -04:00
(DCloE (Sub (^DApp (^F "eq-AB" 0) (^BV 0)) (^K Zero ::: id)))
(^DApp (^F "eq-AB" 0) (^K Zero)),
2023-05-01 21:06:25 -04:00
testEq "(eq-AB @𝟎)0 = A" $
equalE empty
2023-05-21 14:09:34 -04:00
(DCloE (Sub (^DApp (^F "eq-AB" 0) (^BV 0)) (^K Zero ::: id)))
(^F "A" 0),
2023-05-01 21:06:25 -04:00
testEq "(eq-AB @𝟎)1 = B" $
equalE empty
2023-05-21 14:09:34 -04:00
(DCloE (Sub (^DApp (^F "eq-AB" 0) (^BV 0)) (^K One ::: id)))
(^F "B" 0),
2023-05-01 21:06:25 -04:00
testNeq "(eq-AB @𝟎)1 ≠ A" $
equalE empty
2023-05-21 14:09:34 -04:00
(DCloE (Sub (^DApp (^F "eq-AB" 0) (^BV 0)) (^K One ::: id)))
(^F "A" 0),
2023-05-01 21:06:25 -04:00
testEq "(eq-AB @𝟎)𝟎,0 = (eq-AB 𝟎)" $
equalE (extendDim "𝑖" empty)
2023-05-21 14:09:34 -04:00
(DCloE (Sub (^DApp (^F "eq-AB" 0) (^BV 0)) (^BV 0 ::: ^K Zero ::: id)))
(^DApp (^F "eq-AB" 0) (^BV 0)),
2023-05-01 21:06:25 -04:00
testNeq "(eq-AB 𝟎)0 ≠ (eq-AB 0)" $
equalE (extendDim "𝑖" empty)
2023-05-21 14:09:34 -04:00
(DCloE (Sub (^DApp (^F "eq-AB" 0) (^BV 0)) (^BV 0 ::: ^K Zero ::: id)))
(^DApp (^F "eq-AB" 0) (^K Zero)),
2023-05-01 21:06:25 -04:00
testEq "𝟎0 = 𝟎 # term and dim vars distinct" $
equalE
2023-05-21 14:09:34 -04:00
(extendTy Any "x" (^FT "A" 0) empty)
2023-05-01 21:06:25 -04:00
(DCloE (Sub (^BV 0) (^K Zero ::: id))) (^BV 0),
testEq "a0 = a" $
equalE empty
2023-05-21 14:09:34 -04:00
(DCloE (Sub (^F "a" 0) (^K Zero ::: id))) (^F "a" 0),
2023-05-01 21:06:25 -04:00
testEq "(f a)0 = f0 a0" $
let th = ^K Zero ::: id in
equalE empty
2023-05-21 14:09:34 -04:00
(DCloE (Sub (^App (^F "f" 0) (^FT "a" 0)) th))
(^App (DCloE (Sub (^F "f" 0) th)) (DCloT (Sub (^FT "a" 0) th)))
2023-02-12 15:30:08 -05:00
],
"clashes" :- [
2023-05-01 21:06:25 -04:00
testNeq "★₀ ≠ 0.★₀ → ★₀" $
equalT empty (^TYPE 1) (^TYPE 0) (^Arr Zero (^TYPE 0) (^TYPE 0)),
testEq "0=1 ⊢ ★₀ = 0.★₀ → ★₀" $
equalT empty01 (^TYPE 1) (^TYPE 0) (^Arr Zero (^TYPE 0) (^TYPE 0)),
todo "others"
2022-04-27 14:06:39 -04:00
]
]