Average Error: 7.4 → 0.4
Time: 4.2s
Precision: binary64
\[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
\[\begin{array}{l} t_0 := \cosh x \cdot \frac{y}{x}\\ \mathbf{if}\;t_0 \leq -1 \cdot 10^{+219}:\\ \;\;\;\;y \cdot \frac{\cosh x}{x \cdot z}\\ \mathbf{elif}\;t_0 \leq 2 \cdot 10^{+276}:\\ \;\;\;\;\frac{t_0}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{x \cdot z} + \frac{y}{z} \cdot \left(\mathsf{fma}\left(0.041666666666666664, {x}^{3}, 0.001388888888888889 \cdot {x}^{5}\right) + x \cdot 0.5\right)\\ \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))))
   (if (<= t_0 -1e+219)
     (* y (/ (cosh x) (* x z)))
     (if (<= t_0 2e+276)
       (/ t_0 z)
       (+
        (/ y (* x z))
        (*
         (/ y z)
         (+
          (fma
           0.041666666666666664
           (pow x 3.0)
           (* 0.001388888888888889 (pow x 5.0)))
          (* x 0.5))))))))
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);
	double tmp;
	if (t_0 <= -1e+219) {
		tmp = y * (cosh(x) / (x * z));
	} else if (t_0 <= 2e+276) {
		tmp = t_0 / z;
	} else {
		tmp = (y / (x * z)) + ((y / z) * (fma(0.041666666666666664, pow(x, 3.0), (0.001388888888888889 * pow(x, 5.0))) + (x * 0.5)));
	}
	return tmp;
}
function code(x, y, z)
	return Float64(Float64(cosh(x) * Float64(y / x)) / z)
end
function code(x, y, z)
	t_0 = Float64(cosh(x) * Float64(y / x))
	tmp = 0.0
	if (t_0 <= -1e+219)
		tmp = Float64(y * Float64(cosh(x) / Float64(x * z)));
	elseif (t_0 <= 2e+276)
		tmp = Float64(t_0 / z);
	else
		tmp = Float64(Float64(y / Float64(x * z)) + Float64(Float64(y / z) * Float64(fma(0.041666666666666664, (x ^ 3.0), Float64(0.001388888888888889 * (x ^ 5.0))) + Float64(x * 0.5))));
	end
	return tmp
end
code[x_, y_, z_] := N[(N[(N[Cosh[x], $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cosh[x], $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e+219], N[(y * N[(N[Cosh[x], $MachinePrecision] / N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e+276], N[(t$95$0 / z), $MachinePrecision], N[(N[(y / N[(x * z), $MachinePrecision]), $MachinePrecision] + N[(N[(y / z), $MachinePrecision] * N[(N[(0.041666666666666664 * N[Power[x, 3.0], $MachinePrecision] + N[(0.001388888888888889 * N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\frac{\cosh x \cdot \frac{y}{x}}{z}
\begin{array}{l}
t_0 := \cosh x \cdot \frac{y}{x}\\
\mathbf{if}\;t_0 \leq -1 \cdot 10^{+219}:\\
\;\;\;\;y \cdot \frac{\cosh x}{x \cdot z}\\

\mathbf{elif}\;t_0 \leq 2 \cdot 10^{+276}:\\
\;\;\;\;\frac{t_0}{z}\\

\mathbf{else}:\\
\;\;\;\;\frac{y}{x \cdot z} + \frac{y}{z} \cdot \left(\mathsf{fma}\left(0.041666666666666664, {x}^{3}, 0.001388888888888889 \cdot {x}^{5}\right) + x \cdot 0.5\right)\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original7.4
Target0.5
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.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 (cosh.f64 x) (/.f64 y x)) < -9.99999999999999965e218

    1. Initial program 31.3

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

      \[\leadsto \color{blue}{\cosh x \cdot \frac{1}{z \cdot \frac{x}{y}}} \]
    3. Applied egg-rr28.2

      \[\leadsto \color{blue}{\frac{\frac{\cosh x}{z}}{\frac{x}{y}}} \]
    4. Applied egg-rr0.7

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

    if -9.99999999999999965e218 < (*.f64 (cosh.f64 x) (/.f64 y x)) < 2.0000000000000001e276

    1. Initial program 0.2

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Applied egg-rr0.6

      \[\leadsto \color{blue}{\cosh x \cdot \frac{1}{z \cdot \frac{x}{y}}} \]
    3. Applied egg-rr0.4

      \[\leadsto \color{blue}{\frac{\frac{\cosh x}{z}}{\frac{x}{y}}} \]
    4. Applied egg-rr0.2

      \[\leadsto \color{blue}{{\left(\frac{\cosh x \cdot \frac{y}{x}}{z}\right)}^{1}} \]

    if 2.0000000000000001e276 < (*.f64 (cosh.f64 x) (/.f64 y x))

    1. Initial program 48.0

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

      \[\leadsto \color{blue}{0.001388888888888889 \cdot \frac{y \cdot {x}^{5}}{z} + \left(0.5 \cdot \frac{y \cdot x}{z} + \left(\frac{y}{z \cdot x} + 0.041666666666666664 \cdot \frac{y \cdot {x}^{3}}{z}\right)\right)} \]
    3. Simplified0.9

      \[\leadsto \color{blue}{\frac{y}{z \cdot x} + \frac{y}{z} \cdot \left(\mathsf{fma}\left(0.041666666666666664, {x}^{3}, 0.001388888888888889 \cdot {x}^{5}\right) + x \cdot 0.5\right)} \]
  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 \cdot 10^{+219}:\\ \;\;\;\;y \cdot \frac{\cosh x}{x \cdot z}\\ \mathbf{elif}\;\cosh x \cdot \frac{y}{x} \leq 2 \cdot 10^{+276}:\\ \;\;\;\;\frac{\cosh x \cdot \frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{x \cdot z} + \frac{y}{z} \cdot \left(\mathsf{fma}\left(0.041666666666666664, {x}^{3}, 0.001388888888888889 \cdot {x}^{5}\right) + x \cdot 0.5\right)\\ \end{array} \]

Reproduce

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