| Alternative 1 | |
|---|---|
| Error | 0.02% |
| Cost | 26048 |
\[\cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right)
\]
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
(FPCore (re im) :precision binary64 (+ (/ (* 0.5 (cos re)) (exp im)) (* (cos re) (* 0.5 (exp im)))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp(-im) + exp(im));
}
double code(double re, double im) {
return ((0.5 * cos(re)) / exp(im)) + (cos(re) * (0.5 * exp(im)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * (exp(-im) + exp(im))
end function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = ((0.5d0 * cos(re)) / exp(im)) + (cos(re) * (0.5d0 * exp(im)))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im));
}
public static double code(double re, double im) {
return ((0.5 * Math.cos(re)) / Math.exp(im)) + (Math.cos(re) * (0.5 * Math.exp(im)));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
def code(re, im): return ((0.5 * math.cos(re)) / math.exp(im)) + (math.cos(re) * (0.5 * math.exp(im)))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) end
function code(re, im) return Float64(Float64(Float64(0.5 * cos(re)) / exp(im)) + Float64(cos(re) * Float64(0.5 * exp(im)))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp(-im) + exp(im)); end
function tmp = code(re, im) tmp = ((0.5 * cos(re)) / exp(im)) + (cos(re) * (0.5 * exp(im))); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[re_, im_] := N[(N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] / N[Exp[im], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
\frac{0.5 \cdot \cos re}{e^{im}} + \cos re \cdot \left(0.5 \cdot e^{im}\right)
Results
Initial program 0.02
Simplified0.02
[Start]0.02 | \[ \left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
\] |
|---|---|
*-commutative [=>]0.02 | \[ \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{-im} + e^{im}\right)
\] |
associate-*l* [=>]0.02 | \[ \color{blue}{\cos re \cdot \left(0.5 \cdot \left(e^{-im} + e^{im}\right)\right)}
\] |
+-commutative [=>]0.02 | \[ \cos re \cdot \left(0.5 \cdot \color{blue}{\left(e^{im} + e^{-im}\right)}\right)
\] |
distribute-lft-in [=>]0.02 | \[ \cos re \cdot \color{blue}{\left(0.5 \cdot e^{im} + 0.5 \cdot e^{-im}\right)}
\] |
fma-def [=>]0.02 | \[ \cos re \cdot \color{blue}{\mathsf{fma}\left(0.5, e^{im}, 0.5 \cdot e^{-im}\right)}
\] |
exp-neg [=>]0.02 | \[ \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, 0.5 \cdot \color{blue}{\frac{1}{e^{im}}}\right)
\] |
associate-*r/ [=>]0.02 | \[ \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \color{blue}{\frac{0.5 \cdot 1}{e^{im}}}\right)
\] |
metadata-eval [=>]0.02 | \[ \cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{\color{blue}{0.5}}{e^{im}}\right)
\] |
Applied egg-rr0.02
Final simplification0.02
| Alternative 1 | |
|---|---|
| Error | 0.02% |
| Cost | 26048 |
| Alternative 2 | |
|---|---|
| Error | 0.02% |
| Cost | 19712 |
| Alternative 3 | |
|---|---|
| Error | 1.09% |
| Cost | 13760 |
| Alternative 4 | |
|---|---|
| Error | 1.09% |
| Cost | 13696 |
| Alternative 5 | |
|---|---|
| Error | 1.3% |
| Cost | 13376 |
| Alternative 6 | |
|---|---|
| Error | 1.3% |
| Cost | 13248 |
| Alternative 7 | |
|---|---|
| Error | 1.3% |
| Cost | 6976 |
| Alternative 8 | |
|---|---|
| Error | 1.6% |
| Cost | 6848 |
| Alternative 9 | |
|---|---|
| Error | 1.87% |
| Cost | 6464 |
| Alternative 10 | |
|---|---|
| Error | 46.78% |
| Cost | 448 |
| Alternative 11 | |
|---|---|
| Error | 47.07% |
| Cost | 64 |
herbie shell --seed 2023090
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))