Average Error: 7.5 → 0.7
Time: 3.8s
Precision: 64
\[\frac{\cosh x \cdot \frac{y}{x}}{z}\]
\[\begin{array}{l} \mathbf{if}\;z \le -1.4097270866768739 \cdot 10^{-11} \lor \neg \left(z \le 2.4378260307965419 \cdot 10^{-107}\right):\\ \;\;\;\;\frac{\mathsf{fma}\left(e^{x}, y, \frac{y}{e^{x}}\right)}{\left(2 \cdot x\right) \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\cosh x \cdot y}{x}}{z}\\ \end{array}\]
\frac{\cosh x \cdot \frac{y}{x}}{z}
\begin{array}{l}
\mathbf{if}\;z \le -1.4097270866768739 \cdot 10^{-11} \lor \neg \left(z \le 2.4378260307965419 \cdot 10^{-107}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(e^{x}, y, \frac{y}{e^{x}}\right)}{\left(2 \cdot x\right) \cdot z}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{\cosh x \cdot y}{x}}{z}\\

\end{array}
double f(double x, double y, double z) {
        double r481970 = x;
        double r481971 = cosh(r481970);
        double r481972 = y;
        double r481973 = r481972 / r481970;
        double r481974 = r481971 * r481973;
        double r481975 = z;
        double r481976 = r481974 / r481975;
        return r481976;
}

double f(double x, double y, double z) {
        double r481977 = z;
        double r481978 = -1.409727086676874e-11;
        bool r481979 = r481977 <= r481978;
        double r481980 = 2.437826030796542e-107;
        bool r481981 = r481977 <= r481980;
        double r481982 = !r481981;
        bool r481983 = r481979 || r481982;
        double r481984 = x;
        double r481985 = exp(r481984);
        double r481986 = y;
        double r481987 = r481986 / r481985;
        double r481988 = fma(r481985, r481986, r481987);
        double r481989 = 2.0;
        double r481990 = r481989 * r481984;
        double r481991 = r481990 * r481977;
        double r481992 = r481988 / r481991;
        double r481993 = cosh(r481984);
        double r481994 = r481993 * r481986;
        double r481995 = r481994 / r481984;
        double r481996 = r481995 / r481977;
        double r481997 = r481983 ? r481992 : r481996;
        return r481997;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original7.5
Target0.4
Herbie0.7
\[\begin{array}{l} \mathbf{if}\;y \lt -4.618902267687042 \cdot 10^{-52}:\\ \;\;\;\;\frac{\frac{y}{z}}{x} \cdot \cosh x\\ \mathbf{elif}\;y \lt 1.0385305359351529 \cdot 10^{-39}:\\ \;\;\;\;\frac{\frac{\cosh x \cdot y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{z}}{x} \cdot \cosh x\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if z < -1.409727086676874e-11 or 2.437826030796542e-107 < z

    1. Initial program 10.1

      \[\frac{\cosh x \cdot \frac{y}{x}}{z}\]
    2. Using strategy rm
    3. Applied div-inv10.2

      \[\leadsto \color{blue}{\left(\cosh x \cdot \frac{y}{x}\right) \cdot \frac{1}{z}}\]
    4. Using strategy rm
    5. Applied div-inv10.2

      \[\leadsto \left(\cosh x \cdot \color{blue}{\left(y \cdot \frac{1}{x}\right)}\right) \cdot \frac{1}{z}\]
    6. Applied associate-*r*10.2

      \[\leadsto \color{blue}{\left(\left(\cosh x \cdot y\right) \cdot \frac{1}{x}\right)} \cdot \frac{1}{z}\]
    7. Using strategy rm
    8. Applied cosh-def10.2

      \[\leadsto \left(\left(\color{blue}{\frac{e^{x} + e^{-x}}{2}} \cdot y\right) \cdot \frac{1}{x}\right) \cdot \frac{1}{z}\]
    9. Applied associate-*l/10.2

      \[\leadsto \left(\color{blue}{\frac{\left(e^{x} + e^{-x}\right) \cdot y}{2}} \cdot \frac{1}{x}\right) \cdot \frac{1}{z}\]
    10. Applied frac-times10.2

      \[\leadsto \color{blue}{\frac{\left(\left(e^{x} + e^{-x}\right) \cdot y\right) \cdot 1}{2 \cdot x}} \cdot \frac{1}{z}\]
    11. Applied frac-times0.9

      \[\leadsto \color{blue}{\frac{\left(\left(\left(e^{x} + e^{-x}\right) \cdot y\right) \cdot 1\right) \cdot 1}{\left(2 \cdot x\right) \cdot z}}\]
    12. Simplified0.9

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(e^{x}, y, \frac{y}{e^{x}}\right)}}{\left(2 \cdot x\right) \cdot z}\]

    if -1.409727086676874e-11 < z < 2.437826030796542e-107

    1. Initial program 0.3

      \[\frac{\cosh x \cdot \frac{y}{x}}{z}\]
    2. Using strategy rm
    3. Applied div-inv0.4

      \[\leadsto \color{blue}{\left(\cosh x \cdot \frac{y}{x}\right) \cdot \frac{1}{z}}\]
    4. Using strategy rm
    5. Applied div-inv0.5

      \[\leadsto \left(\cosh x \cdot \color{blue}{\left(y \cdot \frac{1}{x}\right)}\right) \cdot \frac{1}{z}\]
    6. Applied associate-*r*0.5

      \[\leadsto \color{blue}{\left(\left(\cosh x \cdot y\right) \cdot \frac{1}{x}\right)} \cdot \frac{1}{z}\]
    7. Using strategy rm
    8. Applied associate-*r/0.4

      \[\leadsto \color{blue}{\frac{\left(\left(\cosh x \cdot y\right) \cdot \frac{1}{x}\right) \cdot 1}{z}}\]
    9. Simplified0.3

      \[\leadsto \frac{\color{blue}{\frac{\cosh x \cdot y}{x}}}{z}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -1.4097270866768739 \cdot 10^{-11} \lor \neg \left(z \le 2.4378260307965419 \cdot 10^{-107}\right):\\ \;\;\;\;\frac{\mathsf{fma}\left(e^{x}, y, \frac{y}{e^{x}}\right)}{\left(2 \cdot x\right) \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\cosh x \cdot y}{x}}{z}\\ \end{array}\]

Reproduce

herbie shell --seed 2020018 +o rules:numerics
(FPCore (x y z)
  :name "Linear.Quaternion:$ctan from linear-1.19.1.3"
  :precision binary64

  :herbie-target
  (if (< y -4.618902267687042e-52) (* (/ (/ y z) x) (cosh x)) (if (< y 1.0385305359351529e-39) (/ (/ (* (cosh x) y) x) z) (* (/ (/ y z) x) (cosh x))))

  (/ (* (cosh x) (/ y x)) z))