我有一个浮点数类型的数组T
,其中T
可以是 float 或 double
T x[n];
这些数字是严格正数并排序的,即
0 < x[0] < x[1] < x[2] < ... < x[n-1]
我想找到最小的浮点数H
类型T
,以便严格满足以下不等式:
int(x[i+1]*H) > int(x[i]*H) // for i=0..n-2
让我们假设这些数字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) ) } ) )