Ackermann Function - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Works in Progress (https://qb64phoenix.com/forum/forumdisplay.php?fid=9) +---- Thread: Ackermann Function (/showthread.php?tid=617) |
RE: Ackermann Function - James D Jarvis - 07-15-2022 (07-15-2022, 11:19 PM)Kernelpanic Wrote:(07-15-2022, 10:40 PM)James D Jarvis Wrote: Looks like you are getting a stack overflow due to the depth of the recursion. The program crashes sometime after 70,609,342(but less than 70,899,999,999) recursive calls to the function. The result itself may well be within the limits of the data type but the number of recursive calls required to get there is extremely high according to the logic used. Here's how I found that number of recursive calls. Code: (Select All) 'Ackermann Funktion - 15. Juli 2022 RE: Ackermann Function - Kernelpanic - 07-16-2022 Thanks for your help! But why do one get the result 65533 in "C" at A(4,1) (not with myself), but here: Ackermann Funktion in C I've had enough for today! It's 02:15 here. RE: Ackermann Function - James D Jarvis - 07-16-2022 those aren't the same functions are they? (!x) means "NOT X" in raw logic doesn't it? if (!n) return ackermann(m - 1, 1); isn't If m > 0 And n = 0 Then ackermann = ackermann(m - 1, 1) RE: Ackermann Function - bplus - 07-16-2022 I suspect this line here is the trouble maker: ackermann = ackermann(m - 1, ackermann(m, n - 1)) RE: Ackermann Function - James D Jarvis - 07-16-2022 The original program certainly runs into a stack overflow due to the use of the recursive function. I was able to calculate a(4,1) using the following code adapted from the basic256 version as that doesn't have recursive functions built in. I takes a couple minutes to calculate but it works. I have no idea if it can calculate A(4,2). Code: (Select All) Dim stack(50000000, 3) As _Integer64 RE: Ackermann Function - bplus - 07-16-2022 Yeah I noticed the 4 levels skipped at RC by most the PL's attempting Akermann. RE: Ackermann Function - Kernelpanic - 07-16-2022 Quote:The original program certainly runs into a stack overflow due to the use of the recursive function. The program works great! I've tried adding a timer, but the damn thing do not want. I assume that has to do with "Gosub". - I tried it out for two hours. The stack overflow can't be true. Here's a page that computes A(4, 1) in no time. One would have to be able to see the source code for it. Ackermann function Code: (Select All) 'Ackermann Funktion von Basic256 angepasst James D. Jarvis RE: Ackermann Function - Kernelpanic - 07-16-2022 (07-16-2022, 01:02 AM)bplus Wrote: I suspect this line here is the trouble maker: But that is the case in all programs that I have found. It works too, but it only causes trouble from A(4, 1). And that is not too big. See the link above. RE: Ackermann Function - Jack - 07-16-2022 hello Kernelpanic as others have stated, you run out of stack, but you can increase the stack size open internal\c\makeline_win.txt add: -Wl,--stack,10485760 your opening post needs a couple of small corrections Code: (Select All) 'Ackermann Funktion - 15. Juli 2022 RE: Ackermann Function - Kernelpanic - 07-16-2022 Thanks for your trouble, but . . . Is it the system? I have 16GB of RAM. But maybe I didn't get it either. |