
(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:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(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}
Initial program 99.8%
(FPCore (x y) :precision binary64 (if (or (<= x 0.00048) (not (<= x 6.5e+252))) (* (sin y) (+ (/ 1.0 y) (* 0.5 (* x (/ x y))))) (cosh x)))
double code(double x, double y) {
double tmp;
if ((x <= 0.00048) || !(x <= 6.5e+252)) {
tmp = sin(y) * ((1.0 / y) + (0.5 * (x * (x / y))));
} else {
tmp = cosh(x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= 0.00048d0) .or. (.not. (x <= 6.5d+252))) then
tmp = sin(y) * ((1.0d0 / y) + (0.5d0 * (x * (x / y))))
else
tmp = cosh(x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= 0.00048) || !(x <= 6.5e+252)) {
tmp = Math.sin(y) * ((1.0 / y) + (0.5 * (x * (x / y))));
} else {
tmp = Math.cosh(x);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= 0.00048) or not (x <= 6.5e+252): tmp = math.sin(y) * ((1.0 / y) + (0.5 * (x * (x / y)))) else: tmp = math.cosh(x) return tmp
function code(x, y) tmp = 0.0 if ((x <= 0.00048) || !(x <= 6.5e+252)) tmp = Float64(sin(y) * Float64(Float64(1.0 / y) + Float64(0.5 * Float64(x * Float64(x / y))))); else tmp = cosh(x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= 0.00048) || ~((x <= 6.5e+252))) tmp = sin(y) * ((1.0 / y) + (0.5 * (x * (x / y)))); else tmp = cosh(x); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, 0.00048], N[Not[LessEqual[x, 6.5e+252]], $MachinePrecision]], N[(N[Sin[y], $MachinePrecision] * N[(N[(1.0 / y), $MachinePrecision] + N[(0.5 * N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Cosh[x], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.00048 \lor \neg \left(x \leq 6.5 \cdot 10^{+252}\right):\\
\;\;\;\;\sin y \cdot \left(\frac{1}{y} + 0.5 \cdot \left(x \cdot \frac{x}{y}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\cosh x\\
\end{array}
\end{array}
if x < 4.80000000000000012e-4 or 6.5e252 < x Initial program 99.8%
*-commutative99.8%
associate-*l/99.8%
associate-/l*99.7%
Simplified99.7%
Taylor expanded in x around 0 89.6%
unpow289.6%
associate-/l*85.8%
Applied egg-rr85.8%
if 4.80000000000000012e-4 < x < 6.5e252Initial program 100.0%
Taylor expanded in y around 0 85.7%
*-rgt-identity85.7%
cosh-def85.7%
clear-num85.7%
cosh-undef85.7%
Applied egg-rr85.7%
associate-/r*85.7%
metadata-eval85.7%
remove-double-div85.7%
Simplified85.7%
Final simplification85.8%
(FPCore (x y)
:precision binary64
(if (<= x 0.00048)
(* (sin y) (+ (/ 1.0 y) (* 0.5 (* x (/ x y)))))
(if (<= x 3.8e+127)
(cosh x)
(* (sin y) (+ (/ 1.0 y) (* 0.5 (/ (* x x) y)))))))
double code(double x, double y) {
double tmp;
if (x <= 0.00048) {
tmp = sin(y) * ((1.0 / y) + (0.5 * (x * (x / y))));
} else if (x <= 3.8e+127) {
tmp = cosh(x);
} else {
tmp = sin(y) * ((1.0 / y) + (0.5 * ((x * x) / y)));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 0.00048d0) then
tmp = sin(y) * ((1.0d0 / y) + (0.5d0 * (x * (x / y))))
else if (x <= 3.8d+127) then
tmp = cosh(x)
else
tmp = sin(y) * ((1.0d0 / y) + (0.5d0 * ((x * x) / y)))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 0.00048) {
tmp = Math.sin(y) * ((1.0 / y) + (0.5 * (x * (x / y))));
} else if (x <= 3.8e+127) {
tmp = Math.cosh(x);
} else {
tmp = Math.sin(y) * ((1.0 / y) + (0.5 * ((x * x) / y)));
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 0.00048: tmp = math.sin(y) * ((1.0 / y) + (0.5 * (x * (x / y)))) elif x <= 3.8e+127: tmp = math.cosh(x) else: tmp = math.sin(y) * ((1.0 / y) + (0.5 * ((x * x) / y))) return tmp
function code(x, y) tmp = 0.0 if (x <= 0.00048) tmp = Float64(sin(y) * Float64(Float64(1.0 / y) + Float64(0.5 * Float64(x * Float64(x / y))))); elseif (x <= 3.8e+127) tmp = cosh(x); else tmp = Float64(sin(y) * Float64(Float64(1.0 / y) + Float64(0.5 * Float64(Float64(x * x) / y)))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 0.00048) tmp = sin(y) * ((1.0 / y) + (0.5 * (x * (x / y)))); elseif (x <= 3.8e+127) tmp = cosh(x); else tmp = sin(y) * ((1.0 / y) + (0.5 * ((x * x) / y))); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 0.00048], N[(N[Sin[y], $MachinePrecision] * N[(N[(1.0 / y), $MachinePrecision] + N[(0.5 * N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 3.8e+127], N[Cosh[x], $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * N[(N[(1.0 / y), $MachinePrecision] + N[(0.5 * N[(N[(x * x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.00048:\\
\;\;\;\;\sin y \cdot \left(\frac{1}{y} + 0.5 \cdot \left(x \cdot \frac{x}{y}\right)\right)\\
\mathbf{elif}\;x \leq 3.8 \cdot 10^{+127}:\\
\;\;\;\;\cosh x\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot \left(\frac{1}{y} + 0.5 \cdot \frac{x \cdot x}{y}\right)\\
\end{array}
\end{array}
if x < 4.80000000000000012e-4Initial program 99.8%
*-commutative99.8%
associate-*l/99.8%
associate-/l*99.7%
Simplified99.7%
Taylor expanded in x around 0 89.0%
unpow289.0%
associate-/l*85.6%
Applied egg-rr85.6%
if 4.80000000000000012e-4 < x < 3.7999999999999998e127Initial program 100.0%
Taylor expanded in y around 0 79.3%
*-rgt-identity79.3%
cosh-def79.3%
clear-num79.3%
cosh-undef79.3%
Applied egg-rr79.3%
associate-/r*79.3%
metadata-eval79.3%
remove-double-div79.3%
Simplified79.3%
if 3.7999999999999998e127 < x Initial program 100.0%
*-commutative100.0%
associate-*l/100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in x around 0 97.4%
unpow297.4%
Applied egg-rr97.4%
Final simplification86.6%
(FPCore (x y) :precision binary64 (if (<= x 0.00025) (/ (sin y) y) (cosh x)))
double code(double x, double y) {
double tmp;
if (x <= 0.00025) {
tmp = sin(y) / y;
} else {
tmp = cosh(x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 0.00025d0) then
tmp = sin(y) / y
else
tmp = cosh(x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 0.00025) {
tmp = Math.sin(y) / y;
} else {
tmp = Math.cosh(x);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 0.00025: tmp = math.sin(y) / y else: tmp = math.cosh(x) return tmp
function code(x, y) tmp = 0.0 if (x <= 0.00025) tmp = Float64(sin(y) / y); else tmp = cosh(x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 0.00025) tmp = sin(y) / y; else tmp = cosh(x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 0.00025], N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision], N[Cosh[x], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.00025:\\
\;\;\;\;\frac{\sin y}{y}\\
\mathbf{else}:\\
\;\;\;\;\cosh x\\
\end{array}
\end{array}
if x < 2.5000000000000001e-4Initial program 99.8%
Taylor expanded in x around 0 67.6%
if 2.5000000000000001e-4 < x Initial program 100.0%
Taylor expanded in y around 0 84.8%
*-rgt-identity84.8%
cosh-def84.8%
clear-num84.8%
cosh-undef84.8%
Applied egg-rr84.8%
associate-/r*84.8%
metadata-eval84.8%
remove-double-div84.8%
Simplified84.8%
(FPCore (x y) :precision binary64 (cosh x))
double code(double x, double y) {
return cosh(x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = cosh(x)
end function
public static double code(double x, double y) {
return Math.cosh(x);
}
def code(x, y): return math.cosh(x)
function code(x, y) return cosh(x) end
function tmp = code(x, y) tmp = cosh(x); end
code[x_, y_] := N[Cosh[x], $MachinePrecision]
\begin{array}{l}
\\
\cosh x
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 64.3%
*-rgt-identity64.3%
cosh-def64.3%
clear-num64.3%
cosh-undef64.3%
Applied egg-rr64.3%
associate-/r*64.3%
metadata-eval64.3%
remove-double-div64.3%
Simplified64.3%
(FPCore (x y) :precision binary64 (if (<= y 3.3e+249) (* y (+ (/ 1.0 y) (* 0.5 (* x (/ x y))))) (* (/ 1.0 y) (* y (+ 1.0 (* -0.16666666666666666 (* y y)))))))
double code(double x, double y) {
double tmp;
if (y <= 3.3e+249) {
tmp = y * ((1.0 / y) + (0.5 * (x * (x / y))));
} else {
tmp = (1.0 / y) * (y * (1.0 + (-0.16666666666666666 * (y * y))));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 3.3d+249) then
tmp = y * ((1.0d0 / y) + (0.5d0 * (x * (x / y))))
else
tmp = (1.0d0 / y) * (y * (1.0d0 + ((-0.16666666666666666d0) * (y * y))))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 3.3e+249) {
tmp = y * ((1.0 / y) + (0.5 * (x * (x / y))));
} else {
tmp = (1.0 / y) * (y * (1.0 + (-0.16666666666666666 * (y * y))));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 3.3e+249: tmp = y * ((1.0 / y) + (0.5 * (x * (x / y)))) else: tmp = (1.0 / y) * (y * (1.0 + (-0.16666666666666666 * (y * y)))) return tmp
function code(x, y) tmp = 0.0 if (y <= 3.3e+249) tmp = Float64(y * Float64(Float64(1.0 / y) + Float64(0.5 * Float64(x * Float64(x / y))))); else tmp = Float64(Float64(1.0 / y) * Float64(y * Float64(1.0 + Float64(-0.16666666666666666 * Float64(y * y))))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 3.3e+249) tmp = y * ((1.0 / y) + (0.5 * (x * (x / y)))); else tmp = (1.0 / y) * (y * (1.0 + (-0.16666666666666666 * (y * y)))); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 3.3e+249], N[(y * N[(N[(1.0 / y), $MachinePrecision] + N[(0.5 * N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / y), $MachinePrecision] * N[(y * N[(1.0 + N[(-0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.3 \cdot 10^{+249}:\\
\;\;\;\;y \cdot \left(\frac{1}{y} + 0.5 \cdot \left(x \cdot \frac{x}{y}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{y} \cdot \left(y \cdot \left(1 + -0.16666666666666666 \cdot \left(y \cdot y\right)\right)\right)\\
\end{array}
\end{array}
if y < 3.30000000000000014e249Initial program 99.8%
*-commutative99.8%
associate-*l/99.9%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around 0 83.6%
unpow283.6%
Applied egg-rr83.6%
associate-/l*79.4%
*-commutative79.4%
Applied egg-rr79.4%
Taylor expanded in y around 0 54.4%
if 3.30000000000000014e249 < y Initial program 99.6%
*-commutative99.6%
associate-*l/99.6%
associate-/l*99.7%
Simplified99.7%
Taylor expanded in x around 0 50.6%
Taylor expanded in y around 0 34.1%
unpow234.1%
Applied egg-rr34.1%
Final simplification53.5%
(FPCore (x y) :precision binary64 (* y (+ (/ 1.0 y) (* 0.5 (* x (/ x y))))))
double code(double x, double y) {
return y * ((1.0 / y) + (0.5 * (x * (x / y))));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y * ((1.0d0 / y) + (0.5d0 * (x * (x / y))))
end function
public static double code(double x, double y) {
return y * ((1.0 / y) + (0.5 * (x * (x / y))));
}
def code(x, y): return y * ((1.0 / y) + (0.5 * (x * (x / y))))
function code(x, y) return Float64(y * Float64(Float64(1.0 / y) + Float64(0.5 * Float64(x * Float64(x / y))))) end
function tmp = code(x, y) tmp = y * ((1.0 / y) + (0.5 * (x * (x / y)))); end
code[x_, y_] := N[(y * N[(N[(1.0 / y), $MachinePrecision] + N[(0.5 * N[(x * N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(\frac{1}{y} + 0.5 \cdot \left(x \cdot \frac{x}{y}\right)\right)
\end{array}
Initial program 99.8%
*-commutative99.8%
associate-*l/99.8%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around 0 83.6%
unpow283.6%
Applied egg-rr83.6%
associate-/l*78.5%
*-commutative78.5%
Applied egg-rr78.5%
Taylor expanded in y around 0 52.3%
Final simplification52.3%
(FPCore (x y) :precision binary64 1.0)
double code(double x, double y) {
return 1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0
end function
public static double code(double x, double y) {
return 1.0;
}
def code(x, y): return 1.0
function code(x, y) return 1.0 end
function tmp = code(x, y) tmp = 1.0; end
code[x_, y_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 99.8%
*-commutative99.8%
associate-*l/99.8%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in x around 0 50.8%
Taylor expanded in y around 0 23.7%
(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}
herbie shell --seed 2024132
(FPCore (x y)
:name "Linear.Quaternion:$csinh from linear-1.19.1.3"
:precision binary64
:alt
(! :herbie-platform default (/ (* (cosh x) (sin y)) y))
(* (cosh x) (/ (sin y) y)))