home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: alt.folklore.computers
- Path: sparky!uunet!haven.umd.edu!darwin.sura.net!spool.mu.edu!umn.edu!sctc.com!boebert
- From: boebert@sctc.com (Earl Boebert)
- Subject: Re: Ackermann's function
- Message-ID: <1992Nov23.211817.22693@sctc.com>
- Keywords: Ackermann's function, recursion, primitive-recursive, FORTRAN, COBOL
- Organization: SCTC
- References: <ken.722284796@base> <1992Nov23.193734.253@cs.cornell.edu>
- Date: Mon, 23 Nov 1992 21:18:17 GMT
- Lines: 91
-
- chapman@cs.cornell.edu (Richard Chapman) writes:
-
- >ken@us.oracle.com (Ken C. Stewart) writes:
-
- >>Can anyone remind me (ahem) of the definition of Ackermann's function (a pair
- >>of mutually-recursive functions I think?)?
-
- >The Ackermann function:
-
- > f(0,y) = y + 1
- > f(x+1,0) = f(x,1)
- > f(x+1,y+1) = f(x,f(x+1,y))
-
- [exchange on recursion deleted]
-
- >While recursion is not allowed in FORTRAN, you can implement it
- >yourself in a FORTRAN program by explicitly implementing a stack and
- >handling it all yourself. Now, whether or not FORTRAN has recursion
- >has little to do with the expressive power of the language; since
- >on-line storage and memory are finite, the most you can implement in
- >any language on any computer is a function that could be implemented by
- >a finite-state automaton (which is a far smaller class than the Turing
- >computable functions). However, barring the finite memory limit. If
- >you assume you have infinite memory size, and each location can hold
- >an arbitrarily large integer, all you need to implement all the
- >computable functions are: load a memory location with zero, increment
- >contents of a memory location, conditional jump, and transfer contents of one
- >memory location to another. All these are operations which FORTRAN and
- >COBOL are both capable of.
-
-
- From CACM 8:2, February 1965:
-
-
- INTEGER FUNCTION ACKER(M,N)
-
- C COMPUTE ACKERMANN'S FUNCTION, DEFINED BY
- C ACKER(0,N) = N+1
- C ACKER(M+1,0) = ACKER(M,1)
- C ACKER(M+1,N+1) = ACKER(M,(ACKER(M+1,N))
- C SIZE OF VALUE AND PLACE TABLES IS ONE MORE THAN LARGEST M EXPECTED
-
- INTEGER VALUE(6), PLACE(6)
-
- C TEST FOR ZERO M
-
- IF (M .NE. 0) GO TO 1
- ACKER = N+1
- RETURN
-
- C NON-ZERO M, INITIALIZE FOR ITERATION
-
- 1 VALUE = 1
- PLACE = 0
-
- C ITERATION LOOP, GET NEW VALUE
-
- 2 VALUE = VALUE+1
- PLACE = PLACE+1
-
- C PROPAGATE VALUE
-
- DO 4 I=1,M
- IF (PLACE(I) .NE. 1) GO TO 3
-
- C INITIATE NEW LEVEL
-
- VALUE(I+1) = VALUE
- PLACE(I+1) = 0
- IF (I .EQ. M) GO TO 5
- GO TO 2
-
- 3 IF (PLACE(I+1) .NE VALUE(I+1)) GO TO 2
- VALUE(I+1) = VALUE
-
- 4 PLACE(I+1) = PLACE(I+1)+1
-
- C CHECK FOR END OF ITERATION
-
- 5 IF (PLACE(M+1) .NE. N) GO TO 2
- ACKER = VALUE
- RETURN
- END
-
- Written by H. Gordon Rice, one of the founders of Computer Sciences
- Corp. He noted with satisfaction that computing ACKER (5,0) = 65,533
- required less than 10 seconds on a Univac 1107. And yes, people used
- to write stuff like that above for a living :-)
-
- Earl
-
-