?

Average Error: 58.0 → 0.4
Time: 19.0s
Precision: binary64
Cost: 46596

?

\[\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \]
\[\begin{array}{l} t_0 := 0.5 \cdot \cos re\\ \mathbf{if}\;t_0 \cdot \left(e^{0 - im} - e^{im}\right) \leq -0.1:\\ \;\;\;\;t_0 \cdot \left(\left(1 - e^{im + im}\right) \cdot e^{-im}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(-0.16666666666666666 \cdot {im}^{3} + -0.0001984126984126984 \cdot {im}^{7}\right) + \left(-0.008333333333333333 \cdot {im}^{5} - im\right)\right) \cdot \cos re\\ \end{array} \]
(FPCore (re im)
 :precision binary64
 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
(FPCore (re im)
 :precision binary64
 (let* ((t_0 (* 0.5 (cos re))))
   (if (<= (* t_0 (- (exp (- 0.0 im)) (exp im))) -0.1)
     (* t_0 (* (- 1.0 (exp (+ im im))) (exp (- im))))
     (*
      (+
       (+
        (* -0.16666666666666666 (pow im 3.0))
        (* -0.0001984126984126984 (pow im 7.0)))
       (- (* -0.008333333333333333 (pow im 5.0)) im))
      (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) {
	double t_0 = 0.5 * cos(re);
	double tmp;
	if ((t_0 * (exp((0.0 - im)) - exp(im))) <= -0.1) {
		tmp = t_0 * ((1.0 - exp((im + im))) * exp(-im));
	} else {
		tmp = (((-0.16666666666666666 * pow(im, 3.0)) + (-0.0001984126984126984 * pow(im, 7.0))) + ((-0.008333333333333333 * pow(im, 5.0)) - im)) * cos(re);
	}
	return tmp;
}
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
    real(8) :: t_0
    real(8) :: tmp
    t_0 = 0.5d0 * cos(re)
    if ((t_0 * (exp((0.0d0 - im)) - exp(im))) <= (-0.1d0)) then
        tmp = t_0 * ((1.0d0 - exp((im + im))) * exp(-im))
    else
        tmp = ((((-0.16666666666666666d0) * (im ** 3.0d0)) + ((-0.0001984126984126984d0) * (im ** 7.0d0))) + (((-0.008333333333333333d0) * (im ** 5.0d0)) - im)) * cos(re)
    end if
    code = tmp
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) {
	double t_0 = 0.5 * Math.cos(re);
	double tmp;
	if ((t_0 * (Math.exp((0.0 - im)) - Math.exp(im))) <= -0.1) {
		tmp = t_0 * ((1.0 - Math.exp((im + im))) * Math.exp(-im));
	} else {
		tmp = (((-0.16666666666666666 * Math.pow(im, 3.0)) + (-0.0001984126984126984 * Math.pow(im, 7.0))) + ((-0.008333333333333333 * Math.pow(im, 5.0)) - im)) * Math.cos(re);
	}
	return tmp;
}
def code(re, im):
	return (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))
def code(re, im):
	t_0 = 0.5 * math.cos(re)
	tmp = 0
	if (t_0 * (math.exp((0.0 - im)) - math.exp(im))) <= -0.1:
		tmp = t_0 * ((1.0 - math.exp((im + im))) * math.exp(-im))
	else:
		tmp = (((-0.16666666666666666 * math.pow(im, 3.0)) + (-0.0001984126984126984 * math.pow(im, 7.0))) + ((-0.008333333333333333 * math.pow(im, 5.0)) - im)) * math.cos(re)
	return tmp
function code(re, im)
	return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im)))
end
function code(re, im)
	t_0 = Float64(0.5 * cos(re))
	tmp = 0.0
	if (Float64(t_0 * Float64(exp(Float64(0.0 - im)) - exp(im))) <= -0.1)
		tmp = Float64(t_0 * Float64(Float64(1.0 - exp(Float64(im + im))) * exp(Float64(-im))));
	else
		tmp = Float64(Float64(Float64(Float64(-0.16666666666666666 * (im ^ 3.0)) + Float64(-0.0001984126984126984 * (im ^ 7.0))) + Float64(Float64(-0.008333333333333333 * (im ^ 5.0)) - im)) * cos(re));
	end
	return tmp
end
function tmp = code(re, im)
	tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
end
function tmp_2 = code(re, im)
	t_0 = 0.5 * cos(re);
	tmp = 0.0;
	if ((t_0 * (exp((0.0 - im)) - exp(im))) <= -0.1)
		tmp = t_0 * ((1.0 - exp((im + im))) * exp(-im));
	else
		tmp = (((-0.16666666666666666 * (im ^ 3.0)) + (-0.0001984126984126984 * (im ^ 7.0))) + ((-0.008333333333333333 * (im ^ 5.0)) - im)) * cos(re);
	end
	tmp_2 = tmp;
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_] := Block[{t$95$0 = N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -0.1], N[(t$95$0 * N[(N[(1.0 - N[Exp[N[(im + im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Exp[(-im)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(-0.16666666666666666 * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision] + N[(-0.0001984126984126984 * N[Power[im, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(-0.008333333333333333 * N[Power[im, 5.0], $MachinePrecision]), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision] * N[Cos[re], $MachinePrecision]), $MachinePrecision]]]
\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\begin{array}{l}
t_0 := 0.5 \cdot \cos re\\
\mathbf{if}\;t_0 \cdot \left(e^{0 - im} - e^{im}\right) \leq -0.1:\\
\;\;\;\;t_0 \cdot \left(\left(1 - e^{im + im}\right) \cdot e^{-im}\right)\\

\mathbf{else}:\\
\;\;\;\;\left(\left(-0.16666666666666666 \cdot {im}^{3} + -0.0001984126984126984 \cdot {im}^{7}\right) + \left(-0.008333333333333333 \cdot {im}^{5} - im\right)\right) \cdot \cos re\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original58.0
Target0.3
Herbie0.4
\[\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 (*.f64 1/2 (cos.f64 re)) (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im))) < -0.10000000000000001

    1. Initial program 0.4

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

      \[\leadsto \color{blue}{\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
      Proof

      [Start]0.4

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

      rational.json-simplify-13 [=>]0.4

      \[ \left(0.5 \cdot \cos re\right) \cdot \left(e^{\color{blue}{-im}} - e^{im}\right) \]
    3. Applied egg-rr4.9

      \[\leadsto \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(\left(1 - e^{im + im}\right) \cdot e^{-im}\right)} \]

    if -0.10000000000000001 < (*.f64 (*.f64 1/2 (cos.f64 re)) (-.f64 (exp.f64 (-.f64 0 im)) (exp.f64 im)))

    1. Initial program 58.2

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

      \[\leadsto \color{blue}{\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} - e^{im}\right)} \]
      Proof

      [Start]58.2

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

      rational.json-simplify-13 [=>]58.2

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

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

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

      [Start]0.4

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

      rational.json-simplify-41 [=>]0.4

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

      rational.json-simplify-1 [<=]0.4

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

      rational.json-simplify-41 [<=]0.4

      \[ \left(0.5 \cdot \cos re\right) \cdot \color{blue}{\left(\left(-2 \cdot im + -0.3333333333333333 \cdot {im}^{3}\right) + \left(-0.0003968253968253968 \cdot {im}^{7} + -0.016666666666666666 \cdot {im}^{5}\right)\right)} \]
    5. Taylor expanded in im around 0 0.4

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right) + \left(-1 \cdot \left(\cos re \cdot im\right) + \left(-0.008333333333333333 \cdot \left(\cos re \cdot {im}^{5}\right) + -0.0001984126984126984 \cdot \left(\cos re \cdot {im}^{7}\right)\right)\right)} \]
    6. Simplified0.4

      \[\leadsto \color{blue}{\cos re \cdot \left(\left({im}^{5} \cdot -0.008333333333333333 + {im}^{7} \cdot -0.0001984126984126984\right) + \left({im}^{3} \cdot -0.16666666666666666 + \left(-im\right)\right)\right)} \]
      Proof

      [Start]0.4

      \[ -0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right) + \left(-1 \cdot \left(\cos re \cdot im\right) + \left(-0.008333333333333333 \cdot \left(\cos re \cdot {im}^{5}\right) + -0.0001984126984126984 \cdot \left(\cos re \cdot {im}^{7}\right)\right)\right) \]

      rational.json-simplify-41 [<=]0.4

      \[ \color{blue}{\left(-0.008333333333333333 \cdot \left(\cos re \cdot {im}^{5}\right) + -0.0001984126984126984 \cdot \left(\cos re \cdot {im}^{7}\right)\right) + \left(-0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right) + -1 \cdot \left(\cos re \cdot im\right)\right)} \]

      rational.json-simplify-1 [=>]0.4

      \[ \color{blue}{\left(-0.16666666666666666 \cdot \left(\cos re \cdot {im}^{3}\right) + -1 \cdot \left(\cos re \cdot im\right)\right) + \left(-0.008333333333333333 \cdot \left(\cos re \cdot {im}^{5}\right) + -0.0001984126984126984 \cdot \left(\cos re \cdot {im}^{7}\right)\right)} \]

      rational.json-simplify-43 [=>]0.4

      \[ \left(\color{blue}{\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666\right)} + -1 \cdot \left(\cos re \cdot im\right)\right) + \left(-0.008333333333333333 \cdot \left(\cos re \cdot {im}^{5}\right) + -0.0001984126984126984 \cdot \left(\cos re \cdot {im}^{7}\right)\right) \]

      rational.json-simplify-43 [=>]0.4

      \[ \left(\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666\right) + \color{blue}{\cos re \cdot \left(im \cdot -1\right)}\right) + \left(-0.008333333333333333 \cdot \left(\cos re \cdot {im}^{5}\right) + -0.0001984126984126984 \cdot \left(\cos re \cdot {im}^{7}\right)\right) \]

      rational.json-simplify-2 [=>]0.4

      \[ \left(\cos re \cdot \left({im}^{3} \cdot -0.16666666666666666\right) + \color{blue}{\left(im \cdot -1\right) \cdot \cos re}\right) + \left(-0.008333333333333333 \cdot \left(\cos re \cdot {im}^{5}\right) + -0.0001984126984126984 \cdot \left(\cos re \cdot {im}^{7}\right)\right) \]

      rational.json-simplify-51 [=>]0.4

      \[ \color{blue}{\cos re \cdot \left(im \cdot -1 + {im}^{3} \cdot -0.16666666666666666\right)} + \left(-0.008333333333333333 \cdot \left(\cos re \cdot {im}^{5}\right) + -0.0001984126984126984 \cdot \left(\cos re \cdot {im}^{7}\right)\right) \]

      rational.json-simplify-1 [=>]0.4

      \[ \cos re \cdot \left(im \cdot -1 + {im}^{3} \cdot -0.16666666666666666\right) + \color{blue}{\left(-0.0001984126984126984 \cdot \left(\cos re \cdot {im}^{7}\right) + -0.008333333333333333 \cdot \left(\cos re \cdot {im}^{5}\right)\right)} \]

      rational.json-simplify-43 [=>]0.4

      \[ \cos re \cdot \left(im \cdot -1 + {im}^{3} \cdot -0.16666666666666666\right) + \left(\color{blue}{\cos re \cdot \left({im}^{7} \cdot -0.0001984126984126984\right)} + -0.008333333333333333 \cdot \left(\cos re \cdot {im}^{5}\right)\right) \]

      rational.json-simplify-43 [=>]0.4

      \[ \cos re \cdot \left(im \cdot -1 + {im}^{3} \cdot -0.16666666666666666\right) + \left(\cos re \cdot \left({im}^{7} \cdot -0.0001984126984126984\right) + \color{blue}{\cos re \cdot \left({im}^{5} \cdot -0.008333333333333333\right)}\right) \]

      rational.json-simplify-2 [=>]0.4

      \[ \cos re \cdot \left(im \cdot -1 + {im}^{3} \cdot -0.16666666666666666\right) + \left(\cos re \cdot \left({im}^{7} \cdot -0.0001984126984126984\right) + \color{blue}{\left({im}^{5} \cdot -0.008333333333333333\right) \cdot \cos re}\right) \]

      rational.json-simplify-51 [=>]0.4

      \[ \cos re \cdot \left(im \cdot -1 + {im}^{3} \cdot -0.16666666666666666\right) + \color{blue}{\cos re \cdot \left({im}^{5} \cdot -0.008333333333333333 + {im}^{7} \cdot -0.0001984126984126984\right)} \]

      rational.json-simplify-2 [=>]0.4

      \[ \cos re \cdot \left(im \cdot -1 + {im}^{3} \cdot -0.16666666666666666\right) + \color{blue}{\left({im}^{5} \cdot -0.008333333333333333 + {im}^{7} \cdot -0.0001984126984126984\right) \cdot \cos re} \]

      rational.json-simplify-51 [=>]0.4

      \[ \color{blue}{\cos re \cdot \left(\left({im}^{5} \cdot -0.008333333333333333 + {im}^{7} \cdot -0.0001984126984126984\right) + \left(im \cdot -1 + {im}^{3} \cdot -0.16666666666666666\right)\right)} \]
    7. Taylor expanded in re around inf 0.4

      \[\leadsto \color{blue}{\cos re \cdot \left(\left(-0.008333333333333333 \cdot {im}^{5} + \left(-0.16666666666666666 \cdot {im}^{3} + -0.0001984126984126984 \cdot {im}^{7}\right)\right) - im\right)} \]
    8. Simplified0.4

      \[\leadsto \color{blue}{\left(\left(-0.16666666666666666 \cdot {im}^{3} + -0.0001984126984126984 \cdot {im}^{7}\right) + \left(-0.008333333333333333 \cdot {im}^{5} - im\right)\right) \cdot \cos re} \]
      Proof

      [Start]0.4

      \[ \cos re \cdot \left(\left(-0.008333333333333333 \cdot {im}^{5} + \left(-0.16666666666666666 \cdot {im}^{3} + -0.0001984126984126984 \cdot {im}^{7}\right)\right) - im\right) \]

      rational.json-simplify-2 [=>]0.4

      \[ \color{blue}{\left(\left(-0.008333333333333333 \cdot {im}^{5} + \left(-0.16666666666666666 \cdot {im}^{3} + -0.0001984126984126984 \cdot {im}^{7}\right)\right) - im\right) \cdot \cos re} \]

      rational.json-simplify-2 [<=]0.4

      \[ \left(\left(\color{blue}{{im}^{5} \cdot -0.008333333333333333} + \left(-0.16666666666666666 \cdot {im}^{3} + -0.0001984126984126984 \cdot {im}^{7}\right)\right) - im\right) \cdot \cos re \]

      rational.json-simplify-48 [=>]0.4

      \[ \color{blue}{\left(\left(-0.16666666666666666 \cdot {im}^{3} + -0.0001984126984126984 \cdot {im}^{7}\right) + \left({im}^{5} \cdot -0.008333333333333333 - im\right)\right)} \cdot \cos re \]

      rational.json-simplify-2 [=>]0.4

      \[ \left(\left(-0.16666666666666666 \cdot {im}^{3} + -0.0001984126984126984 \cdot {im}^{7}\right) + \left(\color{blue}{-0.008333333333333333 \cdot {im}^{5}} - im\right)\right) \cdot \cos re \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \leq -0.1:\\ \;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(\left(1 - e^{im + im}\right) \cdot e^{-im}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(-0.16666666666666666 \cdot {im}^{3} + -0.0001984126984126984 \cdot {im}^{7}\right) + \left(-0.008333333333333333 \cdot {im}^{5} - im\right)\right) \cdot \cos re\\ \end{array} \]

Alternatives

Alternative 1
Error0.6
Cost39812
\[\begin{array}{l} t_0 := 0.5 \cdot \cos re\\ \mathbf{if}\;t_0 \cdot \left(e^{0 - im} - e^{im}\right) \leq -0.1:\\ \;\;\;\;t_0 \cdot \left(\left(1 - e^{im + im}\right) \cdot e^{-im}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-0.16666666666666666 \cdot {im}^{3} - im\right) \cdot \cos re\\ \end{array} \]
Alternative 2
Error0.6
Cost39748
\[\begin{array}{l} t_0 := 0.5 \cdot \cos re\\ \mathbf{if}\;t_0 \cdot \left(e^{0 - im} - e^{im}\right) \leq -0.1:\\ \;\;\;\;t_0 \cdot \left(e^{im} \cdot \left(-1 + e^{im \cdot -2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-0.16666666666666666 \cdot {im}^{3} - im\right) \cdot \cos re\\ \end{array} \]
Alternative 3
Error0.6
Cost39748
\[\begin{array}{l} \mathbf{if}\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right) \leq -0.1:\\ \;\;\;\;\frac{\left(-1 + e^{im \cdot -2}\right) \cdot \left(e^{im} \cdot \cos re\right)}{2}\\ \mathbf{else}:\\ \;\;\;\;\left(-0.16666666666666666 \cdot {im}^{3} - im\right) \cdot \cos re\\ \end{array} \]
Alternative 4
Error0.6
Cost39556
\[\begin{array}{l} t_0 := 0.5 \cdot \cos re\\ \mathbf{if}\;t_0 \cdot \left(e^{0 - im} - e^{im}\right) \leq -0.1:\\ \;\;\;\;t_0 \cdot \left(e^{-im} - e^{im}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-0.16666666666666666 \cdot {im}^{3} - im\right) \cdot \cos re\\ \end{array} \]
Alternative 5
Error0.9
Cost13312
\[\left(-0.16666666666666666 \cdot {im}^{3} - im\right) \cdot \cos re \]
Alternative 6
Error1.2
Cost6656
\[\left(-im\right) \cdot \cos re \]
Alternative 7
Error28.8
Cost128
\[-im \]

Error

Reproduce?

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