Average Error: 2.0 → 1.8
Time: 33.1s
Precision: binary64
\[x + \left(y - x\right) \cdot \frac{z}{t} \]
\[\begin{array}{l} t_1 := \mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\ \mathbf{if}\;t \leq -3.0549464306960693 \cdot 10^{+114}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.9957900418829807 \cdot 10^{-39}:\\ \;\;\;\;\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)))
   (if (<= t -3.0549464306960693e+114)
     t_1
     (if (<= t 1.9957900418829807e-39)
       (- (+ 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 tmp;
	if (t <= -3.0549464306960693e+114) {
		tmp = t_1;
	} else if (t <= 1.9957900418829807e-39) {
		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(y - x) * Float64(z / t)))
end
function code(x, y, z, t)
	t_1 = fma(Float64(y - x), Float64(z / t), x)
	tmp = 0.0
	if (t <= -3.0549464306960693e+114)
		tmp = t_1;
	elseif (t <= 1.9957900418829807e-39)
		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[(y - x), $MachinePrecision] * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(y - x), $MachinePrecision] * N[(z / t), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[t, -3.0549464306960693e+114], t$95$1, If[LessEqual[t, 1.9957900418829807e-39], N[(N[(x + N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision] - N[(N[(x * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
x + \left(y - x\right) \cdot \frac{z}{t}
\begin{array}{l}
t_1 := \mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\
\mathbf{if}\;t \leq -3.0549464306960693 \cdot 10^{+114}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t \leq 1.9957900418829807 \cdot 10^{-39}:\\
\;\;\;\;\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

Original2.0
Target2.2
Herbie1.8
\[\begin{array}{l} \mathbf{if}\;\left(y - x\right) \cdot \frac{z}{t} < -1013646692435.8867:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \mathbf{elif}\;\left(y - x\right) \cdot \frac{z}{t} < 0:\\ \;\;\;\;x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \end{array} \]

Derivation

  1. Split input into 2 regimes
  2. if t < -3.0549464306960693e114 or 1.99579004188298071e-39 < t

    1. Initial program 1.1

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

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

    if -3.0549464306960693e114 < t < 1.99579004188298071e-39

    1. Initial program 3.1

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)} \]
    3. Taylor expanded in y around 0 2.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 simplification1.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \leq -3.0549464306960693 \cdot 10^{+114}:\\ \;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\ \mathbf{elif}\;t \leq 1.9957900418829807 \cdot 10^{-39}:\\ \;\;\;\;\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 "Graphics.Rendering.Plot.Render.Plot.Axis:tickPosition from plot-0.2.3.4"
  :precision binary64

  :herbie-target
  (if (< (* (- y x) (/ z t)) -1013646692435.8867) (+ x (/ (- y x) (/ t z))) (if (< (* (- y x) (/ z t)) 0.0) (+ x (/ (* (- y x) z) t)) (+ x (/ (- y x) (/ t z)))))

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