
(FPCore (x y) :precision binary64 (* (sin x) (/ (sinh y) y)))
double code(double x, double y) {
return sin(x) * (sinh(y) / y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sin(x) * (sinh(y) / y)
end function
public static double code(double x, double y) {
return Math.sin(x) * (Math.sinh(y) / y);
}
def code(x, y): return math.sin(x) * (math.sinh(y) / y)
function code(x, y) return Float64(sin(x) * Float64(sinh(y) / y)) end
function tmp = code(x, y) tmp = sin(x) * (sinh(y) / y); end
code[x_, y_] := N[(N[Sin[x], $MachinePrecision] * N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin x \cdot \frac{\sinh y}{y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* (sin x) (/ (sinh y) y)))
double code(double x, double y) {
return sin(x) * (sinh(y) / y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sin(x) * (sinh(y) / y)
end function
public static double code(double x, double y) {
return Math.sin(x) * (Math.sinh(y) / y);
}
def code(x, y): return math.sin(x) * (math.sinh(y) / y)
function code(x, y) return Float64(sin(x) * Float64(sinh(y) / y)) end
function tmp = code(x, y) tmp = sin(x) * (sinh(y) / y); end
code[x_, y_] := N[(N[Sin[x], $MachinePrecision] * N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin x \cdot \frac{\sinh y}{y}
\end{array}
(FPCore (x y) :precision binary64 (* (sin x) (/ (sinh y) y)))
double code(double x, double y) {
return sin(x) * (sinh(y) / y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sin(x) * (sinh(y) / y)
end function
public static double code(double x, double y) {
return Math.sin(x) * (Math.sinh(y) / y);
}
def code(x, y): return math.sin(x) * (math.sinh(y) / y)
function code(x, y) return Float64(sin(x) * Float64(sinh(y) / y)) end
function tmp = code(x, y) tmp = sin(x) * (sinh(y) / y); end
code[x_, y_] := N[(N[Sin[x], $MachinePrecision] * N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin x \cdot \frac{\sinh y}{y}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y 2.1e-13) (sin x) (+ (sin x) (* 0.16666666666666666 (* x (* y y))))))
double code(double x, double y) {
double tmp;
if (y <= 2.1e-13) {
tmp = sin(x);
} else {
tmp = sin(x) + (0.16666666666666666 * (x * (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 <= 2.1d-13) then
tmp = sin(x)
else
tmp = sin(x) + (0.16666666666666666d0 * (x * (y * y)))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 2.1e-13) {
tmp = Math.sin(x);
} else {
tmp = Math.sin(x) + (0.16666666666666666 * (x * (y * y)));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.1e-13: tmp = math.sin(x) else: tmp = math.sin(x) + (0.16666666666666666 * (x * (y * y))) return tmp
function code(x, y) tmp = 0.0 if (y <= 2.1e-13) tmp = sin(x); else tmp = Float64(sin(x) + Float64(0.16666666666666666 * Float64(x * Float64(y * y)))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.1e-13) tmp = sin(x); else tmp = sin(x) + (0.16666666666666666 * (x * (y * y))); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.1e-13], N[Sin[x], $MachinePrecision], N[(N[Sin[x], $MachinePrecision] + N[(0.16666666666666666 * N[(x * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.1 \cdot 10^{-13}:\\
\;\;\;\;\sin x\\
\mathbf{else}:\\
\;\;\;\;\sin x + 0.16666666666666666 \cdot \left(x \cdot \left(y \cdot y\right)\right)\\
\end{array}
\end{array}
if y < 2.09999999999999989e-13Initial program 100.0%
Taylor expanded in y around 0 58.9%
if 2.09999999999999989e-13 < y Initial program 100.0%
Taylor expanded in y around 0 63.5%
+-commutative63.5%
associate-*r*63.5%
associate-*r*63.5%
distribute-rgt-out63.5%
unpow263.5%
Simplified63.5%
Taylor expanded in x around 0 51.2%
distribute-rgt-in51.2%
+-commutative51.2%
unpow251.2%
distribute-rgt-in51.2%
fma-udef51.2%
Simplified51.2%
Taylor expanded in y around 0 35.5%
unpow235.5%
*-commutative35.5%
associate-*l*35.5%
*-commutative35.5%
Simplified35.5%
Taylor expanded in x around 0 35.5%
unpow235.5%
Simplified35.5%
Final simplification52.7%
(FPCore (x y) :precision binary64 (sin x))
double code(double x, double y) {
return sin(x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sin(x)
end function
public static double code(double x, double y) {
return Math.sin(x);
}
def code(x, y): return math.sin(x)
function code(x, y) return sin(x) end
function tmp = code(x, y) tmp = sin(x); end
code[x_, y_] := N[Sin[x], $MachinePrecision]
\begin{array}{l}
\\
\sin x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 44.3%
Final simplification44.3%
herbie shell --seed 2023283
(FPCore (x y)
:name "Linear.Quaternion:$ccos from linear-1.19.1.3"
:precision binary64
(* (sin x) (/ (sinh y) y)))