Average Error: 16.6 → 4.7
Time: 6.1s
Precision: binary64
\[\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t} \]
\[\begin{array}{l} t_1 := x + \left(1 + \frac{a}{t}\right) \cdot \left(\frac{y}{t} \cdot \left(z - a\right)\right)\\ t_2 := \left(x + y\right) + \frac{y \cdot \left(t - z\right)}{a - t}\\ t_3 := x - \left(\left(\frac{y \cdot t}{t - a} - y\right) - \frac{y \cdot z}{t - a}\right)\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq -5 \cdot 10^{+149}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_2 \leq -5 \cdot 10^{-283}:\\ \;\;\;\;x + \mathsf{fma}\left(y, \frac{z - t}{t - a}, y\right)\\ \mathbf{elif}\;t_2 \leq 0:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 10^{+299}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(\left(1 + \frac{z}{t - a}\right) - \frac{t}{t - a}\right)\\ \end{array} \]
(FPCore (x y z t a) :precision binary64 (- (+ x y) (/ (* (- z t) y) (- a t))))
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (+ x (* (+ 1.0 (/ a t)) (* (/ y t) (- z a)))))
        (t_2 (+ (+ x y) (/ (* y (- t z)) (- a t))))
        (t_3 (- x (- (- (/ (* y t) (- t a)) y) (/ (* y z) (- t a))))))
   (if (<= t_2 (- INFINITY))
     t_1
     (if (<= t_2 -5e+149)
       t_3
       (if (<= t_2 -5e-283)
         (+ x (fma y (/ (- z t) (- t a)) y))
         (if (<= t_2 0.0)
           t_1
           (if (<= t_2 1e+299)
             t_3
             (+ x (* y (- (+ 1.0 (/ z (- t a))) (/ t (- t a))))))))))))
double code(double x, double y, double z, double t, double a) {
	return (x + y) - (((z - t) * y) / (a - t));
}
double code(double x, double y, double z, double t, double a) {
	double t_1 = x + ((1.0 + (a / t)) * ((y / t) * (z - a)));
	double t_2 = (x + y) + ((y * (t - z)) / (a - t));
	double t_3 = x - ((((y * t) / (t - a)) - y) - ((y * z) / (t - a)));
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = t_1;
	} else if (t_2 <= -5e+149) {
		tmp = t_3;
	} else if (t_2 <= -5e-283) {
		tmp = x + fma(y, ((z - t) / (t - a)), y);
	} else if (t_2 <= 0.0) {
		tmp = t_1;
	} else if (t_2 <= 1e+299) {
		tmp = t_3;
	} else {
		tmp = x + (y * ((1.0 + (z / (t - a))) - (t / (t - a))));
	}
	return tmp;
}
function code(x, y, z, t, a)
	return Float64(Float64(x + y) - Float64(Float64(Float64(z - t) * y) / Float64(a - t)))
end
function code(x, y, z, t, a)
	t_1 = Float64(x + Float64(Float64(1.0 + Float64(a / t)) * Float64(Float64(y / t) * Float64(z - a))))
	t_2 = Float64(Float64(x + y) + Float64(Float64(y * Float64(t - z)) / Float64(a - t)))
	t_3 = Float64(x - Float64(Float64(Float64(Float64(y * t) / Float64(t - a)) - y) - Float64(Float64(y * z) / Float64(t - a))))
	tmp = 0.0
	if (t_2 <= Float64(-Inf))
		tmp = t_1;
	elseif (t_2 <= -5e+149)
		tmp = t_3;
	elseif (t_2 <= -5e-283)
		tmp = Float64(x + fma(y, Float64(Float64(z - t) / Float64(t - a)), y));
	elseif (t_2 <= 0.0)
		tmp = t_1;
	elseif (t_2 <= 1e+299)
		tmp = t_3;
	else
		tmp = Float64(x + Float64(y * Float64(Float64(1.0 + Float64(z / Float64(t - a))) - Float64(t / Float64(t - a)))));
	end
	return tmp
end
code[x_, y_, z_, t_, a_] := N[(N[(x + y), $MachinePrecision] - N[(N[(N[(z - t), $MachinePrecision] * y), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(x + N[(N[(1.0 + N[(a / t), $MachinePrecision]), $MachinePrecision] * N[(N[(y / t), $MachinePrecision] * N[(z - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x + y), $MachinePrecision] + N[(N[(y * N[(t - z), $MachinePrecision]), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(x - N[(N[(N[(N[(y * t), $MachinePrecision] / N[(t - a), $MachinePrecision]), $MachinePrecision] - y), $MachinePrecision] - N[(N[(y * z), $MachinePrecision] / N[(t - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], t$95$1, If[LessEqual[t$95$2, -5e+149], t$95$3, If[LessEqual[t$95$2, -5e-283], N[(x + N[(y * N[(N[(z - t), $MachinePrecision] / N[(t - a), $MachinePrecision]), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.0], t$95$1, If[LessEqual[t$95$2, 1e+299], t$95$3, N[(x + N[(y * N[(N[(1.0 + N[(z / N[(t - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(t / N[(t - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]
\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\begin{array}{l}
t_1 := x + \left(1 + \frac{a}{t}\right) \cdot \left(\frac{y}{t} \cdot \left(z - a\right)\right)\\
t_2 := \left(x + y\right) + \frac{y \cdot \left(t - z\right)}{a - t}\\
t_3 := x - \left(\left(\frac{y \cdot t}{t - a} - y\right) - \frac{y \cdot z}{t - a}\right)\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_2 \leq -5 \cdot 10^{+149}:\\
\;\;\;\;t_3\\

\mathbf{elif}\;t_2 \leq -5 \cdot 10^{-283}:\\
\;\;\;\;x + \mathsf{fma}\left(y, \frac{z - t}{t - a}, y\right)\\

\mathbf{elif}\;t_2 \leq 0:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_2 \leq 10^{+299}:\\
\;\;\;\;t_3\\

\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(\left(1 + \frac{z}{t - a}\right) - \frac{t}{t - a}\right)\\


\end{array}

Error

Target

Original16.6
Target9.0
Herbie4.7
\[\begin{array}{l} \mathbf{if}\;\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t} < -1.3664970889390727 \cdot 10^{-7}:\\ \;\;\;\;\left(y + x\right) - \left(\left(z - t\right) \cdot \frac{1}{a - t}\right) \cdot y\\ \mathbf{elif}\;\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t} < 1.4754293444577233 \cdot 10^{-239}:\\ \;\;\;\;\frac{y \cdot \left(a - z\right) - x \cdot t}{a - t}\\ \mathbf{else}:\\ \;\;\;\;\left(y + x\right) - \left(\left(z - t\right) \cdot \frac{1}{a - t}\right) \cdot y\\ \end{array} \]

Derivation

  1. Split input into 4 regimes
  2. if (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) < -inf.0 or -5.0000000000000001e-283 < (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) < 0.0

    1. Initial program 62.4

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

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

      \[\leadsto x + \color{blue}{\left(y + \left(\frac{y \cdot \left(z - a\right)}{t} + \left(-1 \cdot y + \frac{a \cdot \left(y \cdot \left(z - a\right)\right)}{{t}^{2}}\right)\right)\right)} \]
    4. Simplified14.0

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

    if -inf.0 < (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) < -4.9999999999999999e149 or 0.0 < (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) < 1.0000000000000001e299

    1. Initial program 1.3

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

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

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

    if -4.9999999999999999e149 < (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t))) < -5.0000000000000001e-283

    1. Initial program 1.7

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

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

    if 1.0000000000000001e299 < (-.f64 (+.f64 x y) (/.f64 (*.f64 (-.f64 z t) y) (-.f64 a t)))

    1. Initial program 58.3

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(x + y\right) + \frac{y \cdot \left(t - z\right)}{a - t} \leq -\infty:\\ \;\;\;\;x + \left(1 + \frac{a}{t}\right) \cdot \left(\frac{y}{t} \cdot \left(z - a\right)\right)\\ \mathbf{elif}\;\left(x + y\right) + \frac{y \cdot \left(t - z\right)}{a - t} \leq -5 \cdot 10^{+149}:\\ \;\;\;\;x - \left(\left(\frac{y \cdot t}{t - a} - y\right) - \frac{y \cdot z}{t - a}\right)\\ \mathbf{elif}\;\left(x + y\right) + \frac{y \cdot \left(t - z\right)}{a - t} \leq -5 \cdot 10^{-283}:\\ \;\;\;\;x + \mathsf{fma}\left(y, \frac{z - t}{t - a}, y\right)\\ \mathbf{elif}\;\left(x + y\right) + \frac{y \cdot \left(t - z\right)}{a - t} \leq 0:\\ \;\;\;\;x + \left(1 + \frac{a}{t}\right) \cdot \left(\frac{y}{t} \cdot \left(z - a\right)\right)\\ \mathbf{elif}\;\left(x + y\right) + \frac{y \cdot \left(t - z\right)}{a - t} \leq 10^{+299}:\\ \;\;\;\;x - \left(\left(\frac{y \cdot t}{t - a} - y\right) - \frac{y \cdot z}{t - a}\right)\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(\left(1 + \frac{z}{t - a}\right) - \frac{t}{t - a}\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022182 
(FPCore (x y z t a)
  :name "Graphics.Rendering.Plot.Render.Plot.Axis:renderAxisTick from plot-0.2.3.4, B"
  :precision binary64

  :herbie-target
  (if (< (- (+ x y) (/ (* (- z t) y) (- a t))) -1.3664970889390727e-7) (- (+ y x) (* (* (- z t) (/ 1.0 (- a t))) y)) (if (< (- (+ x y) (/ (* (- z t) y) (- a t))) 1.4754293444577233e-239) (/ (- (* y (- a z)) (* x t)) (- a t)) (- (+ y x) (* (* (- z t) (/ 1.0 (- a t))) y))))

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