Message Boards Message Boards

0
|
7150 Views
|
6 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Make conditional statement work in M10.0.2?

Posted 9 years ago

Hello,

I am following a YouTube Wolfram Language Fundamentals lecture. I cannot make the condition example at the link's time stamp work in Mathematica Home 10.0.2. The date of the YouTube lecture is Oct 28, 2014 and Mathematica 10.0.2 came out on Dec 15, 2014. Why doesn't this statement work?

{a, b, c} /. { c \[RightArrow] b, b \[RightArrow] a}

I get this error message:

ReplaceAll::reps: {c\[RightArrow]b,b\[RightArrow]a} is neither a list of replacement rules
nor a valid dispatch table, and so cannot be used for replacing. >>

I tried adding spaces, clearing variable names, exiting and re-entering Mathematica, using a new notebook, etc..., but nothing worked. Can someone tell me why the above statement does not work?

Thanks.

POSTED BY: Dan M
6 Replies

As a novice you should get a habit of looking in docs. There are many examples and you would understand the nature of error very quickly. Even syntax like /. can be looked up in docs:

enter image description here

POSTED BY: Sam Carrettie

Unfortunately, this behavior of the site is somewhat frequent... I mean delayed appearing of the comments.

Posted 9 years ago

Thanks for the help. I rewrote the statement and it worked. In the "Basic Math Assistant", a right arrow is both in the Calculator area and the Typesetting>Arrows areas. I used dash and greater than, "->", to write the statement.

POSTED BY: Dan M

Sorry. My reply is much later but your did not show up until after I posted. Sorry.

Cheers,

Marco

POSTED BY: Marco Thiel

Hi Dan,

your problem is that you used RightArrow, whereas you should use Rule. This is a bit difficult to see in the output:

enter image description here

So it looks the same but it is not. The following lines show what is going on:

{a, b, c} /. {c \[RightArrow] b, b \[RightArrow] a} // Hold // FullForm
{a, b, c} /. {c -> b, b -> a} // Hold // FullForm

The sceenshot shows the output.

enter image description here

So the issue is that both RightArrow and Rule are rendered in the same way. If you type it in as -> it should work.

Cheers,

Marco

POSTED BY: Marco Thiel

It seems that you copied the code and the "->" (\[Rule]) was interpreted as the \[RightArrow]. So the following code must work:

In[5]:= {a, b, c} /. {c -> b, b -> a}

Out[5]= {a, a, b}
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract