From: AES on
In article <hh72e4$kuj$1(a)smc.vnet.net>,
"David Park" <djmpark(a)comcast.net> wrote:

> I don't know how you arrived at the initial expression, but if possible you
> could try to enter only exact expressions (avoiding numbers with decimal
> points, called approximate numbers). Enter approximate numbers only when you
> are absolutely forced to. Try to keep all equations symbolic, free of
> approximate numbers. Also keep them free of units. Then once you have solved
> the equations (if you can do that) then substitute data values with
> approximate numbers and units.

After pondering this for a while, I'd agree that sounds like good advice.

But, there are still lots of opportunities for confusion with "/." and
rules. The definition of "/." says:

ReplaceAll (Built-in Mathematica Symbol)
expr /. rules applies a rule or list of rules in an attempt to
transform each subpart of an expression expr.

ReplaceAll looks at each part of expr, tries all the rules on it, and
then goes on to the next part of expr. The first rule that applies to
a particular part is used; no further rules are tried on that part,
or on any of its subparts.

So try

In[1]:= 1./.{1.->1}
Out[1]= 1
In[2]:= -1./.{1.->1}
Out[2]= -1.
In[3]:= a/.{a->b}
Out[3]= b
In[4]:= -a/.{a->b}
Out[4]= -b

Hmmm -- apparently "-1." is _one_ part (or subpart), but "-a" is _two_
subparts.

I suppose the point is that "-1." is a number (and hence a single thing,
or single part, that has to be matched), while "-a" is (somehow!) two
things or two parts -- an operator, and a symbol? -- that are tested
separately.

Interestingly, a further test shows that "- 1." (note space) is also a
single part in an expression -- and is in fact matched by "-1." (no
space) in a rule.

And "-(1.)" is also matched in the same way by "-1." (which seems an
unfortunate behavior; writing it this way should clearly separate the
operator "-" from the approximate number).

These behaviors clearly account for my difficulties with rules involving
I and -I.

But if there's a formal or rigorous definition of "part" or "subpart"
anywhere in the Mathematica documentation, I have yet to find it.

From: Richard Fateman on
Scot T. Martin wrote:
> The problem is that "-1." is not "1".

And furthermore, this bug has been declared a feature. And defended,
repeatedly. Just as I does not occur in -I.
It can be fixed, should be fixed, and has been fixed in other CAS.

From: DrMajorBob on
True enough, I'd say.

Bobby

On Mon, 28 Dec 2009 03:57:38 -0600, Richard Fateman
<fateman(a)cs.berkeley.edu> wrote:

> Scot T. Martin wrote:
>> The problem is that "-1." is not "1".
>
> And furthermore, this bug has been declared a feature. And defended,
> repeatedly. Just as I does not occur in -I.
> It can be fixed, should be fixed, and has been fixed in other CAS.
>


--
DrMajorBob(a)yahoo.com

From: AES on
In article <hh9vfo$1rk$1(a)smc.vnet.net>,
Richard Fateman <fateman(a)cs.berkeley.edu> wrote:

> Scot T. Martin wrote:
> > The problem is that "-1." is not "1".

> And furthermore, this bug has been declared a feature. And defended,
> repeatedly. Just as I does not occur in -I.
> It can be fixed, should be fixed, and has been fixed in other CAS.


I'll defer to Richard Fateman (and/or other computer algebra experts) as
to whether this general behavior (!! especially with respect to -I !!)
is a bug that should be fixed, or a feature.

But if it's gonna be considered a feature in Mathematica, I'd strongly
suggest that it should be strongly **featured** �� or, if you like, it
should be warned about!! �� in the Mathematica documentation, especially
at the more elementary levels of documentation, **so that ordinary users
can't miss being warned about this unexpected behavior** ^HH^H^H^H
sorry, so that they can't miss being warned about "this feature".

For example, right after the first line of the Help for I, which says

I represents the imaginary unit Sqrt[-1].

there might be a warning line which says

WARNING: I is a number and not a symbol. Attempting to replace
or reverse the sign of I using a rule, such as expr/.{I->-I) may
produce unexpected results if the expr contains -I.

(By the way, note the wording above: "I represents", not "I is".)

There are a very large number of other places in the Mathematica
documentation where emphasized WARNINGs like this would be helpful.

(I suppose there could even be optional warning messages that appear any
time a cell executes a rule containing a number on the LHS of a
ReplaceAll symbol. And, the documentation for ReplaceAll could have an
initial WARNING message that it is not just the kind of Global Search
and Replace command that many ordinary users, familiar with many other
word processing and software apps, might well think it is. )

From: DrMajorBob on
-1. is a Real, hence an Atom, so it has no subordinate parts.

Bobby

On Mon, 28 Dec 2009 03:55:56 -0600, AES <siegman(a)stanford.edu> wrote:

> In article <hh72e4$kuj$1(a)smc.vnet.net>,
> "David Park" <djmpark(a)comcast.net> wrote:
>
>> I don't know how you arrived at the initial expression, but if possible
>> you
>> could try to enter only exact expressions (avoiding numbers with decimal
>> points, called approximate numbers). Enter approximate numbers only
>> when you
>> are absolutely forced to. Try to keep all equations symbolic, free of
>> approximate numbers. Also keep them free of units. Then once you have
>> solved
>> the equations (if you can do that) then substitute data values with
>> approximate numbers and units.
>
> After pondering this for a while, I'd agree that sounds like good advice.
>
> But, there are still lots of opportunities for confusion with "/." and
> rules. The definition of "/." says:
>
> ReplaceAll (Built-in Mathematica Symbol)
> expr /. rules applies a rule or list of rules in an attempt to
> transform each subpart of an expression expr.
>
> ReplaceAll looks at each part of expr, tries all the rules on it, and
> then goes on to the next part of expr. The first rule that applies to
> a particular part is used; no further rules are tried on that part,
> or on any of its subparts.
>
> So try
>
> In[1]:= 1./.{1.->1}
> Out[1]= 1
> In[2]:= -1./.{1.->1}
> Out[2]= -1.
> In[3]:= a/.{a->b}
> Out[3]= b
> In[4]:= -a/.{a->b}
> Out[4]= -b
>
> Hmmm -- apparently "-1." is _one_ part (or subpart), but "-a" is _two_
> subparts.
>
> I suppose the point is that "-1." is a number (and hence a single thing,
> or single part, that has to be matched), while "-a" is (somehow!) two
> things or two parts -- an operator, and a symbol? -- that are tested
> separately.
>
> Interestingly, a further test shows that "- 1." (note space) is also a
> single part in an expression -- and is in fact matched by "-1." (no
> space) in a rule.
>
> And "-(1.)" is also matched in the same way by "-1." (which seems an
> unfortunate behavior; writing it this way should clearly separate the
> operator "-" from the approximate number).
>
> These behaviors clearly account for my difficulties with rules involving
> I and -I.
>
> But if there's a formal or rigorous definition of "part" or "subpart"
> anywhere in the Mathematica documentation, I have yet to find it.
>


--
DrMajorBob(a)yahoo.com