Issues with cases/if and error()

Issues with cases/if and error() - Сообщения

#1 Опубликовано: 21.06.2023 09:48:32
Arie

Arie

93 сообщений из 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 КиБ) скачан 75 раз(а).
variablesInConditions.pdf (88 КиБ) скачан 78 раз(а).
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
#2 Опубликовано: 21.06.2023 10:21:42
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

... BigError.PNG
#3 Опубликовано: 21.06.2023 10:28:04
Arie

Arie

93 сообщений из 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 Опубликовано: 21.06.2023 10:34:42
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: 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 Опубликовано: 21.06.2023 12:17:52
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

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

variablesInConditions.sm (19 КиБ) скачан 67 раз(а).
#6 Опубликовано: 21.06.2023 14:07:36
Davide Carpi

Davide Carpi

1417 сообщений из 2873 понравились пользователям.

Группа: 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 21.06.2023 14:22:00
#7 Опубликовано: 21.06.2023 14:25:34
Arie

Arie

93 сообщений из 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 КиБ) скачан 66 раз(а).
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
#8 Опубликовано: 23.06.2023 10:33:15
Davide Carpi

Davide Carpi

1417 сообщений из 2873 понравились пользователям.

Группа: 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 КиБ) скачан 70 раз(а).

(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 23.06.2023 14:29:00
#9 Опубликовано: 23.06.2023 14:03:50
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

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

algo if_else.PNG
#10 Опубликовано: 23.06.2023 15:07:13
Arie

Arie

93 сообщений из 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 КиБ) скачан 70 раз(а).

(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 25.06.2023 07:10:00
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений