
(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 5 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) (/ (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%
(FPCore (x y) :precision binary64 (if (<= y 0.3) (cos x) (if (<= y 1.35e+154) (/ (sinh y) y) (/ (/ (* y y) (/ y (cos x))) y))))
double code(double x, double y) {
double tmp;
if (y <= 0.3) {
tmp = cos(x);
} else if (y <= 1.35e+154) {
tmp = sinh(y) / y;
} else {
tmp = ((y * y) / (y / cos(x))) / y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 0.3d0) then
tmp = cos(x)
else if (y <= 1.35d+154) then
tmp = sinh(y) / y
else
tmp = ((y * y) / (y / cos(x))) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 0.3) {
tmp = Math.cos(x);
} else if (y <= 1.35e+154) {
tmp = Math.sinh(y) / y;
} else {
tmp = ((y * y) / (y / Math.cos(x))) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 0.3: tmp = math.cos(x) elif y <= 1.35e+154: tmp = math.sinh(y) / y else: tmp = ((y * y) / (y / math.cos(x))) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 0.3) tmp = cos(x); elseif (y <= 1.35e+154) tmp = Float64(sinh(y) / y); else tmp = Float64(Float64(Float64(y * y) / Float64(y / cos(x))) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 0.3) tmp = cos(x); elseif (y <= 1.35e+154) tmp = sinh(y) / y; else tmp = ((y * y) / (y / cos(x))) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 0.3], N[Cos[x], $MachinePrecision], If[LessEqual[y, 1.35e+154], N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision], N[(N[(N[(y * y), $MachinePrecision] / N[(y / N[Cos[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.3:\\
\;\;\;\;\cos x\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\frac{\sinh y}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{y \cdot y}{\frac{y}{\cos x}}}{y}\\
\end{array}
\end{array}
if y < 0.299999999999999989Initial program 100.0%
Taylor expanded in y around 0 69.4%
if 0.299999999999999989 < y < 1.35000000000000003e154Initial program 100.0%
add-log-exp100.0%
*-un-lft-identity100.0%
log-prod100.0%
metadata-eval100.0%
add-log-exp100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
associate-*r/100.0%
*-commutative100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in x around 0 90.6%
associate-*r/90.6%
*-commutative90.6%
*-rgt-identity90.6%
metadata-eval90.6%
associate-/l*90.6%
associate-*l/90.6%
rec-exp90.6%
sinh-def90.6%
*-commutative90.6%
metadata-eval90.6%
associate-/l*90.6%
*-rgt-identity90.6%
*-commutative90.6%
associate-/l*90.6%
metadata-eval90.6%
*-rgt-identity90.6%
Simplified90.6%
if 1.35000000000000003e154 < y Initial program 100.0%
add-log-exp100.0%
*-un-lft-identity100.0%
log-prod100.0%
metadata-eval100.0%
add-log-exp100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
associate-*r/100.0%
*-commutative100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in y around 0 3.1%
associate-*r/3.1%
Applied egg-rr3.1%
*-commutative3.1%
*-un-lft-identity3.1%
rgt-mult-inverse3.1%
un-div-inv3.1%
associate-/r/3.1%
frac-2neg3.1%
associate-*l/100.0%
distribute-neg-frac2100.0%
Applied egg-rr100.0%
Final simplification76.9%
(FPCore (x y) :precision binary64 (if (<= y 0.3) (cos x) (/ (sinh y) y)))
double code(double x, double y) {
double tmp;
if (y <= 0.3) {
tmp = cos(x);
} else {
tmp = sinh(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 <= 0.3d0) then
tmp = cos(x)
else
tmp = sinh(y) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 0.3) {
tmp = Math.cos(x);
} else {
tmp = Math.sinh(y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 0.3: tmp = math.cos(x) else: tmp = math.sinh(y) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 0.3) tmp = cos(x); else tmp = Float64(sinh(y) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 0.3) tmp = cos(x); else tmp = sinh(y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 0.3], N[Cos[x], $MachinePrecision], N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.3:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;\frac{\sinh y}{y}\\
\end{array}
\end{array}
if y < 0.299999999999999989Initial program 100.0%
Taylor expanded in y around 0 69.4%
if 0.299999999999999989 < y Initial program 100.0%
add-log-exp100.0%
*-un-lft-identity100.0%
log-prod100.0%
metadata-eval100.0%
add-log-exp100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
associate-*r/100.0%
*-commutative100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in x around 0 87.7%
associate-*r/87.7%
*-commutative87.7%
*-rgt-identity87.7%
metadata-eval87.7%
associate-/l*87.7%
associate-*l/87.7%
rec-exp87.7%
sinh-def87.7%
*-commutative87.7%
metadata-eval87.7%
associate-/l*87.7%
*-rgt-identity87.7%
*-commutative87.7%
associate-/l*87.7%
metadata-eval87.7%
*-rgt-identity87.7%
Simplified87.7%
(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 50.5%
(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%
add-log-exp99.7%
*-un-lft-identity99.7%
log-prod99.7%
metadata-eval99.7%
add-log-exp100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
associate-*r/99.9%
*-commutative99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around 0 50.4%
Taylor expanded in x around 0 27.2%
herbie shell --seed 2024085
(FPCore (x y)
:name "Linear.Quaternion:$csin from linear-1.19.1.3"
:precision binary64
(* (cos x) (/ (sinh y) y)))