| Alternative 1 | |
|---|---|
| Error | 0.7 |
| Cost | 26752 |
\[\cos re \cdot \left(\left({im}^{3} \cdot -0.16666666666666666 - im\right) + \left({im}^{7} \cdot -0.0001984126984126984 + {im}^{5} \cdot -0.008333333333333333\right)\right)
\]
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
(FPCore (re im)
:precision binary64
(*
(cos re)
(*
0.5
(+
(* -0.0003968253968253968 (pow im 7.0))
(+
(* im -2.0)
(+
(* -0.016666666666666666 (pow im 5.0))
(* -0.3333333333333333 (pow im 3.0))))))))double code(double re, double im) {
return (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
}
double code(double re, double im) {
return cos(re) * (0.5 * ((-0.0003968253968253968 * pow(im, 7.0)) + ((im * -2.0) + ((-0.016666666666666666 * pow(im, 5.0)) + (-0.3333333333333333 * pow(im, 3.0))))));
}
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 = cos(re) * (0.5d0 * (((-0.0003968253968253968d0) * (im ** 7.0d0)) + ((im * (-2.0d0)) + (((-0.016666666666666666d0) * (im ** 5.0d0)) + ((-0.3333333333333333d0) * (im ** 3.0d0))))))
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.cos(re) * (0.5 * ((-0.0003968253968253968 * Math.pow(im, 7.0)) + ((im * -2.0) + ((-0.016666666666666666 * Math.pow(im, 5.0)) + (-0.3333333333333333 * Math.pow(im, 3.0))))));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))
def code(re, im): return math.cos(re) * (0.5 * ((-0.0003968253968253968 * math.pow(im, 7.0)) + ((im * -2.0) + ((-0.016666666666666666 * math.pow(im, 5.0)) + (-0.3333333333333333 * math.pow(im, 3.0))))))
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(cos(re) * Float64(0.5 * Float64(Float64(-0.0003968253968253968 * (im ^ 7.0)) + Float64(Float64(im * -2.0) + Float64(Float64(-0.016666666666666666 * (im ^ 5.0)) + Float64(-0.3333333333333333 * (im ^ 3.0))))))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im)); end
function tmp = code(re, im) tmp = cos(re) * (0.5 * ((-0.0003968253968253968 * (im ^ 7.0)) + ((im * -2.0) + ((-0.016666666666666666 * (im ^ 5.0)) + (-0.3333333333333333 * (im ^ 3.0)))))); 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[Cos[re], $MachinePrecision] * N[(0.5 * N[(N[(-0.0003968253968253968 * N[Power[im, 7.0], $MachinePrecision]), $MachinePrecision] + N[(N[(im * -2.0), $MachinePrecision] + N[(N[(-0.016666666666666666 * N[Power[im, 5.0], $MachinePrecision]), $MachinePrecision] + N[(-0.3333333333333333 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\cos re \cdot \left(0.5 \cdot \left(-0.0003968253968253968 \cdot {im}^{7} + \left(im \cdot -2 + \left(-0.016666666666666666 \cdot {im}^{5} + -0.3333333333333333 \cdot {im}^{3}\right)\right)\right)\right)
Results
| Original | 58.0 |
|---|---|
| Target | 0.3 |
| Herbie | 0.7 |
Initial program 58.0
Simplified58.0
[Start]58.0 | \[ \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\] |
|---|---|
*-commutative [=>]58.0 | \[ \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{0 - im} - e^{im}\right)
\] |
associate-*l* [=>]58.0 | \[ \color{blue}{\cos re \cdot \left(0.5 \cdot \left(e^{0 - im} - e^{im}\right)\right)}
\] |
sub-neg [=>]58.0 | \[ \cos re \cdot \left(0.5 \cdot \color{blue}{\left(e^{0 - im} + \left(-e^{im}\right)\right)}\right)
\] |
sub-neg [<=]58.0 | \[ \cos re \cdot \left(0.5 \cdot \color{blue}{\left(e^{0 - im} - e^{im}\right)}\right)
\] |
sub0-neg [=>]58.0 | \[ \cos re \cdot \left(0.5 \cdot \left(e^{\color{blue}{-im}} - e^{im}\right)\right)
\] |
Taylor expanded in im around 0 0.7
Final simplification0.7
| Alternative 1 | |
|---|---|
| Error | 0.7 |
| Cost | 26752 |
| Alternative 2 | |
|---|---|
| Error | 0.7 |
| Cost | 26560 |
| Alternative 3 | |
|---|---|
| Error | 0.7 |
| Cost | 20032 |
| Alternative 4 | |
|---|---|
| Error | 0.9 |
| Cost | 13312 |
| Alternative 5 | |
|---|---|
| Error | 1.1 |
| Cost | 6976 |
| Alternative 6 | |
|---|---|
| Error | 1.3 |
| Cost | 6656 |
| Alternative 7 | |
|---|---|
| Error | 29.0 |
| Cost | 128 |
herbie shell --seed 2023039
(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))))