Average Error: 8.0 → 0.4
Time: 10.2s
Precision: binary64
Cost: 20424
\[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
\[\begin{array}{l} t_0 := \cosh x \cdot \frac{y}{x}\\ \mathbf{if}\;t_0 \leq -4 \cdot 10^{+282}:\\ \;\;\;\;\frac{y}{x \cdot z}\\ \mathbf{elif}\;t_0 \leq 10^{+221}:\\ \;\;\;\;\frac{t_0}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{z}}{x}\\ \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 -4e+282)
     (/ y (* x z))
     (if (<= t_0 1e+221) (/ t_0 z) (/ (/ y 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 t_0 = cosh(x) * (y / x);
	double tmp;
	if (t_0 <= -4e+282) {
		tmp = y / (x * z);
	} else if (t_0 <= 1e+221) {
		tmp = t_0 / z;
	} else {
		tmp = (y / z) / x;
	}
	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 = cosh(x) * (y / x)
    if (t_0 <= (-4d+282)) then
        tmp = y / (x * z)
    else if (t_0 <= 1d+221) then
        tmp = t_0 / z
    else
        tmp = (y / z) / x
    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 = Math.cosh(x) * (y / x);
	double tmp;
	if (t_0 <= -4e+282) {
		tmp = y / (x * z);
	} else if (t_0 <= 1e+221) {
		tmp = t_0 / z;
	} else {
		tmp = (y / z) / x;
	}
	return tmp;
}
def code(x, y, z):
	return (math.cosh(x) * (y / x)) / z
def code(x, y, z):
	t_0 = math.cosh(x) * (y / x)
	tmp = 0
	if t_0 <= -4e+282:
		tmp = y / (x * z)
	elif t_0 <= 1e+221:
		tmp = t_0 / z
	else:
		tmp = (y / z) / x
	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 <= -4e+282)
		tmp = Float64(y / Float64(x * z));
	elseif (t_0 <= 1e+221)
		tmp = Float64(t_0 / z);
	else
		tmp = Float64(Float64(y / z) / x);
	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 = cosh(x) * (y / x);
	tmp = 0.0;
	if (t_0 <= -4e+282)
		tmp = y / (x * z);
	elseif (t_0 <= 1e+221)
		tmp = t_0 / z;
	else
		tmp = (y / z) / x;
	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[Cosh[x], $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -4e+282], N[(y / N[(x * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e+221], N[(t$95$0 / z), $MachinePrecision], N[(N[(y / z), $MachinePrecision] / x), $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 -4 \cdot 10^{+282}:\\
\;\;\;\;\frac{y}{x \cdot z}\\

\mathbf{elif}\;t_0 \leq 10^{+221}:\\
\;\;\;\;\frac{t_0}{z}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{y}{z}}{x}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original8.0
Target0.4
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)) < -4.00000000000000013e282

    1. Initial program 52.5

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

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

    if -4.00000000000000013e282 < (*.f64 (cosh.f64 x) (/.f64 y x)) < 1e221

    1. Initial program 0.3

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

    if 1e221 < (*.f64 (cosh.f64 x) (/.f64 y x))

    1. Initial program 33.8

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

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

      \[\leadsto \color{blue}{\frac{\frac{\cosh x}{z}}{\frac{x}{y}}} \]
    4. Taylor expanded in x around 0 1.3

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

      \[\leadsto \color{blue}{\frac{\frac{y}{z}}{x}} \]
      Proof
      (/.f64 (/.f64 y z) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-/r*_binary64 (/.f64 y (*.f64 z x))): 54 points increase in error, 71 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cosh x \cdot \frac{y}{x} \leq -4 \cdot 10^{+282}:\\ \;\;\;\;\frac{y}{x \cdot z}\\ \mathbf{elif}\;\cosh x \cdot \frac{y}{x} \leq 10^{+221}:\\ \;\;\;\;\frac{\cosh x \cdot \frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{z}}{x}\\ \end{array} \]

Alternatives

Alternative 1
Error2.1
Cost7244
\[\begin{array}{l} t_0 := \frac{\frac{\cosh x}{z}}{\frac{x}{y}}\\ \mathbf{if}\;z \leq -1 \cdot 10^{-30}:\\ \;\;\;\;\frac{y}{x \cdot z} + y \cdot \left(\frac{x}{z} \cdot \left(x \cdot \left(x \cdot 0.041666666666666664\right) + 0.5\right)\right)\\ \mathbf{elif}\;z \leq 10^{-50}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.3183169543758011 \cdot 10^{+228}:\\ \;\;\;\;\frac{\cosh x}{\frac{x \cdot z}{y}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error2.2
Cost7244
\[\begin{array}{l} t_0 := \frac{\cosh x}{z}\\ \mathbf{if}\;z \leq -1 \cdot 10^{-30}:\\ \;\;\;\;\frac{y}{x \cdot z} + y \cdot \left(\frac{x}{z} \cdot \left(x \cdot \left(x \cdot 0.041666666666666664\right) + 0.5\right)\right)\\ \mathbf{elif}\;z \leq 10^{-60}:\\ \;\;\;\;\frac{y}{x} \cdot t_0\\ \mathbf{elif}\;z \leq 1.3183169543758011 \cdot 10^{+228}:\\ \;\;\;\;\frac{\cosh x}{\frac{x \cdot z}{y}}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{\frac{x}{y}}\\ \end{array} \]
Alternative 3
Error1.4
Cost7112
\[\begin{array}{l} t_0 := \frac{y}{x \cdot z}\\ \mathbf{if}\;y \leq -1 \cdot 10^{+120}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 4.190571633725181 \cdot 10^{-41}:\\ \;\;\;\;\frac{\frac{\cosh x}{z}}{\frac{x}{y}}\\ \mathbf{else}:\\ \;\;\;\;t_0 + y \cdot \left(\frac{x}{z} \cdot \left(x \cdot \left(x \cdot 0.041666666666666664\right) + 0.5\right)\right)\\ \end{array} \]
Alternative 4
Error0.5
Cost7112
\[\begin{array}{l} t_0 := \frac{\cosh x}{z}\\ \mathbf{if}\;z \leq -1 \cdot 10^{-30}:\\ \;\;\;\;\frac{y}{x \cdot z} + y \cdot \left(\frac{x}{z} \cdot \left(x \cdot \left(x \cdot 0.041666666666666664\right) + 0.5\right)\right)\\ \mathbf{elif}\;z \leq 10^{-10}:\\ \;\;\;\;\frac{y}{x} \cdot t_0\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{t_0}{x}\\ \end{array} \]
Alternative 5
Error1.1
Cost1480
\[\begin{array}{l} t_0 := \frac{\frac{y}{z}}{x} + y \cdot \left(\frac{x}{z} \cdot \left(x \cdot \left(x \cdot 0.041666666666666664\right) + 0.5\right)\right)\\ \mathbf{if}\;y \leq -1 \cdot 10^{-20}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 6.436951221045062 \cdot 10^{-73}:\\ \;\;\;\;\frac{\frac{y}{x} + 0.5 \cdot \left(x \cdot y\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error0.9
Cost1480
\[\begin{array}{l} t_0 := y \cdot \left(\frac{x}{z} \cdot \left(x \cdot \left(x \cdot 0.041666666666666664\right) + 0.5\right)\right)\\ t_1 := \frac{y}{x \cdot z} + t_0\\ \mathbf{if}\;z \leq -10000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 10^{+21}:\\ \;\;\;\;\frac{\frac{y}{z}}{x} + t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error1.3
Cost968
\[\begin{array}{l} t_0 := \frac{y}{x \cdot z}\\ \mathbf{if}\;y \leq -1 \cdot 10^{+45}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 10^{+26}:\\ \;\;\;\;\frac{\frac{y}{x} + 0.5 \cdot \left(x \cdot y\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error1.2
Cost968
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \cdot 10^{+45}:\\ \;\;\;\;\frac{y}{x \cdot z}\\ \mathbf{elif}\;y \leq 10^{-5}:\\ \;\;\;\;\frac{\frac{y}{x} + 0.5 \cdot \left(x \cdot y\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{z} \cdot \left(x \cdot 0.5 + \frac{1}{x}\right)\\ \end{array} \]
Alternative 9
Error1.5
Cost584
\[\begin{array}{l} t_0 := \frac{\frac{y}{z}}{x}\\ \mathbf{if}\;y \leq -1 \cdot 10^{-20}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 6.436951221045062 \cdot 10^{-73}:\\ \;\;\;\;\frac{\frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 10
Error1.4
Cost584
\[\begin{array}{l} t_0 := \frac{y}{x \cdot z}\\ \mathbf{if}\;z \leq -10000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 10^{+21}:\\ \;\;\;\;\frac{\frac{y}{z}}{x}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 11
Error8.1
Cost320
\[\frac{\frac{y}{z}}{x} \]

Error

Reproduce

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