
(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 7 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.5%
/-rgt-identity58.5%
exp-058.5%
associate-*l/58.5%
cos-neg58.5%
associate-*l*58.5%
associate-*r/58.5%
exp-058.5%
/-rgt-identity58.5%
*-commutative58.5%
neg-sub058.5%
cos-neg58.5%
Simplified58.5%
Taylor expanded in im around 0 47.5%
log1p-expm1-u98.8%
*-commutative98.8%
associate-*l*98.8%
Applied egg-rr98.8%
(FPCore (re im)
:precision binary64
(if (<= im 430.0)
(* 0.5 (* (cos re) (* im (- (* -0.3333333333333333 (pow im 2.0)) 2.0))))
(if (<= im 4.1e+41)
(* 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 <= 430.0) {
tmp = 0.5 * (cos(re) * (im * ((-0.3333333333333333 * pow(im, 2.0)) - 2.0)));
} else if (im <= 4.1e+41) {
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 <= 430.0) {
tmp = 0.5 * (Math.cos(re) * (im * ((-0.3333333333333333 * Math.pow(im, 2.0)) - 2.0)));
} else if (im <= 4.1e+41) {
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 <= 430.0: tmp = 0.5 * (math.cos(re) * (im * ((-0.3333333333333333 * math.pow(im, 2.0)) - 2.0))) elif im <= 4.1e+41: 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 <= 430.0) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * Float64(Float64(-0.3333333333333333 * (im ^ 2.0)) - 2.0)))); elseif (im <= 4.1e+41) 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, 430.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, 4.1e+41], 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 430:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)\right)\\
\mathbf{elif}\;im \leq 4.1 \cdot 10^{+41}:\\
\;\;\;\;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 < 430Initial program 44.4%
/-rgt-identity44.4%
exp-044.4%
associate-*l/44.4%
cos-neg44.4%
associate-*l*44.4%
associate-*r/44.4%
exp-044.4%
/-rgt-identity44.4%
*-commutative44.4%
neg-sub044.4%
cos-neg44.4%
Simplified44.4%
Taylor expanded in im around 0 93.0%
if 430 < im < 4.1000000000000004e41Initial 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.4%
log1p-expm1-u89.5%
*-commutative89.5%
associate-*l*89.5%
Applied egg-rr89.5%
Taylor expanded in re around 0 78.4%
expm1-define78.4%
Simplified78.4%
if 4.1000000000000004e41 < 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 96.9%
distribute-lft-in96.9%
associate-+r+96.9%
associate-*r*96.9%
*-commutative96.9%
distribute-rgt-out96.9%
+-commutative96.9%
metadata-eval96.9%
sub-neg96.9%
fma-define96.9%
Simplified96.9%
Taylor expanded in im around inf 98.4%
associate-*r*98.4%
*-commutative98.4%
Simplified98.4%
Taylor expanded in re around inf 98.4%
*-commutative98.4%
*-commutative98.4%
Simplified98.4%
Final simplification93.6%
(FPCore (re im)
:precision binary64
(if (<= im 2.6e-15)
(* 0.5 (* (cos re) (* im -2.0)))
(if (<= im 8.4e+18)
(* 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 <= 2.6e-15) {
tmp = 0.5 * (cos(re) * (im * -2.0));
} else if (im <= 8.4e+18) {
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 <= 2.6e-15) {
tmp = 0.5 * (Math.cos(re) * (im * -2.0));
} else if (im <= 8.4e+18) {
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 <= 2.6e-15: tmp = 0.5 * (math.cos(re) * (im * -2.0)) elif im <= 8.4e+18: 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 <= 2.6e-15) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * -2.0))); elseif (im <= 8.4e+18) 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, 2.6e-15], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 8.4e+18], 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 2.6 \cdot 10^{-15}:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\
\mathbf{elif}\;im \leq 8.4 \cdot 10^{+18}:\\
\;\;\;\;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 < 2.60000000000000004e-15Initial program 44.2%
/-rgt-identity44.2%
exp-044.2%
associate-*l/44.2%
cos-neg44.2%
associate-*l*44.2%
associate-*r/44.2%
exp-044.2%
/-rgt-identity44.2%
*-commutative44.2%
neg-sub044.2%
cos-neg44.2%
Simplified44.2%
Taylor expanded in im around 0 61.9%
if 2.60000000000000004e-15 < im < 8.4e18Initial program 89.2%
/-rgt-identity89.2%
exp-089.2%
associate-*l/89.2%
cos-neg89.2%
associate-*l*89.2%
associate-*r/89.2%
exp-089.2%
/-rgt-identity89.2%
*-commutative89.2%
neg-sub089.2%
cos-neg89.2%
Simplified89.2%
Taylor expanded in im around 0 21.6%
log1p-expm1-u77.2%
*-commutative77.2%
associate-*l*77.2%
Applied egg-rr77.2%
Taylor expanded in re around 0 62.2%
expm1-define72.5%
Simplified72.5%
if 8.4e18 < 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 90.9%
distribute-lft-in90.9%
associate-+r+90.9%
associate-*r*90.9%
*-commutative90.9%
distribute-rgt-out90.9%
+-commutative90.9%
metadata-eval90.9%
sub-neg90.9%
fma-define90.9%
Simplified90.9%
Taylor expanded in im around inf 92.2%
associate-*r*92.2%
*-commutative92.2%
Simplified92.2%
Taylor expanded in re around inf 92.2%
*-commutative92.2%
*-commutative92.2%
Simplified92.2%
Final simplification69.3%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* (pow im 7.0) 0.0001984126984126984))
(t_1 (* (pow im 7.0) -0.0001984126984126984)))
(if (<= im 0.2)
(* 0.5 (* (cos re) (* im -2.0)))
(if (<= im 6.5e+93)
(* 0.5 (log1p (expm1 (* im -2.0))))
(if (<= im 6.6e+93)
t_0
(if (<= im 3.6e+151)
t_1
(if (<= im 1.72e+162)
(* 0.5 (* im (- (* 0.26666666666666666 (pow im 4.0)) 2.0)))
(if (or (<= im 2.1e+178) (not (<= im 3.3e+184))) t_1 t_0))))))))
double code(double re, double im) {
double t_0 = pow(im, 7.0) * 0.0001984126984126984;
double t_1 = pow(im, 7.0) * -0.0001984126984126984;
double tmp;
if (im <= 0.2) {
tmp = 0.5 * (cos(re) * (im * -2.0));
} else if (im <= 6.5e+93) {
tmp = 0.5 * log1p(expm1((im * -2.0)));
} else if (im <= 6.6e+93) {
tmp = t_0;
} else if (im <= 3.6e+151) {
tmp = t_1;
} else if (im <= 1.72e+162) {
tmp = 0.5 * (im * ((0.26666666666666666 * pow(im, 4.0)) - 2.0));
} else if ((im <= 2.1e+178) || !(im <= 3.3e+184)) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
public static double code(double re, double im) {
double t_0 = Math.pow(im, 7.0) * 0.0001984126984126984;
double t_1 = Math.pow(im, 7.0) * -0.0001984126984126984;
double tmp;
if (im <= 0.2) {
tmp = 0.5 * (Math.cos(re) * (im * -2.0));
} else if (im <= 6.5e+93) {
tmp = 0.5 * Math.log1p(Math.expm1((im * -2.0)));
} else if (im <= 6.6e+93) {
tmp = t_0;
} else if (im <= 3.6e+151) {
tmp = t_1;
} else if (im <= 1.72e+162) {
tmp = 0.5 * (im * ((0.26666666666666666 * Math.pow(im, 4.0)) - 2.0));
} else if ((im <= 2.1e+178) || !(im <= 3.3e+184)) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(re, im): t_0 = math.pow(im, 7.0) * 0.0001984126984126984 t_1 = math.pow(im, 7.0) * -0.0001984126984126984 tmp = 0 if im <= 0.2: tmp = 0.5 * (math.cos(re) * (im * -2.0)) elif im <= 6.5e+93: tmp = 0.5 * math.log1p(math.expm1((im * -2.0))) elif im <= 6.6e+93: tmp = t_0 elif im <= 3.6e+151: tmp = t_1 elif im <= 1.72e+162: tmp = 0.5 * (im * ((0.26666666666666666 * math.pow(im, 4.0)) - 2.0)) elif (im <= 2.1e+178) or not (im <= 3.3e+184): tmp = t_1 else: tmp = t_0 return tmp
function code(re, im) t_0 = Float64((im ^ 7.0) * 0.0001984126984126984) t_1 = Float64((im ^ 7.0) * -0.0001984126984126984) tmp = 0.0 if (im <= 0.2) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * -2.0))); elseif (im <= 6.5e+93) tmp = Float64(0.5 * log1p(expm1(Float64(im * -2.0)))); elseif (im <= 6.6e+93) tmp = t_0; elseif (im <= 3.6e+151) tmp = t_1; elseif (im <= 1.72e+162) tmp = Float64(0.5 * Float64(im * Float64(Float64(0.26666666666666666 * (im ^ 4.0)) - 2.0))); elseif ((im <= 2.1e+178) || !(im <= 3.3e+184)) tmp = t_1; else tmp = t_0; end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(N[Power[im, 7.0], $MachinePrecision] * 0.0001984126984126984), $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[im, 7.0], $MachinePrecision] * -0.0001984126984126984), $MachinePrecision]}, If[LessEqual[im, 0.2], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 6.5e+93], N[(0.5 * N[Log[1 + N[(Exp[N[(im * -2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 6.6e+93], t$95$0, If[LessEqual[im, 3.6e+151], t$95$1, If[LessEqual[im, 1.72e+162], N[(0.5 * N[(im * N[(N[(0.26666666666666666 * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[im, 2.1e+178], N[Not[LessEqual[im, 3.3e+184]], $MachinePrecision]], t$95$1, t$95$0]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {im}^{7} \cdot 0.0001984126984126984\\
t_1 := {im}^{7} \cdot -0.0001984126984126984\\
\mathbf{if}\;im \leq 0.2:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\
\mathbf{elif}\;im \leq 6.5 \cdot 10^{+93}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\
\mathbf{elif}\;im \leq 6.6 \cdot 10^{+93}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;im \leq 3.6 \cdot 10^{+151}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;im \leq 1.72 \cdot 10^{+162}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(0.26666666666666666 \cdot {im}^{4} - 2\right)\right)\\
\mathbf{elif}\;im \leq 2.1 \cdot 10^{+178} \lor \neg \left(im \leq 3.3 \cdot 10^{+184}\right):\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if im < 0.20000000000000001Initial program 44.4%
/-rgt-identity44.4%
exp-044.4%
associate-*l/44.4%
cos-neg44.4%
associate-*l*44.4%
associate-*r/44.4%
exp-044.4%
/-rgt-identity44.4%
*-commutative44.4%
neg-sub044.4%
cos-neg44.4%
Simplified44.4%
Taylor expanded in im around 0 61.9%
if 0.20000000000000001 < im < 6.4999999999999998e93Initial 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-u94.8%
*-commutative94.8%
associate-*l*94.8%
Applied egg-rr94.8%
Taylor expanded in re around 0 78.1%
expm1-define78.1%
Simplified78.1%
if 6.4999999999999998e93 < im < 6.60000000000000017e93 or 2.0999999999999999e178 < im < 3.2999999999999998e184Initial 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%
distribute-lft-in100.0%
associate-+r+100.0%
associate-*r*100.0%
*-commutative100.0%
distribute-rgt-out100.0%
+-commutative100.0%
metadata-eval100.0%
sub-neg100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
associate-*r*100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in re around 0 0.0%
*-commutative0.0%
Simplified0.0%
add-sqr-sqrt0.0%
sqrt-unprod100.0%
swap-sqr100.0%
pow-prod-up100.0%
metadata-eval100.0%
metadata-eval100.0%
Applied egg-rr100.0%
sqrt-prod100.0%
sqrt-pow1100.0%
metadata-eval100.0%
metadata-eval100.0%
Applied egg-rr100.0%
if 6.60000000000000017e93 < im < 3.6e151 or 1.72e162 < im < 2.0999999999999999e178 or 3.2999999999999998e184 < 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%
distribute-lft-in100.0%
associate-+r+100.0%
associate-*r*100.0%
*-commutative100.0%
distribute-rgt-out100.0%
+-commutative100.0%
metadata-eval100.0%
sub-neg100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
associate-*r*100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in re around 0 82.1%
*-commutative82.1%
Simplified82.1%
if 3.6e151 < im < 1.72e162Initial 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.7%
log1p-expm1-u100.0%
*-commutative100.0%
associate-*l*100.0%
Applied egg-rr100.0%
Taylor expanded in re around 0 0.0%
expm1-define0.0%
Simplified0.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in im around 0 100.0%
Final simplification67.3%
(FPCore (re im)
:precision binary64
(if (<= im 0.056)
(* 0.5 (* (cos re) (* im -2.0)))
(if (or (<= im 1.6e+215) (not (<= im 1.6e+227)))
(* (pow im 7.0) -0.0001984126984126984)
(* 0.5 (* 0.4444444444444444 (pow im 6.0))))))
double code(double re, double im) {
double tmp;
if (im <= 0.056) {
tmp = 0.5 * (cos(re) * (im * -2.0));
} else if ((im <= 1.6e+215) || !(im <= 1.6e+227)) {
tmp = pow(im, 7.0) * -0.0001984126984126984;
} else {
tmp = 0.5 * (0.4444444444444444 * pow(im, 6.0));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 0.056d0) then
tmp = 0.5d0 * (cos(re) * (im * (-2.0d0)))
else if ((im <= 1.6d+215) .or. (.not. (im <= 1.6d+227))) then
tmp = (im ** 7.0d0) * (-0.0001984126984126984d0)
else
tmp = 0.5d0 * (0.4444444444444444d0 * (im ** 6.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 0.056) {
tmp = 0.5 * (Math.cos(re) * (im * -2.0));
} else if ((im <= 1.6e+215) || !(im <= 1.6e+227)) {
tmp = Math.pow(im, 7.0) * -0.0001984126984126984;
} else {
tmp = 0.5 * (0.4444444444444444 * Math.pow(im, 6.0));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 0.056: tmp = 0.5 * (math.cos(re) * (im * -2.0)) elif (im <= 1.6e+215) or not (im <= 1.6e+227): tmp = math.pow(im, 7.0) * -0.0001984126984126984 else: tmp = 0.5 * (0.4444444444444444 * math.pow(im, 6.0)) return tmp
function code(re, im) tmp = 0.0 if (im <= 0.056) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * -2.0))); elseif ((im <= 1.6e+215) || !(im <= 1.6e+227)) tmp = Float64((im ^ 7.0) * -0.0001984126984126984); else tmp = Float64(0.5 * Float64(0.4444444444444444 * (im ^ 6.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 0.056) tmp = 0.5 * (cos(re) * (im * -2.0)); elseif ((im <= 1.6e+215) || ~((im <= 1.6e+227))) tmp = (im ^ 7.0) * -0.0001984126984126984; else tmp = 0.5 * (0.4444444444444444 * (im ^ 6.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 0.056], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[im, 1.6e+215], N[Not[LessEqual[im, 1.6e+227]], $MachinePrecision]], N[(N[Power[im, 7.0], $MachinePrecision] * -0.0001984126984126984), $MachinePrecision], N[(0.5 * N[(0.4444444444444444 * N[Power[im, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.056:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\
\mathbf{elif}\;im \leq 1.6 \cdot 10^{+215} \lor \neg \left(im \leq 1.6 \cdot 10^{+227}\right):\\
\;\;\;\;{im}^{7} \cdot -0.0001984126984126984\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(0.4444444444444444 \cdot {im}^{6}\right)\\
\end{array}
\end{array}
if im < 0.0560000000000000012Initial program 44.1%
/-rgt-identity44.1%
exp-044.1%
associate-*l/44.1%
cos-neg44.1%
associate-*l*44.1%
associate-*r/44.1%
exp-044.1%
/-rgt-identity44.1%
*-commutative44.1%
neg-sub044.1%
cos-neg44.1%
Simplified44.1%
Taylor expanded in im around 0 62.1%
if 0.0560000000000000012 < im < 1.5999999999999999e215 or 1.59999999999999994e227 < im Initial program 99.9%
/-rgt-identity99.9%
exp-099.9%
associate-*l/99.9%
cos-neg99.9%
associate-*l*99.9%
associate-*r/99.9%
exp-099.9%
/-rgt-identity99.9%
*-commutative99.9%
neg-sub099.9%
cos-neg99.9%
Simplified99.9%
Taylor expanded in im around 0 83.9%
distribute-lft-in83.9%
associate-+r+83.9%
associate-*r*83.9%
*-commutative83.9%
distribute-rgt-out83.9%
+-commutative83.9%
metadata-eval83.9%
sub-neg83.9%
fma-define83.9%
Simplified83.9%
Taylor expanded in im around inf 83.8%
associate-*r*83.8%
*-commutative83.8%
Simplified83.8%
Taylor expanded in re around 0 60.0%
*-commutative60.0%
Simplified60.0%
if 1.5999999999999999e215 < im < 1.59999999999999994e227Initial 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 6.1%
log1p-expm1-u100.0%
*-commutative100.0%
associate-*l*100.0%
Applied egg-rr100.0%
Taylor expanded in re around 0 50.0%
expm1-define50.0%
Simplified50.0%
Taylor expanded in im around 0 50.0%
Taylor expanded in im around 0 50.0%
Taylor expanded in im around inf 50.0%
Final simplification61.5%
(FPCore (re im) :precision binary64 (if (<= im 0.00078) (* 0.5 (* im -2.0)) (* (pow im 7.0) -0.0001984126984126984)))
double code(double re, double im) {
double tmp;
if (im <= 0.00078) {
tmp = 0.5 * (im * -2.0);
} 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 <= 0.00078d0) then
tmp = 0.5d0 * (im * (-2.0d0))
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 <= 0.00078) {
tmp = 0.5 * (im * -2.0);
} else {
tmp = Math.pow(im, 7.0) * -0.0001984126984126984;
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 0.00078: tmp = 0.5 * (im * -2.0) else: tmp = math.pow(im, 7.0) * -0.0001984126984126984 return tmp
function code(re, im) tmp = 0.0 if (im <= 0.00078) tmp = Float64(0.5 * Float64(im * -2.0)); else tmp = Float64((im ^ 7.0) * -0.0001984126984126984); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 0.00078) tmp = 0.5 * (im * -2.0); else tmp = (im ^ 7.0) * -0.0001984126984126984; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 0.00078], N[(0.5 * N[(im * -2.0), $MachinePrecision]), $MachinePrecision], N[(N[Power[im, 7.0], $MachinePrecision] * -0.0001984126984126984), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.00078:\\
\;\;\;\;0.5 \cdot \left(im \cdot -2\right)\\
\mathbf{else}:\\
\;\;\;\;{im}^{7} \cdot -0.0001984126984126984\\
\end{array}
\end{array}
if im < 7.79999999999999986e-4Initial program 44.1%
/-rgt-identity44.1%
exp-044.1%
associate-*l/44.1%
cos-neg44.1%
associate-*l*44.1%
associate-*r/44.1%
exp-044.1%
/-rgt-identity44.1%
*-commutative44.1%
neg-sub044.1%
cos-neg44.1%
Simplified44.1%
Taylor expanded in im around 0 62.1%
Taylor expanded in re around 0 34.7%
*-commutative34.7%
Simplified34.7%
if 7.79999999999999986e-4 < im Initial program 99.9%
/-rgt-identity99.9%
exp-099.9%
associate-*l/99.9%
cos-neg99.9%
associate-*l*99.9%
associate-*r/99.9%
exp-099.9%
/-rgt-identity99.9%
*-commutative99.9%
neg-sub099.9%
cos-neg99.9%
Simplified99.9%
Taylor expanded in im around 0 84.4%
distribute-lft-in84.4%
associate-+r+84.4%
associate-*r*84.4%
*-commutative84.4%
distribute-rgt-out84.4%
+-commutative84.4%
metadata-eval84.4%
sub-neg84.4%
fma-define84.4%
Simplified84.4%
Taylor expanded in im around inf 84.3%
associate-*r*84.3%
*-commutative84.3%
Simplified84.3%
Taylor expanded in re around 0 59.7%
*-commutative59.7%
Simplified59.7%
(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 58.5%
/-rgt-identity58.5%
exp-058.5%
associate-*l/58.5%
cos-neg58.5%
associate-*l*58.5%
associate-*r/58.5%
exp-058.5%
/-rgt-identity58.5%
*-commutative58.5%
neg-sub058.5%
cos-neg58.5%
Simplified58.5%
Taylor expanded in im around 0 47.5%
Taylor expanded in re around 0 26.7%
*-commutative26.7%
Simplified26.7%
(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 2024107
(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))))