Average Error: 7.6 → 0.8
Time: 5.2s
Precision: 64
\[\frac{\cosh x \cdot \frac{y}{x}}{z}\]
\[\begin{array}{l} \mathbf{if}\;y \le -6.47943049490942291 \cdot 10^{-17} \lor \neg \left(y \le 1.00920937048972751 \cdot 10^{-5}\right):\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{2}, \frac{x \cdot y}{z}, \frac{y}{x \cdot z}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(\frac{1}{2}, e^{-1 \cdot x}, \frac{1}{2} \cdot e^{x}\right)}{\frac{x}{y}}}{z}\\ \end{array}\]
\frac{\cosh x \cdot \frac{y}{x}}{z}
\begin{array}{l}
\mathbf{if}\;y \le -6.47943049490942291 \cdot 10^{-17} \lor \neg \left(y \le 1.00920937048972751 \cdot 10^{-5}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{2}, \frac{x \cdot y}{z}, \frac{y}{x \cdot z}\right)\\

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

\end{array}
double f(double x, double y, double z) {
        double r533945 = x;
        double r533946 = cosh(r533945);
        double r533947 = y;
        double r533948 = r533947 / r533945;
        double r533949 = r533946 * r533948;
        double r533950 = z;
        double r533951 = r533949 / r533950;
        return r533951;
}

double f(double x, double y, double z) {
        double r533952 = y;
        double r533953 = -6.479430494909423e-17;
        bool r533954 = r533952 <= r533953;
        double r533955 = 1.0092093704897275e-05;
        bool r533956 = r533952 <= r533955;
        double r533957 = !r533956;
        bool r533958 = r533954 || r533957;
        double r533959 = 0.5;
        double r533960 = x;
        double r533961 = r533960 * r533952;
        double r533962 = z;
        double r533963 = r533961 / r533962;
        double r533964 = r533960 * r533962;
        double r533965 = r533952 / r533964;
        double r533966 = fma(r533959, r533963, r533965);
        double r533967 = -1.0;
        double r533968 = r533967 * r533960;
        double r533969 = exp(r533968);
        double r533970 = exp(r533960);
        double r533971 = r533959 * r533970;
        double r533972 = fma(r533959, r533969, r533971);
        double r533973 = r533960 / r533952;
        double r533974 = r533972 / r533973;
        double r533975 = r533974 / r533962;
        double r533976 = r533958 ? r533966 : r533975;
        return r533976;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original7.6
Target0.5
Herbie0.8
\[\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 y < -6.479430494909423e-17 or 1.0092093704897275e-05 < y

    1. Initial program 20.0

      \[\frac{\cosh x \cdot \frac{y}{x}}{z}\]
    2. Taylor expanded around 0 1.5

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{x \cdot y}{z} + \frac{y}{x \cdot z}}\]
    3. Simplified1.5

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

    if -6.479430494909423e-17 < y < 1.0092093704897275e-05

    1. Initial program 0.3

      \[\frac{\cosh x \cdot \frac{y}{x}}{z}\]
    2. Taylor expanded around inf 0.3

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

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

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

Reproduce

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