Add List constructors & methods
parent
90240cf067
commit
323b87189c
26
proof.py
26
proof.py
|
|
@ -106,18 +106,29 @@ 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:
|
||||||
|
|
@ -129,11 +140,12 @@ def apply_rules() -> dict[str, F]:
|
||||||
|
|
||||||
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:
|
||||||
case App():
|
case App():
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue