| Alternative 1 | |
|---|---|
| Error | 0.8 |
| Cost | 13568 |
\[\left(\cos re \cdot -0.5\right) \cdot \left(2 \cdot im + 0.3333333333333333 \cdot {im}^{3}\right)
\]
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
(FPCore (re im) :precision binary64 (+ (* (cos re) (- im)) (* -0.16666666666666666 (* (pow im 3.0) (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 (cos(re) * -im) + (-0.16666666666666666 * (pow(im, 3.0) * 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 = (cos(re) * -im) + ((-0.16666666666666666d0) * ((im ** 3.0d0) * 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.cos(re) * -im) + (-0.16666666666666666 * (Math.pow(im, 3.0) * 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.cos(re) * -im) + (-0.16666666666666666 * (math.pow(im, 3.0) * 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(cos(re) * Float64(-im)) + Float64(-0.16666666666666666 * Float64((im ^ 3.0) * 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 = (cos(re) * -im) + (-0.16666666666666666 * ((im ^ 3.0) * 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[Cos[re], $MachinePrecision] * (-im)), $MachinePrecision] + N[(-0.16666666666666666 * N[(N[Power[im, 3.0], $MachinePrecision] * N[Cos[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\cos re \cdot \left(-im\right) + -0.16666666666666666 \cdot \left({im}^{3} \cdot \cos re\right)
Results
| Original | 58.2 |
|---|---|
| Target | 0.2 |
| Herbie | 0.8 |
Initial program 58.2
Simplified58.2
[Start]58.2 | \[ \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\] |
|---|---|
rational.json-simplify-25 [=>]58.2 | \[ \color{blue}{\left(-0.5 \cdot \cos re\right) \cdot \left(e^{im} - e^{0 - im}\right)}
\] |
rational.json-simplify-69 [=>]58.2 | \[ \color{blue}{\frac{0.5 \cdot \cos re}{-1}} \cdot \left(e^{im} - e^{0 - im}\right)
\] |
rational.json-simplify-19 [=>]58.2 | \[ \color{blue}{\left(\cos re \cdot \frac{0.5}{-1}\right)} \cdot \left(e^{im} - e^{0 - im}\right)
\] |
metadata-eval [=>]58.2 | \[ \left(\cos re \cdot \color{blue}{-0.5}\right) \cdot \left(e^{im} - e^{0 - im}\right)
\] |
rational.json-simplify-68 [=>]58.2 | \[ \left(\cos re \cdot -0.5\right) \cdot \left(e^{im} - e^{\color{blue}{-im}}\right)
\] |
Taylor expanded in im around 0 0.8
Simplified0.8
[Start]0.8 | \[ -0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right) + -1 \cdot \left(\cos re \cdot im\right)
\] |
|---|---|
rational.json-simplify-41 [=>]0.8 | \[ \color{blue}{-1 \cdot \left(\cos re \cdot im\right) + -0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right)}
\] |
rational.json-simplify-3 [=>]0.8 | \[ \color{blue}{\cos re \cdot \left(-1 \cdot im\right)} + -0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right)
\] |
rational.json-simplify-39 [=>]0.8 | \[ \cos re \cdot \color{blue}{\left(im \cdot -1\right)} + -0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right)
\] |
rational.json-simplify-71 [<=]0.8 | \[ \cos re \cdot \color{blue}{\left(-im\right)} + -0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right)
\] |
rational.json-simplify-39 [=>]0.8 | \[ \cos re \cdot \left(-im\right) + -0.16666666666666666 \cdot \color{blue}{\left({im}^{3} \cdot \cos re\right)}
\] |
Final simplification0.8
| Alternative 1 | |
|---|---|
| Error | 0.8 |
| Cost | 13568 |
| Alternative 2 | |
|---|---|
| Error | 0.8 |
| Cost | 13568 |
| Alternative 3 | |
|---|---|
| Error | 1.0 |
| Cost | 13312 |
| Alternative 4 | |
|---|---|
| Error | 1.1 |
| Cost | 6656 |
| Alternative 5 | |
|---|---|
| Error | 29.1 |
| Cost | 128 |
herbie shell --seed 2023066
(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))))