Search All of the Math Forum:

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

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

Topic: Replace, test question
Replies: 6   Last Post: Jul 20, 2011 6:01 AM

 Messages: [ Previous | Next ]
 PA32R Posts: 4 Registered: 7/18/11
Re: Replace, test question
Posted: Jul 20, 2011 6:01 AM

On Jul 19, 4:12 am, Yves Klett <yves.kl...@googlemail.com> wrote:
> Hi,
>
> you need to supply x as argument to PrimeQ... alternatively use PatternTest:
>
> {58, 61, 15, 66, 10, 2, 24, 81, 45, 84} /. x_ /; PrimeQ[x] -> P
>
> {58, P, 15, 66, 10, P, 24, 81, 45, 84}
>
> {58, 61, 15, 66, 10, 2, 24, 81, 45, 84} /. x_?PrimeQ -> P
>
> {58, P, 15, 66, 10, P, 24, 81, 45, 84}
>
> Regards,
> Yves
>
> Am 18.07.2011 12:15, schriebPA32R:
>
>
>
>
>
>
>

> > I'm very new to Mathematica and trying to work my way through it. I
> > don't understand why:
> > {58, 61, 15, 66, 10, 2, 24, 81, 45, 84} /. x_ /; PrimeQ -> P
> > returns:
> > {58, 61, 15, 66, 10, 2, 24, 81, 45, 84}

>
> > I would expect it to take the list, replace everything in the list
> > that matches any pattern and passes the PrimeQ test, i.e., is prime,
> > with P to yield:
> > {58, P, 15, 66, 10, P, 14, 81, 45, 84}

>
> > Can someone explain my misunderstanding?
>
> > Thanks.

Thanks everyone, I got it done. The assistance is much appreciated.

Date Subject Author
7/18/11 PA32R
7/19/11 Bob Hanlon
7/19/11 Peter Breitfeld
7/19/11 Bill Rowe
7/19/11 oleksandr_rasputinov@hmamail.com
7/19/11 Yves Klett
7/20/11 PA32R