?

Average Error: 6.5 → 2.6
Time: 24.3s
Precision: binary64
Cost: 8648

?

\[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:\\ \;\;\;\;\left(c \cdot \left(t_1 \cdot i\right)\right) \cdot -2\\ \mathbf{elif}\;t_2 \leq 4 \cdot 10^{+296}:\\ \;\;\;\;2 \cdot \left(\left(z \cdot t + x \cdot y\right) - t_2\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - c \cdot \left(c \cdot \left(b \cdot i\right)\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))
     (* (* c (* t_1 i)) -2.0)
     (if (<= t_2 4e+296)
       (* 2.0 (- (+ (* z t) (* x y)) t_2))
       (* 2.0 (- (fma x y (* z t)) (* c (* c (* b 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 = (c * (t_1 * i)) * -2.0;
	} else if (t_2 <= 4e+296) {
		tmp = 2.0 * (((z * t) + (x * y)) - t_2);
	} else {
		tmp = 2.0 * (fma(x, y, (z * t)) - (c * (c * (b * 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(Float64(c * Float64(t_1 * i)) * -2.0);
	elseif (t_2 <= 4e+296)
		tmp = Float64(2.0 * Float64(Float64(Float64(z * t) + Float64(x * y)) - t_2));
	else
		tmp = Float64(2.0 * Float64(fma(x, y, Float64(z * t)) - Float64(c * Float64(c * Float64(b * 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[(N[(c * N[(t$95$1 * i), $MachinePrecision]), $MachinePrecision] * -2.0), $MachinePrecision], If[LessEqual[t$95$2, 4e+296], N[(2.0 * N[(N[(N[(z * t), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision] - t$95$2), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(N[(x * y + N[(z * t), $MachinePrecision]), $MachinePrecision] - N[(c * N[(c * N[(b * i), $MachinePrecision]), $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:\\
\;\;\;\;\left(c \cdot \left(t_1 \cdot i\right)\right) \cdot -2\\

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

\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - c \cdot \left(c \cdot \left(b \cdot i\right)\right)\right)\\


\end{array}

Error?

Target

Original6.5
Target2.1
Herbie2.6
\[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 i around inf 25.2

      \[\leadsto 2 \cdot \color{blue}{\left(-1 \cdot \left(c \cdot \left(i \cdot \left(c \cdot b + a\right)\right)\right)\right)} \]

    if -inf.0 < (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i) < 3.99999999999999993e296

    1. Initial program 0.3

      \[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 3.99999999999999993e296 < (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i)

    1. Initial program 60.2

      \[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. Simplified13.3

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

      [Start]60.2

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

      *-commutative [=>]60.2

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

      associate-*l* [=>]13.3

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

      cancel-sign-sub-inv [=>]13.3

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

      cancel-sign-sub [<=]13.3

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

      fma-def [=>]13.3

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

      remove-double-neg [=>]13.3

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

      +-commutative [=>]13.3

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

      fma-def [=>]13.3

      \[ 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - c \cdot \left(\color{blue}{\mathsf{fma}\left(b, c, a\right)} \cdot i\right)\right) \]
    3. Taylor expanded in b around inf 20.5

      \[\leadsto 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - c \cdot \color{blue}{\left(c \cdot \left(i \cdot b\right)\right)}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.6

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

Alternatives

Alternative 1
Error2.1
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
Error10.5
Cost3536
\[\begin{array}{l} t_1 := a + b \cdot c\\ t_2 := i \cdot \left(c \cdot t_1\right)\\ t_3 := 2 \cdot \left(z \cdot t - t_2\right)\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;\left(c \cdot \left(t_1 \cdot i\right)\right) \cdot -2\\ \mathbf{elif}\;t_2 \leq -2 \cdot 10^{+59}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_2 \leq 4 \cdot 10^{-48}:\\ \;\;\;\;2 \cdot \left(z \cdot t + x \cdot y\right)\\ \mathbf{elif}\;t_2 \leq 4 \cdot 10^{+296}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(x \cdot y - \left(c \cdot i\right) \cdot \left(b \cdot c\right)\right)\\ \end{array} \]
Alternative 3
Error9.9
Cost2892
\[\begin{array}{l} t_1 := a + b \cdot c\\ t_2 := 2 \cdot \left(x \cdot y - t_1 \cdot \left(c \cdot i\right)\right)\\ t_3 := i \cdot \left(c \cdot t_1\right)\\ \mathbf{if}\;t_3 \leq -2 \cdot 10^{+237}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_3 \leq -2 \cdot 10^{+59}:\\ \;\;\;\;2 \cdot \left(z \cdot t - t_3\right)\\ \mathbf{elif}\;t_3 \leq 2 \cdot 10^{-13}:\\ \;\;\;\;2 \cdot \left(z \cdot t + x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error2.4
Cost2504
\[\begin{array}{l} t_1 := a + b \cdot c\\ t_2 := i \cdot \left(c \cdot t_1\right)\\ t_3 := z \cdot t + x \cdot y\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;\left(c \cdot \left(t_1 \cdot i\right)\right) \cdot -2\\ \mathbf{elif}\;t_2 \leq 4 \cdot 10^{+296}:\\ \;\;\;\;2 \cdot \left(t_3 - t_2\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(t_3 - c \cdot \left(b \cdot \left(c \cdot i\right)\right)\right)\\ \end{array} \]
Alternative 5
Error27.0
Cost2153
\[\begin{array}{l} t_1 := 2 \cdot \left(x \cdot y - i \cdot \left(a \cdot c\right)\right)\\ t_2 := 2 \cdot \left(z \cdot t - c \cdot \left(b \cdot \left(c \cdot i\right)\right)\right)\\ \mathbf{if}\;x \leq -2.3 \cdot 10^{-5}:\\ \;\;\;\;2 \cdot \left(z \cdot t + x \cdot y\right)\\ \mathbf{elif}\;x \leq -2.15 \cdot 10^{-40}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -3.6 \cdot 10^{-54}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.3 \cdot 10^{-254}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.2 \cdot 10^{-279}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.2 \cdot 10^{-301}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 2.5 \cdot 10^{-230}:\\ \;\;\;\;\left(c \cdot \left(\left(a + b \cdot c\right) \cdot i\right)\right) \cdot -2\\ \mathbf{elif}\;x \leq 3 \cdot 10^{-203} \lor \neg \left(x \leq 6.2 \cdot 10^{-141}\right) \land x \leq 1.15 \cdot 10^{-80}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error27.4
Cost2024
\[\begin{array}{l} t_1 := 2 \cdot \left(z \cdot t + x \cdot y\right)\\ t_2 := 2 \cdot \left(z \cdot t - c \cdot \left(b \cdot \left(c \cdot i\right)\right)\right)\\ t_3 := 2 \cdot \left(x \cdot y - i \cdot \left(a \cdot c\right)\right)\\ \mathbf{if}\;a \leq -5.2 \cdot 10^{+131}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq -1.1 \cdot 10^{+102}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq -1.06 \cdot 10^{+26}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq -1.45 \cdot 10^{-125}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 8.6 \cdot 10^{-198}:\\ \;\;\;\;2 \cdot \left(x \cdot y - \left(c \cdot i\right) \cdot \left(b \cdot c\right)\right)\\ \mathbf{elif}\;a \leq 10^{+49}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a \leq 3.6 \cdot 10^{+143}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;a \leq 1.6 \cdot 10^{+167}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a \leq 7.8 \cdot 10^{+204}:\\ \;\;\;\;-2 \cdot \left(a \cdot \left(c \cdot i\right)\right)\\ \mathbf{elif}\;a \leq 4.8 \cdot 10^{+272}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\left(c \cdot \left(\left(a + b \cdot c\right) \cdot i\right)\right) \cdot -2\\ \end{array} \]
Alternative 7
Error9.1
Cost1609
\[\begin{array}{l} \mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+49} \lor \neg \left(z \cdot t \leq 4 \cdot 10^{-93}\right):\\ \;\;\;\;2 \cdot \left(\left(z \cdot t + x \cdot y\right) - c \cdot \left(b \cdot \left(c \cdot i\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(x \cdot y - \left(a + b \cdot c\right) \cdot \left(c \cdot i\right)\right)\\ \end{array} \]
Alternative 8
Error22.5
Cost969
\[\begin{array}{l} \mathbf{if}\;z \leq -2 \cdot 10^{+51} \lor \neg \left(z \leq 10^{-145}\right):\\ \;\;\;\;2 \cdot \left(z \cdot t + x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(x \cdot y - i \cdot \left(a \cdot c\right)\right)\\ \end{array} \]
Alternative 9
Error20.0
Cost969
\[\begin{array}{l} \mathbf{if}\;c \leq -4 \cdot 10^{+45} \lor \neg \left(c \leq 7 \cdot 10^{+79}\right):\\ \;\;\;\;\left(c \cdot \left(\left(a + b \cdot c\right) \cdot i\right)\right) \cdot -2\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(z \cdot t + x \cdot y\right)\\ \end{array} \]
Alternative 10
Error36.5
Cost850
\[\begin{array}{l} \mathbf{if}\;z \leq -9.6 \cdot 10^{+85} \lor \neg \left(z \leq -4 \cdot 10^{+68} \lor \neg \left(z \leq -1.3 \cdot 10^{+51}\right) \land z \leq 1.38 \cdot 10^{-96}\right):\\ \;\;\;\;2 \cdot \left(z \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(x \cdot y\right)\\ \end{array} \]
Alternative 11
Error22.7
Cost841
\[\begin{array}{l} \mathbf{if}\;c \leq -5.4 \cdot 10^{+45} \lor \neg \left(c \leq 1.12 \cdot 10^{+79}\right):\\ \;\;\;\;\left(c \cdot \left(c \cdot \left(b \cdot i\right)\right)\right) \cdot -2\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(z \cdot t + x \cdot y\right)\\ \end{array} \]
Alternative 12
Error22.4
Cost841
\[\begin{array}{l} \mathbf{if}\;c \leq -5.4 \cdot 10^{+45} \lor \neg \left(c \leq 5 \cdot 10^{+80}\right):\\ \;\;\;\;\left(c \cdot \left(b \cdot \left(c \cdot i\right)\right)\right) \cdot -2\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(z \cdot t + x \cdot y\right)\\ \end{array} \]
Alternative 13
Error22.9
Cost840
\[\begin{array}{l} \mathbf{if}\;c \leq -2.65 \cdot 10^{+125}:\\ \;\;\;\;\left(c \cdot \left(c \cdot i\right)\right) \cdot \left(b \cdot -2\right)\\ \mathbf{elif}\;c \leq 3.7 \cdot 10^{+80}:\\ \;\;\;\;2 \cdot \left(z \cdot t + x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(c \cdot \left(c \cdot \left(b \cdot i\right)\right)\right) \cdot -2\\ \end{array} \]
Alternative 14
Error22.7
Cost840
\[\begin{array}{l} \mathbf{if}\;c \leq -5.4 \cdot 10^{+45}:\\ \;\;\;\;\left(c \cdot \left(b \cdot \left(c \cdot i\right)\right)\right) \cdot -2\\ \mathbf{elif}\;c \leq 3.5 \cdot 10^{+77}:\\ \;\;\;\;2 \cdot \left(z \cdot t + x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \left(c \cdot \left(i \cdot \left(b \cdot c\right)\right)\right)\\ \end{array} \]
Alternative 15
Error42.6
Cost320
\[2 \cdot \left(z \cdot t\right) \]
Alternative 16
Error62.2
Cost64
\[0 \]

Error

Reproduce?

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