Linear.Quaternion:$csinh from linear-1.19.1.3

Percentage Accurate: 99.9% → 99.9%
Time: 11.3s
Alternatives: 6
Speedup: 1.0×

Specification

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

\\
\cosh x \cdot \frac{\sin y}{y}
\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 6 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: 99.9% accurate, 1.0× speedup?

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

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

Alternative 1: 99.9% accurate, 0.7× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ 0.5 \cdot \frac{\sin y \cdot \left(e^{x\_m} + \frac{1}{e^{x\_m}}\right)}{y} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m y)
 :precision binary64
 (* 0.5 (/ (* (sin y) (+ (exp x_m) (/ 1.0 (exp x_m)))) y)))
x_m = fabs(x);
double code(double x_m, double y) {
	return 0.5 * ((sin(y) * (exp(x_m) + (1.0 / exp(x_m)))) / y);
}
x_m = abs(x)
real(8) function code(x_m, y)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    code = 0.5d0 * ((sin(y) * (exp(x_m) + (1.0d0 / exp(x_m)))) / y)
end function
x_m = Math.abs(x);
public static double code(double x_m, double y) {
	return 0.5 * ((Math.sin(y) * (Math.exp(x_m) + (1.0 / Math.exp(x_m)))) / y);
}
x_m = math.fabs(x)
def code(x_m, y):
	return 0.5 * ((math.sin(y) * (math.exp(x_m) + (1.0 / math.exp(x_m)))) / y)
x_m = abs(x)
function code(x_m, y)
	return Float64(0.5 * Float64(Float64(sin(y) * Float64(exp(x_m) + Float64(1.0 / exp(x_m)))) / y))
end
x_m = abs(x);
function tmp = code(x_m, y)
	tmp = 0.5 * ((sin(y) * (exp(x_m) + (1.0 / exp(x_m)))) / y);
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_, y_] := N[(0.5 * N[(N[(N[Sin[y], $MachinePrecision] * N[(N[Exp[x$95$m], $MachinePrecision] + N[(1.0 / N[Exp[x$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|

\\
0.5 \cdot \frac{\sin y \cdot \left(e^{x\_m} + \frac{1}{e^{x\_m}}\right)}{y}
\end{array}
Derivation
  1. Initial program 99.9%

    \[\cosh x \cdot \frac{\sin y}{y} \]
  2. Add Preprocessing
  3. Taylor expanded in x around inf 99.9%

    \[\leadsto \color{blue}{0.5 \cdot \frac{\sin y \cdot \left(e^{x} + \frac{1}{e^{x}}\right)}{y}} \]
  4. Final simplification99.9%

    \[\leadsto 0.5 \cdot \frac{\sin y \cdot \left(e^{x} + \frac{1}{e^{x}}\right)}{y} \]
  5. Add Preprocessing

Alternative 2: 87.3% accurate, 1.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;\cosh x\_m \leq 1.000000001:\\ \;\;\;\;\frac{\sin y}{y}\\ \mathbf{else}:\\ \;\;\;\;\cosh x\_m\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m y)
 :precision binary64
 (if (<= (cosh x_m) 1.000000001) (/ (sin y) y) (cosh x_m)))
x_m = fabs(x);
double code(double x_m, double y) {
	double tmp;
	if (cosh(x_m) <= 1.000000001) {
		tmp = sin(y) / y;
	} else {
		tmp = cosh(x_m);
	}
	return tmp;
}
x_m = abs(x)
real(8) function code(x_m, y)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8) :: tmp
    if (cosh(x_m) <= 1.000000001d0) then
        tmp = sin(y) / y
    else
        tmp = cosh(x_m)
    end if
    code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m, double y) {
	double tmp;
	if (Math.cosh(x_m) <= 1.000000001) {
		tmp = Math.sin(y) / y;
	} else {
		tmp = Math.cosh(x_m);
	}
	return tmp;
}
x_m = math.fabs(x)
def code(x_m, y):
	tmp = 0
	if math.cosh(x_m) <= 1.000000001:
		tmp = math.sin(y) / y
	else:
		tmp = math.cosh(x_m)
	return tmp
x_m = abs(x)
function code(x_m, y)
	tmp = 0.0
	if (cosh(x_m) <= 1.000000001)
		tmp = Float64(sin(y) / y);
	else
		tmp = cosh(x_m);
	end
	return tmp
end
x_m = abs(x);
function tmp_2 = code(x_m, y)
	tmp = 0.0;
	if (cosh(x_m) <= 1.000000001)
		tmp = sin(y) / y;
	else
		tmp = cosh(x_m);
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_, y_] := If[LessEqual[N[Cosh[x$95$m], $MachinePrecision], 1.000000001], N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision], N[Cosh[x$95$m], $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;\cosh x\_m \leq 1.000000001:\\
\;\;\;\;\frac{\sin y}{y}\\

\mathbf{else}:\\
\;\;\;\;\cosh x\_m\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cosh.f64 x) < 1.0000000010000001

    1. Initial program 99.8%

      \[\cosh x \cdot \frac{\sin y}{y} \]
    2. Add Preprocessing
    3. Taylor expanded in x around 0 99.3%

      \[\leadsto \color{blue}{\frac{\sin y}{y}} \]

    if 1.0000000010000001 < (cosh.f64 x)

    1. Initial program 100.0%

      \[\cosh x \cdot \frac{\sin y}{y} \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 76.6%

      \[\leadsto \cosh x \cdot \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification89.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cosh x \leq 1.000000001:\\ \;\;\;\;\frac{\sin y}{y}\\ \mathbf{else}:\\ \;\;\;\;\cosh x\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \cosh x\_m \cdot \frac{\sin y}{y} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m y) :precision binary64 (* (cosh x_m) (/ (sin y) y)))
x_m = fabs(x);
double code(double x_m, double y) {
	return cosh(x_m) * (sin(y) / y);
}
x_m = abs(x)
real(8) function code(x_m, y)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    code = cosh(x_m) * (sin(y) / y)
end function
x_m = Math.abs(x);
public static double code(double x_m, double y) {
	return Math.cosh(x_m) * (Math.sin(y) / y);
}
x_m = math.fabs(x)
def code(x_m, y):
	return math.cosh(x_m) * (math.sin(y) / y)
x_m = abs(x)
function code(x_m, y)
	return Float64(cosh(x_m) * Float64(sin(y) / y))
end
x_m = abs(x);
function tmp = code(x_m, y)
	tmp = cosh(x_m) * (sin(y) / y);
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_, y_] := N[(N[Cosh[x$95$m], $MachinePrecision] * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|

\\
\cosh x\_m \cdot \frac{\sin y}{y}
\end{array}
Derivation
  1. Initial program 99.9%

    \[\cosh x \cdot \frac{\sin y}{y} \]
  2. Add Preprocessing
  3. Final simplification99.9%

    \[\leadsto \cosh x \cdot \frac{\sin y}{y} \]
  4. Add Preprocessing

Alternative 4: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \frac{\sin y}{\frac{y}{\cosh x\_m}} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m y) :precision binary64 (/ (sin y) (/ y (cosh x_m))))
x_m = fabs(x);
double code(double x_m, double y) {
	return sin(y) / (y / cosh(x_m));
}
x_m = abs(x)
real(8) function code(x_m, y)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    code = sin(y) / (y / cosh(x_m))
end function
x_m = Math.abs(x);
public static double code(double x_m, double y) {
	return Math.sin(y) / (y / Math.cosh(x_m));
}
x_m = math.fabs(x)
def code(x_m, y):
	return math.sin(y) / (y / math.cosh(x_m))
x_m = abs(x)
function code(x_m, y)
	return Float64(sin(y) / Float64(y / cosh(x_m)))
end
x_m = abs(x);
function tmp = code(x_m, y)
	tmp = sin(y) / (y / cosh(x_m));
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_, y_] := N[(N[Sin[y], $MachinePrecision] / N[(y / N[Cosh[x$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|

\\
\frac{\sin y}{\frac{y}{\cosh x\_m}}
\end{array}
Derivation
  1. Initial program 99.9%

    \[\cosh x \cdot \frac{\sin y}{y} \]
  2. Step-by-step derivation
    1. *-commutative99.9%

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

      \[\leadsto \color{blue}{\frac{\sin y \cdot \cosh x}{y}} \]
    3. associate-/l*99.8%

      \[\leadsto \color{blue}{\sin y \cdot \frac{\cosh x}{y}} \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{\sin y \cdot \frac{\cosh x}{y}} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. add-sqr-sqrt48.6%

      \[\leadsto \sin y \cdot \color{blue}{\left(\sqrt{\frac{\cosh x}{y}} \cdot \sqrt{\frac{\cosh x}{y}}\right)} \]
    2. pow248.6%

      \[\leadsto \sin y \cdot \color{blue}{{\left(\sqrt{\frac{\cosh x}{y}}\right)}^{2}} \]
  6. Applied egg-rr48.6%

    \[\leadsto \sin y \cdot \color{blue}{{\left(\sqrt{\frac{\cosh x}{y}}\right)}^{2}} \]
  7. Step-by-step derivation
    1. unpow248.6%

      \[\leadsto \sin y \cdot \color{blue}{\left(\sqrt{\frac{\cosh x}{y}} \cdot \sqrt{\frac{\cosh x}{y}}\right)} \]
    2. add-sqr-sqrt99.8%

      \[\leadsto \sin y \cdot \color{blue}{\frac{\cosh x}{y}} \]
    3. clear-num99.8%

      \[\leadsto \sin y \cdot \color{blue}{\frac{1}{\frac{y}{\cosh x}}} \]
    4. un-div-inv99.9%

      \[\leadsto \color{blue}{\frac{\sin y}{\frac{y}{\cosh x}}} \]
  8. Applied egg-rr99.9%

    \[\leadsto \color{blue}{\frac{\sin y}{\frac{y}{\cosh x}}} \]
  9. Final simplification99.9%

    \[\leadsto \frac{\sin y}{\frac{y}{\cosh x}} \]
  10. Add Preprocessing

Alternative 5: 63.2% accurate, 2.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \cosh x\_m \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m y) :precision binary64 (cosh x_m))
x_m = fabs(x);
double code(double x_m, double y) {
	return cosh(x_m);
}
x_m = abs(x)
real(8) function code(x_m, y)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    code = cosh(x_m)
end function
x_m = Math.abs(x);
public static double code(double x_m, double y) {
	return Math.cosh(x_m);
}
x_m = math.fabs(x)
def code(x_m, y):
	return math.cosh(x_m)
x_m = abs(x)
function code(x_m, y)
	return cosh(x_m)
end
x_m = abs(x);
function tmp = code(x_m, y)
	tmp = cosh(x_m);
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_, y_] := N[Cosh[x$95$m], $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|

\\
\cosh x\_m
\end{array}
Derivation
  1. Initial program 99.9%

    \[\cosh x \cdot \frac{\sin y}{y} \]
  2. Add Preprocessing
  3. Taylor expanded in y around 0 62.1%

    \[\leadsto \cosh x \cdot \color{blue}{1} \]
  4. Final simplification62.1%

    \[\leadsto \cosh x \]
  5. Add Preprocessing

Alternative 6: 26.4% accurate, 205.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ 1 \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m y) :precision binary64 1.0)
x_m = fabs(x);
double code(double x_m, double y) {
	return 1.0;
}
x_m = abs(x)
real(8) function code(x_m, y)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    code = 1.0d0
end function
x_m = Math.abs(x);
public static double code(double x_m, double y) {
	return 1.0;
}
x_m = math.fabs(x)
def code(x_m, y):
	return 1.0
x_m = abs(x)
function code(x_m, y)
	return 1.0
end
x_m = abs(x);
function tmp = code(x_m, y)
	tmp = 1.0;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_, y_] := 1.0
\begin{array}{l}
x_m = \left|x\right|

\\
1
\end{array}
Derivation
  1. Initial program 99.9%

    \[\cosh x \cdot \frac{\sin y}{y} \]
  2. Step-by-step derivation
    1. *-commutative99.9%

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

      \[\leadsto \color{blue}{\frac{\sin y \cdot \cosh x}{y}} \]
    3. associate-/l*99.8%

      \[\leadsto \color{blue}{\sin y \cdot \frac{\cosh x}{y}} \]
  3. Simplified99.8%

    \[\leadsto \color{blue}{\sin y \cdot \frac{\cosh x}{y}} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. add-sqr-sqrt48.6%

      \[\leadsto \sin y \cdot \color{blue}{\left(\sqrt{\frac{\cosh x}{y}} \cdot \sqrt{\frac{\cosh x}{y}}\right)} \]
    2. pow248.6%

      \[\leadsto \sin y \cdot \color{blue}{{\left(\sqrt{\frac{\cosh x}{y}}\right)}^{2}} \]
  6. Applied egg-rr48.6%

    \[\leadsto \sin y \cdot \color{blue}{{\left(\sqrt{\frac{\cosh x}{y}}\right)}^{2}} \]
  7. Taylor expanded in x around 0 25.6%

    \[\leadsto \sin y \cdot {\color{blue}{\left(\sqrt{\frac{1}{y}}\right)}}^{2} \]
  8. Taylor expanded in y around 0 29.4%

    \[\leadsto \color{blue}{1} \]
  9. Final simplification29.4%

    \[\leadsto 1 \]
  10. Add Preprocessing

Developer target: 99.9% accurate, 1.0× speedup?

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

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

Reproduce

?
herbie shell --seed 2024078 
(FPCore (x y)
  :name "Linear.Quaternion:$csinh from linear-1.19.1.3"
  :precision binary64

  :alt
  (/ (* (cosh x) (sin y)) y)

  (* (cosh x) (/ (sin y) y)))