
(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
(let* ((t_0 (- (exp (- im)) (exp im))))
(if (<= t_0 (- INFINITY))
(log (exp (* (- im) (cos re))))
(if (<= t_0 4e-5)
(* (cos re) (- (* (pow im 3.0) -0.16666666666666666) im))
(* (* (cos re) 0.5) t_0)))))
double code(double re, double im) {
double t_0 = exp(-im) - exp(im);
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = log(exp((-im * cos(re))));
} else if (t_0 <= 4e-5) {
tmp = cos(re) * ((pow(im, 3.0) * -0.16666666666666666) - im);
} else {
tmp = (cos(re) * 0.5) * t_0;
}
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) {
tmp = Math.log(Math.exp((-im * Math.cos(re))));
} else if (t_0 <= 4e-5) {
tmp = Math.cos(re) * ((Math.pow(im, 3.0) * -0.16666666666666666) - im);
} else {
tmp = (Math.cos(re) * 0.5) * t_0;
}
return tmp;
}
def code(re, im): t_0 = math.exp(-im) - math.exp(im) tmp = 0 if t_0 <= -math.inf: tmp = math.log(math.exp((-im * math.cos(re)))) elif t_0 <= 4e-5: tmp = math.cos(re) * ((math.pow(im, 3.0) * -0.16666666666666666) - im) else: tmp = (math.cos(re) * 0.5) * t_0 return tmp
function code(re, im) t_0 = Float64(exp(Float64(-im)) - exp(im)) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = log(exp(Float64(Float64(-im) * cos(re)))); elseif (t_0 <= 4e-5) tmp = Float64(cos(re) * Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im)); else tmp = Float64(Float64(cos(re) * 0.5) * t_0); end return tmp end
function tmp_2 = code(re, im) t_0 = exp(-im) - exp(im); tmp = 0.0; if (t_0 <= -Inf) tmp = log(exp((-im * cos(re)))); elseif (t_0 <= 4e-5) tmp = cos(re) * (((im ^ 3.0) * -0.16666666666666666) - im); else tmp = (cos(re) * 0.5) * t_0; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[Log[N[Exp[N[((-im) * N[Cos[re], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision], If[LessEqual[t$95$0, 4e-5], N[(N[Cos[re], $MachinePrecision] * N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * t$95$0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-im} - e^{im}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;\log \left(e^{\left(-im\right) \cdot \cos re}\right)\\
\mathbf{elif}\;t_0 \leq 4 \cdot 10^{-5}:\\
\;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot t_0\\
\end{array}
\end{array}
if (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < -inf.0Initial program 100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 5.2%
associate-*r*5.2%
neg-mul-15.2%
Simplified5.2%
distribute-lft-neg-out5.2%
add-sqr-sqrt5.2%
sqrt-unprod56.8%
sqr-neg56.8%
sqrt-unprod0.0%
add-sqr-sqrt0.3%
log1p-expm1-u0.0%
log1p-udef0.0%
neg-log0.0%
add-sqr-sqrt0.0%
sqrt-unprod100.0%
sqr-neg100.0%
sqrt-unprod100.0%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
Taylor expanded in im around inf 100.0%
rec-exp100.0%
distribute-lft-neg-in100.0%
Simplified100.0%
if -inf.0 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < 4.00000000000000033e-5Initial program 7.8%
neg-sub07.8%
Simplified7.8%
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%
if 4.00000000000000033e-5 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) Initial program 100.0%
neg-sub0100.0%
Simplified100.0%
Final simplification99.9%
(FPCore (re im) :precision binary64 (if (or (<= im -700.0) (not (<= im 720.0))) (log (exp (* (- im) (cos re)))) (* (cos re) (- (* (pow im 3.0) -0.16666666666666666) im))))
double code(double re, double im) {
double tmp;
if ((im <= -700.0) || !(im <= 720.0)) {
tmp = log(exp((-im * cos(re))));
} 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) :: tmp
if ((im <= (-700.0d0)) .or. (.not. (im <= 720.0d0))) then
tmp = log(exp((-im * cos(re))))
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 tmp;
if ((im <= -700.0) || !(im <= 720.0)) {
tmp = Math.log(Math.exp((-im * Math.cos(re))));
} else {
tmp = Math.cos(re) * ((Math.pow(im, 3.0) * -0.16666666666666666) - im);
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= -700.0) or not (im <= 720.0): tmp = math.log(math.exp((-im * math.cos(re)))) else: tmp = math.cos(re) * ((math.pow(im, 3.0) * -0.16666666666666666) - im) return tmp
function code(re, im) tmp = 0.0 if ((im <= -700.0) || !(im <= 720.0)) tmp = log(exp(Float64(Float64(-im) * cos(re)))); else tmp = Float64(cos(re) * Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((im <= -700.0) || ~((im <= 720.0))) tmp = log(exp((-im * cos(re)))); else tmp = cos(re) * (((im ^ 3.0) * -0.16666666666666666) - im); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, -700.0], N[Not[LessEqual[im, 720.0]], $MachinePrecision]], N[Log[N[Exp[N[((-im) * N[Cos[re], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $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}
\mathbf{if}\;im \leq -700 \lor \neg \left(im \leq 720\right):\\
\;\;\;\;\log \left(e^{\left(-im\right) \cdot \cos re}\right)\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\
\end{array}
\end{array}
if im < -700 or 720 < im Initial program 100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 5.3%
associate-*r*5.3%
neg-mul-15.3%
Simplified5.3%
distribute-lft-neg-out5.3%
add-sqr-sqrt2.7%
sqrt-unprod29.6%
sqr-neg29.6%
sqrt-unprod0.2%
add-sqr-sqrt0.3%
log1p-expm1-u0.0%
log1p-udef0.0%
neg-log0.0%
add-sqr-sqrt0.0%
sqrt-unprod51.9%
sqr-neg51.9%
sqrt-unprod51.9%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
Taylor expanded in im around inf 100.0%
rec-exp100.0%
distribute-lft-neg-in100.0%
Simplified100.0%
if -700 < im < 720Initial program 9.2%
neg-sub09.2%
Simplified9.2%
Taylor expanded in im around 0 98.9%
+-commutative98.9%
mul-1-neg98.9%
unsub-neg98.9%
associate-*r*98.9%
distribute-rgt-out--98.9%
*-commutative98.9%
Simplified98.9%
Final simplification99.5%
(FPCore (re im)
:precision binary64
(let* ((t_0 (- (log (exp im))))
(t_1 (* -0.16666666666666666 (* (cos re) (pow im 3.0)))))
(if (<= im -2.4e+141)
t_1
(if (<= im -210000000000.0)
t_0
(if (<= im 700.0) (* (- im) (cos re)) (if (<= im 5e+95) t_0 t_1))))))
double code(double re, double im) {
double t_0 = -log(exp(im));
double t_1 = -0.16666666666666666 * (cos(re) * pow(im, 3.0));
double tmp;
if (im <= -2.4e+141) {
tmp = t_1;
} else if (im <= -210000000000.0) {
tmp = t_0;
} else if (im <= 700.0) {
tmp = -im * cos(re);
} else if (im <= 5e+95) {
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 = -log(exp(im))
t_1 = (-0.16666666666666666d0) * (cos(re) * (im ** 3.0d0))
if (im <= (-2.4d+141)) then
tmp = t_1
else if (im <= (-210000000000.0d0)) then
tmp = t_0
else if (im <= 700.0d0) then
tmp = -im * cos(re)
else if (im <= 5d+95) 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 = -Math.log(Math.exp(im));
double t_1 = -0.16666666666666666 * (Math.cos(re) * Math.pow(im, 3.0));
double tmp;
if (im <= -2.4e+141) {
tmp = t_1;
} else if (im <= -210000000000.0) {
tmp = t_0;
} else if (im <= 700.0) {
tmp = -im * Math.cos(re);
} else if (im <= 5e+95) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(re, im): t_0 = -math.log(math.exp(im)) t_1 = -0.16666666666666666 * (math.cos(re) * math.pow(im, 3.0)) tmp = 0 if im <= -2.4e+141: tmp = t_1 elif im <= -210000000000.0: tmp = t_0 elif im <= 700.0: tmp = -im * math.cos(re) elif im <= 5e+95: tmp = t_0 else: tmp = t_1 return tmp
function code(re, im) t_0 = Float64(-log(exp(im))) t_1 = Float64(-0.16666666666666666 * Float64(cos(re) * (im ^ 3.0))) tmp = 0.0 if (im <= -2.4e+141) tmp = t_1; elseif (im <= -210000000000.0) tmp = t_0; elseif (im <= 700.0) tmp = Float64(Float64(-im) * cos(re)); elseif (im <= 5e+95) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(re, im) t_0 = -log(exp(im)); t_1 = -0.16666666666666666 * (cos(re) * (im ^ 3.0)); tmp = 0.0; if (im <= -2.4e+141) tmp = t_1; elseif (im <= -210000000000.0) tmp = t_0; elseif (im <= 700.0) tmp = -im * cos(re); elseif (im <= 5e+95) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = (-N[Log[N[Exp[im], $MachinePrecision]], $MachinePrecision])}, Block[{t$95$1 = N[(-0.16666666666666666 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -2.4e+141], t$95$1, If[LessEqual[im, -210000000000.0], t$95$0, If[LessEqual[im, 700.0], N[((-im) * N[Cos[re], $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 5e+95], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\log \left(e^{im}\right)\\
t_1 := -0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right)\\
\mathbf{if}\;im \leq -2.4 \cdot 10^{+141}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;im \leq -210000000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;im \leq 700:\\
\;\;\;\;\left(-im\right) \cdot \cos re\\
\mathbf{elif}\;im \leq 5 \cdot 10^{+95}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if im < -2.39999999999999997e141 or 5.00000000000000025e95 < im Initial program 100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 98.8%
+-commutative98.8%
mul-1-neg98.8%
unsub-neg98.8%
associate-*r*98.8%
distribute-rgt-out--98.8%
*-commutative98.8%
Simplified98.8%
Taylor expanded in im around inf 98.8%
if -2.39999999999999997e141 < im < -2.1e11 or 700 < im < 5.00000000000000025e95Initial program 100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 3.7%
associate-*r*3.7%
neg-mul-13.7%
Simplified3.7%
distribute-lft-neg-out3.7%
add-sqr-sqrt1.5%
sqrt-unprod1.8%
sqr-neg1.8%
sqrt-unprod0.3%
add-sqr-sqrt0.5%
log1p-expm1-u0.0%
log1p-udef0.0%
neg-log0.0%
add-sqr-sqrt0.0%
sqrt-unprod42.3%
sqr-neg42.3%
sqrt-unprod42.3%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
Taylor expanded in re around 0 78.8%
log-rec78.8%
Simplified78.8%
if -2.1e11 < im < 700Initial program 10.7%
neg-sub010.7%
Simplified10.7%
Taylor expanded in im around 0 96.8%
associate-*r*96.8%
neg-mul-196.8%
Simplified96.8%
Final simplification93.8%
(FPCore (re im)
:precision binary64
(let* ((t_0 (- (log (exp im))))
(t_1 (* -0.16666666666666666 (* (cos re) (pow im 3.0)))))
(if (<= im -2.4e+141)
t_1
(if (<= im -210000000000.0)
t_0
(if (<= im 700.0)
(* (cos re) (- (* (pow im 3.0) -0.16666666666666666) im))
(if (<= im 5e+95) t_0 t_1))))))
double code(double re, double im) {
double t_0 = -log(exp(im));
double t_1 = -0.16666666666666666 * (cos(re) * pow(im, 3.0));
double tmp;
if (im <= -2.4e+141) {
tmp = t_1;
} else if (im <= -210000000000.0) {
tmp = t_0;
} else if (im <= 700.0) {
tmp = cos(re) * ((pow(im, 3.0) * -0.16666666666666666) - im);
} else if (im <= 5e+95) {
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 = -log(exp(im))
t_1 = (-0.16666666666666666d0) * (cos(re) * (im ** 3.0d0))
if (im <= (-2.4d+141)) then
tmp = t_1
else if (im <= (-210000000000.0d0)) then
tmp = t_0
else if (im <= 700.0d0) then
tmp = cos(re) * (((im ** 3.0d0) * (-0.16666666666666666d0)) - im)
else if (im <= 5d+95) 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 = -Math.log(Math.exp(im));
double t_1 = -0.16666666666666666 * (Math.cos(re) * Math.pow(im, 3.0));
double tmp;
if (im <= -2.4e+141) {
tmp = t_1;
} else if (im <= -210000000000.0) {
tmp = t_0;
} else if (im <= 700.0) {
tmp = Math.cos(re) * ((Math.pow(im, 3.0) * -0.16666666666666666) - im);
} else if (im <= 5e+95) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(re, im): t_0 = -math.log(math.exp(im)) t_1 = -0.16666666666666666 * (math.cos(re) * math.pow(im, 3.0)) tmp = 0 if im <= -2.4e+141: tmp = t_1 elif im <= -210000000000.0: tmp = t_0 elif im <= 700.0: tmp = math.cos(re) * ((math.pow(im, 3.0) * -0.16666666666666666) - im) elif im <= 5e+95: tmp = t_0 else: tmp = t_1 return tmp
function code(re, im) t_0 = Float64(-log(exp(im))) t_1 = Float64(-0.16666666666666666 * Float64(cos(re) * (im ^ 3.0))) tmp = 0.0 if (im <= -2.4e+141) tmp = t_1; elseif (im <= -210000000000.0) tmp = t_0; elseif (im <= 700.0) tmp = Float64(cos(re) * Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im)); elseif (im <= 5e+95) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(re, im) t_0 = -log(exp(im)); t_1 = -0.16666666666666666 * (cos(re) * (im ^ 3.0)); tmp = 0.0; if (im <= -2.4e+141) tmp = t_1; elseif (im <= -210000000000.0) tmp = t_0; elseif (im <= 700.0) tmp = cos(re) * (((im ^ 3.0) * -0.16666666666666666) - im); elseif (im <= 5e+95) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = (-N[Log[N[Exp[im], $MachinePrecision]], $MachinePrecision])}, Block[{t$95$1 = N[(-0.16666666666666666 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -2.4e+141], t$95$1, If[LessEqual[im, -210000000000.0], t$95$0, If[LessEqual[im, 700.0], N[(N[Cos[re], $MachinePrecision] * N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 5e+95], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\log \left(e^{im}\right)\\
t_1 := -0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right)\\
\mathbf{if}\;im \leq -2.4 \cdot 10^{+141}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;im \leq -210000000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;im \leq 700:\\
\;\;\;\;\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\
\mathbf{elif}\;im \leq 5 \cdot 10^{+95}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if im < -2.39999999999999997e141 or 5.00000000000000025e95 < im Initial program 100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 98.8%
+-commutative98.8%
mul-1-neg98.8%
unsub-neg98.8%
associate-*r*98.8%
distribute-rgt-out--98.8%
*-commutative98.8%
Simplified98.8%
Taylor expanded in im around inf 98.8%
if -2.39999999999999997e141 < im < -2.1e11 or 700 < im < 5.00000000000000025e95Initial program 100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 3.7%
associate-*r*3.7%
neg-mul-13.7%
Simplified3.7%
distribute-lft-neg-out3.7%
add-sqr-sqrt1.5%
sqrt-unprod1.8%
sqr-neg1.8%
sqrt-unprod0.3%
add-sqr-sqrt0.5%
log1p-expm1-u0.0%
log1p-udef0.0%
neg-log0.0%
add-sqr-sqrt0.0%
sqrt-unprod42.3%
sqr-neg42.3%
sqrt-unprod42.3%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
Taylor expanded in re around 0 78.8%
log-rec78.8%
Simplified78.8%
if -2.1e11 < im < 700Initial program 10.7%
neg-sub010.7%
Simplified10.7%
Taylor expanded in im around 0 97.3%
+-commutative97.3%
mul-1-neg97.3%
unsub-neg97.3%
associate-*r*97.3%
distribute-rgt-out--97.3%
*-commutative97.3%
Simplified97.3%
Final simplification94.1%
(FPCore (re im) :precision binary64 (if (or (<= im -210000000000.0) (not (<= im 700.0))) (- (log (exp im))) (* (- im) (cos re))))
double code(double re, double im) {
double tmp;
if ((im <= -210000000000.0) || !(im <= 700.0)) {
tmp = -log(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 <= (-210000000000.0d0)) .or. (.not. (im <= 700.0d0))) then
tmp = -log(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 <= -210000000000.0) || !(im <= 700.0)) {
tmp = -Math.log(Math.exp(im));
} else {
tmp = -im * Math.cos(re);
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= -210000000000.0) or not (im <= 700.0): tmp = -math.log(math.exp(im)) else: tmp = -im * math.cos(re) return tmp
function code(re, im) tmp = 0.0 if ((im <= -210000000000.0) || !(im <= 700.0)) tmp = Float64(-log(exp(im))); else tmp = Float64(Float64(-im) * cos(re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((im <= -210000000000.0) || ~((im <= 700.0))) tmp = -log(exp(im)); else tmp = -im * cos(re); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, -210000000000.0], N[Not[LessEqual[im, 700.0]], $MachinePrecision]], (-N[Log[N[Exp[im], $MachinePrecision]], $MachinePrecision]), N[((-im) * N[Cos[re], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq -210000000000 \lor \neg \left(im \leq 700\right):\\
\;\;\;\;-\log \left(e^{im}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-im\right) \cdot \cos re\\
\end{array}
\end{array}
if im < -2.1e11 or 700 < im Initial program 100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 5.3%
associate-*r*5.3%
neg-mul-15.3%
Simplified5.3%
distribute-lft-neg-out5.3%
add-sqr-sqrt2.8%
sqrt-unprod30.0%
sqr-neg30.0%
sqrt-unprod0.1%
add-sqr-sqrt0.3%
log1p-expm1-u0.0%
log1p-udef0.0%
neg-log0.0%
add-sqr-sqrt0.0%
sqrt-unprod52.7%
sqr-neg52.7%
sqrt-unprod52.7%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
Taylor expanded in re around 0 72.5%
log-rec72.5%
Simplified72.5%
if -2.1e11 < im < 700Initial program 10.7%
neg-sub010.7%
Simplified10.7%
Taylor expanded in im around 0 96.8%
associate-*r*96.8%
neg-mul-196.8%
Simplified96.8%
Final simplification84.4%
(FPCore (re im)
:precision binary64
(let* ((t_0 (- (* (pow im 3.0) -0.16666666666666666) im)))
(if (<= im -4.2e+101)
t_0
(if (<= im -700.0)
(* (pow re 2.0) (* im 0.5))
(if (<= im 1650000000.0) (* (- im) (cos re)) t_0)))))
double code(double re, double im) {
double t_0 = (pow(im, 3.0) * -0.16666666666666666) - im;
double tmp;
if (im <= -4.2e+101) {
tmp = t_0;
} else if (im <= -700.0) {
tmp = pow(re, 2.0) * (im * 0.5);
} else if (im <= 1650000000.0) {
tmp = -im * cos(re);
} else {
tmp = t_0;
}
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 = ((im ** 3.0d0) * (-0.16666666666666666d0)) - im
if (im <= (-4.2d+101)) then
tmp = t_0
else if (im <= (-700.0d0)) then
tmp = (re ** 2.0d0) * (im * 0.5d0)
else if (im <= 1650000000.0d0) then
tmp = -im * cos(re)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = (Math.pow(im, 3.0) * -0.16666666666666666) - im;
double tmp;
if (im <= -4.2e+101) {
tmp = t_0;
} else if (im <= -700.0) {
tmp = Math.pow(re, 2.0) * (im * 0.5);
} else if (im <= 1650000000.0) {
tmp = -im * Math.cos(re);
} else {
tmp = t_0;
}
return tmp;
}
def code(re, im): t_0 = (math.pow(im, 3.0) * -0.16666666666666666) - im tmp = 0 if im <= -4.2e+101: tmp = t_0 elif im <= -700.0: tmp = math.pow(re, 2.0) * (im * 0.5) elif im <= 1650000000.0: tmp = -im * math.cos(re) else: tmp = t_0 return tmp
function code(re, im) t_0 = Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im) tmp = 0.0 if (im <= -4.2e+101) tmp = t_0; elseif (im <= -700.0) tmp = Float64((re ^ 2.0) * Float64(im * 0.5)); elseif (im <= 1650000000.0) tmp = Float64(Float64(-im) * cos(re)); else tmp = t_0; end return tmp end
function tmp_2 = code(re, im) t_0 = ((im ^ 3.0) * -0.16666666666666666) - im; tmp = 0.0; if (im <= -4.2e+101) tmp = t_0; elseif (im <= -700.0) tmp = (re ^ 2.0) * (im * 0.5); elseif (im <= 1650000000.0) tmp = -im * cos(re); else tmp = t_0; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision]}, If[LessEqual[im, -4.2e+101], t$95$0, If[LessEqual[im, -700.0], N[(N[Power[re, 2.0], $MachinePrecision] * N[(im * 0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1650000000.0], N[((-im) * N[Cos[re], $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {im}^{3} \cdot -0.16666666666666666 - im\\
\mathbf{if}\;im \leq -4.2 \cdot 10^{+101}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;im \leq -700:\\
\;\;\;\;{re}^{2} \cdot \left(im \cdot 0.5\right)\\
\mathbf{elif}\;im \leq 1650000000:\\
\;\;\;\;\left(-im\right) \cdot \cos re\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if im < -4.2e101 or 1.65e9 < im Initial program 100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 79.4%
+-commutative79.4%
mul-1-neg79.4%
unsub-neg79.4%
associate-*r*79.4%
distribute-rgt-out--79.4%
*-commutative79.4%
Simplified79.4%
Taylor expanded in re around 0 57.3%
if -4.2e101 < im < -700Initial program 100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 3.6%
associate-*r*3.6%
neg-mul-13.6%
Simplified3.6%
Taylor expanded in re around 0 32.4%
mul-1-neg32.4%
+-commutative32.4%
*-commutative32.4%
associate-*l*32.4%
mul-1-neg32.4%
*-commutative32.4%
distribute-lft-out32.4%
Simplified32.4%
Taylor expanded in re around inf 31.3%
associate-*r*31.3%
*-commutative31.3%
*-commutative31.3%
Simplified31.3%
if -700 < im < 1.65e9Initial program 9.2%
neg-sub09.2%
Simplified9.2%
Taylor expanded in im around 0 98.3%
associate-*r*98.3%
neg-mul-198.3%
Simplified98.3%
Final simplification74.7%
(FPCore (re im)
:precision binary64
(let* ((t_0 (- (* (pow im 3.0) -0.16666666666666666) im)))
(if (<= im -4.5e+101)
t_0
(if (<= im -480.0)
(* im (+ (* 0.5 (pow re 2.0)) -1.0))
(if (<= im 1650000000.0) (* (- im) (cos re)) t_0)))))
double code(double re, double im) {
double t_0 = (pow(im, 3.0) * -0.16666666666666666) - im;
double tmp;
if (im <= -4.5e+101) {
tmp = t_0;
} else if (im <= -480.0) {
tmp = im * ((0.5 * pow(re, 2.0)) + -1.0);
} else if (im <= 1650000000.0) {
tmp = -im * cos(re);
} else {
tmp = t_0;
}
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 = ((im ** 3.0d0) * (-0.16666666666666666d0)) - im
if (im <= (-4.5d+101)) then
tmp = t_0
else if (im <= (-480.0d0)) then
tmp = im * ((0.5d0 * (re ** 2.0d0)) + (-1.0d0))
else if (im <= 1650000000.0d0) then
tmp = -im * cos(re)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = (Math.pow(im, 3.0) * -0.16666666666666666) - im;
double tmp;
if (im <= -4.5e+101) {
tmp = t_0;
} else if (im <= -480.0) {
tmp = im * ((0.5 * Math.pow(re, 2.0)) + -1.0);
} else if (im <= 1650000000.0) {
tmp = -im * Math.cos(re);
} else {
tmp = t_0;
}
return tmp;
}
def code(re, im): t_0 = (math.pow(im, 3.0) * -0.16666666666666666) - im tmp = 0 if im <= -4.5e+101: tmp = t_0 elif im <= -480.0: tmp = im * ((0.5 * math.pow(re, 2.0)) + -1.0) elif im <= 1650000000.0: tmp = -im * math.cos(re) else: tmp = t_0 return tmp
function code(re, im) t_0 = Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im) tmp = 0.0 if (im <= -4.5e+101) tmp = t_0; elseif (im <= -480.0) tmp = Float64(im * Float64(Float64(0.5 * (re ^ 2.0)) + -1.0)); elseif (im <= 1650000000.0) tmp = Float64(Float64(-im) * cos(re)); else tmp = t_0; end return tmp end
function tmp_2 = code(re, im) t_0 = ((im ^ 3.0) * -0.16666666666666666) - im; tmp = 0.0; if (im <= -4.5e+101) tmp = t_0; elseif (im <= -480.0) tmp = im * ((0.5 * (re ^ 2.0)) + -1.0); elseif (im <= 1650000000.0) tmp = -im * cos(re); else tmp = t_0; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision]}, If[LessEqual[im, -4.5e+101], t$95$0, If[LessEqual[im, -480.0], N[(im * N[(N[(0.5 * N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1650000000.0], N[((-im) * N[Cos[re], $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {im}^{3} \cdot -0.16666666666666666 - im\\
\mathbf{if}\;im \leq -4.5 \cdot 10^{+101}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;im \leq -480:\\
\;\;\;\;im \cdot \left(0.5 \cdot {re}^{2} + -1\right)\\
\mathbf{elif}\;im \leq 1650000000:\\
\;\;\;\;\left(-im\right) \cdot \cos re\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if im < -4.5000000000000002e101 or 1.65e9 < im Initial program 100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 79.4%
+-commutative79.4%
mul-1-neg79.4%
unsub-neg79.4%
associate-*r*79.4%
distribute-rgt-out--79.4%
*-commutative79.4%
Simplified79.4%
Taylor expanded in re around 0 57.3%
if -4.5000000000000002e101 < im < -480Initial program 100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 3.6%
associate-*r*3.6%
neg-mul-13.6%
Simplified3.6%
Taylor expanded in re around 0 32.4%
mul-1-neg32.4%
+-commutative32.4%
*-commutative32.4%
associate-*l*32.4%
mul-1-neg32.4%
*-commutative32.4%
distribute-lft-out32.4%
Simplified32.4%
if -480 < im < 1.65e9Initial program 9.2%
neg-sub09.2%
Simplified9.2%
Taylor expanded in im around 0 98.3%
associate-*r*98.3%
neg-mul-198.3%
Simplified98.3%
Final simplification74.8%
(FPCore (re im) :precision binary64 (if (or (<= im -650.0) (not (<= im 1.7e+50))) (* (pow re 2.0) (* im 0.5)) (* (- im) (cos re))))
double code(double re, double im) {
double tmp;
if ((im <= -650.0) || !(im <= 1.7e+50)) {
tmp = pow(re, 2.0) * (im * 0.5);
} 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 <= (-650.0d0)) .or. (.not. (im <= 1.7d+50))) then
tmp = (re ** 2.0d0) * (im * 0.5d0)
else
tmp = -im * cos(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((im <= -650.0) || !(im <= 1.7e+50)) {
tmp = Math.pow(re, 2.0) * (im * 0.5);
} else {
tmp = -im * Math.cos(re);
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= -650.0) or not (im <= 1.7e+50): tmp = math.pow(re, 2.0) * (im * 0.5) else: tmp = -im * math.cos(re) return tmp
function code(re, im) tmp = 0.0 if ((im <= -650.0) || !(im <= 1.7e+50)) tmp = Float64((re ^ 2.0) * Float64(im * 0.5)); else tmp = Float64(Float64(-im) * cos(re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((im <= -650.0) || ~((im <= 1.7e+50))) tmp = (re ^ 2.0) * (im * 0.5); else tmp = -im * cos(re); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, -650.0], N[Not[LessEqual[im, 1.7e+50]], $MachinePrecision]], N[(N[Power[re, 2.0], $MachinePrecision] * N[(im * 0.5), $MachinePrecision]), $MachinePrecision], N[((-im) * N[Cos[re], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq -650 \lor \neg \left(im \leq 1.7 \cdot 10^{+50}\right):\\
\;\;\;\;{re}^{2} \cdot \left(im \cdot 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-im\right) \cdot \cos re\\
\end{array}
\end{array}
if im < -650 or 1.6999999999999999e50 < im Initial program 100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 5.4%
associate-*r*5.4%
neg-mul-15.4%
Simplified5.4%
Taylor expanded in re around 0 28.5%
mul-1-neg28.5%
+-commutative28.5%
*-commutative28.5%
associate-*l*28.5%
mul-1-neg28.5%
*-commutative28.5%
distribute-lft-out28.5%
Simplified28.5%
Taylor expanded in re around inf 26.2%
associate-*r*26.2%
*-commutative26.2%
*-commutative26.2%
Simplified26.2%
if -650 < im < 1.6999999999999999e50Initial program 16.7%
neg-sub016.7%
Simplified16.7%
Taylor expanded in im around 0 90.5%
associate-*r*90.5%
neg-mul-190.5%
Simplified90.5%
Final simplification59.9%
(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(Float64(-im) * 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}
\\
\left(-im\right) \cdot \cos re
\end{array}
Initial program 56.4%
neg-sub056.4%
Simplified56.4%
Taylor expanded in im around 0 50.0%
associate-*r*50.0%
neg-mul-150.0%
Simplified50.0%
Final simplification50.0%
(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 56.4%
neg-sub056.4%
Simplified56.4%
Taylor expanded in im around 0 50.0%
associate-*r*50.0%
neg-mul-150.0%
Simplified50.0%
Taylor expanded in re around 0 28.6%
mul-1-neg28.6%
Simplified28.6%
Final simplification28.6%
(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 2024024
(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))))