Average Error: 6.4 → 1.1
Time: 20.6s
Precision: binary64
\[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 := \mathsf{fma}\left(x, y, z \cdot t\right)\\ t_2 := \left(c \cdot \left(a + b \cdot c\right)\right) \cdot i\\ \mathbf{if}\;t_2 \leq -8.531786225585547 \cdot 10^{+299}:\\ \;\;\;\;2 \cdot \mathsf{fma}\left(1, t_1, -\left(c \cdot i\right) \cdot \mathsf{fma}\left(c, b, a\right)\right)\\ \mathbf{elif}\;t_2 \leq 6.208551683926593 \cdot 10^{+300}:\\ \;\;\;\;2 \cdot \mathsf{fma}\left(x, y, z \cdot t - i \cdot \left(c \cdot \mathsf{fma}\left(c, b, a\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \left(t_1 - c \cdot \left(c \cdot \left(b \cdot i\right) + a \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 (fma x y (* z t))) (t_2 (* (* c (+ a (* b c))) i)))
   (if (<= t_2 -8.531786225585547e+299)
     (* 2.0 (fma 1.0 t_1 (- (* (* c i) (fma c b a)))))
     (if (<= t_2 6.208551683926593e+300)
       (* 2.0 (fma x y (- (* z t) (* i (* c (fma c b a))))))
       (* 2.0 (- t_1 (* c (+ (* c (* b i)) (* a 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 = fma(x, y, (z * t));
	double t_2 = (c * (a + (b * c))) * i;
	double tmp;
	if (t_2 <= -8.531786225585547e+299) {
		tmp = 2.0 * fma(1.0, t_1, -((c * i) * fma(c, b, a)));
	} else if (t_2 <= 6.208551683926593e+300) {
		tmp = 2.0 * fma(x, y, ((z * t) - (i * (c * fma(c, b, a)))));
	} else {
		tmp = 2.0 * (t_1 - (c * ((c * (b * i)) + (a * 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 = fma(x, y, Float64(z * t))
	t_2 = Float64(Float64(c * Float64(a + Float64(b * c))) * i)
	tmp = 0.0
	if (t_2 <= -8.531786225585547e+299)
		tmp = Float64(2.0 * fma(1.0, t_1, Float64(-Float64(Float64(c * i) * fma(c, b, a)))));
	elseif (t_2 <= 6.208551683926593e+300)
		tmp = Float64(2.0 * fma(x, y, Float64(Float64(z * t) - Float64(i * Float64(c * fma(c, b, a))))));
	else
		tmp = Float64(2.0 * Float64(t_1 - Float64(c * Float64(Float64(c * Float64(b * i)) + Float64(a * 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[(x * y + N[(z * t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(c * N[(a + N[(b * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * i), $MachinePrecision]}, If[LessEqual[t$95$2, -8.531786225585547e+299], N[(2.0 * N[(1.0 * t$95$1 + (-N[(N[(c * i), $MachinePrecision] * N[(c * b + a), $MachinePrecision]), $MachinePrecision])), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 6.208551683926593e+300], N[(2.0 * N[(x * y + N[(N[(z * t), $MachinePrecision] - N[(i * N[(c * N[(c * b + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(t$95$1 - N[(c * N[(N[(c * N[(b * i), $MachinePrecision]), $MachinePrecision] + N[(a * 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 := \mathsf{fma}\left(x, y, z \cdot t\right)\\
t_2 := \left(c \cdot \left(a + b \cdot c\right)\right) \cdot i\\
\mathbf{if}\;t_2 \leq -8.531786225585547 \cdot 10^{+299}:\\
\;\;\;\;2 \cdot \mathsf{fma}\left(1, t_1, -\left(c \cdot i\right) \cdot \mathsf{fma}\left(c, b, a\right)\right)\\

\mathbf{elif}\;t_2 \leq 6.208551683926593 \cdot 10^{+300}:\\
\;\;\;\;2 \cdot \mathsf{fma}\left(x, y, z \cdot t - i \cdot \left(c \cdot \mathsf{fma}\left(c, b, a\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;2 \cdot \left(t_1 - c \cdot \left(c \cdot \left(b \cdot i\right) + a \cdot i\right)\right)\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Bits error versus b

Bits error versus c

Bits error versus i

Target

Original6.4
Target1.8
Herbie1.1
\[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) < -8.53178622558554669e299

    1. Initial program 60.6

      \[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. Simplified60.6

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

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

      \[\leadsto 2 \cdot \left(\mathsf{fma}\left(x, y, z \cdot t\right) - \color{blue}{c \cdot \left(i \cdot \mathsf{fma}\left(c, b, a\right)\right)}\right) \]
    5. Applied egg-rr11.3

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

      \[\leadsto 2 \cdot \color{blue}{{\left(\sqrt[3]{\mathsf{fma}\left(x, y, z \cdot t\right) - \left(c \cdot i\right) \cdot \left(c \cdot b + a\right)}\right)}^{3}} \]
    7. Applied egg-rr11.3

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

    if -8.53178622558554669e299 < (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i) < 6.2085516839265934e300

    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) \]
    2. Simplified0.3

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

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

    if 6.2085516839265934e300 < (*.f64 (*.f64 (+.f64 a (*.f64 b c)) c) i)

    1. Initial program 59.1

      \[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. Simplified59.1

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

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

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

      \[\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) + a \cdot i\right)}\right) \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(c \cdot \left(a + b \cdot c\right)\right) \cdot i \leq -8.531786225585547 \cdot 10^{+299}:\\ \;\;\;\;2 \cdot \mathsf{fma}\left(1, \mathsf{fma}\left(x, y, z \cdot t\right), -\left(c \cdot i\right) \cdot \mathsf{fma}\left(c, b, a\right)\right)\\ \mathbf{elif}\;\left(c \cdot \left(a + b \cdot c\right)\right) \cdot i \leq 6.208551683926593 \cdot 10^{+300}:\\ \;\;\;\;2 \cdot \mathsf{fma}\left(x, y, z \cdot t - i \cdot \left(c \cdot \mathsf{fma}\left(c, b, a\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) + a \cdot i\right)\right)\\ \end{array} \]

Reproduce

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