
(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 (* im (* -2.0 (cos re)))))))
double code(double re, double im) {
return 0.5 * log1p(expm1((im * (-2.0 * cos(re)))));
}
public static double code(double re, double im) {
return 0.5 * Math.log1p(Math.expm1((im * (-2.0 * Math.cos(re)))));
}
def code(re, im): return 0.5 * math.log1p(math.expm1((im * (-2.0 * math.cos(re)))))
function code(re, im) return Float64(0.5 * log1p(expm1(Float64(im * Float64(-2.0 * cos(re)))))) end
code[re_, im_] := N[(0.5 * N[Log[1 + N[(Exp[N[(im * N[(-2.0 * N[Cos[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot \left(-2 \cdot \cos re\right)\right)\right)
\end{array}
Initial program 53.7%
sub-neg53.7%
neg-sub053.7%
remove-double-neg53.7%
remove-double-neg53.7%
sub0-neg53.7%
distribute-neg-in53.7%
+-commutative53.7%
sub-neg53.7%
cos-neg53.7%
associate-*l*53.7%
distribute-rgt-neg-in53.7%
*-commutative53.7%
Simplified53.7%
Taylor expanded in im around 0 52.9%
log1p-expm1-u98.7%
*-commutative98.7%
associate-*l*98.7%
Applied egg-rr98.7%
Final simplification98.7%
(FPCore (re im)
:precision binary64
(if (<= im 0.104)
(* 0.5 (* (cos re) (+ (* im -2.0) (* -0.3333333333333333 (pow im 3.0)))))
(if (<= im 5.6e+102)
(* 0.5 (- (exp (- im)) (exp im)))
(* (cos re) (* (pow im 3.0) -0.16666666666666666)))))
double code(double re, double im) {
double tmp;
if (im <= 0.104) {
tmp = 0.5 * (cos(re) * ((im * -2.0) + (-0.3333333333333333 * pow(im, 3.0))));
} else if (im <= 5.6e+102) {
tmp = 0.5 * (exp(-im) - exp(im));
} else {
tmp = cos(re) * (pow(im, 3.0) * -0.16666666666666666);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 0.104d0) then
tmp = 0.5d0 * (cos(re) * ((im * (-2.0d0)) + ((-0.3333333333333333d0) * (im ** 3.0d0))))
else if (im <= 5.6d+102) then
tmp = 0.5d0 * (exp(-im) - exp(im))
else
tmp = cos(re) * ((im ** 3.0d0) * (-0.16666666666666666d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 0.104) {
tmp = 0.5 * (Math.cos(re) * ((im * -2.0) + (-0.3333333333333333 * Math.pow(im, 3.0))));
} else if (im <= 5.6e+102) {
tmp = 0.5 * (Math.exp(-im) - Math.exp(im));
} else {
tmp = Math.cos(re) * (Math.pow(im, 3.0) * -0.16666666666666666);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 0.104: tmp = 0.5 * (math.cos(re) * ((im * -2.0) + (-0.3333333333333333 * math.pow(im, 3.0)))) elif im <= 5.6e+102: tmp = 0.5 * (math.exp(-im) - math.exp(im)) else: tmp = math.cos(re) * (math.pow(im, 3.0) * -0.16666666666666666) return tmp
function code(re, im) tmp = 0.0 if (im <= 0.104) tmp = Float64(0.5 * Float64(cos(re) * Float64(Float64(im * -2.0) + Float64(-0.3333333333333333 * (im ^ 3.0))))); elseif (im <= 5.6e+102) tmp = Float64(0.5 * Float64(exp(Float64(-im)) - exp(im))); else tmp = Float64(cos(re) * Float64((im ^ 3.0) * -0.16666666666666666)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 0.104) tmp = 0.5 * (cos(re) * ((im * -2.0) + (-0.3333333333333333 * (im ^ 3.0)))); elseif (im <= 5.6e+102) tmp = 0.5 * (exp(-im) - exp(im)); else tmp = cos(re) * ((im ^ 3.0) * -0.16666666666666666); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 0.104], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(N[(im * -2.0), $MachinePrecision] + N[(-0.3333333333333333 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 5.6e+102], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.104:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2 + -0.3333333333333333 \cdot {im}^{3}\right)\right)\\
\mathbf{elif}\;im \leq 5.6 \cdot 10^{+102}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666\right)\\
\end{array}
\end{array}
if im < 0.103999999999999995Initial program 38.6%
sub-neg38.6%
neg-sub038.6%
remove-double-neg38.6%
remove-double-neg38.6%
sub0-neg38.6%
distribute-neg-in38.6%
+-commutative38.6%
sub-neg38.6%
cos-neg38.6%
associate-*l*38.6%
distribute-rgt-neg-in38.6%
*-commutative38.6%
Simplified38.6%
Taylor expanded in im around 0 90.4%
if 0.103999999999999995 < im < 5.60000000000000037e102Initial program 100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
remove-double-neg100.0%
sub0-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
sub-neg100.0%
cos-neg100.0%
associate-*l*100.0%
distribute-rgt-neg-in100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in re around 0 81.8%
if 5.60000000000000037e102 < im Initial program 100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
remove-double-neg100.0%
sub0-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
sub-neg100.0%
cos-neg100.0%
associate-*l*100.0%
distribute-rgt-neg-in100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in im around inf 100.0%
Taylor expanded in im around 0 100.0%
associate-*r*100.0%
*-commutative100.0%
*-commutative100.0%
Simplified100.0%
Final simplification91.2%
(FPCore (re im)
:precision binary64
(if (<= im 460.0)
(* 0.5 (* (cos re) (* im -2.0)))
(if (<= im 5.6e+102)
(* 0.5 (log1p (expm1 (* im -2.0))))
(* (cos re) (* (pow im 3.0) -0.16666666666666666)))))
double code(double re, double im) {
double tmp;
if (im <= 460.0) {
tmp = 0.5 * (cos(re) * (im * -2.0));
} else if (im <= 5.6e+102) {
tmp = 0.5 * log1p(expm1((im * -2.0)));
} else {
tmp = cos(re) * (pow(im, 3.0) * -0.16666666666666666);
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (im <= 460.0) {
tmp = 0.5 * (Math.cos(re) * (im * -2.0));
} else if (im <= 5.6e+102) {
tmp = 0.5 * Math.log1p(Math.expm1((im * -2.0)));
} else {
tmp = Math.cos(re) * (Math.pow(im, 3.0) * -0.16666666666666666);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 460.0: tmp = 0.5 * (math.cos(re) * (im * -2.0)) elif im <= 5.6e+102: tmp = 0.5 * math.log1p(math.expm1((im * -2.0))) else: tmp = math.cos(re) * (math.pow(im, 3.0) * -0.16666666666666666) return tmp
function code(re, im) tmp = 0.0 if (im <= 460.0) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * -2.0))); elseif (im <= 5.6e+102) tmp = Float64(0.5 * log1p(expm1(Float64(im * -2.0)))); else tmp = Float64(cos(re) * Float64((im ^ 3.0) * -0.16666666666666666)); end return tmp end
code[re_, im_] := If[LessEqual[im, 460.0], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 5.6e+102], N[(0.5 * N[Log[1 + N[(Exp[N[(im * -2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 460:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\
\mathbf{elif}\;im \leq 5.6 \cdot 10^{+102}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666\right)\\
\end{array}
\end{array}
if im < 460Initial program 38.6%
sub-neg38.6%
neg-sub038.6%
remove-double-neg38.6%
remove-double-neg38.6%
sub0-neg38.6%
distribute-neg-in38.6%
+-commutative38.6%
sub-neg38.6%
cos-neg38.6%
associate-*l*38.6%
distribute-rgt-neg-in38.6%
*-commutative38.6%
Simplified38.6%
Taylor expanded in im around 0 68.3%
if 460 < im < 5.60000000000000037e102Initial program 100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
remove-double-neg100.0%
sub0-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
sub-neg100.0%
cos-neg100.0%
associate-*l*100.0%
distribute-rgt-neg-in100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in im around 0 3.6%
log1p-expm1-u96.1%
*-commutative96.1%
associate-*l*96.1%
Applied egg-rr96.1%
Taylor expanded in re around 0 77.9%
expm1-def77.9%
Simplified77.9%
if 5.60000000000000037e102 < im Initial program 100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
remove-double-neg100.0%
sub0-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
sub-neg100.0%
cos-neg100.0%
associate-*l*100.0%
distribute-rgt-neg-in100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in im around inf 100.0%
Taylor expanded in im around 0 100.0%
associate-*r*100.0%
*-commutative100.0%
*-commutative100.0%
Simplified100.0%
Final simplification74.2%
(FPCore (re im)
:precision binary64
(if (<= im 0.00155)
(* 0.5 (* (cos re) (* im -2.0)))
(if (<= im 5.6e+102)
(* 0.5 (- (exp (- im)) (exp im)))
(* (cos re) (* (pow im 3.0) -0.16666666666666666)))))
double code(double re, double im) {
double tmp;
if (im <= 0.00155) {
tmp = 0.5 * (cos(re) * (im * -2.0));
} else if (im <= 5.6e+102) {
tmp = 0.5 * (exp(-im) - exp(im));
} else {
tmp = cos(re) * (pow(im, 3.0) * -0.16666666666666666);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 0.00155d0) then
tmp = 0.5d0 * (cos(re) * (im * (-2.0d0)))
else if (im <= 5.6d+102) then
tmp = 0.5d0 * (exp(-im) - exp(im))
else
tmp = cos(re) * ((im ** 3.0d0) * (-0.16666666666666666d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 0.00155) {
tmp = 0.5 * (Math.cos(re) * (im * -2.0));
} else if (im <= 5.6e+102) {
tmp = 0.5 * (Math.exp(-im) - Math.exp(im));
} else {
tmp = Math.cos(re) * (Math.pow(im, 3.0) * -0.16666666666666666);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 0.00155: tmp = 0.5 * (math.cos(re) * (im * -2.0)) elif im <= 5.6e+102: tmp = 0.5 * (math.exp(-im) - math.exp(im)) else: tmp = math.cos(re) * (math.pow(im, 3.0) * -0.16666666666666666) return tmp
function code(re, im) tmp = 0.0 if (im <= 0.00155) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * -2.0))); elseif (im <= 5.6e+102) tmp = Float64(0.5 * Float64(exp(Float64(-im)) - exp(im))); else tmp = Float64(cos(re) * Float64((im ^ 3.0) * -0.16666666666666666)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 0.00155) tmp = 0.5 * (cos(re) * (im * -2.0)); elseif (im <= 5.6e+102) tmp = 0.5 * (exp(-im) - exp(im)); else tmp = cos(re) * ((im ^ 3.0) * -0.16666666666666666); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 0.00155], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 5.6e+102], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.00155:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\
\mathbf{elif}\;im \leq 5.6 \cdot 10^{+102}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666\right)\\
\end{array}
\end{array}
if im < 0.00154999999999999995Initial program 38.3%
sub-neg38.3%
neg-sub038.3%
remove-double-neg38.3%
remove-double-neg38.3%
sub0-neg38.3%
distribute-neg-in38.3%
+-commutative38.3%
sub-neg38.3%
cos-neg38.3%
associate-*l*38.3%
distribute-rgt-neg-in38.3%
*-commutative38.3%
Simplified38.3%
Taylor expanded in im around 0 68.5%
if 0.00154999999999999995 < im < 5.60000000000000037e102Initial program 99.7%
sub-neg99.7%
neg-sub099.7%
remove-double-neg99.7%
remove-double-neg99.7%
sub0-neg99.7%
distribute-neg-in99.7%
+-commutative99.7%
sub-neg99.7%
cos-neg99.7%
associate-*l*99.7%
distribute-rgt-neg-in99.7%
*-commutative99.7%
Simplified99.7%
Taylor expanded in re around 0 79.5%
if 5.60000000000000037e102 < im Initial program 100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
remove-double-neg100.0%
sub0-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
sub-neg100.0%
cos-neg100.0%
associate-*l*100.0%
distribute-rgt-neg-in100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in im around inf 100.0%
Taylor expanded in im around 0 100.0%
associate-*r*100.0%
*-commutative100.0%
*-commutative100.0%
Simplified100.0%
Final simplification74.5%
(FPCore (re im) :precision binary64 (if (<= im 410.0) (* 0.5 (* (cos re) (* im -2.0))) (* 0.5 (log1p (expm1 (* im -2.0))))))
double code(double re, double im) {
double tmp;
if (im <= 410.0) {
tmp = 0.5 * (cos(re) * (im * -2.0));
} else {
tmp = 0.5 * log1p(expm1((im * -2.0)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (im <= 410.0) {
tmp = 0.5 * (Math.cos(re) * (im * -2.0));
} else {
tmp = 0.5 * Math.log1p(Math.expm1((im * -2.0)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 410.0: tmp = 0.5 * (math.cos(re) * (im * -2.0)) else: tmp = 0.5 * math.log1p(math.expm1((im * -2.0))) return tmp
function code(re, im) tmp = 0.0 if (im <= 410.0) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * -2.0))); else tmp = Float64(0.5 * log1p(expm1(Float64(im * -2.0)))); end return tmp end
code[re_, im_] := If[LessEqual[im, 410.0], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Log[1 + N[(Exp[N[(im * -2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 410:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\
\end{array}
\end{array}
if im < 410Initial program 38.6%
sub-neg38.6%
neg-sub038.6%
remove-double-neg38.6%
remove-double-neg38.6%
sub0-neg38.6%
distribute-neg-in38.6%
+-commutative38.6%
sub-neg38.6%
cos-neg38.6%
associate-*l*38.6%
distribute-rgt-neg-in38.6%
*-commutative38.6%
Simplified38.6%
Taylor expanded in im around 0 68.3%
if 410 < im Initial program 100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
remove-double-neg100.0%
sub0-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
sub-neg100.0%
cos-neg100.0%
associate-*l*100.0%
distribute-rgt-neg-in100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in im around 0 5.5%
log1p-expm1-u98.6%
*-commutative98.6%
associate-*l*98.6%
Applied egg-rr98.6%
Taylor expanded in re around 0 74.8%
expm1-def74.8%
Simplified74.8%
Final simplification69.9%
(FPCore (re im) :precision binary64 (if (<= im 3.2e-7) (* 0.5 (* (cos re) (* im -2.0))) (* 0.5 (+ (* im -2.0) (* -0.3333333333333333 (pow im 3.0))))))
double code(double re, double im) {
double tmp;
if (im <= 3.2e-7) {
tmp = 0.5 * (cos(re) * (im * -2.0));
} else {
tmp = 0.5 * ((im * -2.0) + (-0.3333333333333333 * pow(im, 3.0)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 3.2d-7) then
tmp = 0.5d0 * (cos(re) * (im * (-2.0d0)))
else
tmp = 0.5d0 * ((im * (-2.0d0)) + ((-0.3333333333333333d0) * (im ** 3.0d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 3.2e-7) {
tmp = 0.5 * (Math.cos(re) * (im * -2.0));
} else {
tmp = 0.5 * ((im * -2.0) + (-0.3333333333333333 * Math.pow(im, 3.0)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 3.2e-7: tmp = 0.5 * (math.cos(re) * (im * -2.0)) else: tmp = 0.5 * ((im * -2.0) + (-0.3333333333333333 * math.pow(im, 3.0))) return tmp
function code(re, im) tmp = 0.0 if (im <= 3.2e-7) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * -2.0))); else tmp = Float64(0.5 * Float64(Float64(im * -2.0) + Float64(-0.3333333333333333 * (im ^ 3.0)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 3.2e-7) tmp = 0.5 * (cos(re) * (im * -2.0)); else tmp = 0.5 * ((im * -2.0) + (-0.3333333333333333 * (im ^ 3.0))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 3.2e-7], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(im * -2.0), $MachinePrecision] + N[(-0.3333333333333333 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 3.2 \cdot 10^{-7}:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot -2 + -0.3333333333333333 \cdot {im}^{3}\right)\\
\end{array}
\end{array}
if im < 3.2000000000000001e-7Initial program 37.9%
sub-neg37.9%
neg-sub037.9%
remove-double-neg37.9%
remove-double-neg37.9%
sub0-neg37.9%
distribute-neg-in37.9%
+-commutative37.9%
sub-neg37.9%
cos-neg37.9%
associate-*l*37.9%
distribute-rgt-neg-in37.9%
*-commutative37.9%
Simplified37.9%
Taylor expanded in im around 0 68.3%
if 3.2000000000000001e-7 < im Initial program 99.0%
sub-neg99.0%
neg-sub099.0%
remove-double-neg99.0%
remove-double-neg99.0%
sub0-neg99.0%
distribute-neg-in99.0%
+-commutative99.0%
sub-neg99.0%
cos-neg99.0%
associate-*l*99.0%
distribute-rgt-neg-in99.0%
*-commutative99.0%
Simplified99.0%
Taylor expanded in im around 0 68.0%
Taylor expanded in re around 0 50.4%
Final simplification63.7%
(FPCore (re im) :precision binary64 (if (<= im 1.9e+55) (* 0.5 (* (cos re) (* im -2.0))) (* (pow im 3.0) -0.16666666666666666)))
double code(double re, double im) {
double tmp;
if (im <= 1.9e+55) {
tmp = 0.5 * (cos(re) * (im * -2.0));
} else {
tmp = pow(im, 3.0) * -0.16666666666666666;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 1.9d+55) then
tmp = 0.5d0 * (cos(re) * (im * (-2.0d0)))
else
tmp = (im ** 3.0d0) * (-0.16666666666666666d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.9e+55) {
tmp = 0.5 * (Math.cos(re) * (im * -2.0));
} else {
tmp = Math.pow(im, 3.0) * -0.16666666666666666;
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.9e+55: tmp = 0.5 * (math.cos(re) * (im * -2.0)) else: tmp = math.pow(im, 3.0) * -0.16666666666666666 return tmp
function code(re, im) tmp = 0.0 if (im <= 1.9e+55) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * -2.0))); else tmp = Float64((im ^ 3.0) * -0.16666666666666666); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.9e+55) tmp = 0.5 * (cos(re) * (im * -2.0)); else tmp = (im ^ 3.0) * -0.16666666666666666; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.9e+55], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.9 \cdot 10^{+55}:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;{im}^{3} \cdot -0.16666666666666666\\
\end{array}
\end{array}
if im < 1.9e55Initial program 41.3%
sub-neg41.3%
neg-sub041.3%
remove-double-neg41.3%
remove-double-neg41.3%
sub0-neg41.3%
distribute-neg-in41.3%
+-commutative41.3%
sub-neg41.3%
cos-neg41.3%
associate-*l*41.3%
distribute-rgt-neg-in41.3%
*-commutative41.3%
Simplified41.3%
Taylor expanded in im around 0 65.4%
if 1.9e55 < im Initial program 100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
remove-double-neg100.0%
sub0-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
sub-neg100.0%
cos-neg100.0%
associate-*l*100.0%
distribute-rgt-neg-in100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in im around 0 77.5%
Taylor expanded in im around inf 77.5%
Taylor expanded in re around 0 56.9%
*-commutative56.9%
Simplified56.9%
Final simplification63.6%
(FPCore (re im) :precision binary64 (if (<= im 2.4) (* 0.5 (* im -2.0)) (* (pow im 3.0) -0.16666666666666666)))
double code(double re, double im) {
double tmp;
if (im <= 2.4) {
tmp = 0.5 * (im * -2.0);
} else {
tmp = pow(im, 3.0) * -0.16666666666666666;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 2.4d0) then
tmp = 0.5d0 * (im * (-2.0d0))
else
tmp = (im ** 3.0d0) * (-0.16666666666666666d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 2.4) {
tmp = 0.5 * (im * -2.0);
} else {
tmp = Math.pow(im, 3.0) * -0.16666666666666666;
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 2.4: tmp = 0.5 * (im * -2.0) else: tmp = math.pow(im, 3.0) * -0.16666666666666666 return tmp
function code(re, im) tmp = 0.0 if (im <= 2.4) tmp = Float64(0.5 * Float64(im * -2.0)); else tmp = Float64((im ^ 3.0) * -0.16666666666666666); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 2.4) tmp = 0.5 * (im * -2.0); else tmp = (im ^ 3.0) * -0.16666666666666666; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 2.4], N[(0.5 * N[(im * -2.0), $MachinePrecision]), $MachinePrecision], N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 2.4:\\
\;\;\;\;0.5 \cdot \left(im \cdot -2\right)\\
\mathbf{else}:\\
\;\;\;\;{im}^{3} \cdot -0.16666666666666666\\
\end{array}
\end{array}
if im < 2.39999999999999991Initial program 38.6%
sub-neg38.6%
neg-sub038.6%
remove-double-neg38.6%
remove-double-neg38.6%
sub0-neg38.6%
distribute-neg-in38.6%
+-commutative38.6%
sub-neg38.6%
cos-neg38.6%
associate-*l*38.6%
distribute-rgt-neg-in38.6%
*-commutative38.6%
Simplified38.6%
Taylor expanded in im around 0 68.3%
Taylor expanded in re around 0 42.3%
if 2.39999999999999991 < im Initial program 100.0%
sub-neg100.0%
neg-sub0100.0%
remove-double-neg100.0%
remove-double-neg100.0%
sub0-neg100.0%
distribute-neg-in100.0%
+-commutative100.0%
sub-neg100.0%
cos-neg100.0%
associate-*l*100.0%
distribute-rgt-neg-in100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in im around 0 67.0%
Taylor expanded in im around inf 67.0%
Taylor expanded in re around 0 49.2%
*-commutative49.2%
Simplified49.2%
Final simplification44.0%
(FPCore (re im) :precision binary64 (* 0.5 (* im -2.0)))
double code(double re, double im) {
return 0.5 * (im * -2.0);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * (im * (-2.0d0))
end function
public static double code(double re, double im) {
return 0.5 * (im * -2.0);
}
def code(re, im): return 0.5 * (im * -2.0)
function code(re, im) return Float64(0.5 * Float64(im * -2.0)) end
function tmp = code(re, im) tmp = 0.5 * (im * -2.0); end
code[re_, im_] := N[(0.5 * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(im \cdot -2\right)
\end{array}
Initial program 53.7%
sub-neg53.7%
neg-sub053.7%
remove-double-neg53.7%
remove-double-neg53.7%
sub0-neg53.7%
distribute-neg-in53.7%
+-commutative53.7%
sub-neg53.7%
cos-neg53.7%
associate-*l*53.7%
distribute-rgt-neg-in53.7%
*-commutative53.7%
Simplified53.7%
Taylor expanded in im around 0 52.9%
Taylor expanded in re around 0 32.9%
Final simplification32.9%
(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}
Initial program 53.7%
sub-neg53.7%
neg-sub053.7%
remove-double-neg53.7%
remove-double-neg53.7%
sub0-neg53.7%
distribute-neg-in53.7%
+-commutative53.7%
sub-neg53.7%
cos-neg53.7%
associate-*l*53.7%
distribute-rgt-neg-in53.7%
*-commutative53.7%
Simplified53.7%
Applied egg-rr2.9%
Taylor expanded in re around 0 2.9%
Final simplification2.9%
(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 2024019
(FPCore (re im)
:name "math.sin on complex, imaginary part"
:precision binary64
:herbie-target
(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))))