Average Error: 7.5 → 0.8
Time: 8.3s
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 -4 \cdot 10^{-68} \lor \neg \left(t_0 \leq 2 \cdot 10^{-27}\right):\\ \;\;\;\;\cosh x \cdot \frac{\frac{y}{z}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{x} + 0.5 \cdot \left(x \cdot y\right)}{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 -4e-68) (not (<= t_0 2e-27)))
     (* (cosh x) (/ (/ y z) x))
     (/ (+ (/ y x) (* 0.5 (* x y))) 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 <= -4e-68) || !(t_0 <= 2e-27)) {
		tmp = cosh(x) * ((y / z) / x);
	} else {
		tmp = ((y / x) + (0.5 * (x * y))) / 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 <= (-4d-68)) .or. (.not. (t_0 <= 2d-27))) then
        tmp = cosh(x) * ((y / z) / x)
    else
        tmp = ((y / x) + (0.5d0 * (x * y))) / 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 <= -4e-68) || !(t_0 <= 2e-27)) {
		tmp = Math.cosh(x) * ((y / z) / x);
	} else {
		tmp = ((y / x) + (0.5 * (x * y))) / 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 <= -4e-68) or not (t_0 <= 2e-27):
		tmp = math.cosh(x) * ((y / z) / x)
	else:
		tmp = ((y / x) + (0.5 * (x * y))) / 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 <= -4e-68) || !(t_0 <= 2e-27))
		tmp = Float64(cosh(x) * Float64(Float64(y / z) / x));
	else
		tmp = Float64(Float64(Float64(y / x) + Float64(0.5 * Float64(x * y))) / 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 <= -4e-68) || ~((t_0 <= 2e-27)))
		tmp = cosh(x) * ((y / z) / x);
	else
		tmp = ((y / x) + (0.5 * (x * y))) / 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, -4e-68], N[Not[LessEqual[t$95$0, 2e-27]], $MachinePrecision]], N[(N[Cosh[x], $MachinePrecision] * N[(N[(y / z), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(y / x), $MachinePrecision] + N[(0.5 * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $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 -4 \cdot 10^{-68} \lor \neg \left(t_0 \leq 2 \cdot 10^{-27}\right):\\
\;\;\;\;\cosh x \cdot \frac{\frac{y}{z}}{x}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{y}{x} + 0.5 \cdot \left(x \cdot y\right)}{z}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original7.5
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 (/.f64 (*.f64 (cosh.f64 x) (/.f64 y x)) z) < -4.00000000000000027e-68 or 2.0000000000000001e-27 < (/.f64 (*.f64 (cosh.f64 x) (/.f64 y x)) z)

    1. Initial program 11.2

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

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

      [Start]11.2

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

      associate-*r/ [<=]11.2

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

      associate-/l/ [=>]10.8

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

      associate-/r* [=>]0.6

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

    if -4.00000000000000027e-68 < (/.f64 (*.f64 (cosh.f64 x) (/.f64 y x)) z) < 2.0000000000000001e-27

    1. Initial program 0.2

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

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

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

Alternatives

Alternative 1
Error1.5
Cost969
\[\begin{array}{l} \mathbf{if}\;y \leq -1 \cdot 10^{+35} \lor \neg \left(y \leq 2.4 \cdot 10^{+55}\right):\\ \;\;\;\;\frac{\frac{y}{z}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{x} + 0.5 \cdot \left(x \cdot y\right)}{z}\\ \end{array} \]
Alternative 2
Error1.8
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -3.1 \cdot 10^{+39} \lor \neg \left(y \leq 1.12 \cdot 10^{+57}\right):\\ \;\;\;\;\frac{y}{x \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{x}}{z}\\ \end{array} \]
Alternative 3
Error1.7
Cost585
\[\begin{array}{l} \mathbf{if}\;y \leq -1.5 \cdot 10^{-17} \lor \neg \left(y \leq 2.05 \cdot 10^{-81}\right):\\ \;\;\;\;\frac{\frac{y}{z}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{x}}{z}\\ \end{array} \]
Alternative 4
Error8.5
Cost320
\[\frac{y}{x \cdot z} \]

Error

Reproduce

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