
(FPCore (x y) :precision binary64 (* (cos x) (/ (sinh y) y)))
double code(double x, double y) {
return cos(x) * (sinh(y) / y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = cos(x) * (sinh(y) / y)
end function
public static double code(double x, double y) {
return Math.cos(x) * (Math.sinh(y) / y);
}
def code(x, y): return math.cos(x) * (math.sinh(y) / y)
function code(x, y) return Float64(cos(x) * Float64(sinh(y) / y)) end
function tmp = code(x, y) tmp = cos(x) * (sinh(y) / y); end
code[x_, y_] := N[(N[Cos[x], $MachinePrecision] * N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos x \cdot \frac{\sinh y}{y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* (cos x) (/ (sinh y) y)))
double code(double x, double y) {
return cos(x) * (sinh(y) / y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = cos(x) * (sinh(y) / y)
end function
public static double code(double x, double y) {
return Math.cos(x) * (Math.sinh(y) / y);
}
def code(x, y): return math.cos(x) * (math.sinh(y) / y)
function code(x, y) return Float64(cos(x) * Float64(sinh(y) / y)) end
function tmp = code(x, y) tmp = cos(x) * (sinh(y) / y); end
code[x_, y_] := N[(N[Cos[x], $MachinePrecision] * N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos x \cdot \frac{\sinh y}{y}
\end{array}
(FPCore (x y) :precision binary64 (/ (cos x) (/ y (sinh y))))
double code(double x, double y) {
return cos(x) / (y / sinh(y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = cos(x) / (y / sinh(y))
end function
public static double code(double x, double y) {
return Math.cos(x) / (y / Math.sinh(y));
}
def code(x, y): return math.cos(x) / (y / math.sinh(y))
function code(x, y) return Float64(cos(x) / Float64(y / sinh(y))) end
function tmp = code(x, y) tmp = cos(x) / (y / sinh(y)); end
code[x_, y_] := N[(N[Cos[x], $MachinePrecision] / N[(y / N[Sinh[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\cos x}{\frac{y}{\sinh y}}
\end{array}
Initial program 100.0%
clear-num100.0%
un-div-inv100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (* (cos x) (/ (sinh y) y)))
double code(double x, double y) {
return cos(x) * (sinh(y) / y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = cos(x) * (sinh(y) / y)
end function
public static double code(double x, double y) {
return Math.cos(x) * (Math.sinh(y) / y);
}
def code(x, y): return math.cos(x) * (math.sinh(y) / y)
function code(x, y) return Float64(cos(x) * Float64(sinh(y) / y)) end
function tmp = code(x, y) tmp = cos(x) * (sinh(y) / y); end
code[x_, y_] := N[(N[Cos[x], $MachinePrecision] * N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos x \cdot \frac{\sinh y}{y}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y 4.5e+29) (cos x) (* 0.5 (- 2.0 (pow x 2.0)))))
double code(double x, double y) {
double tmp;
if (y <= 4.5e+29) {
tmp = cos(x);
} else {
tmp = 0.5 * (2.0 - pow(x, 2.0));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 4.5d+29) then
tmp = cos(x)
else
tmp = 0.5d0 * (2.0d0 - (x ** 2.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 4.5e+29) {
tmp = Math.cos(x);
} else {
tmp = 0.5 * (2.0 - Math.pow(x, 2.0));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 4.5e+29: tmp = math.cos(x) else: tmp = 0.5 * (2.0 - math.pow(x, 2.0)) return tmp
function code(x, y) tmp = 0.0 if (y <= 4.5e+29) tmp = cos(x); else tmp = Float64(0.5 * Float64(2.0 - (x ^ 2.0))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 4.5e+29) tmp = cos(x); else tmp = 0.5 * (2.0 - (x ^ 2.0)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 4.5e+29], N[Cos[x], $MachinePrecision], N[(0.5 * N[(2.0 - N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.5 \cdot 10^{+29}:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 - {x}^{2}\right)\\
\end{array}
\end{array}
if y < 4.5000000000000002e29Initial program 100.0%
Taylor expanded in y around 0 62.7%
if 4.5000000000000002e29 < y Initial program 100.0%
Taylor expanded in x around inf 100.0%
*-commutative100.0%
associate-/l*100.0%
rec-exp100.0%
Simplified100.0%
Taylor expanded in y around 0 3.1%
Taylor expanded in x around 0 9.3%
mul-1-neg9.3%
unsub-neg9.3%
Simplified9.3%
Final simplification50.6%
(FPCore (x y) :precision binary64 (if (<= y 9e+29) (cos x) (* (pow x 2.0) (- 0.5))))
double code(double x, double y) {
double tmp;
if (y <= 9e+29) {
tmp = cos(x);
} else {
tmp = pow(x, 2.0) * -0.5;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 9d+29) then
tmp = cos(x)
else
tmp = (x ** 2.0d0) * -0.5d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 9e+29) {
tmp = Math.cos(x);
} else {
tmp = Math.pow(x, 2.0) * -0.5;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 9e+29: tmp = math.cos(x) else: tmp = math.pow(x, 2.0) * -0.5 return tmp
function code(x, y) tmp = 0.0 if (y <= 9e+29) tmp = cos(x); else tmp = Float64((x ^ 2.0) * Float64(-0.5)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 9e+29) tmp = cos(x); else tmp = (x ^ 2.0) * -0.5; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 9e+29], N[Cos[x], $MachinePrecision], N[(N[Power[x, 2.0], $MachinePrecision] * (-0.5)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 9 \cdot 10^{+29}:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;{x}^{2} \cdot \left(-0.5\right)\\
\end{array}
\end{array}
if y < 9.0000000000000005e29Initial program 100.0%
Taylor expanded in y around 0 62.7%
if 9.0000000000000005e29 < y Initial program 100.0%
Taylor expanded in x around inf 100.0%
*-commutative100.0%
associate-/l*100.0%
rec-exp100.0%
Simplified100.0%
Taylor expanded in y around 0 3.1%
Taylor expanded in x around 0 9.3%
mul-1-neg9.3%
unsub-neg9.3%
Simplified9.3%
Taylor expanded in x around inf 8.3%
neg-mul-18.3%
Simplified8.3%
Final simplification50.4%
(FPCore (x y) :precision binary64 (cos x))
double code(double x, double y) {
return cos(x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = cos(x)
end function
public static double code(double x, double y) {
return Math.cos(x);
}
def code(x, y): return math.cos(x)
function code(x, y) return cos(x) end
function tmp = code(x, y) tmp = cos(x); end
code[x_, y_] := N[Cos[x], $MachinePrecision]
\begin{array}{l}
\\
\cos x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 49.2%
Final simplification49.2%
(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 100.0%
Taylor expanded in x around inf 55.0%
*-commutative55.0%
associate-/l*55.0%
rec-exp55.0%
Simplified55.0%
Taylor expanded in y around 0 49.2%
Taylor expanded in x around 0 27.4%
Final simplification27.4%
herbie shell --seed 2024096
(FPCore (x y)
:name "Linear.Quaternion:$csin from linear-1.19.1.3"
:precision binary64
(* (cos x) (/ (sinh y) y)))