Average Error: 7.7 → 1.5
Time: 8.9s
Precision: binary64
Cost: 14212
\[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
\[\begin{array}{l} t_0 := \frac{y}{z \cdot x}\\ \mathbf{if}\;z \leq -4 \cdot 10^{-23}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{y}{z} \cdot x, t_0\right) + \frac{0.041666666666666664 \cdot \left(y \cdot {x}^{3}\right)}{z}\\ \mathbf{elif}\;z \leq 3.8 \cdot 10^{+125}:\\ \;\;\;\;\frac{\cosh x \cdot \frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0 + \frac{0.5 \cdot \left(y \cdot x\right)}{z}\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* (cosh x) (/ y x)) z))
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ y (* z x))))
   (if (<= z -4e-23)
     (+
      (fma 0.5 (* (/ y z) x) t_0)
      (/ (* 0.041666666666666664 (* y (pow x 3.0))) z))
     (if (<= z 3.8e+125)
       (/ (* (cosh x) (/ y x)) z)
       (+ t_0 (/ (* 0.5 (* y x)) z))))))
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 = y / (z * x);
	double tmp;
	if (z <= -4e-23) {
		tmp = fma(0.5, ((y / z) * x), t_0) + ((0.041666666666666664 * (y * pow(x, 3.0))) / z);
	} else if (z <= 3.8e+125) {
		tmp = (cosh(x) * (y / x)) / z;
	} else {
		tmp = t_0 + ((0.5 * (y * x)) / z);
	}
	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(y / Float64(z * x))
	tmp = 0.0
	if (z <= -4e-23)
		tmp = Float64(fma(0.5, Float64(Float64(y / z) * x), t_0) + Float64(Float64(0.041666666666666664 * Float64(y * (x ^ 3.0))) / z));
	elseif (z <= 3.8e+125)
		tmp = Float64(Float64(cosh(x) * Float64(y / x)) / z);
	else
		tmp = Float64(t_0 + Float64(Float64(0.5 * Float64(y * x)) / z));
	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[(y / N[(z * x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -4e-23], N[(N[(0.5 * N[(N[(y / z), $MachinePrecision] * x), $MachinePrecision] + t$95$0), $MachinePrecision] + N[(N[(0.041666666666666664 * N[(y * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 3.8e+125], N[(N[(N[Cosh[x], $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], N[(t$95$0 + N[(N[(0.5 * N[(y * x), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]]]]
\frac{\cosh x \cdot \frac{y}{x}}{z}
\begin{array}{l}
t_0 := \frac{y}{z \cdot x}\\
\mathbf{if}\;z \leq -4 \cdot 10^{-23}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{y}{z} \cdot x, t_0\right) + \frac{0.041666666666666664 \cdot \left(y \cdot {x}^{3}\right)}{z}\\

\mathbf{elif}\;z \leq 3.8 \cdot 10^{+125}:\\
\;\;\;\;\frac{\cosh x \cdot \frac{y}{x}}{z}\\

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


\end{array}

Error

Target

Original7.7
Target0.4
Herbie1.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 3 regimes
  2. if z < -3.99999999999999984e-23

    1. Initial program 11.5

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Simplified0.6

      \[\leadsto \color{blue}{y \cdot \frac{\frac{\cosh x}{z}}{x}} \]
      Proof
      (*.f64 y (/.f64 (/.f64 (cosh.f64 x) z) x)): 0 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 y (/.f64 (cosh.f64 x) z)) x)): 64 points increase in error, 63 points decrease in error
      (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 y x) (/.f64 (cosh.f64 x) z))): 54 points increase in error, 62 points decrease in error
      (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 (cosh.f64 x) z) (/.f64 y x))): 0 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 (cosh.f64 x) (/.f64 y x)) z)): 16 points increase in error, 32 points decrease in error
    3. Taylor expanded in x around 0 1.0

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, \frac{y}{z} \cdot x, \frac{y}{x \cdot z}\right) + \frac{0.041666666666666664 \cdot \left(y \cdot {x}^{3}\right)}{z}} \]
      Proof
      (+.f64 (fma.f64 1/2 (*.f64 (/.f64 y z) x) (/.f64 y (*.f64 x z))) (/.f64 (*.f64 1/24 (*.f64 y (pow.f64 x 3))) z)): 0 points increase in error, 0 points decrease in error
      (+.f64 (fma.f64 1/2 (Rewrite<= associate-/r/_binary64 (/.f64 y (/.f64 z x))) (/.f64 y (*.f64 x z))) (/.f64 (*.f64 1/24 (*.f64 y (pow.f64 x 3))) z)): 0 points increase in error, 0 points decrease in error
      (+.f64 (fma.f64 1/2 (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 y x) z)) (/.f64 y (*.f64 x z))) (/.f64 (*.f64 1/24 (*.f64 y (pow.f64 x 3))) z)): 0 points increase in error, 0 points decrease in error
      (+.f64 (fma.f64 1/2 (/.f64 (*.f64 y x) z) (/.f64 y (Rewrite<= *-commutative_binary64 (*.f64 z x)))) (/.f64 (*.f64 1/24 (*.f64 y (pow.f64 x 3))) z)): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= fma-def_binary64 (+.f64 (*.f64 1/2 (/.f64 (*.f64 y x) z)) (/.f64 y (*.f64 z x)))) (/.f64 (*.f64 1/24 (*.f64 y (pow.f64 x 3))) z)): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= +-commutative_binary64 (+.f64 (/.f64 y (*.f64 z x)) (*.f64 1/2 (/.f64 (*.f64 y x) z)))) (/.f64 (*.f64 1/24 (*.f64 y (pow.f64 x 3))) z)): 0 points increase in error, 0 points decrease in error
      (+.f64 (+.f64 (/.f64 y (*.f64 z x)) (*.f64 1/2 (/.f64 (*.f64 y x) z))) (Rewrite<= associate-*r/_binary64 (*.f64 1/24 (/.f64 (*.f64 y (pow.f64 x 3)) z)))): 1 points increase in error, 0 points decrease in error
      (Rewrite<= associate-+r+_binary64 (+.f64 (/.f64 y (*.f64 z x)) (+.f64 (*.f64 1/2 (/.f64 (*.f64 y x) z)) (*.f64 1/24 (/.f64 (*.f64 y (pow.f64 x 3)) z))))): 1 points increase in error, 1 points decrease in error

    if -3.99999999999999984e-23 < z < 3.80000000000000002e125

    1. Initial program 2.1

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

    if 3.80000000000000002e125 < z

    1. Initial program 13.8

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Simplified12.7

      \[\leadsto \color{blue}{\frac{\cosh x \cdot \frac{y}{z}}{x}} \]
      Proof
      (/.f64 (*.f64 (cosh.f64 x) (/.f64 y z)) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*r/_binary64 (*.f64 (cosh.f64 x) (/.f64 (/.f64 y z) x))): 3 points increase in error, 1 points decrease in error
      (*.f64 (cosh.f64 x) (Rewrite<= associate-/r*_binary64 (/.f64 y (*.f64 z x)))): 62 points increase in error, 54 points decrease in error
      (*.f64 (cosh.f64 x) (Rewrite<= associate-/l/_binary64 (/.f64 (/.f64 y x) z))): 59 points increase in error, 65 points decrease in error
      (Rewrite=> associate-*r/_binary64 (/.f64 (*.f64 (cosh.f64 x) (/.f64 y x)) z)): 1 points increase in error, 1 points decrease in error
    3. Taylor expanded in x around 0 0.9

      \[\leadsto \color{blue}{\frac{y}{z \cdot x} + 0.5 \cdot \frac{y \cdot x}{z}} \]
    4. Simplified0.9

      \[\leadsto \color{blue}{\frac{y}{z \cdot x} + \frac{0.5 \cdot \left(y \cdot x\right)}{z}} \]
      Proof
      (+.f64 (/.f64 y (*.f64 z x)) (/.f64 (*.f64 1/2 (*.f64 y x)) z)): 0 points increase in error, 0 points decrease in error
      (+.f64 (/.f64 y (*.f64 z x)) (Rewrite<= associate-*r/_binary64 (*.f64 1/2 (/.f64 (*.f64 y x) z)))): 0 points increase in error, 0 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification1.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -4 \cdot 10^{-23}:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{y}{z} \cdot x, \frac{y}{z \cdot x}\right) + \frac{0.041666666666666664 \cdot \left(y \cdot {x}^{3}\right)}{z}\\ \mathbf{elif}\;z \leq 3.8 \cdot 10^{+125}:\\ \;\;\;\;\frac{\cosh x \cdot \frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{z \cdot x} + \frac{0.5 \cdot \left(y \cdot x\right)}{z}\\ \end{array} \]

Alternatives

Alternative 1
Error0.8
Cost7112
\[\begin{array}{l} \mathbf{if}\;y \leq -1.3 \cdot 10^{-34}:\\ \;\;\;\;\cosh x \cdot \frac{y}{z \cdot x}\\ \mathbf{elif}\;y \leq 6 \cdot 10^{-11}:\\ \;\;\;\;\frac{\frac{y}{x} + 0.5 \cdot \left(y \cdot x\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cosh x}{\frac{z \cdot x}{y}}\\ \end{array} \]
Alternative 2
Error1.6
Cost7112
\[\begin{array}{l} t_0 := \frac{y}{z \cdot x} + \frac{0.5 \cdot \left(y \cdot x\right)}{z}\\ \mathbf{if}\;z \leq -1.8 \cdot 10^{-27}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5 \cdot 10^{+125}:\\ \;\;\;\;\frac{\cosh x \cdot \frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error1.1
Cost6980
\[\begin{array}{l} t_0 := 0.5 \cdot \left(y \cdot x\right)\\ \mathbf{if}\;y \leq -8.3 \cdot 10^{-35}:\\ \;\;\;\;y \cdot \frac{\frac{\cosh x}{z}}{x}\\ \mathbf{elif}\;y \leq 6 \cdot 10^{+28}:\\ \;\;\;\;\frac{\frac{y}{x} + t_0}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{z \cdot x} + \frac{t_0}{z}\\ \end{array} \]
Alternative 4
Error1.1
Cost6980
\[\begin{array}{l} t_0 := 0.5 \cdot \left(y \cdot x\right)\\ t_1 := \frac{y}{z \cdot x}\\ \mathbf{if}\;y \leq -1 \cdot 10^{-34}:\\ \;\;\;\;\cosh x \cdot t_1\\ \mathbf{elif}\;y \leq 4.4 \cdot 10^{+28}:\\ \;\;\;\;\frac{\frac{y}{x} + t_0}{z}\\ \mathbf{else}:\\ \;\;\;\;t_1 + \frac{t_0}{z}\\ \end{array} \]
Alternative 5
Error2.1
Cost1096
\[\begin{array}{l} t_0 := 0.5 \cdot \left(y \cdot x\right)\\ t_1 := \frac{y}{z \cdot x} + \frac{t_0}{z}\\ \mathbf{if}\;z \leq -2.2 \cdot 10^{-22}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.8 \cdot 10^{+125}:\\ \;\;\;\;\frac{\frac{y}{x} + t_0}{z}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error1.4
Cost1032
\[\begin{array}{l} t_0 := \frac{\frac{-1}{x} + x \cdot -0.5}{\frac{-z}{y}}\\ \mathbf{if}\;y \leq -1.3 \cdot 10^{-34}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 4.7 \cdot 10^{+28}:\\ \;\;\;\;\frac{\frac{y}{x} + 0.5 \cdot \left(y \cdot x\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error1.9
Cost968
\[\begin{array}{l} t_0 := \frac{y}{z \cdot x}\\ \mathbf{if}\;z \leq -2 \cdot 10^{-24}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.5 \cdot 10^{+87}:\\ \;\;\;\;\frac{y \cdot \left(0.5 \cdot x + \frac{1}{x}\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error2.3
Cost968
\[\begin{array}{l} t_0 := \frac{y}{z \cdot x}\\ \mathbf{if}\;z \leq -6 \cdot 10^{-26}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.2 \cdot 10^{+127}:\\ \;\;\;\;\frac{\frac{y}{x} + 0.5 \cdot \left(y \cdot x\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error2.5
Cost584
\[\begin{array}{l} t_0 := \frac{y}{z \cdot x}\\ \mathbf{if}\;z \leq -5 \cdot 10^{-22}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 5.7 \cdot 10^{+125}:\\ \;\;\;\;\frac{\frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 10
Error8.4
Cost320
\[\frac{y}{z \cdot x} \]

Error

Reproduce

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