?

Average Error: 8.2 → 0.8
Time: 17.9s
Precision: binary64
Cost: 13832

?

\[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
\[\begin{array}{l} t_0 := \frac{y}{z \cdot x} + 0.5 \cdot \frac{y \cdot x}{z}\\ \mathbf{if}\;z \leq -200:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.6 \cdot 10^{-49}:\\ \;\;\;\;\frac{0.5 \cdot \frac{y \cdot \left(e^{x} + e^{-x}\right)}{x}}{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 (/ (* y x) z)))))
   (if (<= z -200.0)
     t_0
     (if (<= z 1.6e-49)
       (/ (* 0.5 (/ (* y (+ (exp x) (exp (- x)))) x)) 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 * ((y * x) / z));
	double tmp;
	if (z <= -200.0) {
		tmp = t_0;
	} else if (z <= 1.6e-49) {
		tmp = (0.5 * ((y * (exp(x) + exp(-x))) / x)) / 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 * ((y * x) / z))
    if (z <= (-200.0d0)) then
        tmp = t_0
    else if (z <= 1.6d-49) then
        tmp = (0.5d0 * ((y * (exp(x) + exp(-x))) / x)) / 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 * ((y * x) / z));
	double tmp;
	if (z <= -200.0) {
		tmp = t_0;
	} else if (z <= 1.6e-49) {
		tmp = (0.5 * ((y * (Math.exp(x) + Math.exp(-x))) / x)) / 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 * ((y * x) / z))
	tmp = 0
	if z <= -200.0:
		tmp = t_0
	elif z <= 1.6e-49:
		tmp = (0.5 * ((y * (math.exp(x) + math.exp(-x))) / x)) / 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 / Float64(z * x)) + Float64(0.5 * Float64(Float64(y * x) / z)))
	tmp = 0.0
	if (z <= -200.0)
		tmp = t_0;
	elseif (z <= 1.6e-49)
		tmp = Float64(Float64(0.5 * Float64(Float64(y * Float64(exp(x) + exp(Float64(-x)))) / x)) / 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 * ((y * x) / z));
	tmp = 0.0;
	if (z <= -200.0)
		tmp = t_0;
	elseif (z <= 1.6e-49)
		tmp = (0.5 * ((y * (exp(x) + exp(-x))) / x)) / 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 / N[(z * x), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(N[(y * x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -200.0], t$95$0, If[LessEqual[z, 1.6e-49], N[(N[(0.5 * N[(N[(y * N[(N[Exp[x], $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], t$95$0]]]
\frac{\cosh x \cdot \frac{y}{x}}{z}
\begin{array}{l}
t_0 := \frac{y}{z \cdot x} + 0.5 \cdot \frac{y \cdot x}{z}\\
\mathbf{if}\;z \leq -200:\\
\;\;\;\;t_0\\

\mathbf{elif}\;z \leq 1.6 \cdot 10^{-49}:\\
\;\;\;\;\frac{0.5 \cdot \frac{y \cdot \left(e^{x} + e^{-x}\right)}{x}}{z}\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original8.2
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 z < -200 or 1.60000000000000001e-49 < z

    1. Initial program 11.8

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

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

    if -200 < z < 1.60000000000000001e-49

    1. Initial program 0.3

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

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

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

      [Start]0.3

      \[ \frac{0.5 \cdot \frac{\left(\frac{1}{e^{x}} + e^{x}\right) \cdot y}{x}}{z} \]

      rational.json-simplify-2 [=>]0.3

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

      rational.json-simplify-1 [=>]0.3

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

      exponential.json-simplify-4 [=>]0.3

      \[ \frac{0.5 \cdot \frac{y \cdot \left(e^{x} + \color{blue}{e^{-x}}\right)}{x}}{z} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.8

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -200:\\ \;\;\;\;\frac{y}{z \cdot x} + 0.5 \cdot \frac{y \cdot x}{z}\\ \mathbf{elif}\;z \leq 1.6 \cdot 10^{-49}:\\ \;\;\;\;\frac{0.5 \cdot \frac{y \cdot \left(e^{x} + e^{-x}\right)}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{z \cdot x} + 0.5 \cdot \frac{y \cdot x}{z}\\ \end{array} \]

Alternatives

Alternative 1
Error0.8
Cost7112
\[\begin{array}{l} t_0 := \frac{y}{z \cdot x} + 0.5 \cdot \frac{y \cdot x}{z}\\ \mathbf{if}\;z \leq -14.5:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{-50}:\\ \;\;\;\;\frac{\cosh x \cdot \frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error1.3
Cost1096
\[\begin{array}{l} t_0 := \frac{y}{z \cdot x} + 0.5 \cdot \frac{y \cdot x}{z}\\ \mathbf{if}\;z \leq -7.6 \cdot 10^{-31}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{-63}:\\ \;\;\;\;\frac{\frac{y}{x} + y \cdot \left(x \cdot 0.5\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error2.2
Cost968
\[\begin{array}{l} t_0 := y \cdot \frac{0.5 \cdot x + \frac{1}{x}}{z}\\ \mathbf{if}\;y \leq -4 \cdot 10^{-39}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y \leq 3.1 \cdot 10^{+116}:\\ \;\;\;\;\frac{\frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error1.9
Cost968
\[\begin{array}{l} \mathbf{if}\;y \leq -20000:\\ \;\;\;\;\frac{y}{z \cdot x}\\ \mathbf{elif}\;y \leq 3.1 \cdot 10^{+116}:\\ \;\;\;\;\frac{\frac{y}{x} + y \cdot \left(x \cdot 0.5\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;y \cdot \frac{0.5 \cdot x + \frac{1}{x}}{z}\\ \end{array} \]
Alternative 5
Error1.6
Cost584
\[\begin{array}{l} t_0 := \frac{y}{z \cdot x}\\ \mathbf{if}\;z \leq -3 \cdot 10^{-30}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;z \leq 3.2 \cdot 10^{-63}:\\ \;\;\;\;\frac{\frac{y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error8.2
Cost320
\[\frac{y}{z \cdot x} \]

Error

Reproduce?

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