
(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 (let* ((t_0 (/ (sinh y) y))) (if (<= t_0 1.0) (cos x) t_0)))
double code(double x, double y) {
double t_0 = sinh(y) / y;
double tmp;
if (t_0 <= 1.0) {
tmp = cos(x);
} else {
tmp = 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 <= 1.0d0) then
tmp = cos(x)
else
tmp = 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 <= 1.0) {
tmp = Math.cos(x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = math.sinh(y) / y tmp = 0 if t_0 <= 1.0: tmp = math.cos(x) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(sinh(y) / y) tmp = 0.0 if (t_0 <= 1.0) tmp = cos(x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = sinh(y) / y; tmp = 0.0; if (t_0 <= 1.0) tmp = cos(x); else tmp = 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, 1.0], N[Cos[x], $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sinh y}{y}\\
\mathbf{if}\;t\_0 \leq 1:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (/.f64 (sinh.f64 y) y) < 1Initial program 100.0%
Taylor expanded in y around 0 100.0%
if 1 < (/.f64 (sinh.f64 y) y) Initial program 100.0%
Taylor expanded in x around 0 72.6%
*-un-lft-identity72.6%
add-log-exp71.0%
*-un-lft-identity71.0%
log-prod71.0%
metadata-eval71.0%
add-log-exp72.6%
Applied egg-rr72.6%
+-lft-identity72.6%
Simplified72.6%
(FPCore (x y)
:precision binary64
(if (<= y 330.0)
(cos x)
(if (<= y 1.45e+138)
(/ (+ y (* y (* -0.5 (* x x)))) y)
(+ 1.0 (* 0.16666666666666666 (* y y))))))
double code(double x, double y) {
double tmp;
if (y <= 330.0) {
tmp = cos(x);
} else if (y <= 1.45e+138) {
tmp = (y + (y * (-0.5 * (x * x)))) / y;
} else {
tmp = 1.0 + (0.16666666666666666 * (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 <= 330.0d0) then
tmp = cos(x)
else if (y <= 1.45d+138) then
tmp = (y + (y * ((-0.5d0) * (x * x)))) / y
else
tmp = 1.0d0 + (0.16666666666666666d0 * (y * y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 330.0) {
tmp = Math.cos(x);
} else if (y <= 1.45e+138) {
tmp = (y + (y * (-0.5 * (x * x)))) / y;
} else {
tmp = 1.0 + (0.16666666666666666 * (y * y));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 330.0: tmp = math.cos(x) elif y <= 1.45e+138: tmp = (y + (y * (-0.5 * (x * x)))) / y else: tmp = 1.0 + (0.16666666666666666 * (y * y)) return tmp
function code(x, y) tmp = 0.0 if (y <= 330.0) tmp = cos(x); elseif (y <= 1.45e+138) tmp = Float64(Float64(y + Float64(y * Float64(-0.5 * Float64(x * x)))) / y); else tmp = Float64(1.0 + Float64(0.16666666666666666 * Float64(y * y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 330.0) tmp = cos(x); elseif (y <= 1.45e+138) tmp = (y + (y * (-0.5 * (x * x)))) / y; else tmp = 1.0 + (0.16666666666666666 * (y * y)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 330.0], N[Cos[x], $MachinePrecision], If[LessEqual[y, 1.45e+138], N[(N[(y + N[(y * N[(-0.5 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision], N[(1.0 + N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 330:\\
\;\;\;\;\cos x\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{+138}:\\
\;\;\;\;\frac{y + y \cdot \left(-0.5 \cdot \left(x \cdot x\right)\right)}{y}\\
\mathbf{else}:\\
\;\;\;\;1 + 0.16666666666666666 \cdot \left(y \cdot y\right)\\
\end{array}
\end{array}
if y < 330Initial program 100.0%
Taylor expanded in y around 0 73.5%
if 330 < y < 1.45000000000000005e138Initial program 100.0%
add-log-exp97.1%
*-un-lft-identity97.1%
log-prod97.1%
metadata-eval97.1%
add-log-exp100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
associate-*r/100.0%
Simplified100.0%
Taylor expanded in y around 0 3.2%
Taylor expanded in x around 0 8.6%
associate-*r*8.6%
Simplified8.6%
unpow28.6%
Applied egg-rr8.6%
if 1.45000000000000005e138 < y Initial program 100.0%
Taylor expanded in x around 0 71.0%
Taylor expanded in y around 0 62.2%
unpow262.2%
Applied egg-rr62.2%
Final simplification63.8%
(FPCore (x y) :precision binary64 (if (<= x 5.9e+50) (+ 1.0 (* 0.16666666666666666 (* y y))) (/ (+ y (* y (* -0.5 (* x x)))) y)))
double code(double x, double y) {
double tmp;
if (x <= 5.9e+50) {
tmp = 1.0 + (0.16666666666666666 * (y * y));
} else {
tmp = (y + (y * (-0.5 * (x * x)))) / y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 5.9d+50) then
tmp = 1.0d0 + (0.16666666666666666d0 * (y * y))
else
tmp = (y + (y * ((-0.5d0) * (x * x)))) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 5.9e+50) {
tmp = 1.0 + (0.16666666666666666 * (y * y));
} else {
tmp = (y + (y * (-0.5 * (x * x)))) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 5.9e+50: tmp = 1.0 + (0.16666666666666666 * (y * y)) else: tmp = (y + (y * (-0.5 * (x * x)))) / y return tmp
function code(x, y) tmp = 0.0 if (x <= 5.9e+50) tmp = Float64(1.0 + Float64(0.16666666666666666 * Float64(y * y))); else tmp = Float64(Float64(y + Float64(y * Float64(-0.5 * Float64(x * x)))) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 5.9e+50) tmp = 1.0 + (0.16666666666666666 * (y * y)); else tmp = (y + (y * (-0.5 * (x * x)))) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 5.9e+50], N[(1.0 + N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y + N[(y * N[(-0.5 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.9 \cdot 10^{+50}:\\
\;\;\;\;1 + 0.16666666666666666 \cdot \left(y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{y + y \cdot \left(-0.5 \cdot \left(x \cdot x\right)\right)}{y}\\
\end{array}
\end{array}
if x < 5.8999999999999998e50Initial program 100.0%
Taylor expanded in x around 0 73.7%
Taylor expanded in y around 0 54.6%
unpow254.6%
Applied egg-rr54.6%
if 5.8999999999999998e50 < x Initial program 100.0%
add-log-exp99.7%
*-un-lft-identity99.7%
log-prod99.7%
metadata-eval99.7%
add-log-exp100.0%
Applied egg-rr100.0%
+-lft-identity100.0%
associate-*r/99.9%
Simplified99.9%
Taylor expanded in y around 0 53.6%
Taylor expanded in x around 0 18.6%
associate-*r*18.6%
Simplified18.6%
unpow218.6%
Applied egg-rr18.6%
Final simplification48.1%
(FPCore (x y) :precision binary64 (if (<= x 8.6e+151) (+ 1.0 (* 0.16666666666666666 (* y y))) (+ 1.0 (* -0.5 (* x x)))))
double code(double x, double y) {
double tmp;
if (x <= 8.6e+151) {
tmp = 1.0 + (0.16666666666666666 * (y * y));
} else {
tmp = 1.0 + (-0.5 * (x * x));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 8.6d+151) then
tmp = 1.0d0 + (0.16666666666666666d0 * (y * y))
else
tmp = 1.0d0 + ((-0.5d0) * (x * x))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 8.6e+151) {
tmp = 1.0 + (0.16666666666666666 * (y * y));
} else {
tmp = 1.0 + (-0.5 * (x * x));
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 8.6e+151: tmp = 1.0 + (0.16666666666666666 * (y * y)) else: tmp = 1.0 + (-0.5 * (x * x)) return tmp
function code(x, y) tmp = 0.0 if (x <= 8.6e+151) tmp = Float64(1.0 + Float64(0.16666666666666666 * Float64(y * y))); else tmp = Float64(1.0 + Float64(-0.5 * Float64(x * x))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 8.6e+151) tmp = 1.0 + (0.16666666666666666 * (y * y)); else tmp = 1.0 + (-0.5 * (x * x)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 8.6e+151], N[(1.0 + N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(-0.5 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 8.6 \cdot 10^{+151}:\\
\;\;\;\;1 + 0.16666666666666666 \cdot \left(y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;1 + -0.5 \cdot \left(x \cdot x\right)\\
\end{array}
\end{array}
if x < 8.59999999999999965e151Initial program 100.0%
Taylor expanded in x around 0 70.3%
Taylor expanded in y around 0 50.5%
unpow250.5%
Applied egg-rr50.5%
if 8.59999999999999965e151 < x Initial program 100.0%
Taylor expanded in y around 0 53.5%
Taylor expanded in x around 0 24.7%
*-commutative24.7%
Simplified24.7%
unpow224.7%
Applied egg-rr24.7%
Final simplification47.9%
(FPCore (x y) :precision binary64 (+ 1.0 (* 0.16666666666666666 (* y y))))
double code(double x, double y) {
return 1.0 + (0.16666666666666666 * (y * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 + (0.16666666666666666d0 * (y * y))
end function
public static double code(double x, double y) {
return 1.0 + (0.16666666666666666 * (y * y));
}
def code(x, y): return 1.0 + (0.16666666666666666 * (y * y))
function code(x, y) return Float64(1.0 + Float64(0.16666666666666666 * Float64(y * y))) end
function tmp = code(x, y) tmp = 1.0 + (0.16666666666666666 * (y * y)); end
code[x_, y_] := N[(1.0 + N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + 0.16666666666666666 \cdot \left(y \cdot y\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 66.5%
Taylor expanded in y around 0 47.1%
unpow247.1%
Applied egg-rr47.1%
(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 66.5%
Taylor expanded in y around 0 34.7%
herbie shell --seed 2024191
(FPCore (x y)
:name "Linear.Quaternion:$csin from linear-1.19.1.3"
:precision binary64
(* (cos x) (/ (sinh y) y)))