Floating point 用整数数学求解严格不等式并考虑舍入误差
我有一个类型为Floating point 用整数数学求解严格不等式并考虑舍入误差,floating-point,precision,floating-accuracy,ieee-754,epsilon,Floating Point,Precision,Floating Accuracy,Ieee 754,Epsilon,我有一个类型为T的浮点数数组,其中T可以是浮点或双精度 T x[n]; 这些数字是严格的正数,并已排序,即 0 < x[0] < x[1] < x[2] < ... < x[n-1] 让我们假设数字x没有需要担心的下溢或溢出问题 我正在处理如下所述的问题,我不确定它是否健壮,并且,当它工作时,我认为会产生次优结果 有没有一种稳健而准确的方法来解决这个问题?我可以接受次优的解决方案,但至少它需要健壮。 我目前的方法 我使用符号m(x)表示接近x的浮点数,可能会受
T
的浮点数数组,其中T
可以是浮点或双精度
T x[n];
这些数字是严格的正数,并已排序,即
0 < x[0] < x[1] < x[2] < ... < x[n-1]
让我们假设数字x
没有需要担心的下溢或溢出问题
我正在处理如下所述的问题,我不确定它是否健壮,并且,当它工作时,我认为会产生次优结果
有没有一种稳健而准确的方法来解决这个问题?我可以接受次优的解决方案,但至少它需要健壮。
我目前的方法 我使用符号
m(x)
表示接近x
的浮点数,可能会受到舍入误差的影响。在下面的段落中,我修改了下面的不等式,适当地取上下界。请注意,以下内容不应解释为源代码,而应解释为获得最终方程式的数学步骤和推理
Let a(x) be the closest floating point number toward -inf
Let b(x) be the closest floating point number toward +inf
// Original inequality, where the operation affected by rounding error
// are marked with m()
int(m(x[i+1]*H)) > int(m(x[i]*H)) // for i=0..n-2
// I remove `atoi` subtracting and adding 0.5
// this is a conceptual operation, not actually executed on the machine,
// hence I do not mark it with an m()
m(x[i+1]*H) - 0.5 > m(x[i]*H) + 0.5 // for i=0..n-2
// I reorganize terms
m(x[i+1]*H) - m(x[i]*H) > 1.0 // for i=0..n-2
// I would like to resolve the m() operator with strict LHS minorant and RHS majorant
// Note I cannot use `a(x)` and `b(x)` because I do not know `H`
// I use multiplication by `(1+2*eps)` or `(1-2*eps)` as I hope this
// will result in a number strictly greater (or lower) than the original one.
// I already know this does not work for example if x is very small.
// So this seems like a pitfall of this approach.
x[i+1]*H(1-2*eps) - x[i]*H*(1+2*eps) > b(1) // for i=0..n-2
// solve the inequality for H, marking the operations affected by rounding
// with m()
H > m( b(1) / m( x[i+1](1-2*eps) - x[i]*(1+2*eps) ) ) // for i=0..n-2
// take majorant or minorant as appropriate for rounded terms
H > b( b(1) / a( x[i+1](1-2*eps) - x[i]*(1+2*eps) ) ) // for i=0..n-2
// and eventually take a majorant which gives me the final formula for H
H = b( b( b(1) / min{ a( x[i+1](1-2*eps) - x[i]*(1+2*eps) ) } ) )
这是什么语言?什么是原子?C/C++
atoi
函数将字符串转换为整数,因此它不能是整数。你所说的“主要”和“次要”是什么意思?通常的数学定义似乎不适合这里。我的错。对于atoi,我的意思是截断为整数。我纠正了这个问题。根据majorant和minorant,我的意思是majorant(a)>a和minorant(a)感谢您的更新!为了确保我理解:对于[0.99,1.0]
的示例输入数组,最佳输出将是H=1.0
,而您的方法生成的值接近H=100.0
。对吗?这是一个有趣的问题……没错!此外,我还不相信我的方法是可靠的。
Let a(x) be the closest floating point number toward -inf
Let b(x) be the closest floating point number toward +inf
// Original inequality, where the operation affected by rounding error
// are marked with m()
int(m(x[i+1]*H)) > int(m(x[i]*H)) // for i=0..n-2
// I remove `atoi` subtracting and adding 0.5
// this is a conceptual operation, not actually executed on the machine,
// hence I do not mark it with an m()
m(x[i+1]*H) - 0.5 > m(x[i]*H) + 0.5 // for i=0..n-2
// I reorganize terms
m(x[i+1]*H) - m(x[i]*H) > 1.0 // for i=0..n-2
// I would like to resolve the m() operator with strict LHS minorant and RHS majorant
// Note I cannot use `a(x)` and `b(x)` because I do not know `H`
// I use multiplication by `(1+2*eps)` or `(1-2*eps)` as I hope this
// will result in a number strictly greater (or lower) than the original one.
// I already know this does not work for example if x is very small.
// So this seems like a pitfall of this approach.
x[i+1]*H(1-2*eps) - x[i]*H*(1+2*eps) > b(1) // for i=0..n-2
// solve the inequality for H, marking the operations affected by rounding
// with m()
H > m( b(1) / m( x[i+1](1-2*eps) - x[i]*(1+2*eps) ) ) // for i=0..n-2
// take majorant or minorant as appropriate for rounded terms
H > b( b(1) / a( x[i+1](1-2*eps) - x[i]*(1+2*eps) ) ) // for i=0..n-2
// and eventually take a majorant which gives me the final formula for H
H = b( b( b(1) / min{ a( x[i+1](1-2*eps) - x[i]*(1+2*eps) ) } ) )