| Alternative 1 | |
|---|---|
| Accuracy | 98.6% |
| Cost | 7104 |
\[\cos re \cdot \left(im \cdot \left(-0.16666666666666666 \cdot \left(im \cdot im\right) + -1\right)\right)
\]
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
(FPCore (re im) :precision binary64 (* (cos re) (- (* (pow im 3.0) -0.16666666666666666) im)))
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) * ((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 * 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 ** 3.0d0) * (-0.16666666666666666d0)) - im)
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) * ((Math.pow(im, 3.0) * -0.16666666666666666) - im);
}
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) * ((math.pow(im, 3.0) * -0.16666666666666666) - im)
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(Float64((im ^ 3.0) * -0.16666666666666666) - im)) 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 ^ 3.0) * -0.16666666666666666) - im); 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[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)
Results
| Original | 9.2% |
|---|---|
| Target | 99.6% |
| Herbie | 98.6% |
Initial program 9.2%
Simplified9.2%
[Start]9.2 | \[ \left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\] |
|---|---|
*-commutative [=>]9.2 | \[ \color{blue}{\left(\cos re \cdot 0.5\right)} \cdot \left(e^{0 - im} - e^{im}\right)
\] |
associate-*l* [=>]9.2 | \[ \color{blue}{\cos re \cdot \left(0.5 \cdot \left(e^{0 - im} - e^{im}\right)\right)}
\] |
sub-neg [=>]9.2 | \[ \cos re \cdot \left(0.5 \cdot \color{blue}{\left(e^{0 - im} + \left(-e^{im}\right)\right)}\right)
\] |
sub-neg [<=]9.2 | \[ \cos re \cdot \left(0.5 \cdot \color{blue}{\left(e^{0 - im} - e^{im}\right)}\right)
\] |
sub0-neg [=>]9.2 | \[ \cos re \cdot \left(0.5 \cdot \left(e^{\color{blue}{-im}} - e^{im}\right)\right)
\] |
Taylor expanded in im around 0 98.6%
Simplified98.6%
[Start]98.6 | \[ -0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right) + -1 \cdot \left(\cos re \cdot im\right)
\] |
|---|---|
mul-1-neg [=>]98.6 | \[ -0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right) + \color{blue}{\left(-\cos re \cdot im\right)}
\] |
unsub-neg [=>]98.6 | \[ \color{blue}{-0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right) - \cos re \cdot im}
\] |
*-commutative [=>]98.6 | \[ -0.16666666666666666 \cdot \color{blue}{\left({im}^{3} \cdot \cos re\right)} - \cos re \cdot im
\] |
associate-*r* [=>]98.6 | \[ \color{blue}{\left(-0.16666666666666666 \cdot {im}^{3}\right) \cdot \cos re} - \cos re \cdot im
\] |
*-commutative [<=]98.6 | \[ \color{blue}{\cos re \cdot \left(-0.16666666666666666 \cdot {im}^{3}\right)} - \cos re \cdot im
\] |
distribute-lft-out-- [=>]98.6 | \[ \color{blue}{\cos re \cdot \left(-0.16666666666666666 \cdot {im}^{3} - im\right)}
\] |
*-commutative [=>]98.6 | \[ \cos re \cdot \left(\color{blue}{{im}^{3} \cdot -0.16666666666666666} - im\right)
\] |
Final simplification98.6%
| Alternative 1 | |
|---|---|
| Accuracy | 98.6% |
| Cost | 7104 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 6976 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.1% |
| Cost | 6656 |
| Alternative 4 | |
|---|---|
| Accuracy | 55.1% |
| Cost | 128 |
herbie shell --seed 2023133
(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))))