
(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 9 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
(let* ((t_0 (- (exp (- im)) (exp im))))
(if (or (<= t_0 (- INFINITY)) (not (<= t_0 5e-14)))
(* (* 0.5 (cos re)) t_0)
(*
(cos re)
(+
(- (* (pow im 3.0) -0.16666666666666666) im)
(+
(* (pow im 5.0) -0.008333333333333333)
(* (pow im 7.0) -0.0001984126984126984)))))))
double code(double re, double im) {
double t_0 = exp(-im) - exp(im);
double tmp;
if ((t_0 <= -((double) INFINITY)) || !(t_0 <= 5e-14)) {
tmp = (0.5 * cos(re)) * t_0;
} else {
tmp = cos(re) * (((pow(im, 3.0) * -0.16666666666666666) - im) + ((pow(im, 5.0) * -0.008333333333333333) + (pow(im, 7.0) * -0.0001984126984126984)));
}
return tmp;
}
public static double code(double re, double im) {
double t_0 = Math.exp(-im) - Math.exp(im);
double tmp;
if ((t_0 <= -Double.POSITIVE_INFINITY) || !(t_0 <= 5e-14)) {
tmp = (0.5 * Math.cos(re)) * t_0;
} else {
tmp = Math.cos(re) * (((Math.pow(im, 3.0) * -0.16666666666666666) - im) + ((Math.pow(im, 5.0) * -0.008333333333333333) + (Math.pow(im, 7.0) * -0.0001984126984126984)));
}
return tmp;
}
def code(re, im): t_0 = math.exp(-im) - math.exp(im) tmp = 0 if (t_0 <= -math.inf) or not (t_0 <= 5e-14): tmp = (0.5 * math.cos(re)) * t_0 else: tmp = math.cos(re) * (((math.pow(im, 3.0) * -0.16666666666666666) - im) + ((math.pow(im, 5.0) * -0.008333333333333333) + (math.pow(im, 7.0) * -0.0001984126984126984))) return tmp
function code(re, im) t_0 = Float64(exp(Float64(-im)) - exp(im)) tmp = 0.0 if ((t_0 <= Float64(-Inf)) || !(t_0 <= 5e-14)) tmp = Float64(Float64(0.5 * cos(re)) * t_0); else tmp = Float64(cos(re) * Float64(Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im) + Float64(Float64((im ^ 5.0) * -0.008333333333333333) + Float64((im ^ 7.0) * -0.0001984126984126984)))); end return tmp end
function tmp_2 = code(re, im) t_0 = exp(-im) - exp(im); tmp = 0.0; if ((t_0 <= -Inf) || ~((t_0 <= 5e-14))) tmp = (0.5 * cos(re)) * t_0; else tmp = cos(re) * ((((im ^ 3.0) * -0.16666666666666666) - im) + (((im ^ 5.0) * -0.008333333333333333) + ((im ^ 7.0) * -0.0001984126984126984))); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, (-Infinity)], N[Not[LessEqual[t$95$0, 5e-14]], $MachinePrecision]], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision] + N[(N[(N[Power[im, 5.0], $MachinePrecision] * -0.008333333333333333), $MachinePrecision] + N[(N[Power[im, 7.0], $MachinePrecision] * -0.0001984126984126984), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-im} - e^{im}\\
\mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq 5 \cdot 10^{-14}\right):\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot t_0\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left(\left({im}^{3} \cdot -0.16666666666666666 - im\right) + \left({im}^{5} \cdot -0.008333333333333333 + {im}^{7} \cdot -0.0001984126984126984\right)\right)\\
\end{array}
\end{array}
if (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < -inf.0 or 5.0000000000000002e-14 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) Initial program 100.0%
neg-sub0100.0%
Simplified100.0%
if -inf.0 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < 5.0000000000000002e-14Initial program 7.2%
neg-sub07.2%
Simplified7.2%
Taylor expanded in im around 0 99.8%
Taylor expanded in im around 0 99.8%
associate-+r+99.8%
neg-mul-199.8%
distribute-lft-neg-in99.8%
associate-*r*99.8%
distribute-rgt-out99.8%
+-commutative99.8%
sub-neg99.8%
associate-*r*99.8%
associate-*r*99.8%
distribute-rgt-out99.8%
distribute-lft-out99.8%
Simplified99.8%
Final simplification99.9%
(FPCore (re im)
:precision binary64
(let* ((t_0 (- (exp (- im)) (exp im))))
(if (or (<= t_0 -0.05) (not (<= t_0 5e-14)))
(* (* 0.5 (cos re)) t_0)
(* (cos re) (- (* (pow im 3.0) -0.16666666666666666) im)))))
double code(double re, double im) {
double t_0 = exp(-im) - exp(im);
double tmp;
if ((t_0 <= -0.05) || !(t_0 <= 5e-14)) {
tmp = (0.5 * cos(re)) * t_0;
} else {
tmp = cos(re) * ((pow(im, 3.0) * -0.16666666666666666) - im);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: tmp
t_0 = exp(-im) - exp(im)
if ((t_0 <= (-0.05d0)) .or. (.not. (t_0 <= 5d-14))) then
tmp = (0.5d0 * cos(re)) * t_0
else
tmp = cos(re) * (((im ** 3.0d0) * (-0.16666666666666666d0)) - im)
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = Math.exp(-im) - Math.exp(im);
double tmp;
if ((t_0 <= -0.05) || !(t_0 <= 5e-14)) {
tmp = (0.5 * Math.cos(re)) * t_0;
} else {
tmp = Math.cos(re) * ((Math.pow(im, 3.0) * -0.16666666666666666) - im);
}
return tmp;
}
def code(re, im): t_0 = math.exp(-im) - math.exp(im) tmp = 0 if (t_0 <= -0.05) or not (t_0 <= 5e-14): tmp = (0.5 * math.cos(re)) * t_0 else: tmp = math.cos(re) * ((math.pow(im, 3.0) * -0.16666666666666666) - im) return tmp
function code(re, im) t_0 = Float64(exp(Float64(-im)) - exp(im)) tmp = 0.0 if ((t_0 <= -0.05) || !(t_0 <= 5e-14)) tmp = Float64(Float64(0.5 * cos(re)) * t_0); else tmp = Float64(cos(re) * Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im)); end return tmp end
function tmp_2 = code(re, im) t_0 = exp(-im) - exp(im); tmp = 0.0; if ((t_0 <= -0.05) || ~((t_0 <= 5e-14))) tmp = (0.5 * cos(re)) * t_0; else tmp = cos(re) * (((im ^ 3.0) * -0.16666666666666666) - im); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -0.05], N[Not[LessEqual[t$95$0, 5e-14]], $MachinePrecision]], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-im} - e^{im}\\
\mathbf{if}\;t_0 \leq -0.05 \lor \neg \left(t_0 \leq 5 \cdot 10^{-14}\right):\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot t_0\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\
\end{array}
\end{array}
if (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < -0.050000000000000003 or 5.0000000000000002e-14 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) Initial program 100.0%
neg-sub0100.0%
Simplified100.0%
if -0.050000000000000003 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < 5.0000000000000002e-14Initial program 6.5%
neg-sub06.5%
Simplified6.5%
Taylor expanded in im around 0 99.8%
+-commutative99.8%
mul-1-neg99.8%
unsub-neg99.8%
associate-*r*99.8%
distribute-rgt-out--99.8%
*-commutative99.8%
Simplified99.8%
Final simplification99.9%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (- (exp (- im)) (exp im))))
(t_1 (* (pow im 7.0) (* (cos re) -0.0001984126984126984))))
(if (<= im -5.2e+48)
t_1
(if (<= im -0.000245)
t_0
(if (<= im 0.000135)
(* im (- (cos re)))
(if (<= im 1.05e+44) t_0 t_1))))))
double code(double re, double im) {
double t_0 = 0.5 * (exp(-im) - exp(im));
double t_1 = pow(im, 7.0) * (cos(re) * -0.0001984126984126984);
double tmp;
if (im <= -5.2e+48) {
tmp = t_1;
} else if (im <= -0.000245) {
tmp = t_0;
} else if (im <= 0.000135) {
tmp = im * -cos(re);
} else if (im <= 1.05e+44) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 0.5d0 * (exp(-im) - exp(im))
t_1 = (im ** 7.0d0) * (cos(re) * (-0.0001984126984126984d0))
if (im <= (-5.2d+48)) then
tmp = t_1
else if (im <= (-0.000245d0)) then
tmp = t_0
else if (im <= 0.000135d0) then
tmp = im * -cos(re)
else if (im <= 1.05d+44) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 0.5 * (Math.exp(-im) - Math.exp(im));
double t_1 = Math.pow(im, 7.0) * (Math.cos(re) * -0.0001984126984126984);
double tmp;
if (im <= -5.2e+48) {
tmp = t_1;
} else if (im <= -0.000245) {
tmp = t_0;
} else if (im <= 0.000135) {
tmp = im * -Math.cos(re);
} else if (im <= 1.05e+44) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(re, im): t_0 = 0.5 * (math.exp(-im) - math.exp(im)) t_1 = math.pow(im, 7.0) * (math.cos(re) * -0.0001984126984126984) tmp = 0 if im <= -5.2e+48: tmp = t_1 elif im <= -0.000245: tmp = t_0 elif im <= 0.000135: tmp = im * -math.cos(re) elif im <= 1.05e+44: tmp = t_0 else: tmp = t_1 return tmp
function code(re, im) t_0 = Float64(0.5 * Float64(exp(Float64(-im)) - exp(im))) t_1 = Float64((im ^ 7.0) * Float64(cos(re) * -0.0001984126984126984)) tmp = 0.0 if (im <= -5.2e+48) tmp = t_1; elseif (im <= -0.000245) tmp = t_0; elseif (im <= 0.000135) tmp = Float64(im * Float64(-cos(re))); elseif (im <= 1.05e+44) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * (exp(-im) - exp(im)); t_1 = (im ^ 7.0) * (cos(re) * -0.0001984126984126984); tmp = 0.0; if (im <= -5.2e+48) tmp = t_1; elseif (im <= -0.000245) tmp = t_0; elseif (im <= 0.000135) tmp = im * -cos(re); elseif (im <= 1.05e+44) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[im, 7.0], $MachinePrecision] * N[(N[Cos[re], $MachinePrecision] * -0.0001984126984126984), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -5.2e+48], t$95$1, If[LessEqual[im, -0.000245], t$95$0, If[LessEqual[im, 0.000135], N[(im * (-N[Cos[re], $MachinePrecision])), $MachinePrecision], If[LessEqual[im, 1.05e+44], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(e^{-im} - e^{im}\right)\\
t_1 := {im}^{7} \cdot \left(\cos re \cdot -0.0001984126984126984\right)\\
\mathbf{if}\;im \leq -5.2 \cdot 10^{+48}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;im \leq -0.000245:\\
\;\;\;\;t_0\\
\mathbf{elif}\;im \leq 0.000135:\\
\;\;\;\;im \cdot \left(-\cos re\right)\\
\mathbf{elif}\;im \leq 1.05 \cdot 10^{+44}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if im < -5.1999999999999999e48 or 1.04999999999999993e44 < im Initial program 100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in im around inf 100.0%
*-commutative100.0%
associate-*l*100.0%
Simplified100.0%
if -5.1999999999999999e48 < im < -2.4499999999999999e-4 or 1.35000000000000002e-4 < im < 1.04999999999999993e44Initial program 98.9%
neg-sub098.9%
Simplified98.9%
Taylor expanded in re around 0 90.8%
if -2.4499999999999999e-4 < im < 1.35000000000000002e-4Initial program 5.9%
neg-sub05.9%
Simplified5.9%
Taylor expanded in im around 0 99.8%
associate-*r*99.8%
neg-mul-199.8%
Simplified99.8%
Final simplification99.2%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (- (exp (- im)) (exp im))))
(t_1 (* (pow im 7.0) (* (cos re) -0.0001984126984126984))))
(if (<= im -5.2e+48)
t_1
(if (<= im -0.06)
t_0
(if (<= im 0.048)
(* (cos re) (- (* (pow im 3.0) -0.16666666666666666) im))
(if (<= im 1.05e+44) t_0 t_1))))))
double code(double re, double im) {
double t_0 = 0.5 * (exp(-im) - exp(im));
double t_1 = pow(im, 7.0) * (cos(re) * -0.0001984126984126984);
double tmp;
if (im <= -5.2e+48) {
tmp = t_1;
} else if (im <= -0.06) {
tmp = t_0;
} else if (im <= 0.048) {
tmp = cos(re) * ((pow(im, 3.0) * -0.16666666666666666) - im);
} else if (im <= 1.05e+44) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 0.5d0 * (exp(-im) - exp(im))
t_1 = (im ** 7.0d0) * (cos(re) * (-0.0001984126984126984d0))
if (im <= (-5.2d+48)) then
tmp = t_1
else if (im <= (-0.06d0)) then
tmp = t_0
else if (im <= 0.048d0) then
tmp = cos(re) * (((im ** 3.0d0) * (-0.16666666666666666d0)) - im)
else if (im <= 1.05d+44) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 0.5 * (Math.exp(-im) - Math.exp(im));
double t_1 = Math.pow(im, 7.0) * (Math.cos(re) * -0.0001984126984126984);
double tmp;
if (im <= -5.2e+48) {
tmp = t_1;
} else if (im <= -0.06) {
tmp = t_0;
} else if (im <= 0.048) {
tmp = Math.cos(re) * ((Math.pow(im, 3.0) * -0.16666666666666666) - im);
} else if (im <= 1.05e+44) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(re, im): t_0 = 0.5 * (math.exp(-im) - math.exp(im)) t_1 = math.pow(im, 7.0) * (math.cos(re) * -0.0001984126984126984) tmp = 0 if im <= -5.2e+48: tmp = t_1 elif im <= -0.06: tmp = t_0 elif im <= 0.048: tmp = math.cos(re) * ((math.pow(im, 3.0) * -0.16666666666666666) - im) elif im <= 1.05e+44: tmp = t_0 else: tmp = t_1 return tmp
function code(re, im) t_0 = Float64(0.5 * Float64(exp(Float64(-im)) - exp(im))) t_1 = Float64((im ^ 7.0) * Float64(cos(re) * -0.0001984126984126984)) tmp = 0.0 if (im <= -5.2e+48) tmp = t_1; elseif (im <= -0.06) tmp = t_0; elseif (im <= 0.048) tmp = Float64(cos(re) * Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im)); elseif (im <= 1.05e+44) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * (exp(-im) - exp(im)); t_1 = (im ^ 7.0) * (cos(re) * -0.0001984126984126984); tmp = 0.0; if (im <= -5.2e+48) tmp = t_1; elseif (im <= -0.06) tmp = t_0; elseif (im <= 0.048) tmp = cos(re) * (((im ^ 3.0) * -0.16666666666666666) - im); elseif (im <= 1.05e+44) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[im, 7.0], $MachinePrecision] * N[(N[Cos[re], $MachinePrecision] * -0.0001984126984126984), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -5.2e+48], t$95$1, If[LessEqual[im, -0.06], t$95$0, If[LessEqual[im, 0.048], N[(N[Cos[re], $MachinePrecision] * N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.05e+44], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(e^{-im} - e^{im}\right)\\
t_1 := {im}^{7} \cdot \left(\cos re \cdot -0.0001984126984126984\right)\\
\mathbf{if}\;im \leq -5.2 \cdot 10^{+48}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;im \leq -0.06:\\
\;\;\;\;t_0\\
\mathbf{elif}\;im \leq 0.048:\\
\;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\
\mathbf{elif}\;im \leq 1.05 \cdot 10^{+44}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if im < -5.1999999999999999e48 or 1.04999999999999993e44 < im Initial program 100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in im around inf 100.0%
*-commutative100.0%
associate-*l*100.0%
Simplified100.0%
if -5.1999999999999999e48 < im < -0.059999999999999998 or 0.048000000000000001 < im < 1.04999999999999993e44Initial program 100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in re around 0 95.3%
if -0.059999999999999998 < im < 0.048000000000000001Initial program 7.2%
neg-sub07.2%
Simplified7.2%
Taylor expanded in im around 0 99.5%
+-commutative99.5%
mul-1-neg99.5%
unsub-neg99.5%
associate-*r*99.5%
distribute-rgt-out--99.5%
*-commutative99.5%
Simplified99.5%
Final simplification99.4%
(FPCore (re im) :precision binary64 (if (or (<= im -0.0042) (not (<= im 0.00013))) (* 0.5 (- (exp (- im)) (exp im))) (* im (- (cos re)))))
double code(double re, double im) {
double tmp;
if ((im <= -0.0042) || !(im <= 0.00013)) {
tmp = 0.5 * (exp(-im) - exp(im));
} else {
tmp = im * -cos(re);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((im <= (-0.0042d0)) .or. (.not. (im <= 0.00013d0))) then
tmp = 0.5d0 * (exp(-im) - exp(im))
else
tmp = im * -cos(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((im <= -0.0042) || !(im <= 0.00013)) {
tmp = 0.5 * (Math.exp(-im) - Math.exp(im));
} else {
tmp = im * -Math.cos(re);
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= -0.0042) or not (im <= 0.00013): tmp = 0.5 * (math.exp(-im) - math.exp(im)) else: tmp = im * -math.cos(re) return tmp
function code(re, im) tmp = 0.0 if ((im <= -0.0042) || !(im <= 0.00013)) tmp = Float64(0.5 * Float64(exp(Float64(-im)) - exp(im))); else tmp = Float64(im * Float64(-cos(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((im <= -0.0042) || ~((im <= 0.00013))) tmp = 0.5 * (exp(-im) - exp(im)); else tmp = im * -cos(re); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, -0.0042], N[Not[LessEqual[im, 0.00013]], $MachinePrecision]], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(im * (-N[Cos[re], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq -0.0042 \lor \neg \left(im \leq 0.00013\right):\\
\;\;\;\;0.5 \cdot \left(e^{-im} - e^{im}\right)\\
\mathbf{else}:\\
\;\;\;\;im \cdot \left(-\cos re\right)\\
\end{array}
\end{array}
if im < -0.00419999999999999974 or 1.29999999999999989e-4 < im Initial program 99.8%
neg-sub099.8%
Simplified99.8%
Taylor expanded in re around 0 83.1%
if -0.00419999999999999974 < im < 1.29999999999999989e-4Initial program 5.9%
neg-sub05.9%
Simplified5.9%
Taylor expanded in im around 0 99.8%
associate-*r*99.8%
neg-mul-199.8%
Simplified99.8%
Final simplification91.4%
(FPCore (re im) :precision binary64 (if (or (<= im -120.0) (not (<= im 290000000.0))) (* (pow im 7.0) -0.0001984126984126984) (* im (- (cos re)))))
double code(double re, double im) {
double tmp;
if ((im <= -120.0) || !(im <= 290000000.0)) {
tmp = pow(im, 7.0) * -0.0001984126984126984;
} else {
tmp = im * -cos(re);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((im <= (-120.0d0)) .or. (.not. (im <= 290000000.0d0))) then
tmp = (im ** 7.0d0) * (-0.0001984126984126984d0)
else
tmp = im * -cos(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((im <= -120.0) || !(im <= 290000000.0)) {
tmp = Math.pow(im, 7.0) * -0.0001984126984126984;
} else {
tmp = im * -Math.cos(re);
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= -120.0) or not (im <= 290000000.0): tmp = math.pow(im, 7.0) * -0.0001984126984126984 else: tmp = im * -math.cos(re) return tmp
function code(re, im) tmp = 0.0 if ((im <= -120.0) || !(im <= 290000000.0)) tmp = Float64((im ^ 7.0) * -0.0001984126984126984); else tmp = Float64(im * Float64(-cos(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((im <= -120.0) || ~((im <= 290000000.0))) tmp = (im ^ 7.0) * -0.0001984126984126984; else tmp = im * -cos(re); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, -120.0], N[Not[LessEqual[im, 290000000.0]], $MachinePrecision]], N[(N[Power[im, 7.0], $MachinePrecision] * -0.0001984126984126984), $MachinePrecision], N[(im * (-N[Cos[re], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq -120 \lor \neg \left(im \leq 290000000\right):\\
\;\;\;\;{im}^{7} \cdot -0.0001984126984126984\\
\mathbf{else}:\\
\;\;\;\;im \cdot \left(-\cos re\right)\\
\end{array}
\end{array}
if im < -120 or 2.9e8 < im Initial program 100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 88.0%
Taylor expanded in im around inf 88.0%
*-commutative88.0%
associate-*l*88.0%
Simplified88.0%
Taylor expanded in re around 0 72.3%
if -120 < im < 2.9e8Initial program 7.2%
neg-sub07.2%
Simplified7.2%
Taylor expanded in im around 0 99.0%
associate-*r*99.0%
neg-mul-199.0%
Simplified99.0%
Final simplification85.8%
(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 53.2%
neg-sub053.2%
Simplified53.2%
Taylor expanded in im around 0 52.6%
associate-*r*52.6%
neg-mul-152.6%
Simplified52.6%
Final simplification52.6%
(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.2%
neg-sub053.2%
Simplified53.2%
Taylor expanded in re around 0 44.6%
Taylor expanded in im around 0 32.2%
Final simplification32.2%
(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 53.2%
neg-sub053.2%
Simplified53.2%
Taylor expanded in im around 0 52.6%
associate-*r*52.6%
neg-mul-152.6%
Simplified52.6%
Taylor expanded in re around 0 31.9%
mul-1-neg31.9%
Simplified31.9%
Final simplification31.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 2023292
(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))))