Average Error: 10.7 → 0.7
Time: 12.1s
Precision: binary64
Cost: 7748
\[x + \frac{\left(y - z\right) \cdot t}{a - z} \]
\[\begin{array}{l} t_1 := x + \frac{\left(y - z\right) \cdot t}{a - z}\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+136}:\\ \;\;\;\;\mathsf{fma}\left(y - z, \frac{t}{a - z}, x\right)\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+302}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - z}{\frac{a - z}{t}}\\ \end{array} \]
(FPCore (x y z t a) :precision binary64 (+ x (/ (* (- y z) t) (- a z))))
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (+ x (/ (* (- y z) t) (- a z)))))
   (if (<= t_1 -2e+136)
     (fma (- y z) (/ t (- a z)) x)
     (if (<= t_1 5e+302) t_1 (+ x (/ (- y z) (/ (- a z) t)))))))
double code(double x, double y, double z, double t, double a) {
	return x + (((y - z) * t) / (a - z));
}
double code(double x, double y, double z, double t, double a) {
	double t_1 = x + (((y - z) * t) / (a - z));
	double tmp;
	if (t_1 <= -2e+136) {
		tmp = fma((y - z), (t / (a - z)), x);
	} else if (t_1 <= 5e+302) {
		tmp = t_1;
	} else {
		tmp = x + ((y - z) / ((a - z) / t));
	}
	return tmp;
}
function code(x, y, z, t, a)
	return Float64(x + Float64(Float64(Float64(y - z) * t) / Float64(a - z)))
end
function code(x, y, z, t, a)
	t_1 = Float64(x + Float64(Float64(Float64(y - z) * t) / Float64(a - z)))
	tmp = 0.0
	if (t_1 <= -2e+136)
		tmp = fma(Float64(y - z), Float64(t / Float64(a - z)), x);
	elseif (t_1 <= 5e+302)
		tmp = t_1;
	else
		tmp = Float64(x + Float64(Float64(y - z) / Float64(Float64(a - z) / t)));
	end
	return tmp
end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(N[(y - z), $MachinePrecision] * t), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(x + N[(N[(N[(y - z), $MachinePrecision] * t), $MachinePrecision] / N[(a - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+136], N[(N[(y - z), $MachinePrecision] * N[(t / N[(a - z), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[t$95$1, 5e+302], t$95$1, N[(x + N[(N[(y - z), $MachinePrecision] / N[(N[(a - z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
x + \frac{\left(y - z\right) \cdot t}{a - z}
\begin{array}{l}
t_1 := x + \frac{\left(y - z\right) \cdot t}{a - z}\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{+136}:\\
\;\;\;\;\mathsf{fma}\left(y - z, \frac{t}{a - z}, x\right)\\

\mathbf{elif}\;t_1 \leq 5 \cdot 10^{+302}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;x + \frac{y - z}{\frac{a - z}{t}}\\


\end{array}

Error

Target

Original10.7
Target0.7
Herbie0.7
\[\begin{array}{l} \mathbf{if}\;t < -1.0682974490174067 \cdot 10^{-39}:\\ \;\;\;\;x + \frac{y - z}{a - z} \cdot t\\ \mathbf{elif}\;t < 3.9110949887586375 \cdot 10^{-141}:\\ \;\;\;\;x + \frac{\left(y - z\right) \cdot t}{a - z}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - z}{a - z} \cdot t\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if (+.f64 x (/.f64 (*.f64 (-.f64 y z) t) (-.f64 a z))) < -2.00000000000000012e136

    1. Initial program 21.4

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y - z, \frac{t}{a - z}, x\right)} \]
      Proof
      (fma.f64 (-.f64 y z) (/.f64 t (-.f64 a z)) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (-.f64 y z) (/.f64 t (-.f64 a z))) x)): 2 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 (-.f64 y z) t) (-.f64 a z))) x): 58 points increase in error, 32 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 x (/.f64 (*.f64 (-.f64 y z) t) (-.f64 a z)))): 0 points increase in error, 0 points decrease in error

    if -2.00000000000000012e136 < (+.f64 x (/.f64 (*.f64 (-.f64 y z) t) (-.f64 a z))) < 5e302

    1. Initial program 0.4

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

    if 5e302 < (+.f64 x (/.f64 (*.f64 (-.f64 y z) t) (-.f64 a z)))

    1. Initial program 60.1

      \[x + \frac{\left(y - z\right) \cdot t}{a - z} \]
    2. Applied egg-rr0.6

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

      \[\leadsto x + \color{blue}{\frac{y - z}{\frac{a - z}{t}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.7

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

Alternatives

Alternative 1
Error0.7
Cost2248
\[\begin{array}{l} t_1 := x + \frac{y - z}{\frac{a - z}{t}}\\ t_2 := x + \frac{\left(y - z\right) \cdot t}{a - z}\\ \mathbf{if}\;t_2 \leq -1 \cdot 10^{+105}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 5 \cdot 10^{+302}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error0.3
Cost2248
\[\begin{array}{l} t_1 := x + \frac{\left(y - z\right) \cdot t}{a - z}\\ t_2 := \frac{a - z}{t}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;x + \left(y - z\right) \cdot \frac{1}{t_2}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+302}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - z}{t_2}\\ \end{array} \]
Alternative 3
Error18.8
Cost976
\[\begin{array}{l} t_1 := x - \frac{z}{\frac{a}{t}}\\ \mathbf{if}\;a \leq -3.514077983239558 \cdot 10^{+151}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 5.815741964192438 \cdot 10^{+26}:\\ \;\;\;\;x + t\\ \mathbf{elif}\;a \leq 1.0606807149396357 \cdot 10^{+55}:\\ \;\;\;\;t \cdot \frac{y - z}{a}\\ \mathbf{elif}\;a \leq 8.803251860119609 \cdot 10^{+117}:\\ \;\;\;\;x + t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error11.0
Cost840
\[\begin{array}{l} t_1 := x - \frac{t}{\frac{a}{z} + -1}\\ \mathbf{if}\;z \leq -5.741463029644397 \cdot 10^{-155}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 9.988549253736776 \cdot 10^{-245}:\\ \;\;\;\;x + y \cdot \frac{t}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error9.6
Cost840
\[\begin{array}{l} t_1 := x - \frac{t}{\frac{a}{z} + -1}\\ \mathbf{if}\;z \leq -5.741463029644397 \cdot 10^{-155}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.724412253058681 \cdot 10^{-39}:\\ \;\;\;\;x + \left(y - z\right) \cdot \frac{t}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error9.6
Cost840
\[\begin{array}{l} t_1 := x - t \cdot \frac{z}{a - z}\\ \mathbf{if}\;z \leq -5.741463029644397 \cdot 10^{-155}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.724412253058681 \cdot 10^{-39}:\\ \;\;\;\;x + \left(y - z\right) \cdot \frac{t}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error14.2
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -4.660609814288562 \cdot 10^{-96}:\\ \;\;\;\;x + t\\ \mathbf{elif}\;z \leq 1.724412253058681 \cdot 10^{-39}:\\ \;\;\;\;x + \frac{y \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;x + t\\ \end{array} \]
Alternative 8
Error13.8
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -4.660609814288562 \cdot 10^{-96}:\\ \;\;\;\;x + t\\ \mathbf{elif}\;z \leq 1.724412253058681 \cdot 10^{-39}:\\ \;\;\;\;x + y \cdot \frac{t}{a}\\ \mathbf{else}:\\ \;\;\;\;x + t\\ \end{array} \]
Alternative 9
Error2.9
Cost704
\[x + \frac{y - z}{\frac{a - z}{t}} \]
Alternative 10
Error19.2
Cost456
\[\begin{array}{l} \mathbf{if}\;z \leq -6.785872207380266 \cdot 10^{-131}:\\ \;\;\;\;x + t\\ \mathbf{elif}\;z \leq 1.0434913007434336 \cdot 10^{-47}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;x + t\\ \end{array} \]
Alternative 11
Error26.4
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -8.168447485859198 \cdot 10^{-166}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.4896253499042787 \cdot 10^{-146}:\\ \;\;\;\;t\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error50.8
Cost64
\[t \]

Error

Reproduce

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

  :herbie-target
  (if (< t -1.0682974490174067e-39) (+ x (* (/ (- y z) (- a z)) t)) (if (< t 3.9110949887586375e-141) (+ x (/ (* (- y z) t) (- a z))) (+ x (* (/ (- y z) (- a z)) t))))

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