
(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 6 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 2.0) (cos x) t_0)))
double code(double x, double y) {
double t_0 = sinh(y) / y;
double tmp;
if (t_0 <= 2.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 <= 2.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 <= 2.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 <= 2.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 <= 2.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 <= 2.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, 2.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 2:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (/.f64 (sinh.f64 y) y) < 2Initial program 100.0%
Taylor expanded in y around 0 98.9%
if 2 < (/.f64 (sinh.f64 y) y) Initial program 100.0%
Taylor expanded in x around 0 75.9%
*-un-lft-identity75.9%
add-log-exp75.9%
*-un-lft-identity75.9%
log-prod75.9%
metadata-eval75.9%
add-log-exp75.9%
Applied egg-rr75.9%
+-lft-identity75.9%
Simplified75.9%
(FPCore (x y) :precision binary64 (if (<= y 7600000.0) (cos x) (/ 1.0 (/ y (+ y (* -0.5 (* y (* x x))))))))
double code(double x, double y) {
double tmp;
if (y <= 7600000.0) {
tmp = cos(x);
} else {
tmp = 1.0 / (y / (y + (-0.5 * (y * (x * x)))));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 7600000.0d0) then
tmp = cos(x)
else
tmp = 1.0d0 / (y / (y + ((-0.5d0) * (y * (x * x)))))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 7600000.0) {
tmp = Math.cos(x);
} else {
tmp = 1.0 / (y / (y + (-0.5 * (y * (x * x)))));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 7600000.0: tmp = math.cos(x) else: tmp = 1.0 / (y / (y + (-0.5 * (y * (x * x))))) return tmp
function code(x, y) tmp = 0.0 if (y <= 7600000.0) tmp = cos(x); else tmp = Float64(1.0 / Float64(y / Float64(y + Float64(-0.5 * Float64(y * Float64(x * x)))))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 7600000.0) tmp = cos(x); else tmp = 1.0 / (y / (y + (-0.5 * (y * (x * x))))); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 7600000.0], N[Cos[x], $MachinePrecision], N[(1.0 / N[(y / N[(y + N[(-0.5 * N[(y * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 7600000:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{y}{y + -0.5 \cdot \left(y \cdot \left(x \cdot x\right)\right)}}\\
\end{array}
\end{array}
if y < 7.6e6Initial program 100.0%
Taylor expanded in y around 0 61.7%
if 7.6e6 < y Initial program 100.0%
associate-*r/100.0%
clear-num100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 3.1%
Taylor expanded in x around 0 21.7%
unpow221.7%
Applied egg-rr21.7%
Final simplification53.1%
(FPCore (x y) :precision binary64 (/ 1.0 (/ y (+ y (* -0.5 (* y (* x x)))))))
double code(double x, double y) {
return 1.0 / (y / (y + (-0.5 * (y * (x * x)))));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 / (y / (y + ((-0.5d0) * (y * (x * x)))))
end function
public static double code(double x, double y) {
return 1.0 / (y / (y + (-0.5 * (y * (x * x)))));
}
def code(x, y): return 1.0 / (y / (y + (-0.5 * (y * (x * x)))))
function code(x, y) return Float64(1.0 / Float64(y / Float64(y + Float64(-0.5 * Float64(y * Float64(x * x)))))) end
function tmp = code(x, y) tmp = 1.0 / (y / (y + (-0.5 * (y * (x * x))))); end
code[x_, y_] := N[(1.0 / N[(y / N[(y + N[(-0.5 * N[(y * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{y}{y + -0.5 \cdot \left(y \cdot \left(x \cdot x\right)\right)}}
\end{array}
Initial program 100.0%
associate-*r/99.9%
clear-num99.9%
Applied egg-rr99.9%
Taylor expanded in y around 0 49.1%
Taylor expanded in x around 0 38.9%
unpow238.9%
Applied egg-rr38.9%
Final simplification38.9%
(FPCore (x y) :precision binary64 (+ 1.0 (* -0.5 (* x x))))
double code(double x, double y) {
return 1.0 + (-0.5 * (x * x));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 + ((-0.5d0) * (x * x))
end function
public static double code(double x, double y) {
return 1.0 + (-0.5 * (x * x));
}
def code(x, y): return 1.0 + (-0.5 * (x * x))
function code(x, y) return Float64(1.0 + Float64(-0.5 * Float64(x * x))) end
function tmp = code(x, y) tmp = 1.0 + (-0.5 * (x * x)); end
code[x_, y_] := N[(1.0 + N[(-0.5 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + -0.5 \cdot \left(x \cdot x\right)
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 49.2%
Taylor expanded in x around 0 34.5%
*-commutative34.5%
Simplified34.5%
unpow238.9%
Applied egg-rr34.5%
Final simplification34.5%
(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 69.9%
Taylor expanded in y around 0 31.8%
herbie shell --seed 2024133
(FPCore (x y)
:name "Linear.Quaternion:$csin from linear-1.19.1.3"
:precision binary64
(* (cos x) (/ (sinh y) y)))