| Alternative 1 | |
|---|---|
| Accuracy | 74.7% |
| Cost | 13124 |
\[\begin{array}{l}
\mathbf{if}\;e^{re} \leq 0.999999999997:\\
\;\;\;\;e^{re} \cdot im\\
\mathbf{else}:\\
\;\;\;\;\sin im\\
\end{array}
\]
(FPCore (re im) :precision binary64 (* (exp re) (sin im)))
(FPCore (re im) :precision binary64 (if (<= (exp re) 0.0) (* (exp re) im) (* (sin im) (+ re 1.0))))
double code(double re, double im) {
return exp(re) * sin(im);
}
double code(double re, double im) {
double tmp;
if (exp(re) <= 0.0) {
tmp = exp(re) * im;
} else {
tmp = sin(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) * sin(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) <= 0.0d0) then
tmp = exp(re) * im
else
tmp = sin(im) * (re + 1.0d0)
end if
code = tmp
end function
public static double code(double re, double im) {
return Math.exp(re) * Math.sin(im);
}
public static double code(double re, double im) {
double tmp;
if (Math.exp(re) <= 0.0) {
tmp = Math.exp(re) * im;
} else {
tmp = Math.sin(im) * (re + 1.0);
}
return tmp;
}
def code(re, im): return math.exp(re) * math.sin(im)
def code(re, im): tmp = 0 if math.exp(re) <= 0.0: tmp = math.exp(re) * im else: tmp = math.sin(im) * (re + 1.0) return tmp
function code(re, im) return Float64(exp(re) * sin(im)) end
function code(re, im) tmp = 0.0 if (exp(re) <= 0.0) tmp = Float64(exp(re) * im); else tmp = Float64(sin(im) * Float64(re + 1.0)); end return tmp end
function tmp = code(re, im) tmp = exp(re) * sin(im); end
function tmp_2 = code(re, im) tmp = 0.0; if (exp(re) <= 0.0) tmp = exp(re) * im; else tmp = sin(im) * (re + 1.0); end tmp_2 = tmp; end
code[re_, im_] := N[(N[Exp[re], $MachinePrecision] * N[Sin[im], $MachinePrecision]), $MachinePrecision]
code[re_, im_] := If[LessEqual[N[Exp[re], $MachinePrecision], 0.0], N[(N[Exp[re], $MachinePrecision] * im), $MachinePrecision], N[(N[Sin[im], $MachinePrecision] * N[(re + 1.0), $MachinePrecision]), $MachinePrecision]]
e^{re} \cdot \sin im
\begin{array}{l}
\mathbf{if}\;e^{re} \leq 0:\\
\;\;\;\;e^{re} \cdot im\\
\mathbf{else}:\\
\;\;\;\;\sin im \cdot \left(re + 1\right)\\
\end{array}
Results
if (exp.f64 re) < 0.0Initial program 100.0%
Taylor expanded in im around 0 100.0%
if 0.0 < (exp.f64 re) Initial program 67.5%
Taylor expanded in re around 0 67.6%
Simplified67.6%
[Start]67.6 | \[ \sin im + \sin im \cdot re
\] |
|---|---|
*-commutative [=>]67.6 | \[ \sin im + \color{blue}{re \cdot \sin im}
\] |
distribute-rgt1-in [=>]67.6 | \[ \color{blue}{\left(re + 1\right) \cdot \sin im}
\] |
Final simplification75.5%
| Alternative 1 | |
|---|---|
| Accuracy | 74.7% |
| Cost | 13124 |
| Alternative 2 | |
|---|---|
| Accuracy | 75.4% |
| Cost | 12992 |
| Alternative 3 | |
|---|---|
| Accuracy | 55.6% |
| Cost | 6596 |
| Alternative 4 | |
|---|---|
| Accuracy | 32.0% |
| Cost | 708 |
| Alternative 5 | |
|---|---|
| Accuracy | 27.3% |
| Cost | 64 |
herbie shell --seed 2023153
(FPCore (re im)
:name "math.exp on complex, imaginary part"
:precision binary64
(* (exp re) (sin im)))