
(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 12 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 (* (sin re) (fma 0.5 (exp im) (/ 0.5 (exp im)))))
double code(double re, double im) {
return sin(re) * fma(0.5, exp(im), (0.5 / exp(im)));
}
function code(re, im) return Float64(sin(re) * fma(0.5, exp(im), Float64(0.5 / exp(im)))) end
code[re_, im_] := N[(N[Sin[re], $MachinePrecision] * N[(0.5 * N[Exp[im], $MachinePrecision] + N[(0.5 / N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right)
\end{array}
(FPCore (re im) :precision binary64 (* (+ (exp im) (exp (- im))) (* (sin re) 0.5)))
double code(double re, double im) {
return (exp(im) + exp(-im)) * (sin(re) * 0.5);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (exp(im) + exp(-im)) * (sin(re) * 0.5d0)
end function
public static double code(double re, double im) {
return (Math.exp(im) + Math.exp(-im)) * (Math.sin(re) * 0.5);
}
def code(re, im): return (math.exp(im) + math.exp(-im)) * (math.sin(re) * 0.5)
function code(re, im) return Float64(Float64(exp(im) + exp(Float64(-im))) * Float64(sin(re) * 0.5)) end
function tmp = code(re, im) tmp = (exp(im) + exp(-im)) * (sin(re) * 0.5); end
code[re_, im_] := N[(N[(N[Exp[im], $MachinePrecision] + N[Exp[(-im)], $MachinePrecision]), $MachinePrecision] * N[(N[Sin[re], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(e^{im} + e^{-im}\right) \cdot \left(\sin re \cdot 0.5\right)
\end{array}
(FPCore (re im)
:precision binary64
(if (<= im 4.4)
(sin re)
(if (<= im 1.32e+154)
(* re (+ 2.0 (* 0.5 (exp im))))
(* (pow im 2.0) (* (sin re) 0.5)))))
double code(double re, double im) {
double tmp;
if (im <= 4.4) {
tmp = sin(re);
} else if (im <= 1.32e+154) {
tmp = re * (2.0 + (0.5 * exp(im)));
} else {
tmp = pow(im, 2.0) * (sin(re) * 0.5);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 4.4d0) then
tmp = sin(re)
else if (im <= 1.32d+154) then
tmp = re * (2.0d0 + (0.5d0 * exp(im)))
else
tmp = (im ** 2.0d0) * (sin(re) * 0.5d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 4.4) {
tmp = Math.sin(re);
} else if (im <= 1.32e+154) {
tmp = re * (2.0 + (0.5 * Math.exp(im)));
} else {
tmp = Math.pow(im, 2.0) * (Math.sin(re) * 0.5);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 4.4: tmp = math.sin(re) elif im <= 1.32e+154: tmp = re * (2.0 + (0.5 * math.exp(im))) else: tmp = math.pow(im, 2.0) * (math.sin(re) * 0.5) return tmp
function code(re, im) tmp = 0.0 if (im <= 4.4) tmp = sin(re); elseif (im <= 1.32e+154) tmp = Float64(re * Float64(2.0 + Float64(0.5 * exp(im)))); else tmp = Float64((im ^ 2.0) * Float64(sin(re) * 0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 4.4) tmp = sin(re); elseif (im <= 1.32e+154) tmp = re * (2.0 + (0.5 * exp(im))); else tmp = (im ^ 2.0) * (sin(re) * 0.5); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 4.4], N[Sin[re], $MachinePrecision], If[LessEqual[im, 1.32e+154], N[(re * N[(2.0 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[im, 2.0], $MachinePrecision] * N[(N[Sin[re], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 4.4:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 1.32 \cdot 10^{+154}:\\
\;\;\;\;re \cdot \left(2 + 0.5 \cdot e^{im}\right)\\
\mathbf{else}:\\
\;\;\;\;{im}^{2} \cdot \left(\sin re \cdot 0.5\right)\\
\end{array}
\end{array}
(FPCore (re im) :precision binary64 (if (<= im 2.3) (* (sin re) (+ (* 0.5 (pow im 2.0)) 1.0)) (* (sin re) (+ 2.0 (* 0.5 (exp im))))))
double code(double re, double im) {
double tmp;
if (im <= 2.3) {
tmp = sin(re) * ((0.5 * pow(im, 2.0)) + 1.0);
} else {
tmp = sin(re) * (2.0 + (0.5 * exp(im)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 2.3d0) then
tmp = sin(re) * ((0.5d0 * (im ** 2.0d0)) + 1.0d0)
else
tmp = sin(re) * (2.0d0 + (0.5d0 * exp(im)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 2.3) {
tmp = Math.sin(re) * ((0.5 * Math.pow(im, 2.0)) + 1.0);
} else {
tmp = Math.sin(re) * (2.0 + (0.5 * Math.exp(im)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 2.3: tmp = math.sin(re) * ((0.5 * math.pow(im, 2.0)) + 1.0) else: tmp = math.sin(re) * (2.0 + (0.5 * math.exp(im))) return tmp
function code(re, im) tmp = 0.0 if (im <= 2.3) tmp = Float64(sin(re) * Float64(Float64(0.5 * (im ^ 2.0)) + 1.0)); else tmp = Float64(sin(re) * Float64(2.0 + Float64(0.5 * exp(im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 2.3) tmp = sin(re) * ((0.5 * (im ^ 2.0)) + 1.0); else tmp = sin(re) * (2.0 + (0.5 * exp(im))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 2.3], N[(N[Sin[re], $MachinePrecision] * N[(N[(0.5 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[Sin[re], $MachinePrecision] * N[(2.0 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 2.3:\\
\;\;\;\;\sin re \cdot \left(0.5 \cdot {im}^{2} + 1\right)\\
\mathbf{else}:\\
\;\;\;\;\sin re \cdot \left(2 + 0.5 \cdot e^{im}\right)\\
\end{array}
\end{array}
(FPCore (re im) :precision binary64 (if (<= im 1.3) (sin re) (* (sin re) (+ 2.0 (* 0.5 (exp im))))))
double code(double re, double im) {
double tmp;
if (im <= 1.3) {
tmp = sin(re);
} else {
tmp = sin(re) * (2.0 + (0.5 * exp(im)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 1.3d0) then
tmp = sin(re)
else
tmp = sin(re) * (2.0d0 + (0.5d0 * exp(im)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.3) {
tmp = Math.sin(re);
} else {
tmp = Math.sin(re) * (2.0 + (0.5 * Math.exp(im)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.3: tmp = math.sin(re) else: tmp = math.sin(re) * (2.0 + (0.5 * math.exp(im))) return tmp
function code(re, im) tmp = 0.0 if (im <= 1.3) tmp = sin(re); else tmp = Float64(sin(re) * Float64(2.0 + Float64(0.5 * exp(im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.3) tmp = sin(re); else tmp = sin(re) * (2.0 + (0.5 * exp(im))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.3], N[Sin[re], $MachinePrecision], N[(N[Sin[re], $MachinePrecision] * N[(2.0 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.3:\\
\;\;\;\;\sin re\\
\mathbf{else}:\\
\;\;\;\;\sin re \cdot \left(2 + 0.5 \cdot e^{im}\right)\\
\end{array}
\end{array}
(FPCore (re im)
:precision binary64
(if (<= im 5.6)
(sin re)
(if (<= im 2.65e+154)
(* re (+ 2.0 (* 0.5 (exp im))))
(* (sin re) (+ 2.5 (* im (+ 0.5 (* im 0.25))))))))
double code(double re, double im) {
double tmp;
if (im <= 5.6) {
tmp = sin(re);
} else if (im <= 2.65e+154) {
tmp = re * (2.0 + (0.5 * exp(im)));
} else {
tmp = sin(re) * (2.5 + (im * (0.5 + (im * 0.25))));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 5.6d0) then
tmp = sin(re)
else if (im <= 2.65d+154) then
tmp = re * (2.0d0 + (0.5d0 * exp(im)))
else
tmp = sin(re) * (2.5d0 + (im * (0.5d0 + (im * 0.25d0))))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 5.6) {
tmp = Math.sin(re);
} else if (im <= 2.65e+154) {
tmp = re * (2.0 + (0.5 * Math.exp(im)));
} else {
tmp = Math.sin(re) * (2.5 + (im * (0.5 + (im * 0.25))));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 5.6: tmp = math.sin(re) elif im <= 2.65e+154: tmp = re * (2.0 + (0.5 * math.exp(im))) else: tmp = math.sin(re) * (2.5 + (im * (0.5 + (im * 0.25)))) return tmp
function code(re, im) tmp = 0.0 if (im <= 5.6) tmp = sin(re); elseif (im <= 2.65e+154) tmp = Float64(re * Float64(2.0 + Float64(0.5 * exp(im)))); else tmp = Float64(sin(re) * Float64(2.5 + Float64(im * Float64(0.5 + Float64(im * 0.25))))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 5.6) tmp = sin(re); elseif (im <= 2.65e+154) tmp = re * (2.0 + (0.5 * exp(im))); else tmp = sin(re) * (2.5 + (im * (0.5 + (im * 0.25)))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 5.6], N[Sin[re], $MachinePrecision], If[LessEqual[im, 2.65e+154], N[(re * N[(2.0 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[re], $MachinePrecision] * N[(2.5 + N[(im * N[(0.5 + N[(im * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 5.6:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 2.65 \cdot 10^{+154}:\\
\;\;\;\;re \cdot \left(2 + 0.5 \cdot e^{im}\right)\\
\mathbf{else}:\\
\;\;\;\;\sin re \cdot \left(2.5 + im \cdot \left(0.5 + im \cdot 0.25\right)\right)\\
\end{array}
\end{array}
(FPCore (re im) :precision binary64 (if (<= im 5.6) (sin re) (* re (+ 2.0 (* 0.5 (exp im))))))
double code(double re, double im) {
double tmp;
if (im <= 5.6) {
tmp = sin(re);
} else {
tmp = re * (2.0 + (0.5 * exp(im)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 5.6d0) then
tmp = sin(re)
else
tmp = re * (2.0d0 + (0.5d0 * exp(im)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 5.6) {
tmp = Math.sin(re);
} else {
tmp = re * (2.0 + (0.5 * Math.exp(im)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 5.6: tmp = math.sin(re) else: tmp = re * (2.0 + (0.5 * math.exp(im))) return tmp
function code(re, im) tmp = 0.0 if (im <= 5.6) tmp = sin(re); else tmp = Float64(re * Float64(2.0 + Float64(0.5 * exp(im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 5.6) tmp = sin(re); else tmp = re * (2.0 + (0.5 * exp(im))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 5.6], N[Sin[re], $MachinePrecision], N[(re * N[(2.0 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 5.6:\\
\;\;\;\;\sin re\\
\mathbf{else}:\\
\;\;\;\;re \cdot \left(2 + 0.5 \cdot e^{im}\right)\\
\end{array}
\end{array}
(FPCore (re im) :precision binary64 (if (<= im 6e+32) (sin re) (* (pow im 2.0) (* re 0.5))))
double code(double re, double im) {
double tmp;
if (im <= 6e+32) {
tmp = sin(re);
} else {
tmp = pow(im, 2.0) * (re * 0.5);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 6d+32) then
tmp = sin(re)
else
tmp = (im ** 2.0d0) * (re * 0.5d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 6e+32) {
tmp = Math.sin(re);
} else {
tmp = Math.pow(im, 2.0) * (re * 0.5);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 6e+32: tmp = math.sin(re) else: tmp = math.pow(im, 2.0) * (re * 0.5) return tmp
function code(re, im) tmp = 0.0 if (im <= 6e+32) tmp = sin(re); else tmp = Float64((im ^ 2.0) * Float64(re * 0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 6e+32) tmp = sin(re); else tmp = (im ^ 2.0) * (re * 0.5); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 6e+32], N[Sin[re], $MachinePrecision], N[(N[Power[im, 2.0], $MachinePrecision] * N[(re * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 6 \cdot 10^{+32}:\\
\;\;\;\;\sin re\\
\mathbf{else}:\\
\;\;\;\;{im}^{2} \cdot \left(re \cdot 0.5\right)\\
\end{array}
\end{array}
(FPCore (re im) :precision binary64 (if (<= im 1.65e+33) (sin re) (* re (+ 2.5 (* 0.5 im)))))
double code(double re, double im) {
double tmp;
if (im <= 1.65e+33) {
tmp = sin(re);
} else {
tmp = re * (2.5 + (0.5 * im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 1.65d+33) then
tmp = sin(re)
else
tmp = re * (2.5d0 + (0.5d0 * im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.65e+33) {
tmp = Math.sin(re);
} else {
tmp = re * (2.5 + (0.5 * im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.65e+33: tmp = math.sin(re) else: tmp = re * (2.5 + (0.5 * im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 1.65e+33) tmp = sin(re); else tmp = Float64(re * Float64(2.5 + Float64(0.5 * im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.65e+33) tmp = sin(re); else tmp = re * (2.5 + (0.5 * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.65e+33], N[Sin[re], $MachinePrecision], N[(re * N[(2.5 + N[(0.5 * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.65 \cdot 10^{+33}:\\
\;\;\;\;\sin re\\
\mathbf{else}:\\
\;\;\;\;re \cdot \left(2.5 + 0.5 \cdot im\right)\\
\end{array}
\end{array}
(FPCore (re im) :precision binary64 (if (<= im 410.0) re (* re (+ 2.5 (* 0.5 im)))))
double code(double re, double im) {
double tmp;
if (im <= 410.0) {
tmp = re;
} else {
tmp = re * (2.5 + (0.5 * im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 410.0d0) then
tmp = re
else
tmp = re * (2.5d0 + (0.5d0 * im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 410.0) {
tmp = re;
} else {
tmp = re * (2.5 + (0.5 * im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 410.0: tmp = re else: tmp = re * (2.5 + (0.5 * im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 410.0) tmp = re; else tmp = Float64(re * Float64(2.5 + Float64(0.5 * im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 410.0) tmp = re; else tmp = re * (2.5 + (0.5 * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 410.0], re, N[(re * N[(2.5 + N[(0.5 * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 410:\\
\;\;\;\;re\\
\mathbf{else}:\\
\;\;\;\;re \cdot \left(2.5 + 0.5 \cdot im\right)\\
\end{array}
\end{array}
(FPCore (re im) :precision binary64 1.0)
double code(double re, double im) {
return 1.0;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 1.0d0
end function
public static double code(double re, double im) {
return 1.0;
}
def code(re, im): return 1.0
function code(re, im) return 1.0 end
function tmp = code(re, im) tmp = 1.0; end
code[re_, im_] := 1.0
\begin{array}{l}
\\
1
\end{array}
(FPCore (re im) :precision binary64 re)
double code(double re, double im) {
return re;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = re
end function
public static double code(double re, double im) {
return re;
}
def code(re, im): return re
function code(re, im) return re end
function tmp = code(re, im) tmp = re; end
code[re_, im_] := re
\begin{array}{l}
\\
re
\end{array}
herbie shell --seed 2023343
(FPCore (re im)
:name "math.sin on complex, real part"
:precision binary64
(* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))