
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(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 * cos(re)) * (exp((0.0d0 - im)) - exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp((0.0 - im)) - Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[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 \cos 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 (cos re)) (- (exp (- 0.0 im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(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 * cos(re)) * (exp((0.0d0 - im)) - exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp((0.0 - im)) - Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[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 \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\end{array}
(FPCore (re im) :precision binary64 (* 0.5 (log1p (expm1 (* -2.0 (* im (cos re)))))))
double code(double re, double im) {
return 0.5 * log1p(expm1((-2.0 * (im * cos(re)))));
}
public static double code(double re, double im) {
return 0.5 * Math.log1p(Math.expm1((-2.0 * (im * Math.cos(re)))));
}
def code(re, im): return 0.5 * math.log1p(math.expm1((-2.0 * (im * math.cos(re)))))
function code(re, im) return Float64(0.5 * log1p(expm1(Float64(-2.0 * Float64(im * cos(re)))))) end
code[re_, im_] := N[(0.5 * N[Log[1 + N[(Exp[N[(-2.0 * N[(im * N[Cos[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(-2 \cdot \left(im \cdot \cos re\right)\right)\right)
\end{array}
Initial program 55.8%
/-rgt-identity55.8%
exp-055.8%
associate-*l/55.8%
cos-neg55.8%
associate-*l*55.8%
associate-*r/55.8%
exp-055.8%
/-rgt-identity55.8%
*-commutative55.8%
neg-sub055.8%
cos-neg55.8%
Simplified55.8%
Taylor expanded in im around 0 50.4%
log1p-expm1-u99.5%
associate-*l*99.5%
Applied egg-rr99.5%
(FPCore (re im)
:precision binary64
(if (<= im 410.0)
(* 0.5 (* (cos re) (* im (- (* -0.3333333333333333 (pow im 2.0)) 2.0))))
(if (<= im 3.1e+102)
(* 0.5 (log1p (expm1 (* -2.0 im))))
(* 0.5 (* (pow im 3.0) (* (cos re) -0.3333333333333333))))))
double code(double re, double im) {
double tmp;
if (im <= 410.0) {
tmp = 0.5 * (cos(re) * (im * ((-0.3333333333333333 * pow(im, 2.0)) - 2.0)));
} else if (im <= 3.1e+102) {
tmp = 0.5 * log1p(expm1((-2.0 * im)));
} else {
tmp = 0.5 * (pow(im, 3.0) * (cos(re) * -0.3333333333333333));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (im <= 410.0) {
tmp = 0.5 * (Math.cos(re) * (im * ((-0.3333333333333333 * Math.pow(im, 2.0)) - 2.0)));
} else if (im <= 3.1e+102) {
tmp = 0.5 * Math.log1p(Math.expm1((-2.0 * im)));
} else {
tmp = 0.5 * (Math.pow(im, 3.0) * (Math.cos(re) * -0.3333333333333333));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 410.0: tmp = 0.5 * (math.cos(re) * (im * ((-0.3333333333333333 * math.pow(im, 2.0)) - 2.0))) elif im <= 3.1e+102: tmp = 0.5 * math.log1p(math.expm1((-2.0 * im))) else: tmp = 0.5 * (math.pow(im, 3.0) * (math.cos(re) * -0.3333333333333333)) return tmp
function code(re, im) tmp = 0.0 if (im <= 410.0) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * Float64(Float64(-0.3333333333333333 * (im ^ 2.0)) - 2.0)))); elseif (im <= 3.1e+102) tmp = Float64(0.5 * log1p(expm1(Float64(-2.0 * im)))); else tmp = Float64(0.5 * Float64((im ^ 3.0) * Float64(cos(re) * -0.3333333333333333))); end return tmp end
code[re_, im_] := If[LessEqual[im, 410.0], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * N[(N[(-0.3333333333333333 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 3.1e+102], N[(0.5 * N[Log[1 + N[(Exp[N[(-2.0 * im), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Power[im, 3.0], $MachinePrecision] * N[(N[Cos[re], $MachinePrecision] * -0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 410:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)\right)\\
\mathbf{elif}\;im \leq 3.1 \cdot 10^{+102}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(-2 \cdot im\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left({im}^{3} \cdot \left(\cos re \cdot -0.3333333333333333\right)\right)\\
\end{array}
\end{array}
if im < 410Initial program 39.4%
/-rgt-identity39.4%
exp-039.4%
associate-*l/39.4%
cos-neg39.4%
associate-*l*39.4%
associate-*r/39.4%
exp-039.4%
/-rgt-identity39.4%
*-commutative39.4%
neg-sub039.4%
cos-neg39.4%
Simplified39.4%
Taylor expanded in im around 0 85.2%
if 410 < im < 3.09999999999999987e102Initial program 100.0%
/-rgt-identity100.0%
exp-0100.0%
associate-*l/100.0%
cos-neg100.0%
associate-*l*100.0%
associate-*r/100.0%
exp-0100.0%
/-rgt-identity100.0%
*-commutative100.0%
neg-sub0100.0%
cos-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 3.5%
log1p-expm1-u100.0%
associate-*l*100.0%
Applied egg-rr100.0%
Taylor expanded in re around 0 88.2%
if 3.09999999999999987e102 < im Initial program 100.0%
/-rgt-identity100.0%
exp-0100.0%
associate-*l/100.0%
cos-neg100.0%
associate-*l*100.0%
associate-*r/100.0%
exp-0100.0%
/-rgt-identity100.0%
*-commutative100.0%
neg-sub0100.0%
cos-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 98.4%
Taylor expanded in im around inf 98.4%
*-commutative98.4%
associate-*r*98.4%
Simplified98.4%
Final simplification88.1%
(FPCore (re im)
:precision binary64
(if (<= im 520.0)
(* 0.5 (* (cos re) (* -2.0 im)))
(if (<= im 3.1e+102)
(* 0.5 (log1p (expm1 (* -2.0 im))))
(* 0.5 (* (pow im 3.0) (* (cos re) -0.3333333333333333))))))
double code(double re, double im) {
double tmp;
if (im <= 520.0) {
tmp = 0.5 * (cos(re) * (-2.0 * im));
} else if (im <= 3.1e+102) {
tmp = 0.5 * log1p(expm1((-2.0 * im)));
} else {
tmp = 0.5 * (pow(im, 3.0) * (cos(re) * -0.3333333333333333));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (im <= 520.0) {
tmp = 0.5 * (Math.cos(re) * (-2.0 * im));
} else if (im <= 3.1e+102) {
tmp = 0.5 * Math.log1p(Math.expm1((-2.0 * im)));
} else {
tmp = 0.5 * (Math.pow(im, 3.0) * (Math.cos(re) * -0.3333333333333333));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 520.0: tmp = 0.5 * (math.cos(re) * (-2.0 * im)) elif im <= 3.1e+102: tmp = 0.5 * math.log1p(math.expm1((-2.0 * im))) else: tmp = 0.5 * (math.pow(im, 3.0) * (math.cos(re) * -0.3333333333333333)) return tmp
function code(re, im) tmp = 0.0 if (im <= 520.0) tmp = Float64(0.5 * Float64(cos(re) * Float64(-2.0 * im))); elseif (im <= 3.1e+102) tmp = Float64(0.5 * log1p(expm1(Float64(-2.0 * im)))); else tmp = Float64(0.5 * Float64((im ^ 3.0) * Float64(cos(re) * -0.3333333333333333))); end return tmp end
code[re_, im_] := If[LessEqual[im, 520.0], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(-2.0 * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 3.1e+102], N[(0.5 * N[Log[1 + N[(Exp[N[(-2.0 * im), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Power[im, 3.0], $MachinePrecision] * N[(N[Cos[re], $MachinePrecision] * -0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 520:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(-2 \cdot im\right)\right)\\
\mathbf{elif}\;im \leq 3.1 \cdot 10^{+102}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(-2 \cdot im\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left({im}^{3} \cdot \left(\cos re \cdot -0.3333333333333333\right)\right)\\
\end{array}
\end{array}
if im < 520Initial program 39.4%
/-rgt-identity39.4%
exp-039.4%
associate-*l/39.4%
cos-neg39.4%
associate-*l*39.4%
associate-*r/39.4%
exp-039.4%
/-rgt-identity39.4%
*-commutative39.4%
neg-sub039.4%
cos-neg39.4%
Simplified39.4%
Taylor expanded in im around 0 66.8%
if 520 < im < 3.09999999999999987e102Initial program 100.0%
/-rgt-identity100.0%
exp-0100.0%
associate-*l/100.0%
cos-neg100.0%
associate-*l*100.0%
associate-*r/100.0%
exp-0100.0%
/-rgt-identity100.0%
*-commutative100.0%
neg-sub0100.0%
cos-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 3.5%
log1p-expm1-u100.0%
associate-*l*100.0%
Applied egg-rr100.0%
Taylor expanded in re around 0 88.2%
if 3.09999999999999987e102 < im Initial program 100.0%
/-rgt-identity100.0%
exp-0100.0%
associate-*l/100.0%
cos-neg100.0%
associate-*l*100.0%
associate-*r/100.0%
exp-0100.0%
/-rgt-identity100.0%
*-commutative100.0%
neg-sub0100.0%
cos-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 98.4%
Taylor expanded in im around inf 98.4%
*-commutative98.4%
associate-*r*98.4%
Simplified98.4%
Final simplification74.6%
(FPCore (re im) :precision binary64 (if (<= (cos re) -0.09) (* 0.5 (* im (pow re 2.0))) (* 0.5 (* -2.0 im))))
double code(double re, double im) {
double tmp;
if (cos(re) <= -0.09) {
tmp = 0.5 * (im * pow(re, 2.0));
} else {
tmp = 0.5 * (-2.0 * im);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (cos(re) <= (-0.09d0)) then
tmp = 0.5d0 * (im * (re ** 2.0d0))
else
tmp = 0.5d0 * ((-2.0d0) * im)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (Math.cos(re) <= -0.09) {
tmp = 0.5 * (im * Math.pow(re, 2.0));
} else {
tmp = 0.5 * (-2.0 * im);
}
return tmp;
}
def code(re, im): tmp = 0 if math.cos(re) <= -0.09: tmp = 0.5 * (im * math.pow(re, 2.0)) else: tmp = 0.5 * (-2.0 * im) return tmp
function code(re, im) tmp = 0.0 if (cos(re) <= -0.09) tmp = Float64(0.5 * Float64(im * (re ^ 2.0))); else tmp = Float64(0.5 * Float64(-2.0 * im)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (cos(re) <= -0.09) tmp = 0.5 * (im * (re ^ 2.0)); else tmp = 0.5 * (-2.0 * im); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Cos[re], $MachinePrecision], -0.09], N[(0.5 * N[(im * N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(-2.0 * im), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos re \leq -0.09:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{2}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(-2 \cdot im\right)\\
\end{array}
\end{array}
if (cos.f64 re) < -0.089999999999999997Initial program 57.0%
/-rgt-identity57.0%
exp-057.0%
associate-*l/57.0%
cos-neg57.0%
associate-*l*57.0%
associate-*r/57.0%
exp-057.0%
/-rgt-identity57.0%
*-commutative57.0%
neg-sub057.0%
cos-neg57.0%
Simplified57.0%
Taylor expanded in im around 0 50.0%
Taylor expanded in re around 0 43.1%
Taylor expanded in re around inf 43.1%
if -0.089999999999999997 < (cos.f64 re) Initial program 55.4%
/-rgt-identity55.4%
exp-055.4%
associate-*l/55.4%
cos-neg55.4%
associate-*l*55.4%
associate-*r/55.4%
exp-055.4%
/-rgt-identity55.4%
*-commutative55.4%
neg-sub055.4%
cos-neg55.4%
Simplified55.4%
Taylor expanded in im around 0 50.5%
Taylor expanded in re around 0 34.2%
(FPCore (re im) :precision binary64 (if (<= im 480.0) (* 0.5 (* (cos re) (* -2.0 im))) (* 0.5 (log1p (expm1 (* -2.0 im))))))
double code(double re, double im) {
double tmp;
if (im <= 480.0) {
tmp = 0.5 * (cos(re) * (-2.0 * im));
} else {
tmp = 0.5 * log1p(expm1((-2.0 * im)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (im <= 480.0) {
tmp = 0.5 * (Math.cos(re) * (-2.0 * im));
} else {
tmp = 0.5 * Math.log1p(Math.expm1((-2.0 * im)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 480.0: tmp = 0.5 * (math.cos(re) * (-2.0 * im)) else: tmp = 0.5 * math.log1p(math.expm1((-2.0 * im))) return tmp
function code(re, im) tmp = 0.0 if (im <= 480.0) tmp = Float64(0.5 * Float64(cos(re) * Float64(-2.0 * im))); else tmp = Float64(0.5 * log1p(expm1(Float64(-2.0 * im)))); end return tmp end
code[re_, im_] := If[LessEqual[im, 480.0], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(-2.0 * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Log[1 + N[(Exp[N[(-2.0 * im), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 480:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(-2 \cdot im\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(-2 \cdot im\right)\right)\\
\end{array}
\end{array}
if im < 480Initial program 39.4%
/-rgt-identity39.4%
exp-039.4%
associate-*l/39.4%
cos-neg39.4%
associate-*l*39.4%
associate-*r/39.4%
exp-039.4%
/-rgt-identity39.4%
*-commutative39.4%
neg-sub039.4%
cos-neg39.4%
Simplified39.4%
Taylor expanded in im around 0 66.8%
if 480 < im Initial program 100.0%
/-rgt-identity100.0%
exp-0100.0%
associate-*l/100.0%
cos-neg100.0%
associate-*l*100.0%
associate-*r/100.0%
exp-0100.0%
/-rgt-identity100.0%
*-commutative100.0%
neg-sub0100.0%
cos-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 5.8%
log1p-expm1-u100.0%
associate-*l*100.0%
Applied egg-rr100.0%
Taylor expanded in re around 0 76.8%
Final simplification69.5%
(FPCore (re im) :precision binary64 (if (<= (cos re) -4e-310) (* 0.5 (fabs (* -2.0 im))) (* 0.5 (* -2.0 im))))
double code(double re, double im) {
double tmp;
if (cos(re) <= -4e-310) {
tmp = 0.5 * fabs((-2.0 * im));
} else {
tmp = 0.5 * (-2.0 * im);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (cos(re) <= (-4d-310)) then
tmp = 0.5d0 * abs(((-2.0d0) * im))
else
tmp = 0.5d0 * ((-2.0d0) * im)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (Math.cos(re) <= -4e-310) {
tmp = 0.5 * Math.abs((-2.0 * im));
} else {
tmp = 0.5 * (-2.0 * im);
}
return tmp;
}
def code(re, im): tmp = 0 if math.cos(re) <= -4e-310: tmp = 0.5 * math.fabs((-2.0 * im)) else: tmp = 0.5 * (-2.0 * im) return tmp
function code(re, im) tmp = 0.0 if (cos(re) <= -4e-310) tmp = Float64(0.5 * abs(Float64(-2.0 * im))); else tmp = Float64(0.5 * Float64(-2.0 * im)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (cos(re) <= -4e-310) tmp = 0.5 * abs((-2.0 * im)); else tmp = 0.5 * (-2.0 * im); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Cos[re], $MachinePrecision], -4e-310], N[(0.5 * N[Abs[N[(-2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(-2.0 * im), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos re \leq -4 \cdot 10^{-310}:\\
\;\;\;\;0.5 \cdot \left|-2 \cdot im\right|\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(-2 \cdot im\right)\\
\end{array}
\end{array}
if (cos.f64 re) < -3.999999999999988e-310Initial program 53.8%
/-rgt-identity53.8%
exp-053.8%
associate-*l/53.8%
cos-neg53.8%
associate-*l*53.8%
associate-*r/53.8%
exp-053.8%
/-rgt-identity53.8%
*-commutative53.8%
neg-sub053.8%
cos-neg53.8%
Simplified53.8%
Taylor expanded in im around 0 53.3%
log1p-expm1-u99.7%
associate-*l*99.7%
Applied egg-rr99.7%
Taylor expanded in re around 0 2.4%
log1p-expm1-u2.5%
add-sqr-sqrt0.9%
sqrt-unprod20.9%
log1p-expm1-u30.3%
log1p-expm1-u30.3%
log1p-expm1-u30.3%
*-commutative30.3%
log1p-expm1-u20.9%
*-commutative20.9%
swap-sqr20.9%
unpow220.9%
metadata-eval20.9%
Applied egg-rr20.9%
unpow220.9%
metadata-eval20.9%
swap-sqr20.9%
rem-sqrt-square7.8%
Simplified7.8%
if -3.999999999999988e-310 < (cos.f64 re) Initial program 56.4%
/-rgt-identity56.4%
exp-056.4%
associate-*l/56.4%
cos-neg56.4%
associate-*l*56.4%
associate-*r/56.4%
exp-056.4%
/-rgt-identity56.4%
*-commutative56.4%
neg-sub056.4%
cos-neg56.4%
Simplified56.4%
Taylor expanded in im around 0 49.5%
Taylor expanded in re around 0 34.7%
Final simplification28.3%
(FPCore (re im)
:precision binary64
(if (<= im 1.7e-8)
(* 0.5 (* (cos re) (* -2.0 im)))
(if (<= im 1.15e+108)
(* 0.5 (* im (+ -2.0 (pow re 2.0))))
(* 0.5 (* im (- (* -0.3333333333333333 (pow im 2.0)) 2.0))))))
double code(double re, double im) {
double tmp;
if (im <= 1.7e-8) {
tmp = 0.5 * (cos(re) * (-2.0 * im));
} else if (im <= 1.15e+108) {
tmp = 0.5 * (im * (-2.0 + pow(re, 2.0)));
} else {
tmp = 0.5 * (im * ((-0.3333333333333333 * pow(im, 2.0)) - 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 <= 1.7d-8) then
tmp = 0.5d0 * (cos(re) * ((-2.0d0) * im))
else if (im <= 1.15d+108) then
tmp = 0.5d0 * (im * ((-2.0d0) + (re ** 2.0d0)))
else
tmp = 0.5d0 * (im * (((-0.3333333333333333d0) * (im ** 2.0d0)) - 2.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.7e-8) {
tmp = 0.5 * (Math.cos(re) * (-2.0 * im));
} else if (im <= 1.15e+108) {
tmp = 0.5 * (im * (-2.0 + Math.pow(re, 2.0)));
} else {
tmp = 0.5 * (im * ((-0.3333333333333333 * Math.pow(im, 2.0)) - 2.0));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.7e-8: tmp = 0.5 * (math.cos(re) * (-2.0 * im)) elif im <= 1.15e+108: tmp = 0.5 * (im * (-2.0 + math.pow(re, 2.0))) else: tmp = 0.5 * (im * ((-0.3333333333333333 * math.pow(im, 2.0)) - 2.0)) return tmp
function code(re, im) tmp = 0.0 if (im <= 1.7e-8) tmp = Float64(0.5 * Float64(cos(re) * Float64(-2.0 * im))); elseif (im <= 1.15e+108) tmp = Float64(0.5 * Float64(im * Float64(-2.0 + (re ^ 2.0)))); else tmp = Float64(0.5 * Float64(im * Float64(Float64(-0.3333333333333333 * (im ^ 2.0)) - 2.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.7e-8) tmp = 0.5 * (cos(re) * (-2.0 * im)); elseif (im <= 1.15e+108) tmp = 0.5 * (im * (-2.0 + (re ^ 2.0))); else tmp = 0.5 * (im * ((-0.3333333333333333 * (im ^ 2.0)) - 2.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.7e-8], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(-2.0 * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.15e+108], N[(0.5 * N[(im * N[(-2.0 + N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[(N[(-0.3333333333333333 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.7 \cdot 10^{-8}:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(-2 \cdot im\right)\right)\\
\mathbf{elif}\;im \leq 1.15 \cdot 10^{+108}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(-2 + {re}^{2}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)\\
\end{array}
\end{array}
if im < 1.7e-8Initial program 39.3%
/-rgt-identity39.3%
exp-039.3%
associate-*l/39.3%
cos-neg39.3%
associate-*l*39.3%
associate-*r/39.3%
exp-039.3%
/-rgt-identity39.3%
*-commutative39.3%
neg-sub039.3%
cos-neg39.3%
Simplified39.3%
Taylor expanded in im around 0 66.6%
if 1.7e-8 < im < 1.1499999999999999e108Initial program 98.1%
/-rgt-identity98.1%
exp-098.1%
associate-*l/98.1%
cos-neg98.1%
associate-*l*98.1%
associate-*r/98.1%
exp-098.1%
/-rgt-identity98.1%
*-commutative98.1%
neg-sub098.1%
cos-neg98.1%
Simplified98.1%
Taylor expanded in im around 0 8.6%
Taylor expanded in re around 0 23.3%
*-commutative23.3%
distribute-lft-out23.3%
Simplified23.3%
if 1.1499999999999999e108 < im Initial program 100.0%
/-rgt-identity100.0%
exp-0100.0%
associate-*l/100.0%
cos-neg100.0%
associate-*l*100.0%
associate-*r/100.0%
exp-0100.0%
/-rgt-identity100.0%
*-commutative100.0%
neg-sub0100.0%
cos-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in re around 0 74.5%
Final simplification65.0%
(FPCore (re im) :precision binary64 (if (<= im 1.7e-8) (* 0.5 (* (cos re) (* -2.0 im))) (* 0.5 (* im (+ -2.0 (pow re 2.0))))))
double code(double re, double im) {
double tmp;
if (im <= 1.7e-8) {
tmp = 0.5 * (cos(re) * (-2.0 * im));
} else {
tmp = 0.5 * (im * (-2.0 + pow(re, 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 <= 1.7d-8) then
tmp = 0.5d0 * (cos(re) * ((-2.0d0) * im))
else
tmp = 0.5d0 * (im * ((-2.0d0) + (re ** 2.0d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.7e-8) {
tmp = 0.5 * (Math.cos(re) * (-2.0 * im));
} else {
tmp = 0.5 * (im * (-2.0 + Math.pow(re, 2.0)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.7e-8: tmp = 0.5 * (math.cos(re) * (-2.0 * im)) else: tmp = 0.5 * (im * (-2.0 + math.pow(re, 2.0))) return tmp
function code(re, im) tmp = 0.0 if (im <= 1.7e-8) tmp = Float64(0.5 * Float64(cos(re) * Float64(-2.0 * im))); else tmp = Float64(0.5 * Float64(im * Float64(-2.0 + (re ^ 2.0)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.7e-8) tmp = 0.5 * (cos(re) * (-2.0 * im)); else tmp = 0.5 * (im * (-2.0 + (re ^ 2.0))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.7e-8], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(-2.0 * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[(-2.0 + N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.7 \cdot 10^{-8}:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(-2 \cdot im\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(-2 + {re}^{2}\right)\right)\\
\end{array}
\end{array}
if im < 1.7e-8Initial program 39.3%
/-rgt-identity39.3%
exp-039.3%
associate-*l/39.3%
cos-neg39.3%
associate-*l*39.3%
associate-*r/39.3%
exp-039.3%
/-rgt-identity39.3%
*-commutative39.3%
neg-sub039.3%
cos-neg39.3%
Simplified39.3%
Taylor expanded in im around 0 66.6%
if 1.7e-8 < im Initial program 99.5%
/-rgt-identity99.5%
exp-099.5%
associate-*l/99.5%
cos-neg99.5%
associate-*l*99.5%
associate-*r/99.5%
exp-099.5%
/-rgt-identity99.5%
*-commutative99.5%
neg-sub099.5%
cos-neg99.5%
Simplified99.5%
Taylor expanded in im around 0 7.1%
Taylor expanded in re around 0 21.9%
*-commutative21.9%
distribute-lft-out21.9%
Simplified21.9%
Final simplification54.4%
(FPCore (re im) :precision binary64 (if (<= im 82000000.0) (* 0.5 (* (cos re) (* -2.0 im))) (* 0.5 (* im (pow re 2.0)))))
double code(double re, double im) {
double tmp;
if (im <= 82000000.0) {
tmp = 0.5 * (cos(re) * (-2.0 * im));
} else {
tmp = 0.5 * (im * pow(re, 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 <= 82000000.0d0) then
tmp = 0.5d0 * (cos(re) * ((-2.0d0) * im))
else
tmp = 0.5d0 * (im * (re ** 2.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 82000000.0) {
tmp = 0.5 * (Math.cos(re) * (-2.0 * im));
} else {
tmp = 0.5 * (im * Math.pow(re, 2.0));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 82000000.0: tmp = 0.5 * (math.cos(re) * (-2.0 * im)) else: tmp = 0.5 * (im * math.pow(re, 2.0)) return tmp
function code(re, im) tmp = 0.0 if (im <= 82000000.0) tmp = Float64(0.5 * Float64(cos(re) * Float64(-2.0 * im))); else tmp = Float64(0.5 * Float64(im * (re ^ 2.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 82000000.0) tmp = 0.5 * (cos(re) * (-2.0 * im)); else tmp = 0.5 * (im * (re ^ 2.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 82000000.0], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(-2.0 * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 82000000:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(-2 \cdot im\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot {re}^{2}\right)\\
\end{array}
\end{array}
if im < 8.2e7Initial program 39.8%
/-rgt-identity39.8%
exp-039.8%
associate-*l/39.8%
cos-neg39.8%
associate-*l*39.8%
associate-*r/39.8%
exp-039.8%
/-rgt-identity39.8%
*-commutative39.8%
neg-sub039.8%
cos-neg39.8%
Simplified39.8%
Taylor expanded in im around 0 66.5%
if 8.2e7 < im Initial program 100.0%
/-rgt-identity100.0%
exp-0100.0%
associate-*l/100.0%
cos-neg100.0%
associate-*l*100.0%
associate-*r/100.0%
exp-0100.0%
/-rgt-identity100.0%
*-commutative100.0%
neg-sub0100.0%
cos-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 5.8%
Taylor expanded in re around 0 21.0%
Taylor expanded in re around inf 18.6%
Final simplification53.8%
(FPCore (re im) :precision binary64 (* 0.5 (* -2.0 im)))
double code(double re, double im) {
return 0.5 * (-2.0 * im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * ((-2.0d0) * im)
end function
public static double code(double re, double im) {
return 0.5 * (-2.0 * im);
}
def code(re, im): return 0.5 * (-2.0 * im)
function code(re, im) return Float64(0.5 * Float64(-2.0 * im)) end
function tmp = code(re, im) tmp = 0.5 * (-2.0 * im); end
code[re_, im_] := N[(0.5 * N[(-2.0 * im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(-2 \cdot im\right)
\end{array}
Initial program 55.8%
/-rgt-identity55.8%
exp-055.8%
associate-*l/55.8%
cos-neg55.8%
associate-*l*55.8%
associate-*r/55.8%
exp-055.8%
/-rgt-identity55.8%
*-commutative55.8%
neg-sub055.8%
cos-neg55.8%
Simplified55.8%
Taylor expanded in im around 0 50.4%
Taylor expanded in re around 0 27.1%
(FPCore (re im)
:precision binary64
(if (< (fabs im) 1.0)
(-
(*
(cos re)
(+
(+ im (* (* (* 0.16666666666666666 im) im) im))
(* (* (* (* (* 0.008333333333333333 im) im) im) im) im))))
(* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im)))))
double code(double re, double im) {
double tmp;
if (fabs(im) < 1.0) {
tmp = -(cos(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im)));
} else {
tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (abs(im) < 1.0d0) then
tmp = -(cos(re) * ((im + (((0.16666666666666666d0 * im) * im) * im)) + (((((0.008333333333333333d0 * im) * im) * im) * im) * im)))
else
tmp = (0.5d0 * cos(re)) * (exp((0.0d0 - im)) - exp(im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (Math.abs(im) < 1.0) {
tmp = -(Math.cos(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im)));
} else {
tmp = (0.5 * Math.cos(re)) * (Math.exp((0.0 - im)) - Math.exp(im));
}
return tmp;
}
def code(re, im): tmp = 0 if math.fabs(im) < 1.0: tmp = -(math.cos(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im))) else: tmp = (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im)) return tmp
function code(re, im) tmp = 0.0 if (abs(im) < 1.0) tmp = Float64(-Float64(cos(re) * Float64(Float64(im + Float64(Float64(Float64(0.16666666666666666 * im) * im) * im)) + Float64(Float64(Float64(Float64(Float64(0.008333333333333333 * im) * im) * im) * im) * im)))); else tmp = Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (abs(im) < 1.0) tmp = -(cos(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im))); else tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im)); end tmp_2 = tmp; end
code[re_, im_] := If[Less[N[Abs[im], $MachinePrecision], 1.0], (-N[(N[Cos[re], $MachinePrecision] * N[(N[(im + N[(N[(N[(0.16666666666666666 * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[(N[(0.008333333333333333 * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|im\right| < 1:\\
\;\;\;\;-\cos re \cdot \left(\left(im + \left(\left(0.16666666666666666 \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(0.008333333333333333 \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\\
\end{array}
\end{array}
herbie shell --seed 2024111
(FPCore (re im)
:name "math.sin on complex, imaginary part"
:precision binary64
:alt
(if (< (fabs im) 1.0) (- (* (cos re) (+ (+ im (* (* (* 0.16666666666666666 im) im) im)) (* (* (* (* (* 0.008333333333333333 im) im) im) im) im)))) (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
(* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))