Average Error: 7.4 → 0.7
Time: 10.5s
Precision: binary64
Cost: 20681
\[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
\[\begin{array}{l} t_0 := \frac{\cosh x \cdot \frac{y}{x}}{z}\\ \mathbf{if}\;t_0 \leq -5 \cdot 10^{+109} \lor \neg \left(t_0 \leq 2 \cdot 10^{-38}\right):\\ \;\;\;\;\cosh x \cdot \frac{\frac{y}{z}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cosh x \cdot y}{x \cdot z}\\ \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)) z)))
   (if (or (<= t_0 -5e+109) (not (<= t_0 2e-38)))
     (* (cosh x) (/ (/ y z) x))
     (/ (* (cosh x) 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 = (cosh(x) * (y / x)) / z;
	double tmp;
	if ((t_0 <= -5e+109) || !(t_0 <= 2e-38)) {
		tmp = cosh(x) * ((y / z) / x);
	} else {
		tmp = (cosh(x) * y) / (x * z);
	}
	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)) / z
    if ((t_0 <= (-5d+109)) .or. (.not. (t_0 <= 2d-38))) then
        tmp = cosh(x) * ((y / z) / x)
    else
        tmp = (cosh(x) * y) / (x * z)
    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)) / z;
	double tmp;
	if ((t_0 <= -5e+109) || !(t_0 <= 2e-38)) {
		tmp = Math.cosh(x) * ((y / z) / x);
	} else {
		tmp = (Math.cosh(x) * y) / (x * z);
	}
	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)) / z
	tmp = 0
	if (t_0 <= -5e+109) or not (t_0 <= 2e-38):
		tmp = math.cosh(x) * ((y / z) / x)
	else:
		tmp = (math.cosh(x) * 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(Float64(cosh(x) * Float64(y / x)) / z)
	tmp = 0.0
	if ((t_0 <= -5e+109) || !(t_0 <= 2e-38))
		tmp = Float64(cosh(x) * Float64(Float64(y / z) / x));
	else
		tmp = Float64(Float64(cosh(x) * y) / Float64(x * z));
	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)) / z;
	tmp = 0.0;
	if ((t_0 <= -5e+109) || ~((t_0 <= 2e-38)))
		tmp = cosh(x) * ((y / z) / x);
	else
		tmp = (cosh(x) * y) / (x * z);
	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[(N[Cosh[x], $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -5e+109], N[Not[LessEqual[t$95$0, 2e-38]], $MachinePrecision]], N[(N[Cosh[x], $MachinePrecision] * N[(N[(y / z), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cosh[x], $MachinePrecision] * y), $MachinePrecision] / N[(x * z), $MachinePrecision]), $MachinePrecision]]]
\frac{\cosh x \cdot \frac{y}{x}}{z}
\begin{array}{l}
t_0 := \frac{\cosh x \cdot \frac{y}{x}}{z}\\
\mathbf{if}\;t_0 \leq -5 \cdot 10^{+109} \lor \neg \left(t_0 \leq 2 \cdot 10^{-38}\right):\\
\;\;\;\;\cosh x \cdot \frac{\frac{y}{z}}{x}\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original7.4
Target0.4
Herbie0.7
\[\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 (/.f64 (*.f64 (cosh.f64 x) (/.f64 y x)) z) < -5.0000000000000001e109 or 1.9999999999999999e-38 < (/.f64 (*.f64 (cosh.f64 x) (/.f64 y x)) z)

    1. Initial program 13.7

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

      \[\leadsto \color{blue}{\cosh x \cdot \frac{\frac{y}{z}}{x}} \]
      Proof
      (*.f64 (cosh.f64 x) (/.f64 (/.f64 y z) x)): 0 points increase in error, 0 points decrease in error
      (*.f64 (cosh.f64 x) (Rewrite<= associate-/r*_binary64 (/.f64 y (*.f64 z x)))): 0 points increase in error, 0 points decrease in error
      (*.f64 (cosh.f64 x) (Rewrite<= associate-/l/_binary64 (/.f64 (/.f64 y x) z))): 2 points increase in error, 0 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

    if -5.0000000000000001e109 < (/.f64 (*.f64 (cosh.f64 x) (/.f64 y x)) z) < 1.9999999999999999e-38

    1. Initial program 0.2

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Simplified1.1

      \[\leadsto \color{blue}{\frac{\cosh x \cdot y}{z \cdot x}} \]
      Proof
      (*.f64 (cosh.f64 x) (/.f64 (/.f64 y z) x)): 0 points increase in error, 0 points decrease in error
      (*.f64 (cosh.f64 x) (Rewrite<= associate-/r*_binary64 (/.f64 y (*.f64 z x)))): 0 points increase in error, 0 points decrease in error
      (*.f64 (cosh.f64 x) (Rewrite<= associate-/l/_binary64 (/.f64 (/.f64 y x) z))): 2 points increase in error, 0 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. Recombined 2 regimes into one program.
  4. Final simplification0.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\cosh x \cdot \frac{y}{x}}{z} \leq -5 \cdot 10^{+109} \lor \neg \left(\frac{\cosh x \cdot \frac{y}{x}}{z} \leq 2 \cdot 10^{-38}\right):\\ \;\;\;\;\cosh x \cdot \frac{\frac{y}{z}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cosh x \cdot y}{x \cdot z}\\ \end{array} \]

Alternatives

Alternative 1
Error1.0
Cost7113
\[\begin{array}{l} \mathbf{if}\;y \leq -3.4 \cdot 10^{-9} \lor \neg \left(y \leq 1.16 \cdot 10^{-95}\right):\\ \;\;\;\;\cosh x \cdot \frac{y}{x \cdot z}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{y}{\frac{z}{x}} + \frac{\frac{y}{x}}{z}\\ \end{array} \]
Alternative 2
Error0.4
Cost7113
\[\begin{array}{l} \mathbf{if}\;z \leq -2.05 \cdot 10^{-53} \lor \neg \left(z \leq 10^{+23}\right):\\ \;\;\;\;\cosh x \cdot \frac{y}{x \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\cosh x \cdot \frac{\frac{y}{z}}{x}\\ \end{array} \]
Alternative 3
Error0.3
Cost7112
\[\begin{array}{l} \mathbf{if}\;z \leq -2.5 \cdot 10^{-11}:\\ \;\;\;\;y \cdot \frac{\frac{\cosh x}{z}}{x}\\ \mathbf{elif}\;z \leq 3 \cdot 10^{+23}:\\ \;\;\;\;\cosh x \cdot \frac{\frac{y}{z}}{x}\\ \mathbf{else}:\\ \;\;\;\;\cosh x \cdot \frac{y}{x \cdot z}\\ \end{array} \]
Alternative 4
Error1.2
Cost1097
\[\begin{array}{l} \mathbf{if}\;y \leq -3.2 \cdot 10^{-20} \lor \neg \left(y \leq 1.12 \cdot 10^{-48}\right):\\ \;\;\;\;\frac{y}{z} \cdot \left(\frac{1}{x} + x \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{y}{\frac{z}{x}} + \frac{\frac{y}{x}}{z}\\ \end{array} \]
Alternative 5
Error1.3
Cost1097
\[\begin{array}{l} \mathbf{if}\;z \leq -3.2 \cdot 10^{-53} \lor \neg \left(z \leq 10^{+23}\right):\\ \;\;\;\;\frac{y}{x \cdot z} + 0.5 \cdot \frac{x \cdot y}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x} + x \cdot 0.5}{\frac{z}{y}}\\ \end{array} \]
Alternative 6
Error1.4
Cost969
\[\begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{-20} \lor \neg \left(y \leq 1.12 \cdot 10^{-48}\right):\\ \;\;\;\;\frac{y}{z} \cdot \left(\frac{1}{x} + x \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{x}}{z}\\ \end{array} \]
Alternative 7
Error1.2
Cost969
\[\begin{array}{l} \mathbf{if}\;y \leq -1.5 \cdot 10^{-21} \lor \neg \left(y \leq 1.12 \cdot 10^{-48}\right):\\ \;\;\;\;\frac{y}{z} \cdot \left(\frac{1}{x} + x \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{x} + 0.5 \cdot \left(x \cdot y\right)}{z}\\ \end{array} \]
Alternative 8
Error1.7
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -7.7 \cdot 10^{-56} \lor \neg \left(z \leq 9.2 \cdot 10^{+22}\right):\\ \;\;\;\;\frac{y}{x \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{x}}{\frac{z}{y}}\\ \end{array} \]
Alternative 9
Error1.8
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -1.66 \cdot 10^{-81} \lor \neg \left(z \leq 10^{+23}\right):\\ \;\;\;\;\frac{y}{x \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{x}}{z}\\ \end{array} \]
Alternative 10
Error1.6
Cost585
\[\begin{array}{l} \mathbf{if}\;z \leq -3.2 \cdot 10^{-53} \lor \neg \left(z \leq 9.5 \cdot 10^{+22}\right):\\ \;\;\;\;\frac{y}{x \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{z}}{x}\\ \end{array} \]
Alternative 11
Error8.6
Cost320
\[\frac{y}{x \cdot z} \]

Error

Reproduce

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