Average Error: 6.3 → 1.4
Time: 37.0s
Precision: 64
\[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} \mathbf{if}\;i \le -5.065469180562588569878166538565081134378 \cdot 10^{-39} \lor \neg \left(i \le 6.761551533703822259416640751121583901684 \cdot 10^{53}\right):\\ \;\;\;\;2 \cdot \mathsf{fma}\left(y, x, z \cdot t - \left(c \cdot \mathsf{fma}\left(c, b, a\right)\right) \cdot i\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \mathsf{fma}\left(y, x, z \cdot t - c \cdot \left(\mathsf{fma}\left(c, b, a\right) \cdot i\right)\right)\\ \end{array}\]
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}
\mathbf{if}\;i \le -5.065469180562588569878166538565081134378 \cdot 10^{-39} \lor \neg \left(i \le 6.761551533703822259416640751121583901684 \cdot 10^{53}\right):\\
\;\;\;\;2 \cdot \mathsf{fma}\left(y, x, z \cdot t - \left(c \cdot \mathsf{fma}\left(c, b, a\right)\right) \cdot i\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b, double c, double i) {
        double r410998 = 2.0;
        double r410999 = x;
        double r411000 = y;
        double r411001 = r410999 * r411000;
        double r411002 = z;
        double r411003 = t;
        double r411004 = r411002 * r411003;
        double r411005 = r411001 + r411004;
        double r411006 = a;
        double r411007 = b;
        double r411008 = c;
        double r411009 = r411007 * r411008;
        double r411010 = r411006 + r411009;
        double r411011 = r411010 * r411008;
        double r411012 = i;
        double r411013 = r411011 * r411012;
        double r411014 = r411005 - r411013;
        double r411015 = r410998 * r411014;
        return r411015;
}

double f(double x, double y, double z, double t, double a, double b, double c, double i) {
        double r411016 = i;
        double r411017 = -5.0654691805625886e-39;
        bool r411018 = r411016 <= r411017;
        double r411019 = 6.761551533703822e+53;
        bool r411020 = r411016 <= r411019;
        double r411021 = !r411020;
        bool r411022 = r411018 || r411021;
        double r411023 = 2.0;
        double r411024 = y;
        double r411025 = x;
        double r411026 = z;
        double r411027 = t;
        double r411028 = r411026 * r411027;
        double r411029 = c;
        double r411030 = b;
        double r411031 = a;
        double r411032 = fma(r411029, r411030, r411031);
        double r411033 = r411029 * r411032;
        double r411034 = r411033 * r411016;
        double r411035 = r411028 - r411034;
        double r411036 = fma(r411024, r411025, r411035);
        double r411037 = r411023 * r411036;
        double r411038 = r411032 * r411016;
        double r411039 = r411029 * r411038;
        double r411040 = r411028 - r411039;
        double r411041 = fma(r411024, r411025, r411040);
        double r411042 = r411023 * r411041;
        double r411043 = r411022 ? r411037 : r411042;
        return r411043;
}

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.3
Target1.7
Herbie1.4
\[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 2 regimes
  2. if i < -5.0654691805625886e-39 or 6.761551533703822e+53 < i

    1. Initial program 0.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. Simplified0.8

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

    if -5.0654691805625886e-39 < i < 6.761551533703822e+53

    1. Initial program 9.7

      \[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. Simplified9.7

      \[\leadsto \color{blue}{2 \cdot \mathsf{fma}\left(y, x, z \cdot t - \left(c \cdot \mathsf{fma}\left(c, b, a\right)\right) \cdot i\right)}\]
    3. Using strategy rm
    4. Applied associate-*l*1.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;i \le -5.065469180562588569878166538565081134378 \cdot 10^{-39} \lor \neg \left(i \le 6.761551533703822259416640751121583901684 \cdot 10^{53}\right):\\ \;\;\;\;2 \cdot \mathsf{fma}\left(y, x, z \cdot t - \left(c \cdot \mathsf{fma}\left(c, b, a\right)\right) \cdot i\right)\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \mathsf{fma}\left(y, x, z \cdot t - c \cdot \left(\mathsf{fma}\left(c, b, a\right) \cdot i\right)\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019326 +o rules:numerics
(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 (- (+ (* x y) (* z t)) (* (+ a (* b c)) (* c i))))

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