| Alternative 1 | |
|---|---|
| Error | 0.7 |
| Cost | 26752 |
\[\sin re \cdot \left(\left({im}^{7} \cdot -0.0001984126984126984 + -0.008333333333333333 \cdot {im}^{5}\right) + \left({im}^{3} \cdot -0.16666666666666666 - im\right)\right)
\]
(FPCore (re im) :precision binary64 (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))
(FPCore (re im)
:precision binary64
(+
(* (* (pow im 7.0) -0.0001984126984126984) (sin re))
(*
(sin re)
(+
(* -0.008333333333333333 (pow im 5.0))
(- (* (pow im 3.0) -0.16666666666666666) im)))))double code(double re, double im) {
return (0.5 * sin(re)) * (exp(-im) - exp(im));
}
double code(double re, double im) {
return ((pow(im, 7.0) * -0.0001984126984126984) * sin(re)) + (sin(re) * ((-0.008333333333333333 * pow(im, 5.0)) + ((pow(im, 3.0) * -0.16666666666666666) - im)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * sin(re)) * (exp(-im) - exp(im))
end function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (((im ** 7.0d0) * (-0.0001984126984126984d0)) * sin(re)) + (sin(re) * (((-0.008333333333333333d0) * (im ** 5.0d0)) + (((im ** 3.0d0) * (-0.16666666666666666d0)) - im)))
end function
public static double code(double re, double im) {
return (0.5 * Math.sin(re)) * (Math.exp(-im) - Math.exp(im));
}
public static double code(double re, double im) {
return ((Math.pow(im, 7.0) * -0.0001984126984126984) * Math.sin(re)) + (Math.sin(re) * ((-0.008333333333333333 * Math.pow(im, 5.0)) + ((Math.pow(im, 3.0) * -0.16666666666666666) - im)));
}
def code(re, im): return (0.5 * math.sin(re)) * (math.exp(-im) - math.exp(im))
def code(re, im): return ((math.pow(im, 7.0) * -0.0001984126984126984) * math.sin(re)) + (math.sin(re) * ((-0.008333333333333333 * math.pow(im, 5.0)) + ((math.pow(im, 3.0) * -0.16666666666666666) - im)))
function code(re, im) return Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(-im)) - exp(im))) end
function code(re, im) return Float64(Float64(Float64((im ^ 7.0) * -0.0001984126984126984) * sin(re)) + Float64(sin(re) * Float64(Float64(-0.008333333333333333 * (im ^ 5.0)) + Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im)))) end
function tmp = code(re, im) tmp = (0.5 * sin(re)) * (exp(-im) - exp(im)); end
function tmp = code(re, im) tmp = (((im ^ 7.0) * -0.0001984126984126984) * sin(re)) + (sin(re) * ((-0.008333333333333333 * (im ^ 5.0)) + (((im ^ 3.0) * -0.16666666666666666) - im))); end
code[re_, im_] := N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[re_, im_] := N[(N[(N[(N[Power[im, 7.0], $MachinePrecision] * -0.0001984126984126984), $MachinePrecision] * N[Sin[re], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[re], $MachinePrecision] * N[(N[(-0.008333333333333333 * N[Power[im, 5.0], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
\left({im}^{7} \cdot -0.0001984126984126984\right) \cdot \sin re + \sin re \cdot \left(-0.008333333333333333 \cdot {im}^{5} + \left({im}^{3} \cdot -0.16666666666666666 - im\right)\right)
Results
| Original | 43.5 |
|---|---|
| Target | 0.3 |
| Herbie | 0.7 |
Initial program 43.5
Taylor expanded in im around 0 0.7
Simplified0.7
Applied egg-rr0.7
Taylor expanded in re around inf 0.7
Final simplification0.7
| Alternative 1 | |
|---|---|
| Error | 0.7 |
| Cost | 26752 |
| Alternative 2 | |
|---|---|
| Error | 1.0 |
| Cost | 13312 |
| Alternative 3 | |
|---|---|
| Error | 1.4 |
| Cost | 6656 |
| Alternative 4 | |
|---|---|
| Error | 31.7 |
| Cost | 256 |
herbie shell --seed 2022296
(FPCore (re im)
:name "math.cos on complex, imaginary part"
:precision binary64
:herbie-target
(if (< (fabs im) 1.0) (- (* (sin re) (+ (+ im (* (* (* 0.16666666666666666 im) im) im)) (* (* (* (* (* 0.008333333333333333 im) im) im) im) im)))) (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))