       Re: Re: Re: Re: Hold and Equal

• To: mathgroup at smc.vnet.net
• Subject: [mg73875] Re: [mg73804] Re: [mg73771] Re: [mg73747] Re: Hold and Equal
• From: "Chris Chiasson" <chris at chiasson.name>
• Date: Fri, 2 Mar 2007 06:39:04 -0500 (EST)
• References: <erufqm\$s7j\$1@smc.vnet.net> <200702271048.FAA24024@smc.vnet.net>

```Table[formEquation[Integrate[x^#,x],Identity]&@n,{n,1,2}]

The previous result happened because Table doesn't replace its
iterator in the first expression. It merely evaluates that expression
in an environment where the iterator is Set. (the HoldFirst attribute
of formEquation and HoldAll attribute of Hold don't help matters much,
either)

These commands should give an idea of what went on and how to fix it
(use Trace):

With[{n=1},formEquation[Integrate[x^n,x],Identity]]
Block[{n=1},formEquation[Integrate[x^n,x],Identity]]
Block[{n=1},formEquation[Integrate[x^#,x],Identity]&@n]
Block[{n=1},With[{blah=n},formEquation[Integrate[x^blah,x],Identity]]]

On 3/1/07, Murray Eisenberg <murray at math.umass.edu> wrote:
> Almost!  Look at this:
>
>    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.
>
>
> Chris Chiasson wrote:
> > In:= Attributes@formEquation=List@HoldFirst(*or one could just
> > supply Unevaluated arguments*)
> >
> > Out= {HoldFirst}
> >
> > In:=
> > formEquation[expr_,op_]:=With[{result=op@expr},HoldForm[expr=result]]
> >
> > In:= formEquation[Integrate[x^2,x],Identity]
> >
> > Out= \[Integral]x^2\[DifferentialD]x=x^3/3
> >
> > On 2/28/07, Murray Eisenberg <murray at math.umass.edu> wrote:
> >> Aha!  I believe this approach _almost_ allows me to accomplish what I
> >> was REALLY trying to accomplish.  It certainly works in the example I
> >> gave.  If I encapsulate this in a function...
> >>
> >>    formEquation[expr_, op_]:= HoldForm[expr=z]/.z\[Rule]op[expr]
> >>
> >> ... then
> >>
> >>    formEquation[(a+b)^2,Identity]
> >>
> >> will produce exactly what I want.
> >>
> >> However, if I try something like the example I was really after (which I
> >> didn't mention in my original post, since I gave something simpler), it
> >> works in the direct version...
> >>
> >>    HoldForm[Integrate[x^2,x] = z] /. z\[Rule]Integrate[x^2,x]
> >>
> >> but not with the encapsulating function:
> >>
> >>    formEquation[Integrate[x^2, x], Identity]
> >>
> >> The latter produces the equation
> >>
> >>    x^3/3 = x^3/2
> >>
> >> whereas I want the left-hand side to be the unevaluated integral
> >> expression.
> >>
> >> You can tell I'm struggling with Hold!  (One of the "last frontiers" in
> >> my Mathematica education.)
> >>
> >> bghiggins at ucdavis.edu wrote:
> >> > Murray,
> >> >
> >> > Try this
> >> >
> >> >
> >> > HoldForm[(a + b)^2 = z] /. z -> Expand[(a + b)^2]
> >> >
> >> >
> >> > (a + b)^2 = a^2 + 2*a*b + b^2
> >> >
> >> > Cheers,
> >> >
> >> > Brian
> >> >
> >> >
> >> >
> >> > On Feb 26, 3:20 am, Murray Eisenberg <mur... at math.umass.edu> wrote:
> >> >> How can I produce in an Output cell (under program control) an
> >> >> expression like the following,
> >> >>
> >> >>    (a+b)^2 = a^2+ 2 a b + b^2
> >> >>
> >> >> where instead of the usual Equal (==) I get a Set (=), as in
> >> >> math notation?  I want to input the unexpanded (a+b)^2 and have the
> >> >> expansion done automatically.
> >> >>
> >> >> Of course, I can try something like the following:
> >> >>
> >> >>    (a+b)^2 == Expand[(a+b)^2])
> >> >>
> >> >> So how do I convert the == to =?  Of course
> >> >>
> >> >>    ((a + b)^2 == Expand[(a + b)^2]) /. Equal -> Set
> >> >>
> >> >> gives a Set::write error.  And
> >> >>
> >> >>    (Hold[(a + b)^2 == Expand[(a + b)^2]]) /. Equal -> Set
> >> >>
> >> >> doesn't actually evaluate the Expand part and leaves the "Hold"
> >> wrapper.
> >> >>
> >> >> --
> >> >> Murray Eisenberg                     mur... 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
> >> >
> >> >
> >> >
> >>
> >> --
> >> 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
> >>
> >>
> >
> >
>
> --
> 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
>
>

--
http://chris.chiasson.name/

```

• Prev by Date: Re: Limit of Floor function
• Next by Date: Re: Re: Re: Hold and Equal
• Previous by thread: Re: Re: Re: Hold and Equal
• Next by thread: Re: Re: Re: Hold and Equal