The 'if' logic appears to be backwards

The 'if' logic appears to be backwards - Messages

#1 Posted: 9/13/2009 4:02:39 AM
mar

mar

0 likes in 13 posts.

Group: User

x:=0
if x=0
y:=0
else
y:=1

y=1 (should be 0)


x:=1
(same conditional above)
y=0 (should be 1)
#2 Posted: 9/13/2009 7:24:08 AM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

Hello mar,
[LIVE width=170 height=282]http://smath.info/live/?file=631[/LIVE]
You must have done something wrong. It seems Ok.

Regards,
radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#3 Posted: 9/13/2009 11:42:14 AM
mar

mar

0 likes in 13 posts.

Group: User

I just re-tested using both my example & your example and I still get the wrong answer for both. I have ver 0.85 build 3531 installed under winXP SP3.

I also tried to test under the live web version but could not figure out how to add the 'if' conditional since the selection list over on the right does not seem to contain the conditional functions like the installed version.

By the way how are you getting smath pages pasted into the forum?

Update:
Ok it looks like I have issolated my problem. When I entered the conditional in the 'if' stmt I used the stnd '=' key instead of the actual boolean test condition '=' from the right side panel. They both look the same other than the fact that the boolean version appears in bold type. Any reason why smath did not automatically take and convert my stnd '=' into into a boolean test conditional '=' given the context in which it was entered?
#4 Posted: 9/13/2009 12:15:22 PM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

Hello mar,
Wrote

I just re-tested using both my example & your example and I still get the wrong answer for both. I have ver 0.85 build 3531 installed under winXP SP3.

Could you send the *.sm file to me, and will see. My email is omorr@uns.ac.rs
Wrote


I also tried to test under the live web version but could not figure out how to add the 'if' conditional since the selection list over on the right does not seem to contain the conditional functions like the installed version.


There are some restrictions about "Live" version. You can make a *.sm file on your computer and choose the "Upload" option in "Live" SMath from the lower right corner (easyer and faster). After the file has been uploaded, you can get the LIVE link - lower right corner. This link put (copy/paste) into your post and you will get the same as I did.
Wrote


By the way how are you getting smath pages pasted into the forum?


Yuo can have pictures and files into this forum, but you have to provide the links for them. Try to "Quote" some of the posts and see the way. You can upload the files on some free upload file services and provide the adress for them "http://...". There is also an upload SMath server but it is in Russian only (not translated to English yet).

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#5 Posted: 9/13/2009 12:21:28 PM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

Hello mar,
Wrote

Update:
Ok it looks like I have issolated my problem. When I entered the conditional in the 'if' stmt I used the stnd '=' key instead of the actual boolean test condition '=' from the right side panel. They both look the same other than the fact that the boolean version appears in bold type. Any reason why smath did not automatically take and convert my stnd '=' into into a boolean test conditional '=' given the context in which it was entered?


It is a common mistake. I do not believe it could be possible to convert stnd '=' into a boolean test conditional '=' (shortcut is CTRL+=). You have to take care of this.

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#6 Posted: 9/13/2009 12:40:27 PM
mar

mar

0 likes in 13 posts.

Group: User

If smath can not auto translate the stnd '=' into a valid boolean test cond '=' than maybe it could flag the fact that the entire conditional arg does not contain a vaild boolean test condition?
#7 Posted: 9/13/2009 12:45:16 PM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

Wrote

If smath can not auto translate the stnd '=' into a valid boolean test cond '=' than maybe it could flag the fact that the entire conditional arg does not contain a vaild boolean test condition?


Yes, you might be right. I am sure that the SMath author Andrey will answer this.

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#8 Posted: 9/13/2009 8:16:25 PM
Andrey Ivashov

Andrey Ivashov

2271 likes in 3734 posts.

Group: Super Administrator

mar, this is impossible to implement auto conversion of the 'equal to' operator. Unfortunately.
But, please, tell me, how you could write not boolean 'equal to' into the condition of if function? I can't find the way.

omorr, thank you!
#9 Posted: 9/14/2009 6:06:31 AM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

Wrote

mar, this is impossible to implement auto conversion of the 'equal to' operator. Unfortunately.
But, please, tell me, how you could write not boolean 'equal to' into the condition of if function? I can't find the way.

omorr, thank you!


You are welcome,

I'll comment this, if you do not mind. Actually, it is possible. The error will be issued

but you can continue. After the first expression below if, the equal sign will shift to the right

and finally


Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#10 Posted: 9/14/2009 8:33:24 AM
Greg Locock

Greg Locock

0 likes in 53 posts.

Group: User

A change in syntax might be to use == for boolean test =, while keeping := for assignment=

I'm surprised it can't figure out which is meant from context after an 'if' keyword
#11 Posted: 9/14/2009 11:55:36 AM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

Hello Greg,

I think this is a bug - kind of. Actually, "if" is the only tool from Programming palette which will return a value (I think). For instance (Pay attention on equal to signs)
[MATH]if(1≡1;5;6)=5[/MATH]
or
[MATH]if(1≡0;5;6)=6[/MATH]
or
[MATH]x←0[/MATH]
[MATH]a←if(x≡0;10;20)[/MATH]
[MATH]a=10[/MATH]

There is the way it works. I suppose something goes wrong and should be checked out here.

[MATH]if(x;y←9;z←8)=90[/MATH]

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#12 Posted: 1/19/2017 3:32:52 AM
Evgenij

Evgenij

1 likes in 8 posts.

Group: User

By the way
Impossible to assign to a function different values according conditions.
An example in the cloud

Or how it would by correct?
#13 Posted: 1/19/2017 10:50:59 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

By the way
Impossible to assign to a function different values according conditions.
An example in the cloud

Or how it would by correct?



Please: attach your request in a work sheet.

#14 Posted: 1/19/2017 1:00:56 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

An example in the cloud



Can't find the file in cloud.

Generally, conditions must be completely specified [Integrate Discontinuous].
Odd cases happen one of the condition must not be completely specified.
Success or failure is the sole guide. Each case exemplified in the attached.

Jean

Integrate Discontinuous.sm (22 KiB) downloaded 60 time(s).

Spline De Boor [Colibri].sm (32 KiB) downloaded 53 time(s).

#15 Posted: 1/19/2017 1:24:01 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

Generally, conditions must be completely specified [Integrate Discontinuous].



... This example is constructed on Davide "cases".
The numerical integrator works with "cases".
Numerical integrator does NOT "if/else"
"cases" is needed with 'convolution stuff'

Cheers

Integrate Discontinuous [UN].sm (18 KiB) downloaded 49 time(s).
#16 Posted: 1/19/2017 2:05:38 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

"cases" is needed with 'convolution stuff'



... here is the convolution "cases" example:

Convolution RC 6179.sm (13 KiB) downloaded 55 time(s).

  • New Posts New Posts
  • No New Posts No New Posts