Issues with cases/if and error()

Issues with cases/if and error() - Messages

#1 Posted: 6/21/2023 9:48:32 AM
Arie

Arie

93 likes in 285 posts.

Group: User

I am having some strange issues with cases/if statements that contain variables in the condition in addition to error() function in the result.

The issue only arises when the if/cases statements are in a function that is passed into another function. See attached.
Any thoughts?

variablesInConditions.sm (14 KiB) downloaded 38 time(s).
variablesInConditions.pdf (88 KiB) downloaded 44 time(s).
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
#2 Posted: 6/21/2023 10:21:42 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

... BigError.PNG
#3 Posted: 6/21/2023 10:28:04 AM
Arie

Arie

93 likes in 285 posts.

Group: User

Wrote

... BigError.PNG



This is certainly a workaround. Something I could do and perform error handling at the next level.
I'm more curious is this is an actual bug or if I'm doing something incorrectly.
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
#4 Posted: 6/21/2023 10:34:42 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

I'm more curious is this is an actual bug or if I'm doing something incorrectly.


Your function of function complains about the code as bug.
Will come back ... time to seed bean !
#5 Posted: 6/21/2023 12:17:52 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

No more red, I don't understand the project.

variablesInConditions.sm (19 KiB) downloaded 29 time(s).
#6 Posted: 6/21/2023 2:07:36 PM
Davide Carpi

Davide Carpi

1416 likes in 2873 posts.

Group: Moderator

Hello, this is expected. By design because framework constraints, not by will, but it is the only way to have the function working in some contexts like inside integrals and such.

In case of numerical evaluation of the conditions, like in the if(...) function, the single cases are "sealed" from evalution up to when the conditions are actually evaluable. In cases(...) everything is always exposed to evaluation (and that's why you shouldn't use assignments inside the single cases). Hence, since error() is evaluated, it throws the error message.
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 users liked this post
Arie 6/21/2023 2:22:00 PM
#7 Posted: 6/21/2023 2:25:34 PM
Arie

Arie

93 likes in 285 posts.

Group: User

Wrote

Hello, this is expected. By design because framework constraints, not by will, but it is the only way to have the function working in some contexts like inside integrals and such.

In case of numerical evaluation of the conditions, like in the if(...) function, the single cases are "sealed" from evalution up to when the conditions are actually evaluable. In cases(...) everything is always exposed to evaluation (and that's why you shouldn't use assignments inside the single cases). Hence, since error() is evaluated, it throws the error message.



Hi Davide,
Thanks for the explanation. I think I understand why cases(...) will not work. But I still receive a strange error when using if(...). Is this also expected?

Untitled.png
variablesInConditions.sm (15 KiB) downloaded 32 time(s).
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
#8 Posted: 6/23/2023 10:33:15 AM
Davide Carpi

Davide Carpi

1416 likes in 2873 posts.

Group: Moderator

Hi, sorry the late answer!

Wrote

hanks for the explanation. I think I understand why cases(...) will not work. But I still receive a strange error when using if(...). Is this also expected?



Yes, altough I'm not sure if could be improved by Andrey somehow.

With some slight modifications on the names, you can see more clearly that the error is generated on the F1(2) preprocessing. Here x is passed as input to the first argument and if() fires the error.

2023-06-23 14_00_12-SMath Solver - [variablesInConditions_alt1.sm].png

The only alternative that comes to my mind right now is the one below. You have to pass the function name rather than the function itself.

It is a workaround, and if you pass it as a variable, the variable itself must be not defined.

2023-06-23 15_20_28-SMath Solver - [variablesInConditions_alt1.sm_].png

variablesInConditions_alt1.sm (11 KiB) downloaded 40 time(s).

(The attachment has a more complicated function just to make the string input independant from localization settings)
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 users liked this post
Arie 6/23/2023 2:29:00 PM
#9 Posted: 6/23/2023 2:03:50 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

More instances of if/otherwise failed in program.
if/otherwise does not belong to the Smath kernel.

algo if_else.PNG
#10 Posted: 6/23/2023 3:07:13 PM
Arie

Arie

93 likes in 285 posts.

Group: User

Wrote

Hi, sorry the late answer!

Wrote

hanks for the explanation. I think I understand why cases(...) will not work. But I still receive a strange error when using if(...). Is this also expected?



Yes, altough I'm not sure if could be improved by Andrey somehow.

With some slight modifications on the names, you can see more clearly that the error is generated on the F1(2) preprocessing. Here x is passed as input to the first argument and if() fires the error.

2023-06-23 14_00_12-SMath Solver - [variablesInConditions_alt1.sm].png

The only alternative that comes to my mind right now is the one below. You have to pass the function name rather than the function itself.

It is a workaround, and if you pass it as a variable, the variable itself must be not defined.

2023-06-23 15_20_28-SMath Solver - [variablesInConditions_alt1.sm_].png

variablesInConditions_alt1.sm (11 KiB) downloaded 40 time(s).

(The attachment has a more complicated function just to make the string input independant from localization settings)



Thanks Davide!
This workaround will suffice for me.
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
1 users liked this post
Davide Carpi 6/25/2023 7:10:00 AM
  • New Posts New Posts
  • No New Posts No New Posts