Average Error: 7.8 → 0.9
Time: 6.6s
Precision: binary64
\[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
\[\begin{array}{l} \mathbf{if}\;z \leq -3.5 \cdot 10^{+25}:\\ \;\;\;\;\frac{y}{z \cdot x} + \frac{y}{z} \cdot \mathsf{fma}\left(x, 0.5, 0.041666666666666664 \cdot {x}^{3}\right)\\ \mathbf{elif}\;z \leq 4.4 \cdot 10^{-100}:\\ \;\;\;\;\frac{\frac{y \cdot \left(-\cosh x\right)}{-x}}{z}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{y \cdot \left(e^{x} + \frac{1}{e^{x}}\right)}{z \cdot x}\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* (cosh x) (/ y x)) z))
(FPCore (x y z)
 :precision binary64
 (if (<= z -3.5e+25)
   (+
    (/ y (* z x))
    (* (/ y z) (fma x 0.5 (* 0.041666666666666664 (pow x 3.0)))))
   (if (<= z 4.4e-100)
     (/ (/ (* y (- (cosh x))) (- x)) z)
     (* 0.5 (/ (* y (+ (exp x) (/ 1.0 (exp x)))) (* 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 tmp;
	if (z <= -3.5e+25) {
		tmp = (y / (z * x)) + ((y / z) * fma(x, 0.5, (0.041666666666666664 * pow(x, 3.0))));
	} else if (z <= 4.4e-100) {
		tmp = ((y * -cosh(x)) / -x) / z;
	} else {
		tmp = 0.5 * ((y * (exp(x) + (1.0 / exp(x)))) / (z * x));
	}
	return tmp;
}
function code(x, y, z)
	return Float64(Float64(cosh(x) * Float64(y / x)) / z)
end
function code(x, y, z)
	tmp = 0.0
	if (z <= -3.5e+25)
		tmp = Float64(Float64(y / Float64(z * x)) + Float64(Float64(y / z) * fma(x, 0.5, Float64(0.041666666666666664 * (x ^ 3.0)))));
	elseif (z <= 4.4e-100)
		tmp = Float64(Float64(Float64(y * Float64(-cosh(x))) / Float64(-x)) / z);
	else
		tmp = Float64(0.5 * Float64(Float64(y * Float64(exp(x) + Float64(1.0 / exp(x)))) / Float64(z * x)));
	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_] := If[LessEqual[z, -3.5e+25], N[(N[(y / N[(z * x), $MachinePrecision]), $MachinePrecision] + N[(N[(y / z), $MachinePrecision] * N[(x * 0.5 + N[(0.041666666666666664 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 4.4e-100], N[(N[(N[(y * (-N[Cosh[x], $MachinePrecision])), $MachinePrecision] / (-x)), $MachinePrecision] / z), $MachinePrecision], N[(0.5 * N[(N[(y * N[(N[Exp[x], $MachinePrecision] + N[(1.0 / N[Exp[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(z * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{\cosh x \cdot \frac{y}{x}}{z}
\begin{array}{l}
\mathbf{if}\;z \leq -3.5 \cdot 10^{+25}:\\
\;\;\;\;\frac{y}{z \cdot x} + \frac{y}{z} \cdot \mathsf{fma}\left(x, 0.5, 0.041666666666666664 \cdot {x}^{3}\right)\\

\mathbf{elif}\;z \leq 4.4 \cdot 10^{-100}:\\
\;\;\;\;\frac{\frac{y \cdot \left(-\cosh x\right)}{-x}}{z}\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{y \cdot \left(e^{x} + \frac{1}{e^{x}}\right)}{z \cdot x}\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original7.8
Target0.5
Herbie0.9
\[\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 z < -3.49999999999999999e25

    1. Initial program 12.6

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

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

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

    if -3.49999999999999999e25 < z < 4.39999999999999978e-100

    1. Initial program 0.5

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

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

    if 4.39999999999999978e-100 < z

    1. Initial program 9.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -3.5 \cdot 10^{+25}:\\ \;\;\;\;\frac{y}{z \cdot x} + \frac{y}{z} \cdot \mathsf{fma}\left(x, 0.5, 0.041666666666666664 \cdot {x}^{3}\right)\\ \mathbf{elif}\;z \leq 4.4 \cdot 10^{-100}:\\ \;\;\;\;\frac{\frac{y \cdot \left(-\cosh x\right)}{-x}}{z}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{y \cdot \left(e^{x} + \frac{1}{e^{x}}\right)}{z \cdot x}\\ \end{array} \]

Reproduce

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