
(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%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y 0.015) (cos x) (if (<= y 1.8e+154) (/ (sinh y) y) (/ (/ (* y (* (cos x) y)) y) y))))
double code(double x, double y) {
double tmp;
if (y <= 0.015) {
tmp = cos(x);
} else if (y <= 1.8e+154) {
tmp = sinh(y) / y;
} else {
tmp = ((y * (cos(x) * y)) / 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.015d0) then
tmp = cos(x)
else if (y <= 1.8d+154) then
tmp = sinh(y) / y
else
tmp = ((y * (cos(x) * y)) / y) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 0.015) {
tmp = Math.cos(x);
} else if (y <= 1.8e+154) {
tmp = Math.sinh(y) / y;
} else {
tmp = ((y * (Math.cos(x) * y)) / y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 0.015: tmp = math.cos(x) elif y <= 1.8e+154: tmp = math.sinh(y) / y else: tmp = ((y * (math.cos(x) * y)) / y) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 0.015) tmp = cos(x); elseif (y <= 1.8e+154) tmp = Float64(sinh(y) / y); else tmp = Float64(Float64(Float64(y * Float64(cos(x) * y)) / y) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 0.015) tmp = cos(x); elseif (y <= 1.8e+154) tmp = sinh(y) / y; else tmp = ((y * (cos(x) * y)) / y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 0.015], N[Cos[x], $MachinePrecision], If[LessEqual[y, 1.8e+154], N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision], N[(N[(N[(y * N[(N[Cos[x], $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] / y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.015:\\
\;\;\;\;\cos x\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{+154}:\\
\;\;\;\;\frac{\sinh y}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{y \cdot \left(\cos x \cdot y\right)}{y}}{y}\\
\end{array}
\end{array}
if y < 0.014999999999999999Initial program 100.0%
associate-*r/99.9%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in y around 0 81.6%
if 0.014999999999999999 < y < 1.8e154Initial program 100.0%
associate-*r/100.0%
associate-/l*100.0%
Simplified100.0%
associate-/r/100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 65.8%
Taylor expanded in y around inf 65.8%
*-commutative65.8%
associate-/r/65.8%
metadata-eval65.8%
associate-/l*65.8%
*-commutative65.8%
/-rgt-identity65.8%
associate-/r*65.8%
rec-exp65.8%
sinh-def65.8%
Simplified65.8%
if 1.8e154 < y Initial program 100.0%
associate-*r/100.0%
associate-/l*100.0%
Simplified100.0%
associate-/r/100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 3.1%
*-commutative3.1%
associate-*r/3.1%
Applied egg-rr3.1%
*-un-lft-identity3.1%
*-commutative3.1%
lft-mult-inverse3.1%
associate-*l*3.1%
div-inv3.1%
associate-*l/100.0%
Applied egg-rr100.0%
Final simplification82.1%
(FPCore (x y) :precision binary64 (if (<= y 0.00108) (cos x) (/ (sinh y) y)))
double code(double x, double y) {
double tmp;
if (y <= 0.00108) {
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.00108d0) 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.00108) {
tmp = Math.cos(x);
} else {
tmp = Math.sinh(y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 0.00108: tmp = math.cos(x) else: tmp = math.sinh(y) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 0.00108) 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.00108) tmp = cos(x); else tmp = sinh(y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 0.00108], N[Cos[x], $MachinePrecision], N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.00108:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;\frac{\sinh y}{y}\\
\end{array}
\end{array}
if y < 0.00108000000000000001Initial program 100.0%
associate-*r/99.9%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in y around 0 81.6%
if 0.00108000000000000001 < y Initial program 100.0%
associate-*r/100.0%
associate-/l*100.0%
Simplified100.0%
associate-/r/100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 68.8%
Taylor expanded in y around inf 68.8%
*-commutative68.8%
associate-/r/68.8%
metadata-eval68.8%
associate-/l*68.8%
*-commutative68.8%
/-rgt-identity68.8%
associate-/r*68.8%
rec-exp68.8%
sinh-def68.8%
Simplified68.8%
Final simplification77.8%
(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%
associate-*r/100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in y around 0 58.0%
Final simplification58.0%
(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%
associate-*r/100.0%
associate-/l*100.0%
Simplified100.0%
associate-/r/99.8%
Applied egg-rr99.8%
Taylor expanded in x around 0 60.0%
Taylor expanded in y around 0 30.9%
Final simplification30.9%
herbie shell --seed 2023322
(FPCore (x y)
:name "Linear.Quaternion:$csin from linear-1.19.1.3"
:precision binary64
(* (cos x) (/ (sinh y) y)))