From: James Stein on 26 May 2010 07:09 Evaluating: ToExpression [ ToString [ 1/3 ] ] I did not expect negative three! Bug? or a lack in my understanding?
From: Sunt on 27 May 2010 06:42 On May 26, 7:09 pm, James Stein <mathgr...(a)stein.org> wrote: > Evaluating: > > ToExpression [ ToString [ 1/3 ] ] > > I did not expect negative three! > > Bug? or a lack in my understanding? Hi, ToString gives an ouputform as default. So this would be OK-- ToExpression[ToString[1/3, InputForm]]
From: Bob Hanlon on 27 May 2010 06:44 You don't want OutputForm as the input to ToString ToString[1/3] // FullForm "1\n-\n3" ToExpression[ToString[#[1/3]]] & /@ {InputForm, StandardForm, TraditionalForm, OutputForm} {1/3, 1/3, 1/3, -3} Bob Hanlon ---- James Stein <mathgroup(a)stein.org> wrote: ============= Evaluating: ToExpression [ ToString [ 1/3 ] ] I did not expect negative three! Bug? or a lack in my understanding?
From: gekko on 27 May 2010 06:44 On May 26, 9:09 pm, James Stein <mathgr...(a)stein.org> wrote: > Evaluating: > > ToExpression [ ToString [ 1/3 ] ] > > I did not expect negative three! > > Bug? or a lack in my understanding? This is quite an amusing behaviour, but I probably wouldn't call it a bug. If you look at the output of the ToString call you'll see it converts the fraction into: 1 - 3 which is the old-style way of displaying fractions on multiple lines. Unfortunately, when you convert back to input using ToExpression, Mathematica interprets this as several lines of input: "1" followed by "-3" (note the "-" operator acts across lines, so the 2nd and 3rd line are treated as a single line of input). To get around this, you can tell ToString what form of output to use. E.g. this does what you want: In[285]:= ToString[1/3, InputForm] Out[285]= 1/3 In[286]:= ToExpression[%] Out[286]= 1/3 Cheers, P.
From: dh on 27 May 2010 06:44 Hi James, TosTring[1/3] creates a 2 dimensional output form for this expression: ToString[1/3] // FullForm Obviously Mathematica can no more correctly interpret this form. I consider this a bug you should report. We can prevent this faulty behavior by specifying an "InputForm" that prevebts the 2-dim output: ToExpression[ToString[InputForm[1/3]]] cheers, Daniel Am 26.05.2010 13:09, schrieb James Stein: > Evaluating: > > ToExpression [ ToString [ 1/3 ] ] > > I did not expect negative three! > > Bug? or a lack in my understanding? > > -- Daniel Huber Metrohm Ltd. Oberdorfstr. 68 CH-9100 Herisau Tel. +41 71 353 8585, Fax +41 71 353 8907 E-Mail:<mailto:dh(a)metrohm.com> Internet:<http://www.metrohm.com>
|
Next
|
Last
Pages: 1 2 Prev: Could you prove this proposition:the i-th prime gap Next: Integrate expression |