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]{1 + {\left(\frac{lo}{hi}\right)}^{3}}\\ \frac{x}{hi} \cdot \left(\frac{lo}{hi} \cdot \left(\frac{lo}{hi} + 1\right)\right) + \left(\frac{x - lo}{hi} - \sqrt{{\log \left(\left(1 + \mathsf{expm1}\left(\mathsf{fma}\left(t_0 \cdot t_0, t_0, -1\right)\right)\right) \cdot \left(1 + \mathsf{expm1}\left({\left(\frac{lo}{hi}\right)}^{2}\right)\right)\right)}^{2}}\right) \end{array} \]
(FPCore (lo hi x) :precision binary64 (/ (- x lo) (- hi lo)))
(FPCore (lo hi x)
 :precision binary64
 (let* ((t_0 (cbrt (+ 1.0 (pow (/ lo hi) 3.0)))))
   (+
    (* (/ x hi) (* (/ lo hi) (+ (/ lo hi) 1.0)))
    (-
     (/ (- x lo) hi)
     (sqrt
      (pow
       (log
        (*
         (+ 1.0 (expm1 (fma (* t_0 t_0) t_0 -1.0)))
         (+ 1.0 (expm1 (pow (/ lo hi) 2.0)))))
       2.0))))))
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((1.0 + pow((lo / hi), 3.0)));
	return ((x / hi) * ((lo / hi) * ((lo / hi) + 1.0))) + (((x - lo) / hi) - sqrt(pow(log(((1.0 + expm1(fma((t_0 * t_0), t_0, -1.0))) * (1.0 + expm1(pow((lo / hi), 2.0))))), 2.0)));
}
function code(lo, hi, x)
	return Float64(Float64(x - lo) / Float64(hi - lo))
end
function code(lo, hi, x)
	t_0 = cbrt(Float64(1.0 + (Float64(lo / hi) ^ 3.0)))
	return Float64(Float64(Float64(x / hi) * Float64(Float64(lo / hi) * Float64(Float64(lo / hi) + 1.0))) + Float64(Float64(Float64(x - lo) / hi) - sqrt((log(Float64(Float64(1.0 + expm1(fma(Float64(t_0 * t_0), t_0, -1.0))) * Float64(1.0 + expm1((Float64(lo / hi) ^ 2.0))))) ^ 2.0))))
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[(1.0 + N[Power[N[(lo / hi), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, N[(N[(N[(x / hi), $MachinePrecision] * N[(N[(lo / hi), $MachinePrecision] * N[(N[(lo / hi), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(x - lo), $MachinePrecision] / hi), $MachinePrecision] - N[Sqrt[N[Power[N[Log[N[(N[(1.0 + N[(Exp[N[(N[(t$95$0 * t$95$0), $MachinePrecision] * t$95$0 + -1.0), $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(Exp[N[Power[N[(lo / hi), $MachinePrecision], 2.0], $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{x - lo}{hi - lo}
\begin{array}{l}
t_0 := \sqrt[3]{1 + {\left(\frac{lo}{hi}\right)}^{3}}\\
\frac{x}{hi} \cdot \left(\frac{lo}{hi} \cdot \left(\frac{lo}{hi} + 1\right)\right) + \left(\frac{x - lo}{hi} - \sqrt{{\log \left(\left(1 + \mathsf{expm1}\left(\mathsf{fma}\left(t_0 \cdot t_0, t_0, -1\right)\right)\right) \cdot \left(1 + \mathsf{expm1}\left({\left(\frac{lo}{hi}\right)}^{2}\right)\right)\right)}^{2}}\right)
\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 hi around inf 64.0

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

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

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

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

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

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

Reproduce

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