1 страниц (6 вхождений)
bad recursive function calling causes crash - Сообщения
#1 Опубликовано: 02.12.2011 08:22:37
Hello,
Try this one:
[MATH=eng]f(x)←line(x←x+1,f(x),2,1)[/MATH]
[MATH=eng]f(5)=#[/MATH]
This will cause SMath to crash.
Just wondering how to suppress the bad recursive function calls and to avoid crashes.
Regards,
Radovan
Try this one:
[MATH=eng]f(x)←line(x←x+1,f(x),2,1)[/MATH]
[MATH=eng]f(5)=#[/MATH]
This will cause SMath to crash.
Just wondering how to suppress the bad recursive function calls and to avoid crashes.
Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#2 Опубликовано: 03.12.2011 09:36:43
Radovan,
This subject came up recently. See my post. I don't think there is any way for SMath to determine the recursion could go on indefinitely. You need to put a test in your function.
http://en.smath.info/forum/default.aspx?g=posts&t=1049
This subject came up recently. See my post. I don't think there is any way for SMath to determine the recursion could go on indefinitely. You need to put a test in your function.
http://en.smath.info/forum/default.aspx?g=posts&t=1049
Ed
#3 Опубликовано: 03.12.2011 11:22:49
Hello Ed,
I agree that we have to pay attention when writing such functions. In fact, I think we should try to avoid them at all, if possible. Just crossed my mind that if I make a mistake and get into some indefinite loop or the calculation is taking to long, I can interrupt the calculation. On the other hand, I do not feel comfortable when I know that a mistake like unintentional recursive call could crash the SMath. I am not a programmer and I do not know if there is something that could be done in order to avoid such crashes. If not, we just have to accept that and be extra careful.
Regards,
radovan
I agree that we have to pay attention when writing such functions. In fact, I think we should try to avoid them at all, if possible. Just crossed my mind that if I make a mistake and get into some indefinite loop or the calculation is taking to long, I can interrupt the calculation. On the other hand, I do not feel comfortable when I know that a mistake like unintentional recursive call could crash the SMath. I am not a programmer and I do not know if there is something that could be done in order to avoid such crashes. If not, we just have to accept that and be extra careful.
Regards,
radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#4 Опубликовано: 04.12.2011 17:05:42
WroteJust crossed my mind that if I make a mistake and get into some indefinite loop or the calculation is taking to long, I can interrupt the calculation.
Hello. Your sample doesn't cause crashes in my pc with the prior version of SMath.
You can interrupt the current calculation, bordered in green, by pressing the stop icon.
It might be useful to have SMath provide some report about the callings involved in an interrupted calculation.
#5 Опубликовано: 04.12.2011 19:49:50
Hello,
Yes, you are right. Version 0.89 stable will not crash and we can interrupt the calculation. It can be considered as expected behavior. Therefore, I think that this might be a bug in 0.89.8 beta version.
About reporting the callings, I suppose this might be connected to the debugger . It started by uni more than a year ago. It might be quite helpful in writing functions but I do not know the progress of it.
Regards,
Radovan
WroteWroteJust crossed my mind that if I make a mistake and get into some indefinite loop or the calculation is taking to long, I can interrupt the calculation.
Hello. Your sample doesn't cause crashes in my pc with the prior version of SMath.
You can interrupt the current calculation, bordered in green, by pressing the stop icon.
It might be useful to have SMath provide some report about the callings involved in an interrupted calculation.
Yes, you are right. Version 0.89 stable will not crash and we can interrupt the calculation. It can be considered as expected behavior. Therefore, I think that this might be a bug in 0.89.8 beta version.
About reporting the callings, I suppose this might be connected to the debugger . It started by uni more than a year ago. It might be quite helpful in writing functions but I do not know the progress of it.
Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#6 Опубликовано: 09.01.2012 21:37:30
Hello,
There is some change in v.0.90 about recursive function calls, as Andrey pointed out. Here are some simple testing examples which show some different behavior regarding recursive function calls.
The previous trivial example will not cause crash anymore:
[MATH=eng]f(x)←line(x←x+1,f(x),2,1)[/MATH]
Although we can have the symbolic answer, the numerical answer will give the error that the function is undefined.
[MATH=eng]f(x)—f(2+x)[/MATH]
[MATH=eng]f(-8)=#@#[/MATH]
Here is another one:
[MATH=eng]ff(x)←line(x←x+1,if(x<10,ff(x),y←x),y,3,1)[/MATH]
[MATH=eng]ff(x)—3+x[/MATH]
Lets try to get some numerical answer
[MATH=eng]ff(8)=#@#[/MATH] [MATH=eng]ff(12)=13[/MATH]
For 8 the result is undefined function but for 12 there is a result
Lets make another function by just assigning the previous one, and try the same
[MATH=eng]fff(x)←ff(x)[/MATH] [MATH=eng]fff(x)—3+x[/MATH]
[MATH=eng]fff(8)=11[/MATH] [MATH=eng]fff(12)=15[/MATH]
Now we get the result.
To be honest, I am a bit puzzled here. Do not get at the moment what happened.
Andrey, could you give us the answer what has going on and how to understand this please?
Regards,
Radovan
There is some change in v.0.90 about recursive function calls, as Andrey pointed out. Here are some simple testing examples which show some different behavior regarding recursive function calls.
The previous trivial example will not cause crash anymore:
[MATH=eng]f(x)←line(x←x+1,f(x),2,1)[/MATH]
Although we can have the symbolic answer, the numerical answer will give the error that the function is undefined.
[MATH=eng]f(x)—f(2+x)[/MATH]
[MATH=eng]f(-8)=#@#[/MATH]
Here is another one:
[MATH=eng]ff(x)←line(x←x+1,if(x<10,ff(x),y←x),y,3,1)[/MATH]
[MATH=eng]ff(x)—3+x[/MATH]
Lets try to get some numerical answer
[MATH=eng]ff(8)=#@#[/MATH] [MATH=eng]ff(12)=13[/MATH]
For 8 the result is undefined function but for 12 there is a result
Lets make another function by just assigning the previous one, and try the same
[MATH=eng]fff(x)←ff(x)[/MATH] [MATH=eng]fff(x)—3+x[/MATH]
[MATH=eng]fff(8)=11[/MATH] [MATH=eng]fff(12)=15[/MATH]
Now we get the result.
To be honest, I am a bit puzzled here. Do not get at the moment what happened.
Andrey, could you give us the answer what has going on and how to understand this please?
Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
1 страниц (6 вхождений)
-
Новые сообщения
-
Нет новых сообщений