Average Error: 6.5 → 1.6
Time: 6.5s
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 := c \cdot \left(a + b \cdot c\right)\\ \mathbf{if}\;t_1 \leq 5 \cdot 10^{-173}:\\ \;\;\;\;2 \cdot \mathsf{fma}\left(z, t, \mathsf{fma}\left(\mathsf{fma}\left(b, c, a\right), c \cdot \left(-i\right), x \cdot y\right)\right)\\ \mathbf{elif}\;t_1 \leq 10^{+204}:\\ \;\;\;\;2 \cdot \mathsf{fma}\left(z, t, x \cdot y - i \cdot \left(a \cdot c + b \cdot {c}^{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \mathsf{fma}\left(z, t, \mathsf{fma}\left(x, y, -\mathsf{fma}\left(c, a \cdot i, c \cdot \left(b \cdot \left(c \cdot i\right)\right)\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 (* c (+ a (* b c)))))
   (if (<= t_1 5e-173)
     (* 2.0 (fma z t (fma (fma b c a) (* c (- i)) (* x y))))
     (if (<= t_1 1e+204)
       (* 2.0 (fma z t (- (* x y) (* i (+ (* a c) (* b (pow c 2.0)))))))
       (* 2.0 (fma z t (fma x y (- (fma c (* a i) (* c (* b (* c 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 = c * (a + (b * c));
	double tmp;
	if (t_1 <= 5e-173) {
		tmp = 2.0 * fma(z, t, fma(fma(b, c, a), (c * -i), (x * y)));
	} else if (t_1 <= 1e+204) {
		tmp = 2.0 * fma(z, t, ((x * y) - (i * ((a * c) + (b * pow(c, 2.0))))));
	} else {
		tmp = 2.0 * fma(z, t, fma(x, y, -fma(c, (a * i), (c * (b * (c * 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(c * Float64(a + Float64(b * c)))
	tmp = 0.0
	if (t_1 <= 5e-173)
		tmp = Float64(2.0 * fma(z, t, fma(fma(b, c, a), Float64(c * Float64(-i)), Float64(x * y))));
	elseif (t_1 <= 1e+204)
		tmp = Float64(2.0 * fma(z, t, Float64(Float64(x * y) - Float64(i * Float64(Float64(a * c) + Float64(b * (c ^ 2.0)))))));
	else
		tmp = Float64(2.0 * fma(z, t, fma(x, y, Float64(-fma(c, Float64(a * i), Float64(c * Float64(b * Float64(c * 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[(c * N[(a + N[(b * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 5e-173], N[(2.0 * N[(z * t + N[(N[(b * c + a), $MachinePrecision] * N[(c * (-i)), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1e+204], N[(2.0 * N[(z * t + N[(N[(x * y), $MachinePrecision] - N[(i * N[(N[(a * c), $MachinePrecision] + N[(b * N[Power[c, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(z * t + N[(x * y + (-N[(c * N[(a * i), $MachinePrecision] + N[(c * N[(b * N[(c * i), $MachinePrecision]), $MachinePrecision]), $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 := c \cdot \left(a + b \cdot c\right)\\
\mathbf{if}\;t_1 \leq 5 \cdot 10^{-173}:\\
\;\;\;\;2 \cdot \mathsf{fma}\left(z, t, \mathsf{fma}\left(\mathsf{fma}\left(b, c, a\right), c \cdot \left(-i\right), x \cdot y\right)\right)\\

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

\mathbf{else}:\\
\;\;\;\;2 \cdot \mathsf{fma}\left(z, t, \mathsf{fma}\left(x, y, -\mathsf{fma}\left(c, a \cdot i, c \cdot \left(b \cdot \left(c \cdot i\right)\right)\right)\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.5
Target2.0
Herbie1.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 a (*.f64 b c)) c) < 5.0000000000000002e-173

    1. Initial program 5.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. Simplified1.7

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

    if 5.0000000000000002e-173 < (*.f64 (+.f64 a (*.f64 b c)) c) < 9.99999999999999989e203

    1. Initial program 0.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. Simplified1.6

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

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

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

    if 9.99999999999999989e203 < (*.f64 (+.f64 a (*.f64 b c)) c)

    1. Initial program 31.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) \]
    2. Simplified5.0

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

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

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

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

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

Reproduce

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