MathGroup Archive 2007

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

Search the Archive

Re: Simplify 0/0 to 1?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg77514] Re: Simplify 0/0 to 1?
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Mon, 11 Jun 2007 04:24:55 -0400 (EDT)
  • References: <934147.40360.qm@web43135.mail.sp1.yahoo.com> <2DFED10A-AAB0-4649-A747-93E238C30B75@mimuw.edu.pl>
  • Reply-to: Andrzej Kozlowski <akoz at mimuw.edu.pl>

In fact, if you are really concerned with this, you could do  
something like:

$Pre = (If[Simplify[Denominator[#]] == 0, Print["Zero denominator!"],  
#] &);

You will then get:

o = (Log[2]*Cos[Pi/12] - Log[2]*Sin[Pi/12] - 2*Cos[Pi/12] + 2*Sin[Pi/ 
12] +
     Sqrt[2] + 2*Log[Cos[Pi/12] - Sin[Pi/12]]*Cos[Pi/12] -
     2*Log[Cos[Pi/12] - Sin[Pi/12]]*Sin[Pi/12])/(Log[2]*Cos[Pi/12] -
     Log[2]*Sin[Pi/12] + 2*Log[Cos[Pi/12] - Sin[Pi/12]]*Cos[Pi/12] -
     2*Log[Cos[Pi/12] - Sin[Pi/12]]*Sin[Pi/12])

"Zero denominator!"

before you even apply Simplify. Similarly:

(1 - Cos[Pi/23]^2 - Sin[Pi/23]^2)^2/(1 - 2*Cos[Pi/23]^2 +
       Cos[Pi/23]^4 - 2*Sin[Pi/23]^2 + 2*Cos[Pi/23]^2*Sin[Pi/23]^2 +
       Sin[Pi/23]^4)
"Zero denominator!"

Unfortunately this will produce dramatic slowdowns in any slighlty   
complex algebraic computations (I haven't tried it but I am pretty  
sure).  It might be better to replace this with a numerical check,  
but you will have to use extended precision arithemtic, since machine  
precision will often fail to detect zeros. So you could instead use:

$Pre =.
$Pre = If[N[Denominator[#1], 20] == 0,
      Print["Probably zero denominator!"], #1] & ;
o
N::meprec:Internal precision limit $MaxExtraPrecision = 50. reached  
while evaluating -((-1+) log(2))/(2 )+((1+) log(2))/(2 )-((-1+) log((1 
+)/(2 )-<<1>>/(2 <<1>>)))/+((1+) log((1+)/(2 )-(-1+)/(2 )))/. >>
"Probably zero denominator!"

Peronally I think it is much better to leave thigs as they are, keep  
this in mind  and be a little careful.

Andrzej Kozlowski


On 10 Jun 2007, at 22:20, Andrzej Kozlowski wrote:

> *This message was transferred with a trial version of CommuniGate 
> (tm) Pro*
> I would not call this bad performance. In fact this is inevitable,  
> not only in Mathematica but in every CAS that exists today  
> (although not necssarily in the same example). ALl you need to do  
> is to choose numerator and denominator  equal to zero but  
> sufficiently complicated and such that the CAS will see that they  
> are equal before it can check that they are both 0. Every CAS will  
> then simplify the expression to 1, because for reason of  
> performance they cancel common factors as soon as they see them.  
> Here is a very trivial example:
>
>  (1 - Cos[Pi/23]^2 - Sin[Pi/23]^2)/(1 - Cos[Pi/23]^2 - Sin[Pi/23]^2)
>  1
>
> This was turned into 1 by the evaluator withot any Simplify even  
> though both, the numerator and the denominator are clearly zero.  
> You can avoid this by mapping Sinmplify on the numerator and the  
> denominator but you have to use Unevaluated first:
>
> Simplify /@
>  Unevaluated[(1 - Cos[Pi/23]^2 - Sin[Pi/23]^2)/(1 - Cos[Pi/23]^2 -
>      Sin[Pi/23]^2)]
> The same approach will work in your example:
>
> Simplify/@o
>
> I am convinced that this phenomenon is general will be observed in  
> every CAS, although not necessarily in the same examples. But in  
> every CAS you can construct expressions equal to zero that will be  
> sufficiently complicated for the CAS not to be able to see that  
> they are zero before seeing that they are equal. Here is another  
> example, which is just again based on the Sin^2[a]+Cos^2[a]==1  
> identity, but just made a bit more complicated, so that ti doe not  
> reduce to 1 immediately:
>
>
> Simplify[(1 - Cos[Pi/23]^2 - Sin[Pi/23]^2)^2/(1 - 2*Cos[Pi/23]^2 +  
> Cos[Pi/23]^4 -
>     2*Sin[Pi/23]^2 + 2*Cos[Pi/23]^2*Sin[Pi/23]^2 + Sin[Pi/23]^4)]
>
> 1
>
> As you can see again, the numerator and the denominator are both  
> zero but Simplify sees that they are equal before it can see that  
> they are both zero and at that point the Evaluator performs the  
> cancelation. I think for reason of performance all CAS have to work  
> like this in principle.
>
> Andrzej Kozlowski
>
>
>
>
>
> On 10 Jun 2007, at 20:57, dimitris anagnostou wrote:
>
>>
>> Hi.
>> This appeared in another forum as part of a question
>> what another CAS does.
>> Just of curiosity I check Mathematica's performance (5.2).
>> The result was poor!
>>
>> Here is the expression
>>
>>
>> In[16]:=
>> o = (Log[2]*Cos[Pi/12] - Log[2]*Sin[Pi/12] - 2*Cos[Pi/12] + 2*Sin[Pi/
>> 12] + Sqrt[2] +
>>     2*Log[Cos[Pi/12] - Sin[Pi/12]]*Cos[Pi/12] - 2*Log[Cos[Pi/12] -
>> Sin[Pi/12]]*Sin[Pi/12])/
>>    (Log[2]*Cos[Pi/12] - Log[2]*Sin[Pi/12] + 2*Log[Cos[Pi/12] -
>> Sin[Pi/
>> 12]]*Cos[Pi/12] -
>>     2*Log[Cos[Pi/12] - Sin[Pi/12]]*Sin[Pi/12])
>>
>>
>> Out[16]=
>> (Sqrt[2] + (-1 + Sqrt[3])/Sqrt[2] - (1 + Sqrt[3])/Sqrt[2] - ((-1 +
>> Sqrt[3])*Log[2])/(2*Sqrt[2]) +
>>    ((1 + Sqrt[3])*Log[2])/(2*Sqrt[2]) - ((-1 + Sqrt[3])*Log[-((-1 +
>> Sqrt[3])/(2*Sqrt[2])) + (1 + Sqrt[3])/(2*Sqrt[2])])/
>>     Sqrt[2] + ((1 + Sqrt[3])*Log[-((-1 + Sqrt[3])/(2*Sqrt[2])) + (1 +
>> Sqrt[3])/(2*Sqrt[2])])/Sqrt[2])/
>>   (-(((-1 + Sqrt[3])*Log[2])/(2*Sqrt[2])) + ((1 + Sqrt[3])*Log[2])/
>> (2*Sqrt[2]) -
>>    ((-1 + Sqrt[3])*Log[-((-1 + Sqrt[3])/(2*Sqrt[2])) + (1 + Sqrt[3])/
>> (2*Sqrt[2])])/Sqrt[2] +
>>    ((1 + Sqrt[3])*Log[-((-1 + Sqrt[3])/(2*Sqrt[2])) + (1 + Sqrt[3])/
>> (2*Sqrt[2])])/Sqrt[2])
>>
>> Watch now a really bad performance!
>>
>> In[17]:=
>> (Simplify[#1[o]] & ) /@ {Numerator, Denominator}
>>
>> Out[17]=
>> {0, 0}
>>
>> That is Mathematica simplifies succesfully both the numerator
>> and denominator to zero. So, you wonder what goes wrong?
>>
>> Try now to simplify the whole expression!
>>
>> In[19]:=
>> Simplify[o]
>>
>> Out[19]=
>> 1
>>
>> A very weird result to my opinion!
>> Simplification of 0/0 to 1?
>> I think no simplification or some
>> warning messages would be much better
>> than 1!
>>
>> Note also that
>>
>> In[20]:=
>> RootReduce[o]
>>
>> Out[20]=
>> 1
>>
>> Dimitris
>>
>> Take the Internet to Go: Yahoo!Go puts the Internet in your  
>> pocket: mail, news, photos & more.
>



  • Prev by Date: Re: Fast interactive graphics
  • Next by Date: Re: Re: Re: Re: Re: v6: still no multiple undo?
  • Previous by thread: Re: Simplify 0/0 to 1?
  • Next by thread: Re: Simplify 0/0 to 1?