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

\mathbf{elif}\;t_1 \leq 5 \cdot 10^{+289}:\\
\;\;\;\;x + \frac{y \cdot \left(t - z\right)}{a}\\

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


\end{array}

Error

Target

Original6.3
Target0.6
Herbie1.1
\[\begin{array}{l} \mathbf{if}\;y < -1.0761266216389975 \cdot 10^{-10}:\\ \;\;\;\;x - \frac{1}{\frac{\frac{a}{z - t}}{y}}\\ \mathbf{elif}\;y < 2.894426862792089 \cdot 10^{-49}:\\ \;\;\;\;x - \frac{y \cdot \left(z - t\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{y}{\frac{a}{z - t}}\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if (*.f64 y (-.f64 z t)) < -4.9999999999999997e303

    1. Initial program 60.7

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{t - z}{a}, x\right)} \]
      Proof
      (fma.f64 y (/.f64 (-.f64 t z) a) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 y (/.f64 (-.f64 (Rewrite<= remove-double-neg_binary64 (neg.f64 (neg.f64 t))) z) a) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 y (/.f64 (Rewrite<= unsub-neg_binary64 (+.f64 (neg.f64 (neg.f64 t)) (neg.f64 z))) a) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 y (/.f64 (Rewrite<= distribute-neg-in_binary64 (neg.f64 (+.f64 (neg.f64 t) z))) a) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 y (/.f64 (neg.f64 (Rewrite<= +-commutative_binary64 (+.f64 z (neg.f64 t)))) a) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 y (/.f64 (neg.f64 (Rewrite<= sub-neg_binary64 (-.f64 z t))) a) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 y (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 (-.f64 z t) a))) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y (neg.f64 (/.f64 (-.f64 z t) a))) x)): 2 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 y (Rewrite=> distribute-neg-frac_binary64 (/.f64 (neg.f64 (-.f64 z t)) a))) x): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 y (neg.f64 (-.f64 z t))) a)) x): 35 points increase in error, 40 points decrease in error
      (+.f64 (/.f64 (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 y (-.f64 z t)))) a) x): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 (*.f64 y (-.f64 z t)) a))) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 x (neg.f64 (/.f64 (*.f64 y (-.f64 z t)) a)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= sub-neg_binary64 (-.f64 x (/.f64 (*.f64 y (-.f64 z t)) a))): 0 points increase in error, 0 points decrease in error

    if -4.9999999999999997e303 < (*.f64 y (-.f64 z t)) < 5.00000000000000031e289

    1. Initial program 0.4

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

    if 5.00000000000000031e289 < (*.f64 y (-.f64 z t))

    1. Initial program 54.5

      \[x - \frac{y \cdot \left(z - t\right)}{a} \]
    2. Taylor expanded in x around 0 57.3

      \[\leadsto \color{blue}{-1 \cdot \frac{\left(z - t\right) \cdot y}{a}} \]
    3. Simplified12.0

      \[\leadsto \color{blue}{\frac{y}{\frac{a}{t - z}}} \]
      Proof
      (/.f64 y (/.f64 a (-.f64 t z))): 0 points increase in error, 0 points decrease in error
      (/.f64 y (/.f64 a (Rewrite=> sub-neg_binary64 (+.f64 t (neg.f64 z))))): 0 points increase in error, 0 points decrease in error
      (/.f64 y (/.f64 a (+.f64 (Rewrite<= remove-double-neg_binary64 (neg.f64 (neg.f64 t))) (neg.f64 z)))): 0 points increase in error, 0 points decrease in error
      (/.f64 y (/.f64 a (Rewrite<= distribute-neg-in_binary64 (neg.f64 (+.f64 (neg.f64 t) z))))): 0 points increase in error, 0 points decrease in error
      (/.f64 y (/.f64 a (neg.f64 (Rewrite<= +-commutative_binary64 (+.f64 z (neg.f64 t)))))): 0 points increase in error, 0 points decrease in error
      (/.f64 y (/.f64 a (neg.f64 (Rewrite<= sub-neg_binary64 (-.f64 z t))))): 0 points increase in error, 0 points decrease in error
      (/.f64 y (/.f64 a (Rewrite=> neg-mul-1_binary64 (*.f64 -1 (-.f64 z t))))): 0 points increase in error, 0 points decrease in error
      (/.f64 y (Rewrite<= associate-/l/_binary64 (/.f64 (/.f64 a (-.f64 z t)) -1))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> associate-/r/_binary64 (*.f64 (/.f64 y (/.f64 a (-.f64 z t))) -1)): 0 points increase in error, 0 points decrease in error
      (*.f64 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 y (-.f64 z t)) a)) -1): 58 points increase in error, 59 points decrease in error
      (Rewrite<= *-commutative_binary64 (*.f64 -1 (/.f64 (*.f64 y (-.f64 z t)) a))): 0 points increase in error, 0 points decrease in error
      (*.f64 -1 (/.f64 (Rewrite<= *-commutative_binary64 (*.f64 (-.f64 z t) y)) a)): 0 points increase in error, 0 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification1.1

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

Alternatives

Alternative 1
Error2.4
Cost1352
\[\begin{array}{l} t_1 := y \cdot \left(z - t\right)\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{+303}:\\ \;\;\;\;x - y \cdot \frac{z}{a}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+289}:\\ \;\;\;\;x + \frac{y \cdot \left(t - z\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{a}{t - z}}\\ \end{array} \]
Alternative 2
Error15.7
Cost1108
\[\begin{array}{l} t_1 := x - y \cdot \frac{z}{a}\\ \mathbf{if}\;x \leq -1.3684013200587338 \cdot 10^{+107}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -27958.73319776311:\\ \;\;\;\;x + \frac{y}{\frac{a}{t}}\\ \mathbf{elif}\;x \leq -5.0664580198150126 \cdot 10^{-163}:\\ \;\;\;\;x - \frac{y \cdot z}{a}\\ \mathbf{elif}\;x \leq 1.0990457089541516 \cdot 10^{-137}:\\ \;\;\;\;\frac{y}{\frac{a}{t - z}}\\ \mathbf{elif}\;x \leq 1.330705057036598 \cdot 10^{+83}:\\ \;\;\;\;x + \frac{y \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error19.3
Cost844
\[\begin{array}{l} t_1 := x + \frac{y}{\frac{a}{t}}\\ \mathbf{if}\;z \leq 1.0194106529681273 \cdot 10^{+46}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 7 \cdot 10^{+213}:\\ \;\;\;\;\frac{-y}{\frac{a}{z}}\\ \mathbf{elif}\;z \leq 1.45 \cdot 10^{+245}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(-\frac{y}{a}\right)\\ \end{array} \]
Alternative 4
Error28.9
Cost716
\[\begin{array}{l} \mathbf{if}\;x \leq -8.326338025399783 \cdot 10^{-180}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.10274229300989 \cdot 10^{-279}:\\ \;\;\;\;\frac{-y}{\frac{a}{z}}\\ \mathbf{elif}\;x \leq 50747318.28978736:\\ \;\;\;\;t \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error12.1
Cost712
\[\begin{array}{l} t_1 := x - \frac{y \cdot z}{a}\\ \mathbf{if}\;z \leq -3.003301132523552 \cdot 10^{-85}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.192508321952651 \cdot 10^{-13}:\\ \;\;\;\;x + \frac{y}{\frac{a}{t}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error12.1
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -3.003301132523552 \cdot 10^{-85}:\\ \;\;\;\;x - \frac{y \cdot z}{a}\\ \mathbf{elif}\;z \leq 5.192508321952651 \cdot 10^{-13}:\\ \;\;\;\;x + \frac{y}{\frac{a}{t}}\\ \mathbf{else}:\\ \;\;\;\;x - y \cdot \frac{z}{a}\\ \end{array} \]
Alternative 7
Error12.5
Cost712
\[\begin{array}{l} \mathbf{if}\;z \leq -3.003301132523552 \cdot 10^{-85}:\\ \;\;\;\;x - \frac{y \cdot z}{a}\\ \mathbf{elif}\;z \leq 5.192508321952651 \cdot 10^{-13}:\\ \;\;\;\;x + \frac{y \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;x - y \cdot \frac{z}{a}\\ \end{array} \]
Alternative 8
Error28.1
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -5.0664580198150126 \cdot 10^{-163}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.53934846170318 \cdot 10^{-91}:\\ \;\;\;\;\frac{y}{\frac{a}{t}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error28.9
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -5.0664580198150126 \cdot 10^{-163}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 50747318.28978736:\\ \;\;\;\;\frac{t}{\frac{a}{y}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error28.8
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -5.0664580198150126 \cdot 10^{-163}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 50747318.28978736:\\ \;\;\;\;t \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Error31.0
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022294 
(FPCore (x y z t a)
  :name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, F"
  :precision binary64

  :herbie-target
  (if (< y -1.0761266216389975e-10) (- x (/ 1.0 (/ (/ a (- z t)) y))) (if (< y 2.894426862792089e-49) (- x (/ (* y (- z t)) a)) (- x (/ y (/ a (- z t))))))

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