| Alternative 1 | |
|---|---|
| Error | 51.7 |
| Cost | 576 |
\[1 + \frac{x - hi}{lo} \cdot -0.6666666666666666
\]
(FPCore (lo hi x) :precision binary64 (/ (- x lo) (- hi lo)))
(FPCore (lo hi x) :precision binary64 (pow (+ 1.0 (* -0.3333333333333333 (/ (- x hi) lo))) 2.0))
double code(double lo, double hi, double x) {
return (x - lo) / (hi - lo);
}
double code(double lo, double hi, double x) {
return pow((1.0 + (-0.3333333333333333 * ((x - hi) / lo))), 2.0);
}
real(8) function code(lo, hi, x)
real(8), intent (in) :: lo
real(8), intent (in) :: hi
real(8), intent (in) :: x
code = (x - lo) / (hi - lo)
end function
real(8) function code(lo, hi, x)
real(8), intent (in) :: lo
real(8), intent (in) :: hi
real(8), intent (in) :: x
code = (1.0d0 + ((-0.3333333333333333d0) * ((x - hi) / lo))) ** 2.0d0
end function
public static double code(double lo, double hi, double x) {
return (x - lo) / (hi - lo);
}
public static double code(double lo, double hi, double x) {
return Math.pow((1.0 + (-0.3333333333333333 * ((x - hi) / lo))), 2.0);
}
def code(lo, hi, x): return (x - lo) / (hi - lo)
def code(lo, hi, x): return math.pow((1.0 + (-0.3333333333333333 * ((x - hi) / lo))), 2.0)
function code(lo, hi, x) return Float64(Float64(x - lo) / Float64(hi - lo)) end
function code(lo, hi, x) return Float64(1.0 + Float64(-0.3333333333333333 * Float64(Float64(x - hi) / lo))) ^ 2.0 end
function tmp = code(lo, hi, x) tmp = (x - lo) / (hi - lo); end
function tmp = code(lo, hi, x) tmp = (1.0 + (-0.3333333333333333 * ((x - hi) / lo))) ^ 2.0; end
code[lo_, hi_, x_] := N[(N[(x - lo), $MachinePrecision] / N[(hi - lo), $MachinePrecision]), $MachinePrecision]
code[lo_, hi_, x_] := N[Power[N[(1.0 + N[(-0.3333333333333333 * N[(N[(x - hi), $MachinePrecision] / lo), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]
\frac{x - lo}{hi - lo}
{\left(1 + -0.3333333333333333 \cdot \frac{x - hi}{lo}\right)}^{2}
Results
Initial program 62.0
Simplified62.0
Taylor expanded in lo around inf 57.9
Simplified57.9
Applied egg-rr57.9
Taylor expanded in lo around inf 51.6
Taylor expanded in lo around -inf 49.1
Final simplification49.1
| Alternative 1 | |
|---|---|
| Error | 51.7 |
| Cost | 576 |
| Alternative 2 | |
|---|---|
| Error | 52.0 |
| Cost | 320 |
| Alternative 3 | |
|---|---|
| Error | 52.0 |
| Cost | 256 |
| Alternative 4 | |
|---|---|
| Error | 52.0 |
| Cost | 64 |

herbie shell --seed 2022296
(FPCore (lo hi x)
:name "(/ (- x lo) (- hi lo))"
:precision binary64
:pre (and (< lo -1e+308) (> hi 1e+308))
(/ (- x lo) (- hi lo)))