7.123 bug in Random Tools in Maple 7 (28.11.01)

7.123.1 Mike May
7.123.2 Preben Alsholm (3.12.01)
7.123.3 Mike May (3.12.01)
7.123.4 Preben Alsholm (7.12.01)
7.123.5 Carl Devore (13.12.01)

7.123.1 Mike May

I have been playing with some of the new packages with Maple release 7. I am having some trouble with the RandomTools package. As the examples below show the digits option does weird things on the range used.

1) Is this a known bug?

2) When I try verboseproc to look at code, I am having trouble getting to the code called with specific options. Any suggestions on how to do that?

>  data := sort([seq(Generate(float(range=0.0321..162.0, 
                 digits=2,method=uniform)), i=1..2000)]): 
>  data[1];data[2000]; 
 
                                  .032 
 
                                  1.6 
 
>  data := sort([seq(Generate(float(range=0.0321..162.0, 
                 digits=3,method=uniform)), i=1..2000)]): 
>  data[1];data[2000]; 
 
                                 .0337 
 
                                  16.2 
 
>  data := sort([seq(Generate(float(range=0.0321..162.0, 
                 digits=4,method=uniform)), i=1..2000)]): 
>  data[1];data[2000]; 
 
                                 .2092 
 
                                 161.9 
 
>  data := sort([seq(Generate(float(range=0.0321..162.0, 
                 digits=5,method=uniform)), i=1..2000)]): 
>  data[1];data[2000]; 
 
                                 .34690 
 
                                 1619.4 
 
>  data := sort([seq(Generate(float(range=0.0321..162.0, 
                 digits=6,method=uniform)), i=1..2000)]): 
>  data[1];data[2000]; 
 
                                1.61150 
 
                                16197.6 
 
>  data := sort([seq(Generate(float(range=0.0321..162.0, 
                 digits=10,method=uniform)), i=1..2000)]): 
>  data[1];data[2000]; 
 
                              16630.71940 
 
                                          9 
                            .1619774165 10
                                                                                    
                                                                                    
 

It is corrected with Maple 8 (U. Klein)

7.123.2 Preben Alsholm (3.12.01)

It appears to me that the bug can be found in line 37 of the code for the float-flavor:

showstat(op(1,GetFlavor(float)));
 

There it says

evalf(Float(rand(manL .. manR*10^Digits)(),expL))
 

I think it should say

evalf(Float(rand(manL .. manR*10^(expR-expL))(),expL))
 

And incidentally:

In this procedure ’logarithmic’ is consistently misspelled ’logrithmic’. This has the following amusing effect:

Generate(float(range=0.0321..162.0,method=logarithmic)): 
Error, (in ProcessOptions) argument 'method = logarithmic' invalid: rhs
 

should be of type identical(uniform), identical(logrithmic)

It is corrected with Maple 8 (U. Klein)

7.123.3 Mike May (3.12.01)

Thanks for the help. Since I did not get a copy of the message posted to MUG, it seems that I somehow got deleted from the e-mail list. I have re-subscribed.

A couple of follow-up questions:

1) Is there a standard procedure for reporting bugs in the code?

2) I was able to follow your example to get the code with showstat. I am not clear on the construction of the command. Is there a reason I should suspect I want

showstat(op(1,GetFlavor(float)));
 

rather than

showstat(GetFlavor(float));
 

3) Looking at the code there is repeated reference in the RandomTools package to the FlavorTable. Is there any way to print out the FlavorTable?

I am also running into "features" of the CurveFitting package. When I run the same data through linear regression on the stats[fit, leastsquare] command and the CurveFitting[LeastSquares] command, my coefficients on the new command have extra digits. When I do a least squares fit to a higher degree equation the coefficients only agree to 6 significant digits.

>  mdata := [65.5, 73.3, 41, 61.6, 42.9, 51, 62.3, 70, 56.9, 52.3]: 
>  fdata := [72.7, 79.6, 42, 63.3, 46.1, 55.4, 67.6, 76.8, 56, 59.7]: 
>  UNESCO1 := [seq([mdata[i],fdata[i]], i=1..10)]: 
>  with(stats[fit]): with(CurveFitting): 
>  reglineold := leastsquare[[x,y]]([mdata, fdata]); 
 
             reglineold := y = -3.192082489 + 1.128850251 x 
 
>  regline := y = LeastSquares(UNESCO1,x); 
 
          regliner := y = -3.192082489 + 1.12885025120340932 x 
 
>  leastsquare[[x,y], y=a+b*x+c*x^2]([mdata, fdata]); 
 
                                                            2 
           y = 5.744726622 + .8029638020 x + .002871857378 x 
 
>  LeastSquares(UNESCO1, x, curve=a+b*x+c*x^2); 
 
                                                                  2 
     5.744723280 + .802963923918129096 x + .00287185630353611324 x
 

This leads to the questions:

4) Is this a known bug?

5) Any suggestions on how to determine which command is giving the correct answer?

6) Any way to get the newer package to print the normal number of digits?

I did some more playing that leads me to believe the old stats/fit command is the more accurate:

>  with(CurveFitting):with(ListTools):with(stats[fit]): 
>  data1 := [[0,0],[1.,2],[2,2],[3,2],[4,4]]: 
>  data2 := Transpose(data1): 
>  LeastSquares(data1,x); 
 
                  .4000000000 + .799999999999999932 x 
 
>  leastsquare[[x,y]](data2); 
 
                    y = .4000000000 + .8000000000 x
 

7.123.4 Preben Alsholm (7.12.01)

| Mike May wrote:

| 1) Is there a standard procedure for reporting bugs in the code?

No, as far as I know. I used to report bugs to ’support’, but have stopped doing that. Now I just use the newsgroup comp.soft-sys.math.maple. I would be very surprised, if the Waterloo Maple people don’t read that. The advantage is that the bug is made public.

| 2) I was able to follow your example to get the code with showstat.

GetFlavor(float) is a module, which can be seen by doing:

eval(GetFlavorFloat);
 

It exports the procedure Main. The exports make up the first operand of a module. The code for Main can also be accessed by doing:

interface(verboseproc=2): 
eval(GetFlavor(float):-Main);
 

or instead

showstat(GetFlavor(float):-Main);
                                                                                    
                                                                                    
 

| 3) Looking at the code there is repeated reference in the ...

FlavorTable is local to the module RandomTools. The locals form the third operand:

op(3, eval(RandomTools));
 

To see the module structure try

op(2,eval(RandomTools));
 

To print the FlavorTable do

eval(op([3,1],eval(RandomTools)));
 

| I am also running into "features" of the CurveFitting package. ...

Try increasing Digits to e.g. 20. Then it appears that there is considerable agreement between CurveFitting and stats[fit].

| 4) Is this a known bug?

I don’t think there is a bug.

| 6) Any way to get the newer package to print the normal number of digits?

On the result you could use

evalf[5](%);
 

if you want 5 digits, say.

7.123.5 Carl Devore (13.12.01)

| Mike May wrote:

| I am also running into "features" of the CurveFitting package. ...

The LeastSquares computation is using hardware floating point double precision, which is usually 14 or 15 decimal digits.

| When I do a least squares fit to a higher degree equation ...

And the LeastSquares is the more accurate one. You can verify this by setting Digits:= 20, and redoing the (old) leastsquare. (Or just check the residulas).

| 4) Is this a known bug?

No bug. The old packge was doing the computation to 10 digits, and the newer was using more.

| 5) Any suggestions on how to determine which command is giving ...

Look at the residuals. See my worksheet "Contour plots for three-ingredient mixing problems" at www.mapleapps.com for more info.

| 6) Any way to get the newer package to print the normal number of digits?

Run the results through evalf.

| I did some more playing that leads me to believe the old stats/fit ...

It is just a rare coincidence that in this example the coefficients can be computed exactly in base 10 arithmetic. The software floats that Maple uses are base 10. The hardware floats used by LeastSquares are base 2.