Average Error: 62.0 → 52.0
Time: 3.6s
Precision: binary64
\[lo < -1 \cdot 10^{+308} \land hi > 10^{+308}\]
\[\frac{x - lo}{hi - lo} \]
\[\begin{array}{l} t_0 := \frac{x}{hi} - 1\\ t_1 := \sqrt[3]{\frac{lo \cdot t_0}{hi}}\\ \left(t_1 \cdot t_1\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\sqrt[3]{t_0 \cdot \frac{lo}{hi}}\right)\right) \end{array} \]
\frac{x - lo}{hi - lo}
\begin{array}{l}
t_0 := \frac{x}{hi} - 1\\
t_1 := \sqrt[3]{\frac{lo \cdot t_0}{hi}}\\
\left(t_1 \cdot t_1\right) \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\sqrt[3]{t_0 \cdot \frac{lo}{hi}}\right)\right)
\end{array}
(FPCore (lo hi x) :precision binary64 (/ (- x lo) (- hi lo)))
(FPCore (lo hi x)
 :precision binary64
 (let* ((t_0 (- (/ x hi) 1.0)) (t_1 (cbrt (/ (* lo t_0) hi))))
   (* (* t_1 t_1) (log1p (expm1 (cbrt (* t_0 (/ lo hi))))))))
double code(double lo, double hi, double x) {
	return (x - lo) / (hi - lo);
}
double code(double lo, double hi, double x) {
	double t_0 = (x / hi) - 1.0;
	double t_1 = cbrt((lo * t_0) / hi);
	return (t_1 * t_1) * log1p(expm1(cbrt(t_0 * (lo / hi))));
}

Error

Bits error versus lo

Bits error versus hi

Bits error versus x

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 62.0

    \[\frac{x - lo}{hi - lo} \]
  2. Taylor expanded around 0 58.0

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{x}{hi}, \frac{lo}{hi}, \frac{x - lo}{hi}\right)} \]
  4. Taylor expanded around inf 52.0

    \[\leadsto \color{blue}{lo \cdot \left(\frac{x}{{hi}^{2}} - \frac{1}{hi}\right)} \]
  5. Simplified52.0

    \[\leadsto \color{blue}{\frac{lo}{hi} \cdot \left(\frac{x}{hi} + -1\right)} \]
  6. Using strategy rm
  7. Applied add-cube-cbrt_binary6452.0

    \[\leadsto \color{blue}{\left(\sqrt[3]{\frac{lo}{hi} \cdot \left(\frac{x}{hi} + -1\right)} \cdot \sqrt[3]{\frac{lo}{hi} \cdot \left(\frac{x}{hi} + -1\right)}\right) \cdot \sqrt[3]{\frac{lo}{hi} \cdot \left(\frac{x}{hi} + -1\right)}} \]
  8. Simplified52.0

    \[\leadsto \color{blue}{\left(\sqrt[3]{\frac{lo \cdot \left(\frac{x}{hi} - 1\right)}{hi}} \cdot \sqrt[3]{\frac{lo \cdot \left(\frac{x}{hi} - 1\right)}{hi}}\right)} \cdot \sqrt[3]{\frac{lo}{hi} \cdot \left(\frac{x}{hi} + -1\right)} \]
  9. Simplified52.0

    \[\leadsto \left(\sqrt[3]{\frac{lo \cdot \left(\frac{x}{hi} - 1\right)}{hi}} \cdot \sqrt[3]{\frac{lo \cdot \left(\frac{x}{hi} - 1\right)}{hi}}\right) \cdot \color{blue}{\sqrt[3]{\frac{lo \cdot \left(\frac{x}{hi} - 1\right)}{hi}}} \]
  10. Using strategy rm
  11. Applied log1p-expm1-u_binary6452.0

    \[\leadsto \left(\sqrt[3]{\frac{lo \cdot \left(\frac{x}{hi} - 1\right)}{hi}} \cdot \sqrt[3]{\frac{lo \cdot \left(\frac{x}{hi} - 1\right)}{hi}}\right) \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\sqrt[3]{\frac{lo \cdot \left(\frac{x}{hi} - 1\right)}{hi}}\right)\right)} \]
  12. Simplified52.0

    \[\leadsto \left(\sqrt[3]{\frac{lo \cdot \left(\frac{x}{hi} - 1\right)}{hi}} \cdot \sqrt[3]{\frac{lo \cdot \left(\frac{x}{hi} - 1\right)}{hi}}\right) \cdot \mathsf{log1p}\left(\color{blue}{\mathsf{expm1}\left(\sqrt[3]{\left(\frac{x}{hi} - 1\right) \cdot \frac{lo}{hi}}\right)}\right) \]
  13. Final simplification52.0

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

Reproduce

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