Average Error: 7.9 → 0.6
Time: 5.0s
Precision: binary64
\[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
\[\begin{array}{l} \mathbf{if}\;z \leq -3.443166066450671 \cdot 10^{+34}:\\ \;\;\;\;\frac{0.5 \cdot \left(e^{x} \cdot y\right) + 0.5 \cdot \left(y \cdot e^{-x}\right)}{z \cdot x}\\ \mathbf{elif}\;z \leq 3.30371938788329 \cdot 10^{+39}:\\ \;\;\;\;\frac{\frac{y}{z} \cdot \mathsf{fma}\left(0.5, e^{x}, \frac{0.5}{e^{x}}\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.001388888888888889, \frac{y \cdot {x}^{5}}{z}, \mathsf{fma}\left(0.5, \frac{x \cdot y}{z}, \mathsf{fma}\left(0.041666666666666664, \frac{y \cdot {x}^{3}}{z}, \frac{y}{z \cdot x}\right)\right)\right)\\ \end{array} \]
\frac{\cosh x \cdot \frac{y}{x}}{z}
\begin{array}{l}
\mathbf{if}\;z \leq -3.443166066450671 \cdot 10^{+34}:\\
\;\;\;\;\frac{0.5 \cdot \left(e^{x} \cdot y\right) + 0.5 \cdot \left(y \cdot e^{-x}\right)}{z \cdot x}\\

\mathbf{elif}\;z \leq 3.30371938788329 \cdot 10^{+39}:\\
\;\;\;\;\frac{\frac{y}{z} \cdot \mathsf{fma}\left(0.5, e^{x}, \frac{0.5}{e^{x}}\right)}{x}\\

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


\end{array}
(FPCore (x y z) :precision binary64 (/ (* (cosh x) (/ y x)) z))
(FPCore (x y z)
 :precision binary64
 (if (<= z -3.443166066450671e+34)
   (/ (+ (* 0.5 (* (exp x) y)) (* 0.5 (* y (exp (- x))))) (* z x))
   (if (<= z 3.30371938788329e+39)
     (/ (* (/ y z) (fma 0.5 (exp x) (/ 0.5 (exp x)))) x)
     (fma
      0.001388888888888889
      (/ (* y (pow x 5.0)) z)
      (fma
       0.5
       (/ (* x y) z)
       (fma 0.041666666666666664 (/ (* y (pow x 3.0)) z) (/ y (* 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 <= -3.443166066450671e+34) {
		tmp = ((0.5 * (exp(x) * y)) + (0.5 * (y * exp(-x)))) / (z * x);
	} else if (z <= 3.30371938788329e+39) {
		tmp = ((y / z) * fma(0.5, exp(x), (0.5 / exp(x)))) / x;
	} else {
		tmp = fma(0.001388888888888889, ((y * pow(x, 5.0)) / z), fma(0.5, ((x * y) / z), fma(0.041666666666666664, ((y * pow(x, 3.0)) / z), (y / (z * x)))));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original7.9
Target0.5
Herbie0.6
\[\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 < -3.4431660664506708e34

    1. Initial program 12.9

      \[\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 div-inv_binary640.3

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

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

    if -3.4431660664506708e34 < z < 3.30371938788329005e39

    1. Initial program 0.6

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

      \[\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 associate-/r*_binary640.6

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

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

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

    if 3.30371938788329005e39 < z

    1. Initial program 13.5

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

      \[\leadsto \color{blue}{0.001388888888888889 \cdot \frac{y \cdot {x}^{5}}{z} + \left(0.5 \cdot \frac{y \cdot x}{z} + \left(\frac{y}{z \cdot x} + 0.041666666666666664 \cdot \frac{y \cdot {x}^{3}}{z}\right)\right)} \]
    3. Simplified0.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -3.443166066450671 \cdot 10^{+34}:\\ \;\;\;\;\frac{0.5 \cdot \left(e^{x} \cdot y\right) + 0.5 \cdot \left(y \cdot e^{-x}\right)}{z \cdot x}\\ \mathbf{elif}\;z \leq 3.30371938788329 \cdot 10^{+39}:\\ \;\;\;\;\frac{\frac{y}{z} \cdot \mathsf{fma}\left(0.5, e^{x}, \frac{0.5}{e^{x}}\right)}{x}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(0.001388888888888889, \frac{y \cdot {x}^{5}}{z}, \mathsf{fma}\left(0.5, \frac{x \cdot y}{z}, \mathsf{fma}\left(0.041666666666666664, \frac{y \cdot {x}^{3}}{z}, \frac{y}{z \cdot x}\right)\right)\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022077 
(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))