Issues with cases/if and error()

Issues with cases/if and error() - 消息

#1 已发布: 2023/6/21 09:48:32
Arie

Arie

94个赞,共285个帖子。

组: 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.62 KiB)已下载 1696 次。
variablesInConditions.pdf (88.21 KiB)已下载 921 次。
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
#2 已发布: 2023/6/21 10:21:42
Jean Giraud

Jean Giraud

983个赞,共6,866个帖子。

组: User

... BigError.PNG
#3 已发布: 2023/6/21 10:28:04
Arie

Arie

94个赞,共285个帖子。

组: 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 已发布: 2023/6/21 10:34:42
Jean Giraud

Jean Giraud

983个赞,共6,866个帖子。

组: 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 已发布: 2023/6/21 12:17:52
Jean Giraud

Jean Giraud

983个赞,共6,866个帖子。

组: User

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

variablesInConditions.sm (19.07 KiB)已下载 1721 次。
#6 已发布: 2023/6/21 14:07:36
Davide Carpi

Davide Carpi

1,443个赞,共2,936个帖子。

组: 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位用户喜欢此帖子
Arie 2023/6/21 14:22:00
#7 已发布: 2023/6/21 14:25:34
Arie

Arie

94个赞,共285个帖子。

组: 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.05 KiB)已下载 1689 次。
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
#8 已发布: 2023/6/23 10:33:15
Davide Carpi

Davide Carpi

1,443个赞,共2,936个帖子。

组: 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.58 KiB)已下载 1627 次。

(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位用户喜欢此帖子
Arie 2023/6/23 14:29:00
#9 已发布: 2023/6/23 14:03:50
Jean Giraud

Jean Giraud

983个赞,共6,866个帖子。

组: User

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

algo if_else.PNG
#10 已发布: 2023/6/23 15:07:13
Arie

Arie

94个赞,共285个帖子。

组: 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.58 KiB)已下载 1627 次。

(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位用户喜欢此帖子
Davide Carpi 2023/6/25 07:10:00
  • 有新帖
  • 无新帖