
(FPCore (re im) :precision binary64 (* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))
double code(double re, double im) {
return (0.5 * sin(re)) * (exp((0.0 - im)) + exp(im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * sin(re)) * (exp((0.0d0 - im)) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.sin(re)) * (Math.exp((0.0 - im)) + Math.exp(im));
}
def code(re, im): return (0.5 * math.sin(re)) * (math.exp((0.0 - im)) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(0.0 - im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * sin(re)) * (exp((0.0 - im)) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))
double code(double re, double im) {
return (0.5 * sin(re)) * (exp((0.0 - im)) + exp(im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * sin(re)) * (exp((0.0d0 - im)) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.sin(re)) * (Math.exp((0.0 - im)) + Math.exp(im));
}
def code(re, im): return (0.5 * math.sin(re)) * (math.exp((0.0 - im)) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(0.0 - im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * sin(re)) * (exp((0.0 - im)) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right)
\end{array}
(FPCore (re im) :precision binary64 (* (* 0.5 (sin re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
return (0.5 * sin(re)) * (exp(-im) + exp(im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * sin(re)) * (exp(-im) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.sin(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im): return (0.5 * math.sin(re)) * (math.exp(-im) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(-im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * sin(re)) * (exp(-im) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)
\end{array}
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sin re))))
(if (<= im 0.0068)
(* t_0 (fma im im 2.0))
(if (<= im 1.32e+154)
(* (* 0.5 re) (+ (exp (- im)) (exp im)))
(* t_0 (pow im 2.0))))))
double code(double re, double im) {
double t_0 = 0.5 * sin(re);
double tmp;
if (im <= 0.0068) {
tmp = t_0 * fma(im, im, 2.0);
} else if (im <= 1.32e+154) {
tmp = (0.5 * re) * (exp(-im) + exp(im));
} else {
tmp = t_0 * pow(im, 2.0);
}
return tmp;
}
function code(re, im) t_0 = Float64(0.5 * sin(re)) tmp = 0.0 if (im <= 0.0068) tmp = Float64(t_0 * fma(im, im, 2.0)); elseif (im <= 1.32e+154) tmp = Float64(Float64(0.5 * re) * Float64(exp(Float64(-im)) + exp(im))); else tmp = Float64(t_0 * (im ^ 2.0)); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, 0.0068], N[(t$95$0 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.32e+154], N[(N[(0.5 * re), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sin re\\
\mathbf{if}\;im \leq 0.0068:\\
\;\;\;\;t_0 \cdot \mathsf{fma}\left(im, im, 2\right)\\
\mathbf{elif}\;im \leq 1.32 \cdot 10^{+154}:\\
\;\;\;\;\left(0.5 \cdot re\right) \cdot \left(e^{-im} + e^{im}\right)\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot {im}^{2}\\
\end{array}
\end{array}
(FPCore (re im)
:precision binary64
(if (<= im 245.0)
(sin re)
(if (<= im 1.32e+154)
(cbrt (/ 0.015625 (pow re 6.0)))
(* (* 0.5 (sin re)) (pow im 2.0)))))
double code(double re, double im) {
double tmp;
if (im <= 245.0) {
tmp = sin(re);
} else if (im <= 1.32e+154) {
tmp = cbrt((0.015625 / pow(re, 6.0)));
} else {
tmp = (0.5 * sin(re)) * pow(im, 2.0);
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (im <= 245.0) {
tmp = Math.sin(re);
} else if (im <= 1.32e+154) {
tmp = Math.cbrt((0.015625 / Math.pow(re, 6.0)));
} else {
tmp = (0.5 * Math.sin(re)) * Math.pow(im, 2.0);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 245.0) tmp = sin(re); elseif (im <= 1.32e+154) tmp = cbrt(Float64(0.015625 / (re ^ 6.0))); else tmp = Float64(Float64(0.5 * sin(re)) * (im ^ 2.0)); end return tmp end
code[re_, im_] := If[LessEqual[im, 245.0], N[Sin[re], $MachinePrecision], If[LessEqual[im, 1.32e+154], N[Power[N[(0.015625 / N[Power[re, 6.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 245:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 1.32 \cdot 10^{+154}:\\
\;\;\;\;\sqrt[3]{\frac{0.015625}{{re}^{6}}}\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \sin re\right) \cdot {im}^{2}\\
\end{array}
\end{array}
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sin re))))
(if (<= im 245.0)
(* t_0 (fma im im 2.0))
(if (<= im 1.32e+154)
(cbrt (/ 0.015625 (pow re 6.0)))
(* t_0 (pow im 2.0))))))
double code(double re, double im) {
double t_0 = 0.5 * sin(re);
double tmp;
if (im <= 245.0) {
tmp = t_0 * fma(im, im, 2.0);
} else if (im <= 1.32e+154) {
tmp = cbrt((0.015625 / pow(re, 6.0)));
} else {
tmp = t_0 * pow(im, 2.0);
}
return tmp;
}
function code(re, im) t_0 = Float64(0.5 * sin(re)) tmp = 0.0 if (im <= 245.0) tmp = Float64(t_0 * fma(im, im, 2.0)); elseif (im <= 1.32e+154) tmp = cbrt(Float64(0.015625 / (re ^ 6.0))); else tmp = Float64(t_0 * (im ^ 2.0)); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, 245.0], N[(t$95$0 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.32e+154], N[Power[N[(0.015625 / N[Power[re, 6.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], N[(t$95$0 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sin re\\
\mathbf{if}\;im \leq 245:\\
\;\;\;\;t_0 \cdot \mathsf{fma}\left(im, im, 2\right)\\
\mathbf{elif}\;im \leq 1.32 \cdot 10^{+154}:\\
\;\;\;\;\sqrt[3]{\frac{0.015625}{{re}^{6}}}\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot {im}^{2}\\
\end{array}
\end{array}
(FPCore (re im)
:precision binary64
(if (<= im 245.0)
(sin re)
(if (<= im 1.7e+141)
(cbrt (/ 0.015625 (pow re 6.0)))
(* re (* 0.5 (pow im 2.0))))))
double code(double re, double im) {
double tmp;
if (im <= 245.0) {
tmp = sin(re);
} else if (im <= 1.7e+141) {
tmp = cbrt((0.015625 / pow(re, 6.0)));
} else {
tmp = re * (0.5 * pow(im, 2.0));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (im <= 245.0) {
tmp = Math.sin(re);
} else if (im <= 1.7e+141) {
tmp = Math.cbrt((0.015625 / Math.pow(re, 6.0)));
} else {
tmp = re * (0.5 * Math.pow(im, 2.0));
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 245.0) tmp = sin(re); elseif (im <= 1.7e+141) tmp = cbrt(Float64(0.015625 / (re ^ 6.0))); else tmp = Float64(re * Float64(0.5 * (im ^ 2.0))); end return tmp end
code[re_, im_] := If[LessEqual[im, 245.0], N[Sin[re], $MachinePrecision], If[LessEqual[im, 1.7e+141], N[Power[N[(0.015625 / N[Power[re, 6.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], N[(re * N[(0.5 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 245:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 1.7 \cdot 10^{+141}:\\
\;\;\;\;\sqrt[3]{\frac{0.015625}{{re}^{6}}}\\
\mathbf{else}:\\
\;\;\;\;re \cdot \left(0.5 \cdot {im}^{2}\right)\\
\end{array}
\end{array}
(FPCore (re im) :precision binary64 (if (<= im 4.8e+22) (sin re) (if (<= im 1.95e+141) (/ (/ 0.25 re) re) (* re (* 0.5 (pow im 2.0))))))
double code(double re, double im) {
double tmp;
if (im <= 4.8e+22) {
tmp = sin(re);
} else if (im <= 1.95e+141) {
tmp = (0.25 / re) / re;
} else {
tmp = re * (0.5 * pow(im, 2.0));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 4.8d+22) then
tmp = sin(re)
else if (im <= 1.95d+141) then
tmp = (0.25d0 / re) / re
else
tmp = re * (0.5d0 * (im ** 2.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 4.8e+22) {
tmp = Math.sin(re);
} else if (im <= 1.95e+141) {
tmp = (0.25 / re) / re;
} else {
tmp = re * (0.5 * Math.pow(im, 2.0));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 4.8e+22: tmp = math.sin(re) elif im <= 1.95e+141: tmp = (0.25 / re) / re else: tmp = re * (0.5 * math.pow(im, 2.0)) return tmp
function code(re, im) tmp = 0.0 if (im <= 4.8e+22) tmp = sin(re); elseif (im <= 1.95e+141) tmp = Float64(Float64(0.25 / re) / re); else tmp = Float64(re * Float64(0.5 * (im ^ 2.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 4.8e+22) tmp = sin(re); elseif (im <= 1.95e+141) tmp = (0.25 / re) / re; else tmp = re * (0.5 * (im ^ 2.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 4.8e+22], N[Sin[re], $MachinePrecision], If[LessEqual[im, 1.95e+141], N[(N[(0.25 / re), $MachinePrecision] / re), $MachinePrecision], N[(re * N[(0.5 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 4.8 \cdot 10^{+22}:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 1.95 \cdot 10^{+141}:\\
\;\;\;\;\frac{\frac{0.25}{re}}{re}\\
\mathbf{else}:\\
\;\;\;\;re \cdot \left(0.5 \cdot {im}^{2}\right)\\
\end{array}
\end{array}
(FPCore (re im) :precision binary64 (if (<= im 245.0) (sin re) (+ 0.08333333333333333 (* (/ 0.5 re) (/ 0.5 re)))))
double code(double re, double im) {
double tmp;
if (im <= 245.0) {
tmp = sin(re);
} else {
tmp = 0.08333333333333333 + ((0.5 / re) * (0.5 / re));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 245.0d0) then
tmp = sin(re)
else
tmp = 0.08333333333333333d0 + ((0.5d0 / re) * (0.5d0 / re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 245.0) {
tmp = Math.sin(re);
} else {
tmp = 0.08333333333333333 + ((0.5 / re) * (0.5 / re));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 245.0: tmp = math.sin(re) else: tmp = 0.08333333333333333 + ((0.5 / re) * (0.5 / re)) return tmp
function code(re, im) tmp = 0.0 if (im <= 245.0) tmp = sin(re); else tmp = Float64(0.08333333333333333 + Float64(Float64(0.5 / re) * Float64(0.5 / re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 245.0) tmp = sin(re); else tmp = 0.08333333333333333 + ((0.5 / re) * (0.5 / re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 245.0], N[Sin[re], $MachinePrecision], N[(0.08333333333333333 + N[(N[(0.5 / re), $MachinePrecision] * N[(0.5 / re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 245:\\
\;\;\;\;\sin re\\
\mathbf{else}:\\
\;\;\;\;0.08333333333333333 + \frac{0.5}{re} \cdot \frac{0.5}{re}\\
\end{array}
\end{array}
(FPCore (re im) :precision binary64 (if (<= im 2.55e+21) re (/ (/ 0.25 re) re)))
double code(double re, double im) {
double tmp;
if (im <= 2.55e+21) {
tmp = re;
} else {
tmp = (0.25 / re) / re;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 2.55d+21) then
tmp = re
else
tmp = (0.25d0 / re) / re
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 2.55e+21) {
tmp = re;
} else {
tmp = (0.25 / re) / re;
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 2.55e+21: tmp = re else: tmp = (0.25 / re) / re return tmp
function code(re, im) tmp = 0.0 if (im <= 2.55e+21) tmp = re; else tmp = Float64(Float64(0.25 / re) / re); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 2.55e+21) tmp = re; else tmp = (0.25 / re) / re; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 2.55e+21], re, N[(N[(0.25 / re), $MachinePrecision] / re), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 2.55 \cdot 10^{+21}:\\
\;\;\;\;re\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.25}{re}}{re}\\
\end{array}
\end{array}
(FPCore (re im) :precision binary64 (if (<= re 2.7) re 0.08333333333333333))
double code(double re, double im) {
double tmp;
if (re <= 2.7) {
tmp = re;
} else {
tmp = 0.08333333333333333;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= 2.7d0) then
tmp = re
else
tmp = 0.08333333333333333d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 2.7) {
tmp = re;
} else {
tmp = 0.08333333333333333;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 2.7: tmp = re else: tmp = 0.08333333333333333 return tmp
function code(re, im) tmp = 0.0 if (re <= 2.7) tmp = re; else tmp = 0.08333333333333333; end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 2.7) tmp = re; else tmp = 0.08333333333333333; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 2.7], re, 0.08333333333333333]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 2.7:\\
\;\;\;\;re\\
\mathbf{else}:\\
\;\;\;\;0.08333333333333333\\
\end{array}
\end{array}
(FPCore (re im) :precision binary64 0.08333333333333333)
double code(double re, double im) {
return 0.08333333333333333;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.08333333333333333d0
end function
public static double code(double re, double im) {
return 0.08333333333333333;
}
def code(re, im): return 0.08333333333333333
function code(re, im) return 0.08333333333333333 end
function tmp = code(re, im) tmp = 0.08333333333333333; end
code[re_, im_] := 0.08333333333333333
\begin{array}{l}
\\
0.08333333333333333
\end{array}
herbie shell --seed 2023350
(FPCore (re im)
:name "math.sin on complex, real part"
:precision binary64
(* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))