Average Error: 6.2 → 2.0
Time: 26.2s
Precision: binary64
Cost: 8004
\[2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right) \]
\[\begin{array}{l} t_1 := a + b \cdot c\\ t_2 := i \cdot \left(c \cdot t_1\right)\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;2 \cdot \mathsf{fma}\left(y, x, z \cdot t - c \cdot \left(b \cdot \left(c \cdot i\right)\right)\right)\\ \mathbf{elif}\;t_2 \leq 10^{+294}:\\ \;\;\;\;2 \cdot \left(\left(x \cdot y + z \cdot t\right) - t_2\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(x \cdot y - c \cdot \left(t_1 \cdot i\right)\right)\\ \end{array} \]
(FPCore (x y z t a b c i)
 :precision binary64
 (* 2.0 (- (+ (* x y) (* z t)) (* (* (+ a (* b c)) c) i))))
(FPCore (x y z t a b c i)
 :precision binary64
 (let* ((t_1 (+ a (* b c))) (t_2 (* i (* c t_1))))
   (if (<= t_2 (- INFINITY))
     (* 2.0 (fma y x (- (* z t) (* c (* b (* c i))))))
     (if (<= t_2 1e+294)
       (* 2.0 (- (+ (* x y) (* z t)) t_2))
       (* 2.0 (- (* x y) (* c (* t_1 i))))))))
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
	return 2.0 * (((x * y) + (z * t)) - (((a + (b * c)) * c) * i));
}
double code(double x, double y, double z, double t, double a, double b, double c, double i) {
	double t_1 = a + (b * c);
	double t_2 = i * (c * t_1);
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = 2.0 * fma(y, x, ((z * t) - (c * (b * (c * i)))));
	} else if (t_2 <= 1e+294) {
		tmp = 2.0 * (((x * y) + (z * t)) - t_2);
	} else {
		tmp = 2.0 * ((x * y) - (c * (t_1 * i)));
	}
	return tmp;
}
function code(x, y, z, t, a, b, c, i)
	return Float64(2.0 * Float64(Float64(Float64(x * y) + Float64(z * t)) - Float64(Float64(Float64(a + Float64(b * c)) * c) * i)))
end
function code(x, y, z, t, a, b, c, i)
	t_1 = Float64(a + Float64(b * c))
	t_2 = Float64(i * Float64(c * t_1))
	tmp = 0.0
	if (t_2 <= Float64(-Inf))
		tmp = Float64(2.0 * fma(y, x, Float64(Float64(z * t) - Float64(c * Float64(b * Float64(c * i))))));
	elseif (t_2 <= 1e+294)
		tmp = Float64(2.0 * Float64(Float64(Float64(x * y) + Float64(z * t)) - t_2));
	else
		tmp = Float64(2.0 * Float64(Float64(x * y) - Float64(c * Float64(t_1 * i))));
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_, c_, i_] := N[(2.0 * N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] - N[(N[(N[(a + N[(b * c), $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision] * i), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_, c_, i_] := Block[{t$95$1 = N[(a + N[(b * c), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(i * N[(c * t$95$1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], N[(2.0 * N[(y * x + N[(N[(z * t), $MachinePrecision] - N[(c * N[(b * N[(c * i), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 1e+294], N[(2.0 * N[(N[(N[(x * y), $MachinePrecision] + N[(z * t), $MachinePrecision]), $MachinePrecision] - t$95$2), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(N[(x * y), $MachinePrecision] - N[(c * N[(t$95$1 * i), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right)
\begin{array}{l}
t_1 := a + b \cdot c\\
t_2 := i \cdot \left(c \cdot t_1\right)\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;2 \cdot \mathsf{fma}\left(y, x, z \cdot t - c \cdot \left(b \cdot \left(c \cdot i\right)\right)\right)\\

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

\mathbf{else}:\\
\;\;\;\;2 \cdot \left(x \cdot y - c \cdot \left(t_1 \cdot i\right)\right)\\


\end{array}

Error

Target

Original6.2
Target1.8
Herbie2.0
\[2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(a + b \cdot c\right) \cdot \left(c \cdot i\right)\right) \]

Derivation

  1. Split input into 3 regimes
  2. if (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i) < -inf.0

    1. Initial program 64.0

      \[2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right) \]
    2. Taylor expanded in a around 0 60.7

      \[\leadsto 2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\color{blue}{\left(c \cdot b\right)} \cdot c\right) \cdot i\right) \]
    3. Applied egg-rr15.7

      \[\leadsto 2 \cdot \color{blue}{\mathsf{fma}\left(y, x, z \cdot t - c \cdot \left(b \cdot \left(c \cdot i\right)\right)\right)} \]

    if -inf.0 < (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i) < 1.00000000000000007e294

    1. Initial program 0.4

      \[2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right) \]

    if 1.00000000000000007e294 < (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i)

    1. Initial program 56.8

      \[2 \cdot \left(\left(x \cdot y + z \cdot t\right) - \left(\left(a + b \cdot c\right) \cdot c\right) \cdot i\right) \]
    2. Taylor expanded in z around 0 18.9

      \[\leadsto 2 \cdot \color{blue}{\left(y \cdot x - c \cdot \left(i \cdot \left(c \cdot b + a\right)\right)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \cdot \left(c \cdot \left(a + b \cdot c\right)\right) \leq -\infty:\\ \;\;\;\;2 \cdot \mathsf{fma}\left(y, x, z \cdot t - c \cdot \left(b \cdot \left(c \cdot i\right)\right)\right)\\ \mathbf{elif}\;i \cdot \left(c \cdot \left(a + b \cdot c\right)\right) \leq 10^{+294}:\\ \;\;\;\;2 \cdot \left(\left(x \cdot y + z \cdot t\right) - i \cdot \left(c \cdot \left(a + b \cdot c\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(x \cdot y - c \cdot \left(\left(a + b \cdot c\right) \cdot i\right)\right)\\ \end{array} \]

Alternatives

Alternative 1
Error1.8
Cost7488
\[2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \left(a + b \cdot c\right) \cdot \left(c \cdot i\right)\right) \]
Alternative 2
Error3.0
Cost2504
\[\begin{array}{l} t_1 := x \cdot y + z \cdot t\\ t_2 := a + b \cdot c\\ t_3 := i \cdot \left(c \cdot t_2\right)\\ \mathbf{if}\;t_3 \leq -\infty:\\ \;\;\;\;2 \cdot \left(t_1 - c \cdot \left(a \cdot i\right)\right)\\ \mathbf{elif}\;t_3 \leq 10^{+294}:\\ \;\;\;\;2 \cdot \left(t_1 - t_3\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(x \cdot y - c \cdot \left(t_2 \cdot i\right)\right)\\ \end{array} \]
Alternative 3
Error22.0
Cost2413
\[\begin{array}{l} t_1 := 2 \cdot \left(z \cdot t - c \cdot \left(\left(a + b \cdot c\right) \cdot i\right)\right)\\ t_2 := i \cdot \left(a \cdot c\right)\\ t_3 := 2 \cdot \left(x \cdot y - t_2\right)\\ t_4 := 2 \cdot \left(x \cdot y + z \cdot t\right)\\ \mathbf{if}\;t \leq -7.2 \cdot 10^{-115}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;t \leq 2.6 \cdot 10^{-195}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 8 \cdot 10^{-87}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 1.25 \cdot 10^{-56}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 1.4 \cdot 10^{+68}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;t \leq 3.3 \cdot 10^{+93}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 3.2 \cdot 10^{+122}:\\ \;\;\;\;2 \cdot \left(z \cdot t - t_2\right)\\ \mathbf{elif}\;t \leq 1.55 \cdot 10^{+134}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 2.5 \cdot 10^{+144}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 5.5 \cdot 10^{+245} \lor \neg \left(t \leq 7 \cdot 10^{+273}\right):\\ \;\;\;\;t_4\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error11.2
Cost2388
\[\begin{array}{l} t_1 := x \cdot y + z \cdot t\\ t_2 := 2 \cdot \left(t_1 - c \cdot \left(a \cdot i\right)\right)\\ \mathbf{if}\;x \cdot y \leq -1 \cdot 10^{-168}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \cdot y \leq 4 \cdot 10^{-182}:\\ \;\;\;\;2 \cdot \left(z \cdot t - c \cdot \left(\left(a + b \cdot c\right) \cdot i\right)\right)\\ \mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{-32}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \cdot y \leq 2 \cdot 10^{-26}:\\ \;\;\;\;\left(b \cdot \left(c \cdot \left(c \cdot i\right)\right)\right) \cdot -2\\ \mathbf{elif}\;x \cdot y \leq 5 \cdot 10^{+159}:\\ \;\;\;\;2 \cdot \left(t_1 - i \cdot \left(c \cdot \left(b \cdot c\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error18.6
Cost2281
\[\begin{array}{l} t_1 := 2 \cdot \left(z \cdot t - i \cdot \left(a \cdot c\right)\right)\\ t_2 := c \cdot \left(\left(a + b \cdot c\right) \cdot i\right)\\ t_3 := 2 \cdot \left(x \cdot y - t_2\right)\\ t_4 := 2 \cdot \left(x \cdot y + z \cdot t\right)\\ t_5 := 2 \cdot \left(z \cdot t - t_2\right)\\ \mathbf{if}\;t \leq -2.8 \cdot 10^{-126}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;t \leq 1.35 \cdot 10^{-130}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 7.6 \cdot 10^{-87}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 0.175:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 1.25 \cdot 10^{+42}:\\ \;\;\;\;t_5\\ \mathbf{elif}\;t \leq 1.7 \cdot 10^{+68}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;t \leq 6.6 \cdot 10^{+92}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t \leq 5.8 \cdot 10^{+135}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 6.5 \cdot 10^{+241} \lor \neg \left(t \leq 1.3 \cdot 10^{+274}\right):\\ \;\;\;\;t_4\\ \mathbf{else}:\\ \;\;\;\;t_5\\ \end{array} \]
Alternative 6
Error22.8
Cost1760
\[\begin{array}{l} t_1 := 2 \cdot \left(z \cdot t - i \cdot \left(a \cdot c\right)\right)\\ t_2 := 2 \cdot \left(x \cdot y + z \cdot t\right)\\ t_3 := \left(c \cdot \left(\left(a + b \cdot c\right) \cdot i\right)\right) \cdot -2\\ \mathbf{if}\;c \leq -2.7 \cdot 10^{+151}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;c \leq -1.55 \cdot 10^{-21}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq -1 \cdot 10^{-68}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq -3.8 \cdot 10^{-204}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq -2.9 \cdot 10^{-239}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 6.1 \cdot 10^{-158}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;c \leq 1.25 \cdot 10^{-12}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;c \leq 1.04 \cdot 10^{+43}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 7
Error22.6
Cost1496
\[\begin{array}{l} t_1 := 2 \cdot \left(z \cdot t - i \cdot \left(a \cdot c\right)\right)\\ t_2 := 2 \cdot \left(x \cdot y - c \cdot \left(a \cdot i\right)\right)\\ \mathbf{if}\;a \leq -1.8 \cdot 10^{+212}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -2.9 \cdot 10^{+139}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -3.6 \cdot 10^{+91}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -2.4 \cdot 10^{+22}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 6 \cdot 10^{+54}:\\ \;\;\;\;2 \cdot \left(x \cdot y + z \cdot t\right)\\ \mathbf{elif}\;a \leq 2.6 \cdot 10^{+263}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 8
Error11.0
Cost1481
\[\begin{array}{l} \mathbf{if}\;x \cdot y \leq -1 \cdot 10^{-168} \lor \neg \left(x \cdot y \leq 4 \cdot 10^{-182}\right):\\ \;\;\;\;2 \cdot \left(\left(x \cdot y + z \cdot t\right) - c \cdot \left(a \cdot i\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(z \cdot t - c \cdot \left(\left(a + b \cdot c\right) \cdot i\right)\right)\\ \end{array} \]
Alternative 9
Error41.6
Cost1241
\[\begin{array}{l} t_1 := 2 \cdot \left(z \cdot t\right)\\ t_2 := -2 \cdot \left(i \cdot \left(a \cdot c\right)\right)\\ t_3 := 2 \cdot \left(x \cdot y\right)\\ \mathbf{if}\;a \leq -2.5 \cdot 10^{+101}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -3.8 \cdot 10^{-307}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 1.45 \cdot 10^{-92}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq 2.8 \cdot 10^{-65}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 8 \cdot 10^{+54} \lor \neg \left(a \leq 6.5 \cdot 10^{+281}\right):\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 10
Error40.5
Cost1241
\[\begin{array}{l} t_1 := 2 \cdot \left(z \cdot t\right)\\ t_2 := -2 \cdot \left(a \cdot \left(c \cdot i\right)\right)\\ t_3 := 2 \cdot \left(x \cdot y\right)\\ \mathbf{if}\;a \leq -2.45 \cdot 10^{+101}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 2.1 \cdot 10^{-307}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 5.4 \cdot 10^{-95}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq 5 \cdot 10^{-69}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 1.85 \cdot 10^{+55} \lor \neg \left(a \leq 5.8 \cdot 10^{+281}\right):\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 11
Error21.7
Cost1100
\[\begin{array}{l} t_1 := i \cdot \left(a \cdot c\right)\\ \mathbf{if}\;a \leq -4 \cdot 10^{+101}:\\ \;\;\;\;2 \cdot \left(x \cdot y - t_1\right)\\ \mathbf{elif}\;a \leq 8.5 \cdot 10^{+54}:\\ \;\;\;\;2 \cdot \left(x \cdot y + z \cdot t\right)\\ \mathbf{elif}\;a \leq 6.5 \cdot 10^{+263}:\\ \;\;\;\;2 \cdot \left(z \cdot t - t_1\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(x \cdot y - c \cdot \left(a \cdot i\right)\right)\\ \end{array} \]
Alternative 12
Error37.2
Cost848
\[\begin{array}{l} t_1 := 2 \cdot \left(x \cdot y\right)\\ t_2 := 2 \cdot \left(z \cdot t\right)\\ \mathbf{if}\;z \leq -8 \cdot 10^{-15}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.4 \cdot 10^{-226}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2.4 \cdot 10^{-279}:\\ \;\;\;\;-2 \cdot \left(c \cdot \left(a \cdot i\right)\right)\\ \mathbf{elif}\;z \leq 4.1 \cdot 10^{-157}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 13
Error24.6
Cost844
\[\begin{array}{l} t_1 := -2 \cdot \left(a \cdot \left(c \cdot i\right)\right)\\ \mathbf{if}\;a \leq -1.7 \cdot 10^{+114}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 6.5 \cdot 10^{+98}:\\ \;\;\;\;2 \cdot \left(x \cdot y + z \cdot t\right)\\ \mathbf{elif}\;a \leq 6.2 \cdot 10^{+279}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(x \cdot y\right)\\ \end{array} \]
Alternative 14
Error36.6
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -1.5 \cdot 10^{-14} \lor \neg \left(z \leq 4.1 \cdot 10^{-157}\right):\\ \;\;\;\;2 \cdot \left(z \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(x \cdot y\right)\\ \end{array} \]
Alternative 15
Error42.9
Cost320
\[2 \cdot \left(z \cdot t\right) \]
Alternative 16
Error62.2
Cost64
\[0 \]

Error

Reproduce

herbie shell --seed 2022343 
(FPCore (x y z t a b c i)
  :name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, A"
  :precision binary64

  :herbie-target
  (* 2.0 (- (+ (* x y) (* z t)) (* (+ a (* b c)) (* c i))))

  (* 2.0 (- (+ (* x y) (* z t)) (* (* (+ a (* b c)) c) i))))