
(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 9 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) (/ y (sinh y))))
double code(double x, double y) {
return sin(x) / (y / sinh(y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = sin(x) / (y / sinh(y))
end function
public static double code(double x, double y) {
return Math.sin(x) / (y / Math.sinh(y));
}
def code(x, y): return math.sin(x) / (y / math.sinh(y))
function code(x, y) return Float64(sin(x) / Float64(y / sinh(y))) end
function tmp = code(x, y) tmp = sin(x) / (y / sinh(y)); end
code[x_, y_] := N[(N[Sin[x], $MachinePrecision] / N[(y / N[Sinh[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sin x}{\frac{y}{\sinh y}}
\end{array}
Initial program 100.0%
add-log-exp77.9%
*-un-lft-identity77.9%
log-prod77.9%
metadata-eval77.9%
add-log-exp100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
associate-*r/88.8%
associate-*l/87.8%
associate-/r/100.0%
Simplified100.0%
(FPCore (x y) :precision binary64 (let* ((t_0 (/ (sinh y) y))) (if (<= t_0 2.0) (sin x) (* x t_0))))
double code(double x, double y) {
double t_0 = sinh(y) / y;
double tmp;
if (t_0 <= 2.0) {
tmp = sin(x);
} else {
tmp = x * t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = sinh(y) / y
if (t_0 <= 2.0d0) then
tmp = sin(x)
else
tmp = x * t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = Math.sinh(y) / y;
double tmp;
if (t_0 <= 2.0) {
tmp = Math.sin(x);
} else {
tmp = x * t_0;
}
return tmp;
}
def code(x, y): t_0 = math.sinh(y) / y tmp = 0 if t_0 <= 2.0: tmp = math.sin(x) else: tmp = x * t_0 return tmp
function code(x, y) t_0 = Float64(sinh(y) / y) tmp = 0.0 if (t_0 <= 2.0) tmp = sin(x); else tmp = Float64(x * t_0); end return tmp end
function tmp_2 = code(x, y) t_0 = sinh(y) / y; tmp = 0.0; if (t_0 <= 2.0) tmp = sin(x); else tmp = x * t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[t$95$0, 2.0], N[Sin[x], $MachinePrecision], N[(x * t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sinh y}{y}\\
\mathbf{if}\;t\_0 \leq 2:\\
\;\;\;\;\sin x\\
\mathbf{else}:\\
\;\;\;\;x \cdot t\_0\\
\end{array}
\end{array}
if (/.f64 (sinh.f64 y) y) < 2Initial program 100.0%
Taylor expanded in y around 0 99.2%
if 2 < (/.f64 (sinh.f64 y) y) Initial program 100.0%
Taylor expanded in x around 0 79.9%
(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%
(FPCore (x y)
:precision binary64
(if (<= y 8.5e+25)
(sin x)
(if (<= y 9.8e+182)
(* x (+ 1.0 (* (/ (* x (* x y)) y) -0.16666666666666666)))
(/ (* x y) y))))
double code(double x, double y) {
double tmp;
if (y <= 8.5e+25) {
tmp = sin(x);
} else if (y <= 9.8e+182) {
tmp = x * (1.0 + (((x * (x * y)) / y) * -0.16666666666666666));
} else {
tmp = (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 <= 8.5d+25) then
tmp = sin(x)
else if (y <= 9.8d+182) then
tmp = x * (1.0d0 + (((x * (x * y)) / y) * (-0.16666666666666666d0)))
else
tmp = (x * y) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 8.5e+25) {
tmp = Math.sin(x);
} else if (y <= 9.8e+182) {
tmp = x * (1.0 + (((x * (x * y)) / y) * -0.16666666666666666));
} else {
tmp = (x * y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 8.5e+25: tmp = math.sin(x) elif y <= 9.8e+182: tmp = x * (1.0 + (((x * (x * y)) / y) * -0.16666666666666666)) else: tmp = (x * y) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 8.5e+25) tmp = sin(x); elseif (y <= 9.8e+182) tmp = Float64(x * Float64(1.0 + Float64(Float64(Float64(x * Float64(x * y)) / y) * -0.16666666666666666))); else tmp = Float64(Float64(x * y) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 8.5e+25) tmp = sin(x); elseif (y <= 9.8e+182) tmp = x * (1.0 + (((x * (x * y)) / y) * -0.16666666666666666)); else tmp = (x * y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 8.5e+25], N[Sin[x], $MachinePrecision], If[LessEqual[y, 9.8e+182], N[(x * N[(1.0 + N[(N[(N[(x * N[(x * y), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] / y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8.5 \cdot 10^{+25}:\\
\;\;\;\;\sin x\\
\mathbf{elif}\;y \leq 9.8 \cdot 10^{+182}:\\
\;\;\;\;x \cdot \left(1 + \frac{x \cdot \left(x \cdot y\right)}{y} \cdot -0.16666666666666666\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot y}{y}\\
\end{array}
\end{array}
if y < 8.5000000000000007e25Initial program 100.0%
Taylor expanded in y around 0 58.4%
if 8.5000000000000007e25 < y < 9.7999999999999999e182Initial program 100.0%
Taylor expanded in y around 0 2.7%
Taylor expanded in x around 0 10.7%
*-commutative10.7%
Simplified10.7%
unpow210.7%
Applied egg-rr10.7%
*-un-lft-identity10.7%
associate-*r*10.7%
*-inverses10.7%
associate-/l*10.7%
associate-*l/10.7%
*-commutative10.7%
Applied egg-rr10.7%
if 9.7999999999999999e182 < 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%
Simplified100.0%
Taylor expanded in y around 0 2.6%
Taylor expanded in x around 0 19.3%
Final simplification47.8%
(FPCore (x y) :precision binary64 (if (<= y 3e+182) (* x (+ 1.0 (* (/ (* x (* x y)) y) -0.16666666666666666))) (/ (* x y) y)))
double code(double x, double y) {
double tmp;
if (y <= 3e+182) {
tmp = x * (1.0 + (((x * (x * y)) / y) * -0.16666666666666666));
} else {
tmp = (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 <= 3d+182) then
tmp = x * (1.0d0 + (((x * (x * y)) / y) * (-0.16666666666666666d0)))
else
tmp = (x * y) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 3e+182) {
tmp = x * (1.0 + (((x * (x * y)) / y) * -0.16666666666666666));
} else {
tmp = (x * y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 3e+182: tmp = x * (1.0 + (((x * (x * y)) / y) * -0.16666666666666666)) else: tmp = (x * y) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 3e+182) tmp = Float64(x * Float64(1.0 + Float64(Float64(Float64(x * Float64(x * y)) / y) * -0.16666666666666666))); else tmp = Float64(Float64(x * y) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 3e+182) tmp = x * (1.0 + (((x * (x * y)) / y) * -0.16666666666666666)); else tmp = (x * y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 3e+182], N[(x * N[(1.0 + N[(N[(N[(x * N[(x * y), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3 \cdot 10^{+182}:\\
\;\;\;\;x \cdot \left(1 + \frac{x \cdot \left(x \cdot y\right)}{y} \cdot -0.16666666666666666\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot y}{y}\\
\end{array}
\end{array}
if y < 3.0000000000000002e182Initial program 100.0%
Taylor expanded in y around 0 50.1%
Taylor expanded in x around 0 34.8%
*-commutative34.8%
Simplified34.8%
unpow234.8%
Applied egg-rr34.8%
*-un-lft-identity34.8%
associate-*r*34.8%
*-inverses34.8%
associate-/l*34.8%
associate-*l/35.6%
*-commutative35.6%
Applied egg-rr35.6%
if 3.0000000000000002e182 < 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%
Simplified100.0%
Taylor expanded in y around 0 2.6%
Taylor expanded in x around 0 19.3%
Final simplification33.8%
(FPCore (x y) :precision binary64 (if (<= y 3.9e+177) (* x (+ 1.0 (* -0.16666666666666666 (* x x)))) (/ (* x y) y)))
double code(double x, double y) {
double tmp;
if (y <= 3.9e+177) {
tmp = x * (1.0 + (-0.16666666666666666 * (x * x)));
} else {
tmp = (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 <= 3.9d+177) then
tmp = x * (1.0d0 + ((-0.16666666666666666d0) * (x * x)))
else
tmp = (x * y) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 3.9e+177) {
tmp = x * (1.0 + (-0.16666666666666666 * (x * x)));
} else {
tmp = (x * y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 3.9e+177: tmp = x * (1.0 + (-0.16666666666666666 * (x * x))) else: tmp = (x * y) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 3.9e+177) tmp = Float64(x * Float64(1.0 + Float64(-0.16666666666666666 * Float64(x * x)))); else tmp = Float64(Float64(x * y) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 3.9e+177) tmp = x * (1.0 + (-0.16666666666666666 * (x * x))); else tmp = (x * y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 3.9e+177], N[(x * N[(1.0 + N[(-0.16666666666666666 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.9 \cdot 10^{+177}:\\
\;\;\;\;x \cdot \left(1 + -0.16666666666666666 \cdot \left(x \cdot x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot y}{y}\\
\end{array}
\end{array}
if y < 3.8999999999999999e177Initial program 100.0%
Taylor expanded in y around 0 50.7%
Taylor expanded in x around 0 35.3%
*-commutative35.3%
Simplified35.3%
unpow235.3%
Applied egg-rr35.3%
if 3.8999999999999999e177 < 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%
Simplified100.0%
Taylor expanded in y around 0 2.6%
Taylor expanded in x around 0 20.8%
Final simplification33.5%
(FPCore (x y) :precision binary64 (if (<= x 2.5e-8) x (* (* x y) (/ 1.0 y))))
double code(double x, double y) {
double tmp;
if (x <= 2.5e-8) {
tmp = x;
} else {
tmp = (x * y) * (1.0 / y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 2.5d-8) then
tmp = x
else
tmp = (x * y) * (1.0d0 / y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 2.5e-8) {
tmp = x;
} else {
tmp = (x * y) * (1.0 / y);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 2.5e-8: tmp = x else: tmp = (x * y) * (1.0 / y) return tmp
function code(x, y) tmp = 0.0 if (x <= 2.5e-8) tmp = x; else tmp = Float64(Float64(x * y) * Float64(1.0 / y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 2.5e-8) tmp = x; else tmp = (x * y) * (1.0 / y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 2.5e-8], x, N[(N[(x * y), $MachinePrecision] * N[(1.0 / y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.5 \cdot 10^{-8}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot y\right) \cdot \frac{1}{y}\\
\end{array}
\end{array}
if x < 2.4999999999999999e-8Initial program 100.0%
Taylor expanded in x around 0 81.4%
Taylor expanded in y around 0 33.6%
if 2.4999999999999999e-8 < x Initial program 100.0%
add-log-exp99.5%
*-un-lft-identity99.5%
log-prod99.5%
metadata-eval99.5%
add-log-exp100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
associate-*r/100.0%
Simplified100.0%
Taylor expanded in y around 0 41.6%
Taylor expanded in x around 0 16.0%
clear-num16.0%
associate-/r/16.0%
*-commutative16.0%
Applied egg-rr16.0%
Final simplification29.1%
(FPCore (x y) :precision binary64 (if (<= x 2e-8) x (/ (* x y) y)))
double code(double x, double y) {
double tmp;
if (x <= 2e-8) {
tmp = x;
} else {
tmp = (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 (x <= 2d-8) then
tmp = x
else
tmp = (x * y) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 2e-8) {
tmp = x;
} else {
tmp = (x * y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 2e-8: tmp = x else: tmp = (x * y) / y return tmp
function code(x, y) tmp = 0.0 if (x <= 2e-8) tmp = x; else tmp = Float64(Float64(x * y) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 2e-8) tmp = x; else tmp = (x * y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 2e-8], x, N[(N[(x * y), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2 \cdot 10^{-8}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot y}{y}\\
\end{array}
\end{array}
if x < 2e-8Initial program 100.0%
Taylor expanded in x around 0 81.4%
Taylor expanded in y around 0 33.6%
if 2e-8 < x Initial program 100.0%
add-log-exp99.5%
*-un-lft-identity99.5%
log-prod99.5%
metadata-eval99.5%
add-log-exp100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
associate-*r/100.0%
Simplified100.0%
Taylor expanded in y around 0 41.6%
Taylor expanded in x around 0 16.0%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 69.3%
Taylor expanded in y around 0 25.8%
herbie shell --seed 2024143
(FPCore (x y)
:name "Linear.Quaternion:$ccos from linear-1.19.1.3"
:precision binary64
(* (sin x) (/ (sinh y) y)))