Search All of the Math Forum:

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

Topic: apply rule to Partition
Replies: 6   Last Post: Sep 21, 2013 4:34 AM

 Messages: [ Previous | Next ]
 Tomas Garza Hernandez Posts: 264 Registered: 4/15/05
Re: apply rule to Partition
Posted: Sep 21, 2013 4:21 AM

The error message doesn't prevent the evaluation from taking place. In this case it acts more as a warning. You may eliminate this warning using Quiet:
In[1]:= Partition[Range[10],m]/.m->3//QuietOut[2]= {{1,2,3},{4,5,6},{7,8,9}}
Alternatively you can write the ReplaceAll inside the brackets:
In[3]:= Partition[Range[10],m/.m->3]Out[3]= {{1,2,3},{4,5,6},{7,8,9}}
or you can use With:
In[5]:= With[{m=3},Partition[Range[10],m]]Out[5]= {{1,2,3},{4,5,6},{7,8,9}}
In all cases, m has to be a positive integer; otherwise the error actually prevents the evaluation. The definition of Partition doesn't make this explicit but I guess it goes without saying.
-Tomas

> From: jougraw@gmail.com
> Subject: apply rule to Partition
> To: mathgroup@smc.vnet.net
> Date: Fri, 20 Sep 2013 07:06:57 -0400
>
>
> I want to use rule to simplify my code. A piece of my code use Partition
> and I tried something like:
>
> Partition[Range[10], m] /. m -> 2
>
> It give me error message. My real code is in fact more complicated and this
> way failed to give me an output. How could I make it work?
> Thanks.
>
>

Date Subject Author
9/21/13 Tomas Garza Hernandez
9/21/13 Itai Seggev
9/21/13 Bob Hanlon
9/21/13 Ulrich Arndt
9/21/13 Ulrich Arndt