math.sin on complex, real part

?

Percentage Accurate: 100.0% → 100.0%
Time: 13.2s
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?

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.

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
Accuracy96.2%
Cost14092
\[\begin{array}{l} t_0 := re \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(0.5 \cdot \left(im \cdot im\right)\right)\right)\\ t_1 := 0.041666666666666664 \cdot \left(\sin re \cdot {im}^{4}\right)\\ \mathbf{if}\;im \leq -1.35 \cdot 10^{+83}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq -650:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 580:\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \left(2 + \left(im \cdot im + {im}^{4} \cdot 0.08333333333333333\right)\right)\\ \mathbf{elif}\;im \leq 4.9 \cdot 10^{+73}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Accuracy96.1%
Cost13776
\[\begin{array}{l} t_0 := re \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(0.5 \cdot \left(im \cdot im\right)\right)\right)\\ t_1 := 0.041666666666666664 \cdot \left(\sin re \cdot {im}^{4}\right)\\ \mathbf{if}\;im \leq -1.35 \cdot 10^{+83}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq -600:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 580:\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \left(im \cdot im + 2\right)\\ \mathbf{elif}\;im \leq 4.9 \cdot 10^{+73}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Accuracy96.1%
Cost13776
\[\begin{array}{l} t_0 := re \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(0.5 \cdot \left(im \cdot im\right)\right)\right)\\ t_1 := 0.041666666666666664 \cdot \left(\sin re \cdot {im}^{4}\right)\\ \mathbf{if}\;im \leq -1.35 \cdot 10^{+83}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq -550:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 620:\\ \;\;\;\;\sin re + 0.5 \cdot \left(\sin re \cdot \left(im \cdot im\right)\right)\\ \mathbf{elif}\;im \leq 4.9 \cdot 10^{+73}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Accuracy88.9%
Cost13712
\[\begin{array}{l} t_0 := 0.041666666666666664 \cdot \left(\sin re \cdot {im}^{4}\right)\\ \mathbf{if}\;im \leq -1.3 \cdot 10^{+62}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -54000:\\ \;\;\;\;re \cdot \left(0.041666666666666664 \cdot {im}^{4}\right)\\ \mathbf{elif}\;im \leq 14000:\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \left(im \cdot im + 2\right)\\ \mathbf{elif}\;im \leq 1.1 \cdot 10^{+76}:\\ \;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 \cdot re + -0.08333333333333333 \cdot {re}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Accuracy86.6%
Cost7696
\[\begin{array}{l} t_0 := \left(im \cdot im\right) \cdot \left(\left(im \cdot im\right) \cdot \left(\sin re \cdot 0.041666666666666664\right)\right)\\ \mathbf{if}\;im \leq -1.15 \cdot 10^{+101}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -290:\\ \;\;\;\;re \cdot \left(0.041666666666666664 \cdot {im}^{4}\right)\\ \mathbf{elif}\;im \leq 13500:\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \left(im \cdot im + 2\right)\\ \mathbf{elif}\;im \leq 1.7 \cdot 10^{+77}:\\ \;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 \cdot re + -0.08333333333333333 \cdot {re}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Accuracy85.8%
Cost7500
\[\begin{array}{l} t_0 := \left(im \cdot im\right) \cdot \left(\left(im \cdot im\right) \cdot \left(\sin re \cdot 0.041666666666666664\right)\right)\\ \mathbf{if}\;im \leq -2.7 \cdot 10^{+98}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -190000:\\ \;\;\;\;re \cdot \left(0.041666666666666664 \cdot {im}^{4}\right)\\ \mathbf{elif}\;im \leq 3.7:\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \left(im \cdot im + 2\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Accuracy82.1%
Cost7308
\[\begin{array}{l} t_0 := re \cdot \left(1 + 0.041666666666666664 \cdot {im}^{4}\right)\\ \mathbf{if}\;im \leq -1.46 \cdot 10^{-7}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 4.1 \cdot 10^{+21}:\\ \;\;\;\;\sin re\\ \mathbf{elif}\;im \leq 3.9 \cdot 10^{+151}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\sin re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \end{array} \]
Alternative 8
Accuracy82.6%
Cost7308
\[\begin{array}{l} t_0 := 0.041666666666666664 \cdot {im}^{4}\\ \mathbf{if}\;im \leq -12500:\\ \;\;\;\;re \cdot t_0\\ \mathbf{elif}\;im \leq 1.35 \cdot 10^{+21}:\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \left(im \cdot im + 2\right)\\ \mathbf{elif}\;im \leq 3.9 \cdot 10^{+151}:\\ \;\;\;\;re \cdot \left(1 + t_0\right)\\ \mathbf{else}:\\ \;\;\;\;\sin re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \end{array} \]
Alternative 9
Accuracy82.3%
Cost7244
\[\begin{array}{l} t_0 := re \cdot \left(0.041666666666666664 \cdot {im}^{4}\right)\\ \mathbf{if}\;im \leq -120000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 2.2 \cdot 10^{+21}:\\ \;\;\;\;\sin re\\ \mathbf{elif}\;im \leq 3.9 \cdot 10^{+151}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\sin re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \end{array} \]
Alternative 10
Accuracy79.6%
Cost7049
\[\begin{array}{l} \mathbf{if}\;im \leq -290 \lor \neg \left(im \leq 4.1 \cdot 10^{+21}\right):\\ \;\;\;\;re \cdot \left(0.041666666666666664 \cdot {im}^{4}\right)\\ \mathbf{else}:\\ \;\;\;\;\sin re\\ \end{array} \]
Alternative 11
Accuracy72.4%
Cost6728
\[\begin{array}{l} t_0 := re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \mathbf{if}\;im \leq -1.46 \cdot 10^{-7}:\\ \;\;\;\;re + t_0\\ \mathbf{elif}\;im \leq 1.2 \cdot 10^{+21}:\\ \;\;\;\;\sin re\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 12
Accuracy47.9%
Cost713
\[\begin{array}{l} \mathbf{if}\;im \leq -1.4 \lor \neg \left(im \leq 1.65 \cdot 10^{-11}\right):\\ \;\;\;\;re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;re\\ \end{array} \]
Alternative 13
Accuracy48.3%
Cost576
\[re + re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right) \]
Alternative 14
Accuracy26.9%
Cost64
\[re \]

Error

Reproduce?

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