The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: rookie code issue
Replies: 4   Last Post: Mar 21, 2013 12:55 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Murray Eisenberg

Posts: 2,105
Registered: 12/6/04
Re: rookie code issue
Posted: Mar 21, 2013 12:55 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

According to the reference page for Which:

If any of the Subscript[test, i] evaluated by Which give neither True nor False, then a Which object
containing these remaining elements is returned unevaluated.

So look at the following result:

Cos == Sin

You'll get back as output:

Cos == Sin

which is neither True nor False. On the other hand,

Cos === Sin (* using SameQ now *)

gives result False. Hence

m = Cos;
Which[m === Sin, 5, m === Cos, 2]

does give the result 2 that you wanted.

On Mar 20, 2013, at 4:22 AM, wrote:

> ...Why doesn't the following code return a 2?
> m = Cos;
> Which[m == Sin, 5, m == Cos, 2]

Murray Eisenberg
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2838 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.