Rank: Newbie
Groups: Registered
Joined: 21/12/2023(UTC) Posts: 7 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
|
|
|
|
Rank: Advanced Member Groups: Registered, Advanced Member Joined: 13/01/2012(UTC) Posts: 2,678 Location: Italy Was thanked: 1364 time(s) in 892 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 |
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)
|
|
Rank: Advanced Member Groups: Registered
Joined: 28/08/2014(UTC) Posts: 1,407 Was thanked: 857 time(s) in 543 post(s)
|
Originally Posted by: Davide Carpi ... 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 5 time(s).
|
2 users thanked Razonar for this useful post.
|
on 08/05/2024(UTC), on 08/05/2024(UTC)
|
|
Rank: Newbie
Groups: Registered
Joined: 21/12/2023(UTC) Posts: 7 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
|
|
|
|
Rank: Advanced Member Groups: Registered, Advanced Member Joined: 13/01/2012(UTC) Posts: 2,678 Location: Italy Was thanked: 1364 time(s) in 892 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 |
|
|
|
Rank: Advanced Member Groups: Registered
Joined: 28/08/2014(UTC) Posts: 1,407 Was thanked: 857 time(s) in 543 post(s)
|
Originally Posted by: JonAReynolds ... 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 2 time(s).Best regards. Alvaro.
|
|
|
|
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.