kill(all)$

maxima :recursion Ackermann function 1.0
peter.vlasschaert@gmail.com,14/03/2020

see also :truebasic programming

load packages
===========

load(lrats)$

algo : Ackermann function
===================

print "********************************************"
print "* ack(m,n) =>   algo                              *"
print "* n+1                       if m=0                     *"
print "* ack(m-1,1)            if m>0 and  n=0       *"
print "* ack(m-1,ack(m,n-1))   if m>0 and  n>0  *"
print "********************************************"

ack(m,n):=block([],
    if m=0 then
        return(n+1)
    else if  (n=0) then
        return(ack(m-1,1))
    else 
       return(ack(m-1,ack(m,n-1)))
)$

example: test ack(,)
-----------------------

ack(3,7);

approximation : Ackermann function
===========================

print "**************************************"
print "problem : ack(4,1) => out of memory"
print "**************************************"
print "ack(0,k) =k+1                                 "
print "ack(1,k) =k+2                                 "
print "ack(3,k) =2^(k+3)-3                         "
print "ack(4,k) =2^(ack(4,k-1)+3) -3 if k>0 "
print "ack(4,0) =13  ,see output : matrix     "
print "**************************************"

print(m,n,value)$

 =========

for i:0 thru 3 do(
   for j:0 thru 7 do(
      print(i,j,ack(i,j))
    )
    
)$

 => Input matrix
--------------------

ackm:genmatrix(a, 4, 8);

for i:1 thru 4 do(
   for j:1 thru 8 do(
      ackm[i,j]:ack(i-1,j-1)
    )
    
)$

 => Output matrix
----------------------

p1:ackm;

same : example for test.
==================

p2:ackm[4,8];

p3:table_form(p1)$

see : print output 'above' 
why : addrow , addcol

p4:makelist(i,i,0,7)$
p4a: [0,1,2,3,"&"]$
p5:addrow(p1,p4);

p6:addcol(p5,p4a);

final table 
=======

p7:table_form(p6)$

matrix :contains ,numbers and txt ,see :p6