Average Error: 7.3 → 0.6
Time: 4.4s
Precision: 64
\[\frac{x \cdot y - z \cdot t}{a}\]
\[\begin{array}{l} \mathbf{if}\;x \cdot y - z \cdot t = -\infty \lor \neg \left(x \cdot y - z \cdot t \le 6.823892997990362310076105741944369198968 \cdot 10^{254}\right):\\ \;\;\;\;\frac{x}{\frac{a}{y}} - \frac{t}{\frac{a}{z}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x \cdot y, \frac{1}{a}, -\frac{t \cdot z}{a}\right)\\ \end{array}\]
\frac{x \cdot y - z \cdot t}{a}
\begin{array}{l}
\mathbf{if}\;x \cdot y - z \cdot t = -\infty \lor \neg \left(x \cdot y - z \cdot t \le 6.823892997990362310076105741944369198968 \cdot 10^{254}\right):\\
\;\;\;\;\frac{x}{\frac{a}{y}} - \frac{t}{\frac{a}{z}}\\

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

\end{array}
double f(double x, double y, double z, double t, double a) {
        double r1114391 = x;
        double r1114392 = y;
        double r1114393 = r1114391 * r1114392;
        double r1114394 = z;
        double r1114395 = t;
        double r1114396 = r1114394 * r1114395;
        double r1114397 = r1114393 - r1114396;
        double r1114398 = a;
        double r1114399 = r1114397 / r1114398;
        return r1114399;
}

double f(double x, double y, double z, double t, double a) {
        double r1114400 = x;
        double r1114401 = y;
        double r1114402 = r1114400 * r1114401;
        double r1114403 = z;
        double r1114404 = t;
        double r1114405 = r1114403 * r1114404;
        double r1114406 = r1114402 - r1114405;
        double r1114407 = -inf.0;
        bool r1114408 = r1114406 <= r1114407;
        double r1114409 = 6.823892997990362e+254;
        bool r1114410 = r1114406 <= r1114409;
        double r1114411 = !r1114410;
        bool r1114412 = r1114408 || r1114411;
        double r1114413 = a;
        double r1114414 = r1114413 / r1114401;
        double r1114415 = r1114400 / r1114414;
        double r1114416 = r1114413 / r1114403;
        double r1114417 = r1114404 / r1114416;
        double r1114418 = r1114415 - r1114417;
        double r1114419 = 1.0;
        double r1114420 = r1114419 / r1114413;
        double r1114421 = r1114404 * r1114403;
        double r1114422 = r1114421 / r1114413;
        double r1114423 = -r1114422;
        double r1114424 = fma(r1114402, r1114420, r1114423);
        double r1114425 = r1114412 ? r1114418 : r1114424;
        return r1114425;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original7.3
Target6.1
Herbie0.6
\[\begin{array}{l} \mathbf{if}\;z \lt -2.468684968699548224247694913169778644284 \cdot 10^{170}:\\ \;\;\;\;\frac{y}{a} \cdot x - \frac{t}{a} \cdot z\\ \mathbf{elif}\;z \lt 6.309831121978371209578784129518242708809 \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 2 regimes
  2. if (- (* x y) (* z t)) < -inf.0 or 6.823892997990362e+254 < (- (* x y) (* z t))

    1. Initial program 51.0

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

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

      \[\leadsto \frac{x \cdot y}{a} - \color{blue}{\frac{t \cdot z}{a}}\]
    5. Using strategy rm
    6. Applied associate-/l*26.5

      \[\leadsto \color{blue}{\frac{x}{\frac{a}{y}}} - \frac{t \cdot z}{a}\]
    7. Using strategy rm
    8. Applied associate-/l*0.3

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

    if -inf.0 < (- (* x y) (* z t)) < 6.823892997990362e+254

    1. Initial program 0.7

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

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

      \[\leadsto \frac{x \cdot y}{a} - \color{blue}{\frac{t \cdot z}{a}}\]
    5. Using strategy rm
    6. Applied div-inv0.7

      \[\leadsto \color{blue}{\left(x \cdot y\right) \cdot \frac{1}{a}} - \frac{t \cdot z}{a}\]
    7. Applied fma-neg0.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y - z \cdot t = -\infty \lor \neg \left(x \cdot y - z \cdot t \le 6.823892997990362310076105741944369198968 \cdot 10^{254}\right):\\ \;\;\;\;\frac{x}{\frac{a}{y}} - \frac{t}{\frac{a}{z}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x \cdot y, \frac{1}{a}, -\frac{t \cdot z}{a}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2019362 +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))