Average Error: 7.9 → 0.5
Time: 3.3s
Precision: 64
\[\frac{\cosh x \cdot \frac{y}{x}}{z}\]
\[\begin{array}{l} \mathbf{if}\;\cosh x \cdot \frac{y}{x} \le -1.865052624181062 \cdot 10^{247}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{2}, x \cdot \frac{y}{z}, \frac{y}{x \cdot z}\right)\\ \mathbf{elif}\;\cosh x \cdot \frac{y}{x} \le 2.4776903717072572 \cdot 10^{243}:\\ \;\;\;\;\frac{\cosh x \cdot \frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{2}, \frac{x \cdot y}{z}, \frac{1}{\frac{x \cdot z}{y}}\right)\\ \end{array}\]
\frac{\cosh x \cdot \frac{y}{x}}{z}
\begin{array}{l}
\mathbf{if}\;\cosh x \cdot \frac{y}{x} \le -1.865052624181062 \cdot 10^{247}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{2}, x \cdot \frac{y}{z}, \frac{y}{x \cdot z}\right)\\

\mathbf{elif}\;\cosh x \cdot \frac{y}{x} \le 2.4776903717072572 \cdot 10^{243}:\\
\;\;\;\;\frac{\cosh x \cdot \frac{y}{x}}{z}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{2}, \frac{x \cdot y}{z}, \frac{1}{\frac{x \cdot z}{y}}\right)\\

\end{array}
double code(double x, double y, double z) {
	return ((cosh(x) * (y / x)) / z);
}
double code(double x, double y, double z) {
	double temp;
	if (((cosh(x) * (y / x)) <= -1.865052624181062e+247)) {
		temp = fma(0.5, (x * (y / z)), (y / (x * z)));
	} else {
		double temp_1;
		if (((cosh(x) * (y / x)) <= 2.477690371707257e+243)) {
			temp_1 = ((cosh(x) * (y / x)) / z);
		} else {
			temp_1 = fma(0.5, ((x * y) / z), (1.0 / ((x * z) / y)));
		}
		temp = temp_1;
	}
	return temp;
}

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

Original7.9
Target0.5
Herbie0.5
\[\begin{array}{l} \mathbf{if}\;y \lt -4.618902267687042 \cdot 10^{-52}:\\ \;\;\;\;\frac{\frac{y}{z}}{x} \cdot \cosh x\\ \mathbf{elif}\;y \lt 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 (* (cosh x) (/ y x)) < -1.865052624181062e+247

    1. Initial program 38.8

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

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{x \cdot y}{z} + \frac{y}{x \cdot z}}\]
    3. Simplified1.3

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{2}, \frac{x \cdot y}{z}, \frac{y}{x \cdot z}\right)}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity1.3

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \frac{x \cdot y}{\color{blue}{1 \cdot z}}, \frac{y}{x \cdot z}\right)\]
    6. Applied times-frac1.3

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \color{blue}{\frac{x}{1} \cdot \frac{y}{z}}, \frac{y}{x \cdot z}\right)\]
    7. Simplified1.3

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

    if -1.865052624181062e+247 < (* (cosh x) (/ y x)) < 2.477690371707257e+243

    1. Initial program 0.2

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

    if 2.477690371707257e+243 < (* (cosh x) (/ y x))

    1. Initial program 39.3

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

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{x \cdot y}{z} + \frac{y}{x \cdot z}}\]
    3. Simplified1.5

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{2}, \frac{x \cdot y}{z}, \frac{y}{x \cdot z}\right)}\]
    4. Using strategy rm
    5. Applied clear-num1.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cosh x \cdot \frac{y}{x} \le -1.865052624181062 \cdot 10^{247}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{2}, x \cdot \frac{y}{z}, \frac{y}{x \cdot z}\right)\\ \mathbf{elif}\;\cosh x \cdot \frac{y}{x} \le 2.4776903717072572 \cdot 10^{243}:\\ \;\;\;\;\frac{\cosh x \cdot \frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\frac{1}{2}, \frac{x \cdot y}{z}, \frac{1}{\frac{x \cdot z}{y}}\right)\\ \end{array}\]

Reproduce

herbie shell --seed 2020060 +o rules:numerics
(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))