浮点乘积扩展等价 [英] floating point product expansion equivalence

查看:149
本文介绍了浮点乘积扩展等价的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在IEEE 754浮点上,有可能是

$ $ $ $ $ c $ a *(bc)!= a * ba * c / / a,b,c double

因此,产品的扩展不能保证等于未扩展产品。



但这又如何:

  a *(b1 + b2 + ... + bn)== a * b1 + a * b2 + ... + a * bn // b1 == b2 == ... == bn 

当所有 b 相等时,是等价保证的(在没有欠/溢出的情况下)?如果在编译时已知或

编辑:



这不是 - 见Eric Postpischil和Pascal Cuoq。 >但是也许持有较弱的断言?:

 (1.0 / n)*(b1 + b2 + ... + bn)< ; = 1.0 
&& (1.0 / n)* b1 +(1.0 / n)* b2 + ... +(1.0 / n)* bn <= 1.0

//当所有b <不是2
的功率//所以1.0 / n不能完全用base-2浮点数表示



我只是想知道,是否可以保证数据集的平均值不超过每个
数据值也不超过的某个值,无论你如何计算平均值(首先加法和一次除法,或者加上每一个除数)。

Edit2:



好的,&& 不成立。见Eric Postpischil和David Hammen:

 平均值为9的1.0  - >只有第一个条件是真的,第二个超过。 
平均十个1.0 / 3 - >只有第二个条件是真的,第一个超过。

然后是计算上期望的平均依赖性的 optimal 方法数据集的限制?还是数据集的大小(即 n )?或者,有没有最佳的方法肯定存在?

解决方案

即使排除溢出和下溢,结果可能

.3 *(.3 + .3 + .3) 0.269999999999999962252417162744677625596523284912109375
.3 * .3 + .3 * .3 + .3 * .3 0.270000000000000017763568394002504646778106689453125 (当两者都使用IEEE-754规则和64位二进制浮点进行评估时)。



关于更新中添加的问题:

有两个问题,其中一个问是否计算出的每个不超过1的数字的平均值是否可以超过1。正如 David Hammon指出的那样,计算九个1的平均值为 1./9*1 + 1./9*1 + 1./9*1 + 1./9*1 + 1./9*1 + 1./9*1 + 1./9*1 + 1./9*1 + 1 ./9*1 产生1.0000000000000002220446049250313080847263336181640625。



另一个问题是,一个集合的计算平均值是否可以超过集合中的所有数字。这是第一个问题的超集,但是这里是一个使用不同的平均值计算的例子:

让b = 1./3 (即0.333333333333333314829616256247390992939472198486328125)。
$ b $ 然后 1.10 *(b + b + b + b + b + b + b + b + b + b)是0.33333333333333337034076748750521801412105560302734375,它大于 b


In IEEE 754 floating point, it is possible that

a*(b-c) != a*b-a*c // a, b, c double

So expansion of a product is not guaranteed to be equal to the unexpanded product.

But what about this:

a*(b1+b2+...+bn) == a*b1+a*b2+...+a*bn // b1==b2==...==bn

When all b equal, is equivalence guaranteed (in case of no under-/overflow)? Is there a difference if equality of b is known at compile time or not?

Edit:

It is not - see Eric Postpischil and Pascal Cuoq.

But maybe holds the weaker assertion?:

   (1.0/n)*(b1+b2+...+bn) <= 1.0
&& (1.0/n)*b1+(1.0/n)*b2+...+(1.0/n)*bn <= 1.0

// when all b<=1.0 and n integral double but not power of 2
// so that 1.0/n not exactly representable with base-2 floating point

I simply wonder if you can guarantee that the average of a data set does not exceed some value that is also not exceeded by every single data value, no matter how you compute the average (first adding and once dividing, or adding every value divided).

Edit2:

Ok, the && doesn't hold. See Eric Postpischil and David Hammen:

average of nine 1.0 -> only first condition is true, second exceeds.
average of ten 1.0/3 -> only second condition is true, first exceeds.

Is then the optimal method of computation of an average dependent of upper expected limit of data set? Or also of size (that means n) of data set? Or is there no optimal method surely existing?

解决方案

Even excluding overflow and underflow, the results may differ.

.3 * (.3+.3+.3) is 0.269999999999999962252417162744677625596523284912109375 while .3*.3 + .3*.3 + .3*.3 is 0.270000000000000017763568394002504646778106689453125 (when both are evaluated with IEEE-754 rules and 64-bit binary floating-point).

Regarding the questions added in an update:

There are two questions, one of which asks whether the computed average of a set of numbers each not exceeding one can exceed one. As David Hammon points out, calculating the average of nine 1s as 1./9*1 + 1./9*1 + 1./9*1 + 1./9*1 + 1./9*1 + 1./9*1 + 1./9*1 + 1./9*1 + 1./9*1 produces 1.0000000000000002220446049250313080847263336181640625.

The other asks whether the computed average of a set can exceed all of the numbers in the set. This is a superset of the first question, but here is an example using a different calculation of the average:

Let b = 1./3 (which is 0.333333333333333314829616256247390992939472198486328125).

Then 1./10 * (b+b+b+b+b+b+b+b+b+b) is 0.33333333333333337034076748750521801412105560302734375, which is greater than b.

这篇关于浮点乘积扩展等价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆