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,19 +106,30 @@ def apply_rules() -> dict[str, F]:
case Const("Bool.Contradiction"): case Const("Bool.Contradiction"):
return Truth() 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: def __nat_add(x : Term, y : Term) -> Term | None:
match x: match x:
case Const("Nat.Zero"): case Const("Nat.Zero"):
return y return y
case App(f=Const("Nat.Succ"), x=x_): case App(f=Const("Nat.Succ"), x=x_):
return Succ( return Succ(A2("Nat.add", x_, y))
App(
f=App(Const("Nat.add"), x_),
x=y,
)
)
def __nat_iszero(x : Term) -> Term | None: def __nat_iszero(x : Term) -> Term | None:
match x: match x:
case Const("Nat.Zero"): case Const("Nat.Zero"):
@ -126,13 +137,14 @@ def apply_rules() -> dict[str, F]:
case App(f=Const("Nat.Succ")): case App(f=Const("Nat.Succ")):
return Contradiction() return Contradiction()
return { return {
"Bool.not": F1(__bool_not), "Bool.not": F1(__bool_not),
"List.isEmpty": F1(__list_isempty),
"List.length": F1(__list_length),
"Nat.add" : F2(__nat_add), "Nat.add" : F2(__nat_add),
"Nat.isZero" : F1(__nat_iszero), "Nat.isZero" : F1(__nat_iszero),
} }
def normalize(term : Term) -> Term: def normalize(term : Term) -> Term:
match term: match term: