Linear.Quaternion:$ctan from linear-1.19.1.3

Percentage Accurate: 84.2% → 96.1%
Time: 7.4s
Alternatives: 8
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \frac{\cosh x \cdot \frac{y}{x}}{z} \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* (cosh x) (/ y x)) z))
double code(double x, double y, double z) {
	return (cosh(x) * (y / x)) / z;
}
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
public static double code(double x, double y, double z) {
	return (Math.cosh(x) * (y / x)) / z;
}
def code(x, y, z):
	return (math.cosh(x) * (y / x)) / z
function code(x, y, z)
	return Float64(Float64(cosh(x) * Float64(y / x)) / z)
end
function tmp = code(x, y, z)
	tmp = (cosh(x) * (y / x)) / z;
end
code[x_, y_, z_] := N[(N[(N[Cosh[x], $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}

\\
\frac{\cosh x \cdot \frac{y}{x}}{z}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 84.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\cosh x \cdot \frac{y}{x}}{z} \end{array} \]
(FPCore (x y z) :precision binary64 (/ (* (cosh x) (/ y x)) z))
double code(double x, double y, double z) {
	return (cosh(x) * (y / x)) / z;
}
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
public static double code(double x, double y, double z) {
	return (Math.cosh(x) * (y / x)) / z;
}
def code(x, y, z):
	return (math.cosh(x) * (y / x)) / z
function code(x, y, z)
	return Float64(Float64(cosh(x) * Float64(y / x)) / z)
end
function tmp = code(x, y, z)
	tmp = (cosh(x) * (y / x)) / z;
end
code[x_, y_, z_] := N[(N[(N[Cosh[x], $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}

\\
\frac{\cosh x \cdot \frac{y}{x}}{z}
\end{array}

Alternative 1: 96.1% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cosh x \cdot \frac{y}{x} \leq -5 \cdot 10^{-182}:\\ \;\;\;\;y \cdot \frac{\frac{\cosh x}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\cosh x \cdot y}{z}}{x}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= (* (cosh x) (/ y x)) -5e-182)
   (* y (/ (/ (cosh x) x) z))
   (/ (/ (* (cosh x) y) z) x)))
double code(double x, double y, double z) {
	double tmp;
	if ((cosh(x) * (y / x)) <= -5e-182) {
		tmp = y * ((cosh(x) / 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
    real(8) :: tmp
    if ((cosh(x) * (y / x)) <= (-5d-182)) then
        tmp = y * ((cosh(x) / 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) {
	double tmp;
	if ((Math.cosh(x) * (y / x)) <= -5e-182) {
		tmp = y * ((Math.cosh(x) / x) / z);
	} else {
		tmp = ((Math.cosh(x) * y) / z) / x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (math.cosh(x) * (y / x)) <= -5e-182:
		tmp = y * ((math.cosh(x) / x) / z)
	else:
		tmp = ((math.cosh(x) * y) / z) / x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (Float64(cosh(x) * Float64(y / x)) <= -5e-182)
		tmp = Float64(y * Float64(Float64(cosh(x) / x) / z));
	else
		tmp = Float64(Float64(Float64(cosh(x) * y) / z) / x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((cosh(x) * (y / x)) <= -5e-182)
		tmp = y * ((cosh(x) / x) / z);
	else
		tmp = ((cosh(x) * y) / z) / x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[N[(N[Cosh[x], $MachinePrecision] * N[(y / x), $MachinePrecision]), $MachinePrecision], -5e-182], N[(y * N[(N[(N[Cosh[x], $MachinePrecision] / x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Cosh[x], $MachinePrecision] * y), $MachinePrecision] / z), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\cosh x \cdot \frac{y}{x} \leq -5 \cdot 10^{-182}:\\
\;\;\;\;y \cdot \frac{\frac{\cosh x}{x}}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (cosh.f64 x) (/.f64 y x)) < -5.00000000000000024e-182

    1. Initial program 96.6%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Step-by-step derivation
      1. associate-*l/96.6%

        \[\leadsto \color{blue}{\frac{\cosh x}{z} \cdot \frac{y}{x}} \]
    3. Simplified96.6%

      \[\leadsto \color{blue}{\frac{\cosh x}{z} \cdot \frac{y}{x}} \]
    4. Step-by-step derivation
      1. associate-/r/91.1%

        \[\leadsto \color{blue}{\frac{\cosh x}{\frac{z}{\frac{y}{x}}}} \]
      2. associate-/l*88.4%

        \[\leadsto \frac{\cosh x}{\color{blue}{\frac{z \cdot x}{y}}} \]
      3. *-commutative88.4%

        \[\leadsto \frac{\cosh x}{\frac{\color{blue}{x \cdot z}}{y}} \]
      4. expm1-log1p-u53.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\cosh x}{\frac{x \cdot z}{y}}\right)\right)} \]
      5. expm1-udef37.6%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\cosh x}{\frac{x \cdot z}{y}}\right)} - 1} \]
      6. associate-/l*37.6%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{\cosh x \cdot y}{x \cdot z}}\right)} - 1 \]
      7. times-frac41.0%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{\cosh x}{x} \cdot \frac{y}{z}}\right)} - 1 \]
    5. Applied egg-rr41.0%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\cosh x}{x} \cdot \frac{y}{z}\right)} - 1} \]
    6. Step-by-step derivation
      1. expm1-def50.5%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\cosh x}{x} \cdot \frac{y}{z}\right)\right)} \]
      2. expm1-log1p92.2%

        \[\leadsto \color{blue}{\frac{\cosh x}{x} \cdot \frac{y}{z}} \]
      3. associate-*r/96.6%

        \[\leadsto \color{blue}{\frac{\frac{\cosh x}{x} \cdot y}{z}} \]
      4. *-commutative96.6%

        \[\leadsto \frac{\color{blue}{y \cdot \frac{\cosh x}{x}}}{z} \]
      5. associate-*r/98.2%

        \[\leadsto \color{blue}{y \cdot \frac{\frac{\cosh x}{x}}{z}} \]
    7. Simplified98.2%

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

    if -5.00000000000000024e-182 < (*.f64 (cosh.f64 x) (/.f64 y x))

    1. Initial program 71.7%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Step-by-step derivation
      1. associate-*l/71.7%

        \[\leadsto \color{blue}{\frac{\cosh x}{z} \cdot \frac{y}{x}} \]
    3. Simplified71.7%

      \[\leadsto \color{blue}{\frac{\cosh x}{z} \cdot \frac{y}{x}} \]
    4. Step-by-step derivation
      1. associate-*r/98.7%

        \[\leadsto \color{blue}{\frac{\frac{\cosh x}{z} \cdot y}{x}} \]
      2. associate-*l/98.7%

        \[\leadsto \frac{\color{blue}{\frac{\cosh x \cdot y}{z}}}{x} \]
    5. Applied egg-rr98.7%

      \[\leadsto \color{blue}{\frac{\frac{\cosh x \cdot y}{z}}{x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cosh x \cdot \frac{y}{x} \leq -5 \cdot 10^{-182}:\\ \;\;\;\;y \cdot \frac{\frac{\cosh x}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\cosh x \cdot y}{z}}{x}\\ \end{array} \]

Alternative 2: 95.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ y \cdot \frac{\frac{\cosh x}{x}}{z} \end{array} \]
(FPCore (x y z) :precision binary64 (* y (/ (/ (cosh x) x) z)))
double code(double x, double y, double z) {
	return y * ((cosh(x) / x) / z);
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = y * ((cosh(x) / x) / z)
end function
public static double code(double x, double y, double z) {
	return y * ((Math.cosh(x) / x) / z);
}
def code(x, y, z):
	return y * ((math.cosh(x) / x) / z)
function code(x, y, z)
	return Float64(y * Float64(Float64(cosh(x) / x) / z))
end
function tmp = code(x, y, z)
	tmp = y * ((cosh(x) / x) / z);
end
code[x_, y_, z_] := N[(y * N[(N[(N[Cosh[x], $MachinePrecision] / x), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
y \cdot \frac{\frac{\cosh x}{x}}{z}
\end{array}
Derivation
  1. Initial program 82.9%

    \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
  2. Step-by-step derivation
    1. associate-*l/82.9%

      \[\leadsto \color{blue}{\frac{\cosh x}{z} \cdot \frac{y}{x}} \]
  3. Simplified82.9%

    \[\leadsto \color{blue}{\frac{\cosh x}{z} \cdot \frac{y}{x}} \]
  4. Step-by-step derivation
    1. associate-/r/78.8%

      \[\leadsto \color{blue}{\frac{\cosh x}{\frac{z}{\frac{y}{x}}}} \]
    2. associate-/l*81.4%

      \[\leadsto \frac{\cosh x}{\color{blue}{\frac{z \cdot x}{y}}} \]
    3. *-commutative81.4%

      \[\leadsto \frac{\cosh x}{\frac{\color{blue}{x \cdot z}}{y}} \]
    4. expm1-log1p-u52.6%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\cosh x}{\frac{x \cdot z}{y}}\right)\right)} \]
    5. expm1-udef40.1%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\cosh x}{\frac{x \cdot z}{y}}\right)} - 1} \]
    6. associate-/l*45.2%

      \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{\cosh x \cdot y}{x \cdot z}}\right)} - 1 \]
    7. times-frac47.6%

      \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{\cosh x}{x} \cdot \frac{y}{z}}\right)} - 1 \]
  5. Applied egg-rr47.6%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\cosh x}{x} \cdot \frac{y}{z}\right)} - 1} \]
  6. Step-by-step derivation
    1. expm1-def56.6%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\cosh x}{x} \cdot \frac{y}{z}\right)\right)} \]
    2. expm1-log1p91.5%

      \[\leadsto \color{blue}{\frac{\cosh x}{x} \cdot \frac{y}{z}} \]
    3. associate-*r/96.5%

      \[\leadsto \color{blue}{\frac{\frac{\cosh x}{x} \cdot y}{z}} \]
    4. *-commutative96.5%

      \[\leadsto \frac{\color{blue}{y \cdot \frac{\cosh x}{x}}}{z} \]
    5. associate-*r/96.9%

      \[\leadsto \color{blue}{y \cdot \frac{\frac{\cosh x}{x}}{z}} \]
  7. Simplified96.9%

    \[\leadsto \color{blue}{y \cdot \frac{\frac{\cosh x}{x}}{z}} \]
  8. Final simplification96.9%

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

Alternative 3: 68.7% accurate, 7.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{y}{x \cdot z}\\ \mathbf{if}\;y \leq 10^{+29}:\\ \;\;\;\;0.5 \cdot \left(y \cdot \frac{x}{z}\right) + t_0\\ \mathbf{else}:\\ \;\;\;\;t_0 + 0.5 \cdot \frac{x \cdot y}{z}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (/ y (* x z))))
   (if (<= y 1e+29)
     (+ (* 0.5 (* y (/ x z))) t_0)
     (+ t_0 (* 0.5 (/ (* x y) z))))))
double code(double x, double y, double z) {
	double t_0 = y / (x * z);
	double tmp;
	if (y <= 1e+29) {
		tmp = (0.5 * (y * (x / z))) + t_0;
	} else {
		tmp = t_0 + (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
    real(8) :: t_0
    real(8) :: tmp
    t_0 = y / (x * z)
    if (y <= 1d+29) then
        tmp = (0.5d0 * (y * (x / z))) + t_0
    else
        tmp = t_0 + (0.5d0 * ((x * y) / z))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = y / (x * z);
	double tmp;
	if (y <= 1e+29) {
		tmp = (0.5 * (y * (x / z))) + t_0;
	} else {
		tmp = t_0 + (0.5 * ((x * y) / z));
	}
	return tmp;
}
def code(x, y, z):
	t_0 = y / (x * z)
	tmp = 0
	if y <= 1e+29:
		tmp = (0.5 * (y * (x / z))) + t_0
	else:
		tmp = t_0 + (0.5 * ((x * y) / z))
	return tmp
function code(x, y, z)
	t_0 = Float64(y / Float64(x * z))
	tmp = 0.0
	if (y <= 1e+29)
		tmp = Float64(Float64(0.5 * Float64(y * Float64(x / z))) + t_0);
	else
		tmp = Float64(t_0 + Float64(0.5 * Float64(Float64(x * y) / z)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = y / (x * z);
	tmp = 0.0;
	if (y <= 1e+29)
		tmp = (0.5 * (y * (x / z))) + t_0;
	else
		tmp = t_0 + (0.5 * ((x * y) / z));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(y / N[(x * z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, 1e+29], N[(N[(0.5 * N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision], N[(t$95$0 + N[(0.5 * N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{y}{x \cdot z}\\
\mathbf{if}\;y \leq 10^{+29}:\\
\;\;\;\;0.5 \cdot \left(y \cdot \frac{x}{z}\right) + t_0\\

\mathbf{else}:\\
\;\;\;\;t_0 + 0.5 \cdot \frac{x \cdot y}{z}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if y < 9.99999999999999914e28

    1. Initial program 79.7%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Step-by-step derivation
      1. associate-*l/79.7%

        \[\leadsto \color{blue}{\frac{\cosh x}{z} \cdot \frac{y}{x}} \]
    3. Simplified79.7%

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{x \cdot y}{z} + \frac{y}{x \cdot z}} \]
    5. Step-by-step derivation
      1. associate-/l*62.5%

        \[\leadsto 0.5 \cdot \color{blue}{\frac{x}{\frac{z}{y}}} + \frac{y}{x \cdot z} \]
      2. associate-/r/69.8%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\frac{x}{z} \cdot y\right)} + \frac{y}{x \cdot z} \]
    6. Applied egg-rr69.8%

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

    if 9.99999999999999914e28 < y

    1. Initial program 92.7%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Step-by-step derivation
      1. associate-*l/92.6%

        \[\leadsto \color{blue}{\frac{\cosh x}{z} \cdot \frac{y}{x}} \]
    3. Simplified92.6%

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

      \[\leadsto \color{blue}{0.5 \cdot \frac{x \cdot y}{z} + \frac{y}{x \cdot z}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification72.9%

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

Alternative 4: 66.0% accurate, 8.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 1.6 \cdot 10^{+132}:\\ \;\;\;\;\frac{\frac{y}{x} + 0.5 \cdot \left(x \cdot y\right)}{z}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(y \cdot \frac{x}{z}\right)\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (<= x 1.6e+132) (/ (+ (/ y x) (* 0.5 (* x y))) z) (* 0.5 (* y (/ x z)))))
double code(double x, double y, double z) {
	double tmp;
	if (x <= 1.6e+132) {
		tmp = ((y / x) + (0.5 * (x * y))) / z;
	} else {
		tmp = 0.5 * (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
    real(8) :: tmp
    if (x <= 1.6d+132) then
        tmp = ((y / x) + (0.5d0 * (x * y))) / z
    else
        tmp = 0.5d0 * (y * (x / z))
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if (x <= 1.6e+132) {
		tmp = ((y / x) + (0.5 * (x * y))) / z;
	} else {
		tmp = 0.5 * (y * (x / z));
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if x <= 1.6e+132:
		tmp = ((y / x) + (0.5 * (x * y))) / z
	else:
		tmp = 0.5 * (y * (x / z))
	return tmp
function code(x, y, z)
	tmp = 0.0
	if (x <= 1.6e+132)
		tmp = Float64(Float64(Float64(y / x) + Float64(0.5 * Float64(x * y))) / z);
	else
		tmp = Float64(0.5 * Float64(y * Float64(x / z)));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if (x <= 1.6e+132)
		tmp = ((y / x) + (0.5 * (x * y))) / z;
	else
		tmp = 0.5 * (y * (x / z));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[LessEqual[x, 1.6e+132], N[(N[(N[(y / x), $MachinePrecision] + N[(0.5 * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], N[(0.5 * N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.6 \cdot 10^{+132}:\\
\;\;\;\;\frac{\frac{y}{x} + 0.5 \cdot \left(x \cdot y\right)}{z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1.5999999999999999e132

    1. Initial program 86.3%

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

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

    if 1.5999999999999999e132 < x

    1. Initial program 59.4%

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

      \[\leadsto \frac{\color{blue}{0.5 \cdot \left(x \cdot y\right) + \frac{y}{x}}}{z} \]
    3. Taylor expanded in x around inf 55.3%

      \[\leadsto \color{blue}{0.5 \cdot \frac{x \cdot y}{z}} \]
    4. Step-by-step derivation
      1. associate-/l*49.4%

        \[\leadsto 0.5 \cdot \color{blue}{\frac{x}{\frac{z}{y}}} \]
    5. Simplified49.4%

      \[\leadsto \color{blue}{0.5 \cdot \frac{x}{\frac{z}{y}}} \]
    6. Step-by-step derivation
      1. associate-/r/76.1%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\frac{x}{z} \cdot y\right)} \]
    7. Applied egg-rr76.1%

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

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

Alternative 5: 66.6% accurate, 8.2× speedup?

\[\begin{array}{l} \\ 0.5 \cdot \left(y \cdot \frac{x}{z}\right) + \frac{y}{x \cdot z} \end{array} \]
(FPCore (x y z) :precision binary64 (+ (* 0.5 (* y (/ x z))) (/ y (* x z))))
double code(double x, double y, double z) {
	return (0.5 * (y * (x / z))) + (y / (x * z));
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = (0.5d0 * (y * (x / z))) + (y / (x * z))
end function
public static double code(double x, double y, double z) {
	return (0.5 * (y * (x / z))) + (y / (x * z));
}
def code(x, y, z):
	return (0.5 * (y * (x / z))) + (y / (x * z))
function code(x, y, z)
	return Float64(Float64(0.5 * Float64(y * Float64(x / z))) + Float64(y / Float64(x * z)))
end
function tmp = code(x, y, z)
	tmp = (0.5 * (y * (x / z))) + (y / (x * z));
end
code[x_, y_, z_] := N[(N[(0.5 * N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(y / N[(x * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
0.5 \cdot \left(y \cdot \frac{x}{z}\right) + \frac{y}{x \cdot z}
\end{array}
Derivation
  1. Initial program 82.9%

    \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
  2. Step-by-step derivation
    1. associate-*l/82.9%

      \[\leadsto \color{blue}{\frac{\cosh x}{z} \cdot \frac{y}{x}} \]
  3. Simplified82.9%

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

    \[\leadsto \color{blue}{0.5 \cdot \frac{x \cdot y}{z} + \frac{y}{x \cdot z}} \]
  5. Step-by-step derivation
    1. associate-/l*65.2%

      \[\leadsto 0.5 \cdot \color{blue}{\frac{x}{\frac{z}{y}}} + \frac{y}{x \cdot z} \]
    2. associate-/r/70.7%

      \[\leadsto 0.5 \cdot \color{blue}{\left(\frac{x}{z} \cdot y\right)} + \frac{y}{x \cdot z} \]
  6. Applied egg-rr70.7%

    \[\leadsto 0.5 \cdot \color{blue}{\left(\frac{x}{z} \cdot y\right)} + \frac{y}{x \cdot z} \]
  7. Final simplification70.7%

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

Alternative 6: 66.4% accurate, 9.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -1.42 \lor \neg \left(x \leq 1.4\right):\\ \;\;\;\;0.5 \cdot \left(y \cdot \frac{x}{z}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{x \cdot z}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= x -1.42) (not (<= x 1.4))) (* 0.5 (* y (/ x z))) (/ y (* x z))))
double code(double x, double y, double z) {
	double tmp;
	if ((x <= -1.42) || !(x <= 1.4)) {
		tmp = 0.5 * (y * (x / z));
	} else {
		tmp = 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
    real(8) :: tmp
    if ((x <= (-1.42d0)) .or. (.not. (x <= 1.4d0))) then
        tmp = 0.5d0 * (y * (x / z))
    else
        tmp = y / (x * z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((x <= -1.42) || !(x <= 1.4)) {
		tmp = 0.5 * (y * (x / z));
	} else {
		tmp = y / (x * z);
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (x <= -1.42) or not (x <= 1.4):
		tmp = 0.5 * (y * (x / z))
	else:
		tmp = y / (x * z)
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((x <= -1.42) || !(x <= 1.4))
		tmp = Float64(0.5 * Float64(y * Float64(x / z)));
	else
		tmp = Float64(y / Float64(x * z));
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((x <= -1.42) || ~((x <= 1.4)))
		tmp = 0.5 * (y * (x / z));
	else
		tmp = y / (x * z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.42], N[Not[LessEqual[x, 1.4]], $MachinePrecision]], N[(0.5 * N[(y * N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y / N[(x * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.42 \lor \neg \left(x \leq 1.4\right):\\
\;\;\;\;0.5 \cdot \left(y \cdot \frac{x}{z}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -1.4199999999999999 or 1.3999999999999999 < x

    1. Initial program 72.9%

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

      \[\leadsto \frac{\color{blue}{0.5 \cdot \left(x \cdot y\right) + \frac{y}{x}}}{z} \]
    3. Taylor expanded in x around inf 42.0%

      \[\leadsto \color{blue}{0.5 \cdot \frac{x \cdot y}{z}} \]
    4. Step-by-step derivation
      1. associate-/l*36.9%

        \[\leadsto 0.5 \cdot \color{blue}{\frac{x}{\frac{z}{y}}} \]
    5. Simplified36.9%

      \[\leadsto \color{blue}{0.5 \cdot \frac{x}{\frac{z}{y}}} \]
    6. Step-by-step derivation
      1. associate-/r/47.8%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\frac{x}{z} \cdot y\right)} \]
    7. Applied egg-rr47.8%

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

    if -1.4199999999999999 < x < 1.3999999999999999

    1. Initial program 93.1%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Step-by-step derivation
      1. associate-*l/93.1%

        \[\leadsto \color{blue}{\frac{\cosh x}{z} \cdot \frac{y}{x}} \]
    3. Simplified93.1%

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

      \[\leadsto \color{blue}{\frac{y}{x \cdot z}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification70.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.42 \lor \neg \left(x \leq 1.4\right):\\ \;\;\;\;0.5 \cdot \left(y \cdot \frac{x}{z}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{y}{x \cdot z}\\ \end{array} \]

Alternative 7: 57.4% accurate, 11.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq -5000 \lor \neg \left(z \leq 0.0005\right):\\ \;\;\;\;\frac{y}{x \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{z}}{x}\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (if (or (<= z -5000.0) (not (<= z 0.0005))) (/ y (* x z)) (/ (/ y z) x)))
double code(double x, double y, double z) {
	double tmp;
	if ((z <= -5000.0) || !(z <= 0.0005)) {
		tmp = y / (x * 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
    real(8) :: tmp
    if ((z <= (-5000.0d0)) .or. (.not. (z <= 0.0005d0))) then
        tmp = y / (x * z)
    else
        tmp = (y / z) / x
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double tmp;
	if ((z <= -5000.0) || !(z <= 0.0005)) {
		tmp = y / (x * z);
	} else {
		tmp = (y / z) / x;
	}
	return tmp;
}
def code(x, y, z):
	tmp = 0
	if (z <= -5000.0) or not (z <= 0.0005):
		tmp = y / (x * z)
	else:
		tmp = (y / z) / x
	return tmp
function code(x, y, z)
	tmp = 0.0
	if ((z <= -5000.0) || !(z <= 0.0005))
		tmp = Float64(y / Float64(x * z));
	else
		tmp = Float64(Float64(y / z) / x);
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	tmp = 0.0;
	if ((z <= -5000.0) || ~((z <= 0.0005)))
		tmp = y / (x * z);
	else
		tmp = (y / z) / x;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := If[Or[LessEqual[z, -5000.0], N[Not[LessEqual[z, 0.0005]], $MachinePrecision]], N[(y / N[(x * z), $MachinePrecision]), $MachinePrecision], N[(N[(y / z), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq -5000 \lor \neg \left(z \leq 0.0005\right):\\
\;\;\;\;\frac{y}{x \cdot z}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < -5e3 or 5.0000000000000001e-4 < z

    1. Initial program 81.4%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Step-by-step derivation
      1. associate-*l/81.4%

        \[\leadsto \color{blue}{\frac{\cosh x}{z} \cdot \frac{y}{x}} \]
    3. Simplified81.4%

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

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

    if -5e3 < z < 5.0000000000000001e-4

    1. Initial program 84.4%

      \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
    2. Step-by-step derivation
      1. associate-*l/84.4%

        \[\leadsto \color{blue}{\frac{\cosh x}{z} \cdot \frac{y}{x}} \]
    3. Simplified84.4%

      \[\leadsto \color{blue}{\frac{\cosh x}{z} \cdot \frac{y}{x}} \]
    4. Step-by-step derivation
      1. associate-*r/100.0%

        \[\leadsto \color{blue}{\frac{\frac{\cosh x}{z} \cdot y}{x}} \]
      2. associate-*l/100.0%

        \[\leadsto \frac{\color{blue}{\frac{\cosh x \cdot y}{z}}}{x} \]
    5. Applied egg-rr100.0%

      \[\leadsto \color{blue}{\frac{\frac{\cosh x \cdot y}{z}}{x}} \]
    6. Taylor expanded in x around 0 58.8%

      \[\leadsto \frac{\frac{\color{blue}{y}}{z}}{x} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification58.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -5000 \lor \neg \left(z \leq 0.0005\right):\\ \;\;\;\;\frac{y}{x \cdot z}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{y}{z}}{x}\\ \end{array} \]

Alternative 8: 50.1% accurate, 21.4× speedup?

\[\begin{array}{l} \\ \frac{y}{x \cdot z} \end{array} \]
(FPCore (x y z) :precision binary64 (/ y (* x z)))
double code(double x, double y, double z) {
	return y / (x * z);
}
real(8) function code(x, y, z)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    code = y / (x * z)
end function
public static double code(double x, double y, double z) {
	return y / (x * z);
}
def code(x, y, z):
	return y / (x * z)
function code(x, y, z)
	return Float64(y / Float64(x * z))
end
function tmp = code(x, y, z)
	tmp = y / (x * z);
end
code[x_, y_, z_] := N[(y / N[(x * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{y}{x \cdot z}
\end{array}
Derivation
  1. Initial program 82.9%

    \[\frac{\cosh x \cdot \frac{y}{x}}{z} \]
  2. Step-by-step derivation
    1. associate-*l/82.9%

      \[\leadsto \color{blue}{\frac{\cosh x}{z} \cdot \frac{y}{x}} \]
  3. Simplified82.9%

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

    \[\leadsto \color{blue}{\frac{y}{x \cdot z}} \]
  5. Final simplification49.5%

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

Developer target: 97.2% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\frac{y}{z}}{x} \cdot \cosh x\\ \mathbf{if}\;y < -4.618902267687042 \cdot 10^{-52}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;y < 1.038530535935153 \cdot 10^{-39}:\\ \;\;\;\;\frac{\frac{\cosh x \cdot y}{x}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \]
(FPCore (x y z)
 :precision binary64
 (let* ((t_0 (* (/ (/ y z) x) (cosh x))))
   (if (< y -4.618902267687042e-52)
     t_0
     (if (< y 1.038530535935153e-39) (/ (/ (* (cosh x) y) x) z) t_0))))
double code(double x, double y, double z) {
	double t_0 = ((y / z) / x) * cosh(x);
	double tmp;
	if (y < -4.618902267687042e-52) {
		tmp = t_0;
	} else if (y < 1.038530535935153e-39) {
		tmp = ((cosh(x) * y) / 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
    real(8) :: t_0
    real(8) :: tmp
    t_0 = ((y / z) / x) * cosh(x)
    if (y < (-4.618902267687042d-52)) then
        tmp = t_0
    else if (y < 1.038530535935153d-39) then
        tmp = ((cosh(x) * y) / x) / z
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x, double y, double z) {
	double t_0 = ((y / z) / x) * Math.cosh(x);
	double tmp;
	if (y < -4.618902267687042e-52) {
		tmp = t_0;
	} else if (y < 1.038530535935153e-39) {
		tmp = ((Math.cosh(x) * y) / x) / z;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x, y, z):
	t_0 = ((y / z) / x) * math.cosh(x)
	tmp = 0
	if y < -4.618902267687042e-52:
		tmp = t_0
	elif y < 1.038530535935153e-39:
		tmp = ((math.cosh(x) * y) / x) / z
	else:
		tmp = t_0
	return tmp
function code(x, y, z)
	t_0 = Float64(Float64(Float64(y / z) / x) * cosh(x))
	tmp = 0.0
	if (y < -4.618902267687042e-52)
		tmp = t_0;
	elseif (y < 1.038530535935153e-39)
		tmp = Float64(Float64(Float64(cosh(x) * y) / x) / z);
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x, y, z)
	t_0 = ((y / z) / x) * cosh(x);
	tmp = 0.0;
	if (y < -4.618902267687042e-52)
		tmp = t_0;
	elseif (y < 1.038530535935153e-39)
		tmp = ((cosh(x) * y) / x) / z;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(N[(y / z), $MachinePrecision] / x), $MachinePrecision] * N[Cosh[x], $MachinePrecision]), $MachinePrecision]}, If[Less[y, -4.618902267687042e-52], t$95$0, If[Less[y, 1.038530535935153e-39], N[(N[(N[(N[Cosh[x], $MachinePrecision] * y), $MachinePrecision] / x), $MachinePrecision] / z), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{\frac{y}{z}}{x} \cdot \cosh x\\
\mathbf{if}\;y < -4.618902267687042 \cdot 10^{-52}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;y < 1.038530535935153 \cdot 10^{-39}:\\
\;\;\;\;\frac{\frac{\cosh x \cdot y}{x}}{z}\\

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


\end{array}
\end{array}

Reproduce

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