Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #4942 > unrolled thread
| Started by | James Stein <mathgroup@stein.org> |
|---|---|
| First post | 2011-09-14 09:20 +0000 |
| Last post | 2011-09-15 08:48 +0000 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
These Simple Four Lines of Mathematic Confound Me -- Bug? James Stein <mathgroup@stein.org> - 2011-09-14 09:20 +0000
Re: These Simple Four Lines of Mathematic Confound Me -- Bug? David Bailey <dave@removedbailey.co.uk> - 2011-09-15 08:44 +0000
Re: These Simple Four Lines of Mathematic Confound Me -- Bug? Richard Fateman <fateman@cs.berkeley.edu> - 2011-09-15 08:45 +0000
Re: These Simple Four Lines of Mathematic Confound Me -- Bug? James Stein <mathgroup@stein.org> - 2011-09-15 08:48 +0000
| From | James Stein <mathgroup@stein.org> |
|---|---|
| Date | 2011-09-14 09:20 +0000 |
| Subject | These Simple Four Lines of Mathematic Confound Me -- Bug? |
| Message-ID | <j4prlp$fne$1@smc.vnet.net> |
I've boiled this puzzlement down to bare bones:
Clear [ g ];
g := { NumberForm [ 13.0, { 5, 3 } ] };
g
% // N
Line 3 gives the output: {13.0} (as expected)
Line 4 gives the output: {13.} but first gives this error message:
NumberForm::iprf : "Formatting specification =91=99{\"5.\", \"3.\"} should be \
a positive integer or a pair of positive integers."
Line 4 seems to cause 'g' to be called. Why?
And how has the formatting spec {5,3} been converted away from integers?
(running Mathematica 8.0.1.0 on a Macintosh)
[toc] | [next] | [standalone]
| From | David Bailey <dave@removedbailey.co.uk> |
|---|---|
| Date | 2011-09-15 08:44 +0000 |
| Message-ID | <j4sdtc$sku$1@smc.vnet.net> |
| In reply to | #4942 |
On 14/09/2011 10:20, James Stein wrote:
> I've boiled this puzzlement down to bare bones:
>
> Clear [ g ];
> g := { NumberForm [ 13.0, { 5, 3 } ] };
> g
> % // N
>
> Line 3 gives the output: {13.0} (as expected)
> Line 4 gives the output: {13.} but first gives this error message:
>
> NumberForm::iprf : "Formatting specification =91=99{\"5.\", \"3.\"} should be \
> a positive integer or a pair of positive integers."
>
> Line 4 seems to cause 'g' to be called. Why?
> And how has the formatting spec {5,3} been converted away from integers?
> (running Mathematica 8.0.1.0 on a Macintosh)
>
Look at g//FullForm
You will see that NumberForm (like MatrixForm and TableForm, and a
number of other functions) becomes part of the expression. Your specific
error happens because the numbers 5 an3 get converted to Reals, which
are not suitable for NumberForm.
The answer is to never (at least unless you really know what you are
doing) assign anything to an expression involving any of the above
functions (NumberForm, etc.), or embed those functions in more calculations.
David Bailey
http://www.dbaileyconsultancy.co.uk
[toc] | [prev] | [next] | [standalone]
| From | Richard Fateman <fateman@cs.berkeley.edu> |
|---|---|
| Date | 2011-09-15 08:45 +0000 |
| Message-ID | <j4sdva$sll$1@smc.vnet.net> |
| In reply to | #4942 |
On 9/14/2011 2:20 AM, James Stein wrote:
> g := { NumberForm [ 13.0, { 5, 3 } ] };
> g
> % // N
in FullForm, g is List[NumberForm[13.`,List[5,3]]]
converting that to floating point numbers results in ...List[5.,3.]
which is illegal as a format.
while NumberForm [....] prints something that you appear to like, it
does not return a value that you apparently expect.
RJF
[toc] | [prev] | [next] | [standalone]
| From | James Stein <mathgroup@stein.org> |
|---|---|
| Date | 2011-09-15 08:48 +0000 |
| Message-ID | <j4se48$smv$1@smc.vnet.net> |
| In reply to | #4942 |
I thank Richard Fateman for his informative reply. I had not known about the
persistence of Mathematica's so-called 'wrappers', whose definition I had
not readily found via the program's help features, but which I recently
found alluded to
here <http://reference.wolfram.com/mathematica/tutorial/FormattedOutput.html>
.
The original form of 'g' did not return a list, and was something like this
'f':
f [ expr_ /; NumericQ[expr]] := If [ expr < 1,
NumberForm[expr, {4, 4}],
NumberForm[expr, {5, 5}]];
The error message occurred when applying "//N" to a list returned
by Mapping 'f' onto a list.
At the above link I found an interesting technique, leading to this
workaround :
g
% //. NumberForm[a_, b_] -> a
% // N
One learns every day.
Thanks to Richard and any others that may answer !
On Wed, Sep 14, 2011 at 1:09 PM, Richard Fateman <fateman@cs.berkeley.edu>wrote:
> On 9/14/2011 2:20 AM, James Stein wrote:
>
>> g := { NumberForm [ 13.0, { 5, 3 } ] };
>> g
>> % // N
>>
>
>
>
> in FullForm, g is List[NumberForm[13.`,List[5,3]**]]
>
> converting that to floating point numbers results in ...List[5.,3.] which
> is illegal as a format.
>
> while NumberForm [....] prints something that you appear to like, it does
> not return a value that you apparently expect.
>
> RJF
>
>
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web