Average Error: 6.2 → 5.2
Time: 2.4m
Precision: 64
\[\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}\]
\[\begin{array}{l} \mathbf{if}\;z \le -4.131310447132096911666115196413486201723 \cdot 10^{109}:\\ \;\;\;\;\frac{1}{\left(\left(x \cdot y\right) \cdot z\right) \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(y \cdot \mathsf{fma}\left(z, z, 1\right)\right) \cdot x}\\ \end{array}\]
\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}
\begin{array}{l}
\mathbf{if}\;z \le -4.131310447132096911666115196413486201723 \cdot 10^{109}:\\
\;\;\;\;\frac{1}{\left(\left(x \cdot y\right) \cdot z\right) \cdot z}\\

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

\end{array}
double f(double x, double y, double z) {
        double r15661313 = 1.0;
        double r15661314 = x;
        double r15661315 = r15661313 / r15661314;
        double r15661316 = y;
        double r15661317 = z;
        double r15661318 = r15661317 * r15661317;
        double r15661319 = r15661313 + r15661318;
        double r15661320 = r15661316 * r15661319;
        double r15661321 = r15661315 / r15661320;
        return r15661321;
}

double f(double x, double y, double z) {
        double r15661322 = z;
        double r15661323 = -4.131310447132097e+109;
        bool r15661324 = r15661322 <= r15661323;
        double r15661325 = 1.0;
        double r15661326 = x;
        double r15661327 = y;
        double r15661328 = r15661326 * r15661327;
        double r15661329 = r15661328 * r15661322;
        double r15661330 = r15661329 * r15661322;
        double r15661331 = r15661325 / r15661330;
        double r15661332 = fma(r15661322, r15661322, r15661325);
        double r15661333 = r15661327 * r15661332;
        double r15661334 = r15661333 * r15661326;
        double r15661335 = r15661325 / r15661334;
        double r15661336 = r15661324 ? r15661331 : r15661335;
        return r15661336;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original6.2
Target5.4
Herbie5.2
\[\begin{array}{l} \mathbf{if}\;y \cdot \left(1 + z \cdot z\right) \lt -\infty:\\ \;\;\;\;\frac{\frac{1}{y}}{\left(1 + z \cdot z\right) \cdot x}\\ \mathbf{elif}\;y \cdot \left(1 + z \cdot z\right) \lt 8.680743250567251617010582226806563373013 \cdot 10^{305}:\\ \;\;\;\;\frac{\frac{1}{x}}{\left(1 + z \cdot z\right) \cdot y}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{y}}{\left(1 + z \cdot z\right) \cdot x}\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if z < -4.131310447132097e+109

    1. Initial program 14.5

      \[\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}\]
    2. Simplified14.5

      \[\leadsto \color{blue}{\frac{\frac{1}{\mathsf{fma}\left(z, z, 1\right) \cdot y}}{x}}\]
    3. Using strategy rm
    4. Applied div-inv14.5

      \[\leadsto \frac{\color{blue}{1 \cdot \frac{1}{\mathsf{fma}\left(z, z, 1\right) \cdot y}}}{x}\]
    5. Applied associate-/l*14.5

      \[\leadsto \color{blue}{\frac{1}{\frac{x}{\frac{1}{\mathsf{fma}\left(z, z, 1\right) \cdot y}}}}\]
    6. Simplified14.5

      \[\leadsto \frac{1}{\color{blue}{x \cdot \left(y \cdot \mathsf{fma}\left(z, z, 1\right)\right)}}\]
    7. Taylor expanded around inf 14.5

      \[\leadsto \color{blue}{\frac{1}{x \cdot \left({z}^{2} \cdot y\right)}}\]
    8. Simplified7.5

      \[\leadsto \color{blue}{\frac{1}{\left(\left(y \cdot x\right) \cdot z\right) \cdot z}}\]

    if -4.131310447132097e+109 < z

    1. Initial program 4.4

      \[\frac{\frac{1}{x}}{y \cdot \left(1 + z \cdot z\right)}\]
    2. Simplified4.4

      \[\leadsto \color{blue}{\frac{\frac{1}{\mathsf{fma}\left(z, z, 1\right) \cdot y}}{x}}\]
    3. Using strategy rm
    4. Applied div-inv4.4

      \[\leadsto \frac{\color{blue}{1 \cdot \frac{1}{\mathsf{fma}\left(z, z, 1\right) \cdot y}}}{x}\]
    5. Applied associate-/l*4.8

      \[\leadsto \color{blue}{\frac{1}{\frac{x}{\frac{1}{\mathsf{fma}\left(z, z, 1\right) \cdot y}}}}\]
    6. Simplified4.7

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -4.131310447132096911666115196413486201723 \cdot 10^{109}:\\ \;\;\;\;\frac{1}{\left(\left(x \cdot y\right) \cdot z\right) \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(y \cdot \mathsf{fma}\left(z, z, 1\right)\right) \cdot x}\\ \end{array}\]

Reproduce

herbie shell --seed 2019200 +o rules:numerics
(FPCore (x y z)
  :name "Statistics.Distribution.CauchyLorentz:$cdensity from math-functions-0.1.5.2"

  :herbie-target
  (if (< (* y (+ 1.0 (* z z))) -inf.0) (/ (/ 1.0 y) (* (+ 1.0 (* z z)) x)) (if (< (* y (+ 1.0 (* z z))) 8.680743250567252e+305) (/ (/ 1.0 x) (* (+ 1.0 (* z z)) y)) (/ (/ 1.0 y) (* (+ 1.0 (* z z)) x))))

  (/ (/ 1.0 x) (* y (+ 1.0 (* z z)))))