Average Error: 7.9 → 0.4
Time: 3.8s
Precision: 64
\[\frac{\cosh x \cdot \frac{y}{x}}{z}\]
\[\begin{array}{l} \mathbf{if}\;z \le -1948241059787096980000 \lor \neg \left(z \le 7.2256649558957228 \cdot 10^{-45}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{2}, e^{-1 \cdot x}, \frac{1}{2} \cdot e^{x}\right) \cdot \frac{y}{x \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(e^{x} + e^{-x}\right) \cdot \frac{y}{z}}{2 \cdot x}\\ \end{array}\]
\frac{\cosh x \cdot \frac{y}{x}}{z}
\begin{array}{l}
\mathbf{if}\;z \le -1948241059787096980000 \lor \neg \left(z \le 7.2256649558957228 \cdot 10^{-45}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{2}, e^{-1 \cdot x}, \frac{1}{2} \cdot e^{x}\right) \cdot \frac{y}{x \cdot z}\\

\mathbf{else}:\\
\;\;\;\;\frac{\left(e^{x} + e^{-x}\right) \cdot \frac{y}{z}}{2 \cdot x}\\

\end{array}
double f(double x, double y, double z) {
        double r546752 = x;
        double r546753 = cosh(r546752);
        double r546754 = y;
        double r546755 = r546754 / r546752;
        double r546756 = r546753 * r546755;
        double r546757 = z;
        double r546758 = r546756 / r546757;
        return r546758;
}

double f(double x, double y, double z) {
        double r546759 = z;
        double r546760 = -1.948241059787097e+21;
        bool r546761 = r546759 <= r546760;
        double r546762 = 7.225664955895723e-45;
        bool r546763 = r546759 <= r546762;
        double r546764 = !r546763;
        bool r546765 = r546761 || r546764;
        double r546766 = 0.5;
        double r546767 = -1.0;
        double r546768 = x;
        double r546769 = r546767 * r546768;
        double r546770 = exp(r546769);
        double r546771 = exp(r546768);
        double r546772 = r546766 * r546771;
        double r546773 = fma(r546766, r546770, r546772);
        double r546774 = y;
        double r546775 = r546768 * r546759;
        double r546776 = r546774 / r546775;
        double r546777 = r546773 * r546776;
        double r546778 = -r546768;
        double r546779 = exp(r546778);
        double r546780 = r546771 + r546779;
        double r546781 = r546774 / r546759;
        double r546782 = r546780 * r546781;
        double r546783 = 2.0;
        double r546784 = r546783 * r546768;
        double r546785 = r546782 / r546784;
        double r546786 = r546765 ? r546777 : r546785;
        return r546786;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original7.9
Target0.4
Herbie0.4
\[\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.948241059787097e+21 or 7.225664955895723e-45 < z

    1. Initial program 11.8

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{\left(e^{x} + e^{-x}\right) \cdot y}{z}}}{2 \cdot x}\]
    9. Using strategy rm
    10. Applied *-un-lft-identity10.0

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

      \[\leadsto \frac{\color{blue}{\frac{e^{x} + e^{-x}}{1} \cdot \frac{y}{z}}}{2 \cdot x}\]
    12. Applied times-frac10.0

      \[\leadsto \color{blue}{\frac{\frac{e^{x} + e^{-x}}{1}}{2} \cdot \frac{\frac{y}{z}}{x}}\]
    13. Simplified10.0

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{2}, e^{-1 \cdot x}, \frac{1}{2} \cdot e^{x}\right)} \cdot \frac{\frac{y}{z}}{x}\]
    14. Simplified0.4

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

    if -1.948241059787097e+21 < z < 7.225664955895723e-45

    1. Initial program 0.4

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{\left(e^{x} + e^{-x}\right) \cdot y}{z}}}{2 \cdot x}\]
    9. Using strategy rm
    10. Applied *-un-lft-identity0.3

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

      \[\leadsto \frac{\color{blue}{\frac{e^{x} + e^{-x}}{1} \cdot \frac{y}{z}}}{2 \cdot x}\]
    12. Simplified0.3

      \[\leadsto \frac{\color{blue}{\left(e^{x} + e^{-x}\right)} \cdot \frac{y}{z}}{2 \cdot x}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \le -1948241059787096980000 \lor \neg \left(z \le 7.2256649558957228 \cdot 10^{-45}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{2}, e^{-1 \cdot x}, \frac{1}{2} \cdot e^{x}\right) \cdot \frac{y}{x \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(e^{x} + e^{-x}\right) \cdot \frac{y}{z}}{2 \cdot x}\\ \end{array}\]

Reproduce

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