Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


2 Pages12>
Options
Go to last post Go to first unread
Offline MarB  
#1 Posted : 29 April 2018 21:11:33(UTC)
MarB


Rank: Advanced Member

Groups: Registered
Joined: 21/10/2016(UTC)
Posts: 84

Was thanked: 21 time(s) in 17 post(s)
Shouldn't the variable A be replaced by its value 1 when 'cases' is used instead of 'if/else'?

cases.png
thanks 1 user thanked MarB for this useful post.
on 30/04/2018(UTC)

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline Jean Giraud  
#2 Posted : 30 April 2018 02:02:30(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: MarB Go to Quoted Post
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
Offline MarB  
#3 Posted : 30 April 2018 09:43:25(UTC)
MarB


Rank: Advanced Member

Groups: Registered
Joined: 21/10/2016(UTC)
Posts: 84

Was thanked: 21 time(s) in 17 post(s)
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 (10kb) downloaded 24 time(s).
Offline Jean Giraud  
#4 Posted : 30 April 2018 14:47:02(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
I notice one instance if/otherwise does not work vs if/else.
Reported, not acknowledged ... maybe more than one instance.

Silly.PNG
Offline Jean Giraud  
#5 Posted : 30 April 2018 16:17:16(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
... generally, if/else is more convenient in program.

Utilities Matrix Exclude Region.sm (36kb) downloaded 21 time(s).
Offline Jean Giraud  
#6 Posted : 30 April 2018 16:41:02(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
.. generally, if/else is more convenient in program.


... refreshed

Utilities Matrix Exclude Region.sm (42kb) downloaded 20 time(s).

Offline Jean Giraud  
#7 Posted : 30 April 2018 17:20:30(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
... ill posed code don't speak, rather crash the project.
Glance for De Boor in Samples,,, will be pleased to re-post.

Intelligible.PNG
Offline alyles  
#8 Posted : 30 April 2018 21:12:40(UTC)
alyles


Rank: Advanced Member

Groups: Registered
Joined: 23/03/2016(UTC)
Posts: 276
United States

Was thanked: 91 time(s) in 57 post(s)
Quote:
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
Offline MarB  
#9 Posted : 30 April 2018 22:23:02(UTC)
MarB


Rank: Advanced Member

Groups: Registered
Joined: 21/10/2016(UTC)
Posts: 84

Was thanked: 21 time(s) in 17 post(s)
Originally Posted by: alyles Go to Quoted Post

... 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.
Offline alyles  
#10 Posted : 30 April 2018 22:30:39(UTC)
alyles


Rank: Advanced Member

Groups: Registered
Joined: 23/03/2016(UTC)
Posts: 276
United States

Was thanked: 91 time(s) in 57 post(s)
MarB 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/fo...ns-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
Offline alyles  
#11 Posted : 30 April 2018 22:40:48(UTC)
alyles


Rank: Advanced Member

Groups: Registered
Joined: 23/03/2016(UTC)
Posts: 276
United States

Was thanked: 91 time(s) in 57 post(s)
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
Offline Jean Giraud  
#12 Posted : 30 April 2018 23:05:02(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: MarB Go to Quoted Post
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.
Offline MarB  
#13 Posted : 30 April 2018 23:28:50(UTC)
MarB


Rank: Advanced Member

Groups: Registered
Joined: 21/10/2016(UTC)
Posts: 84

Was thanked: 21 time(s) in 17 post(s)
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
Offline ElSid  
#14 Posted : 30 April 2018 23:43:56(UTC)
ElSid


Rank: Advanced Member

Groups: Registered
Joined: 05/03/2009(UTC)
Posts: 433
Man
United States
Location: USA

Was thanked: 17 time(s) in 15 post(s)
Have you tried programing it? Use line in lieu of the system of values or equations bracket?
Offline CBG  
#15 Posted : 01 May 2018 00:11:39(UTC)
CBG


Rank: Advanced Member

Groups: Registered
Joined: 14/10/2015(UTC)
Posts: 308

Was thanked: 77 time(s) in 58 post(s)
by--->MarB

Quote:
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 (5kb) downloaded 17 time(s).


Best Regards

Carlos
Offline Jean Giraud  
#16 Posted : 01 May 2018 00:46:22(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
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

Offline Jean Giraud  
#17 Posted : 01 May 2018 02:14:58(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: Jean Giraud Go to Quoted Post
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 (14kb) downloaded 16 time(s).
Offline alyles  
#18 Posted : 01 May 2018 16:04:25(UTC)
alyles


Rank: Advanced Member

Groups: Registered
Joined: 23/03/2016(UTC)
Posts: 276
United States

Was thanked: 91 time(s) in 57 post(s)
Originally Posted by: CBG Go to Quoted Post

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 (6kb) downloaded 20 time(s).
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
Offline alyles  
#19 Posted : 01 May 2018 23:53:43(UTC)
alyles


Rank: Advanced Member

Groups: Registered
Joined: 23/03/2016(UTC)
Posts: 276
United States

Was thanked: 91 time(s) in 57 post(s)
Quote:
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,x<A,b ), which is essentially the function call of cases(). But it does not further evaluate cases() or or it's input variables.
Note when g(x) is defined it will step through and evaluate the if() function and each individual input parameter (x<A,a,b ).
The 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<A,b ).

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 (6kb) downloaded 19 time(s).
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
Offline Jean Giraud  
#20 Posted : 02 May 2018 00:51:59(UTC)
Jean Giraud

Rank: Guest

Groups: Registered
Joined: 04/07/2015(UTC)
Posts: 6,866
Canada

Was thanked: 981 time(s) in 809 post(s)
Originally Posted by: alyles Go to Quoted Post
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

Users browsing this topic
Guest
2 Pages12>
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.