
(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) (/ (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 (or (<= y 0.012) (not (<= y 1.4e+154))) (* (cos x) (+ 1.0 (* 0.16666666666666666 (* y y)))) (/ (sinh y) y)))
double code(double x, double y) {
double tmp;
if ((y <= 0.012) || !(y <= 1.4e+154)) {
tmp = cos(x) * (1.0 + (0.16666666666666666 * (y * y)));
} 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.012d0) .or. (.not. (y <= 1.4d+154))) then
tmp = cos(x) * (1.0d0 + (0.16666666666666666d0 * (y * y)))
else
tmp = sinh(y) / y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= 0.012) || !(y <= 1.4e+154)) {
tmp = Math.cos(x) * (1.0 + (0.16666666666666666 * (y * y)));
} else {
tmp = Math.sinh(y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 0.012) or not (y <= 1.4e+154): tmp = math.cos(x) * (1.0 + (0.16666666666666666 * (y * y))) else: tmp = math.sinh(y) / y return tmp
function code(x, y) tmp = 0.0 if ((y <= 0.012) || !(y <= 1.4e+154)) tmp = Float64(cos(x) * Float64(1.0 + Float64(0.16666666666666666 * Float64(y * y)))); else tmp = Float64(sinh(y) / y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= 0.012) || ~((y <= 1.4e+154))) tmp = cos(x) * (1.0 + (0.16666666666666666 * (y * y))); else tmp = sinh(y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 0.012], N[Not[LessEqual[y, 1.4e+154]], $MachinePrecision]], N[(N[Cos[x], $MachinePrecision] * N[(1.0 + N[(0.16666666666666666 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.012 \lor \neg \left(y \leq 1.4 \cdot 10^{+154}\right):\\
\;\;\;\;\cos x \cdot \left(1 + 0.16666666666666666 \cdot \left(y \cdot y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\sinh y}{y}\\
\end{array}
\end{array}
if y < 0.012 or 1.4e154 < y Initial program 100.0%
Taylor expanded in y around 0 82.8%
unpow282.8%
Applied egg-rr82.8%
if 0.012 < y < 1.4e154Initial program 100.0%
Taylor expanded in x around 0 85.7%
*-un-lft-identity85.7%
clear-num85.7%
Applied egg-rr85.7%
associate-/r/85.7%
associate-*l/85.7%
*-lft-identity85.7%
Simplified85.7%
Final simplification83.2%
(FPCore (x y) :precision binary64 (if (<= y 0.00036) (cos x) (/ (sinh y) y)))
double code(double x, double y) {
double tmp;
if (y <= 0.00036) {
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.00036d0) 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.00036) {
tmp = Math.cos(x);
} else {
tmp = Math.sinh(y) / y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 0.00036: tmp = math.cos(x) else: tmp = math.sinh(y) / y return tmp
function code(x, y) tmp = 0.0 if (y <= 0.00036) 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.00036) tmp = cos(x); else tmp = sinh(y) / y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 0.00036], N[Cos[x], $MachinePrecision], N[(N[Sinh[y], $MachinePrecision] / y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.00036:\\
\;\;\;\;\cos x\\
\mathbf{else}:\\
\;\;\;\;\frac{\sinh y}{y}\\
\end{array}
\end{array}
if y < 3.60000000000000023e-4Initial program 100.0%
Taylor expanded in y around 0 60.9%
if 3.60000000000000023e-4 < y Initial program 100.0%
Taylor expanded in x around 0 82.9%
*-un-lft-identity82.9%
clear-num82.9%
Applied egg-rr82.9%
associate-/r/82.9%
associate-*l/82.9%
*-lft-identity82.9%
Simplified82.9%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ 1.0 (* 0.16666666666666666 (* y y)))))
(if (<= y 600.0)
(cos x)
(if (<= y 9.5e+174) (* (+ 1.0 (* (* x x) -0.5)) t_0) t_0))))
double code(double x, double y) {
double t_0 = 1.0 + (0.16666666666666666 * (y * y));
double tmp;
if (y <= 600.0) {
tmp = cos(x);
} else if (y <= 9.5e+174) {
tmp = (1.0 + ((x * x) * -0.5)) * t_0;
} 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 = 1.0d0 + (0.16666666666666666d0 * (y * y))
if (y <= 600.0d0) then
tmp = cos(x)
else if (y <= 9.5d+174) then
tmp = (1.0d0 + ((x * x) * (-0.5d0))) * t_0
else
tmp = t_0
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 <= 600.0) {
tmp = Math.cos(x);
} else if (y <= 9.5e+174) {
tmp = (1.0 + ((x * x) * -0.5)) * t_0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 + (0.16666666666666666 * (y * y)) tmp = 0 if y <= 600.0: tmp = math.cos(x) elif y <= 9.5e+174: tmp = (1.0 + ((x * x) * -0.5)) * t_0 else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 + Float64(0.16666666666666666 * Float64(y * y))) tmp = 0.0 if (y <= 600.0) tmp = cos(x); elseif (y <= 9.5e+174) tmp = Float64(Float64(1.0 + Float64(Float64(x * x) * -0.5)) * t_0); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 + (0.16666666666666666 * (y * y)); tmp = 0.0; if (y <= 600.0) tmp = cos(x); elseif (y <= 9.5e+174) tmp = (1.0 + ((x * x) * -0.5)) * t_0; else tmp = t_0; 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, 600.0], N[Cos[x], $MachinePrecision], If[LessEqual[y, 9.5e+174], N[(N[(1.0 + N[(N[(x * x), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + 0.16666666666666666 \cdot \left(y \cdot y\right)\\
\mathbf{if}\;y \leq 600:\\
\;\;\;\;\cos x\\
\mathbf{elif}\;y \leq 9.5 \cdot 10^{+174}:\\
\;\;\;\;\left(1 + \left(x \cdot x\right) \cdot -0.5\right) \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < 600Initial program 100.0%
Taylor expanded in y around 0 60.9%
if 600 < y < 9.4999999999999992e174Initial program 100.0%
Taylor expanded in y around 0 12.3%
unpow212.3%
Applied egg-rr12.3%
Taylor expanded in x around 0 19.1%
*-commutative19.1%
Simplified19.1%
unpow219.1%
Applied egg-rr19.1%
if 9.4999999999999992e174 < y Initial program 100.0%
Taylor expanded in y around 0 100.0%
unpow2100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 81.3%
Final simplification57.3%
(FPCore (x y) :precision binary64 (let* ((t_0 (+ 1.0 (* 0.16666666666666666 (* y y))))) (if (<= x 7.5e+123) t_0 (* (+ 1.0 (* (* x x) -0.5)) t_0))))
double code(double x, double y) {
double t_0 = 1.0 + (0.16666666666666666 * (y * y));
double tmp;
if (x <= 7.5e+123) {
tmp = t_0;
} else {
tmp = (1.0 + ((x * x) * -0.5)) * 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 = 1.0d0 + (0.16666666666666666d0 * (y * y))
if (x <= 7.5d+123) then
tmp = t_0
else
tmp = (1.0d0 + ((x * x) * (-0.5d0))) * t_0
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 (x <= 7.5e+123) {
tmp = t_0;
} else {
tmp = (1.0 + ((x * x) * -0.5)) * t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 + (0.16666666666666666 * (y * y)) tmp = 0 if x <= 7.5e+123: tmp = t_0 else: tmp = (1.0 + ((x * x) * -0.5)) * t_0 return tmp
function code(x, y) t_0 = Float64(1.0 + Float64(0.16666666666666666 * Float64(y * y))) tmp = 0.0 if (x <= 7.5e+123) tmp = t_0; else tmp = Float64(Float64(1.0 + Float64(Float64(x * x) * -0.5)) * t_0); end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 + (0.16666666666666666 * (y * y)); tmp = 0.0; if (x <= 7.5e+123) tmp = t_0; else tmp = (1.0 + ((x * x) * -0.5)) * t_0; 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[x, 7.5e+123], t$95$0, N[(N[(1.0 + N[(N[(x * x), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + 0.16666666666666666 \cdot \left(y \cdot y\right)\\
\mathbf{if}\;x \leq 7.5 \cdot 10^{+123}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\left(1 + \left(x \cdot x\right) \cdot -0.5\right) \cdot t\_0\\
\end{array}
\end{array}
if x < 7.4999999999999999e123Initial program 100.0%
Taylor expanded in y around 0 72.8%
unpow272.8%
Applied egg-rr72.8%
Taylor expanded in x around 0 53.6%
if 7.4999999999999999e123 < x Initial program 100.0%
Taylor expanded in y around 0 68.3%
unpow268.3%
Applied egg-rr68.3%
Taylor expanded in x around 0 39.8%
*-commutative39.8%
Simplified39.8%
unpow239.8%
Applied egg-rr39.8%
Final simplification51.6%
(FPCore (x y) :precision binary64 (if (<= x 6.6e+154) (+ 1.0 (* 0.16666666666666666 (* y y))) (+ 1.0 (* (* x x) -0.5))))
double code(double x, double y) {
double tmp;
if (x <= 6.6e+154) {
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 <= 6.6d+154) 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 <= 6.6e+154) {
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 <= 6.6e+154: 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 <= 6.6e+154) 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 <= 6.6e+154) 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, 6.6e+154], 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 6.6 \cdot 10^{+154}:\\
\;\;\;\;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 < 6.6e154Initial program 100.0%
Taylor expanded in y around 0 71.9%
unpow271.9%
Applied egg-rr71.9%
Taylor expanded in x around 0 52.1%
if 6.6e154 < x Initial program 100.0%
Taylor expanded in y around 0 36.5%
Taylor expanded in x around 0 42.2%
*-commutative42.2%
Simplified42.2%
unpow242.2%
Applied egg-rr42.2%
Final simplification51.0%
(FPCore (x y) :precision binary64 (+ 1.0 (* (* x x) -0.5)))
double code(double x, double y) {
return 1.0 + ((x * x) * -0.5);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 1.0d0 + ((x * x) * (-0.5d0))
end function
public static double code(double x, double y) {
return 1.0 + ((x * x) * -0.5);
}
def code(x, y): return 1.0 + ((x * x) * -0.5)
function code(x, y) return Float64(1.0 + Float64(Float64(x * x) * -0.5)) end
function tmp = code(x, y) tmp = 1.0 + ((x * x) * -0.5); end
code[x_, y_] := N[(1.0 + N[(N[(x * x), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \left(x \cdot x\right) \cdot -0.5
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 45.1%
Taylor expanded in x around 0 32.3%
*-commutative49.2%
Simplified32.3%
unpow249.2%
Applied egg-rr32.3%
(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 70.7%
Taylor expanded in y around 0 27.3%
herbie shell --seed 2024143
(FPCore (x y)
:name "Linear.Quaternion:$csin from linear-1.19.1.3"
:precision binary64
(* (cos x) (/ (sinh y) y)))