| Alternative 1 | |
|---|---|
| Error | 1.0 |
| Cost | 13312 |
\[\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)
\]
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
(FPCore (re im) :precision binary64 (* (+ (- (* (pow im 5.0) -0.008333333333333333) im) (* (pow im 3.0) -0.16666666666666666)) (cos re)))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
}
double code(double re, double im) {
return (((pow(im, 5.0) * -0.008333333333333333) - im) + (pow(im, 3.0) * -0.16666666666666666)) * cos(re);
}
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
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = ((((im ** 5.0d0) * (-0.008333333333333333d0)) - im) + ((im ** 3.0d0) * (-0.16666666666666666d0))) * cos(re)
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp((0.0 - im)) - Math.exp(im));
}
public static double code(double re, double im) {
return (((Math.pow(im, 5.0) * -0.008333333333333333) - im) + (Math.pow(im, 3.0) * -0.16666666666666666)) * Math.cos(re);
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))
def code(re, im): return (((math.pow(im, 5.0) * -0.008333333333333333) - im) + (math.pow(im, 3.0) * -0.16666666666666666)) * math.cos(re)
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) end
function code(re, im) return Float64(Float64(Float64(Float64((im ^ 5.0) * -0.008333333333333333) - im) + Float64((im ^ 3.0) * -0.16666666666666666)) * cos(re)) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im)); end
function tmp = code(re, im) tmp = ((((im ^ 5.0) * -0.008333333333333333) - im) + ((im ^ 3.0) * -0.16666666666666666)) * cos(re); 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]
code[re_, im_] := N[(N[(N[(N[(N[Power[im, 5.0], $MachinePrecision] * -0.008333333333333333), $MachinePrecision] - im), $MachinePrecision] + N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision] * N[Cos[re], $MachinePrecision]), $MachinePrecision]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\left(\left({im}^{5} \cdot -0.008333333333333333 - im\right) + {im}^{3} \cdot -0.16666666666666666\right) \cdot \cos re
Results
| Original | 57.9 |
|---|---|
| Target | 0.3 |
| Herbie | 0.9 |
Initial program 57.9
Taylor expanded in im around 0 0.9
Taylor expanded in re around inf 0.9
Simplified0.9
Final simplification0.9
| Alternative 1 | |
|---|---|
| Error | 1.0 |
| Cost | 13312 |
| Alternative 2 | |
|---|---|
| Error | 1.3 |
| Cost | 6656 |
| Alternative 3 | |
|---|---|
| Error | 29.0 |
| Cost | 128 |
herbie shell --seed 2022317
(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))))