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 JonAReynolds  
#1 Posted : 07 May 2024 07:36:26(UTC)
JonAReynolds

Rank: Newbie

Groups: Registered
Joined: 21/12/2023(UTC)
Posts: 7
United Kingdom
Location: Hampshire

I don't fully understand the use of 'eval', which probably means I don't really understand how SMath works. Can anyone help me?

I sort of understand what it does, and have proved to myself that it can speed up calculations considerably.

Do I need to use eval on every expression if I want calculations as fast as possible (seems a bit of an odd way of doing things)? What do I lose by doing this? Is there some option I can set so that the whole worksheet is forced to assume that eval is in every expression?

I used MathCad for decades, and I don't remember anything equivalent. As I recall numerical and symbolic were easy to keep separate.

TIA for any help.

Jon

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

Offline Davide Carpi  
#2 Posted : 07 May 2024 08:22:45(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,654
Man
Italy
Location: Italy

Was thanked: 1340 time(s) in 879 post(s)
Hi Jon,

by default SMath evaluate simbolically. In short, this means that if you have (f.e.) X=a+b+c=A, the expression (a+b+c) is stored and then evaluated on request; so if you have Y=d+e=B and you want to calculate X+Y, SMath returns a+b+c+d+e, not A+B. This minimize the error propagation.

When you use eval(), the calculation of a+b+c is performed and the numerical result (A) is stored.

When you have loops or complex calculation, the expression terms might stack in a very long equation. If you have a vector or a matrix, each element might contains a lot of them.

When the complexity arise, since an evaluation requires to retrieve each element from the memory, replace it, and perform the actual calculations, it might be useful to perform an eval() (in some functions the result is forced to be a numerical evalution, so the performance improvement might vary).

Edited by user 07 May 2024 09:18:40(UTC)  | Reason: Not specified

If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
thanks 4 users thanked Davide Carpi for this useful post.
on 08/05/2024(UTC),  on 08/05/2024(UTC),  on 08/05/2024(UTC),  on 08/05/2024(UTC)
Offline Razonar  
#3 Posted : 08 May 2024 10:01:03(UTC)
Razonar


Rank: Advanced Member

Groups: Registered
Joined: 28/08/2014(UTC)
Posts: 1,370
Uruguay

Was thanked: 829 time(s) in 525 post(s)
Originally Posted by: Davide Carpi Go to Quoted Post
... When you have loops or complex calculation, the expression terms might stack in a very long equation. If you have a vector or a matrix, each element might contains a lot of them.

When the complexity arise, since an evaluation requires to retrieve each element from the memory, replace it, and perform the actual calculations, it might be useful to perform an eval() ...


Hi. This example can illustrate what Davide says.

Best regards.
Alvaro.

using_eval.sm (20kb) downloaded 3 time(s).

eval.png
thanks 2 users thanked Razonar for this useful post.
on 08/05/2024(UTC),  on 08/05/2024(UTC)
Offline JonAReynolds  
#4 Posted : 14 May 2024 07:47:15(UTC)
JonAReynolds

Rank: Newbie

Groups: Registered
Joined: 21/12/2023(UTC)
Posts: 7
United Kingdom
Location: Hampshire

Thank you, Davide & Alvaro,

I understand that a bit better now.

I'm still not sure what I might lose by using 'eval' all the time, apart from minimisation of error propagation - not normally relevant to what I do with Smath. My background & training leads me to think about such errors as I'm designing algorithms.

I'm thinking that I might just as well use 'eval' all the time, on every expression, but this is a bit of a pain (just more typing, really, but ...). I can't help but think that an 'auto-eval' mode would be a useful feature, but maybe this is not possible to integrate into the Smath structure.

Anyway, thanks for the help.

Jon
Offline Davide Carpi  
#5 Posted : 14 May 2024 23:11:49(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,654
Man
Italy
Location: Italy

Was thanked: 1340 time(s) in 879 post(s)
As a rule of thumb, you can/should write everything without eval() and introduce some only if the evaluation as a whole is noticeably slow; the threshold is on you, I think 5 to 10 seconds is where you should start to investigate if something could be improved, looking at the regions with persistent green border (those under evaluation) and their contributors.
Too many eval() are useless and they make the worksheet less readable, though in this case you might use a user-defined overload one-character function to mitigate it (something like ''(x):eval(x) or \0024\(x):eval(x) ).

Edited by user 14 May 2024 23:49:40(UTC)  | Reason: Not specified

If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
Offline Razonar  
#6 Posted : 15 May 2024 07:37:55(UTC)
Razonar


Rank: Advanced Member

Groups: Registered
Joined: 28/08/2014(UTC)
Posts: 1,370
Uruguay

Was thanked: 829 time(s) in 525 post(s)
Originally Posted by: JonAReynolds Go to Quoted Post
... think that an 'auto-eval' mode would be a useful feature, but maybe this is not possible to integrate into the Smath structure. ...


Hi. There is something like that, the Optimization/Numeric option from the contextual menu. You can also select all expressions with Ctrl-A and choose that option for the entire worksheet.

num-optimiz.sm (72kb) downloaded 0 time(s).

num-optimiz.png

Best regards.
Alvaro.
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.