       Re: Solve never calls Equal?

```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:= Unprotect[Equal]
>>
>> Out= {Equal}
>>
>> In:= Equal[a_, b__] := SameQ[a, b]
>>
>> In:= Protect[Equal]
>>
>> Out= {Equal}
>>
>> In:= Solve[3 x  == 1, x]
>>
>> Out= {}
>>
>> 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 computes 5! =
and
> calls Equal 6 times... but Factorial 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:= Unprotect[Equal];

In:= Equal[a_?NumberQ, b_?NumberQ] := SameQ[a, b]

In:= Protect[Equal];

In:= eqn = 2 x + 1 == 0;

In:= Solve[eqn, x][] // N

Out= {x->-0.5}

In:= eqn /. %

Out= 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

```

• Prev by Date: infection model of numeric coercion in Mathematica [Was: Re: Numerical accuracy/precision - this is a bug or]
• Next by Date: Re: Solve never calls Equal?
• Previous by thread: Re: Solve never calls Equal?
• Next by thread: Re: Solve never calls Equal?