[Push] Akermann function
Maarten Keijzer
mkeijzer at xs4all.nl
Fri Jun 18 17:48:33 EDT 2010
On Friday, June 18, 2010 10:46:51 pm PerPlex Ed wrote:
> In case anybody wants to meet other people using any Push implementation,
you can join the
>
> ##push
>
> IRC channel on freenode.net.
>
> I'll be in there sometimes while working on anything related to Push.
>
>
>
>
>
> _______________________________________________
> Push mailing list
> Push at lists.hampshire.edu
> https://lists.hampshire.edu/mailman/listinfo/push
>
-------------- next part --------------
# 1. If x = 0 then A(x, y) = y + 1
# 2. If y = 0 then A(x, y) = A(x-1, 1)
#3. Otherwise, A(x, y) = A(x-1, A(x, y-1))
(
CODE.POP # get rid of this pesky code on the stack
CODE.QUOTE
(
EXEC.Y
( INTEGER.DUP 0 INTEGER.= EXEC.IF # if x = 0
( #then
INTEGER.POP 1 INTEGER.+ EXEC.K CODE.NOOP # break
)
( #else
INTEGER.SWAP INTEGER.DUP 0 INTEGER.= INTEGER.SWAP EXEC.IF # if y = 0
( #then
INTEGER.SWAP INTEGER.POP 1 INTEGER.SWAP # y = 1
1 INTEGER.- # A(x-1, 1)
)
( #else
EXEC.S ( # S CODE1 CODE2 ACKERMANN -> S CODE1 ACKERMANN (CODE2 ACKERMANN)
INTEGER.DUP 2 INTEGER.SHOVE # copy x to 3d position
INTEGER.SWAP 1 INTEGER.- INTEGER.SWAP # A(x, y-1)
)
(
INTEGER.SWAP # previous recursion will return y first, then x, so swap
1 INTEGER.- # A(x-1, A(x,y-1))
)
)
)
)
)
# define name
ACKERMANN CODE.DEFINE
# run tests
2 3 ACKERMANN 29 INTEGER.=
4 3 ACKERMANN 125 INTEGER.=
5 3 ACKERMANN 253 INTEGER.=
BOOLEAN.AND # check if all tests passed
BOOLEAN.AND # check if all tests passed
)
More information about the Push
mailing list