more test cases, problem in Tree.newt

This commit is contained in:
2024-10-07 20:59:50 -07:00
parent 38b09ac028
commit 75015f094a
9 changed files with 108 additions and 16 deletions

70
newt/Tree.newt Normal file
View File

@@ -0,0 +1,70 @@
module Tree
-- https://youtu.be/v2yXrOkzt5w?t=3013
data Nat : U where
Z : Nat
S : Nat -> Nat
data Unit : U where
MkUnit : Unit
data Void : U where
infixl 4 _+_
data _+_ : U -> U -> U where
inl : {A B : U} -> A -> A + B
inr : {A B : U} -> B -> A + B
infix 4 _<=_
_<=_ : Nat -> Nat -> U
Z <= y = Unit
S x <= Z = Void
S x <= S y = x <= y
cmp : (x y : Nat) -> (x <= y) + (y <= x)
cmp Z y = inl MkUnit
cmp (S z) Z = inr MkUnit
cmp (S x) (S y) = cmp x y
-- 53:21
data Bnd : U where
Bot : Bnd
N : Nat -> Bnd
Top : Bnd
infix 4 _<<=_
_<<=_ : Bnd -> Bnd -> U
Bot <<= _ = Unit
N x <<= N y = x <= y
_ <<= Top = Unit
_ <<= _ = Void
data Intv : Bnd -> Bnd -> U where
MkInt : {l u : Bnd} (x : Nat) (lx : l <<= N x) (xu : N x <<= u) -> Intv l u
data T23 : Bnd -> Bnd -> Nat -> U where
leaf : {l u : Bnd} {h : Nat} (lu : l <<= u) -> T23 l u Z
node2 : {l u : Bnd} {h : Nat} (x : _)
(tlx : T23 l (N x) h) (txu : T23 (N x) u h) ->
T23 l u (S h)
node3 : {l u : Bnd} {h : Nat} (x y : _)
(tlx : T23 l (N x) h) (txy : T23 (N x) (N y) h) (tyu : T23 (N y) u h) ->
T23 l u (S h)
-- -- 56:
infixl 5 _*_
infixl 1 _,_
data Sg : (A : U) -> (A -> U) -> U where
_,_ : {A : U} {B : A -> U} -> (a : A) -> B a -> Sg A B
data _*_ : (A B : U) -> U where
Foo : {A B : U} -> A -> B -> A * B
TooBig : Bnd -> Bnd -> Nat -> U
TooBig l u h = Sg Nat (\ x => T23 l (N x) h * T23 (N x) u h)