Add List constructors & methods

main
Bram van den Heuvel 2026-06-29 16:44:43 +02:00
parent 90240cf067
commit 323b87189c
1 changed files with 21 additions and 9 deletions

View File

@ -106,18 +106,29 @@ def apply_rules() -> dict[str, F]:
case Const("Bool.Contradiction"):
return Truth()
def __list_isempty(x : Term) -> Term | None:
match x:
case Const("List.Nil"):
return Truth()
case App(f=App(f=Const("List.Cons"))):
return Contradiction()
def __list_length(x : Term) -> Term | None:
match x:
case Const("List.Nil"):
return Zero()
case App(f=App(f=Const("List.Cons"), x=head), x=tail):
return Succ(A1("List.length", tail))
def __nat_add(x : Term, y : Term) -> Term | None:
match x:
case Const("Nat.Zero"):
return y
case App(f=Const("Nat.Succ"), x=x_):
return Succ(
App(
f=App(Const("Nat.add"), x_),
x=y,
)
)
return Succ(A2("Nat.add", x_, y))
def __nat_iszero(x : Term) -> Term | None:
match x:
@ -129,11 +140,12 @@ def apply_rules() -> dict[str, F]:
return {
"Bool.not": F1(__bool_not),
"List.isEmpty": F1(__list_isempty),
"List.length": F1(__list_length),
"Nat.add" : F2(__nat_add),
"Nat.isZero" : F1(__nat_iszero),
}
def normalize(term : Term) -> Term:
match term:
case App():