Average Error: 6.4 → 1.4
Time: 1.6m
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}\;c \le -3.780226141482327129579157526221877803227 \cdot 10^{-17}:\\ \;\;\;\;\left(\mathsf{fma}\left(t, z, x \cdot y\right) - \left(i \cdot \mathsf{fma}\left(c, b, a\right)\right) \cdot c\right) \cdot 2\\ \mathbf{elif}\;c \le 2.405310837335638562254649692762064198741 \cdot 10^{-63}:\\ \;\;\;\;2 \cdot \left(\mathsf{fma}\left(y, x, z \cdot t\right) - \left(c \cdot \mathsf{fma}\left(c, b, a\right)\right) \cdot i\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\mathsf{fma}\left(t, z, x \cdot y\right) - \left(i \cdot \mathsf{fma}\left(c, b, a\right)\right) \cdot c\right) \cdot 2\\ \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}\;c \le -3.780226141482327129579157526221877803227 \cdot 10^{-17}:\\
\;\;\;\;\left(\mathsf{fma}\left(t, z, x \cdot y\right) - \left(i \cdot \mathsf{fma}\left(c, b, a\right)\right) \cdot c\right) \cdot 2\\

\mathbf{elif}\;c \le 2.405310837335638562254649692762064198741 \cdot 10^{-63}:\\
\;\;\;\;2 \cdot \left(\mathsf{fma}\left(y, x, z \cdot t\right) - \left(c \cdot \mathsf{fma}\left(c, b, a\right)\right) \cdot i\right)\\

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

\end{array}
double f(double x, double y, double z, double t, double a, double b, double c, double i) {
        double r34505471 = 2.0;
        double r34505472 = x;
        double r34505473 = y;
        double r34505474 = r34505472 * r34505473;
        double r34505475 = z;
        double r34505476 = t;
        double r34505477 = r34505475 * r34505476;
        double r34505478 = r34505474 + r34505477;
        double r34505479 = a;
        double r34505480 = b;
        double r34505481 = c;
        double r34505482 = r34505480 * r34505481;
        double r34505483 = r34505479 + r34505482;
        double r34505484 = r34505483 * r34505481;
        double r34505485 = i;
        double r34505486 = r34505484 * r34505485;
        double r34505487 = r34505478 - r34505486;
        double r34505488 = r34505471 * r34505487;
        return r34505488;
}

double f(double x, double y, double z, double t, double a, double b, double c, double i) {
        double r34505489 = c;
        double r34505490 = -3.780226141482327e-17;
        bool r34505491 = r34505489 <= r34505490;
        double r34505492 = t;
        double r34505493 = z;
        double r34505494 = x;
        double r34505495 = y;
        double r34505496 = r34505494 * r34505495;
        double r34505497 = fma(r34505492, r34505493, r34505496);
        double r34505498 = i;
        double r34505499 = b;
        double r34505500 = a;
        double r34505501 = fma(r34505489, r34505499, r34505500);
        double r34505502 = r34505498 * r34505501;
        double r34505503 = r34505502 * r34505489;
        double r34505504 = r34505497 - r34505503;
        double r34505505 = 2.0;
        double r34505506 = r34505504 * r34505505;
        double r34505507 = 2.4053108373356386e-63;
        bool r34505508 = r34505489 <= r34505507;
        double r34505509 = r34505493 * r34505492;
        double r34505510 = fma(r34505495, r34505494, r34505509);
        double r34505511 = r34505489 * r34505501;
        double r34505512 = r34505511 * r34505498;
        double r34505513 = r34505510 - r34505512;
        double r34505514 = r34505505 * r34505513;
        double r34505515 = r34505508 ? r34505514 : r34505506;
        double r34505516 = r34505491 ? r34505506 : r34505515;
        return r34505516;
}

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.6
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 c < -3.780226141482327e-17 or 2.4053108373356386e-63 < c

    1. Initial program 15.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. Simplified15.8

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

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

    if -3.780226141482327e-17 < c < 2.4053108373356386e-63

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

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

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

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

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

Reproduce

herbie shell --seed 2019200 +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"

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

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