Average Error: 7.9 → 0.8
Time: 13.0s
Precision: 64
\[\frac{x \cdot y - z \cdot t}{a}\]
\[\begin{array}{l} \mathbf{if}\;x \cdot y - z \cdot t \le -3.195172105862473541761250419012489109784 \cdot 10^{185} \lor \neg \left(x \cdot y - z \cdot t \le 4.23388534661884408648975353744435589979 \cdot 10^{238}\right):\\ \;\;\;\;\frac{x}{\frac{a}{y}} - \frac{t}{\frac{a}{z}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y - z \cdot t}{a}\\ \end{array}\]
\frac{x \cdot y - z \cdot t}{a}
\begin{array}{l}
\mathbf{if}\;x \cdot y - z \cdot t \le -3.195172105862473541761250419012489109784 \cdot 10^{185} \lor \neg \left(x \cdot y - z \cdot t \le 4.23388534661884408648975353744435589979 \cdot 10^{238}\right):\\
\;\;\;\;\frac{x}{\frac{a}{y}} - \frac{t}{\frac{a}{z}}\\

\mathbf{else}:\\
\;\;\;\;\frac{x \cdot y - z \cdot t}{a}\\

\end{array}
double f(double x, double y, double z, double t, double a) {
        double r521688 = x;
        double r521689 = y;
        double r521690 = r521688 * r521689;
        double r521691 = z;
        double r521692 = t;
        double r521693 = r521691 * r521692;
        double r521694 = r521690 - r521693;
        double r521695 = a;
        double r521696 = r521694 / r521695;
        return r521696;
}

double f(double x, double y, double z, double t, double a) {
        double r521697 = x;
        double r521698 = y;
        double r521699 = r521697 * r521698;
        double r521700 = z;
        double r521701 = t;
        double r521702 = r521700 * r521701;
        double r521703 = r521699 - r521702;
        double r521704 = -3.1951721058624735e+185;
        bool r521705 = r521703 <= r521704;
        double r521706 = 4.233885346618844e+238;
        bool r521707 = r521703 <= r521706;
        double r521708 = !r521707;
        bool r521709 = r521705 || r521708;
        double r521710 = a;
        double r521711 = r521710 / r521698;
        double r521712 = r521697 / r521711;
        double r521713 = r521710 / r521700;
        double r521714 = r521701 / r521713;
        double r521715 = r521712 - r521714;
        double r521716 = r521703 / r521710;
        double r521717 = r521709 ? r521715 : r521716;
        return r521717;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original7.9
Target5.8
Herbie0.8
\[\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)) < -3.1951721058624735e+185 or 4.233885346618844e+238 < (- (* x y) (* z t))

    1. Initial program 30.6

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

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

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

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

    if -3.1951721058624735e+185 < (- (* x y) (* z t)) < 4.233885346618844e+238

    1. Initial program 0.7

      \[\frac{x \cdot y - z \cdot t}{a}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot y - z \cdot t \le -3.195172105862473541761250419012489109784 \cdot 10^{185} \lor \neg \left(x \cdot y - z \cdot t \le 4.23388534661884408648975353744435589979 \cdot 10^{238}\right):\\ \;\;\;\;\frac{x}{\frac{a}{y}} - \frac{t}{\frac{a}{z}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y - z \cdot t}{a}\\ \end{array}\]

Reproduce

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

  :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))