| Alternative 1 | |
|---|---|
| Accuracy | 74.8% |
| Cost | 13124 |
\[\begin{array}{l}
\mathbf{if}\;e^{re} \leq 5 \cdot 10^{-25}:\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;re + \cos im\\
\end{array}
\]
(FPCore (re im) :precision binary64 (* (exp re) (cos im)))
(FPCore (re im) :precision binary64 (if (<= (exp re) 5e-25) (exp re) (* (cos im) (+ re 1.0))))
double code(double re, double im) {
return exp(re) * cos(im);
}
double code(double re, double im) {
double tmp;
if (exp(re) <= 5e-25) {
tmp = exp(re);
} else {
tmp = cos(im) * (re + 1.0);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = exp(re) * cos(im)
end function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (exp(re) <= 5d-25) then
tmp = exp(re)
else
tmp = cos(im) * (re + 1.0d0)
end if
code = tmp
end function
public static double code(double re, double im) {
return Math.exp(re) * Math.cos(im);
}
public static double code(double re, double im) {
double tmp;
if (Math.exp(re) <= 5e-25) {
tmp = Math.exp(re);
} else {
tmp = Math.cos(im) * (re + 1.0);
}
return tmp;
}
def code(re, im): return math.exp(re) * math.cos(im)
def code(re, im): tmp = 0 if math.exp(re) <= 5e-25: tmp = math.exp(re) else: tmp = math.cos(im) * (re + 1.0) return tmp
function code(re, im) return Float64(exp(re) * cos(im)) end
function code(re, im) tmp = 0.0 if (exp(re) <= 5e-25) tmp = exp(re); else tmp = Float64(cos(im) * Float64(re + 1.0)); end return tmp end
function tmp = code(re, im) tmp = exp(re) * cos(im); end
function tmp_2 = code(re, im) tmp = 0.0; if (exp(re) <= 5e-25) tmp = exp(re); else tmp = cos(im) * (re + 1.0); end tmp_2 = tmp; end
code[re_, im_] := N[(N[Exp[re], $MachinePrecision] * N[Cos[im], $MachinePrecision]), $MachinePrecision]
code[re_, im_] := If[LessEqual[N[Exp[re], $MachinePrecision], 5e-25], N[Exp[re], $MachinePrecision], N[(N[Cos[im], $MachinePrecision] * N[(re + 1.0), $MachinePrecision]), $MachinePrecision]]
e^{re} \cdot \cos im
\begin{array}{l}
\mathbf{if}\;e^{re} \leq 5 \cdot 10^{-25}:\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;\cos im \cdot \left(re + 1\right)\\
\end{array}
Results
if (exp.f64 re) < 4.99999999999999962e-25Initial program 100.0%
Taylor expanded in im around 0 100.0%
if 4.99999999999999962e-25 < (exp.f64 re) Initial program 67.9%
Taylor expanded in re around 0 68.0%
Simplified68.0%
[Start]68.0 | \[ \cos im \cdot re + \cos im
\] |
|---|---|
*-rgt-identity [<=]68.0 | \[ \cos im \cdot re + \color{blue}{\cos im \cdot 1}
\] |
distribute-lft-in [<=]68.0 | \[ \color{blue}{\cos im \cdot \left(re + 1\right)}
\] |
Final simplification76.6%
| Alternative 1 | |
|---|---|
| Accuracy | 74.8% |
| Cost | 13124 |
| Alternative 2 | |
|---|---|
| Accuracy | 75.1% |
| Cost | 12992 |
| Alternative 3 | |
|---|---|
| Accuracy | 74.5% |
| Cost | 6596 |
| Alternative 4 | |
|---|---|
| Accuracy | 50.3% |
| Cost | 6464 |
| Alternative 5 | |
|---|---|
| Accuracy | 28.4% |
| Cost | 192 |
herbie shell --seed 2023157
(FPCore (re im)
:name "math.exp on complex, real part"
:precision binary64
(* (exp re) (cos im)))