Average Error: 24.8 → 7.3
Time: 21.1s
Precision: 64
\[\frac{\left(x \cdot y\right) \cdot z}{\sqrt{z \cdot z - t \cdot a}}\]
\[\begin{array}{l} \mathbf{if}\;z \le -2.106976415350951692258705282827720142037 \cdot 10^{65}:\\ \;\;\;\;\frac{x \cdot y}{\mathsf{fma}\left(\frac{t}{\frac{z \cdot z}{a}}, \frac{1}{2}, -1\right)}\\ \mathbf{elif}\;z \le 0.007263648305243833834532463100686072721146:\\ \;\;\;\;\frac{x \cdot y}{\frac{\sqrt{z \cdot z - t \cdot a}}{z}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y}{\frac{\mathsf{fma}\left(t \cdot \frac{a}{z}, \frac{-1}{2}, z\right)}{z}}\\ \end{array}\]
\frac{\left(x \cdot y\right) \cdot z}{\sqrt{z \cdot z - t \cdot a}}
\begin{array}{l}
\mathbf{if}\;z \le -2.106976415350951692258705282827720142037 \cdot 10^{65}:\\
\;\;\;\;\frac{x \cdot y}{\mathsf{fma}\left(\frac{t}{\frac{z \cdot z}{a}}, \frac{1}{2}, -1\right)}\\

\mathbf{elif}\;z \le 0.007263648305243833834532463100686072721146:\\
\;\;\;\;\frac{x \cdot y}{\frac{\sqrt{z \cdot z - t \cdot a}}{z}}\\

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

\end{array}
double f(double x, double y, double z, double t, double a) {
        double r12370646 = x;
        double r12370647 = y;
        double r12370648 = r12370646 * r12370647;
        double r12370649 = z;
        double r12370650 = r12370648 * r12370649;
        double r12370651 = r12370649 * r12370649;
        double r12370652 = t;
        double r12370653 = a;
        double r12370654 = r12370652 * r12370653;
        double r12370655 = r12370651 - r12370654;
        double r12370656 = sqrt(r12370655);
        double r12370657 = r12370650 / r12370656;
        return r12370657;
}

double f(double x, double y, double z, double t, double a) {
        double r12370658 = z;
        double r12370659 = -2.1069764153509517e+65;
        bool r12370660 = r12370658 <= r12370659;
        double r12370661 = x;
        double r12370662 = y;
        double r12370663 = r12370661 * r12370662;
        double r12370664 = t;
        double r12370665 = r12370658 * r12370658;
        double r12370666 = a;
        double r12370667 = r12370665 / r12370666;
        double r12370668 = r12370664 / r12370667;
        double r12370669 = 0.5;
        double r12370670 = -1.0;
        double r12370671 = fma(r12370668, r12370669, r12370670);
        double r12370672 = r12370663 / r12370671;
        double r12370673 = 0.007263648305243834;
        bool r12370674 = r12370658 <= r12370673;
        double r12370675 = r12370664 * r12370666;
        double r12370676 = r12370665 - r12370675;
        double r12370677 = sqrt(r12370676);
        double r12370678 = r12370677 / r12370658;
        double r12370679 = r12370663 / r12370678;
        double r12370680 = r12370666 / r12370658;
        double r12370681 = r12370664 * r12370680;
        double r12370682 = -0.5;
        double r12370683 = fma(r12370681, r12370682, r12370658);
        double r12370684 = r12370683 / r12370658;
        double r12370685 = r12370663 / r12370684;
        double r12370686 = r12370674 ? r12370679 : r12370685;
        double r12370687 = r12370660 ? r12370672 : r12370686;
        return r12370687;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Bits error versus a

Target

Original24.8
Target7.5
Herbie7.3
\[\begin{array}{l} \mathbf{if}\;z \lt -3.192130590385276419686361646843883646209 \cdot 10^{46}:\\ \;\;\;\;-y \cdot x\\ \mathbf{elif}\;z \lt 5.976268120920894210257945708950453212935 \cdot 10^{90}:\\ \;\;\;\;\frac{x \cdot z}{\frac{\sqrt{z \cdot z - a \cdot t}}{y}}\\ \mathbf{else}:\\ \;\;\;\;y \cdot x\\ \end{array}\]

Derivation

  1. Split input into 3 regimes
  2. if z < -2.1069764153509517e+65

    1. Initial program 39.3

      \[\frac{\left(x \cdot y\right) \cdot z}{\sqrt{z \cdot z - t \cdot a}}\]
    2. Using strategy rm
    3. Applied associate-/l*36.3

      \[\leadsto \color{blue}{\frac{x \cdot y}{\frac{\sqrt{z \cdot z - t \cdot a}}{z}}}\]
    4. Taylor expanded around -inf 6.8

      \[\leadsto \frac{x \cdot y}{\color{blue}{\frac{1}{2} \cdot \frac{a \cdot t}{{z}^{2}} - 1}}\]
    5. Simplified3.0

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

    if -2.1069764153509517e+65 < z < 0.007263648305243834

    1. Initial program 11.6

      \[\frac{\left(x \cdot y\right) \cdot z}{\sqrt{z \cdot z - t \cdot a}}\]
    2. Using strategy rm
    3. Applied associate-/l*11.7

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

    if 0.007263648305243834 < z

    1. Initial program 32.4

      \[\frac{\left(x \cdot y\right) \cdot z}{\sqrt{z \cdot z - t \cdot a}}\]
    2. Using strategy rm
    3. Applied associate-/l*30.1

      \[\leadsto \color{blue}{\frac{x \cdot y}{\frac{\sqrt{z \cdot z - t \cdot a}}{z}}}\]
    4. Taylor expanded around inf 6.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -2.106976415350951692258705282827720142037 \cdot 10^{65}:\\ \;\;\;\;\frac{x \cdot y}{\mathsf{fma}\left(\frac{t}{\frac{z \cdot z}{a}}, \frac{1}{2}, -1\right)}\\ \mathbf{elif}\;z \le 0.007263648305243833834532463100686072721146:\\ \;\;\;\;\frac{x \cdot y}{\frac{\sqrt{z \cdot z - t \cdot a}}{z}}\\ \mathbf{else}:\\ \;\;\;\;\frac{x \cdot y}{\frac{\mathsf{fma}\left(t \cdot \frac{a}{z}, \frac{-1}{2}, z\right)}{z}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019192 +o rules:numerics
(FPCore (x y z t a)
  :name "Statistics.Math.RootFinding:ridders from math-functions-0.1.5.2"

  :herbie-target
  (if (< z -3.1921305903852764e+46) (- (* y x)) (if (< z 5.976268120920894e+90) (/ (* x z) (/ (sqrt (- (* z z) (* a t))) y)) (* y x)))

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