Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline omorr  
#1 Posted : 02 December 2011 15:22:37(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

Was thanked: 318 time(s) in 268 post(s)
Hello,


Try this one:

f(x)←line(x←x+1,f(x),2,1)
f(5)=#

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!"

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline TheWizEd  
#2 Posted : 03 December 2011 16:36:43(UTC)
TheWizEd


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2010(UTC)
Posts: 178
Man
United States

Was thanked: 19 time(s) in 13 post(s)
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/defa....aspx?g=posts&t=1049
Ed
Offline omorr  
#3 Posted : 03 December 2011 18:22:49(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

Was thanked: 318 time(s) in 268 post(s)
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


When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline kilele  
#4 Posted : 05 December 2011 00:05:42(UTC)
kilele


Rank: Advanced Member

Groups: Registered
Joined: 30/03/2011(UTC)
Posts: 393

Was thanked: 132 time(s) in 113 post(s)
omorr wrote:
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.


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.

Edited by user 05 December 2011 00:08:18(UTC)  | Reason: Not specified

Offline omorr  
#5 Posted : 05 December 2011 02:49:50(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

Was thanked: 318 time(s) in 268 post(s)
Hello,
kilele wrote:
omorr wrote:
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.


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

Edited by user 05 December 2011 02:57:11(UTC)  | Reason: Not specified

When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline omorr  
#6 Posted : 10 January 2012 04:37:30(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

Was thanked: 318 time(s) in 268 post(s)
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:
f(x)←line(x←x+1,f(x),2,1)
Although we can have the symbolic answer, the numerical answer will give the error that the function is undefined.
f(x)—f(2+x)
f(-8)=#@#
Here is another one:
ff(x)←line(x←x+1,if(x<10,ff(x),y←x),y,3,1)
ff(x)—3+x
Lets try to get some numerical answer
ff(8)=#@# ff(12)=13
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
fff(x)←ff(x) fff(x)—3+x
fff(8)=11 fff(12)=15
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

Edited by user 10 January 2012 04:39:29(UTC)  | Reason: Not specified

When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.