Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: Re: Help with output form?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg60953] Re: [mg60925] Re: [mg60902] Help with output form?
  • From: Chris Chiasson <chris.chiasson at gmail.com>
  • Date: Wed, 5 Oct 2005 02:27:53 -0400 (EDT)
  • References: <200510030806.EAA00162@smc.vnet.net> <200510040524.BAA17881@smc.vnet.net>
  • Reply-to: Chris Chiasson <chris.chiasson at gmail.com>
  • Sender: owner-wri-mathgroup at wolfram.com

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


  • Prev by Date: Re: partitioning a string
  • Next by Date: Re: Visualization site updates
  • Previous by thread: Re: Help with output form?
  • Next by thread: Re: Help with output form?