Subject: Simplification of products and the number 0
From: Dieter Kaiser
Date: Wed, 13 Oct 2010 23:21:18 +0200
Am Montag, den 27.09.2010, 09:57 -0400 schrieb Stavros Macrakis:
> Agreed entirely that * should be associative and commutative, so 0*0.0
> = 0.0*0 etc.
>
>
> However, there are two possible reasonable results for 0*0.0: 0 or
> 0.0. Here are the arguments in favor of each:
>
>
> 0 -- 0 represents an exact zero; 0.0 represents some unknown number
> very near zero. Therefore 0*0.0 is always exactly 0.
>
>
> 0.0 -- a) calculating with 0.0 implies that we want an approximate
> result
> b) we want type(a*b) to be a function of type(a) and type(b),
> independently of their values (especially important for compilation)
> c) multiplying by integer 0 is a very special case -- do we
> really want to handle it differently from other integers?
>
>
> I started writing this email thinking that 0 was the 'correct'
> solution -- and I think it is, in fact, logically correct -- however,
> it looks as though 0.0 is the pragmatic solution.
>
>
> Thoughts?
Yes, I think the result 0.0 is a good and pragmatic solution.
Meanwhile, I have started to build some tables to have a look much more
consistently at what is implemented and what should be the result. If we
would agree that the suggested tables show a correct simplification, we
could implement the tables and add the tables to the testsuite as a
reference. In the following I show three tables, two tables have
problems.
This is a suggested table for the multiplication of zeros (all flags
have their standard value):
/* Table 2.1: Multiplication of zeros
*
* TIMES | 0 0.0 0.0b0 [0] [0.0] [0.0b0]
* ---------------------------------------------------------
* 0 | 0 0.0 0.0b0 [0] [0.0] [0.0b0]
* 0.0 | 0.0 0.0 0.0b0 [0.0] [0.0] [0.0b0]
* 0.0b0 | 0.0b0 0.0b0 0.0b0 [0.0b0] [0.0b0] [0.0b0]
* [0] | [0] [0.0] [0.0b0] [0] [0.0] [0.0b0]
* [0.0] | [0.0] [0.0] [0.0b0] [0.0] [0.0] [0.0b0]
* [0.0b0] | [0.0b0] [0.0b0] [0.0b0] [0.0b0] [0.0b0] [0.0b0]
*/
Furthermore, I have written a testfile to verify the results of Maxima.
We have 12 different simplifications in comparison with the suggested
table. The differences are related to the following simplifications:
0 * 0.0 -> 0 or
0 * 0.0b0 -> 0
But most astonishing is the simplification (it is the first time I have
recognized this case):
0.0 * 0.0b0 -> 0.0
********************** Problem 182 ***************
Input:
0 0.0
Result:
0
This differed from the expected result:
0.0
********************** Problem 183 ***************
Input:
0 0.0b0
Result:
0
This differed from the expected result:
0.0b0
********************** Problem 185 ***************
Input:
0 [0.0]
Result:
[0]
This differed from the expected result:
[0.0]
********************** Problem 186 ***************
Input:
0 [0.0b0]
Result:
[0]
This differed from the expected result:
[0.0b0]
********************** Problem 189 ***************
Input:
0.0 0.0b0
Result:
0.0
This differed from the expected result:
0.0b0
********************** Problem 192 ***************
Input:
0.0 [0.0b0]
Result:
[0.0]
This differed from the expected result:
[0.0b0]
********************** Problem 203 ***************
Input:
[0] [0.0]
Result:
[0]
This differed from the expected result:
[0.0]
********************** Problem 204 ***************
Input:
[0] [0.0b0]
Result:
[0]
This differed from the expected result:
[0.0b0]
********************** Problem 205 ***************
Input:
[0.0] 0
Result:
[0]
This differed from the expected result:
[0.0]
********************** Problem 210 ***************
Input:
[0.0] [0.0b0]
Result:
[0.0]
This differed from the expected result:
[0.0b0]
********************** Problem 211 ***************
Input:
[0.0b0] 0
Result:
[0]
This differed from the expected result:
[0.0b0]
********************** Problem 212 ***************
Input:
[0.0b0] 0.0
Result:
[0.0]
This differed from the expected result:
[0.0b0]
The following table is interesting too.
/* Table 2.2: Multiplication of zeros and the number one
*
* MUL | 1 1.0 1.0b0 [1] [1.0] [1.0b0]
* ---------------------------------------------------------
* 0 | 0 0.0 0.0b0 [0] [0.0] [0.0b0]
* 0.0 | 0.0 0.0 0.0b0 [0.0] [0.0] [0.0b0]
* 0.0b0 | 0.0b0 0.0b0 0.0b0 [0.0b0] [0.0b0] [0.0b0]
* [0] | [0] [0.0] [0.0b0] [0] [0.0] [0.0b0]
* [0.0] | [0.0] [0.0] [0.0b0] [0.0] [0.0] [0.0b0]
* [0.0b0] | [0.0b0] [0.0b0] [0.0b0] [0.0b0] [0.0b0] [0.0b0]
*/
If we would agree that this table shows a correct simplification, then
we have 24 different results with the current version of Maxima. Now the
problems are
0*1.0 -> 0 or 0*1.0b0 -> 0 and 0.0*1.0b0 -> 0.0
********************** Problem 219 ***************
Input:
0 1.0
Result:
0
This differed from the expected result:
0.0
********************** Problem 220 ***************
Input:
1.0 0
Result:
0
This differed from the expected result:
0.0
********************** Problem 221 ***************
Input:
0 1.0b0
Result:
0
This differed from the expected result:
0.0b0
********************** Problem 222 ***************
Input:
1.0b0 0
Result:
0
This differed from the expected result:
0.0b0
********************** Problem 225 ***************
Input:
0 [1.0]
Result:
[0]
This differed from the expected result:
[0.0]
********************** Problem 226 ***************
Input:
[1.0] 0
Result:
[0]
This differed from the expected result:
[0.0]
********************** Problem 227 ***************
Input:
0 [1.0b0]
Result:
[0]
This differed from the expected result:
[0.0b0]
********************** Problem 228 ***************
Input:
[1.0b0] 0
Result:
[0]
This differed from the expected result:
[0.0b0]
********************** Problem 233 ***************
Input:
0.0 1.0b0
Result:
0.0
This differed from the expected result:
0.0b0
********************** Problem 234 ***************
Input:
1.0b0 0.0
Result:
0.0
This differed from the expected result:
0.0b0
********************** Problem 239 ***************
Input:
0.0 [1.0b0]
Result:
[0.0]
This differed from the expected result:
[0.0b0]
********************** Problem 240 ***************
Input:
[1.0b0] 0.0
Result:
[0.0]
This differed from the expected result:
[0.0b0]
********************** Problem 255 ***************
Input:
[0] 1.0
Result:
[0]
This differed from the expected result:
[0.0]
********************** Problem 256 ***************
Input:
1.0 [0]
Result:
[0]
This differed from the expected result:
[0.0]
********************** Problem 257 ***************
Input:
[0] 1.0b0
Result:
[0]
This differed from the expected result:
[0.0b0]
********************** Problem 258 ***************
Input:
1.0b0 [0]
Result:
[0]
This differed from the expected result:
[0.0b0]
********************** Problem 261 ***************
Input:
[0] [1.0]
Result:
[0]
This differed from the expected result:
[0.0]
********************** Problem 262 ***************
Input:
[1.0] [0]
Result:
[0]
This differed from the expected result:
[0.0]
********************** Problem 263 ***************
Input:
[0] [1.0b0]
Result:
[0]
This differed from the expected result:
[0.0b0]
********************** Problem 264 ***************
Input:
[1.0b0] [0]
Result:
[0]
This differed from the expected result:
[0.0b0]
********************** Problem 269 ***************
Input:
[0.0] 1.0b0
Result:
[0.0]
This differed from the expected result:
[0.0b0]
********************** Problem 270 ***************
Input:
1.0b0 [0.0]
Result:
[0.0]
This differed from the expected result:
[0.0b0]
********************** Problem 275 ***************
Input:
[0.0] [1.0b0]
Result:
[0.0]
This differed from the expected result:
[0.0b0]
********************** Problem 276 ***************
Input:
[1.0b0] [0.0]
Result:
[0.0]
This differed from the expected result:
[0.0b0]
Again a table: The following table is constructed the same way as the
tables from above. But now Maxima simplifies all multiplications as
shown.
/* Table 2.3: Multiplication of the number one
*
* TIMES | 1 1.0 1.0b0 [1] [1.0] [1.0b0]
* ---------------------------------------------------------
* 1 | 1 1.0 1.0b0 [1] [1.0] [1.0b0]
* 1.0 | 1.0 1.0 1.0b0 [1.0] [1.0] [1.0b0]
* 1.0b0 | 1.0b0 1.0b0 1.0b0 [1.0b0] [1.0b0] [1.0b0]
* [1] | [1] [1.0] [1.0b0] [1] [1.0] [1.0b0]
* [1.0] | [1.0] [1.0] [1.0b0] [1.0] [1.0] [1.0b0]
* [1.0b0] | [1.0b0] [1.0b0] [1.0b0] [1.0b0] [1.0b0] [1.0b0]
*/
I have some more tables and I have tried to go consistently through the
possible simplifications of the simplifier. We get much more trouble
with the tables which show the simplifications for the exponentiation.
Dieter Kaiser