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

\mathbf{elif}\;y \leq 2 \cdot 10^{-54}:\\
\;\;\;\;x + \frac{\frac{y}{\frac{1}{z - t}}}{a - t}\\

\mathbf{else}:\\
\;\;\;\;x + y \cdot t_1\\


\end{array}

Error

Target

Original1.3
Target0.4
Herbie0.5
\[\begin{array}{l} \mathbf{if}\;y < -8.508084860551241 \cdot 10^{-17}:\\ \;\;\;\;x + y \cdot \frac{z - t}{a - t}\\ \mathbf{elif}\;y < 2.894426862792089 \cdot 10^{-49}:\\ \;\;\;\;x + \left(y \cdot \left(z - t\right)\right) \cdot \frac{1}{a - t}\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{z - t}{a - t}\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if y < -1.99999999999999999e-70

    1. Initial program 0.6

      \[x + y \cdot \frac{z - t}{a - t} \]
    2. Simplified0.6

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

      [Start]0.6

      \[ x + y \cdot \frac{z - t}{a - t} \]

      +-commutative [=>]0.6

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

      fma-def [=>]0.6

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

    if -1.99999999999999999e-70 < y < 2.0000000000000001e-54

    1. Initial program 2.1

      \[x + y \cdot \frac{z - t}{a - t} \]
    2. Simplified0.3

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

      [Start]2.1

      \[ x + y \cdot \frac{z - t}{a - t} \]

      associate-*r/ [=>]0.3

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

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

    if 2.0000000000000001e-54 < y

    1. Initial program 0.6

      \[x + y \cdot \frac{z - t}{a - t} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.5

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

Alternatives

Alternative 1
Error0.5
Cost1097
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \cdot 10^{-70} \lor \neg \left(y \leq 2 \cdot 10^{-54}\right):\\ \;\;\;\;x + y \cdot \frac{z - t}{a - t}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{\frac{y}{\frac{1}{z - t}}}{a - t}\\ \end{array} \]
Alternative 2
Error0.4
Cost969
\[\begin{array}{l} \mathbf{if}\;y \leq -1.95 \cdot 10^{-19} \lor \neg \left(y \leq 1.35 \cdot 10^{-80}\right):\\ \;\;\;\;x + y \cdot \frac{z - t}{a - t}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y \cdot \left(z - t\right)}{a - t}\\ \end{array} \]
Alternative 3
Error16.9
Cost841
\[\begin{array}{l} \mathbf{if}\;x \leq -3.6 \cdot 10^{-110} \lor \neg \left(x \leq 6 \cdot 10^{-80}\right):\\ \;\;\;\;y + x\\ \mathbf{else}:\\ \;\;\;\;\left(z - t\right) \cdot \frac{y}{a - t}\\ \end{array} \]
Alternative 4
Error10.7
Cost841
\[\begin{array}{l} \mathbf{if}\;t \leq -2.7 \cdot 10^{+45} \lor \neg \left(t \leq 1.85 \cdot 10^{+78}\right):\\ \;\;\;\;y + x\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{z}{a - t}\\ \end{array} \]
Alternative 5
Error8.5
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -1.7 \cdot 10^{+25}:\\ \;\;\;\;x + \frac{y}{\frac{a - t}{z}}\\ \mathbf{elif}\;z \leq 4.05 \cdot 10^{-23}:\\ \;\;\;\;x - y \cdot \frac{t}{a - t}\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{z}{a - t}\\ \end{array} \]
Alternative 6
Error8.5
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -9 \cdot 10^{+27}:\\ \;\;\;\;x + \frac{y}{\frac{a - t}{z}}\\ \mathbf{elif}\;z \leq 3.9 \cdot 10^{-23}:\\ \;\;\;\;x - \frac{y}{\frac{a - t}{t}}\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{z}{a - t}\\ \end{array} \]
Alternative 7
Error14.6
Cost713
\[\begin{array}{l} \mathbf{if}\;t \leq -1.35 \cdot 10^{-72} \lor \neg \left(t \leq 1.1 \cdot 10^{-61}\right):\\ \;\;\;\;y + x\\ \mathbf{else}:\\ \;\;\;\;x + z \cdot \frac{y}{a}\\ \end{array} \]
Alternative 8
Error14.6
Cost713
\[\begin{array}{l} \mathbf{if}\;t \leq -9.8 \cdot 10^{-95} \lor \neg \left(t \leq 4.4 \cdot 10^{+49}\right):\\ \;\;\;\;y + x\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{\frac{a}{z}}\\ \end{array} \]
Alternative 9
Error23.0
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -4.4 \cdot 10^{-190}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;x \leq 2.55 \cdot 10^{-157}:\\ \;\;\;\;z \cdot \frac{y}{a - t}\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 10
Error1.3
Cost704
\[x + y \cdot \frac{z - t}{a - t} \]
Alternative 11
Error19.6
Cost456
\[\begin{array}{l} \mathbf{if}\;t \leq -2.25 \cdot 10^{-76}:\\ \;\;\;\;y + x\\ \mathbf{elif}\;t \leq 6.2 \cdot 10^{-71}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;y + x\\ \end{array} \]
Alternative 12
Error26.9
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -5.5 \cdot 10^{-110}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{-154}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 13
Error28.8
Cost64
\[x \]

Error

Reproduce

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

  :herbie-target
  (if (< y -8.508084860551241e-17) (+ x (* y (/ (- z t) (- a t)))) (if (< y 2.894426862792089e-49) (+ x (* (* y (- z t)) (/ 1.0 (- a t)))) (+ x (* y (/ (- z t) (- a t))))))

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