Average Error: 6.2 → 1.0
Time: 3.8s
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(1, y \cdot \frac{z}{t}, x \cdot \left(1 - \frac{z}{t}\right)\right)\\ \mathbf{if}\;t_1 \leq -1.5169274143000037 \cdot 10^{+270}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 3.778364107257837 \cdot 10^{+282}:\\ \;\;\;\;\left(x + \frac{y \cdot z}{t}\right) + \left(x \cdot z\right) \cdot \frac{-1}{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 1.0 (* y (/ z t)) (* x (- 1.0 (/ z t))))))
   (if (<= t_1 -1.5169274143000037e+270)
     t_2
     (if (<= t_1 3.778364107257837e+282)
       (+ (+ x (/ (* y z) t)) (* (* x z) (/ -1.0 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(1.0, (y * (z / t)), (x * (1.0 - (z / t))));
	double tmp;
	if (t_1 <= -1.5169274143000037e+270) {
		tmp = t_2;
	} else if (t_1 <= 3.778364107257837e+282) {
		tmp = (x + ((y * z) / t)) + ((x * z) * (-1.0 / 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(1.0, Float64(y * Float64(z / t)), Float64(x * Float64(1.0 - Float64(z / t))))
	tmp = 0.0
	if (t_1 <= -1.5169274143000037e+270)
		tmp = t_2;
	elseif (t_1 <= 3.778364107257837e+282)
		tmp = Float64(Float64(x + Float64(Float64(y * z) / t)) + Float64(Float64(x * z) * Float64(-1.0 / 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[(1.0 * N[(y * N[(z / t), $MachinePrecision]), $MachinePrecision] + N[(x * N[(1.0 - N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1.5169274143000037e+270], t$95$2, If[LessEqual[t$95$1, 3.778364107257837e+282], N[(N[(x + N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] + N[(N[(x * z), $MachinePrecision] * N[(-1.0 / t), $MachinePrecision]), $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(1, y \cdot \frac{z}{t}, x \cdot \left(1 - \frac{z}{t}\right)\right)\\
\mathbf{if}\;t_1 \leq -1.5169274143000037 \cdot 10^{+270}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq 3.778364107257837 \cdot 10^{+282}:\\
\;\;\;\;\left(x + \frac{y \cdot z}{t}\right) + \left(x \cdot z\right) \cdot \frac{-1}{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.2
Target2.0
Herbie1.0
\[\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)) < -1.5169274143000037e270 or 3.77836410725783722e282 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t))

    1. Initial program 38.7

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

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

      \[\leadsto \color{blue}{\left(\frac{y \cdot z}{t} + x\right) - \frac{z \cdot x}{t}} \]
    4. Applied egg-rr26.0

      \[\leadsto \left(\frac{y \cdot z}{t} + x\right) - \color{blue}{x \cdot \left(z \cdot \frac{1}{t}\right)} \]
    5. Applied egg-rr2.4

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

    if -1.5169274143000037e270 < (+.f64 x (/.f64 (*.f64 (-.f64 y x) z) t)) < 3.77836410725783722e282

    1. Initial program 0.7

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

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

      \[\leadsto \color{blue}{\left(\frac{y \cdot z}{t} + x\right) - \frac{z \cdot x}{t}} \]
    4. Applied egg-rr0.8

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

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

Reproduce

herbie shell --seed 2022150 
(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)))