Average Error: 6.8 → 1.2
Time: 4.1s
Precision: binary64
\[x + \frac{\left(y - x\right) \cdot z}{t} \]
\[\begin{array}{l} t_1 := x + \frac{\left(y - x\right) \cdot z}{t}\\ t_2 := \mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\ \mathbf{if}\;t_1 \leq -6.575161590052845 \cdot 10^{+278}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 6.34035290608625 \cdot 10^{+257}:\\ \;\;\;\;\left(x + \frac{y \cdot z}{t}\right) - \frac{x \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (/ (* (- y x) z) t)))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (+ x (/ (* (- y x) z) t))) (t_2 (fma (- y x) (/ z t) x)))
   (if (<= t_1 -6.575161590052845e+278)
     t_2
     (if (<= t_1 6.34035290608625e+257)
       (- (+ x (/ (* y z) t)) (/ (* x z) t))
       t_2))))
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 = x + (((y - x) * z) / t);
	double t_2 = fma((y - x), (z / t), x);
	double tmp;
	if (t_1 <= -6.575161590052845e+278) {
		tmp = t_2;
	} else if (t_1 <= 6.34035290608625e+257) {
		tmp = (x + ((y * z) / t)) - ((x * z) / t);
	} else {
		tmp = t_2;
	}
	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 = Float64(x + Float64(Float64(Float64(y - x) * z) / t))
	t_2 = fma(Float64(y - x), Float64(z / t), x)
	tmp = 0.0
	if (t_1 <= -6.575161590052845e+278)
		tmp = t_2;
	elseif (t_1 <= 6.34035290608625e+257)
		tmp = Float64(Float64(x + Float64(Float64(y * z) / t)) - Float64(Float64(x * z) / t));
	else
		tmp = t_2;
	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[(x + N[(N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(y - x), $MachinePrecision] * N[(z / t), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[t$95$1, -6.575161590052845e+278], t$95$2, If[LessEqual[t$95$1, 6.34035290608625e+257], N[(N[(x + N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] - N[(N[(x * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], t$95$2]]]]
x + \frac{\left(y - x\right) \cdot z}{t}
\begin{array}{l}
t_1 := x + \frac{\left(y - x\right) \cdot z}{t}\\
t_2 := \mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\
\mathbf{if}\;t_1 \leq -6.575161590052845 \cdot 10^{+278}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq 6.34035290608625 \cdot 10^{+257}:\\
\;\;\;\;\left(x + \frac{y \cdot z}{t}\right) - \frac{x \cdot z}{t}\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original6.8
Target2.0
Herbie1.2
\[\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)) < -6.57516159005284458e278 or 6.34035290608625043e257 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t))

    1. Initial program 35.1

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

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

    if -6.57516159005284458e278 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < 6.34035290608625043e257

    1. Initial program 0.9

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

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

      \[\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 simplification1.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;x + \frac{\left(y - x\right) \cdot z}{t} \leq -6.575161590052845 \cdot 10^{+278}:\\ \;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\ \mathbf{elif}\;x + \frac{\left(y - x\right) \cdot z}{t} \leq 6.34035290608625 \cdot 10^{+257}:\\ \;\;\;\;\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 2022133 
(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)))