Average Error: 6.2 → 0.8
Time: 12.3s
Precision: binary64
Cost: 7112
\[x - \frac{y \cdot \left(z - t\right)}{a} \]
\[\begin{array}{l} t_1 := \mathsf{fma}\left(y, \frac{t - z}{a}, x\right)\\ \mathbf{if}\;a \leq -1.3804930328694653 \cdot 10^{+42}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 5 \cdot 10^{-60}:\\ \;\;\;\;x + \frac{y \cdot \left(t - z\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \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 (fma y (/ (- t z) a) x)))
   (if (<= a -1.3804930328694653e+42)
     t_1
     (if (<= a 5e-60) (+ x (/ (* y (- t z)) a)) t_1))))
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 = fma(y, ((t - z) / a), x);
	double tmp;
	if (a <= -1.3804930328694653e+42) {
		tmp = t_1;
	} else if (a <= 5e-60) {
		tmp = x + ((y * (t - z)) / a);
	} else {
		tmp = t_1;
	}
	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 = fma(y, Float64(Float64(t - z) / a), x)
	tmp = 0.0
	if (a <= -1.3804930328694653e+42)
		tmp = t_1;
	elseif (a <= 5e-60)
		tmp = Float64(x + Float64(Float64(y * Float64(t - z)) / a));
	else
		tmp = t_1;
	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[(N[(t - z), $MachinePrecision] / a), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[a, -1.3804930328694653e+42], t$95$1, If[LessEqual[a, 5e-60], N[(x + N[(N[(y * N[(t - z), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], t$95$1]]]
x - \frac{y \cdot \left(z - t\right)}{a}
\begin{array}{l}
t_1 := \mathsf{fma}\left(y, \frac{t - z}{a}, x\right)\\
\mathbf{if}\;a \leq -1.3804930328694653 \cdot 10^{+42}:\\
\;\;\;\;t_1\\

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

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Target

Original6.2
Target0.8
Herbie0.8
\[\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 a < -1.38049303286946533e42 or 5.0000000000000001e-60 < a

    1. Initial program 9.2

      \[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)): 0 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): 39 points increase in error, 27 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 -1.38049303286946533e42 < a < 5.0000000000000001e-60

    1. Initial program 1.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -1.3804930328694653 \cdot 10^{+42}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{t - z}{a}, x\right)\\ \mathbf{elif}\;a \leq 5 \cdot 10^{-60}:\\ \;\;\;\;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
Error3.3
Cost1864
\[\begin{array}{l} t_1 := x - y \cdot \frac{z}{a}\\ t_2 := x + \frac{y \cdot \left(t - z\right)}{a}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 5 \cdot 10^{+286}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error28.2
Cost1376
\[\begin{array}{l} t_1 := \frac{y \cdot \left(-z\right)}{a}\\ t_2 := \frac{y \cdot t}{a}\\ \mathbf{if}\;x \leq -1.631652995356941 \cdot 10^{-86}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -9.729848090895173 \cdot 10^{-110}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -4.5359721866976623 \cdot 10^{-147}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -8.733688695047591 \cdot 10^{-299}:\\ \;\;\;\;\frac{y}{\frac{a}{t}}\\ \mathbf{elif}\;x \leq 7.869915740082897 \cdot 10^{-231}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 6.933210449614127 \cdot 10^{-127}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.6368081122149312 \cdot 10^{-57}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2149141.061362807:\\ \;\;\;\;t \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error28.2
Cost1044
\[\begin{array}{l} t_1 := y \cdot \frac{z}{-a}\\ \mathbf{if}\;x \leq -1.631652995356941 \cdot 10^{-86}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -9.729848090895173 \cdot 10^{-110}:\\ \;\;\;\;\frac{y \cdot t}{a}\\ \mathbf{elif}\;x \leq -2.5632190709826754 \cdot 10^{-130}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -8.733688695047591 \cdot 10^{-299}:\\ \;\;\;\;\frac{y}{\frac{a}{t}}\\ \mathbf{elif}\;x \leq 7.140766910416544 \cdot 10^{-72}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error28.1
Cost1044
\[\begin{array}{l} \mathbf{if}\;x \leq -1.631652995356941 \cdot 10^{-86}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -9.729848090895173 \cdot 10^{-110}:\\ \;\;\;\;\frac{y \cdot t}{a}\\ \mathbf{elif}\;x \leq -2.5632190709826754 \cdot 10^{-130}:\\ \;\;\;\;y \cdot \frac{z}{-a}\\ \mathbf{elif}\;x \leq -2.6386329653016047 \cdot 10^{-250}:\\ \;\;\;\;\frac{y}{\frac{a}{t}}\\ \mathbf{elif}\;x \leq 7.140766910416544 \cdot 10^{-72}:\\ \;\;\;\;z \cdot \frac{-y}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error20.8
Cost976
\[\begin{array}{l} t_1 := \frac{y \cdot \left(t - z\right)}{a}\\ \mathbf{if}\;x \leq -3579062875979496000:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.4950239964298727 \cdot 10^{-36}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.472983676869023 \cdot 10^{-83}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 7.140766910416544 \cdot 10^{-72}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error16.3
Cost976
\[\begin{array}{l} t_1 := x + \frac{y \cdot t}{a}\\ \mathbf{if}\;x \leq -9.729848090895173 \cdot 10^{-110}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -3.4895069410611724 \cdot 10^{-137}:\\ \;\;\;\;\frac{z}{\frac{a}{-y}}\\ \mathbf{elif}\;x \leq -1.7510344433515037 \cdot 10^{-172}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.8495272509234792 \cdot 10^{-126}:\\ \;\;\;\;\frac{y \cdot \left(t - z\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error27.8
Cost848
\[\begin{array}{l} \mathbf{if}\;x \leq -1.631652995356941 \cdot 10^{-86}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -3.4895069410611724 \cdot 10^{-137}:\\ \;\;\;\;\frac{t}{\frac{a}{y}}\\ \mathbf{elif}\;x \leq -1.7510344433515037 \cdot 10^{-172}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.933210449614127 \cdot 10^{-127}:\\ \;\;\;\;\frac{y}{\frac{a}{t}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error27.8
Cost848
\[\begin{array}{l} \mathbf{if}\;x \leq -1.631652995356941 \cdot 10^{-86}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -3.4895069410611724 \cdot 10^{-137}:\\ \;\;\;\;t \cdot \frac{y}{a}\\ \mathbf{elif}\;x \leq -1.7510344433515037 \cdot 10^{-172}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.933210449614127 \cdot 10^{-127}:\\ \;\;\;\;\frac{y}{\frac{a}{t}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error12.7
Cost712
\[\begin{array}{l} t_1 := x - y \cdot \frac{z}{a}\\ \mathbf{if}\;z \leq -3.1634017390530787 \cdot 10^{-55}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.204094872476087 \cdot 10^{-56}:\\ \;\;\;\;x + \frac{y \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error12.5
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -805.4171436125572:\\ \;\;\;\;x + y \cdot \frac{t}{a}\\ \mathbf{elif}\;t \leq 1190516.9400455246:\\ \;\;\;\;x - y \cdot \frac{z}{a}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y \cdot t}{a}\\ \end{array} \]
Alternative 11
Error27.6
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -6.016765421401446 \cdot 10^{-101}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.933210449614127 \cdot 10^{-127}:\\ \;\;\;\;\frac{y}{\frac{a}{t}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error30.8
Cost64
\[x \]

Error

Reproduce

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