Average Error: 6.4 → 0.8
Time: 33.0s
Precision: binary64
\[x + \frac{\left(y - x\right) \cdot z}{t} \]
\[\begin{array}{l} t_1 := \mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\ t_2 := x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 9.26477070805321 \cdot 10^{+301}:\\ \;\;\;\;\left(x + \frac{y \cdot z}{t}\right) - \frac{x \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (/ (* (- y x) z) t)))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (fma (- y x) (/ z t) x)) (t_2 (+ x (/ (* (- y x) z) t))))
   (if (<= t_2 (- INFINITY))
     t_1
     (if (<= t_2 9.26477070805321e+301)
       (- (+ x (/ (* y z) t)) (/ (* x z) t))
       t_1))))
double code(double x, double y, double z, double t) {
	return x + (((y - x) * z) / t);
}
double code(double x, double y, double z, double t) {
	double t_1 = fma((y - x), (z / t), x);
	double t_2 = x + (((y - x) * z) / t);
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = t_1;
	} else if (t_2 <= 9.26477070805321e+301) {
		tmp = (x + ((y * z) / t)) - ((x * z) / t);
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z, t)
	return Float64(x + Float64(Float64(Float64(y - x) * z) / t))
end
function code(x, y, z, t)
	t_1 = fma(Float64(y - x), Float64(z / t), x)
	t_2 = Float64(x + Float64(Float64(Float64(y - x) * z) / t))
	tmp = 0.0
	if (t_2 <= Float64(-Inf))
		tmp = t_1;
	elseif (t_2 <= 9.26477070805321e+301)
		tmp = Float64(Float64(x + Float64(Float64(y * z) / t)) - Float64(Float64(x * z) / t));
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_, t_] := N[(x + N[(N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(y - x), $MachinePrecision] * N[(z / t), $MachinePrecision] + x), $MachinePrecision]}, Block[{t$95$2 = N[(x + N[(N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], t$95$1, If[LessEqual[t$95$2, 9.26477070805321e+301], N[(N[(x + N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] - N[(N[(x * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
x + \frac{\left(y - x\right) \cdot z}{t}
\begin{array}{l}
t_1 := \mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\
t_2 := x + \frac{\left(y - x\right) \cdot z}{t}\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_2 \leq 9.26477070805321 \cdot 10^{+301}:\\
\;\;\;\;\left(x + \frac{y \cdot z}{t}\right) - \frac{x \cdot z}{t}\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original6.4
Target1.9
Herbie0.8
\[\begin{array}{l} \mathbf{if}\;x < -9.025511195533005 \cdot 10^{-135}:\\ \;\;\;\;x - \frac{z}{t} \cdot \left(x - y\right)\\ \mathbf{elif}\;x < 4.275032163700715 \cdot 10^{-250}:\\ \;\;\;\;x + \frac{y - x}{t} \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < -inf.0 or 9.26477070805321052e301 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t))

    1. Initial program 61.2

      \[x + \frac{\left(y - x\right) \cdot z}{t} \]
    2. Simplified0.3

      \[\leadsto \color{blue}{\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)} \]

    if -inf.0 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < 9.26477070805321052e301

    1. Initial program 0.8

      \[x + \frac{\left(y - x\right) \cdot z}{t} \]
    2. Simplified2.1

      \[\leadsto \color{blue}{\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)} \]
    3. Taylor expanded in y around 0 0.8

      \[\leadsto \color{blue}{\left(\frac{y \cdot z}{t} + x\right) - \frac{z \cdot x}{t}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;x + \frac{\left(y - x\right) \cdot z}{t} \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\ \mathbf{elif}\;x + \frac{\left(y - x\right) \cdot z}{t} \leq 9.26477070805321 \cdot 10^{+301}:\\ \;\;\;\;\left(x + \frac{y \cdot z}{t}\right) - \frac{x \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022131 
(FPCore (x y z t)
  :name "Numeric.Histogram:binBounds from Chart-1.5.3"
  :precision binary64

  :herbie-target
  (if (< x -9.025511195533005e-135) (- x (* (/ z t) (- x y))) (if (< x 4.275032163700715e-250) (+ x (* (/ (- y x) t) z)) (+ x (/ (- y x) (/ t z)))))

  (+ x (/ (* (- y x) z) t)))