From: Mart Lubbers Date: Wed, 16 May 2018 12:59:44 +0000 (+0200) Subject: reduce rules arithmetics in preamble X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=f43771d78bcce4dcf65ef405fb5d6be8e9062ac7;p=lambda.git reduce rules arithmetics in preamble --- diff --git a/preamble b/preamble index 8eda655..2861a88 100644 --- a/preamble +++ b/preamble @@ -7,3 +7,7 @@ W=\x y.x y y; SOMEGA=\x.x x; OMEGA=SOMEGA SOMEGA; Y=\g.(\x.g (x x))(\x.g (x x)); +ZERO=\f x.x; +SUCC=\n f x.f(n f x); +PLUS=\m n.m SUCC n; +MULT=\m n f x.m(n f)x; diff --git a/reduce.c b/reduce.c index 7335bfd..9dbf678 100644 --- a/reduce.c +++ b/reduce.c @@ -45,6 +45,7 @@ void lambda_reduce(struct lambda *t, struct lambda *total, int *maxdepth) //If the first argument is an abstraction, we apply t1 = t->data.application.expr1; t2 = t->data.application.expr2; + lambda_reduce(t1, total, maxdepth); if(t1->which == lambda_abs){ subst(t1->data.abstraction.ident, t1->data.abstraction.expr, t2, total); (*maxdepth)--; @@ -54,9 +55,9 @@ void lambda_reduce(struct lambda *t, struct lambda *total, int *maxdepth) printf("-> "); lambda_print(total); lambda_reduce(t, total, maxdepth); + } else { + lambda_reduce(t2, total, maxdepth); } - lambda_reduce(t1, total, maxdepth); - lambda_reduce(t, total, maxdepth); break; } }