Average Error: 8.0 → 0.4
Time: 1.0min
Precision: binary64
\[\frac{\cosh x \cdot \frac{y}{x}}{z}\]
\[\begin{array}{l} \mathbf{if}\;\cosh x \cdot \frac{y}{x} \leq -1.9265948427821044 \cdot 10^{+247}:\\ \;\;\;\;\frac{0.5 \cdot \left(y \cdot e^{x}\right) + 0.5 \cdot \left(y \cdot e^{-x}\right)}{x \cdot z}\\ \mathbf{elif}\;\cosh x \cdot \frac{y}{x} \leq 2.3818179904215993 \cdot 10^{+243}:\\ \;\;\;\;\frac{\frac{\cosh x \cdot y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2 \cdot \frac{x \cdot z}{y \cdot \left(e^{x} + e^{-x}\right)}}\\ \end{array}\]
\frac{\cosh x \cdot \frac{y}{x}}{z}
\begin{array}{l}
\mathbf{if}\;\cosh x \cdot \frac{y}{x} \leq -1.9265948427821044 \cdot 10^{+247}:\\
\;\;\;\;\frac{0.5 \cdot \left(y \cdot e^{x}\right) + 0.5 \cdot \left(y \cdot e^{-x}\right)}{x \cdot z}\\

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

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

\end{array}
(FPCore (x y z) :precision binary64 (/ (* (cosh x) (/ y x)) z))
(FPCore (x y z)
 :precision binary64
 (if (<= (* (cosh x) (/ y x)) -1.9265948427821044e+247)
   (/ (+ (* 0.5 (* y (exp x))) (* 0.5 (* y (exp (- x))))) (* x z))
   (if (<= (* (cosh x) (/ y x)) 2.3818179904215993e+243)
     (/ (/ (* (cosh x) y) x) z)
     (/ 1.0 (* 2.0 (/ (* x z) (* y (+ (exp x) (exp (- 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 ((cosh(x) * (y / x)) <= -1.9265948427821044e+247) {
		tmp = ((0.5 * (y * exp(x))) + (0.5 * (y * exp(-x)))) / (x * z);
	} else if ((cosh(x) * (y / x)) <= 2.3818179904215993e+243) {
		tmp = ((cosh(x) * y) / x) / z;
	} else {
		tmp = 1.0 / (2.0 * ((x * z) / (y * (exp(x) + exp(-x)))));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original8.0
Target0.4
Herbie0.4
\[\begin{array}{l} \mathbf{if}\;y < -4.618902267687042 \cdot 10^{-52}:\\ \;\;\;\;\frac{\frac{y}{z}}{x} \cdot \cosh x\\ \mathbf{elif}\;y < 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 3 regimes
  2. if (*.f64 (cosh.f64 x) (/.f64 y x)) < -1.92659484278210436e247

    1. Initial program 39.7

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

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

    if -1.92659484278210436e247 < (*.f64 (cosh.f64 x) (/.f64 y x)) < 2.38181799042159928e243

    1. Initial program 0.2

      \[\frac{\cosh x \cdot \frac{y}{x}}{z}\]
    2. Using strategy rm
    3. Applied associate-*r/_binary64_136600.2

      \[\leadsto \frac{\color{blue}{\frac{\cosh x \cdot y}{x}}}{z}\]

    if 2.38181799042159928e243 < (*.f64 (cosh.f64 x) (/.f64 y x))

    1. Initial program 39.1

      \[\frac{\cosh x \cdot \frac{y}{x}}{z}\]
    2. Using strategy rm
    3. Applied clear-num_binary64_1371739.1

      \[\leadsto \color{blue}{\frac{1}{\frac{z}{\cosh x \cdot \frac{y}{x}}}}\]
    4. Simplified39.1

      \[\leadsto \frac{1}{\color{blue}{\frac{z}{\frac{y}{x} \cdot \cosh x}}}\]
    5. Taylor expanded around 0 1.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cosh x \cdot \frac{y}{x} \leq -1.9265948427821044 \cdot 10^{+247}:\\ \;\;\;\;\frac{0.5 \cdot \left(y \cdot e^{x}\right) + 0.5 \cdot \left(y \cdot e^{-x}\right)}{x \cdot z}\\ \mathbf{elif}\;\cosh x \cdot \frac{y}{x} \leq 2.3818179904215993 \cdot 10^{+243}:\\ \;\;\;\;\frac{\frac{\cosh x \cdot y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2 \cdot \frac{x \cdot z}{y \cdot \left(e^{x} + e^{-x}\right)}}\\ \end{array}\]

Reproduce

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