
(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 4 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 14500000000.0) (cos x) (/ (sinh y) y)))
double code(double x, double y) {
double tmp;
if (y <= 14500000000.0) {
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 <= 14500000000.0d0) 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 <= 14500000000.0) {
tmp = Math.cos(x);
} else {
tmp = Math.sinh(y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 14500000000.0: tmp = math.cos(x) else: tmp = math.sinh(y) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 14500000000.0) tmp = cos(x); else tmp = Float64(sinh(y) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 14500000000.0) tmp = cos(x); else tmp = sinh(y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 14500000000.0], N[Cos[x], $MachinePrecision], N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 14500000000:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;\frac{\sinh y}{y}\\
\end{array}
\end{array}
if y < 1.45e10Initial program 100.0%
Taylor expanded in y around 0 68.0%
if 1.45e10 < y Initial program 100.0%
Taylor expanded in x around 0 80.3%
associate-*r/80.3%
associate-/l*80.3%
*-rgt-identity80.3%
associate-/l*80.3%
metadata-eval80.3%
associate-/l*80.3%
associate-*l/80.3%
rec-exp80.3%
sinh-def80.3%
associate-/l/80.3%
Simplified80.3%
add-log-exp80.3%
*-un-lft-identity80.3%
log-prod80.3%
metadata-eval80.3%
div-inv80.3%
add-log-exp80.3%
clear-num80.3%
div-inv80.3%
clear-num80.3%
Applied egg-rr80.3%
+-lft-identity80.3%
associate-*r/80.3%
*-commutative80.3%
associate-*r/80.3%
associate-*r*80.3%
metadata-eval80.3%
*-lft-identity80.3%
Simplified80.3%
Final simplification71.2%
(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 51.3%
Final simplification51.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 100.0%
Taylor expanded in x around 0 42.3%
associate-*r/42.3%
associate-/l*42.3%
*-rgt-identity42.3%
associate-/l*42.3%
metadata-eval42.3%
associate-/l*42.3%
associate-*l/42.3%
rec-exp42.4%
sinh-def65.2%
associate-/l/65.2%
Simplified65.2%
Taylor expanded in y around 0 27.3%
Final simplification27.3%
herbie shell --seed 2023309
(FPCore (x y)
:name "Linear.Quaternion:$csin from linear-1.19.1.3"
:precision binary64
(* (cos x) (/ (sinh y) y)))