The 'if' logic appears to be backwards

The 'if' logic appears to be backwards - 消息

#1 已发布: 2009/9/13 04:02:39
mar

mar

0个赞,共13个帖子。

组: 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 已发布: 2009/9/13 07:24:08
Radovan Omorjan

Radovan Omorjan

325个赞和1个踩,共2,052个帖子。

组: 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 已发布: 2009/9/13 11:42:14
mar

mar

0个赞,共13个帖子。

组: 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 已发布: 2009/9/13 12:15:22
Radovan Omorjan

Radovan Omorjan

325个赞和1个踩,共2,052个帖子。

组: 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 已发布: 2009/9/13 12:21:28
Radovan Omorjan

Radovan Omorjan

325个赞和1个踩,共2,052个帖子。

组: 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 已发布: 2009/9/13 12:40:27
mar

mar

0个赞,共13个帖子。

组: 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 已发布: 2009/9/13 12:45:16
Radovan Omorjan

Radovan Omorjan

325个赞和1个踩,共2,052个帖子。

组: 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 已发布: 2009/9/13 20:16:25
Andrey Ivashov

Andrey Ivashov

2,344个赞,共4,057个帖子。

组: 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 已发布: 2009/9/14 06:06:31
Radovan Omorjan

Radovan Omorjan

325个赞和1个踩,共2,052个帖子。

组: 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 已发布: 2009/9/14 08:33:24
Greg Locock

Greg Locock

0个赞,共53个帖子。

组: 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 已发布: 2009/9/14 11:55:36
Radovan Omorjan

Radovan Omorjan

325个赞和1个踩,共2,052个帖子。

组: 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 已发布: 2017/1/19 03:32:52
Evgenij

Evgenij

1个赞,共8个帖子。

组: 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 已发布: 2017/1/19 10:50:59
Jean Giraud

Jean Giraud

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

组: 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 已发布: 2017/1/19 13:00:56
Jean Giraud

Jean Giraud

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

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

Spline De Boor [Colibri].sm (32.46 KiB)已下载 1121 次。

#15 已发布: 2017/1/19 13:24:01
Jean Giraud

Jean Giraud

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

组: 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.95 KiB)已下载 1080 次。
#16 已发布: 2017/1/19 14:05:38
Jean Giraud

Jean Giraud

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

组: User

Wrote

"cases" is needed with 'convolution stuff'



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

Convolution RC 6179.sm (13.82 KiB)已下载 1332 次。

  • 有新帖
  • 无新帖