Average Error: 10.7 → 1.3
Time: 11.0s
Precision: binary64
Cost: 7240
\[x + \frac{y \cdot \left(z - t\right)}{a - t} \]
\[\begin{array}{l} \mathbf{if}\;t \leq -3.2 \cdot 10^{-123}:\\ \;\;\;\;x + \frac{y}{\frac{a - t}{z - t}}\\ \mathbf{elif}\;t \leq 2.15 \cdot 10^{-270}:\\ \;\;\;\;x + \frac{1}{a - t} \cdot \left(y \cdot \left(z - t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{z - t}{a - t}, x\right)\\ \end{array} \]
(FPCore (x y z t a) :precision binary64 (+ x (/ (* y (- z t)) (- a t))))
(FPCore (x y z t a)
 :precision binary64
 (if (<= t -3.2e-123)
   (+ x (/ y (/ (- a t) (- z t))))
   (if (<= t 2.15e-270)
     (+ x (* (/ 1.0 (- a t)) (* y (- z t))))
     (fma y (/ (- z t) (- a t)) x))))
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 tmp;
	if (t <= -3.2e-123) {
		tmp = x + (y / ((a - t) / (z - t)));
	} else if (t <= 2.15e-270) {
		tmp = x + ((1.0 / (a - t)) * (y * (z - t)));
	} else {
		tmp = fma(y, ((z - t) / (a - t)), x);
	}
	return tmp;
}
function code(x, y, z, t, a)
	return Float64(x + Float64(Float64(y * Float64(z - t)) / Float64(a - t)))
end
function code(x, y, z, t, a)
	tmp = 0.0
	if (t <= -3.2e-123)
		tmp = Float64(x + Float64(y / Float64(Float64(a - t) / Float64(z - t))));
	elseif (t <= 2.15e-270)
		tmp = Float64(x + Float64(Float64(1.0 / Float64(a - t)) * Float64(y * Float64(z - t))));
	else
		tmp = fma(y, Float64(Float64(z - t) / Float64(a - t)), x);
	end
	return tmp
end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := If[LessEqual[t, -3.2e-123], N[(x + N[(y / N[(N[(a - t), $MachinePrecision] / N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, 2.15e-270], N[(x + N[(N[(1.0 / N[(a - t), $MachinePrecision]), $MachinePrecision] * N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(N[(z - t), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]]]
x + \frac{y \cdot \left(z - t\right)}{a - t}
\begin{array}{l}
\mathbf{if}\;t \leq -3.2 \cdot 10^{-123}:\\
\;\;\;\;x + \frac{y}{\frac{a - t}{z - t}}\\

\mathbf{elif}\;t \leq 2.15 \cdot 10^{-270}:\\
\;\;\;\;x + \frac{1}{a - t} \cdot \left(y \cdot \left(z - t\right)\right)\\

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


\end{array}

Error

Target

Original10.7
Target1.3
Herbie1.3
\[x + \frac{y}{\frac{a - t}{z - t}} \]

Derivation

  1. Split input into 3 regimes
  2. if t < -3.19999999999999979e-123

    1. Initial program 13.7

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

      \[\leadsto \color{blue}{x + \frac{y}{\frac{a - t}{z - t}}} \]
      Proof
      (+.f64 x (/.f64 y (/.f64 (-.f64 a t) (-.f64 z t)))): 0 points increase in error, 0 points decrease in error
      (+.f64 x (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 y (-.f64 z t)) (-.f64 a t)))): 49 points increase in error, 17 points decrease in error

    if -3.19999999999999979e-123 < t < 2.1500000000000001e-270

    1. Initial program 3.4

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

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

    if 2.1500000000000001e-270 < t

    1. Initial program 10.9

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{z - t}{a - t}, x\right)} \]
      Proof
      (fma.f64 y (/.f64 (-.f64 z t) (-.f64 a t)) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y (/.f64 (-.f64 z t) (-.f64 a t))) x)): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 y (-.f64 z t)) (-.f64 a t))) x): 51 points increase in error, 18 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 x (/.f64 (*.f64 y (-.f64 z t)) (-.f64 a t)))): 0 points increase in error, 0 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification1.3

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

Alternatives

Alternative 1
Error14.3
Cost1104
\[\begin{array}{l} t_1 := x + \left(z - t\right) \cdot \frac{y}{a}\\ \mathbf{if}\;t \leq -5 \cdot 10^{+105}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;t \leq -1.9 \cdot 10^{-77}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.52 \cdot 10^{-207}:\\ \;\;\;\;x + \frac{y \cdot z}{a}\\ \mathbf{elif}\;t \leq 1.9 \cdot 10^{+28}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 2
Error1.3
Cost1096
\[\begin{array}{l} t_1 := x + \frac{y}{\frac{a - t}{z - t}}\\ \mathbf{if}\;t \leq -4 \cdot 10^{-125}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.4 \cdot 10^{-270}:\\ \;\;\;\;x + \frac{1}{a - t} \cdot \left(y \cdot \left(z - t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error11.0
Cost968
\[\begin{array}{l} \mathbf{if}\;t \leq -1.26 \cdot 10^{-92}:\\ \;\;\;\;x - t \cdot \frac{y}{a - t}\\ \mathbf{elif}\;t \leq 7.2 \cdot 10^{+27}:\\ \;\;\;\;x + \left(y \cdot \left(z - t\right)\right) \cdot \frac{1}{a}\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \left(1 - \frac{z}{t}\right)\\ \end{array} \]
Alternative 4
Error3.5
Cost968
\[\begin{array}{l} t_1 := x + \left(z - t\right) \cdot \frac{y}{a - t}\\ \mathbf{if}\;t \leq -1 \cdot 10^{-171}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 6.5 \cdot 10^{-205}:\\ \;\;\;\;x + \left(y \cdot \left(z - t\right)\right) \cdot \frac{1}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error1.5
Cost968
\[\begin{array}{l} t_1 := x + \frac{y}{\frac{a - t}{z - t}}\\ \mathbf{if}\;t \leq -65000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 8 \cdot 10^{-271}:\\ \;\;\;\;x + \frac{y \cdot \left(z - t\right)}{a - t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error19.0
Cost840
\[\begin{array}{l} \mathbf{if}\;x \leq -1.95 \cdot 10^{-50}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.6 \cdot 10^{-45}:\\ \;\;\;\;y \cdot \frac{z - t}{a - t}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y \cdot z}{a}\\ \end{array} \]
Alternative 7
Error11.7
Cost840
\[\begin{array}{l} t_1 := x + \left(z - t\right) \cdot \frac{y}{a}\\ \mathbf{if}\;a \leq -0.00025:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 3.6 \cdot 10^{-56}:\\ \;\;\;\;x + y \cdot \left(1 - \frac{z}{t}\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error16.2
Cost712
\[\begin{array}{l} t_1 := x + z \cdot \frac{y}{a}\\ \mathbf{if}\;a \leq -4.8 \cdot 10^{-25}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 3.9 \cdot 10^{-50}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error14.4
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -9 \cdot 10^{-20}:\\ \;\;\;\;x + y\\ \mathbf{elif}\;t \leq 1.86 \cdot 10^{+28}:\\ \;\;\;\;x + \frac{y \cdot z}{a}\\ \mathbf{else}:\\ \;\;\;\;x + y\\ \end{array} \]
Alternative 10
Error1.3
Cost704
\[x + \frac{y}{\frac{a - t}{z - t}} \]
Alternative 11
Error19.9
Cost456
\[\begin{array}{l} \mathbf{if}\;a \leq -1.8 \cdot 10^{+141}:\\ \;\;\;\;x\\ \mathbf{elif}\;a \leq 5.8 \cdot 10^{+104}:\\ \;\;\;\;x + y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error27.6
Cost328
\[\begin{array}{l} \mathbf{if}\;x \leq -7.5 \cdot 10^{-171}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{-305}:\\ \;\;\;\;y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 13
Error28.5
Cost64
\[x \]

Error

Reproduce

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

  :herbie-target
  (+ x (/ y (/ (- a t) (- z t))))

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