math.sin on complex, real part

?

Percentage Accurate: 100.0% → 100.0%
Time: 10.6s
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 17 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
Accuracy92.4%
Cost13712
\[\begin{array}{l} t_0 := \sin re \cdot \left({im}^{4} \cdot 0.041666666666666664\right)\\ \mathbf{if}\;im \leq -1.16 \cdot 10^{+77}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -2400000000:\\ \;\;\;\;\log \left(\frac{-2}{e^{re}}\right)\\ \mathbf{elif}\;im \leq 6.8:\\ \;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 1.15 \cdot 10^{+77}:\\ \;\;\;\;re \cdot \left(0.5 + 0.5 \cdot e^{im}\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Accuracy97.0%
Cost13640
\[\begin{array}{l} \mathbf{if}\;im \leq -3.2 \cdot 10^{+72}:\\ \;\;\;\;\sin re \cdot \left({im}^{4} \cdot 0.041666666666666664\right)\\ \mathbf{elif}\;im \leq -9.2 \cdot 10^{-10}:\\ \;\;\;\;0.5 \cdot \left(\frac{re}{e^{im}} + re \cdot e^{im}\right)\\ \mathbf{else}:\\ \;\;\;\;\sin re \cdot \left(0.5 + 0.5 \cdot e^{im}\right)\\ \end{array} \]
Alternative 4
Accuracy97.0%
Cost13576
\[\begin{array}{l} \mathbf{if}\;im \leq -3.2 \cdot 10^{+72}:\\ \;\;\;\;\sin re \cdot \left({im}^{4} \cdot 0.041666666666666664\right)\\ \mathbf{elif}\;im \leq -9.2 \cdot 10^{-10}:\\ \;\;\;\;re \cdot \left(0.5 \cdot \left(e^{-im} + e^{im}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sin re \cdot \left(0.5 + 0.5 \cdot e^{im}\right)\\ \end{array} \]
Alternative 5
Accuracy93.2%
Cost13512
\[\begin{array}{l} \mathbf{if}\;im \leq -7.2 \cdot 10^{+76}:\\ \;\;\;\;\sin re \cdot \left({im}^{4} \cdot 0.041666666666666664\right)\\ \mathbf{elif}\;im \leq -2400000000:\\ \;\;\;\;\log \left(\frac{-2}{e^{re}}\right)\\ \mathbf{else}:\\ \;\;\;\;\sin re \cdot \left(0.5 + 0.5 \cdot e^{im}\right)\\ \end{array} \]
Alternative 6
Accuracy92.4%
Cost13388
\[\begin{array}{l} t_0 := 2 + im \cdot im\\ t_1 := 0.5 \cdot \sin re\\ t_2 := t_1 \cdot \left(im \cdot im\right)\\ t_3 := t_1 \cdot \frac{t_0 \cdot t_0 - 1.1736111111111112}{t_0 - 1.0833333333333333}\\ \mathbf{if}\;im \leq -1.35 \cdot 10^{+154}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;im \leq -9 \cdot 10^{+76}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;im \leq -2400000000:\\ \;\;\;\;\log \left(\frac{-2}{e^{re}}\right)\\ \mathbf{elif}\;im \leq 7:\\ \;\;\;\;t_1 \cdot t_0\\ \mathbf{elif}\;im \leq 1.15 \cdot 10^{+77}:\\ \;\;\;\;re \cdot \left(0.5 + 0.5 \cdot e^{im}\right)\\ \mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Accuracy91.8%
Cost8660
\[\begin{array}{l} t_0 := 2 + im \cdot im\\ t_1 := 0.5 \cdot \sin re\\ t_2 := t_1 \cdot \left(im \cdot im\right)\\ t_3 := t_1 \cdot \frac{t_0 \cdot t_0 - 1.1736111111111112}{t_0 - 1.0833333333333333}\\ \mathbf{if}\;im \leq -1.35 \cdot 10^{+154}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;im \leq -1.55:\\ \;\;\;\;t_3\\ \mathbf{elif}\;im \leq 6.8:\\ \;\;\;\;t_1 \cdot t_0\\ \mathbf{elif}\;im \leq 1.15 \cdot 10^{+77}:\\ \;\;\;\;re \cdot \left(0.5 + 0.5 \cdot e^{im}\right)\\ \mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 8
Accuracy87.2%
Cost7560
\[\begin{array}{l} t_0 := 0.5 \cdot \sin re\\ t_1 := t_0 \cdot \left(im \cdot im\right)\\ \mathbf{if}\;im \leq -1.35 \cdot 10^{+154}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq -1.3 \cdot 10^{+95}:\\ \;\;\;\;\frac{\left(0.5 \cdot re\right) \cdot \left(4 - {im}^{4}\right)}{2 - im \cdot im}\\ \mathbf{elif}\;im \leq 5.6:\\ \;\;\;\;t_0 \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;re \cdot \left(0.5 + 0.5 \cdot e^{im}\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Accuracy78.9%
Cost7376
\[\begin{array}{l} t_0 := \left(0.5 \cdot \sin re\right) \cdot \left(im \cdot im\right)\\ t_1 := 8874444426961748000 + \left(\frac{26623333280885244000}{re \cdot re} + \left(re \cdot re\right) \cdot 1774888885392349700\right)\\ \mathbf{if}\;im \leq -1.35 \cdot 10^{+154}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -2300000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 3 \cdot 10^{+56}:\\ \;\;\;\;\sin re\\ \mathbf{elif}\;im \leq 2.3 \cdot 10^{+139}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 10
Accuracy86.3%
Cost7376
\[\begin{array}{l} t_0 := \left(0.5 \cdot \sin re\right) \cdot \left(im \cdot im\right)\\ \mathbf{if}\;im \leq -1.35 \cdot 10^{+154}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -2300000000000:\\ \;\;\;\;8874444426961748000 + \left(\frac{26623333280885244000}{re \cdot re} + \left(re \cdot re\right) \cdot 1774888885392349700\right)\\ \mathbf{elif}\;im \leq 3.8:\\ \;\;\;\;\sin re\\ \mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;re \cdot \left(0.5 + 0.5 \cdot e^{im}\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 11
Accuracy86.6%
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 -1.35 \cdot 10^{+154}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq -2300000000000:\\ \;\;\;\;8874444426961748000 + \left(\frac{26623333280885244000}{re \cdot re} + \left(re \cdot re\right) \cdot 1774888885392349700\right)\\ \mathbf{elif}\;im \leq 7.4:\\ \;\;\;\;t_0 \cdot \left(2 + im \cdot im\right)\\ \mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;re \cdot \left(0.5 + 0.5 \cdot e^{im}\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Accuracy72.7%
Cost6860
\[\begin{array}{l} t_0 := 0.5 \cdot \left(re \cdot \left(im \cdot im\right)\right)\\ t_1 := 8874444426961748000 + \left(\frac{26623333280885244000}{re \cdot re} + \left(re \cdot re\right) \cdot 1774888885392349700\right)\\ \mathbf{if}\;im \leq -8.2 \cdot 10^{+152}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq -2300000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 3 \cdot 10^{+56}:\\ \;\;\;\;\sin re\\ \mathbf{elif}\;im \leq 2.3 \cdot 10^{+138}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 13
Accuracy46.6%
Cost713
\[\begin{array}{l} \mathbf{if}\;im \leq -19.5 \lor \neg \left(im \leq 1.45\right):\\ \;\;\;\;0.5 \cdot \left(re \cdot \left(im \cdot im\right)\right)\\ \mathbf{else}:\\ \;\;\;\;re\\ \end{array} \]
Alternative 14
Accuracy31.6%
Cost585
\[\begin{array}{l} \mathbf{if}\;im \leq -1.5 \cdot 10^{+37} \lor \neg \left(im \leq 4.7 \cdot 10^{+47}\right):\\ \;\;\;\;\frac{26623333280885244000}{re \cdot re}\\ \mathbf{else}:\\ \;\;\;\;re\\ \end{array} \]
Alternative 15
Accuracy46.8%
Cost576
\[re \cdot \left(0.5 \cdot \left(2 + im \cdot im\right)\right) \]
Alternative 16
Accuracy4.7%
Cost64
\[1 \]
Alternative 17
Accuracy26.3%
Cost64
\[re \]

Reproduce?

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