Group Abstract Group Abstract

Message Boards Message Boards

0
|
3.4K Views
|
6 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Why assignment and delayed assignment to Sin[x]==0 are the same?

Posted 3 years ago
POSTED BY: Zhenyu Zeng
6 Replies
Posted 3 years ago
POSTED BY: Eric Rimbey
Posted 3 years ago

Okay. I am still confused but your answer helps me a lot.

POSTED BY: Zhenyu Zeng
Posted 3 years ago

If x is unassigned, then the expression Sin[x]==0 cannot be evaluated further. That's just a consequence of the rules for Sin and Equal. So, it turns out that the immediate evaluation of Sin[x]==0 effects no change to that expression. SetDelayed holds the right hand side unevaluated, but in this case, you get the same result whether you evaluate it or not. What Gianluca showed you illustrates the difference between Set and SetDelayed by making it possible to further evaluate Sin[x]==0 (by assigning a value to x). In otherwords, the fact that OwnValues[test] is the same in both cases is a coincidence due to the particular expression you chose to assign to test.

POSTED BY: Eric Rimbey
Posted 3 years ago

Hello, Thanks for your reply. Set function is evaluated as it shows the first time. So,

test=Sin[x]==0 

will assign Sin[x]==0 to test.

After this, I input x=pi, then I enter test the result are False.

As Set function is evaluated as it shows the first time. So, test should always be Sin[x]==0. Why after I inputing x=pi, test becomes False?

POSTED BY: Zhenyu Zeng

Try this to feel the difference:

x = Pi/2;
testImmediate = Sin[x] == 0;
testDelayed := Sin[x] == 0;
OwnValues[testImmediate]
OwnValues[testDelayed]
POSTED BY: Gianluca Gorni
Posted 3 years ago

But, may you tell me why they are the same in my two lines of code? Thanks.

POSTED BY: Zhenyu Zeng
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard