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

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


\end{array}

Error

Target

Original2.0
Target2.1
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 z < 1e15

    1. Initial program 1.7

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

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

    if 1e15 < z

    1. Initial program 3.8

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

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

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

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

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

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

Reproduce

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