Average Error: 6.0 → 0.4
Time: 14.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)\\ t_2 := \mathsf{fma}\left(y, \frac{t - z}{a}, x\right)\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+284}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 6 \cdot 10^{+219}:\\ \;\;\;\;x + \frac{y \cdot \left(t - z\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \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))) (t_2 (fma y (/ (- t z) a) x)))
   (if (<= t_1 -2e+284)
     t_2
     (if (<= t_1 6e+219) (+ x (/ (* y (- t z)) a)) t_2))))
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 t_2 = fma(y, ((t - z) / a), x);
	double tmp;
	if (t_1 <= -2e+284) {
		tmp = t_2;
	} else if (t_1 <= 6e+219) {
		tmp = x + ((y * (t - z)) / a);
	} else {
		tmp = t_2;
	}
	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))
	t_2 = fma(y, Float64(Float64(t - z) / a), x)
	tmp = 0.0
	if (t_1 <= -2e+284)
		tmp = t_2;
	elseif (t_1 <= 6e+219)
		tmp = Float64(x + Float64(Float64(y * Float64(t - z)) / a));
	else
		tmp = t_2;
	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]}, Block[{t$95$2 = N[(y * N[(N[(t - z), $MachinePrecision] / a), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+284], t$95$2, If[LessEqual[t$95$1, 6e+219], N[(x + N[(N[(y * N[(t - z), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], t$95$2]]]]
x - \frac{y \cdot \left(z - t\right)}{a}
\begin{array}{l}
t_1 := y \cdot \left(z - t\right)\\
t_2 := \mathsf{fma}\left(y, \frac{t - z}{a}, x\right)\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{+284}:\\
\;\;\;\;t_2\\

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

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}

Error

Target

Original6.0
Target0.7
Herbie0.4
\[\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 2 regimes
  2. if (*.f64 y (-.f64 z t)) < -2.00000000000000016e284 or 5.9999999999999995e219 < (*.f64 y (-.f64 z t))

    1. Initial program 38.5

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

      \[\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, 50 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 -2.00000000000000016e284 < (*.f64 y (-.f64 z t)) < 5.9999999999999995e219

    1. Initial program 0.4

      \[x - \frac{y \cdot \left(z - t\right)}{a} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot \left(z - t\right) \leq -2 \cdot 10^{+284}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{t - z}{a}, x\right)\\ \mathbf{elif}\;y \cdot \left(z - t\right) \leq 6 \cdot 10^{+219}:\\ \;\;\;\;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
Error2.3
Cost1864
\[\begin{array}{l} t_1 := x + \frac{y \cdot \left(t - z\right)}{a}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;x + t \cdot \frac{y}{a}\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+303}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{t - z}{\frac{a}{y}}\\ \end{array} \]
Alternative 2
Error27.9
Cost1308
\[\begin{array}{l} t_1 := \frac{y \cdot z}{-a}\\ \mathbf{if}\;x \leq -3.14204748956194 \cdot 10^{-61}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.393902066024469 \cdot 10^{-306}:\\ \;\;\;\;t \cdot \frac{y}{a}\\ \mathbf{elif}\;x \leq 2.8951589409718027 \cdot 10^{-273}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.3345476234698706 \cdot 10^{-235}:\\ \;\;\;\;y \cdot \frac{t}{a}\\ \mathbf{elif}\;x \leq 2.424910321959504 \cdot 10^{-185}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.729421160739016 \cdot 10^{-126}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.442857047780397 \cdot 10^{-62}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error27.9
Cost1308
\[\begin{array}{l} t_1 := y \cdot \frac{-z}{a}\\ \mathbf{if}\;x \leq -3.14204748956194 \cdot 10^{-61}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.393902066024469 \cdot 10^{-306}:\\ \;\;\;\;t \cdot \frac{y}{a}\\ \mathbf{elif}\;x \leq 2.8951589409718027 \cdot 10^{-273}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.3345476234698706 \cdot 10^{-235}:\\ \;\;\;\;y \cdot \frac{t}{a}\\ \mathbf{elif}\;x \leq 2.424910321959504 \cdot 10^{-185}:\\ \;\;\;\;\frac{y \cdot z}{-a}\\ \mathbf{elif}\;x \leq 5.729421160739016 \cdot 10^{-126}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.442857047780397 \cdot 10^{-62}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error27.9
Cost1308
\[\begin{array}{l} t_1 := z \cdot \frac{-y}{a}\\ \mathbf{if}\;x \leq -3.14204748956194 \cdot 10^{-61}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.393902066024469 \cdot 10^{-306}:\\ \;\;\;\;t \cdot \frac{y}{a}\\ \mathbf{elif}\;x \leq 2.8951589409718027 \cdot 10^{-273}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.3345476234698706 \cdot 10^{-235}:\\ \;\;\;\;y \cdot \frac{t}{a}\\ \mathbf{elif}\;x \leq 6.151314293952634 \cdot 10^{-168}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.729421160739016 \cdot 10^{-126}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.442857047780397 \cdot 10^{-62}:\\ \;\;\;\;y \cdot \frac{-z}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error13.9
Cost976
\[\begin{array}{l} t_1 := \frac{t - z}{\frac{a}{y}}\\ t_2 := x + t \cdot \frac{y}{a}\\ \mathbf{if}\;x \leq -4.9235899911462975 \cdot 10^{-105}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 6.151314293952634 \cdot 10^{-168}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.729421160739016 \cdot 10^{-126}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 5.782056327887322 \cdot 10^{-111}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error13.9
Cost976
\[\begin{array}{l} t_1 := x + t \cdot \frac{y}{a}\\ \mathbf{if}\;x \leq -4.9235899911462975 \cdot 10^{-105}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.151314293952634 \cdot 10^{-168}:\\ \;\;\;\;\frac{t - z}{\frac{a}{y}}\\ \mathbf{elif}\;x \leq 5.729421160739016 \cdot 10^{-126}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.782056327887322 \cdot 10^{-111}:\\ \;\;\;\;y \cdot \frac{t - z}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error18.9
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -1.0013054940819153 \cdot 10^{+55}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.442857047780397 \cdot 10^{-62}:\\ \;\;\;\;\frac{t - z}{\frac{a}{y}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error10.8
Cost712
\[\begin{array}{l} t_1 := x + t \cdot \frac{y}{a}\\ \mathbf{if}\;t \leq -1.9326802475682665 \cdot 10^{-78}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 8.15853462450141 \cdot 10^{+73}:\\ \;\;\;\;x - \frac{y \cdot z}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error27.9
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -4.507482250885998 \cdot 10^{-75}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.138373898763733 \cdot 10^{-158}:\\ \;\;\;\;\frac{y}{\frac{a}{t}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error27.7
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -3.14204748956194 \cdot 10^{-61}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.138373898763733 \cdot 10^{-158}:\\ \;\;\;\;\frac{t}{\frac{a}{y}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Error27.7
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -3.14204748956194 \cdot 10^{-61}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.138373898763733 \cdot 10^{-158}:\\ \;\;\;\;t \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error30.8
Cost64
\[x \]

Error

Reproduce

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