Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Simple pattern matching' topicStudent Support Forum > General > Archives > "Simple pattern matching"

Next Comment >Help | Reply To Topic
Author Comment/Response
Walter Snafu
03/25/11 10:53am

I'm trying to accomplish this replacement rule:

z^-n_ -> Cos[n]

but I can't get it to work.

However, it does work, if I remove the minus sign:

z^n_ -> Cos[n]

And it does work, if I set n to a specific value, such as 2:

z^-2 -> Cos[2]

In other words, the replacement rule is not working when the sign is negative and n is non-specific.

I see the cause of the problem when I look at the FullForm[] of the replacement rule. I'm sure there must be a work-around. How do I get it to work?

Thanks for your help.
(My first post.)

URL: ,

Subject (listing for 'Simple pattern matching')
Author Date Posted
Simple pattern matching Walter Snafu 03/25/11 10:53am
Re: Simple pattern matching Isaac 03/26/11 4:31pm
Re: Simple pattern matching yehuda ben-s... 03/26/11 10:56pm
Re: Simple pattern matching Peter Pein 03/27/11 06:45am
Re: Simple pattern matching Walter Snafu 04/04/11 1:57pm
Re: Re: Simple pattern matching Peter Pein 04/09/11 06:20am
Next Comment >Help | Reply To Topic