
(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 8 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) (/ y (sinh y))))
double code(double x, double y) {
return cos(x) / (y / sinh(y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = cos(x) / (y / sinh(y))
end function
public static double code(double x, double y) {
return Math.cos(x) / (y / Math.sinh(y));
}
def code(x, y): return math.cos(x) / (y / math.sinh(y))
function code(x, y) return Float64(cos(x) / Float64(y / sinh(y))) end
function tmp = code(x, y) tmp = cos(x) / (y / sinh(y)); end
code[x_, y_] := N[(N[Cos[x], $MachinePrecision] / N[(y / N[Sinh[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\cos x}{\frac{y}{\sinh y}}
\end{array}
Initial program 100.0%
clear-num100.0%
un-div-inv100.0%
Applied egg-rr100.0%
(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 (+ 1.0 (* 0.16666666666666666 (* y y)))))
(if (or (<= y 2.6e+20) (not (<= y 1.65e+153)))
(* (cos x) t_0)
(* t_0 (+ 1.0 (* (* x x) -0.5))))))
double code(double x, double y) {
double t_0 = 1.0 + (0.16666666666666666 * (y * y));
double tmp;
if ((y <= 2.6e+20) || !(y <= 1.65e+153)) {
tmp = cos(x) * t_0;
} else {
tmp = t_0 * (1.0 + ((x * x) * -0.5));
}
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 = 1.0d0 + (0.16666666666666666d0 * (y * y))
if ((y <= 2.6d+20) .or. (.not. (y <= 1.65d+153))) then
tmp = cos(x) * t_0
else
tmp = t_0 * (1.0d0 + ((x * x) * (-0.5d0)))
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 1.0 + (0.16666666666666666 * (y * y));
double tmp;
if ((y <= 2.6e+20) || !(y <= 1.65e+153)) {
tmp = Math.cos(x) * t_0;
} else {
tmp = t_0 * (1.0 + ((x * x) * -0.5));
}
return tmp;
}
def code(x, y): t_0 = 1.0 + (0.16666666666666666 * (y * y)) tmp = 0 if (y <= 2.6e+20) or not (y <= 1.65e+153): tmp = math.cos(x) * t_0 else: tmp = t_0 * (1.0 + ((x * x) * -0.5)) return tmp
function code(x, y) t_0 = Float64(1.0 + Float64(0.16666666666666666 * Float64(y * y))) tmp = 0.0 if ((y <= 2.6e+20) || !(y <= 1.65e+153)) tmp = Float64(cos(x) * t_0); else tmp = Float64(t_0 * Float64(1.0 + Float64(Float64(x * x) * -0.5))); end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 + (0.16666666666666666 * (y * y)); tmp = 0.0; if ((y <= 2.6e+20) || ~((y <= 1.65e+153))) tmp = cos(x) * t_0; else tmp = t_0 * (1.0 + ((x * x) * -0.5)); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 + N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[y, 2.6e+20], N[Not[LessEqual[y, 1.65e+153]], $MachinePrecision]], N[(N[Cos[x], $MachinePrecision] * t$95$0), $MachinePrecision], N[(t$95$0 * N[(1.0 + N[(N[(x * x), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + 0.16666666666666666 \cdot \left(y \cdot y\right)\\
\mathbf{if}\;y \leq 2.6 \cdot 10^{+20} \lor \neg \left(y \leq 1.65 \cdot 10^{+153}\right):\\
\;\;\;\;\cos x \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \left(1 + \left(x \cdot x\right) \cdot -0.5\right)\\
\end{array}
\end{array}
if y < 2.6e20 or 1.64999999999999997e153 < y Initial program 100.0%
Taylor expanded in y around 0 82.3%
unpow282.3%
Applied egg-rr82.3%
if 2.6e20 < y < 1.64999999999999997e153Initial program 100.0%
Taylor expanded in y around 0 5.6%
unpow25.6%
Applied egg-rr5.6%
Taylor expanded in x around 0 28.9%
*-commutative28.9%
Simplified28.9%
unpow228.9%
Applied egg-rr28.9%
Final simplification76.8%
(FPCore (x y) :precision binary64 (if (<= y 4.1e+20) (cos x) (* (+ 1.0 (* 0.16666666666666666 (* y y))) (+ 1.0 (* (* x x) -0.5)))))
double code(double x, double y) {
double tmp;
if (y <= 4.1e+20) {
tmp = cos(x);
} else {
tmp = (1.0 + (0.16666666666666666 * (y * y))) * (1.0 + ((x * x) * -0.5));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 4.1d+20) then
tmp = cos(x)
else
tmp = (1.0d0 + (0.16666666666666666d0 * (y * y))) * (1.0d0 + ((x * x) * (-0.5d0)))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 4.1e+20) {
tmp = Math.cos(x);
} else {
tmp = (1.0 + (0.16666666666666666 * (y * y))) * (1.0 + ((x * x) * -0.5));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 4.1e+20: tmp = math.cos(x) else: tmp = (1.0 + (0.16666666666666666 * (y * y))) * (1.0 + ((x * x) * -0.5)) return tmp
function code(x, y) tmp = 0.0 if (y <= 4.1e+20) tmp = cos(x); else tmp = Float64(Float64(1.0 + Float64(0.16666666666666666 * Float64(y * y))) * Float64(1.0 + Float64(Float64(x * x) * -0.5))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 4.1e+20) tmp = cos(x); else tmp = (1.0 + (0.16666666666666666 * (y * y))) * (1.0 + ((x * x) * -0.5)); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 4.1e+20], N[Cos[x], $MachinePrecision], N[(N[(1.0 + N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(N[(x * x), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 4.1 \cdot 10^{+20}:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;\left(1 + 0.16666666666666666 \cdot \left(y \cdot y\right)\right) \cdot \left(1 + \left(x \cdot x\right) \cdot -0.5\right)\\
\end{array}
\end{array}
if y < 4.1e20Initial program 100.0%
Taylor expanded in y around 0 61.3%
if 4.1e20 < y Initial program 100.0%
Taylor expanded in y around 0 53.7%
unpow253.7%
Applied egg-rr53.7%
Taylor expanded in x around 0 53.8%
*-commutative53.8%
Simplified53.8%
unpow253.8%
Applied egg-rr53.8%
Final simplification59.7%
(FPCore (x y) :precision binary64 (let* ((t_0 (+ 1.0 (* 0.16666666666666666 (* y y))))) (if (<= y 2.9e+20) t_0 (* t_0 (+ 1.0 (* (* x x) -0.5))))))
double code(double x, double y) {
double t_0 = 1.0 + (0.16666666666666666 * (y * y));
double tmp;
if (y <= 2.9e+20) {
tmp = t_0;
} else {
tmp = t_0 * (1.0 + ((x * x) * -0.5));
}
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 = 1.0d0 + (0.16666666666666666d0 * (y * y))
if (y <= 2.9d+20) then
tmp = t_0
else
tmp = t_0 * (1.0d0 + ((x * x) * (-0.5d0)))
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 1.0 + (0.16666666666666666 * (y * y));
double tmp;
if (y <= 2.9e+20) {
tmp = t_0;
} else {
tmp = t_0 * (1.0 + ((x * x) * -0.5));
}
return tmp;
}
def code(x, y): t_0 = 1.0 + (0.16666666666666666 * (y * y)) tmp = 0 if y <= 2.9e+20: tmp = t_0 else: tmp = t_0 * (1.0 + ((x * x) * -0.5)) return tmp
function code(x, y) t_0 = Float64(1.0 + Float64(0.16666666666666666 * Float64(y * y))) tmp = 0.0 if (y <= 2.9e+20) tmp = t_0; else tmp = Float64(t_0 * Float64(1.0 + Float64(Float64(x * x) * -0.5))); end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 + (0.16666666666666666 * (y * y)); tmp = 0.0; if (y <= 2.9e+20) tmp = t_0; else tmp = t_0 * (1.0 + ((x * x) * -0.5)); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 + N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, 2.9e+20], t$95$0, N[(t$95$0 * N[(1.0 + N[(N[(x * x), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + 0.16666666666666666 \cdot \left(y \cdot y\right)\\
\mathbf{if}\;y \leq 2.9 \cdot 10^{+20}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \left(1 + \left(x \cdot x\right) \cdot -0.5\right)\\
\end{array}
\end{array}
if y < 2.9e20Initial program 100.0%
Taylor expanded in y around 0 79.9%
Taylor expanded in x around 0 50.9%
unpow279.9%
Applied egg-rr50.9%
if 2.9e20 < y Initial program 100.0%
Taylor expanded in y around 0 53.7%
unpow253.7%
Applied egg-rr53.7%
Taylor expanded in x around 0 53.8%
*-commutative53.8%
Simplified53.8%
unpow253.8%
Applied egg-rr53.8%
Final simplification51.5%
(FPCore (x y) :precision binary64 (if (<= x 1.45e+144) (+ 1.0 (* 0.16666666666666666 (* y y))) (+ 1.0 (* (* x x) -0.5))))
double code(double x, double y) {
double tmp;
if (x <= 1.45e+144) {
tmp = 1.0 + (0.16666666666666666 * (y * y));
} else {
tmp = 1.0 + ((x * x) * -0.5);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 1.45d+144) then
tmp = 1.0d0 + (0.16666666666666666d0 * (y * y))
else
tmp = 1.0d0 + ((x * x) * (-0.5d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 1.45e+144) {
tmp = 1.0 + (0.16666666666666666 * (y * y));
} else {
tmp = 1.0 + ((x * x) * -0.5);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 1.45e+144: tmp = 1.0 + (0.16666666666666666 * (y * y)) else: tmp = 1.0 + ((x * x) * -0.5) return tmp
function code(x, y) tmp = 0.0 if (x <= 1.45e+144) tmp = Float64(1.0 + Float64(0.16666666666666666 * Float64(y * y))); else tmp = Float64(1.0 + Float64(Float64(x * x) * -0.5)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 1.45e+144) tmp = 1.0 + (0.16666666666666666 * (y * y)); else tmp = 1.0 + ((x * x) * -0.5); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 1.45e+144], N[(1.0 + N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(N[(x * x), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.45 \cdot 10^{+144}:\\
\;\;\;\;1 + 0.16666666666666666 \cdot \left(y \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;1 + \left(x \cdot x\right) \cdot -0.5\\
\end{array}
\end{array}
if x < 1.44999999999999999e144Initial program 100.0%
Taylor expanded in y around 0 74.8%
Taylor expanded in x around 0 51.0%
unpow274.8%
Applied egg-rr51.0%
if 1.44999999999999999e144 < x Initial program 100.0%
Taylor expanded in y around 0 39.0%
Taylor expanded in x around 0 37.7%
*-commutative37.7%
Simplified37.7%
unpow237.7%
Applied egg-rr37.7%
(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 y around 0 74.5%
Taylor expanded in x around 0 47.7%
unpow274.5%
Applied egg-rr47.7%
(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 y around 0 74.5%
Taylor expanded in x around 0 47.7%
Taylor expanded in y around 0 29.2%
herbie shell --seed 2024118
(FPCore (x y)
:name "Linear.Quaternion:$csin from linear-1.19.1.3"
:precision binary64
(* (cos x) (/ (sinh y) y)))