Average Error: 7.7 → 0.6
Time: 5.5s
Precision: binary64
\[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
\[\begin{array}{l} t_0 := \frac{\cosh x \cdot \frac{y}{x}}{z}\\ \mathbf{if}\;t_0 \leq -4.3175020757824464 \cdot 10^{+210}:\\ \;\;\;\;\frac{1}{\frac{x}{\frac{y}{z} \cdot \mathsf{fma}\left(0.5, e^{x}, \frac{0.5}{e^{x}}\right)}}\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_1 := \mathsf{fma}\left(y, e^{x}, \frac{y}{e^{x}}\right)\\ \mathbf{if}\;t_0 \leq 2.383605224751973 \cdot 10^{-78}:\\ \;\;\;\;\frac{\frac{t_1}{x \cdot 2}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.5 \cdot \frac{t_1}{z}}{-x}\\ \end{array}\\ \end{array} \]
\frac{\cosh x \cdot \frac{y}{x}}{z}
\begin{array}{l}
t_0 := \frac{\cosh x \cdot \frac{y}{x}}{z}\\
\mathbf{if}\;t_0 \leq -4.3175020757824464 \cdot 10^{+210}:\\
\;\;\;\;\frac{1}{\frac{x}{\frac{y}{z} \cdot \mathsf{fma}\left(0.5, e^{x}, \frac{0.5}{e^{x}}\right)}}\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_1 := \mathsf{fma}\left(y, e^{x}, \frac{y}{e^{x}}\right)\\
\mathbf{if}\;t_0 \leq 2.383605224751973 \cdot 10^{-78}:\\
\;\;\;\;\frac{\frac{t_1}{x \cdot 2}}{z}\\

\mathbf{else}:\\
\;\;\;\;\frac{-0.5 \cdot \frac{t_1}{z}}{-x}\\


\end{array}\\


\end{array}
(FPCore (x y z) :precision binary64 (/ (* (cosh x) (/ y x)) z))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ (* (cosh x) (/ y x)) z)))
   (if (<= t_0 -4.3175020757824464e+210)
     (/ 1.0 (/ x (* (/ y z) (fma 0.5 (exp x) (/ 0.5 (exp x))))))
     (let* ((t_1 (fma y (exp x) (/ y (exp x)))))
       (if (<= t_0 2.383605224751973e-78)
         (/ (/ t_1 (* x 2.0)) z)
         (/ (* -0.5 (/ t_1 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 t_0 = (cosh(x) * (y / x)) / z;
	double tmp;
	if (t_0 <= -4.3175020757824464e+210) {
		tmp = 1.0 / (x / ((y / z) * fma(0.5, exp(x), (0.5 / exp(x)))));
	} else {
		double t_1 = fma(y, exp(x), (y / exp(x)));
		double tmp_1;
		if (t_0 <= 2.383605224751973e-78) {
			tmp_1 = (t_1 / (x * 2.0)) / z;
		} else {
			tmp_1 = (-0.5 * (t_1 / z)) / -x;
		}
		tmp = tmp_1;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original7.7
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 (/.f64 (*.f64 (cosh.f64 x) (/.f64 y x)) z) < -4.3175020757824464e210

    1. Initial program 30.6

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

      \[\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.5

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

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

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

    if -4.3175020757824464e210 < (/.f64 (*.f64 (cosh.f64 x) (/.f64 y x)) z) < 2.3836052247519729e-78

    1. Initial program 0.2

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

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

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

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

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

    if 2.3836052247519729e-78 < (/.f64 (*.f64 (cosh.f64 x) (/.f64 y x)) z)

    1. Initial program 10.2

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

      \[\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*_binary641.1

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

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

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

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

Reproduce

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