?

Average Error: 10.25% → 2.37%
Time: 10.7s
Precision: binary64
Cost: 7112

?

\[x + \frac{y \cdot \left(z - x\right)}{t} \]
\[\begin{array}{l} \mathbf{if}\;t \leq -4.01 \cdot 10^{-143}:\\ \;\;\;\;x + \frac{y}{t} \cdot \left(z - x\right)\\ \mathbf{elif}\;t \leq 1.2 \cdot 10^{-10}:\\ \;\;\;\;x + \frac{y \cdot \left(z - x\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{z - x}{t}, x\right)\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
(FPCore (x y z t)
 :precision binary64
 (if (<= t -4.01e-143)
   (+ x (* (/ y t) (- z x)))
   (if (<= t 1.2e-10) (+ x (/ (* y (- z x)) t)) (fma y (/ (- z x) t) x))))
double code(double x, double y, double z, double t) {
	return x + ((y * (z - x)) / t);
}
double code(double x, double y, double z, double t) {
	double tmp;
	if (t <= -4.01e-143) {
		tmp = x + ((y / t) * (z - x));
	} else if (t <= 1.2e-10) {
		tmp = x + ((y * (z - x)) / t);
	} else {
		tmp = fma(y, ((z - x) / t), x);
	}
	return tmp;
}
function code(x, y, z, t)
	return Float64(x + Float64(Float64(y * Float64(z - x)) / t))
end
function code(x, y, z, t)
	tmp = 0.0
	if (t <= -4.01e-143)
		tmp = Float64(x + Float64(Float64(y / t) * Float64(z - x)));
	elseif (t <= 1.2e-10)
		tmp = Float64(x + Float64(Float64(y * Float64(z - x)) / t));
	else
		tmp = fma(y, Float64(Float64(z - x) / t), x);
	end
	return tmp
end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := If[LessEqual[t, -4.01e-143], N[(x + N[(N[(y / t), $MachinePrecision] * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, 1.2e-10], N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(y * N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision] + x), $MachinePrecision]]]
x + \frac{y \cdot \left(z - x\right)}{t}
\begin{array}{l}
\mathbf{if}\;t \leq -4.01 \cdot 10^{-143}:\\
\;\;\;\;x + \frac{y}{t} \cdot \left(z - x\right)\\

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

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


\end{array}

Error?

Target

Original10.25%
Target3.31%
Herbie2.37%
\[x - \left(x \cdot \frac{y}{t} + \left(-z\right) \cdot \frac{y}{t}\right) \]

Derivation?

  1. Split input into 3 regimes
  2. if t < -4.0099999999999998e-143

    1. Initial program 10.96

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

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

      [Start]10.96

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

      associate-*l/ [<=]2

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

    if -4.0099999999999998e-143 < t < 1.2e-10

    1. Initial program 3.5

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

    if 1.2e-10 < t

    1. Initial program 15.29

      \[x + \frac{y \cdot \left(z - x\right)}{t} \]
    2. Simplified1.87

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

      [Start]15.29

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

      +-commutative [=>]15.29

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

      associate-*r/ [<=]1.87

      \[ \color{blue}{y \cdot \frac{z - x}{t}} + x \]

      fma-def [=>]1.87

      \[ \color{blue}{\mathsf{fma}\left(y, \frac{z - x}{t}, x\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.37

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

Alternatives

Alternative 1
Error23.01%
Cost1108
\[\begin{array}{l} t_1 := x + y \cdot \frac{z}{t}\\ t_2 := \frac{y}{t} \cdot \left(z - x\right)\\ \mathbf{if}\;y \leq -1.2 \cdot 10^{+203}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -2 \cdot 10^{-205}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 10^{-243}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 6 \cdot 10^{+202}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.18 \cdot 10^{+291}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \end{array} \]
Alternative 2
Error40.46%
Cost1044
\[\begin{array}{l} \mathbf{if}\;x \leq -4.6 \cdot 10^{-104}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.2 \cdot 10^{-106}:\\ \;\;\;\;\frac{y}{t} \cdot z\\ \mathbf{elif}\;x \leq 1.8 \cdot 10^{-30}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 1.6 \cdot 10^{-15}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{elif}\;x \leq 3.7 \cdot 10^{+17}:\\ \;\;\;\;\frac{-y}{\frac{t}{x}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error40.44%
Cost1044
\[\begin{array}{l} \mathbf{if}\;x \leq -1.7 \cdot 10^{-106}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5 \cdot 10^{-108}:\\ \;\;\;\;\frac{y}{t} \cdot z\\ \mathbf{elif}\;x \leq 1.8 \cdot 10^{-30}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{-10}:\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{elif}\;x \leq 3.7 \cdot 10^{+17}:\\ \;\;\;\;\frac{x \cdot \left(-y\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error3.71%
Cost841
\[\begin{array}{l} \mathbf{if}\;t \leq -1.45 \cdot 10^{-183} \lor \neg \left(t \leq 5.8 \cdot 10^{-296}\right):\\ \;\;\;\;x + \frac{y}{t} \cdot \left(z - x\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot \left(z - x\right)}{t}\\ \end{array} \]
Alternative 5
Error4.08%
Cost841
\[\begin{array}{l} \mathbf{if}\;z \leq -1 \cdot 10^{+25} \lor \neg \left(z \leq -6.2 \cdot 10^{-286}\right):\\ \;\;\;\;x + \frac{y}{t} \cdot \left(z - x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{\frac{t}{z - x}}\\ \end{array} \]
Alternative 6
Error2.23%
Cost841
\[\begin{array}{l} \mathbf{if}\;t \leq -4.01 \cdot 10^{-143} \lor \neg \left(t \leq 6 \cdot 10^{+18}\right):\\ \;\;\;\;x + \frac{y}{t} \cdot \left(z - x\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y \cdot \left(z - x\right)}{t}\\ \end{array} \]
Alternative 7
Error2.31%
Cost840
\[\begin{array}{l} \mathbf{if}\;t \leq -4.01 \cdot 10^{-143}:\\ \;\;\;\;x + \frac{y}{t} \cdot \left(z - x\right)\\ \mathbf{elif}\;t \leq 1.96 \cdot 10^{+40}:\\ \;\;\;\;x + \frac{y \cdot \left(z - x\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{z - x}{\frac{t}{y}}\\ \end{array} \]
Alternative 8
Error35.26%
Cost713
\[\begin{array}{l} \mathbf{if}\;y \leq -1.9 \cdot 10^{-44} \lor \neg \left(y \leq 2.3 \cdot 10^{-28}\right):\\ \;\;\;\;\frac{y}{t} \cdot \left(z - x\right)\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error16.18%
Cost713
\[\begin{array}{l} \mathbf{if}\;x \leq -1.55 \cdot 10^{-33} \lor \neg \left(x \leq 2.4 \cdot 10^{-14}\right):\\ \;\;\;\;x - x \cdot \frac{y}{t}\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{z}{t}\\ \end{array} \]
Alternative 10
Error16.17%
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -1.55 \cdot 10^{-33}:\\ \;\;\;\;x - \frac{x}{\frac{t}{y}}\\ \mathbf{elif}\;x \leq 1.7 \cdot 10^{-14}:\\ \;\;\;\;x + y \cdot \frac{z}{t}\\ \mathbf{else}:\\ \;\;\;\;x - x \cdot \frac{y}{t}\\ \end{array} \]
Alternative 11
Error45.47%
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -1.16 \cdot 10^{-42} \lor \neg \left(y \leq 2.8 \cdot 10^{-28}\right):\\ \;\;\;\;\frac{y}{\frac{t}{z}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 12
Error39.87%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -3 \cdot 10^{-108}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 6.6 \cdot 10^{-108}:\\ \;\;\;\;\frac{y}{t} \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 13
Error49.73%
Cost64
\[x \]

Error

Reproduce?

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

  :herbie-target
  (- x (+ (* x (/ y t)) (* (- z) (/ y t))))

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