Average Error: 8.2 → 0.3
Time: 5.5s
Precision: binary64
\[\frac{\cosh x \cdot \frac{y}{x}}{z}\]
\[\begin{array}{l} \mathbf{if}\;\frac{\cosh x \cdot \frac{y}{x}}{z} \leq -1.0883442995444593 \cdot 10^{+227}:\\ \;\;\;\;0.5 \cdot \frac{\left(e^{x} + e^{-x}\right) \cdot \frac{y}{z}}{x}\\ \mathbf{elif}\;\frac{\cosh x \cdot \frac{y}{x}}{z} \leq 320335455290.5229:\\ \;\;\;\;\frac{\cosh x \cdot \frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\left(\left(e^{x} + e^{-x}\right) \cdot \frac{y}{z}\right) \cdot \frac{1}{x}\right)\\ \end{array}\]
\frac{\cosh x \cdot \frac{y}{x}}{z}
\begin{array}{l}
\mathbf{if}\;\frac{\cosh x \cdot \frac{y}{x}}{z} \leq -1.0883442995444593 \cdot 10^{+227}:\\
\;\;\;\;0.5 \cdot \frac{\left(e^{x} + e^{-x}\right) \cdot \frac{y}{z}}{x}\\

\mathbf{elif}\;\frac{\cosh x \cdot \frac{y}{x}}{z} \leq 320335455290.5229:\\
\;\;\;\;\frac{\cosh x \cdot \frac{y}{x}}{z}\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\left(\left(e^{x} + e^{-x}\right) \cdot \frac{y}{z}\right) \cdot \frac{1}{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)) z) -1.0883442995444593e+227)
   (* 0.5 (/ (* (+ (exp x) (exp (- x))) (/ y z)) x))
   (if (<= (/ (* (cosh x) (/ y x)) z) 320335455290.5229)
     (/ (* (cosh x) (/ y x)) z)
     (* 0.5 (* (* (+ (exp x) (exp (- x))) (/ y z)) (/ 1.0 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)) / z) <= -1.0883442995444593e+227) {
		tmp = 0.5 * (((exp(x) + exp(-x)) * (y / z)) / x);
	} else if (((cosh(x) * (y / x)) / z) <= 320335455290.5229) {
		tmp = (cosh(x) * (y / x)) / z;
	} else {
		tmp = 0.5 * (((exp(x) + exp(-x)) * (y / z)) * (1.0 / 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.2
Target0.4
Herbie0.3
\[\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 (*.f64 (cosh.f64 x) (/.f64 y x)) z) < -1.0883442995444593e227

    1. Initial program 34.8

      \[\frac{\cosh x \cdot \frac{y}{x}}{z}\]
    2. Taylor expanded around inf 12.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}}\]
    3. Simplified12.5

      \[\leadsto \color{blue}{0.5 \cdot \left(\frac{y}{x \cdot z} \cdot \left(e^{x} + e^{-x}\right)\right)}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity_binary6412.5

      \[\leadsto 0.5 \cdot \left(\frac{\color{blue}{1 \cdot y}}{x \cdot z} \cdot \left(e^{x} + e^{-x}\right)\right)\]
    6. Applied times-frac_binary640.7

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

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

      \[\leadsto 0.5 \cdot \left(\frac{1}{x} \cdot \color{blue}{\left(\left(e^{x} + e^{-x}\right) \cdot \frac{y}{z}\right)}\right)\]
    9. Using strategy rm
    10. Applied associate-*l/_binary640.5

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

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

    if -1.0883442995444593e227 < (/.f64 (*.f64 (cosh.f64 x) (/.f64 y x)) z) < 320335455290.522888

    1. Initial program 0.2

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

    if 320335455290.522888 < (/.f64 (*.f64 (cosh.f64 x) (/.f64 y x)) z)

    1. Initial program 14.3

      \[\frac{\cosh x \cdot \frac{y}{x}}{z}\]
    2. Taylor expanded around inf 11.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}}\]
    3. Simplified11.7

      \[\leadsto \color{blue}{0.5 \cdot \left(\frac{y}{x \cdot z} \cdot \left(e^{x} + e^{-x}\right)\right)}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity_binary6411.7

      \[\leadsto 0.5 \cdot \left(\frac{\color{blue}{1 \cdot y}}{x \cdot z} \cdot \left(e^{x} + e^{-x}\right)\right)\]
    6. Applied times-frac_binary640.4

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

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

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

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

Alternatives

Reproduce

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