Average Error: 6.1 → 0.5
Time: 11.7s
Precision: binary64
Cost: 7624
\[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 -2 \cdot 10^{+185}:\\ \;\;\;\;x + \frac{y}{a} \cdot \left(t - z\right)\\ \mathbf{elif}\;t_1 \leq 10^{+223}:\\ \;\;\;\;x + \frac{y \cdot \left(t - z\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{t - z}{a}, x\right)\\ \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 -2e+185)
     (+ x (* (/ y a) (- t z)))
     (if (<= t_1 1e+223) (+ x (/ (* y (- t z)) a)) (fma y (/ (- t z) a) x)))))
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 <= -2e+185) {
		tmp = x + ((y / a) * (t - z));
	} else if (t_1 <= 1e+223) {
		tmp = x + ((y * (t - z)) / a);
	} else {
		tmp = fma(y, ((t - z) / a), x);
	}
	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 <= -2e+185)
		tmp = Float64(x + Float64(Float64(y / a) * Float64(t - z)));
	elseif (t_1 <= 1e+223)
		tmp = Float64(x + Float64(Float64(y * Float64(t - z)) / a));
	else
		tmp = fma(y, Float64(Float64(t - z) / a), x);
	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, -2e+185], N[(x + N[(N[(y / a), $MachinePrecision] * N[(t - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1e+223], N[(x + N[(N[(y * N[(t - z), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(y * N[(N[(t - z), $MachinePrecision] / a), $MachinePrecision] + x), $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 -2 \cdot 10^{+185}:\\
\;\;\;\;x + \frac{y}{a} \cdot \left(t - z\right)\\

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

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


\end{array}

Error

Target

Original6.1
Target0.7
Herbie0.5
\[\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)) < -2e185

    1. Initial program 25.3

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

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

    if -2e185 < (*.f64 y (-.f64 z t)) < 1.00000000000000005e223

    1. Initial program 0.5

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

    if 1.00000000000000005e223 < (*.f64 y (-.f64 z t))

    1. Initial program 32.8

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

      \[\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): 38 points increase in error, 36 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
  3. Recombined 3 regimes into one program.
  4. Final simplification0.5

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

Alternatives

Alternative 1
Error0.5
Cost1352
\[\begin{array}{l} t_1 := y \cdot \left(z - t\right)\\ t_2 := x + \frac{y}{a} \cdot \left(t - z\right)\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+185}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 10^{+272}:\\ \;\;\;\;x + \frac{y \cdot \left(t - z\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error28.3
Cost980
\[\begin{array}{l} t_1 := y \cdot \frac{-z}{a}\\ \mathbf{if}\;x \leq -6.735527098115393 \cdot 10^{-110}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.048676419712637 \cdot 10^{-270}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -6.294804054505135 \cdot 10^{-299}:\\ \;\;\;\;t \cdot \frac{y}{a}\\ \mathbf{elif}\;x \leq 5.5438105646444514 \cdot 10^{-207}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.5249367156220249 \cdot 10^{-62}:\\ \;\;\;\;\frac{y \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error28.2
Cost980
\[\begin{array}{l} \mathbf{if}\;x \leq -5.879079768867322 \cdot 10^{-93}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.048676419712637 \cdot 10^{-270}:\\ \;\;\;\;\frac{-y \cdot z}{a}\\ \mathbf{elif}\;x \leq -1.0926703519016563 \cdot 10^{-289}:\\ \;\;\;\;t \cdot \frac{y}{a}\\ \mathbf{elif}\;x \leq 5.5438105646444514 \cdot 10^{-207}:\\ \;\;\;\;y \cdot \frac{-z}{a}\\ \mathbf{elif}\;x \leq 1.5249367156220249 \cdot 10^{-62}:\\ \;\;\;\;\frac{y \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error28.1
Cost980
\[\begin{array}{l} t_1 := \frac{y}{a} \cdot \left(-z\right)\\ \mathbf{if}\;x \leq -5.879079768867322 \cdot 10^{-93}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.048676419712637 \cdot 10^{-270}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.0926703519016563 \cdot 10^{-289}:\\ \;\;\;\;t \cdot \frac{y}{a}\\ \mathbf{elif}\;x \leq 5.5438105646444514 \cdot 10^{-207}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.5249367156220249 \cdot 10^{-62}:\\ \;\;\;\;\frac{y \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error18.7
Cost976
\[\begin{array}{l} t_1 := \frac{t - z}{\frac{a}{y}}\\ \mathbf{if}\;x \leq -6.057731047738162 \cdot 10^{+36}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -4.5380588884311886 \cdot 10^{-52}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -5.879079768867322 \cdot 10^{-93}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 7847399326898.593:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error10.6
Cost976
\[\begin{array}{l} t_1 := x + t \cdot \frac{y}{a}\\ \mathbf{if}\;t \leq -6779177025630763:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -1.3206117117532275 \cdot 10^{-9}:\\ \;\;\;\;\frac{t - z}{\frac{a}{y}}\\ \mathbf{elif}\;t \leq -5.284218356075154 \cdot 10^{-70}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 4.388908270815513 \cdot 10^{-5}:\\ \;\;\;\;x - \frac{y \cdot z}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error10.7
Cost976
\[\begin{array}{l} t_1 := x + t \cdot \frac{y}{a}\\ \mathbf{if}\;t \leq -6779177025630763:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -1.3206117117532275 \cdot 10^{-9}:\\ \;\;\;\;\frac{t - z}{\frac{a}{y}}\\ \mathbf{elif}\;t \leq -1.5259706590952329 \cdot 10^{-92}:\\ \;\;\;\;x + \frac{y \cdot t}{a}\\ \mathbf{elif}\;t \leq 4.388908270815513 \cdot 10^{-5}:\\ \;\;\;\;x - \frac{y \cdot z}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error3.3
Cost840
\[\begin{array}{l} t_1 := x + \frac{y}{a} \cdot \left(t - z\right)\\ \mathbf{if}\;z \leq -1.475919472182075 \cdot 10^{-170}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.3282701662690138 \cdot 10^{-145}:\\ \;\;\;\;x + \frac{y \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error15.3
Cost712
\[\begin{array}{l} t_1 := x - \frac{y \cdot z}{a}\\ \mathbf{if}\;x \leq -5.879079768867322 \cdot 10^{-93}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.229371342463818 \cdot 10^{-28}:\\ \;\;\;\;\frac{t - z}{\frac{a}{y}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error28.3
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -2.924663774134821 \cdot 10^{-134}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.5249367156220249 \cdot 10^{-62}:\\ \;\;\;\;\frac{y}{\frac{a}{t}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Error28.4
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -2.924663774134821 \cdot 10^{-134}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.5249367156220249 \cdot 10^{-62}:\\ \;\;\;\;y \cdot \frac{t}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error31.1
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022308 
(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)))