
(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 58.4%
/-rgt-identity58.4%
exp-058.4%
associate-*l/58.4%
cos-neg58.4%
associate-*l*58.4%
associate-*r/58.4%
exp-058.4%
/-rgt-identity58.4%
*-commutative58.4%
neg-sub058.4%
cos-neg58.4%
Simplified58.4%
Taylor expanded in im around 0 48.6%
log1p-expm1-u98.9%
*-commutative98.9%
associate-*l*98.9%
Applied egg-rr98.9%
(FPCore (re im)
:precision binary64
(if (<= re 3e-42)
(* 0.5 (log1p (expm1 (* im -2.0))))
(*
0.5
(* im (* (cos re) (- (* -0.0003968253968253968 (pow im 6.0)) 2.0))))))
double code(double re, double im) {
double tmp;
if (re <= 3e-42) {
tmp = 0.5 * log1p(expm1((im * -2.0)));
} else {
tmp = 0.5 * (im * (cos(re) * ((-0.0003968253968253968 * pow(im, 6.0)) - 2.0)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= 3e-42) {
tmp = 0.5 * Math.log1p(Math.expm1((im * -2.0)));
} else {
tmp = 0.5 * (im * (Math.cos(re) * ((-0.0003968253968253968 * Math.pow(im, 6.0)) - 2.0)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 3e-42: tmp = 0.5 * math.log1p(math.expm1((im * -2.0))) else: tmp = 0.5 * (im * (math.cos(re) * ((-0.0003968253968253968 * math.pow(im, 6.0)) - 2.0))) return tmp
function code(re, im) tmp = 0.0 if (re <= 3e-42) tmp = Float64(0.5 * log1p(expm1(Float64(im * -2.0)))); else tmp = Float64(0.5 * Float64(im * Float64(cos(re) * Float64(Float64(-0.0003968253968253968 * (im ^ 6.0)) - 2.0)))); end return tmp end
code[re_, im_] := If[LessEqual[re, 3e-42], N[(0.5 * N[Log[1 + N[(Exp[N[(im * -2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[(N[Cos[re], $MachinePrecision] * N[(N[(-0.0003968253968253968 * N[Power[im, 6.0], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 3 \cdot 10^{-42}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(\cos re \cdot \left(-0.0003968253968253968 \cdot {im}^{6} - 2\right)\right)\right)\\
\end{array}
\end{array}
if re < 3.00000000000000027e-42Initial program 58.9%
/-rgt-identity58.9%
exp-058.9%
associate-*l/58.9%
cos-neg58.9%
associate-*l*58.9%
associate-*r/58.9%
exp-058.9%
/-rgt-identity58.9%
*-commutative58.9%
neg-sub058.9%
cos-neg58.9%
Simplified58.9%
Taylor expanded in im around 0 47.6%
log1p-expm1-u99.3%
*-commutative99.3%
associate-*l*99.3%
Applied egg-rr99.3%
Taylor expanded in re around 0 47.0%
expm1-define76.5%
Simplified76.5%
if 3.00000000000000027e-42 < re Initial program 56.9%
/-rgt-identity56.9%
exp-056.9%
associate-*l/56.9%
cos-neg56.9%
associate-*l*56.9%
associate-*r/56.9%
exp-056.9%
/-rgt-identity56.9%
*-commutative56.9%
neg-sub056.9%
cos-neg56.9%
Simplified56.9%
Taylor expanded in im around 0 93.2%
Simplified93.2%
Taylor expanded in re around inf 93.2%
Taylor expanded in im around inf 92.4%
Final simplification80.8%
(FPCore (re im)
:precision binary64
(if (<= im 500.0)
(* (cos re) (- (* -0.16666666666666666 (pow im 3.0)) im))
(if (<= im 9e+38)
(* 0.5 (log1p (expm1 (* im -2.0))))
(* (* (cos re) (pow im 7.0)) -0.0001984126984126984))))
double code(double re, double im) {
double tmp;
if (im <= 500.0) {
tmp = cos(re) * ((-0.16666666666666666 * pow(im, 3.0)) - im);
} else if (im <= 9e+38) {
tmp = 0.5 * log1p(expm1((im * -2.0)));
} else {
tmp = (cos(re) * pow(im, 7.0)) * -0.0001984126984126984;
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (im <= 500.0) {
tmp = Math.cos(re) * ((-0.16666666666666666 * Math.pow(im, 3.0)) - im);
} else if (im <= 9e+38) {
tmp = 0.5 * Math.log1p(Math.expm1((im * -2.0)));
} else {
tmp = (Math.cos(re) * Math.pow(im, 7.0)) * -0.0001984126984126984;
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 500.0: tmp = math.cos(re) * ((-0.16666666666666666 * math.pow(im, 3.0)) - im) elif im <= 9e+38: tmp = 0.5 * math.log1p(math.expm1((im * -2.0))) else: tmp = (math.cos(re) * math.pow(im, 7.0)) * -0.0001984126984126984 return tmp
function code(re, im) tmp = 0.0 if (im <= 500.0) tmp = Float64(cos(re) * Float64(Float64(-0.16666666666666666 * (im ^ 3.0)) - im)); elseif (im <= 9e+38) tmp = Float64(0.5 * log1p(expm1(Float64(im * -2.0)))); else tmp = Float64(Float64(cos(re) * (im ^ 7.0)) * -0.0001984126984126984); end return tmp end
code[re_, im_] := If[LessEqual[im, 500.0], N[(N[Cos[re], $MachinePrecision] * N[(N[(-0.16666666666666666 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 9e+38], N[(0.5 * N[Log[1 + N[(Exp[N[(im * -2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[re], $MachinePrecision] * N[Power[im, 7.0], $MachinePrecision]), $MachinePrecision] * -0.0001984126984126984), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 500:\\
\;\;\;\;\cos re \cdot \left(-0.16666666666666666 \cdot {im}^{3} - im\right)\\
\mathbf{elif}\;im \leq 9 \cdot 10^{+38}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\cos re \cdot {im}^{7}\right) \cdot -0.0001984126984126984\\
\end{array}
\end{array}
if im < 500Initial program 43.0%
/-rgt-identity43.0%
exp-043.0%
associate-*l/43.0%
cos-neg43.0%
associate-*l*43.0%
associate-*r/43.0%
exp-043.0%
/-rgt-identity43.0%
*-commutative43.0%
neg-sub043.0%
cos-neg43.0%
Simplified43.0%
Taylor expanded in im around 0 87.1%
Taylor expanded in im around 0 86.7%
+-commutative86.7%
distribute-rgt-in86.7%
*-commutative86.7%
associate-*r*86.7%
associate-*r*87.1%
unpow287.1%
unpow387.1%
*-commutative87.1%
associate-*l*87.1%
*-commutative87.1%
associate-*l*87.1%
distribute-lft-out87.1%
mul-1-neg87.1%
Simplified87.1%
if 500 < im < 8.99999999999999961e38Initial 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.3%
log1p-expm1-u100.0%
*-commutative100.0%
associate-*l*100.0%
Applied egg-rr100.0%
Taylor expanded in re around 0 57.1%
expm1-define57.1%
Simplified57.1%
if 8.99999999999999961e38 < 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.5%
Simplified98.5%
Taylor expanded in im around inf 98.5%
Taylor expanded in im around 0 98.5%
*-commutative98.5%
*-commutative98.5%
Simplified98.5%
Final simplification89.1%
(FPCore (re im)
:precision binary64
(if (<= im 10.6)
(* im (- (cos re)))
(if (<= im 9e+38)
(* 0.5 (log1p (expm1 (* im -2.0))))
(* (* (cos re) (pow im 7.0)) -0.0001984126984126984))))
double code(double re, double im) {
double tmp;
if (im <= 10.6) {
tmp = im * -cos(re);
} else if (im <= 9e+38) {
tmp = 0.5 * log1p(expm1((im * -2.0)));
} else {
tmp = (cos(re) * pow(im, 7.0)) * -0.0001984126984126984;
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (im <= 10.6) {
tmp = im * -Math.cos(re);
} else if (im <= 9e+38) {
tmp = 0.5 * Math.log1p(Math.expm1((im * -2.0)));
} else {
tmp = (Math.cos(re) * Math.pow(im, 7.0)) * -0.0001984126984126984;
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 10.6: tmp = im * -math.cos(re) elif im <= 9e+38: tmp = 0.5 * math.log1p(math.expm1((im * -2.0))) else: tmp = (math.cos(re) * math.pow(im, 7.0)) * -0.0001984126984126984 return tmp
function code(re, im) tmp = 0.0 if (im <= 10.6) tmp = Float64(im * Float64(-cos(re))); elseif (im <= 9e+38) tmp = Float64(0.5 * log1p(expm1(Float64(im * -2.0)))); else tmp = Float64(Float64(cos(re) * (im ^ 7.0)) * -0.0001984126984126984); end return tmp end
code[re_, im_] := If[LessEqual[im, 10.6], N[(im * (-N[Cos[re], $MachinePrecision])), $MachinePrecision], If[LessEqual[im, 9e+38], N[(0.5 * N[Log[1 + N[(Exp[N[(im * -2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[re], $MachinePrecision] * N[Power[im, 7.0], $MachinePrecision]), $MachinePrecision] * -0.0001984126984126984), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 10.6:\\
\;\;\;\;im \cdot \left(-\cos re\right)\\
\mathbf{elif}\;im \leq 9 \cdot 10^{+38}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\cos re \cdot {im}^{7}\right) \cdot -0.0001984126984126984\\
\end{array}
\end{array}
if im < 10.5999999999999996Initial program 42.7%
/-rgt-identity42.7%
exp-042.7%
associate-*l/42.7%
cos-neg42.7%
associate-*l*42.7%
associate-*r/42.7%
exp-042.7%
/-rgt-identity42.7%
*-commutative42.7%
neg-sub042.7%
cos-neg42.7%
Simplified42.7%
Taylor expanded in im around 0 87.5%
Taylor expanded in im around 0 64.8%
mul-1-neg64.8%
*-commutative64.8%
distribute-rgt-neg-in64.8%
Simplified64.8%
if 10.5999999999999996 < im < 8.99999999999999961e38Initial 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 4.5%
log1p-expm1-u89.1%
*-commutative89.1%
associate-*l*89.1%
Applied egg-rr89.1%
Taylor expanded in re around 0 51.6%
expm1-define51.6%
Simplified51.6%
if 8.99999999999999961e38 < 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.5%
Simplified98.5%
Taylor expanded in im around inf 98.5%
Taylor expanded in im around 0 98.5%
*-commutative98.5%
*-commutative98.5%
Simplified98.5%
Final simplification72.5%
(FPCore (re im)
:precision binary64
(if (<= im 10.5)
(* im (- (cos re)))
(if (<= im 5.6e+102)
(* 0.5 (log1p (expm1 (* im -2.0))))
(* (cos re) (* -0.16666666666666666 (pow im 3.0))))))
double code(double re, double im) {
double tmp;
if (im <= 10.5) {
tmp = im * -cos(re);
} else if (im <= 5.6e+102) {
tmp = 0.5 * log1p(expm1((im * -2.0)));
} else {
tmp = cos(re) * (-0.16666666666666666 * pow(im, 3.0));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (im <= 10.5) {
tmp = im * -Math.cos(re);
} else if (im <= 5.6e+102) {
tmp = 0.5 * Math.log1p(Math.expm1((im * -2.0)));
} else {
tmp = Math.cos(re) * (-0.16666666666666666 * Math.pow(im, 3.0));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 10.5: tmp = im * -math.cos(re) elif im <= 5.6e+102: tmp = 0.5 * math.log1p(math.expm1((im * -2.0))) else: tmp = math.cos(re) * (-0.16666666666666666 * math.pow(im, 3.0)) return tmp
function code(re, im) tmp = 0.0 if (im <= 10.5) tmp = Float64(im * Float64(-cos(re))); elseif (im <= 5.6e+102) tmp = Float64(0.5 * log1p(expm1(Float64(im * -2.0)))); else tmp = Float64(cos(re) * Float64(-0.16666666666666666 * (im ^ 3.0))); end return tmp end
code[re_, im_] := If[LessEqual[im, 10.5], N[(im * (-N[Cos[re], $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[(-0.16666666666666666 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 10.5:\\
\;\;\;\;im \cdot \left(-\cos re\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(-0.16666666666666666 \cdot {im}^{3}\right)\\
\end{array}
\end{array}
if im < 10.5Initial program 42.7%
/-rgt-identity42.7%
exp-042.7%
associate-*l/42.7%
cos-neg42.7%
associate-*l*42.7%
associate-*r/42.7%
exp-042.7%
/-rgt-identity42.7%
*-commutative42.7%
neg-sub042.7%
cos-neg42.7%
Simplified42.7%
Taylor expanded in im around 0 87.5%
Taylor expanded in im around 0 64.8%
mul-1-neg64.8%
*-commutative64.8%
distribute-rgt-neg-in64.8%
Simplified64.8%
if 10.5 < im < 5.60000000000000037e102Initial 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 4.1%
log1p-expm1-u95.2%
*-commutative95.2%
associate-*l*95.2%
Applied egg-rr95.2%
Taylor expanded in re around 0 67.4%
expm1-define67.4%
Simplified67.4%
if 5.60000000000000037e102 < 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 im around inf 100.0%
associate-*l*100.0%
Simplified100.0%
Final simplification72.1%
(FPCore (re im) :precision binary64 (if (<= im 10.6) (* im (- (cos re))) (* 0.5 (log1p (expm1 (* im -2.0))))))
double code(double re, double im) {
double tmp;
if (im <= 10.6) {
tmp = im * -cos(re);
} else {
tmp = 0.5 * log1p(expm1((im * -2.0)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (im <= 10.6) {
tmp = im * -Math.cos(re);
} else {
tmp = 0.5 * Math.log1p(Math.expm1((im * -2.0)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 10.6: tmp = im * -math.cos(re) else: tmp = 0.5 * math.log1p(math.expm1((im * -2.0))) return tmp
function code(re, im) tmp = 0.0 if (im <= 10.6) tmp = Float64(im * Float64(-cos(re))); else tmp = Float64(0.5 * log1p(expm1(Float64(im * -2.0)))); end return tmp end
code[re_, im_] := If[LessEqual[im, 10.6], N[(im * (-N[Cos[re], $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 10.6:\\
\;\;\;\;im \cdot \left(-\cos re\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\
\end{array}
\end{array}
if im < 10.5999999999999996Initial program 42.7%
/-rgt-identity42.7%
exp-042.7%
associate-*l/42.7%
cos-neg42.7%
associate-*l*42.7%
associate-*r/42.7%
exp-042.7%
/-rgt-identity42.7%
*-commutative42.7%
neg-sub042.7%
cos-neg42.7%
Simplified42.7%
Taylor expanded in im around 0 87.5%
Taylor expanded in im around 0 64.8%
mul-1-neg64.8%
*-commutative64.8%
distribute-rgt-neg-in64.8%
Simplified64.8%
if 10.5999999999999996 < 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-u98.8%
*-commutative98.8%
associate-*l*98.8%
Applied egg-rr98.8%
Taylor expanded in re around 0 71.6%
expm1-define71.6%
Simplified71.6%
Final simplification66.6%
(FPCore (re im) :precision binary64 (if (<= im 6.7) (* im (- (cos re))) (* (pow im 7.0) -0.0001984126984126984)))
double code(double re, double im) {
double tmp;
if (im <= 6.7) {
tmp = im * -cos(re);
} else {
tmp = pow(im, 7.0) * -0.0001984126984126984;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 6.7d0) then
tmp = im * -cos(re)
else
tmp = (im ** 7.0d0) * (-0.0001984126984126984d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 6.7) {
tmp = im * -Math.cos(re);
} else {
tmp = Math.pow(im, 7.0) * -0.0001984126984126984;
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 6.7: tmp = im * -math.cos(re) else: tmp = math.pow(im, 7.0) * -0.0001984126984126984 return tmp
function code(re, im) tmp = 0.0 if (im <= 6.7) tmp = Float64(im * Float64(-cos(re))); else tmp = Float64((im ^ 7.0) * -0.0001984126984126984); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 6.7) tmp = im * -cos(re); else tmp = (im ^ 7.0) * -0.0001984126984126984; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 6.7], N[(im * (-N[Cos[re], $MachinePrecision])), $MachinePrecision], N[(N[Power[im, 7.0], $MachinePrecision] * -0.0001984126984126984), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 6.7:\\
\;\;\;\;im \cdot \left(-\cos re\right)\\
\mathbf{else}:\\
\;\;\;\;{im}^{7} \cdot -0.0001984126984126984\\
\end{array}
\end{array}
if im < 6.70000000000000018Initial program 42.7%
/-rgt-identity42.7%
exp-042.7%
associate-*l/42.7%
cos-neg42.7%
associate-*l*42.7%
associate-*r/42.7%
exp-042.7%
/-rgt-identity42.7%
*-commutative42.7%
neg-sub042.7%
cos-neg42.7%
Simplified42.7%
Taylor expanded in im around 0 87.5%
Taylor expanded in im around 0 64.8%
mul-1-neg64.8%
*-commutative64.8%
distribute-rgt-neg-in64.8%
Simplified64.8%
if 6.70000000000000018 < 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 88.0%
Simplified88.0%
Taylor expanded in im around inf 88.0%
Taylor expanded in re around 0 66.2%
*-commutative66.2%
Simplified66.2%
Final simplification65.2%
(FPCore (re im) :precision binary64 (if (<= im 3e+48) (* im (- (cos re))) (* -0.16666666666666666 (pow im 3.0))))
double code(double re, double im) {
double tmp;
if (im <= 3e+48) {
tmp = im * -cos(re);
} else {
tmp = -0.16666666666666666 * 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 <= 3d+48) then
tmp = im * -cos(re)
else
tmp = (-0.16666666666666666d0) * (im ** 3.0d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 3e+48) {
tmp = im * -Math.cos(re);
} else {
tmp = -0.16666666666666666 * Math.pow(im, 3.0);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 3e+48: tmp = im * -math.cos(re) else: tmp = -0.16666666666666666 * math.pow(im, 3.0) return tmp
function code(re, im) tmp = 0.0 if (im <= 3e+48) tmp = Float64(im * Float64(-cos(re))); else tmp = Float64(-0.16666666666666666 * (im ^ 3.0)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 3e+48) tmp = im * -cos(re); else tmp = -0.16666666666666666 * (im ^ 3.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 3e+48], N[(im * (-N[Cos[re], $MachinePrecision])), $MachinePrecision], N[(-0.16666666666666666 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 3 \cdot 10^{+48}:\\
\;\;\;\;im \cdot \left(-\cos re\right)\\
\mathbf{else}:\\
\;\;\;\;-0.16666666666666666 \cdot {im}^{3}\\
\end{array}
\end{array}
if im < 3e48Initial program 45.3%
/-rgt-identity45.3%
exp-045.3%
associate-*l/45.3%
cos-neg45.3%
associate-*l*45.3%
associate-*r/45.3%
exp-045.3%
/-rgt-identity45.3%
*-commutative45.3%
neg-sub045.3%
cos-neg45.3%
Simplified45.3%
Taylor expanded in im around 0 83.7%
Taylor expanded in im around 0 62.0%
mul-1-neg62.0%
*-commutative62.0%
distribute-rgt-neg-in62.0%
Simplified62.0%
if 3e48 < 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 86.3%
Taylor expanded in im around inf 86.3%
associate-*l*86.3%
Simplified86.3%
Taylor expanded in re around 0 63.2%
*-commutative63.2%
Simplified63.2%
Final simplification62.3%
(FPCore (re im) :precision binary64 (* im (- (cos re))))
double code(double re, double im) {
return im * -cos(re);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = im * -cos(re)
end function
public static double code(double re, double im) {
return im * -Math.cos(re);
}
def code(re, im): return im * -math.cos(re)
function code(re, im) return Float64(im * Float64(-cos(re))) end
function tmp = code(re, im) tmp = im * -cos(re); end
code[re_, im_] := N[(im * (-N[Cos[re], $MachinePrecision])), $MachinePrecision]
\begin{array}{l}
\\
im \cdot \left(-\cos re\right)
\end{array}
Initial program 58.4%
/-rgt-identity58.4%
exp-058.4%
associate-*l/58.4%
cos-neg58.4%
associate-*l*58.4%
associate-*r/58.4%
exp-058.4%
/-rgt-identity58.4%
*-commutative58.4%
neg-sub058.4%
cos-neg58.4%
Simplified58.4%
Taylor expanded in im around 0 84.3%
Taylor expanded in im around 0 48.6%
mul-1-neg48.6%
*-commutative48.6%
distribute-rgt-neg-in48.6%
Simplified48.6%
Final simplification48.6%
(FPCore (re im) :precision binary64 (- im))
double code(double re, double im) {
return -im;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = -im
end function
public static double code(double re, double im) {
return -im;
}
def code(re, im): return -im
function code(re, im) return Float64(-im) end
function tmp = code(re, im) tmp = -im; end
code[re_, im_] := (-im)
\begin{array}{l}
\\
-im
\end{array}
Initial program 58.4%
/-rgt-identity58.4%
exp-058.4%
associate-*l/58.4%
cos-neg58.4%
associate-*l*58.4%
associate-*r/58.4%
exp-058.4%
/-rgt-identity58.4%
*-commutative58.4%
neg-sub058.4%
cos-neg58.4%
Simplified58.4%
Taylor expanded in im around 0 84.3%
Taylor expanded in im around 0 48.6%
mul-1-neg48.6%
*-commutative48.6%
distribute-rgt-neg-in48.6%
Simplified48.6%
Taylor expanded in re around 0 28.4%
mul-1-neg28.4%
Simplified28.4%
(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 2024085
(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))))