Re: Re: Help with output form?

*To*: mathgroup at smc.vnet.net*Subject*: [mg60952] Re: [mg60925] Re: [mg60902] Help with output form?*From*: Andrzej Kozlowski <andrzej at yhc.att.ne.jp>*Date*: Wed, 5 Oct 2005 02:27:52 -0400 (EDT)*Reply-to*: Andrzej Kozlowski <andrzej at akikoz.net>*Sender*: owner-wri-mathgroup at wolfram.com

It seems to me that the key issue here is the meaning of "output the lhs" . If by output one really means "Output" in the strict sense (which in particular implies it should be possible to use it as input for another evaluation) then one indeed needs all these tricks with Hold, HoldForm etc. If on the other hand one is satisfied with just having something printed out than probably the simplest way is: y = Expand[(a + b)^2]; Information[y] "Global`y" y = a^2 + 2*a*b + b^2 Andrzej Kozlowski On 4 Oct 2005, at 21:32, Chris Chiasson wrote: > I used to try stuff like this. > If you are careful, you could get away with the following: > > input[1]=lhs[1]==rhs[1] > input[1]/.Equal->Set; > > However, you must then be careful to not use this trick with lhs[1] > again, because it would be automatically evaluated. > > Following off of what Andrzej started, try: > y=10 > Rest[HoldForm@@First@Take[DownValues[In],{-2,-2}]] > > This second approach could even be extended to show all previous > inputs. > > On 10/4/05, Andrzej Kozlowski <akoz at mimuw.edu.pl> wrote: > >> >> On 3 Oct 2005, at 17:06, aufgang wrote: >> >> >>> I am struggling to get mathematica to output certain expressions the >>> way I'd like and i'm wondering if anyone could help me. >>> >>> normally, when you input an expression using the Set operator (=), >>> mathematica evaluates the expression, assigns the rhs to the lhs and >>> returns the evaluated rhs (eg. y=Expand[(a+b)^2] -> a^2+2 a b >>> +b^2) >>> >>> what I would like to do is coax mathematica to output the lhs as >>> wel as >>> the evaluated rhs (ie. y=Expand[(a+b)^2] -> y=a^2+2 a b +b^2). >>> >>> I want the rhs to be evaluated like normal, and the value of the >>> lhs to >>> be set to rhs, so so Hold, HoldForm, etc wont work (they keep the >>> lhs >>> but wont evaluate the rhs and the value isnt actually set) and I >>> know I >>> dont want to be using == instead of =. i just want the lhs to >>> appear >>> in the output. >>> >>> the reson I want to do this is because I am calling the Mathematica >>> Kernel from a web app and I want to display this output format to >>> the >>> users. >>> >>> I suspect I could do this somehow by redefining Set or something >>> but i >>> can't seem to figure that out. >>> >>> Thanks for any help. >>> >>> >>> >> >> >> What you are asking for is strictly speaking impossible, since if y >> has been assigned a^2+2 a b +b^2 as its value than whenever y is >> evaluated it will be replaced by a^2+2 a b +b^2. There is no way to >> do this without using some form of Hold. Probably the easiest >> approach is: >> >> >> y = Expand[(a + b)^2]; OwnValues[y][[1]] >> >> >> HoldPattern[y] :> a^2 + 2*b*a + b^2 >> >> >> If you do not want to see HoldPattern in your output you can replace >> it by HoldForm: >> >> >> y = Expand[(a + b)^2]; OwnValues[y][[1]] /. >> {HoldPattern -> HoldForm} >> >> >> HoldForm[y] :> a^2 + 2*b*a + b^2 >> >> In StandardForm or TraditionalForm you won't see the HoldForm. If you >> still do not like :> you cannot simply replace it by = (Set) because >> then Mathematica will attempt to set HoldForm[y] to the RHS (can't be >> done without unprotecting HoldForm) and in any case the output again >> would be just the RHS. If you really insist on having Set in your >> output you have to wrap everything in HoldForm, e.g. >> >> >> Block[{x}, y = Expand[(a + b)^2]; HoldForm[y -> x] /. {x -> y, Rule - >> >>> Set}] >>> >> >> HoldForm[y = a^2 + 2*b*a + b^2] >> >> >> Andrzej Kozlowski >> >> >> > > > -- > Chris Chiasson > http://chrischiasson.com/contact/chris_chiasson >

**Re: Visualization site updates**

**Re: "Mathematica in Education and Research"**

**Re: Help with output form?**

**Re: Help with output form?**