MathGroup Archive 2008

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

Search the Archive

Re: Request for Collective Wisdom...

  • To: mathgroup at
  • Subject: [mg88804] Re: Request for Collective Wisdom...
  • From: David Bailey <dave at>
  • Date: Fri, 16 May 2008 06:26:51 -0400 (EDT)
  • References: <> <fvudnm$ec1$>

Ingolf Dahl wrote:
> My humble contribution to the collective wisdom:
> Do not forget to tell them about how to trace errors. The simplest way is
> often to put print expressions into the code: 
> Print["localizing text", var]; 
> to check a variable value. If you tell them about pure functions, a variant
> of this theme is often useful. The expression
> (Print["text ", #]; #) &@ 
> can often be inserted inside expressions in appropriate places, without the
> need of setting any variable value. It is a good example of the use of pure
> functions and of printing as "side effect", not disturbing the computational
> flow. For instance 
> Sin[(Print["mytext ", #]; #) &@ Sin[2.]]
> will print 
> mytext 0.909297
> and return
> 0.789072 
> Best regards
> Ingolf Dahl
> ingolf.dahl at
>> -----Original Message-----
>> From: W_Craig Carter [mailto:wcraigcarter at] 
>> Sent: den 6 maj 2008 12:38
>> To: mathgroup at
>> Subject:  Request for Collective Wisdom...
>> (*Below is a request for suggestions for "hints for 
>> beginners. The preface is a bit long-winded" *)
>> I am working on an applied math for physical scientists 
>> undergraduate text---I am using Mathematica as the engine to 
>> learn and solve problems quickly.
>> I have an appendix that I have been creating (empirically) 
>> for  a couple years: "Common Mathematica Beginners' Errors." 
>> This wasn't difficult.
>> I am now considering how to write another Appendix: 
>> "Mathematica Usage Paradigms for Beginners."  This one is not 
>> as straightforward because it will be a list of short 
>> sequences of Mathematica code. The size of the list should be 
>> a compromise between length, completeness, and "orthogonality."
>> Some topics are obvious to (subjective) me: work symbolically 
>> and with exact representations; scale to remove units when 
>> possible; visualize often and when in doubt evaluate as a 
>> number; pure functions are power; avoid the outdoors unless 
>> you have applied the documentation, lists are your friends...
>> Nota bene, this is a book for undergraduates who have just 
>> received the "physics, chemistry, and multivariable calculus" 
>> catechism, and
>> (typically) don't appreciate that there are common themes in 
>> their education (think back...).
>> (* Punchline: *)
>> I would sincerely appreciate thoughtful (bullet-type) 
>> suggestions for paradigms.  (off-line or on- as you please).
>> PS: Implicit in this is what a dear friend called "The 
>> Homotopy Conjecture."  Give me a small working example, and 
>> it can deformed into a complicated one for my own purposes.
>> PPS: I expect a small fraction of snarky answers---I won't respond.
>> --
>> W. Craig Carter
A variant of the above is to define a function that prints out an 
expression before and after evaluation separated by '=':

SetAttributes[dPrint, HoldFirst];
dPrint[x_] :=
  Module[{ans = x},
   StylePrint[SequenceForm[Unevaluated[x], "=", ans],
    Background -> RGBColor[0.6`, 1, 0.6`]]; ans]

Using this function, calling dPrint[x] will print something like:


It will also return the original answer (evaluated only once) so that it 
can be nicely embedded in a bigger calculation.

Furthermore, because these debug prints come out with a light green 
background, they don't get confused with other output from the program.

David Bailey

  • Prev by Date: Re: Re: Expression manipulation
  • Next by Date: Re: RenderBadPicture error while running Mathematica 6 on Linux
  • Previous by thread: RE: Request for Collective Wisdom...
  • Next by thread: Re: Request for Collective Wisdom...