MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Re: Hold and Equal

  • To: mathgroup at smc.vnet.net
  • Subject: [mg73913] Re: [mg73863] Re: Re: Hold and Equal
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Sat, 3 Mar 2007 00:58:16 -0500 (EST)
  • Organization: Mathematics & Statistics, Univ. of Mass./Amherst
  • References: <erufqm$s7j$1@smc.vnet.net> <200702280929.EAA24225@smc.vnet.net> <acbec1a40702280457r5cd8708at59e67331d62326f5@mail.gmail.com> <es6bt0$r9q$1@smc.vnet.net> <200703021132.GAA03599@smc.vnet.net>
  • Reply-to: murray at math.umass.edu

Your first suggestion, to use the nn->n replacement, and the second to 
use With, both allow me to do what I want nicely, with most of the work 
being encapsulated within formEquation.  Thank you!

The third method you suggest, using Map, is not sufficiently robust as 
to cover the case where the operation op to be applied by formEquation 
is something other than Identity.  For example:

   Map[formEquation[(a + b)^n, Expand] &, Range[2]]

albert wrote:
> Hi,
> 
>>    Attributes@formEquation=List@HoldFirst
>>    formEquation[expr_,op_]:=With[{result=op@expr},HoldForm[expr=result]]
>>
>>    Table[formEquation[Integrate[x^n, x], Identity], {n, 1, 2}]//InputForm
>> {HoldForm[Integrate[x^n, x] = x^2/2], HoldForm[Integrate[x^n, x] = x^3/3]}
>>
>> I used InputForm there so could copy as plain text from Mathematica to
>> here.  The problem is that both entries in the list have x^n on the left
>> side of the equations now.
> 
> I think now you are asking for quite much: You want the expression to be
> evaluated partially, that is n should be evaluated but not Integrate. I
> think the only way to achieve this is to tell mathematica which parts you
> want to be evaluated, the following should work:
> 
> Table[formEquation[Integrate[x^nn,x],Identity]/.nn->n,{n,1,2}]
> 
> or:
> 
> Table[With[{n=n},formEquation[Integrate[x^n,x],Identity]],{n,1,2}]
> 
> Of course one could argue that Table should be implemented in such a way,
> that n will always be inserted in the "evaluted" form since the unevaluated
> n doesn't look very usefull. This would be possible, and as an exercise to
> learn the details about evaluation you might want to write a myTable that
> behaves like that, but probably there were good reasons why Table behaves
> as it does.
> 
> Using different constructs than Table, you could achieve the same results
> without having even more trouble with evaluation, e.g.:
> 
> Map[formEquation[Integrate[x^#,x],Identity]&,Range[2]]
> 
> 
> hth, 
> 
> albert
> 
> 

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


  • Prev by Date: RE: ReadList and columns
  • Next by Date: Re: Re: Hold and Equal
  • Previous by thread: Re: Re: Hold and Equal
  • Next by thread: Re: Re: Hold and Equal