Re: Re: Need a new type of Hold
- To: mathgroup at smc.vnet.net
- Subject: [mg7599] Re: [mg7538] Re: Need a new type of Hold
- From: daiyanh at mindspring.com (Daitaro Hagihara)
- Date: Thu, 19 Jun 1997 03:14:02 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
essage-Id: <v01540b01afc9549664e3 at [38.11.35.28]> >Ersek_Ted%PAX1A at mr.nawcad.navy.mil wrote: >> >> I could use a new type of Hold that is similar to HoldForm. >> The difference is I don't want the new Hold to show up in >> the FullForm. >> >> Lets call this new feature HoldTemporary. >> The following shows the way I want it to work. >> >> (*-----------------------------------------*) >> >> In[1]:= foo=HoldTemporary[z+2+d+a+3] >> Out[1]= z+2+d+a+3 >> >> In[2]:= foo-d+4 >> Out[2]= 9+a+z >> > >At first I thought that what you really want to do is define your >own addition operator, but then I decided thathat you are trying to >do is fundamentally inconsistent with the way >Mathematica works (I won't say "impossible", since everytime I say >that some smart-aleck figures out a way to do it.) > >Here's why: >in your first output, the 2 and the 3 don't combine. Yet, in the second >output, they have combined with the 9. What should happen if I type >"foo + b"? Should the result be "z+2+d+a+3+b" or should it be >"5+a+d+a+b". Or should it be something else? The fact is, if you want >the 2 and 3 to combine, then they should have combined in the first >output; if you want the order of the terms to be strictly maintained, >then the second output should have been "z+2+d+a+7" (let's assume that >it's okay to combine adjacent terms). One or the other, you can't >have it both ways. > >By the way, if it's a non-associative addition operator that you're >after, I don't recommend removing the Orderless attribute from Plus, >or you'll break a lot of other things. > >-- > Dave Wagner > Principia Consulting > http://www.princon.com/princon/ > Voice: (500) PRN-CPIA or (303) 258-9178 > Fax: (303) 258-3859 Hi, With all due respect, the question is quite legitimate and has more to do with semantics rather than mathematics. The case in point: consider the following: NIntegrate[1/Sqrt[Abs[x]],{x,-1000,1000}]. Mathematica outputs something that is an intermediate step (the input expression itself in this case) without evaluating it (or, more precisely, after Mma determines that the problem cannot be solved in a standard way). You can access its InputForm, FullForm, etc., just like any other regular output expression. But here the output itself is held without any Hold-related head. There are many other similar examples where their outputs are truly intermediate steps. It seems that there is no way, as far as I can tell, that users can do such a trick without rewriting the whole thing (Mma, i.e.) from scratch and throwing in a switch or two. It's even somewhat surprising to see that, however mathematically correct Mma's answer is, Identity[2+3] gives 5 instead of 2+3 (Plus[2,3]) despite deliberately setting the HoldAll attribute first. Though I face a more difficult problem of this kind, as far as Ted's particular question is concerned, there is a solution (sort of). First define: Literal[x_=HoldTemporary[y_]]^:=(x=y;HoldForm[y]); SetAttributes[HoldTemporary, HoldAll]; Then we get: In[300]:= foo=HoldTemporary[z+2+d+a+3] Out[300]= z + 2 + d + a + 3 In[301]:= foo-d+4 Out[301]= 9 + a + z Even so, Copy_Output_from_Above command doesn't work the way it's expected to, since Out[300] was already assigned an output with HoldForm head on it, unfortunately... --daiyan