Re: Solve never calls Equal?
- To: mathgroup at smc.vnet.net
- Subject: [mg120298] Re: Solve never calls Equal?
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Sun, 17 Jul 2011 06:03:57 -0400 (EDT)
- References: <201107150118.VAA23606@smc.vnet.net> <ivovvt$qpa$1@smc.vnet.net> <201107160941.FAA08237@smc.vnet.net> <7BBB2BCC-0234-4BDA-A129-3270EBA623CE@mimuw.edu.pl>
On 17 Jul 2011, at 07:10, Andrzej Kozlowski wrote: > > On 16 Jul 2011, at 11:41, Richard Fateman wrote: > >> (in a different thread, where replacing Equal by SameQ was proposed) >> >> >> On 7/15/2011 2:07 AM, Andrzej Kozlowski wrote: >>> Well, here is one example of what would happen: >>> >>> In[3]:= Unprotect[Equal] >>> >>> Out[3]= {Equal} >>> >>> In[5]:= Equal[a_, b__] := SameQ[a, b] >>> >>> In[6]:= Protect[Equal] >>> >>> Out[6]= {Equal} >>> >>> In[7]:= Solve[3 x == 1, x] >>> >>> Out[7]= {} >>> >>> Doesn't look like a great idea to me. >>> >>> Andrzej Kozlowski >>> >> >> That's because 3*x==1 is immediately changed to False, and >> Solve[False, x] is indeed not a great idea. >> >> >> >> Equal[a_?NumberQ, b_?NumberQ] := SameQ[a, b]; >> >> works better. That Solve example works just fine. >> >> Indeed, if one does this.. >> >> Equal[a_?NumberQ, b_?NumberQ] := (Print[test[a, b]]; SameQ[a, b]); >> >> one can detect when, if ever, the Solve program calls Equal on two >> numbers. It will print test[...] on such occasions. >> >> When does Solve call Equal on 2 numbers? I poked around a little and >> found -- never. I tried Integrate, Factor, Do, Product, Plot.. --never. >> >> >> note that f[x_] := If [x == 0, 1, f[x - 1]*x]; f[5] computes 5! and >> calls Equal 6 times... but Factorial[5] does not. >> >> >> Perhaps the internal support routines do not call Equal? >> or calls to it are compiled away and not in reach of redefinition by the >> user? Or do they call SameQ? (no, they don't. I tried it). >> >> Cheers >> >> >> RJF >> >> > > This may indeed "work", though one would have to check functions such as NSolve, NSum, Reduce, etc, which I haven't tried (and don't want to). But it certainly will produce effects like this: > > In[1]:= Unprotect[Equal]; > > In[2]:= Equal[a_?NumberQ, b_?NumberQ] := SameQ[a, b] > > In[3]:= Protect[Equal]; > > In[4]:= eqn = 2 x + 1 == 0; > > In[5]:= Solve[eqn, x][[1]] // N > > Out[5]= {x->-0.5} > > In[6]:= eqn /. % > > Out[6]= False > > I am not at all convinced that the "naive user" will find this behaviour much of an improvement, in fact, quite the opposite. > > Andrzej Kozlowski Well, I decided to test it, and, as I suspected, the results are not "great". Let's solve a nice equation: Reduce[Exp[x] - x == 1/2 && Abs[x] < 1, x]//N x==0.162909 -0.972479 I\[Or]x==0.162909 +0.972479 I Great, now let's try Richard's "improved" Mathematica: Unprotect[Equal]; Equal[a_?NumberQ, b_?NumberQ] := SameQ[a, b] Protect[Equal]; Reduce[Exp[x]-x==1/2&&Abs[x]<1,x] Reduce::nsmet: This system cannot be solved with the methods available to Reduce. >> Bummer! It took ages to get to decide that it could no longer do it!. The ability to solve such kind of equations is for me one of the major advances in Mathematica's capabilities in tis decade. (I am even teaching a course centered around explaining how this sort of thing is done). Would I give this up to please Richard Fateman and his imaginary "naive users"? Would anyone? (I don't think this really needs an answer). Is WRI right to ignore all Richard's "helpful" code that "improves" Mathematica in various ways? (I think the answer is also obvious). Andrzej
- Follow-Ups:
- Re: Solve never calls Equal?
- From: Andrzej Kozlowski <akoz@mimuw.edu.pl>
- Re: Solve never calls Equal?
- References:
- Re: Numerical accuracy/precision - this is a bug or a feature?
- From: "Christoph Lhotka" <christoph.lhotka@univie.ac.at>
- Solve never calls Equal?
- From: Richard Fateman <fateman@cs.berkeley.edu>
- Re: Numerical accuracy/precision - this is a bug or a feature?