MathGroup Archive 2008

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

Search the Archive

Re: How to print TraditionalForm without evaluation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg92641] Re: How to print TraditionalForm without evaluation
  • From: David Bailey <dave at Remove_Thisdbailey.co.uk>
  • Date: Thu, 9 Oct 2008 06:36:21 -0400 (EDT)
  • References: <gci1sm$iv$1@smc.vnet.net>

Serych Jakub wrote:
> I want to write notebook which prints simple integration examples with
> results for the students.
> Something like:
> 
> ex1 = (1 - 3*x^3 + 2*x^5)/(4*x^3);
> ex2 = (-5*x^(1/4) + (x^2)^(4/3))/x^(3/2);
> 
> Grid[{
>   Table[
>    TraditionalForm[Integrate[Symbol["ex" <> ToString[nr]], x]], {nr, 1, 2}],
> (* do not integrate this *)
>   Table[
>    TraditionalForm[Integrate[Symbol["ex" <> ToString[nr]], x]], {nr, 1, 2}]},
> (* integrate this *)
>  Frame -> All, ItemStyle -> Directive[FontSize -> 18, Bold]]
> 
> (there will be much more examples ex3,ex4, etc.)
> 
> This works nice, but I need to tell Mathematica not to Integrate in the first
> row of the table - examples (only in the second one - results). Is there  any
> possibility to suppress the evaluation of the Integral in the first row of
> the grid and just print the symbol of Integral and the TraditionalForm of the
> example behind it? 
> 
> May be this is a newbie kind of question, but I have spent lot of time on it,
> and I cannot solve it.
> 
> Thanks in advance for any help
> 
> Jakub
> 
HoldForm prevents evaluation, but your requirements are slightly more 
complicated because you do need to obtain the value of ex1, etc. I 
expect you have already encountered that gotcha! Here is some code that 
works, and also eliminates the clumsiness of constructing symbols just 
in order to access a list of things:

ex[1] = (1 - 3*x^3 + 2*x^5)/(4*x^3);
ex[2] = (-5*x^(1/4) + (x^2)^(4/3))/x^(3/2);

Grid[{Table[
    TraditionalForm[
     With[{exx = ex[nr]}, HoldForm[Integrate[exx, x]]]], {nr, 1,
     2}],(*do not integrate this*)
   Table[TraditionalForm[
     Integrate[Symbol["ex" <> ToString[nr]], x]], {nr, 1,
     2}]},(*integrate this*)Frame -> All,
  ItemStyle -> Directive[FontSize -> 18, Bold]]

Notice that the 'With' construct injects the value of ex[nr] inside the 
HoldForm construction, but the HoldForm still prevents further 
evaluation - which is exactly what you want.

David Bailey
http://www.dbaileyconsultancy.co.uk




  • Prev by Date: Re: Overlapping binning of differences of two lists
  • Next by Date: Re: Finding the optimum by repeteadly zooming on the solution space
  • Previous by thread: Re: How to print TraditionalForm without evaluation
  • Next by thread: Re: How to print TraditionalForm without evaluation