cases and replacement of variable by value

cases and replacement of variable by value - 消息

#1 已发布: 2018/4/29 15:11:33
Martin_B

Martin_B

22个赞,共84个帖子。

组: User

Shouldn't the variable A be replaced by its value 1 when 'cases' is used instead of 'if/else'?

cases.png
1位用户喜欢此帖子
sergio 2018/4/30 04:20:00
#2 已发布: 2018/4/29 20:02:30
Jean Giraud

Jean Giraud

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

组: User

Wrote

Shouldn't the variable A be replaced by its value 1 when 'cases' is used instead of 'if/else'?


Whatever is behind the scene, your project is ill posed..
Conditional statements must be intelligible for the numerical maths.

MarB.PNG
#3 已发布: 2018/4/30 03:43:25
Martin_B

Martin_B

22个赞,共84个帖子。

组: User

I really don't want to play silly games with you anymore.

I asked a simple question: "Why is the value of the canvas variable A not stored in the function, when cases is involved?"

Your answer has absolutely nothing to do with my question.

I have attended another screenshot to show the consequences of not storing the value.
cases behaves, as if there where a line operator.

cases2.png

cases.sm (9.81 KiB)已下载 1178 次。
#4 已发布: 2018/4/30 08:47:02
Jean Giraud

Jean Giraud

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

组: User

I notice one instance if/otherwise does not work vs if/else.
Reported, not acknowledged ... maybe more than one instance.

Silly.PNG
#5 已发布: 2018/4/30 10:17:16
Jean Giraud

Jean Giraud

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

组: User

... generally, if/else is more convenient in program.

Utilities Matrix Exclude Region.sm (35.43 KiB)已下载 1177 次。
#6 已发布: 2018/4/30 10:41:02
Jean Giraud

Jean Giraud

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

组: User

Wrote

.. generally, if/else is more convenient in program.



... refreshed

Utilities Matrix Exclude Region.sm (41.01 KiB)已下载 1143 次。

#7 已发布: 2018/4/30 11:20:30
Jean Giraud

Jean Giraud

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

组: User

... ill posed code don't speak, rather crash the project.
Glance for De Boor in Samples,,, will be pleased to re-post.

Intelligible.PNG
#8 已发布: 2018/4/30 15:12:40
Arie

Arie

94个赞,共285个帖子。

组: User

引用

Shouldn't the variable A be replaced by its value 1 when 'cases' is used instead of 'if/else'?



Davide can answer this for certain. However, I would imagine that it should not. Since cases() function is kind of like a wrapper for nested if() statements, I imagine that it stays completely symbolic until evaluated numerically.

This is just a guess. Otherwise I would imagine that when you evaluated a cases() statement symbolically you would see the nested if() instead.
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
#9 已发布: 2018/4/30 16:23:02
Martin_B

Martin_B

22个赞,共84个帖子。

组: User

Wrote


... However, I would imagine that it should not. Since cases() function is kind of like a wrapper for nested if() statements, I imagine that it stays completely symbolic until evaluated numerically.

This is just a guess. Otherwise I would imagine that when you evaluated a cases() statement symbolically you would see the nested if() instead.



The two expressions in the screenshot in my first post are evaluated symbolically.
I think I can remember that in the past when "hovering the mouse" it was was dissolved in a chain (product) of boolean expressions, without using if/else.
#10 已发布: 2018/4/30 16:30:39
Arie

Arie

94个赞,共285个帖子。

组: User

Wrote


I think I can remember that in the past when "hovering the mouse" it was was dissolved in a chain (product) of boolean expressions, without using if/else.



Yes, It looks like that may have changed about two years ago according to this post: https://en.smath.info/forum/yaf_postsm35489_Custom-Functions-plugin.aspx#post35489

Which leads me to believe the cases() functions worked different depending on the optimization.

You can see source code here: https://smath.info:8443/!/#public/view/head/plugins/CustomFunctions/SMathFunctions/Programming/cases.cs

I'm not well versed enough in plugin creation to know how this is handled with different optimizations.
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
#11 已发布: 2018/4/30 16:40:48
Arie

Arie

94个赞,共285个帖子。

组: User

I suppose what it comes down to is how input variables are passed to a function defined in a plugin and when they are evaluated w.r.t. the different optimization options.
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
#12 已发布: 2018/4/30 17:05:02
Jean Giraud

Jean Giraud

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

组: User

Wrote

The two expressions in the screenshot in my first post are evaluated symbolically.



Can't be evaluated otherwise => nothing is defined/assigned,
thus literal evaluation ... try this

ifOtherwise.PNG



Maybe you missed my other point about appropriate condition [De Boor]
You have that in much simpler instances, not visible and falsifying project.
#13 已发布: 2018/4/30 17:28:50
Martin_B

Martin_B

22个赞,共84个帖子。

组: User

The values of a, b and q(x) are not stored in f, as you can see in the following screenshot.
cases3.png

And by assigning f to f they are!
And that seems to me like a kind of invisible line operator, because it behaves like one.

cases4.png
#14 已发布: 2018/4/30 17:43:56
Ruben Sidranski

Ruben Sidranski

17个赞,共465个帖子。

组: User

Have you tried programing it? Use line in lieu of the system of values or equations bracket?
#15 已发布: 2018/4/30 18:11:39
CBG

CBG

78个赞,共312个帖子。

组: User

by--->MarB

引用

Shouldn't the variable A be replaced by its value 1 when 'cases' is used instead of 'if/else'?




I do not understand. The cases function works perfectly.



Cases.png

cases_ok.sm (4.6 KiB)已下载 1167 次。


Best Regards

Carlos
#16 已发布: 2018/4/30 18:46:22
Jean Giraud

Jean Giraud

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

组: User

The all thing is about what comes from conditional.
For instance: the integration operator needs an analytical integrand.
From if/else, integrand is not scalar vs if/Otherwise.
Simple things turn nightmare ... many same in Mathcad.

Plots are same but not integration.

intDiscontinuous.PNG

#17 已发布: 2018/4/30 20:14:58
Jean Giraud

Jean Giraud

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

组: User

Wrote

From if/else, integrand is not scalar vs if/Otherwise.



... for this particular integration example, it is necessary and sufficeinet
to transform the domain of if/else [ infinitesimal ...] in scalar domain.
Here, we have it already done in term of integration.

Integrate Discontinuous [Nuance].sm (13.02 KiB)已下载 1007 次。
#18 已发布: 2018/5/1 10:04:25
Arie

Arie

94个赞,共285个帖子。

组: User

Wrote


I do not understand. The cases function works perfectly.




The difference comes when the value of A changes after the definition of f(x) and g(x).

For g(x) the original definition of A:=1 remains. However, for f(x) the value of A changes.

Untitled.png
cases_ok_alyles.sm (5.57 KiB)已下载 1144 次。
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
#19 已发布: 2018/5/1 17:53:43
Arie

Arie

94个赞,共285个帖子。

组: User

引用

And by assigning f to f they are!
And that seems to me like a kind of invisible line operator, because it behaves like one.



So I believe I understand what is going on a little better.
I've attached the same .sm file as before only this time with break points. If you open the debugger window and step through you can see exactly what happens.
When f(x) is defined it sets f(x) equal to cases(a,xNote when g(x) is defined it will step through and evaluate the if() function and each individual input parameter (xThe cases() function within f(x) doesn't actually evaluate until it is called with f(0).
This is why, as you described earlier, if you set f(x):=f(x) you finally get the result that you want, because at this point it will finally evaluate cases(a,x
I'm not sure if this is a plugin issue or if this is just how SMath handles it's plugin interface.


cases_ok_alyles_with_breakpoints.sm (5.57 KiB)已下载 1162 次。
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
#20 已发布: 2018/5/1 18:51:59
Jean Giraud

Jean Giraud

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

组: User

Wrote

I'm not sure if this is a plugin issue or if this is just how SMath handles it's plugin interface.



This type of maths is universal and maybe centuries accepted,
and a rigorous rule since numerical computing machinery.

Just like this.

illPosed.PNG

  • 有新帖
  • 无新帖