MathGroup Archive 1993

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

Search the Archive

Re: Hold[], Evaluate[] and so forth.

  • To: mathgroup <mathgroup at>
  • Subject: Re: Hold[], Evaluate[] and so forth.
  • From: Charles Wells <cfw2 at>
  • Date: 21 Oct 1993 18:08:44 GMT

> I'm writing a piece of code which takes a Mma expression
> as an argument, processes it through TeXForm, merges that
> with some LaTeX to make a runnable LaTeX file, which is
> viewed with a DVI viewer on the screen. You can see that
> this is potentially useful, in that it allows an inexperienced
> computer user to get a translation of their Mma expressions
> into standard mathematical form. You can also see that its
> rather crucial that the original expression remains completely
> unevaluated in the process, even to the point of simple
> reordering of sub-expressions into canonical form.

One way to do this is to apply InString to $Line.   If you write
s = InString[$Line] then s is a string containing exactly the
current input.  You can then operate on it using Mathematica's
string functions.  An illustration of its use is in the
following code, which is part of my package 0204-769 on
MathSource. Try TruthTable[(x && y) || z], for example.

TT[1] := {{True},{False}}

TT[n_ /; n>1] := T[n] =

SymbolQ[x_] := If[Head[x]==Symbol,True,False,False]

VariableSet[e_] := 
   Select[Union[Level[e, {-1}]],SymbolQ]

MakeArgs[l_List] := StringReplace[ToString[l],
   {"," -> "_,","{" -> "[", "}" -> "_]"}]

MakeFunction[e_,f_] := 
  ToExpression[StringJoin[f // ToString, 
     " := ", e // InputForm // HoldForm //ToString]]

Abb[True] := "T"

Abb[False] := "F"


TruthTable[e_] :=
  Module[{args = VariableSet[e],
    n = Length[args];
    list = MapThread[Join,
         {TT[n],Map[List[Apply[ff,#]]&,TT[n]]}] // Abb;
    list = Prepend[list,    
        TableAlignments-> Center,
        TableSpacing -> {0,2}])]

Charles Wells
Department of Mathematics, Case Western Reserve University
10900 Euclid Avenue, Cleveland, OH 44106-7058, USA
216 368 2893

  • Prev by Date: random number seeds
  • Next by Date: mathHDF & NeXT
  • Previous by thread: Re: Hold[], Evaluate[] and so forth.
  • Next by thread: 3-Day Hands-On Mathematica Workshops in Santa Clara