
(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 7 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.45)
(cos x)
(if (<= y 1.35e+154)
(* (sinh y) (/ 1.0 y))
(/ (/ (* y y) (/ y (cos x))) y))))
double code(double x, double y) {
double tmp;
if (y <= 0.45) {
tmp = cos(x);
} else if (y <= 1.35e+154) {
tmp = sinh(y) * (1.0 / 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.45d0) then
tmp = cos(x)
else if (y <= 1.35d+154) then
tmp = sinh(y) * (1.0d0 / 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.45) {
tmp = Math.cos(x);
} else if (y <= 1.35e+154) {
tmp = Math.sinh(y) * (1.0 / y);
} else {
tmp = ((y * y) / (y / Math.cos(x))) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 0.45: tmp = math.cos(x) elif y <= 1.35e+154: tmp = math.sinh(y) * (1.0 / y) else: tmp = ((y * y) / (y / math.cos(x))) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 0.45) tmp = cos(x); elseif (y <= 1.35e+154) tmp = Float64(sinh(y) * Float64(1.0 / 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.45) tmp = cos(x); elseif (y <= 1.35e+154) tmp = sinh(y) * (1.0 / y); else tmp = ((y * y) / (y / cos(x))) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 0.45], N[Cos[x], $MachinePrecision], If[LessEqual[y, 1.35e+154], N[(N[Sinh[y], $MachinePrecision] * N[(1.0 / y), $MachinePrecision]), $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.45:\\
\;\;\;\;\cos x\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\sinh y \cdot \frac{1}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{y \cdot y}{\frac{y}{\cos x}}}{y}\\
\end{array}
\end{array}
if y < 0.450000000000000011Initial program 100.0%
Taylor expanded in y around 0 64.6%
if 0.450000000000000011 < y < 1.35000000000000003e154Initial program 100.0%
*-commutative100.0%
associate-*l/100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in x around 0 83.9%
if 1.35000000000000003e154 < y Initial program 100.0%
*-commutative100.0%
associate-*l/100.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 simplification71.5%
(FPCore (x y) :precision binary64 (if (<= y 0.45) (cos x) (/ (sinh y) y)))
double code(double x, double y) {
double tmp;
if (y <= 0.45) {
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.45d0) 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.45) {
tmp = Math.cos(x);
} else {
tmp = Math.sinh(y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 0.45: tmp = math.cos(x) else: tmp = math.sinh(y) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 0.45) 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.45) tmp = cos(x); else tmp = sinh(y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 0.45], N[Cos[x], $MachinePrecision], N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.45:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;\frac{\sinh y}{y}\\
\end{array}
\end{array}
if y < 0.450000000000000011Initial program 100.0%
Taylor expanded in y around 0 64.6%
if 0.450000000000000011 < y Initial program 100.0%
associate-*r/100.0%
associate-*l/100.0%
*-commutative100.0%
clear-num100.0%
un-div-inv100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 78.1%
(FPCore (x y)
:precision binary64
(if (<= y 4.2e+29)
(cos x)
(if (<= y 8.4e+147)
(/ (+ y (* -0.5 (* x (* x y)))) y)
(/ (/ (* y y) y) y))))
double code(double x, double y) {
double tmp;
if (y <= 4.2e+29) {
tmp = cos(x);
} else if (y <= 8.4e+147) {
tmp = (y + (-0.5 * (x * (x * y)))) / y;
} else {
tmp = ((y * 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 <= 4.2d+29) then
tmp = cos(x)
else if (y <= 8.4d+147) then
tmp = (y + ((-0.5d0) * (x * (x * y)))) / y
else
tmp = ((y * y) / y) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 4.2e+29) {
tmp = Math.cos(x);
} else if (y <= 8.4e+147) {
tmp = (y + (-0.5 * (x * (x * y)))) / y;
} else {
tmp = ((y * y) / y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 4.2e+29: tmp = math.cos(x) elif y <= 8.4e+147: tmp = (y + (-0.5 * (x * (x * y)))) / y else: tmp = ((y * y) / y) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 4.2e+29) tmp = cos(x); elseif (y <= 8.4e+147) tmp = Float64(Float64(y + Float64(-0.5 * Float64(x * Float64(x * y)))) / y); else tmp = Float64(Float64(Float64(y * y) / y) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 4.2e+29) tmp = cos(x); elseif (y <= 8.4e+147) tmp = (y + (-0.5 * (x * (x * y)))) / y; else tmp = ((y * y) / y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 4.2e+29], N[Cos[x], $MachinePrecision], If[LessEqual[y, 8.4e+147], N[(N[(y + N[(-0.5 * N[(x * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision], N[(N[(N[(y * y), $MachinePrecision] / y), $MachinePrecision] / y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.2 \cdot 10^{+29}:\\
\;\;\;\;\cos x\\
\mathbf{elif}\;y \leq 8.4 \cdot 10^{+147}:\\
\;\;\;\;\frac{y + -0.5 \cdot \left(x \cdot \left(x \cdot y\right)\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{y \cdot y}{y}}{y}\\
\end{array}
\end{array}
if y < 4.2000000000000003e29Initial program 100.0%
Taylor expanded in y around 0 62.7%
if 4.2000000000000003e29 < y < 8.40000000000000024e147Initial program 100.0%
*-commutative100.0%
associate-*l/100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in y around 0 3.1%
associate-*r/3.1%
Applied egg-rr3.1%
Taylor expanded in x around 0 10.3%
*-commutative10.3%
unpow210.3%
associate-*r*10.3%
Applied egg-rr10.3%
if 8.40000000000000024e147 < y Initial program 100.0%
*-commutative100.0%
associate-*l/100.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/97.2%
distribute-neg-frac297.2%
Applied egg-rr97.2%
Taylor expanded in x around 0 70.7%
mul-1-neg70.7%
Simplified70.7%
Final simplification58.9%
(FPCore (x y)
:precision binary64
(if (<= y 40000000000000.0)
1.0
(if (<= y 8.8e+147)
(/ (+ y (* -0.5 (* x (* x y)))) y)
(/ (/ (* y y) y) y))))
double code(double x, double y) {
double tmp;
if (y <= 40000000000000.0) {
tmp = 1.0;
} else if (y <= 8.8e+147) {
tmp = (y + (-0.5 * (x * (x * y)))) / y;
} else {
tmp = ((y * 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 <= 40000000000000.0d0) then
tmp = 1.0d0
else if (y <= 8.8d+147) then
tmp = (y + ((-0.5d0) * (x * (x * y)))) / y
else
tmp = ((y * y) / y) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 40000000000000.0) {
tmp = 1.0;
} else if (y <= 8.8e+147) {
tmp = (y + (-0.5 * (x * (x * y)))) / y;
} else {
tmp = ((y * y) / y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 40000000000000.0: tmp = 1.0 elif y <= 8.8e+147: tmp = (y + (-0.5 * (x * (x * y)))) / y else: tmp = ((y * y) / y) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 40000000000000.0) tmp = 1.0; elseif (y <= 8.8e+147) tmp = Float64(Float64(y + Float64(-0.5 * Float64(x * Float64(x * y)))) / y); else tmp = Float64(Float64(Float64(y * y) / y) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 40000000000000.0) tmp = 1.0; elseif (y <= 8.8e+147) tmp = (y + (-0.5 * (x * (x * y)))) / y; else tmp = ((y * y) / y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 40000000000000.0], 1.0, If[LessEqual[y, 8.8e+147], N[(N[(y + N[(-0.5 * N[(x * N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision], N[(N[(N[(y * y), $MachinePrecision] / y), $MachinePrecision] / y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 40000000000000:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 8.8 \cdot 10^{+147}:\\
\;\;\;\;\frac{y + -0.5 \cdot \left(x \cdot \left(x \cdot y\right)\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{y \cdot y}{y}}{y}\\
\end{array}
\end{array}
if y < 4e13Initial program 100.0%
*-commutative100.0%
associate-*l/99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around 0 63.9%
Taylor expanded in x around 0 35.3%
if 4e13 < y < 8.8000000000000007e147Initial program 100.0%
*-commutative100.0%
associate-*l/100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in y around 0 3.1%
associate-*r/3.1%
Applied egg-rr3.1%
Taylor expanded in x around 0 9.2%
*-commutative9.2%
unpow29.2%
associate-*r*9.2%
Applied egg-rr9.2%
if 8.8000000000000007e147 < y Initial program 100.0%
*-commutative100.0%
associate-*l/100.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/97.2%
distribute-neg-frac297.2%
Applied egg-rr97.2%
Taylor expanded in x around 0 70.7%
mul-1-neg70.7%
Simplified70.7%
Final simplification37.2%
(FPCore (x y) :precision binary64 (if (<= y 5e-15) 1.0 (/ (/ (* y y) y) y)))
double code(double x, double y) {
double tmp;
if (y <= 5e-15) {
tmp = 1.0;
} else {
tmp = ((y * 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 <= 5d-15) then
tmp = 1.0d0
else
tmp = ((y * y) / y) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 5e-15) {
tmp = 1.0;
} else {
tmp = ((y * y) / y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 5e-15: tmp = 1.0 else: tmp = ((y * y) / y) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 5e-15) tmp = 1.0; else tmp = Float64(Float64(Float64(y * y) / y) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 5e-15) tmp = 1.0; else tmp = ((y * y) / y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 5e-15], 1.0, N[(N[(N[(y * y), $MachinePrecision] / y), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 5 \cdot 10^{-15}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{y \cdot y}{y}}{y}\\
\end{array}
\end{array}
if y < 4.99999999999999999e-15Initial program 100.0%
*-commutative100.0%
associate-*l/99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around 0 64.6%
Taylor expanded in x around 0 36.0%
if 4.99999999999999999e-15 < y Initial program 100.0%
*-commutative100.0%
associate-*l/100.0%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in y around 0 6.6%
associate-*r/6.6%
Applied egg-rr6.6%
*-commutative6.6%
*-un-lft-identity6.6%
rgt-mult-inverse6.6%
un-div-inv6.6%
associate-/r/6.6%
frac-2neg6.6%
associate-*l/53.6%
distribute-neg-frac253.6%
Applied egg-rr53.6%
Taylor expanded in x around 0 37.8%
mul-1-neg37.8%
Simplified37.8%
Final simplification36.4%
(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%
*-commutative100.0%
associate-*l/99.9%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in y around 0 49.2%
Taylor expanded in x around 0 27.4%
herbie shell --seed 2024096
(FPCore (x y)
:name "Linear.Quaternion:$csin from linear-1.19.1.3"
:precision binary64
(* (cos x) (/ (sinh y) y)))