MathGroup Archive 2002

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

Search the Archive


  • To: mathgroup at
  • Subject: [mg35697] ToExpression
  • From: "Heubach, Silvia" <sheubac at>
  • Date: Fri, 26 Jul 2002 04:16:45 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

Hi all, 

I have a problem with using the function ToExpression to make a string 
into an expression that can then be evaluated. Something goes wrong with 
the evaluation - when I type the same expression in "by hand", then it 
evaluates properly. Either I am totally off in my understanding of how 
ToExpression works, or there is a potential bug (I am using version 
4.0). Please reply to this email 
(sheubac at rather than to the mathgroup, as I am 
travelling and cannot subscribe to the mathgroup right now - it would 
make my mailbox overflow....:) 

Thanks for any tips on this! 


i = {1, 0, 0}; j = {0, 1, 0}; k = {0, 0, 1}; zero = {0, 0, 0}; 
a = {i, j, k} 

str1 = "(((..)(..))(..))" 

The function insertx is to convert this string of parentheses and dots 
into a cross product, where each dot represents a different variable, 
and the parentheses indicate the groupings of the cross product. 

insertx[str_] := Module[{foo = str, vars, n, pos}, 
    foo = 
        foo, {")(" -> "),(", ".(" -> ".,(", ")." -> "),.", ".." -> 
    foo = StringReplace[foo, {")" -> "]", "(" -> "Cross["}]; 
         n = Length[StringPosition[foo, "."]]; 
    Do[pos = StringPosition[foo, "."][[1]]; 
          foo = StringReplacePart[foo, ToString[Slot[i]], pos] 
         (*Print[foo]*) , {i, n}]; 

The function properly converts the string into the associated cross 
product, but does not evaluate correctly. Checking whether what is 
returned by the function is still a string gives a false, and it should, 
as the function should return an expression. (the output is indented) 



insertx[str1] &[j, k, i, k, k, i] 




Typing in the corresponding cross product "by hand" and evaluating it 
returns the correct result. 

Cross[Cross[Cross[#1, #2], Cross[#3, #4]], Cross[#5, #6]] &[j, k, i, k, 
k, i] 

   {1, 0, 0} 

What is wrong??? I have spent many hours on trying to understand this, 
so either I am completely off or there is a bug. 

  • Prev by Date: Dashing problem in Graphics3D
  • Next by Date: Mathematica function writing for data analysis at Gould Academy
  • Previous by thread: Dashing problem in Graphics3D
  • Next by thread: RE: ToExpression