[Date Index]
[Thread Index]
[Author Index]
Re: Need a new type of Hold
*To*: mathgroup at smc.vnet.net
*Subject*: [mg7626] Re: Need a new type of Hold
*From*: daiyanh at mindspring.com (Daitaro Hagihara)
*Date*: Fri, 20 Jun 1997 16:15:59 -0400 (EDT)
*Organization*: MindSpring Enterprises
*Sender*: owner-wri-mathgroup at wolfram.com
In article <5nqses$l6m at smc.vnet.net>, "David B. Wagner"
<dbwagner at princon.com> wrote:
> 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
My second reply though I still don't see my first...
Ted's problem is partially solved (but not mine). However, it breaks
SequenceForm, and auto expansion is inhibited when (1) there is any
HoldTemporary form within the expression and when (2) the temporarily
held expression is Print'ed.
mypre[x_]:=If[Position[Hold[x],HoldTemporary]=!={},
(Hold[x]/.HoldTemporary->SequenceForm)[[1]],
Hold[x/.SequenceForm->Identity][[1]]];
SetAttributes[mypre,HoldFirst];
SetAttributes[HoldTemporary,HoldFirst];
SetAttributes[SequenceForm,HoldFirst];
$Pre=mypre;
The good news:
In[12]:=
foo=-5^2+HoldTemporary[2^2+3^2]+HoldTemporary[a+5^2]
Out[12]=
2 2 2
-25 + 2 + 3 + a + 5
and
In[13]:=
(foo-a)^2
Out[13]=
169
But the devil is still with us...
In[14]:=
foo-HoldTemporary[a]
Out[14]=
2 2 2
-25 + 2 + 3 + a + 5 - a
and...
In[15]:=
Print[foo]
2 2 2
-25 + 2 + 3 + a + 5
Perhaps the most distressing part of all is the breaking of SequenceForm
since I was unable to define my own output form, which partially stems
from my ignorance. I wonder if the solution here works on v.3 as the
observed behavior of SequenceForm is different from the expected one.
--daiyan
Prev by Date:
**Re: Errors in Jacobian Elliptic Functions**
Next by Date:
**wri responds to font problems (long)**
Previous by thread:
**Re: Re: Need a new type of Hold**
Next by thread:
**Unfinished machine arithmatic**
| |