?

Average Error: 9.5% → 0.5%
Time: 13.1s
Precision: binary64
Cost: 7625

?

\[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^{+261} \lor \neg \left(t_1 \leq 5 \cdot 10^{+223}\right):\\ \;\;\;\;\mathsf{fma}\left(y, \frac{t - z}{a}, x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y \cdot \left(t - z\right)}{a}\\ \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 (or (<= t_1 -2e+261) (not (<= t_1 5e+223)))
     (fma y (/ (- t z) a) x)
     (+ x (/ (* y (- t z)) a)))))
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+261) || !(t_1 <= 5e+223)) {
		tmp = fma(y, ((t - z) / a), x);
	} else {
		tmp = x + ((y * (t - z)) / a);
	}
	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+261) || !(t_1 <= 5e+223))
		tmp = fma(y, Float64(Float64(t - z) / a), x);
	else
		tmp = Float64(x + Float64(Float64(y * Float64(t - z)) / a));
	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[Or[LessEqual[t$95$1, -2e+261], N[Not[LessEqual[t$95$1, 5e+223]], $MachinePrecision]], N[(y * N[(N[(t - z), $MachinePrecision] / a), $MachinePrecision] + x), $MachinePrecision], N[(x + N[(N[(y * N[(t - z), $MachinePrecision]), $MachinePrecision] / a), $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 -2 \cdot 10^{+261} \lor \neg \left(t_1 \leq 5 \cdot 10^{+223}\right):\\
\;\;\;\;\mathsf{fma}\left(y, \frac{t - z}{a}, x\right)\\

\mathbf{else}:\\
\;\;\;\;x + \frac{y \cdot \left(t - z\right)}{a}\\


\end{array}

Error?

Target

Original9.5%
Target0.97%
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 2 regimes
  2. if (*.f64 y (-.f64 z t)) < -1.9999999999999999e261 or 4.99999999999999985e223 < (*.f64 y (-.f64 z t))

    1. Initial program 57.76

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{t - z}{a}, x\right)} \]
      Proof

      [Start]57.76

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

      sub-neg [=>]57.76

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

      +-commutative [=>]57.76

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

      *-commutative [=>]57.76

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

      associate-/l* [=>]0.62

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

      distribute-neg-frac [=>]0.62

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

      associate-/r/ [=>]0.95

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

      *-commutative [=>]0.95

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

      fma-def [=>]0.95

      \[ \color{blue}{\mathsf{fma}\left(y, \frac{-\left(z - t\right)}{a}, x\right)} \]

      sub-neg [=>]0.95

      \[ \mathsf{fma}\left(y, \frac{-\color{blue}{\left(z + \left(-t\right)\right)}}{a}, x\right) \]

      distribute-neg-in [=>]0.95

      \[ \mathsf{fma}\left(y, \frac{\color{blue}{\left(-z\right) + \left(-\left(-t\right)\right)}}{a}, x\right) \]

      +-commutative [=>]0.95

      \[ \mathsf{fma}\left(y, \frac{\color{blue}{\left(-\left(-t\right)\right) + \left(-z\right)}}{a}, x\right) \]

      remove-double-neg [=>]0.95

      \[ \mathsf{fma}\left(y, \frac{\color{blue}{t} + \left(-z\right)}{a}, x\right) \]

      sub-neg [<=]0.95

      \[ \mathsf{fma}\left(y, \frac{\color{blue}{t - z}}{a}, x\right) \]

    if -1.9999999999999999e261 < (*.f64 y (-.f64 z t)) < 4.99999999999999985e223

    1. Initial program 0.41

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

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

Alternatives

Alternative 1
Error0.42%
Cost1352
\[\begin{array}{l} t_1 := y \cdot \left(z - t\right)\\ \mathbf{if}\;t_1 \leq -2.5 \cdot 10^{+261}:\\ \;\;\;\;x - \frac{y}{\frac{a}{z - t}}\\ \mathbf{elif}\;t_1 \leq 10^{+264}:\\ \;\;\;\;x + \frac{y \cdot \left(t - z\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{a} \cdot \left(t - z\right)\\ \end{array} \]
Alternative 2
Error27.57%
Cost1108
\[\begin{array}{l} t_1 := x + \frac{t}{\frac{a}{y}}\\ t_2 := x + \frac{y \cdot t}{a}\\ \mathbf{if}\;a \leq -2.3 \cdot 10^{+133}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -2.1 \cdot 10^{+113}:\\ \;\;\;\;y \cdot \frac{t - z}{a}\\ \mathbf{elif}\;a \leq -1.25 \cdot 10^{-211}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -6.2 \cdot 10^{-304}:\\ \;\;\;\;\frac{y \cdot \left(-z\right)}{a}\\ \mathbf{elif}\;a \leq 2.7 \cdot 10^{-280}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error2.72%
Cost1097
\[\begin{array}{l} \mathbf{if}\;z - t \leq -2 \cdot 10^{+92} \lor \neg \left(z - t \leq 10^{+42}\right):\\ \;\;\;\;x + \frac{y}{a} \cdot \left(t - z\right)\\ \mathbf{else}:\\ \;\;\;\;x - \frac{y}{\frac{a}{z - t}}\\ \end{array} \]
Alternative 4
Error25.02%
Cost978
\[\begin{array}{l} \mathbf{if}\;x \leq -8.5 \cdot 10^{-158} \lor \neg \left(x \leq -2.25 \cdot 10^{-241}\right) \land \left(x \leq 1.56 \cdot 10^{-257} \lor \neg \left(x \leq 8.5 \cdot 10^{-205}\right)\right):\\ \;\;\;\;x + \frac{t}{\frac{a}{y}}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{t - z}{a}\\ \end{array} \]
Alternative 5
Error47.15%
Cost848
\[\begin{array}{l} t_1 := t \cdot \frac{y}{a}\\ \mathbf{if}\;t \leq -7.2 \cdot 10^{+194}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -4.6 \cdot 10^{-201}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq -2.8 \cdot 10^{-229}:\\ \;\;\;\;-y \cdot \frac{z}{a}\\ \mathbf{elif}\;t \leq 2.4 \cdot 10^{+92}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error47.09%
Cost848
\[\begin{array}{l} t_1 := t \cdot \frac{y}{a}\\ \mathbf{if}\;t \leq -7.2 \cdot 10^{+194}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq -2.55 \cdot 10^{-201}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq -2.3 \cdot 10^{-230}:\\ \;\;\;\;-\frac{y}{\frac{a}{z}}\\ \mathbf{elif}\;t \leq 8 \cdot 10^{+91}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error4.91%
Cost841
\[\begin{array}{l} \mathbf{if}\;t \leq -7.4 \cdot 10^{-131} \lor \neg \left(t \leq 5.4 \cdot 10^{-230}\right):\\ \;\;\;\;x + \frac{y}{a} \cdot \left(t - z\right)\\ \mathbf{else}:\\ \;\;\;\;x - \frac{y}{\frac{a}{z}}\\ \end{array} \]
Alternative 8
Error15.19%
Cost713
\[\begin{array}{l} \mathbf{if}\;t \leq -260 \lor \neg \left(t \leq 5.8 \cdot 10^{-25}\right):\\ \;\;\;\;x + \frac{t}{\frac{a}{y}}\\ \mathbf{else}:\\ \;\;\;\;x - \frac{y}{\frac{a}{z}}\\ \end{array} \]
Alternative 9
Error33.64%
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -1.55 \cdot 10^{+58}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5.5 \cdot 10^{-127}:\\ \;\;\;\;y \cdot \frac{t - z}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error46.59%
Cost585
\[\begin{array}{l} \mathbf{if}\;t \leq -1.15 \cdot 10^{+195} \lor \neg \left(t \leq 1.5 \cdot 10^{+91}\right):\\ \;\;\;\;t \cdot \frac{y}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 11
Error47.05%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.55 \cdot 10^{+58}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.05 \cdot 10^{-127}:\\ \;\;\;\;y \cdot \frac{t}{a}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error48.34%
Cost64
\[x \]

Error

Reproduce?

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