| Alternative 1 | |
|---|---|
| Error | 0.0 |
| Cost | 19712 |
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
\]
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
(FPCore (re im)
:precision binary64
(let* ((t_0 (exp (- im))))
(*
(* 0.5 (cos re))
(* (/ 1.0 (+ t_0 (exp im))) (pow (+ (exp im) t_0) 2.0)))))double code(double re, double im) {
return (0.5 * cos(re)) * (exp(-im) + exp(im));
}
double code(double re, double im) {
double t_0 = exp(-im);
return (0.5 * cos(re)) * ((1.0 / (t_0 + exp(im))) * pow((exp(im) + t_0), 2.0));
}
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
real(8) :: t_0
t_0 = exp(-im)
code = (0.5d0 * cos(re)) * ((1.0d0 / (t_0 + exp(im))) * ((exp(im) + t_0) ** 2.0d0))
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) {
double t_0 = Math.exp(-im);
return (0.5 * Math.cos(re)) * ((1.0 / (t_0 + Math.exp(im))) * Math.pow((Math.exp(im) + t_0), 2.0));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
def code(re, im): t_0 = math.exp(-im) return (0.5 * math.cos(re)) * ((1.0 / (t_0 + math.exp(im))) * math.pow((math.exp(im) + t_0), 2.0))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) end
function code(re, im) t_0 = exp(Float64(-im)) return Float64(Float64(0.5 * cos(re)) * Float64(Float64(1.0 / Float64(t_0 + exp(im))) * (Float64(exp(im) + t_0) ^ 2.0))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp(-im) + exp(im)); end
function tmp = code(re, im) t_0 = exp(-im); tmp = (0.5 * cos(re)) * ((1.0 / (t_0 + exp(im))) * ((exp(im) + t_0) ^ 2.0)); 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_] := Block[{t$95$0 = N[Exp[(-im)], $MachinePrecision]}, N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[(1.0 / N[(t$95$0 + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[Exp[im], $MachinePrecision] + t$95$0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
\begin{array}{l}
t_0 := e^{-im}\\
\left(0.5 \cdot \cos re\right) \cdot \left(\frac{1}{t_0 + e^{im}} \cdot {\left(e^{im} + t_0\right)}^{2}\right)
\end{array}
Results
Initial program 0.0
Applied egg-rr0.1
Taylor expanded in im around inf 0.1
Final simplification0.1
| Alternative 1 | |
|---|---|
| Error | 0.0 |
| Cost | 19712 |
| Alternative 2 | |
|---|---|
| Error | 0.8 |
| Cost | 13312 |
| Alternative 3 | |
|---|---|
| Error | 1.0 |
| Cost | 13184 |
| Alternative 4 | |
|---|---|
| Error | 1.2 |
| Cost | 6464 |
| Alternative 5 | |
|---|---|
| Error | 30.1 |
| 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))))