Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #5859 > unrolled thread

bug ?

Started byswiss <gregoire.nicollier@hevs.ch>
First post2011-10-25 10:17 +0000
Last post2011-10-29 11:29 +0000
Articles 6 — 5 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  bug ? swiss <gregoire.nicollier@hevs.ch> - 2011-10-25 10:17 +0000
    Re: bug ? Richard Fateman <fateman@cs.berkeley.edu> - 2011-10-26 21:48 +0000
    Re: bug ? DrMajorBob <btreat1@austin.rr.com> - 2011-10-27 10:31 +0000
    Re: bug ? Peter Pein <petsie@dordos.net> - 2011-10-28 09:37 +0000
      Re: bug ? Peter Pein <petsie@dordos.net> - 2011-10-29 11:16 +0000
    Re:  Re: bug ? Andrzej Kozlowski <akoz@mimuw.edu.pl> - 2011-10-29 11:29 +0000

#5859 — bug ?

Fromswiss <gregoire.nicollier@hevs.ch>
Date2011-10-25 10:17 +0000
Subjectbug ?
Message-ID<j862b6$5ls$1@smc.vnet.net>
Following rational function has a double pole matched by a double root at (4+\sqrt{17})/4. The first result is correct, the other ones are false, but come without warning. Can somebody explain this to me?

In[50]:= Limit[-(((s (4 s - 5)^2 - (5 + 3 Sqrt[17])/
      8 (4 s + 1)) ((4 s - 5)^2 - 
     4 (5 + 3 Sqrt[17])/8 (4 s - 7)))/(16 s^2 - 32 s - 1)^2), 
 s -> 1/4 (4 + Sqrt[17])]

Out[50]= 1/544 (331 - 19 Sqrt[17])

In[51]:= 1/544 (331 - 19 Sqrt[17]) // N

Out[51]= 0.46445

In[52]:= -(((s (4 s - 5)^2 - (5 + 3 Sqrt[17])/
       8 (4 s + 1)) ((4 s - 5)^2 - 
      4 (5 + 3 Sqrt[17])/8 (4 s - 7)))/(16 s^2 - 32 s - 1)^2) /. 
  s -> 1/4 (4 + Sqrt[17]) // Simplify

Out[52]= 1/16 (1 + 2 Sqrt[17])

In[53]:= 1/16 (1 + 2 Sqrt[17]) // N

Out[53]= 0.577888

In[54]:= -(((s (4 s - 5)^2 - (5 + 3 Sqrt[17])/
      8 (4 s + 1)) ((4 s - 5)^2 - 
     4 (5 + 3 Sqrt[17])/8 (4 s - 7)))/(16 s^2 - 32 s - 1)^2) /. 
 s -> 1/4 (4 + Sqrt[17.])

Out[54]= 0.09375

[toc] | [next] | [standalone]


#5896

FromRichard Fateman <fateman@cs.berkeley.edu>
Date2011-10-26 21:48 +0000
Message-ID<j89v84$1f2$1@smc.vnet.net>
In reply to#5859
On 10/25/2011 3:17 AM, swiss wrote:
> Following rational function has a double pole matched by a double root at (4+\sqrt{17})/4.

> The first result is correct, the other ones are false, but come without warning.
 >
>Can somebody explain this to me?

As you know, you are dividing by zero. That's why you take a limit.
If you are not doing arithmetic NOT with the exact values you think you 
have, but some other numbers more or less nearby, you get different results.


Consider a slight variation on your input 54..

-(((s (4 s - 5)^2 - (5 + 3 Sqrt[17])/8 (4 s + 1)) ((4 s - 5)^2 -
         4 (5 + 3 Sqrt[17])/8 (4 s - 7)))/(16 s^2 - 32 s - 1)^2) /.
  s -> 1/4 (4 + Sqrt[17.0000000000000000])

which returns Indeterminate.

Although

-(((s (4 s - 5)^2 - (5 + 3 Sqrt[17])/8 (4 s + 1)) ((4 s - 5)^2 -
         4 (5 + 3 Sqrt[17])/8 (4 s - 7)))/(16 s^2 - 32 s - 1)^2) /.
  s -> 1/4 (4 + Sqrt[17.000000000000000])

(one fewer "0") in there, returns without comment, 0.09375.

Is this a bug? I am sure that some people will call it a feature.
It is a result of compromises made in numerics.


Your example on line 52 is more interesting.

Let q =
-(((s (4 s - 5)^2 - (5 + 3 Sqrt[17])/
          8 (4 s + 1)) ((4 s - 5)^2 -
         4 (5 + 3 Sqrt[17])/8 (4 s - 7)))/(16 s^2 - 32 s - 1)^2) /.
     s ->  1/4 (4 + Sqrt[17])

Then

Simplify[q]     returns, as you show,  1/16* (1+2*Sqrt[17])
FullSimplify[q] returns the same
N[q]            returns 0.
N[q,1]          returns Indeterminate  (with warning)
Expand[q]       returns 0

Map[N,Distribute[q]]  returns -1.49737* 10^14     [A HUGE number!]

Oh, for fun, take that q value and do this:

  qq=  (q/. 17 -> r)

That is, replace all the instances of 17 with r.

Limit[qq, r->17]  is  1/16*(1+2*Sqrt[17])

which is of course not the same as output 50, but is the result of Simplify.

Some of the results about can be explained by a feature/bug that is 
likely to be in Mathematica.  That is essentially a rule that says if 
one is computing a product like A * B, and one is able to simplify A
to zero, there is no need to look at B.  The product is zero. Probably 
other programs like Mathematica do the same thing, by the way.

In this case B =  1/0, but B wasn't examined.  So that is an 
explanation.   It is a result of a heuristic in the Simplify program.

Is it a bug or a feature?  Well, it wouldn't be the first time that 
something in Mathematica is simultaneously declared to be a feature and 
produces um, mathematically questionable results.  I guess that a fan of 
Mathematica could argue that it must be a feature because this behavior 
is well known to WRI and has not been changed, and WRI would change it 
if it were a bug, so it must be a feature. :)





> In[50]:= Limit[-(((s (4 s - 5)^2 - (5 + 3 Sqrt[17])/
>        8 (4 s + 1)) ((4 s - 5)^2 -
>       4 (5 + 3 Sqrt[17])/8 (4 s - 7)))/(16 s^2 - 32 s - 1)^2),
>   s ->  1/4 (4 + Sqrt[17])]
>
> Out[50]= 1/544 (331 - 19 Sqrt[17])
>
> In[51]:= 1/544 (331 - 19 Sqrt[17]) // N
>
> Out[51]= 0.46445
>
> In[52]:= -(((s (4 s - 5)^2 - (5 + 3 Sqrt[17])/
>         8 (4 s + 1)) ((4 s - 5)^2 -
>        4 (5 + 3 Sqrt[17])/8 (4 s - 7)))/(16 s^2 - 32 s - 1)^2) /.
>    s ->  1/4 (4 + Sqrt[17]) // Simplify
>
> Out[52]= 1/16 (1 + 2 Sqrt[17])
>
> In[53]:= 1/16 (1 + 2 Sqrt[17]) // N
>
> Out[53]= 0.577888
>
> In[54]:= -(((s (4 s - 5)^2 - (5 + 3 Sqrt[17])/
>        8 (4 s + 1)) ((4 s - 5)^2 -
>       4 (5 + 3 Sqrt[17])/8 (4 s - 7)))/(16 s^2 - 32 s - 1)^2) /.
>   s ->  1/4 (4 + Sqrt[17.])
>
> Out[54]= 0.09375
>

[toc] | [prev] | [next] | [standalone]


#5909

FromDrMajorBob <btreat1@austin.rr.com>
Date2011-10-27 10:31 +0000
Message-ID<j8bbtq$8kn$1@smc.vnet.net>
In reply to#5859
"I guess that a fan of Mathematica could argue that it must be a feature  
because this behavior is well known to WRI and has not been changed, and  
WRI would change it if it were a bug, so it must be a feature."

Sad, but true!

Bobby

On Wed, 26 Oct 2011 16:40:25 -0500, Richard Fateman  
<fateman@cs.berkeley.edu> wrote:

> On 10/25/2011 3:17 AM, swiss wrote:
>> Following rational function has a double pole matched by a double root  
>> at (4+\sqrt{17})/4.
>
>> The first result is correct, the other ones are false, but come without  
>> warning.
>  >
>> Can somebody explain this to me?
>
> As you know, you are dividing by zero. That's why you take a limit.
> If you are not doing arithmetic NOT with the exact values you think you
> have, but some other numbers more or less nearby, you get different  
> results.
>
>
> Consider a slight variation on your input 54..
>
> -(((s (4 s - 5)^2 - (5 + 3 Sqrt[17])/8 (4 s + 1)) ((4 s - 5)^2 -
>          4 (5 + 3 Sqrt[17])/8 (4 s - 7)))/(16 s^2 - 32 s - 1)^2) /.
>   s -> 1/4 (4 + Sqrt[17.0000000000000000])
>
> which returns Indeterminate.
>
> Although
>
> -(((s (4 s - 5)^2 - (5 + 3 Sqrt[17])/8 (4 s + 1)) ((4 s - 5)^2 -
>          4 (5 + 3 Sqrt[17])/8 (4 s - 7)))/(16 s^2 - 32 s - 1)^2) /.
>   s -> 1/4 (4 + Sqrt[17.000000000000000])
>
> (one fewer "0") in there, returns without comment, 0.09375.
>
> Is this a bug? I am sure that some people will call it a feature.
> It is a result of compromises made in numerics.
>
>
> Your example on line 52 is more interesting.
>
> Let q =
> -(((s (4 s - 5)^2 - (5 + 3 Sqrt[17])/
>           8 (4 s + 1)) ((4 s - 5)^2 -
>          4 (5 + 3 Sqrt[17])/8 (4 s - 7)))/(16 s^2 - 32 s - 1)^2) /.
>      s ->  1/4 (4 + Sqrt[17])
>
> Then
>
> Simplify[q]     returns, as you show,  1/16* (1+2*Sqrt[17])
> FullSimplify[q] returns the same
> N[q]            returns 0.
> N[q,1]          returns Indeterminate  (with warning)
> Expand[q]       returns 0
>
> Map[N,Distribute[q]]  returns -1.49737* 10^14     [A HUGE number!]
>
> Oh, for fun, take that q value and do this:
>
>   qq=  (q/. 17 -> r)
>
> That is, replace all the instances of 17 with r.
>
> Limit[qq, r->17]  is  1/16*(1+2*Sqrt[17])
>
> which is of course not the same as output 50, but is the result of  
> Simplify.
>
> Some of the results about can be explained by a feature/bug that is
> likely to be in Mathematica.  That is essentially a rule that says if
> one is computing a product like A * B, and one is able to simplify A
> to zero, there is no need to look at B.  The product is zero. Probably
> other programs like Mathematica do the same thing, by the way.
>
> In this case B =  1/0, but B wasn't examined.  So that is an
> explanation.   It is a result of a heuristic in the Simplify program.
>
> Is it a bug or a feature?  Well, it wouldn't be the first time that
> something in Mathematica is simultaneously declared to be a feature and
> produces um, mathematically questionable results.  I guess that a fan of
> Mathematica could argue that it must be a feature because this behavior
> is well known to WRI and has not been changed, and WRI would change it
> if it were a bug, so it must be a feature. :)
>
>
>
>
>
>> In[50]:= Limit[-(((s (4 s - 5)^2 - (5 + 3 Sqrt[17])/
>>        8 (4 s + 1)) ((4 s - 5)^2 -
>>       4 (5 + 3 Sqrt[17])/8 (4 s - 7)))/(16 s^2 - 32 s - 1)^2),
>>   s ->  1/4 (4 + Sqrt[17])]
>>
>> Out[50]= 1/544 (331 - 19 Sqrt[17])
>>
>> In[51]:= 1/544 (331 - 19 Sqrt[17]) // N
>>
>> Out[51]= 0.46445
>>
>> In[52]:= -(((s (4 s - 5)^2 - (5 + 3 Sqrt[17])/
>>         8 (4 s + 1)) ((4 s - 5)^2 -
>>        4 (5 + 3 Sqrt[17])/8 (4 s - 7)))/(16 s^2 - 32 s - 1)^2) /.
>>    s ->  1/4 (4 + Sqrt[17]) // Simplify
>>
>> Out[52]= 1/16 (1 + 2 Sqrt[17])
>>
>> In[53]:= 1/16 (1 + 2 Sqrt[17]) // N
>>
>> Out[53]= 0.577888
>>
>> In[54]:= -(((s (4 s - 5)^2 - (5 + 3 Sqrt[17])/
>>        8 (4 s + 1)) ((4 s - 5)^2 -
>>       4 (5 + 3 Sqrt[17])/8 (4 s - 7)))/(16 s^2 - 32 s - 1)^2) /.
>>   s ->  1/4 (4 + Sqrt[17.])
>>
>> Out[54]= 0.09375
>>
>
>


-- 
DrMajorBob@yahoo.com

[toc] | [prev] | [next] | [standalone]


#5954

FromPeter Pein <petsie@dordos.net>
Date2011-10-28 09:37 +0000
Message-ID<j8dt48$kcu$1@smc.vnet.net>
In reply to#5859
Am 25.10.2011 12:17, schrieb swiss:
> Following rational function has a double pole matched by a double root at (4+\sqrt{17})/4. The first result is correct, the other ones are false, but come without warning. Can somebody explain this to me?
> 
> In[50]:= Limit[-(((s (4 s - 5)^2 - (5 + 3 Sqrt[17])/
>       8 (4 s + 1)) ((4 s - 5)^2 - 
>      4 (5 + 3 Sqrt[17])/8 (4 s - 7)))/(16 s^2 - 32 s - 1)^2), 
>  s -> 1/4 (4 + Sqrt[17])]
> 
> Out[50]= 1/544 (331 - 19 Sqrt[17])
> 
> In[51]:= 1/544 (331 - 19 Sqrt[17]) // N
> 
> Out[51]= 0.46445
> 
> In[52]:= -(((s (4 s - 5)^2 - (5 + 3 Sqrt[17])/
>        8 (4 s + 1)) ((4 s - 5)^2 - 
>       4 (5 + 3 Sqrt[17])/8 (4 s - 7)))/(16 s^2 - 32 s - 1)^2) /. 
>   s -> 1/4 (4 + Sqrt[17]) // Simplify
> 
> Out[52]= 1/16 (1 + 2 Sqrt[17])
> 
> In[53]:= 1/16 (1 + 2 Sqrt[17]) // N
> 
> Out[53]= 0.577888
> 
> In[54]:= -(((s (4 s - 5)^2 - (5 + 3 Sqrt[17])/
>       8 (4 s + 1)) ((4 s - 5)^2 - 
>      4 (5 + 3 Sqrt[17])/8 (4 s - 7)))/(16 s^2 - 32 s - 1)^2) /. 
>  s -> 1/4 (4 + Sqrt[17.])
> 
> Out[54]= 0.09375
> 

Well, if Cancel[], Factor[] and/or Apart[] can't do that (and I would
consider this a bug), let's do it by hand:

In[1]:= {n, d} = Through[{Numerator, Denominator}[
    Together[-(((s*(4*s - 5)^2 - (1/8)*(5 + 3*Sqrt[17])*(4*s + 1))*
        ((4*s - 5)^2 - (4/8)*(5 + 3*Sqrt[17])*(4*s - 7)))/
       (16*s^2 - 32*s - 1)^2)]]]

    s0 = (1/4)*(4 + Sqrt[17]);

Out[1]= {(-(85 + 21*Sqrt[17] - 100*s - 12*Sqrt[17]*s + 32*s^2))*
   (-5 - 3*Sqrt[17] + 180*s - 12*Sqrt[17]*s - 320*s^2 + 128*s^3),
  16*(-1 - 32*s + 16*s^2)^2}

In[3]:= gcd = PolynomialGCD[n, d, Extension -> Automatic]
Out[3]= (4 + Sqrt[17] - 4*s)^2

In[4]:= pqr = (PolynomialQuotientRemainder[#1, gcd, s] & ) /@ {n, d}
Out[4]= {{408 - 88*Sqrt[17] + (-928 + 144*Sqrt[17])*s +
         (928 - 32*Sqrt[17])*s^2 - 256*s^3, 0},
        {528 - 128*Sqrt[17]    +(-512 + 128*Sqrt[17])*s + 256*s^2, 0}}

In[5]:= y = Divide @@ pqr[[All,1]];
In[6]:= Limit[y, s -> s0]
        N[%]

Out[6]= (1/544)*(331 - 19*Sqrt[17])
Out[7]= 0.4644503549876185

In[8]:= y /. s -> s0
        N[%]
        Simplify[%%]

Out[8]= (408 - 88*Sqrt[17] +(1/16)*(928 - 32*Sqrt[17])*(4 + Sqrt[17])^2
-  4*(4 + Sqrt[17])^3 + (1/4)*(4 + Sqrt[17])*(-928 + 144*Sqrt[17]))/
  (528 - 128*Sqrt[17] + 16*(4 + Sqrt[17])^2 + (1/4)*(4 + Sqrt[17])*
  (-512 + 128*Sqrt[17]))
Out[9]= 0.4644503549876185
Out[10]= (1/544)*(331 - 19*Sqrt[17])

In[11]:= y /. s -> N[s0]
Out[11]= 0.46445035498761833

In[12]:= RootApproximant[%, 2]
Out[12]= (1/544)*(331 - 19*Sqrt[17])


IMHO these steps should belong to Cancel[].

Peter

[toc] | [prev] | [next] | [standalone]


#5985

FromPeter Pein <petsie@dordos.net>
Date2011-10-29 11:16 +0000
Message-ID<j8gnae$5d1$1@smc.vnet.net>
In reply to#5954
Am 28.10.2011 11:37, schrieb Peter Pein:
...
> 
> Well, if Cancel[], Factor[] and/or Apart[] can't do that (and I would
> consider this a bug), let's do it by hand:
...
> 
> IMHO these steps should belong to Cancel[].
> 
> Peter
> 

Sorry,

my computer must have been under a witch's spell.

Today works Cancel[rat.func., Extension->Automatic] like a charm.

I guess I should do things like these with a clean kernel, before
becoming fussy...


Peter

[toc] | [prev] | [next] | [standalone]


#6017

FromAndrzej Kozlowski <akoz@mimuw.edu.pl>
Date2011-10-29 11:29 +0000
Message-ID<j8go3c$5j9$1@smc.vnet.net>
In reply to#5859
On 28 Oct 2011, at 11:33, Peter Pein wrote:

> Am 25.10.2011 12:17, schrieb swiss:
>> Following rational function has a double pole matched by a double 
root at (4+\sqrt{17})/4. The first result is correct, the other ones are 
false, but come without warning. Can somebody explain this to me?
>>
>> In[50]:= Limit[-(((s (4 s - 5)^2 - (5 + 3 Sqrt[17])/
>>      8 (4 s + 1)) ((4 s - 5)^2 -
>>     4 (5 + 3 Sqrt[17])/8 (4 s - 7)))/(16 s^2 - 32 s - 1)^2),
>> s -> 1/4 (4 + Sqrt[17])]
>>
>> Out[50]= 1/544 (331 - 19 Sqrt[17])
>>
>> In[51]:= 1/544 (331 - 19 Sqrt[17]) // N
>>
>> Out[51]= 0.46445
>>
>> In[52]:= -(((s (4 s - 5)^2 - (5 + 3 Sqrt[17])/
>>       8 (4 s + 1)) ((4 s - 5)^2 -
>>      4 (5 + 3 Sqrt[17])/8 (4 s - 7)))/(16 s^2 - 32 s - 1)^2) /.
>>  s -> 1/4 (4 + Sqrt[17]) // Simplify
>>
>> Out[52]= 1/16 (1 + 2 Sqrt[17])
>>
>> In[53]:= 1/16 (1 + 2 Sqrt[17]) // N
>>
>> Out[53]= 0.577888
>>
>> In[54]:= -(((s (4 s - 5)^2 - (5 + 3 Sqrt[17])/
>>      8 (4 s + 1)) ((4 s - 5)^2 -
>>     4 (5 + 3 Sqrt[17])/8 (4 s - 7)))/(16 s^2 - 32 s - 1)^2) /.
>> s -> 1/4 (4 + Sqrt[17.])
>>
>> Out[54]= 0.09375
>>
>
> Well, if Cancel[], Factor[] and/or Apart[] can't do that (and I would
> consider this a bug), let's do it by hand:
>
> In[1]:= {n, d} = Through[{Numerator, Denominator}[
>    Together[-(((s*(4*s - 5)^2 - (1/8)*(5 + 3*Sqrt[17])*(4*s + 1))*
>        ((4*s - 5)^2 - (4/8)*(5 + 3*Sqrt[17])*(4*s - 7)))/
>       (16*s^2 - 32*s - 1)^2)]]]
>
>    s0 = (1/4)*(4 + Sqrt[17]);
>
> Out[1]= {(-(85 + 21*Sqrt[17] - 100*s - 12*Sqrt[17]*s + 32*s^2))*
>   (-5 - 3*Sqrt[17] + 180*s - 12*Sqrt[17]*s - 320*s^2 + 128*s^3),
>  16*(-1 - 32*s + 16*s^2)^2}
>
> In[3]:= gcd = PolynomialGCD[n, d, Extension -> Automatic]
> Out[3]= (4 + Sqrt[17] - 4*s)^2
>
> In[4]:= pqr = (PolynomialQuotientRemainder[#1, gcd, s] & ) /@ {n, d}
> Out[4]= {{408 - 88*Sqrt[17] + (-928 + 144*Sqrt[17])*s +
>         (928 - 32*Sqrt[17])*s^2 - 256*s^3, 0},
>        {528 - 128*Sqrt[17]    +(-512 + 128*Sqrt[17])*s + 256*s^2, 0}}
>
> In[5]:= y = Divide @@ pqr[[All,1]];
> In[6]:= Limit[y, s -> s0]
>        N[%]
>
> Out[6]= (1/544)*(331 - 19*Sqrt[17])
> Out[7]= 0.4644503549876185
>
> In[8]:= y /. s -> s0
>        N[%]
>        Simplify[%%]
>
> Out[8]= (408 - 88*Sqrt[17] +(1/16)*(928 - 32*Sqrt[17])*(4 + Sqrt[17])^2
> -  4*(4 + Sqrt[17])^3 + (1/4)*(4 + Sqrt[17])*(-928 + 144*Sqrt[17]))/
>  (528 - 128*Sqrt[17] + 16*(4 + Sqrt[17])^2 + (1/4)*(4 + Sqrt[17])*
>  (-512 + 128*Sqrt[17]))
> Out[9]= 0.4644503549876185
> Out[10]= (1/544)*(331 - 19*Sqrt[17])
>
> In[11]:= y /. s -> N[s0]
> Out[11]= 0.46445035498761833
>
> In[12]:= RootApproximant[%, 2]
> Out[12]= (1/544)*(331 - 19*Sqrt[17])
>
>
> IMHO these steps should belong to Cancel[].
>
> Peter
>

I have not read this thread carefully so maybe I am have missed something but the simplest thing to do seems to me to be:

ff = -(((s*(4*s - 5)^2 - (1/8)*(3*Sqrt[17] + 5)*(4*s + 1))*((4*s - 5)^2 - (4/8)*(3*Sqrt[17] + 5)*(4*s - 7)))/(16*s^2 - 32*s - 1)^2);
gg = Factor[ff, Extension -> (s /. {ToRules[Roots[ff == 0, s]]})];

Simplify[gg /. s -> (1/4)*(Sqrt[17] + 4)]
(1/544)*(331- 19*Sqrt[17] )

Of course I agree that Cancel should do this automatically.

Andrzej Kozlowski


[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web