math.sin on complex, real part

?

Percentage Accurate: 100.0% → 100.0%
Time: 16.8s
Precision: binary64
Cost: 19712

?

\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right) \]
(FPCore (re im)
 :precision binary64
 (* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))
(FPCore (re im)
 :precision binary64
 (* (* 0.5 (sin re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
	return (0.5 * sin(re)) * (exp((0.0 - im)) + exp(im));
}
double code(double re, double im) {
	return (0.5 * sin(re)) * (exp(-im) + exp(im));
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = (0.5d0 * sin(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 = (0.5d0 * sin(re)) * (exp(-im) + exp(im))
end function
public static double code(double re, double im) {
	return (0.5 * Math.sin(re)) * (Math.exp((0.0 - im)) + Math.exp(im));
}
public static double code(double re, double im) {
	return (0.5 * Math.sin(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im):
	return (0.5 * math.sin(re)) * (math.exp((0.0 - im)) + math.exp(im))
def code(re, im):
	return (0.5 * math.sin(re)) * (math.exp(-im) + math.exp(im))
function code(re, im)
	return Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(0.0 - im)) + exp(im)))
end
function code(re, im)
	return Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(-im)) + exp(im)))
end
function tmp = code(re, im)
	tmp = (0.5 * sin(re)) * (exp((0.0 - im)) + exp(im));
end
function tmp = code(re, im)
	tmp = (0.5 * sin(re)) * (exp(-im) + exp(im));
end
code[re_, im_] := N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[re_, im_] := N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right)
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 21 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 100.0%

    \[\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right) \]
  2. Simplified100.0%

    \[\leadsto \color{blue}{\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right)} \]
    Step-by-step derivation

    [Start]100.0%

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

    sub0-neg [=>]100.0%

    \[ \left(0.5 \cdot \sin re\right) \cdot \left(e^{\color{blue}{-im}} + e^{im}\right) \]
  3. Final simplification100.0%

    \[\leadsto \left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right) \]

Alternatives

Alternative 1
Accuracy100.0%
Cost19712
\[\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} + e^{im}\right) \]
Alternative 2
Accuracy93.8%
Cost32713
\[\begin{array}{l} \mathbf{if}\;\sin re \leq -0.0005 \lor \neg \left(\sin re \leq 2 \cdot 10^{-33}\right):\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \left(\left(2 + im \cdot im\right) + {im}^{4} \cdot 0.08333333333333333\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \mathsf{fma}\left(re, e^{im}, \frac{re}{e^{im}}\right)\\ \end{array} \]
Alternative 3
Accuracy93.8%
Cost26761
\[\begin{array}{l} \mathbf{if}\;\sin re \leq -0.0005 \lor \neg \left(\sin re \leq 2 \cdot 10^{-33}\right):\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \left(\left(2 + im \cdot im\right) + {im}^{4} \cdot 0.08333333333333333\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \left(\frac{re}{e^{im}} + re \cdot e^{im}\right)\\ \end{array} \]
Alternative 4
Accuracy95.7%
Cost14096
\[\begin{array}{l} t_0 := 0.5 \cdot \sin re\\ t_1 := t_0 \cdot \left(im \cdot im + {im}^{4} \cdot 0.08333333333333333\right)\\ \mathbf{if}\;im \leq -1.25 \cdot 10^{+79}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq -0.00043:\\ \;\;\;\;0.5 \cdot \left(\frac{re}{e^{im}} + re \cdot e^{im}\right)\\ \mathbf{elif}\;im \leq 33.5:\\ \;\;\;\;\sin re + t_0 \cdot \left(im \cdot im\right)\\ \mathbf{elif}\;im \leq 2.45 \cdot 10^{+64}:\\ \;\;\;\;\left(e^{-im} + e^{im}\right) \cdot \left(0.5 \cdot re\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Accuracy92.6%
Cost13840
\[\begin{array}{l} t_0 := 0.5 \cdot \sin re\\ t_1 := t_0 \cdot \left(im \cdot im\right)\\ t_2 := \left(e^{-im} + e^{im}\right) \cdot \left(0.5 \cdot re\right)\\ \mathbf{if}\;im \leq -3.8 \cdot 10^{+188}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq -0.00043:\\ \;\;\;\;t_2\\ \mathbf{elif}\;im \leq 33.5:\\ \;\;\;\;t_0 \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 1.34 \cdot 10^{+154}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Accuracy92.6%
Cost13840
\[\begin{array}{l} t_0 := 0.5 \cdot \sin re\\ t_1 := t_0 \cdot \left(im \cdot im\right)\\ \mathbf{if}\;im \leq -3.8 \cdot 10^{+188}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq -0.00043:\\ \;\;\;\;0.5 \cdot \left(\frac{re}{e^{im}} + re \cdot e^{im}\right)\\ \mathbf{elif}\;im \leq 33.5:\\ \;\;\;\;t_0 \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 1.34 \cdot 10^{+154}:\\ \;\;\;\;\left(e^{-im} + e^{im}\right) \cdot \left(0.5 \cdot re\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Accuracy92.6%
Cost13840
\[\begin{array}{l} t_0 := \left(0.5 \cdot \sin re\right) \cdot \left(im \cdot im\right)\\ \mathbf{if}\;im \leq -5 \cdot 10^{+188}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -0.00043:\\ \;\;\;\;0.5 \cdot \left(\frac{re}{e^{im}} + re \cdot e^{im}\right)\\ \mathbf{elif}\;im \leq 33.5:\\ \;\;\;\;\sin re + t_0\\ \mathbf{elif}\;im \leq 1.5 \cdot 10^{+154}:\\ \;\;\;\;\left(e^{-im} + e^{im}\right) \cdot \left(0.5 \cdot re\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Accuracy89.7%
Cost13648
\[\begin{array}{l} t_0 := 0.5 \cdot \sin re\\ t_1 := t_0 \cdot \left(im \cdot im\right)\\ \mathbf{if}\;im \leq -9.6 \cdot 10^{+158}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq -102000:\\ \;\;\;\;{\left(\sin re \cdot 1.9380669946781485 \cdot 10^{-10}\right)}^{-512}\\ \mathbf{elif}\;im \leq 33.5:\\ \;\;\;\;t_0 \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 1.34 \cdot 10^{+154}:\\ \;\;\;\;0.5 \cdot \mathsf{fma}\left(re, e^{im}, re\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Accuracy85.8%
Cost13584
\[\begin{array}{l} t_0 := 0.5 \cdot \sin re\\ t_1 := t_0 \cdot \left(im \cdot im\right)\\ t_2 := {\left(\sin re \cdot 1.9380669946781485 \cdot 10^{-10}\right)}^{-512}\\ \mathbf{if}\;im \leq -9.6 \cdot 10^{+158}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq -102000:\\ \;\;\;\;t_2\\ \mathbf{elif}\;im \leq 600:\\ \;\;\;\;t_0 \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 1.1 \cdot 10^{+140}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Accuracy74.4%
Cost7508
\[\begin{array}{l} t_0 := 0.5 \cdot \left(im \cdot \left(\sin re \cdot im\right)\right)\\ \mathbf{if}\;im \leq -6 \cdot 10^{+188}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -4.4 \cdot 10^{+129}:\\ \;\;\;\;\left(2 + im \cdot im\right) \cdot \left(0.5 \cdot re\right)\\ \mathbf{elif}\;im \leq -102000:\\ \;\;\;\;{re}^{-512}\\ \mathbf{elif}\;im \leq 2.4 \cdot 10^{+56}:\\ \;\;\;\;\sin re\\ \mathbf{elif}\;im \leq 1.05 \cdot 10^{+140}:\\ \;\;\;\;{re}^{-512}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 11
Accuracy78.6%
Cost7376
\[\begin{array}{l} t_0 := \left(0.5 \cdot \sin re\right) \cdot \left(im \cdot im\right)\\ \mathbf{if}\;im \leq -4.7 \cdot 10^{+129}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -102000:\\ \;\;\;\;{re}^{-512}\\ \mathbf{elif}\;im \leq 1.95 \cdot 10^{+57}:\\ \;\;\;\;\sin re\\ \mathbf{elif}\;im \leq 1.1 \cdot 10^{+140}:\\ \;\;\;\;{re}^{-512}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 12
Accuracy79.0%
Cost7376
\[\begin{array}{l} t_0 := 0.5 \cdot \sin re\\ t_1 := t_0 \cdot \left(im \cdot im\right)\\ \mathbf{if}\;im \leq -4.7 \cdot 10^{+129}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq -102000:\\ \;\;\;\;{re}^{-512}\\ \mathbf{elif}\;im \leq 2.4 \cdot 10^{+56}:\\ \;\;\;\;t_0 \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 1.1 \cdot 10^{+140}:\\ \;\;\;\;{re}^{-512}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 13
Accuracy72.8%
Cost7056
\[\begin{array}{l} t_0 := \left(2 + im \cdot im\right) \cdot \left(0.5 \cdot re\right)\\ \mathbf{if}\;im \leq -4.6 \cdot 10^{+129}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -102000:\\ \;\;\;\;{re}^{-512}\\ \mathbf{elif}\;im \leq 2.4 \cdot 10^{+56}:\\ \;\;\;\;\sin re\\ \mathbf{elif}\;im \leq 3.2 \cdot 10^{+139}:\\ \;\;\;\;{re}^{-512}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 14
Accuracy74.1%
Cost6860
\[\begin{array}{l} t_0 := 0.08333333333333333 + \left(\frac{0.25}{re \cdot re} + \left(re \cdot re\right) \cdot 0.016666666666666666\right)\\ t_1 := \left(2 + im \cdot im\right) \cdot \left(0.5 \cdot re\right)\\ \mathbf{if}\;im \leq -4.7 \cdot 10^{+129}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq -102000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 460:\\ \;\;\;\;\sin re\\ \mathbf{elif}\;im \leq 1.9 \cdot 10^{+123}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 15
Accuracy31.6%
Cost712
\[\begin{array}{l} \mathbf{if}\;im \leq -3.2 \cdot 10^{+18}:\\ \;\;\;\;0.08333333333333333 + re \cdot \left(re \cdot 0.016666666666666666\right)\\ \mathbf{elif}\;im \leq 6.8 \cdot 10^{+56}:\\ \;\;\;\;re\\ \mathbf{else}:\\ \;\;\;\;0.08333333333333333 + \frac{0.25}{re \cdot re}\\ \end{array} \]
Alternative 16
Accuracy47.8%
Cost708
\[\begin{array}{l} \mathbf{if}\;re \leq -6 \cdot 10^{+249}:\\ \;\;\;\;0.08333333333333333 + re \cdot \left(re \cdot 0.016666666666666666\right)\\ \mathbf{else}:\\ \;\;\;\;\left(2 + im \cdot im\right) \cdot \left(0.5 \cdot re\right)\\ \end{array} \]
Alternative 17
Accuracy47.8%
Cost708
\[\begin{array}{l} \mathbf{if}\;re \leq -6 \cdot 10^{+249}:\\ \;\;\;\;0.08333333333333333 + re \cdot \left(re \cdot 0.016666666666666666\right)\\ \mathbf{else}:\\ \;\;\;\;re + 0.5 \cdot \left(re \cdot \left(im \cdot im\right)\right)\\ \end{array} \]
Alternative 18
Accuracy31.5%
Cost585
\[\begin{array}{l} \mathbf{if}\;im \leq -105000 \lor \neg \left(im \leq 4 \cdot 10^{+56}\right):\\ \;\;\;\;\frac{0.25}{re \cdot re}\\ \mathbf{else}:\\ \;\;\;\;re\\ \end{array} \]
Alternative 19
Accuracy31.5%
Cost584
\[\begin{array}{l} \mathbf{if}\;im \leq -122000:\\ \;\;\;\;\frac{0.25}{re \cdot re}\\ \mathbf{elif}\;im \leq 2.4 \cdot 10^{+56}:\\ \;\;\;\;re\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{0.25}{re}}{re}\\ \end{array} \]
Alternative 20
Accuracy31.5%
Cost584
\[\begin{array}{l} \mathbf{if}\;im \leq -8 \cdot 10^{+18}:\\ \;\;\;\;0.08333333333333333 + re \cdot \left(re \cdot 0.016666666666666666\right)\\ \mathbf{elif}\;im \leq 2.4 \cdot 10^{+56}:\\ \;\;\;\;re\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{0.25}{re}}{re}\\ \end{array} \]
Alternative 21
Accuracy26.6%
Cost64
\[re \]

Reproduce?

herbie shell --seed 2023263 
(FPCore (re im)
  :name "math.sin on complex, real part"
  :precision binary64
  (* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))