Average Error: 8.0 → 0.7
Time: 4.4s
Precision: binary64
\[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
\[\begin{array}{l} t_0 := \mathsf{fma}\left(y, e^{x}, \frac{y}{e^{x}}\right)\\ \mathbf{if}\;y \leq -3.441851333323831 \cdot 10^{-84}:\\ \;\;\;\;0.5 \cdot \frac{t_0}{x \cdot z}\\ \mathbf{elif}\;y \leq 5.152424174613172 \cdot 10^{+47}:\\ \;\;\;\;\frac{\frac{t_0}{x \cdot 2}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot \cosh x}{x \cdot z}\\ \end{array} \]
\frac{\cosh x \cdot \frac{y}{x}}{z}
\begin{array}{l}
t_0 := \mathsf{fma}\left(y, e^{x}, \frac{y}{e^{x}}\right)\\
\mathbf{if}\;y \leq -3.441851333323831 \cdot 10^{-84}:\\
\;\;\;\;0.5 \cdot \frac{t_0}{x \cdot z}\\

\mathbf{elif}\;y \leq 5.152424174613172 \cdot 10^{+47}:\\
\;\;\;\;\frac{\frac{t_0}{x \cdot 2}}{z}\\

\mathbf{else}:\\
\;\;\;\;\frac{y \cdot \cosh x}{x \cdot z}\\


\end{array}
(FPCore (x y z) :precision binary64 (/ (* (cosh x) (/ y x)) z))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (fma y (exp x) (/ y (exp x)))))
   (if (<= y -3.441851333323831e-84)
     (* 0.5 (/ t_0 (* x z)))
     (if (<= y 5.152424174613172e+47)
       (/ (/ t_0 (* x 2.0)) z)
       (/ (* y (cosh x)) (* x z))))))
double code(double x, double y, double z) {
	return (cosh(x) * (y / x)) / z;
}
double code(double x, double y, double z) {
	double t_0 = fma(y, exp(x), (y / exp(x)));
	double tmp;
	if (y <= -3.441851333323831e-84) {
		tmp = 0.5 * (t_0 / (x * z));
	} else if (y <= 5.152424174613172e+47) {
		tmp = (t_0 / (x * 2.0)) / z;
	} else {
		tmp = (y * cosh(x)) / (x * z);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original8.0
Target0.5
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 y < -3.44185133332383086e-84

    1. Initial program 15.4

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

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

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

      \[\leadsto \frac{\frac{0.5 \cdot \left(e^{x} \cdot y\right) + 0.5 \cdot \frac{y}{e^{x}}}{\color{blue}{1 \cdot x}}}{1 \cdot z} \]
    5. Applied distribute-lft-out_binary6415.4

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

      \[\leadsto \frac{\color{blue}{\frac{0.5}{1} \cdot \frac{e^{x} \cdot y + \frac{y}{e^{x}}}{x}}}{1 \cdot z} \]
    7. Applied times-frac_binary6415.4

      \[\leadsto \color{blue}{\frac{\frac{0.5}{1}}{1} \cdot \frac{\frac{e^{x} \cdot y + \frac{y}{e^{x}}}{x}}{z}} \]
    8. Simplified15.4

      \[\leadsto \color{blue}{0.5} \cdot \frac{\frac{e^{x} \cdot y + \frac{y}{e^{x}}}{x}}{z} \]
    9. Simplified1.5

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

    if -3.44185133332383086e-84 < y < 5.15242417461317167e47

    1. Initial program 0.5

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Applied cosh-def_binary640.5

      \[\leadsto \frac{\color{blue}{\frac{e^{x} + e^{-x}}{2}} \cdot \frac{y}{x}}{z} \]
    3. Applied frac-times_binary640.5

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

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

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

    if 5.15242417461317167e47 < y

    1. Initial program 26.5

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Applied associate-*r/_binary6426.5

      \[\leadsto \frac{\color{blue}{\frac{\cosh x \cdot y}{x}}}{z} \]
    3. Applied associate-/l/_binary640.3

      \[\leadsto \color{blue}{\frac{\cosh x \cdot y}{z \cdot x}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.7

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

Reproduce

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