Average Error: 62.0 → 51.5
Time: 2.9s
Precision: binary64
\[lo < -1 \cdot 10^{+308} \land hi > 10^{+308}\]
\[\frac{x - lo}{hi - lo} \]
\[\begin{array}{l} t_0 := \sqrt[3]{\frac{hi}{lo}}\\ 1 + \sqrt{{\left(\mathsf{fma}\left(\mathsf{expm1}\left(\mathsf{log1p}\left({t_0}^{2}\right)\right), t_0, 1\right)\right)}^{2}} \cdot \frac{hi - x}{lo} \end{array} \]
(FPCore (lo hi x) :precision binary64 (/ (- x lo) (- hi lo)))
(FPCore (lo hi x)
 :precision binary64
 (let* ((t_0 (cbrt (/ hi lo))))
   (+
    1.0
    (*
     (sqrt (pow (fma (expm1 (log1p (pow t_0 2.0))) t_0 1.0) 2.0))
     (/ (- hi x) lo)))))
double code(double lo, double hi, double x) {
	return (x - lo) / (hi - lo);
}
double code(double lo, double hi, double x) {
	double t_0 = cbrt((hi / lo));
	return 1.0 + (sqrt(pow(fma(expm1(log1p(pow(t_0, 2.0))), t_0, 1.0), 2.0)) * ((hi - x) / lo));
}
function code(lo, hi, x)
	return Float64(Float64(x - lo) / Float64(hi - lo))
end
function code(lo, hi, x)
	t_0 = cbrt(Float64(hi / lo))
	return Float64(1.0 + Float64(sqrt((fma(expm1(log1p((t_0 ^ 2.0))), t_0, 1.0) ^ 2.0)) * Float64(Float64(hi - x) / lo)))
end
code[lo_, hi_, x_] := N[(N[(x - lo), $MachinePrecision] / N[(hi - lo), $MachinePrecision]), $MachinePrecision]
code[lo_, hi_, x_] := Block[{t$95$0 = N[Power[N[(hi / lo), $MachinePrecision], 1/3], $MachinePrecision]}, N[(1.0 + N[(N[Sqrt[N[Power[N[(N[(Exp[N[Log[1 + N[Power[t$95$0, 2.0], $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision] * t$95$0 + 1.0), $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision] * N[(N[(hi - x), $MachinePrecision] / lo), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{x - lo}{hi - lo}
\begin{array}{l}
t_0 := \sqrt[3]{\frac{hi}{lo}}\\
1 + \sqrt{{\left(\mathsf{fma}\left(\mathsf{expm1}\left(\mathsf{log1p}\left({t_0}^{2}\right)\right), t_0, 1\right)\right)}^{2}} \cdot \frac{hi - x}{lo}
\end{array}

Error

Bits error versus lo

Bits error versus hi

Bits error versus x

Derivation

  1. Initial program 62.0

    \[\frac{x - lo}{hi - lo} \]
  2. Taylor expanded in lo around inf 64.0

    \[\leadsto \color{blue}{\left(\frac{\left(-1 \cdot x - -1 \cdot hi\right) \cdot hi}{{lo}^{2}} + \left(1 + -1 \cdot \frac{x}{lo}\right)\right) - -1 \cdot \frac{hi}{lo}} \]
  3. Simplified51.9

    \[\leadsto \color{blue}{1 + \left(\frac{hi}{lo} + 1\right) \cdot \frac{hi - x}{lo}} \]
  4. Applied egg-rr51.5

    \[\leadsto 1 + \color{blue}{\sqrt{{\left(\frac{hi}{lo} + 1\right)}^{2}}} \cdot \frac{hi - x}{lo} \]
  5. Applied egg-rr51.5

    \[\leadsto 1 + \sqrt{{\color{blue}{\left(\mathsf{fma}\left({\left(\sqrt[3]{\frac{hi}{lo}}\right)}^{2}, \sqrt[3]{\frac{hi}{lo}}, 1\right)\right)}}^{2}} \cdot \frac{hi - x}{lo} \]
  6. Applied egg-rr51.5

    \[\leadsto 1 + \sqrt{{\left(\mathsf{fma}\left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({\left(\sqrt[3]{\frac{hi}{lo}}\right)}^{2}\right)\right)}, \sqrt[3]{\frac{hi}{lo}}, 1\right)\right)}^{2}} \cdot \frac{hi - x}{lo} \]
  7. Final simplification51.5

    \[\leadsto 1 + \sqrt{{\left(\mathsf{fma}\left(\mathsf{expm1}\left(\mathsf{log1p}\left({\left(\sqrt[3]{\frac{hi}{lo}}\right)}^{2}\right)\right), \sqrt[3]{\frac{hi}{lo}}, 1\right)\right)}^{2}} \cdot \frac{hi - x}{lo} \]

Reproduce

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