MathGroup Archive 2009

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

Search the Archive

How to print/display symbolic expressions from inside a Module without the $ dollar signs?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg104198] How to print/display symbolic expressions from inside a Module without the $ dollar signs?
  • From: "Nasser M. Abbasi" <nma at 12000.org>
  • Date: Thu, 22 Oct 2009 22:34:47 -0400 (EDT)
  • Reply-to: "Nasser M. Abbasi" <nma at 12000.org>

Hello;

I use Print[] allot while debugging, and trace how the expression evolve 
etc... while it is still symbolic, before I plug in numerical values.

But when I have a Module, and use Print[] on expression which involves local 
variables, they all print with a $ sign ofcourse.  This makes it hard to 
read the expressions.

foo[] := Module[{x, y,expr},
                 expr= x^2 + y;
                 Print[" expression now is ",
                    ToString[expr,FormatType->TraditionalForm]]
          ]
foo[]
 expression now is x$589^2+y$589

A standard way to solve this is to pass the symbols themselves as in

foo[x_, y_] := Module[{expr}, expr = x^2 + y;
                       Print[" expression now is ",
                           ToString[expr,FormatType -> TraditionalForm]]
                      ]

Remove[x, y]
foo[x, y]
 expression now is x^2+y

But the problem is that I am calling foo[] itself from inside yet another 
Module, and I also can't have global variables at all.  So, everything is 
wrapped inside a Module, and every symbol much have a scope inside, nothing 
global.

So, the only option I see (which I am going to try next, do not know if it 
will work) is to make a pattern which strips these $nnn from the symbols for 
display purposes?

Or Am I missing some other simple solution to this common problem?

Thanks,
--Nasser 



  • Prev by Date: variable ordering in TeXForm
  • Next by Date: Re: Re: Re: Re: Suggestions on how to use standard engineering
  • Previous by thread: Re: variable ordering in TeXForm
  • Next by thread: Re: Re: Re: Re: Suggestions on how to use standard engineering