MathGroup Archive 2009

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

Search the Archive

Re: Re: Replace and ReplaceAll -- simple application

  • To: mathgroup at smc.vnet.net
  • Subject: [mg106004] Re: [mg105982] Re: Replace and ReplaceAll -- simple application
  • From: danl at wolfram.com
  • Date: Wed, 30 Dec 2009 04:12:56 -0500 (EST)
  • References: <200912270006.TAA12080@smc.vnet.net> <hh72dp$kud$1@smc.vnet.net>

> In article <hh9vfo$1rk$1 at smc.vnet.net>,
>  Richard Fateman <fateman at 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.

In the Documentation Center search for I. Under Possible Issues one sees
"Complex numbers are atomic objects and do not explicitly contain I:",
along with FullForm representations that show this. I would not mind if an
example along the lines you suggest, e.g. "3+4*I/.I->-I evaluates to
3+4*I" were added. Would having such an example there have helped you?


> (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.

It is difficult to anticipate all manner of misunderstandings of
functionality. It is also the case that Mathematica is a complex language,
hence has room for many such misunderstandings. I run into my share. The
documentation mainly states what various functions do, not what they do
not do.

The misunderstanding you allude to above is fairly common, and perhaps
deserves more attention in the ReplaceAll et al pages. I would not ascribe
that level of importance to all such issues you have raised in this forum.


> (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. )

I think the documetation is clear that it is a syntactic replacement and
not a string replacement. Under "More Informnation: it states "ReplaceAll
looks at each part of expr, tries all the rules on it, and then..."

Having configurable warning messages of the sort you describe is on the
wish list of many people. I think it is fair to call this a design
weakness in the Mathematica language, that it is not easy to make such a
message system. I do not think Mathematica is exceptional in this regard:
the current message system is perhaps more advanced than one finds in
other software of serious complexity.

Daniel Lichtblau
Wolfram Research



  • Prev by Date: Re: Re: Replace and ReplaceAll -- simple application
  • Next by Date: Re: Re: Replace and ReplaceAll -- simple application
  • Previous by thread: Re: Re: Replace and ReplaceAll -- simple application
  • Next by thread: Re: Re: Re: Re: Replace and