Average Error: 7.9 → 0.9
Time: 8.9s
Precision: 64
\[\frac{x \cdot y - z \cdot t}{a}\]
\[\begin{array}{l} \mathbf{if}\;x \cdot y - z \cdot t \le -1.84983714649141212 \cdot 10^{228}:\\ \;\;\;\;x \cdot \frac{y}{a} - z \cdot \frac{t}{a}\\ \mathbf{elif}\;x \cdot y - z \cdot t \le -3.89245830945422355 \cdot 10^{-123} \lor \neg \left(x \cdot y - z \cdot t \le 8.05837194167480624 \cdot 10^{-141}\right) \land x \cdot y - z \cdot t \le 1.06699263789496906 \cdot 10^{186}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, y, -t \cdot z\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{a}, \frac{-t}{\frac{a}{z}}\right)\\ \end{array}\]
\frac{x \cdot y - z \cdot t}{a}
\begin{array}{l}
\mathbf{if}\;x \cdot y - z \cdot t \le -1.84983714649141212 \cdot 10^{228}:\\
\;\;\;\;x \cdot \frac{y}{a} - z \cdot \frac{t}{a}\\

\mathbf{elif}\;x \cdot y - z \cdot t \le -3.89245830945422355 \cdot 10^{-123} \lor \neg \left(x \cdot y - z \cdot t \le 8.05837194167480624 \cdot 10^{-141}\right) \land x \cdot y - z \cdot t \le 1.06699263789496906 \cdot 10^{186}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x, y, -t \cdot z\right)}{a}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, \frac{y}{a}, \frac{-t}{\frac{a}{z}}\right)\\

\end{array}
double f(double x, double y, double z, double t, double a) {
        double r806122 = x;
        double r806123 = y;
        double r806124 = r806122 * r806123;
        double r806125 = z;
        double r806126 = t;
        double r806127 = r806125 * r806126;
        double r806128 = r806124 - r806127;
        double r806129 = a;
        double r806130 = r806128 / r806129;
        return r806130;
}

double f(double x, double y, double z, double t, double a) {
        double r806131 = x;
        double r806132 = y;
        double r806133 = r806131 * r806132;
        double r806134 = z;
        double r806135 = t;
        double r806136 = r806134 * r806135;
        double r806137 = r806133 - r806136;
        double r806138 = -1.849837146491412e+228;
        bool r806139 = r806137 <= r806138;
        double r806140 = a;
        double r806141 = r806132 / r806140;
        double r806142 = r806131 * r806141;
        double r806143 = r806135 / r806140;
        double r806144 = r806134 * r806143;
        double r806145 = r806142 - r806144;
        double r806146 = -3.8924583094542236e-123;
        bool r806147 = r806137 <= r806146;
        double r806148 = 8.058371941674806e-141;
        bool r806149 = r806137 <= r806148;
        double r806150 = !r806149;
        double r806151 = 1.066992637894969e+186;
        bool r806152 = r806137 <= r806151;
        bool r806153 = r806150 && r806152;
        bool r806154 = r806147 || r806153;
        double r806155 = r806135 * r806134;
        double r806156 = -r806155;
        double r806157 = fma(r806131, r806132, r806156);
        double r806158 = r806157 / r806140;
        double r806159 = -r806135;
        double r806160 = r806140 / r806134;
        double r806161 = r806159 / r806160;
        double r806162 = fma(r806131, r806141, r806161);
        double r806163 = r806154 ? r806158 : r806162;
        double r806164 = r806139 ? r806145 : r806163;
        return r806164;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original7.9
Target6.0
Herbie0.9
\[\begin{array}{l} \mathbf{if}\;z \lt -2.46868496869954822 \cdot 10^{170}:\\ \;\;\;\;\frac{y}{a} \cdot x - \frac{t}{a} \cdot z\\ \mathbf{elif}\;z \lt 6.30983112197837121 \cdot 10^{-71}:\\ \;\;\;\;\frac{x \cdot y - z \cdot t}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{a} \cdot x - \frac{t}{a} \cdot z\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if (- (* x y) (* z t)) < -1.849837146491412e+228

    1. Initial program 34.5

      \[\frac{x \cdot y - z \cdot t}{a}\]
    2. Using strategy rm
    3. Applied div-sub34.5

      \[\leadsto \color{blue}{\frac{x \cdot y}{a} - \frac{z \cdot t}{a}}\]
    4. Simplified19.9

      \[\leadsto \color{blue}{x \cdot \frac{y}{a}} - \frac{z \cdot t}{a}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity19.9

      \[\leadsto x \cdot \frac{y}{a} - \frac{z \cdot t}{\color{blue}{1 \cdot a}}\]
    7. Applied times-frac0.8

      \[\leadsto x \cdot \frac{y}{a} - \color{blue}{\frac{z}{1} \cdot \frac{t}{a}}\]
    8. Simplified0.8

      \[\leadsto x \cdot \frac{y}{a} - \color{blue}{z} \cdot \frac{t}{a}\]

    if -1.849837146491412e+228 < (- (* x y) (* z t)) < -3.8924583094542236e-123 or 8.058371941674806e-141 < (- (* x y) (* z t)) < 1.066992637894969e+186

    1. Initial program 0.3

      \[\frac{x \cdot y - z \cdot t}{a}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity0.3

      \[\leadsto \frac{x \cdot y - z \cdot t}{\color{blue}{1 \cdot a}}\]
    4. Applied associate-/r*0.3

      \[\leadsto \color{blue}{\frac{\frac{x \cdot y - z \cdot t}{1}}{a}}\]
    5. Simplified0.3

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

    if -3.8924583094542236e-123 < (- (* x y) (* z t)) < 8.058371941674806e-141 or 1.066992637894969e+186 < (- (* x y) (* z t))

    1. Initial program 15.5

      \[\frac{x \cdot y - z \cdot t}{a}\]
    2. Using strategy rm
    3. Applied div-sub15.5

      \[\leadsto \color{blue}{\frac{x \cdot y}{a} - \frac{z \cdot t}{a}}\]
    4. Simplified9.4

      \[\leadsto \color{blue}{x \cdot \frac{y}{a}} - \frac{z \cdot t}{a}\]
    5. Using strategy rm
    6. Applied fma-neg9.4

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, \frac{y}{a}, -\frac{z \cdot t}{a}\right)}\]
    7. Simplified2.6

      \[\leadsto \mathsf{fma}\left(x, \frac{y}{a}, \color{blue}{\frac{-t}{\frac{a}{z}}}\right)\]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y - z \cdot t \le -1.84983714649141212 \cdot 10^{228}:\\ \;\;\;\;x \cdot \frac{y}{a} - z \cdot \frac{t}{a}\\ \mathbf{elif}\;x \cdot y - z \cdot t \le -3.89245830945422355 \cdot 10^{-123} \lor \neg \left(x \cdot y - z \cdot t \le 8.05837194167480624 \cdot 10^{-141}\right) \land x \cdot y - z \cdot t \le 1.06699263789496906 \cdot 10^{186}:\\ \;\;\;\;\frac{\mathsf{fma}\left(x, y, -t \cdot z\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, \frac{y}{a}, \frac{-t}{\frac{a}{z}}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020047 +o rules:numerics
(FPCore (x y z t a)
  :name "Data.Colour.Matrix:inverse from colour-2.3.3, B"
  :precision binary64

  :herbie-target
  (if (< z -2.468684968699548e+170) (- (* (/ y a) x) (* (/ t a) z)) (if (< z 6.309831121978371e-71) (/ (- (* x y) (* z t)) a) (- (* (/ y a) x) (* (/ t a) z))))

  (/ (- (* x y) (* z t)) a))