Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to print TraditionalForm without evaluation

3 views
Skip to first unread message

Serych Jakub

unread,
Oct 8, 2008, 6:26:30 AM10/8/08
to
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

David Park

unread,
Oct 9, 2008, 6:32:19 AM10/9/08
to
The following is probably the most common answer you will receive. To
simplify things I have taken the TraditionalForm outside the the Grid. I
have also used the new Version 6 iterator construction that allows us to
list the specific substitutions. (It might have been simpler to use ex[1],
ex[2] etc., to specify the examples and then iterate on the integer range.)
Since the Integrate is in a HoldForm, we have to use a rule to substitute
the iterated values.

Grid[
{(* Do not integrate the first row *)
Table[HoldForm[Integrate[integrand, x]] /.
integrand -> expr, {expr, {ex1, ex2}}],
(* Integrate the second row *)
Table[Integrate[expr, x], {expr, {ex1, ex2}}]}, Frame -> All,
ItemStyle -> Directive[FontSize -> 18, Bold]] // TraditionalForm

With the Presentations package it is possible to use the command HoldOp,
which holds an operation but evaluates the arguments. Then we could write
the above more simply as:

Needs["Presentations`Master`"]

Grid[
{(* Do not integrate this *)
Table[Integrate[expr, x] //
HoldOp[Integrate], {expr, {ex1, ex2}}],
(* Integrate this *)
Table[Integrate[expr, x], {expr, {ex1, ex2}}]}, Frame -> All,
ItemStyle -> Directive[FontSize -> 18, Bold]] // TraditionalForm

Or if you use the Student's Integral part of Presentations you can write it
even simpler using Integrate with a small 'i'.

Grid[
{(* Do not integrate this *)
Table[integrate[expr, x], {expr, {ex1, ex2}}],
(* Integrate this *)
Table[Integrate[expr, x], {expr, {ex1, ex2}}]},
Frame -> All,
ItemStyle -> Directive[FontSize -> 18, Bold]] // TraditionalForm

And if you want the students to actually practice doing integrals
step-by-step using basic integration techniques and a BasicIntegralTable,
such as students often work from, then the first integral could be done by
the following commands:

integrate[ex1, x] // TraditionalForm
% // OperateIntegrand[Apart] // TraditionalForm
% // BreakoutIntegral // TraditionalForm
% // UseIntegralTable[BasicIntegralTable] // TraditionalForm

There are also commands: ChangeIntegralVariable, IntegrateByParts and
Trigonometric Substitute. You can also do definite integrals and obtain
intermediate limit bracket expressions. A student can bypass the Mathematica
Integrate command altogether using integral tables, or at some point the
student can hand the integral over to Mathematica's Integrate or NIntegrate
command.


--
David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/


"Serych Jakub" <Ser...@panska.cz> wrote in message
news:gci1sm$iv$1...@smc.vnet.net...

Albert Retey

unread,
Oct 9, 2008, 6:33:30 AM10/9/08
to
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?

This is what I would do:

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);

heldintegrate[expr_, x_] :=
With[{e = expr}, HoldForm[Integrate[e, x]]]

Grid[{Table[TraditionalForm[
heldintegrate[ex[nr], x]


], {nr, 1, 2}],(*do not integrate this*)

Table[TraditionalForm[Integrate[ex[nr], x]], {nr, 1,
2}]},(*integrate this*)Frame -> All,


ItemStyle -> Directive[FontSize -> 18, Bold]]

hth,

albert

Bob F

unread,
Oct 9, 2008, 6:35:18 AM10/9/08
to

Jakub,

One way is to just leave off the Integrate[], and prepend an Integral
sign to the "TraditionalForm" string, ie

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[

"\[Integral]"
TraditionalForm[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]]

-Bob Freeman

Jean-Marc Gulliet

unread,
Oct 9, 2008, 6:35:37 AM10/9/08
to
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?

One possible way is illustrated below. First, we prevent the evaluation
of the integrals (but not of the inner expression leading to the
integrands) by substituting a dummy symbol, say 'int', in place of
*Integrate*, then we replace the dummy head by
*HoldForm[Integrate[__]]*, and voila!

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[
int[Symbol["ex" <> ToString[nr]], x] /.
int[exp__] -> HoldForm[Integrate[exp]]], {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]]

Regards,
-- Jean-Marc

David Bailey

unread,
Oct 9, 2008, 6:36:32 AM10/9/08
to
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

Szabolcs Horvat

unread,
Oct 9, 2008, 6:39:38 AM10/9/08
to

Hello Jakub,

The keyword is HoldForm:

Grid[
{HoldForm[Integrate[#, x]], Integrate[#, x]} & /@ {ex1, ex2},


Frame -> All, ItemStyle -> Directive[FontSize -> 18, Bold]

] // TraditionalForm

(You might want to Transpose the list inside the grid.)

Jens-Peer Kuska

unread,
Oct 9, 2008, 6:40:10 AM10/9/08
to
Hi,

ex1 = (1 - 3*x^3 + 2*x^5)/(4*x^3);
ex2 = (-5*x^(1/4) + (x^2)^(4/3))/x^(3/2);

toHoldForm[expr_] := (HoldForm @@ {expr}) /. int -> Integrate

Grid[{Table[
toHoldForm[
TraditionalForm[int[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]]

??

Regards
Jens

Bob Hanlon

unread,
Oct 9, 2008, 6:43:26 AM10/9/08
to
Recommend that you use columns rather than rows.

input = {
(1 - 3*x^3 + 2*x^5)/(4*x^3),
(-5*x^(1/4) + (x^2)^(4/3))/x^(3/2),
Sin[x], Cos[x]
};

labels = HoldForm[Integrate[#, x]] & /@ input;

output = ReleaseHold[labels] // FullSimplify;

Grid[Transpose[{labels, output}],
Frame -> All,
ItemStyle -> Directive[18, Bold]] // TraditionalForm


Bob Hanlon

---- Serych Jakub <Ser...@panska.cz> 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


--

Bob Hanlon


chandl...@gmail.com

unread,
Oct 11, 2008, 6:40:40 AM10/11/08
to
On Oct 9, 5:43 am, Bob Hanlon <hanl...@cox.net> wrote:
> Recommend that you use columns rather than rows.
>
> input = {
> (1 - 3*x^3 + 2*x^5)/(4*x^3),
> (-5*x^(1/4) + (x^2)^(4/3))/x^(3/2),
> Sin[x], Cos[x]
> };
>
> labels = HoldForm[Integrate[#, x]] & /@ input;
>
> output = ReleaseHold[labels] // FullSimplify;
>
> Grid[Transpose[{labels, output}],
> Frame -> All,
> ItemStyle -> Directive[18, Bold]] // TraditionalForm
>
> Bob Hanlon
>
> ---- Serych Jakub <Ser...@panska.cz> 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 f=
irst
> 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 o=
f
> 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
>
> --
>
> Bob Hanlon

Thanks folks, for a really helpful thread. Very instructive.

Alexei Boulbitch

unread,
Oct 13, 2008, 7:05:03 AM10/13/08
to
Jacub,
it seems me that what you would like to achieve is done by the following

ex1 = (1 - 3*x^3 + 2*x^5)/(4*x^3);
ex2 = (-5*x^(1/4) + (x^2)^(4/3))/x^(3/2);


Grid[{(*Do not integrate this*)
Table[Row[{"\[Integral]", expr , "dx"}], {expr, {ex1,
ex2}}],(*Integrate this*)
Table[Integrate[expr, x], {expr, {ex1, ex2}}]}, Frame -> All,

ItemStyle -> Directive[FontSize -> 18, Bold]] // TraditionalForm

Best, Alexei


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

--
Alexei Boulbitch, Dr., Habil.
Senior Scientist

IEE S.A.
ZAE Weiergewan
11, rue Edmond Reuter
L-5326 Contern
Luxembourg

Phone: +352 2454 2566
Fax: +352 2454 3566

Website: www.iee.lu

This e-mail may contain trade secrets or privileged, undisclosed or otherwise confidential information. If you are not the intended recipient and have received this e-mail in error, you are hereby notified that any review, copying or distribution of it is strictly prohibited. Please inform us immediately and destroy the original transmittal from your system. Thank you for your co-operation.

0 new messages