Average Error: 2.0 → 1.8
Time: 4.3s
Precision: binary64
\[x + \left(y - x\right) \cdot \frac{z}{t} \]
\[\begin{array}{l} \mathbf{if}\;t \leq -1.7058464213464965 \cdot 10^{+61}:\\ \;\;\;\;x + z \cdot \frac{1}{\frac{t}{y - x}}\\ \mathbf{elif}\;t \leq -9.888058153974043 \cdot 10^{-263}:\\ \;\;\;\;\mathsf{fma}\left(z \cdot \left(y - x\right), \frac{1}{t}, x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (* (- y x) (/ z t))))
(FPCore (x y z t)
 :precision binary64
 (if (<= t -1.7058464213464965e+61)
   (+ x (* z (/ 1.0 (/ t (- y x)))))
   (if (<= t -9.888058153974043e-263)
     (fma (* z (- y x)) (/ 1.0 t) x)
     (fma (- y x) (/ z t) x))))
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 tmp;
	if (t <= -1.7058464213464965e+61) {
		tmp = x + (z * (1.0 / (t / (y - x))));
	} else if (t <= -9.888058153974043e-263) {
		tmp = fma((z * (y - x)), (1.0 / t), x);
	} else {
		tmp = fma((y - x), (z / t), x);
	}
	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)
	tmp = 0.0
	if (t <= -1.7058464213464965e+61)
		tmp = Float64(x + Float64(z * Float64(1.0 / Float64(t / Float64(y - x)))));
	elseif (t <= -9.888058153974043e-263)
		tmp = fma(Float64(z * Float64(y - x)), Float64(1.0 / t), x);
	else
		tmp = fma(Float64(y - x), Float64(z / t), x);
	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_] := If[LessEqual[t, -1.7058464213464965e+61], N[(x + N[(z * N[(1.0 / N[(t / N[(y - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, -9.888058153974043e-263], N[(N[(z * N[(y - x), $MachinePrecision]), $MachinePrecision] * N[(1.0 / t), $MachinePrecision] + x), $MachinePrecision], N[(N[(y - x), $MachinePrecision] * N[(z / t), $MachinePrecision] + x), $MachinePrecision]]]
x + \left(y - x\right) \cdot \frac{z}{t}
\begin{array}{l}
\mathbf{if}\;t \leq -1.7058464213464965 \cdot 10^{+61}:\\
\;\;\;\;x + z \cdot \frac{1}{\frac{t}{y - x}}\\

\mathbf{elif}\;t \leq -9.888058153974043 \cdot 10^{-263}:\\
\;\;\;\;\mathsf{fma}\left(z \cdot \left(y - x\right), \frac{1}{t}, x\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)\\


\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 3 regimes
  2. if t < -1.7058464213464965e61

    1. Initial program 1.2

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

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

      \[\leadsto \color{blue}{\left(y - x\right) \cdot \frac{z}{t} + x} \]
    4. Simplified1.3

      \[\leadsto \color{blue}{z \cdot \frac{y - x}{t}} + x \]
    5. Applied clear-num_binary641.4

      \[\leadsto z \cdot \color{blue}{\frac{1}{\frac{t}{y - x}}} + x \]

    if -1.7058464213464965e61 < t < -9.8880581539740433e-263

    1. Initial program 2.9

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

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

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

      \[\leadsto \color{blue}{z \cdot \frac{y - x}{t}} + x \]
    5. Applied div-inv_binary6410.5

      \[\leadsto z \cdot \color{blue}{\left(\left(y - x\right) \cdot \frac{1}{t}\right)} + x \]
    6. Applied associate-*r*_binary641.9

      \[\leadsto \color{blue}{\left(z \cdot \left(y - x\right)\right) \cdot \frac{1}{t}} + x \]
    7. Applied fma-def_binary641.9

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

    if -9.8880581539740433e-263 < t

    1. Initial program 2.0

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y - x, \frac{z}{t}, x\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.8

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

Reproduce

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