Average Error: 7.6 → 0.6
Time: 8.4s
Precision: binary64
Cost: 7112
\[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
\[\begin{array}{l} \mathbf{if}\;y \leq -1.15 \cdot 10^{-25}:\\ \;\;\;\;\frac{\frac{y}{z}}{x} + \frac{y}{z} \cdot \left(x \cdot 0.5\right)\\ \mathbf{elif}\;y \leq 7.2 \cdot 10^{+29}:\\ \;\;\;\;\frac{\cosh x \cdot \frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;\cosh x \cdot \frac{y}{z \cdot x}\\ \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* (cosh x) (/ y x)) z))
(FPCore (x y z)
 :precision binary64
 (if (<= y -1.15e-25)
   (+ (/ (/ y z) x) (* (/ y z) (* x 0.5)))
   (if (<= y 7.2e+29) (/ (* (cosh x) (/ y x)) z) (* (cosh x) (/ 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 tmp;
	if (y <= -1.15e-25) {
		tmp = ((y / z) / x) + ((y / z) * (x * 0.5));
	} else if (y <= 7.2e+29) {
		tmp = (cosh(x) * (y / x)) / z;
	} else {
		tmp = cosh(x) * (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) :: tmp
    if (y <= (-1.15d-25)) then
        tmp = ((y / z) / x) + ((y / z) * (x * 0.5d0))
    else if (y <= 7.2d+29) then
        tmp = (cosh(x) * (y / x)) / z
    else
        tmp = cosh(x) * (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 tmp;
	if (y <= -1.15e-25) {
		tmp = ((y / z) / x) + ((y / z) * (x * 0.5));
	} else if (y <= 7.2e+29) {
		tmp = (Math.cosh(x) * (y / x)) / z;
	} else {
		tmp = Math.cosh(x) * (y / (z * x));
	}
	return tmp;
}
def code(x, y, z):
	return (math.cosh(x) * (y / x)) / z
def code(x, y, z):
	tmp = 0
	if y <= -1.15e-25:
		tmp = ((y / z) / x) + ((y / z) * (x * 0.5))
	elif y <= 7.2e+29:
		tmp = (math.cosh(x) * (y / x)) / z
	else:
		tmp = math.cosh(x) * (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)
	tmp = 0.0
	if (y <= -1.15e-25)
		tmp = Float64(Float64(Float64(y / z) / x) + Float64(Float64(y / z) * Float64(x * 0.5)));
	elseif (y <= 7.2e+29)
		tmp = Float64(Float64(cosh(x) * Float64(y / x)) / z);
	else
		tmp = Float64(cosh(x) * Float64(y / Float64(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)
	tmp = 0.0;
	if (y <= -1.15e-25)
		tmp = ((y / z) / x) + ((y / z) * (x * 0.5));
	elseif (y <= 7.2e+29)
		tmp = (cosh(x) * (y / x)) / z;
	else
		tmp = cosh(x) * (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_] := If[LessEqual[y, -1.15e-25], N[(N[(N[(y / z), $MachinePrecision] / x), $MachinePrecision] + N[(N[(y / z), $MachinePrecision] * N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7.2e+29], N[(N[(N[Cosh[x], $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], N[(N[Cosh[x], $MachinePrecision] * N[(y / N[(z * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{\cosh x \cdot \frac{y}{x}}{z}
\begin{array}{l}
\mathbf{if}\;y \leq -1.15 \cdot 10^{-25}:\\
\;\;\;\;\frac{\frac{y}{z}}{x} + \frac{y}{z} \cdot \left(x \cdot 0.5\right)\\

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

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original7.6
Target0.4
Herbie0.6
\[\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 y < -1.15e-25

    1. Initial program 18.4

      \[\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)): 63 points increase in error, 62 points decrease in error
      (Rewrite<= associate-*l/_binary64 (*.f64 (/.f64 y x) (/.f64 (cosh.f64 x) z))): 69 points increase in error, 65 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)): 14 points increase in error, 37 points decrease in error
    3. Taylor expanded in x around 0 1.7

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

      \[\leadsto \color{blue}{\frac{\frac{y}{z}}{x} + \frac{0.5 \cdot \left(x \cdot y\right)}{z}} \]
      Proof
      (+.f64 (/.f64 (/.f64 y z) x) (/.f64 (*.f64 1/2 (*.f64 x y)) z)): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= associate-/r*_binary64 (/.f64 y (*.f64 z x))) (/.f64 (*.f64 1/2 (*.f64 x y)) z)): 66 points increase in error, 62 points decrease in error
      (+.f64 (/.f64 y (*.f64 z x)) (/.f64 (*.f64 1/2 (Rewrite<= *-commutative_binary64 (*.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
    5. Applied egg-rr1.7

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

    if -1.15e-25 < y < 7.19999999999999952e29

    1. Initial program 0.4

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

    if 7.19999999999999952e29 < y

    1. Initial program 24.6

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

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

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

Alternatives

Alternative 1
Error0.9
Cost7112
\[\begin{array}{l} t_0 := y \cdot \frac{\frac{\cosh x}{z}}{x}\\ \mathbf{if}\;z \leq -10000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 4.2 \cdot 10^{-56}:\\ \;\;\;\;\frac{\frac{y}{z}}{x} + \frac{y}{z} \cdot \left(x \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.7
Cost7112
\[\begin{array}{l} \mathbf{if}\;z \leq -225:\\ \;\;\;\;y \cdot \frac{\frac{\cosh x}{z}}{x}\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{-47}:\\ \;\;\;\;\frac{\frac{y}{z}}{x} + \frac{y}{z} \cdot \left(x \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\cosh x \cdot \frac{y}{z \cdot x}\\ \end{array} \]
Alternative 3
Error1.2
Cost1224
\[\begin{array}{l} t_0 := 0.5 \cdot \left(y \cdot x\right)\\ \mathbf{if}\;y \leq -9 \cdot 10^{-26}:\\ \;\;\;\;\frac{\frac{y}{z}}{x} + \frac{y}{z} \cdot \left(x \cdot 0.5\right)\\ \mathbf{elif}\;y \leq 1.9 \cdot 10^{+27}:\\ \;\;\;\;\frac{\frac{y}{x} + t_0}{z}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{1}{z \cdot x} + \frac{t_0}{z}\\ \end{array} \]
Alternative 4
Error1.7
Cost1096
\[\begin{array}{l} t_0 := \frac{y}{z \cdot x}\\ \mathbf{if}\;z \leq -4.6 \cdot 10^{+44}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 3.4 \cdot 10^{+82}:\\ \;\;\;\;\frac{0.5 \cdot \left(y \cdot x\right)}{z} + \frac{\frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error1.8
Cost968
\[\begin{array}{l} t_0 := \frac{y}{z \cdot x}\\ \mathbf{if}\;z \leq -8.8 \cdot 10^{+45}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.6 \cdot 10^{+82}:\\ \;\;\;\;\frac{y \cdot \left(x \cdot 0.5 + \frac{1}{x}\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error1.8
Cost968
\[\begin{array}{l} t_0 := \frac{y}{z \cdot x}\\ \mathbf{if}\;z \leq -4.6 \cdot 10^{+44}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{+86}:\\ \;\;\;\;\frac{\frac{y}{x} + 0.5 \cdot \left(y \cdot x\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Error1.5
Cost584
\[\begin{array}{l} t_0 := \frac{y}{z \cdot x}\\ \mathbf{if}\;y \leq -1.95 \cdot 10^{-25}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 2 \cdot 10^{+27}:\\ \;\;\;\;\frac{\frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error1.5
Cost584
\[\begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{-25}:\\ \;\;\;\;\frac{\frac{y}{z}}{x}\\ \mathbf{elif}\;y \leq 8 \cdot 10^{+30}:\\ \;\;\;\;\frac{\frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{z \cdot x}\\ \end{array} \]
Alternative 9
Error8.7
Cost320
\[\frac{y}{z \cdot x} \]

Error

Reproduce

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