Average Error: 7.6 → 0.5
Time: 6.3s
Precision: binary64
\[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
\[\begin{array}{l} t_0 := \cosh x \cdot \frac{y}{x}\\ t_1 := \frac{y \cdot \left(\mathsf{fma}\left(x, x \cdot 0.5, 0.001388888888888889 \cdot {x}^{6}\right) + \left(0.041666666666666664 \cdot {x}^{4} + 1\right)\right)}{x \cdot z}\\ \mathbf{if}\;t_0 \leq -1.3453778045793706 \cdot 10^{+264}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 1.5168936677776953 \cdot 10^{+199}:\\ \;\;\;\;\frac{t_0}{z}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \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)))
        (t_1
         (/
          (*
           y
           (+
            (fma x (* x 0.5) (* 0.001388888888888889 (pow x 6.0)))
            (+ (* 0.041666666666666664 (pow x 4.0)) 1.0)))
          (* x z))))
   (if (<= t_0 -1.3453778045793706e+264)
     t_1
     (if (<= t_0 1.5168936677776953e+199) (/ t_0 z) t_1))))
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 t_1 = (y * (fma(x, (x * 0.5), (0.001388888888888889 * pow(x, 6.0))) + ((0.041666666666666664 * pow(x, 4.0)) + 1.0))) / (x * z);
	double tmp;
	if (t_0 <= -1.3453778045793706e+264) {
		tmp = t_1;
	} else if (t_0 <= 1.5168936677776953e+199) {
		tmp = t_0 / z;
	} else {
		tmp = t_1;
	}
	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))
	t_1 = Float64(Float64(y * Float64(fma(x, Float64(x * 0.5), Float64(0.001388888888888889 * (x ^ 6.0))) + Float64(Float64(0.041666666666666664 * (x ^ 4.0)) + 1.0))) / Float64(x * z))
	tmp = 0.0
	if (t_0 <= -1.3453778045793706e+264)
		tmp = t_1;
	elseif (t_0 <= 1.5168936677776953e+199)
		tmp = Float64(t_0 / z);
	else
		tmp = t_1;
	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]}, Block[{t$95$1 = N[(N[(y * N[(N[(x * N[(x * 0.5), $MachinePrecision] + N[(0.001388888888888889 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(0.041666666666666664 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(x * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1.3453778045793706e+264], t$95$1, If[LessEqual[t$95$0, 1.5168936677776953e+199], N[(t$95$0 / z), $MachinePrecision], t$95$1]]]]
\frac{\cosh x \cdot \frac{y}{x}}{z}
\begin{array}{l}
t_0 := \cosh x \cdot \frac{y}{x}\\
t_1 := \frac{y \cdot \left(\mathsf{fma}\left(x, x \cdot 0.5, 0.001388888888888889 \cdot {x}^{6}\right) + \left(0.041666666666666664 \cdot {x}^{4} + 1\right)\right)}{x \cdot z}\\
\mathbf{if}\;t_0 \leq -1.3453778045793706 \cdot 10^{+264}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq 1.5168936677776953 \cdot 10^{+199}:\\
\;\;\;\;\frac{t_0}{z}\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Target

Original7.6
Target0.5
Herbie0.5
\[\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 2 regimes
  2. if (*.f64 (cosh.f64 x) (/.f64 y x)) < -1.3453778045793706e264 or 1.51689366777769529e199 < (*.f64 (cosh.f64 x) (/.f64 y x))

    1. Initial program 33.6

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Simplified1.4

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

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

      \[\leadsto \color{blue}{\frac{1}{\frac{x}{\frac{y}{z} \cdot \cosh x}}} \]
    5. Taylor expanded in x around 0 1.6

      \[\leadsto \frac{1}{\frac{x}{\color{blue}{\frac{y}{z} + \left(0.001388888888888889 \cdot \frac{y \cdot {x}^{6}}{z} + \left(0.5 \cdot \frac{y \cdot {x}^{2}}{z} + 0.041666666666666664 \cdot \frac{y \cdot {x}^{4}}{z}\right)\right)}}} \]
    6. Simplified1.6

      \[\leadsto \frac{1}{\frac{x}{\color{blue}{\frac{y}{z} \cdot \left(0.5 \cdot \left(x \cdot x\right) + 0.001388888888888889 \cdot {x}^{6}\right) + \mathsf{fma}\left(\frac{y}{z}, 0.041666666666666664 \cdot {x}^{4}, \frac{y}{z}\right)}}} \]
    7. Taylor expanded in z around 0 1.4

      \[\leadsto \color{blue}{\frac{0.001388888888888889 \cdot \left(y \cdot {x}^{6}\right) + \left(y + \left(0.5 \cdot \left(y \cdot {x}^{2}\right) + 0.041666666666666664 \cdot \left(y \cdot {x}^{4}\right)\right)\right)}{z \cdot x}} \]
    8. Simplified1.4

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

    if -1.3453778045793706e264 < (*.f64 (cosh.f64 x) (/.f64 y x)) < 1.51689366777769529e199

    1. Initial program 0.3

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cosh x \cdot \frac{y}{x} \leq -1.3453778045793706 \cdot 10^{+264}:\\ \;\;\;\;\frac{y \cdot \left(\mathsf{fma}\left(x, x \cdot 0.5, 0.001388888888888889 \cdot {x}^{6}\right) + \left(0.041666666666666664 \cdot {x}^{4} + 1\right)\right)}{x \cdot z}\\ \mathbf{elif}\;\cosh x \cdot \frac{y}{x} \leq 1.5168936677776953 \cdot 10^{+199}:\\ \;\;\;\;\frac{\cosh x \cdot \frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y \cdot \left(\mathsf{fma}\left(x, x \cdot 0.5, 0.001388888888888889 \cdot {x}^{6}\right) + \left(0.041666666666666664 \cdot {x}^{4} + 1\right)\right)}{x \cdot z}\\ \end{array} \]

Reproduce

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