Average Error: 7.7 → 0.8
Time: 9.1s
Precision: binary64
Cost: 7112
\[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
\[\begin{array}{l} t_0 := \frac{y}{z} \cdot \left(x \cdot 0.5 + \frac{1}{x}\right)\\ \mathbf{if}\;y \leq -1 \cdot 10^{-15}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 10^{-20}:\\ \;\;\;\;\frac{\frac{\cosh x}{\frac{x}{y}}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \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 0.5) (/ 1.0 x)))))
   (if (<= y -1e-15) t_0 (if (<= y 1e-20) (/ (/ (cosh x) (/ x y)) z) t_0))))
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 * 0.5) + (1.0 / x));
	double tmp;
	if (y <= -1e-15) {
		tmp = t_0;
	} else if (y <= 1e-20) {
		tmp = (cosh(x) / (x / y)) / z;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (cosh(x) * (y / x)) / z
end function
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (y / z) * ((x * 0.5d0) + (1.0d0 / x))
    if (y <= (-1d-15)) then
        tmp = t_0
    else if (y <= 1d-20) then
        tmp = (cosh(x) / (x / y)) / z
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	return (Math.cosh(x) * (y / x)) / z;
}
public static double code(double x, double y, double z) {
	double t_0 = (y / z) * ((x * 0.5) + (1.0 / x));
	double tmp;
	if (y <= -1e-15) {
		tmp = t_0;
	} else if (y <= 1e-20) {
		tmp = (Math.cosh(x) / (x / y)) / z;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	return (math.cosh(x) * (y / x)) / z
def code(x, y, z):
	t_0 = (y / z) * ((x * 0.5) + (1.0 / x))
	tmp = 0
	if y <= -1e-15:
		tmp = t_0
	elif y <= 1e-20:
		tmp = (math.cosh(x) / (x / y)) / z
	else:
		tmp = t_0
	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(Float64(y / z) * Float64(Float64(x * 0.5) + Float64(1.0 / x)))
	tmp = 0.0
	if (y <= -1e-15)
		tmp = t_0;
	elseif (y <= 1e-20)
		tmp = Float64(Float64(cosh(x) / Float64(x / y)) / z);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp = code(x, y, z)
	tmp = (cosh(x) * (y / x)) / z;
end
function tmp_2 = code(x, y, z)
	t_0 = (y / z) * ((x * 0.5) + (1.0 / x));
	tmp = 0.0;
	if (y <= -1e-15)
		tmp = t_0;
	elseif (y <= 1e-20)
		tmp = (cosh(x) / (x / y)) / z;
	else
		tmp = t_0;
	end
	tmp_2 = 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[(y / z), $MachinePrecision] * N[(N[(x * 0.5), $MachinePrecision] + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1e-15], t$95$0, If[LessEqual[y, 1e-20], N[(N[(N[Cosh[x], $MachinePrecision] / N[(x / y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], t$95$0]]]
\frac{\cosh x \cdot \frac{y}{x}}{z}
\begin{array}{l}
t_0 := \frac{y}{z} \cdot \left(x \cdot 0.5 + \frac{1}{x}\right)\\
\mathbf{if}\;y \leq -1 \cdot 10^{-15}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y \leq 10^{-20}:\\
\;\;\;\;\frac{\frac{\cosh x}{\frac{x}{y}}}{z}\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original7.7
Target0.4
Herbie0.8
\[\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 y < -1.0000000000000001e-15 or 9.99999999999999945e-21 < y

    1. Initial program 19.7

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

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

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

    if -1.0000000000000001e-15 < y < 9.99999999999999945e-21

    1. Initial program 0.3

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

      \[\leadsto \frac{\color{blue}{\frac{\cosh x}{\frac{x}{y}}}}{z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \leq -1 \cdot 10^{-15}:\\ \;\;\;\;\frac{y}{z} \cdot \left(x \cdot 0.5 + \frac{1}{x}\right)\\ \mathbf{elif}\;y \leq 10^{-20}:\\ \;\;\;\;\frac{\frac{\cosh x}{\frac{x}{y}}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{z} \cdot \left(x \cdot 0.5 + \frac{1}{x}\right)\\ \end{array} \]

Alternatives

Alternative 1
Error1.5
Cost968
\[\begin{array}{l} t_0 := \frac{y}{z} \cdot \left(x \cdot 0.5 + \frac{1}{x}\right)\\ \mathbf{if}\;y \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 10^{+48}:\\ \;\;\;\;\frac{\frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error1.3
Cost968
\[\begin{array}{l} t_0 := \frac{y}{z} \cdot \left(x \cdot 0.5 + \frac{1}{x}\right)\\ \mathbf{if}\;y \leq -1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 10^{+48}:\\ \;\;\;\;\frac{\frac{y}{x} + 0.5 \cdot \left(y \cdot x\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error1.5
Cost584
\[\begin{array}{l} t_0 := \frac{\frac{y}{z}}{x}\\ \mathbf{if}\;y \leq -1 \cdot 10^{-45}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 10^{-20}:\\ \;\;\;\;\frac{\frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error7.9
Cost320
\[\frac{\frac{y}{z}}{x} \]

Error

Reproduce

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