Average Error: 7.6 → 0.7
Time: 6.4s
Precision: binary64
\[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
\[\begin{array}{l} \mathbf{if}\;z \leq -404248964266.4667:\\ \;\;\;\;\frac{y \cdot \mathsf{fma}\left(0.5, e^{x}, \frac{0.5}{e^{x}}\right)}{z \cdot x}\\ \mathbf{elif}\;z \leq 4.13020256225072 \cdot 10^{+92}:\\ \;\;\;\;\frac{\cosh x \cdot \frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5 \cdot \mathsf{fma}\left(e^{x}, y, \frac{y}{e^{x}}\right)}{z \cdot x}\\ \end{array} \]
\frac{\cosh x \cdot \frac{y}{x}}{z}
\begin{array}{l}
\mathbf{if}\;z \leq -404248964266.4667:\\
\;\;\;\;\frac{y \cdot \mathsf{fma}\left(0.5, e^{x}, \frac{0.5}{e^{x}}\right)}{z \cdot x}\\

\mathbf{elif}\;z \leq 4.13020256225072 \cdot 10^{+92}:\\
\;\;\;\;\frac{\cosh x \cdot \frac{y}{x}}{z}\\

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


\end{array}
(FPCore (x y z) :precision binary64 (/ (* (cosh x) (/ y x)) z))
(FPCore (x y z)
 :precision binary64
 (if (<= z -404248964266.4667)
   (/ (* y (fma 0.5 (exp x) (/ 0.5 (exp x)))) (* z x))
   (if (<= z 4.13020256225072e+92)
     (/ (* (cosh x) (/ y x)) z)
     (/ (* 0.5 (fma (exp x) y (/ y (exp x)))) (* z x)))))
double code(double x, double y, double z) {
	return (cosh(x) * (y / x)) / z;
}
double code(double x, double y, double z) {
	double tmp;
	if (z <= -404248964266.4667) {
		tmp = (y * fma(0.5, exp(x), (0.5 / exp(x)))) / (z * x);
	} else if (z <= 4.13020256225072e+92) {
		tmp = (cosh(x) * (y / x)) / z;
	} else {
		tmp = (0.5 * fma(exp(x), y, (y / exp(x)))) / (z * x);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original7.6
Target0.4
Herbie0.7
\[\begin{array}{l} \mathbf{if}\;y < -4.618902267687042 \cdot 10^{-52}:\\ \;\;\;\;\frac{\frac{y}{z}}{x} \cdot \cosh x\\ \mathbf{elif}\;y < 1.038530535935153 \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 3 regimes
  2. if z < -404248964266.46667

    1. Initial program 11.8

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

      \[\leadsto \color{blue}{\frac{0.5 \cdot \left(e^{x} \cdot y\right) + 0.5 \cdot \frac{y}{e^{x}}}{z \cdot x}} \]
    3. Taylor expanded in x around -inf 0.3

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

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

    if -404248964266.46667 < z < 4.13020256225072017e92

    1. Initial program 1.1

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]

    if 4.13020256225072017e92 < z

    1. Initial program 14.1

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

      \[\leadsto \color{blue}{\frac{0.5 \cdot \left(e^{x} \cdot y\right) + 0.5 \cdot \frac{y}{e^{x}}}{z \cdot x}} \]
    3. Applied egg-rr0.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -404248964266.4667:\\ \;\;\;\;\frac{y \cdot \mathsf{fma}\left(0.5, e^{x}, \frac{0.5}{e^{x}}\right)}{z \cdot x}\\ \mathbf{elif}\;z \leq 4.13020256225072 \cdot 10^{+92}:\\ \;\;\;\;\frac{\cosh x \cdot \frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5 \cdot \mathsf{fma}\left(e^{x}, y, \frac{y}{e^{x}}\right)}{z \cdot x}\\ \end{array} \]

Reproduce

herbie shell --seed 2022130 
(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.038530535935153e-39) (/ (/ (* (cosh x) y) x) z) (* (/ (/ y z) x) (cosh x))))

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