Average Error: 58.0 → 0.6
Time: 9.8s
Precision: binary64
\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
\[\begin{array}{l} \mathbf{if}\;e^{-im} - e^{im} \leq 4.026223700770437 \cdot 10^{-06}:\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(\left(im \cdot -2 - 0.3333333333333333 \cdot {im}^{3}\right) + {im}^{5} \cdot -0.016666666666666666\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot e^{\log \left(e^{-im} - e^{im}\right)}\\ \end{array}\]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\begin{array}{l}
\mathbf{if}\;e^{-im} - e^{im} \leq 4.026223700770437 \cdot 10^{-06}:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(\left(im \cdot -2 - 0.3333333333333333 \cdot {im}^{3}\right) + {im}^{5} \cdot -0.016666666666666666\right)\\

\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot e^{\log \left(e^{-im} - e^{im}\right)}\\

\end{array}
(FPCore (re im)
 :precision binary64
 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
(FPCore (re im)
 :precision binary64
 (if (<= (- (exp (- im)) (exp im)) 4.026223700770437e-06)
   (*
    (* 0.5 (cos re))
    (+
     (- (* im -2.0) (* 0.3333333333333333 (pow im 3.0)))
     (* (pow im 5.0) -0.016666666666666666)))
   (* (* 0.5 (cos re)) (exp (log (- (exp (- im)) (exp im)))))))
double code(double re, double im) {
	return (0.5 * cos(re)) * (exp(0.0 - im) - exp(im));
}
double code(double re, double im) {
	double tmp;
	if ((exp(-im) - exp(im)) <= 4.026223700770437e-06) {
		tmp = (0.5 * cos(re)) * (((im * -2.0) - (0.3333333333333333 * pow(im, 3.0))) + (pow(im, 5.0) * -0.016666666666666666));
	} else {
		tmp = (0.5 * cos(re)) * exp(log(exp(-im) - exp(im)));
	}
	return tmp;
}

Error

Bits error versus re

Bits error versus im

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original58.0
Target0.3
Herbie0.6
\[\begin{array}{l} \mathbf{if}\;\left|im\right| < 1:\\ \;\;\;\;-\cos re \cdot \left(\left(im + \left(\left(0.16666666666666666 \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(0.008333333333333333 \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\\ \end{array}\]

Derivation

  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)) < 4.02622370077e-6

    1. Initial program 58.7

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
    2. Simplified58.7

      \[\leadsto \color{blue}{\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} - e^{im}\right)}\]
    3. Taylor expanded around 0 0.5

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(-\left(2 \cdot im + \left(0.3333333333333333 \cdot {im}^{3} + 0.016666666666666666 \cdot {im}^{5}\right)\right)\right)}\]
    4. Simplified0.5

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(\left(im \cdot -2 - 0.3333333333333333 \cdot {im}^{3}\right) + {im}^{5} \cdot -0.016666666666666666\right)}\]

    if 4.02622370077e-6 < (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im))

    1. Initial program 4.7

      \[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\]
    2. Simplified4.7

      \[\leadsto \color{blue}{\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} - e^{im}\right)}\]
    3. Using strategy rm
    4. Applied add-exp-log_binary64_28084.9

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{e^{\log \left(e^{-im} - e^{im}\right)}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{-im} - e^{im} \leq 4.026223700770437 \cdot 10^{-06}:\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(\left(im \cdot -2 - 0.3333333333333333 \cdot {im}^{3}\right) + {im}^{5} \cdot -0.016666666666666666\right)\\ \mathbf{else}:\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot e^{\log \left(e^{-im} - e^{im}\right)}\\ \end{array}\]

Reproduce

herbie shell --seed 2020292 
(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))))