Average Error: 6.4 → 0.9
Time: 10.4s
Precision: binary64
Cost: 8136
\[x + \frac{y \cdot \left(z - x\right)}{t} \]
\[\begin{array}{l} t_1 := \mathsf{fma}\left(y, \frac{z - x}{t}, x\right)\\ t_2 := x + \frac{y \cdot \left(z - x\right)}{t}\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 10^{+293}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (fma y (/ (- z x) t) x)) (t_2 (+ x (/ (* y (- z x)) t))))
   (if (<= t_2 (- INFINITY)) t_1 (if (<= t_2 1e+293) t_2 t_1))))
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 t_1 = fma(y, ((z - x) / t), x);
	double t_2 = x + ((y * (z - x)) / t);
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = t_1;
	} else if (t_2 <= 1e+293) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	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)
	t_1 = fma(y, Float64(Float64(z - x) / t), x)
	t_2 = Float64(x + Float64(Float64(y * Float64(z - x)) / t))
	tmp = 0.0
	if (t_2 <= Float64(-Inf))
		tmp = t_1;
	elseif (t_2 <= 1e+293)
		tmp = t_2;
	else
		tmp = t_1;
	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_] := Block[{t$95$1 = N[(y * N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision] + x), $MachinePrecision]}, Block[{t$95$2 = N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], t$95$1, If[LessEqual[t$95$2, 1e+293], t$95$2, t$95$1]]]]
x + \frac{y \cdot \left(z - x\right)}{t}
\begin{array}{l}
t_1 := \mathsf{fma}\left(y, \frac{z - x}{t}, x\right)\\
t_2 := x + \frac{y \cdot \left(z - x\right)}{t}\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_2 \leq 10^{+293}:\\
\;\;\;\;t_2\\

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


\end{array}

Error

Target

Original6.4
Target2.2
Herbie0.9
\[x - \left(x \cdot \frac{y}{t} + \left(-z\right) \cdot \frac{y}{t}\right) \]

Derivation

  1. Split input into 2 regimes
  2. if (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) < -inf.0 or 9.9999999999999992e292 < (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t))

    1. Initial program 55.8

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, \frac{z - x}{t}, x\right)} \]
      Proof
      (fma.f64 y (/.f64 (-.f64 z x) t) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 y (/.f64 (-.f64 z x) t)) x)): 0 points increase in error, 2 points decrease in error
      (+.f64 (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 y (-.f64 z x)) t)) x): 42 points increase in error, 38 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t))): 0 points increase in error, 0 points decrease in error

    if -inf.0 < (+.f64 x (/.f64 (*.f64 y (-.f64 z x)) t)) < 9.9999999999999992e292

    1. Initial program 0.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x + \frac{y \cdot \left(z - x\right)}{t} \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(y, \frac{z - x}{t}, x\right)\\ \mathbf{elif}\;x + \frac{y \cdot \left(z - x\right)}{t} \leq 10^{+293}:\\ \;\;\;\;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
Error3.1
Cost1864
\[\begin{array}{l} t_1 := x + \frac{y \cdot \left(z - x\right)}{t}\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;x - x \cdot \frac{y}{t}\\ \mathbf{elif}\;t_1 \leq 10^{+293}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + y \cdot \frac{z}{t}\\ \end{array} \]
Alternative 2
Error18.8
Cost1108
\[\begin{array}{l} t_1 := \frac{z - x}{\frac{t}{y}}\\ t_2 := x - \frac{y}{\frac{t}{x}}\\ \mathbf{if}\;x \leq -5.751085135312617 \cdot 10^{-81}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -9.870121280897563 \cdot 10^{-141}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.1292509909742563 \cdot 10^{-169}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.3970343556013374 \cdot 10^{-274}:\\ \;\;\;\;\frac{y \cdot \left(z - x\right)}{t}\\ \mathbf{elif}\;x \leq 4.272794682655018 \cdot 10^{-101}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error16.3
Cost1108
\[\begin{array}{l} t_1 := \frac{z - x}{\frac{t}{y}}\\ t_2 := x - x \cdot \frac{y}{t}\\ \mathbf{if}\;x \leq -5.751085135312617 \cdot 10^{-81}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -9.870121280897563 \cdot 10^{-141}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.1292509909742563 \cdot 10^{-169}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.3970343556013374 \cdot 10^{-274}:\\ \;\;\;\;\frac{y \cdot \left(z - x\right)}{t}\\ \mathbf{elif}\;x \leq 4.272794682655018 \cdot 10^{-101}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error25.8
Cost980
\[\begin{array}{l} t_1 := \frac{z}{\frac{t}{y}}\\ \mathbf{if}\;x \leq -5.751085135312617 \cdot 10^{-81}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -9.870121280897563 \cdot 10^{-141}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.1292509909742563 \cdot 10^{-169}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.3970343556013374 \cdot 10^{-274}:\\ \;\;\;\;\frac{y \cdot z}{t}\\ \mathbf{elif}\;x \leq 4.272794682655018 \cdot 10^{-101}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error11.3
Cost976
\[\begin{array}{l} t_1 := x + y \cdot \frac{z}{t}\\ t_2 := x - x \cdot \frac{y}{t}\\ \mathbf{if}\;x \leq -1.7280191389896422 \cdot 10^{-43}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -2.1292509909742563 \cdot 10^{-169}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -6.857850161955733 \cdot 10^{-245}:\\ \;\;\;\;\frac{z - x}{\frac{t}{y}}\\ \mathbf{elif}\;x \leq 9.46027295064604 \cdot 10^{-43}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error11.2
Cost976
\[\begin{array}{l} t_1 := x + \frac{y \cdot z}{t}\\ t_2 := x - x \cdot \frac{y}{t}\\ \mathbf{if}\;x \leq -2.0307850805105914 \cdot 10^{+53}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 6.269791038530099 \cdot 10^{-253}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.518083584242054 \cdot 10^{-198}:\\ \;\;\;\;\frac{z - x}{\frac{t}{y}}\\ \mathbf{elif}\;x \leq 9.46027295064604 \cdot 10^{-43}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Error23.3
Cost712
\[\begin{array}{l} \mathbf{if}\;t \leq -8.844349846648677 \cdot 10^{+102}:\\ \;\;\;\;x\\ \mathbf{elif}\;t \leq 5.8 \cdot 10^{-73}:\\ \;\;\;\;\frac{y \cdot \left(z - x\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 8
Error19.2
Cost712
\[\begin{array}{l} t_1 := x - \frac{y}{\frac{t}{x}}\\ \mathbf{if}\;t \leq -2.6 \cdot 10^{-104}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 7.8 \cdot 10^{-57}:\\ \;\;\;\;\frac{y \cdot \left(z - x\right)}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error25.5
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -5.751085135312617 \cdot 10^{-81}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.272794682655018 \cdot 10^{-101}:\\ \;\;\;\;\frac{z}{\frac{t}{y}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error31.8
Cost64
\[x \]

Error

Reproduce

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