
(FPCore (re im) :precision binary64 (* (exp re) (sin im)))
double code(double re, double im) {
return exp(re) * sin(im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = exp(re) * sin(im)
end function
public static double code(double re, double im) {
return Math.exp(re) * Math.sin(im);
}
def code(re, im): return math.exp(re) * math.sin(im)
function code(re, im) return Float64(exp(re) * sin(im)) end
function tmp = code(re, im) tmp = exp(re) * sin(im); end
code[re_, im_] := N[(N[Exp[re], $MachinePrecision] * N[Sin[im], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{re} \cdot \sin im
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 24 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* (exp re) (sin im)))
double code(double re, double im) {
return exp(re) * sin(im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = exp(re) * sin(im)
end function
public static double code(double re, double im) {
return Math.exp(re) * Math.sin(im);
}
def code(re, im): return math.exp(re) * math.sin(im)
function code(re, im) return Float64(exp(re) * sin(im)) end
function tmp = code(re, im) tmp = exp(re) * sin(im); end
code[re_, im_] := N[(N[Exp[re], $MachinePrecision] * N[Sin[im], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{re} \cdot \sin im
\end{array}
(FPCore (re im) :precision binary64 (* (exp re) (sin im)))
double code(double re, double im) {
return exp(re) * sin(im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = exp(re) * sin(im)
end function
public static double code(double re, double im) {
return Math.exp(re) * Math.sin(im);
}
def code(re, im): return math.exp(re) * math.sin(im)
function code(re, im) return Float64(exp(re) * sin(im)) end
function tmp = code(re, im) tmp = exp(re) * sin(im); end
code[re_, im_] := N[(N[Exp[re], $MachinePrecision] * N[Sin[im], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{re} \cdot \sin im
\end{array}
Initial program 100.0%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* (exp re) (sin im))) (t_1 (* (exp re) im)))
(if (<= t_0 (- INFINITY))
(* (exp re) (fma im (* -0.16666666666666666 (* im im)) im))
(if (<= t_0 -0.01)
(* (sin im) (+ re 1.0))
(if (<= t_0 2.12e-21)
t_1
(if (<= t_0 1.0) (* (sin im) (fma re (fma re 0.5 1.0) 1.0)) t_1))))))
double code(double re, double im) {
double t_0 = exp(re) * sin(im);
double t_1 = exp(re) * im;
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = exp(re) * fma(im, (-0.16666666666666666 * (im * im)), im);
} else if (t_0 <= -0.01) {
tmp = sin(im) * (re + 1.0);
} else if (t_0 <= 2.12e-21) {
tmp = t_1;
} else if (t_0 <= 1.0) {
tmp = sin(im) * fma(re, fma(re, 0.5, 1.0), 1.0);
} else {
tmp = t_1;
}
return tmp;
}
function code(re, im) t_0 = Float64(exp(re) * sin(im)) t_1 = Float64(exp(re) * im) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = Float64(exp(re) * fma(im, Float64(-0.16666666666666666 * Float64(im * im)), im)); elseif (t_0 <= -0.01) tmp = Float64(sin(im) * Float64(re + 1.0)); elseif (t_0 <= 2.12e-21) tmp = t_1; elseif (t_0 <= 1.0) tmp = Float64(sin(im) * fma(re, fma(re, 0.5, 1.0), 1.0)); else tmp = t_1; end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[re], $MachinePrecision] * N[Sin[im], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[re], $MachinePrecision] * im), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(N[Exp[re], $MachinePrecision] * N[(im * N[(-0.16666666666666666 * N[(im * im), $MachinePrecision]), $MachinePrecision] + im), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -0.01], N[(N[Sin[im], $MachinePrecision] * N[(re + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2.12e-21], t$95$1, If[LessEqual[t$95$0, 1.0], N[(N[Sin[im], $MachinePrecision] * N[(re * N[(re * 0.5 + 1.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{re} \cdot \sin im\\
t_1 := e^{re} \cdot im\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;e^{re} \cdot \mathsf{fma}\left(im, -0.16666666666666666 \cdot \left(im \cdot im\right), im\right)\\
\mathbf{elif}\;t\_0 \leq -0.01:\\
\;\;\;\;\sin im \cdot \left(re + 1\right)\\
\mathbf{elif}\;t\_0 \leq 2.12 \cdot 10^{-21}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 1:\\
\;\;\;\;\sin im \cdot \mathsf{fma}\left(re, \mathsf{fma}\left(re, 0.5, 1\right), 1\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (*.f64 (exp.f64 re) (sin.f64 im)) < -inf.0Initial program 99.9%
Taylor expanded in im around 0
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6473.8
Applied rewrites73.8%
if -inf.0 < (*.f64 (exp.f64 re) (sin.f64 im)) < -0.0100000000000000002Initial program 100.0%
Taylor expanded in re around 0
+-commutativeN/A
lower-+.f6498.5
Applied rewrites98.5%
if -0.0100000000000000002 < (*.f64 (exp.f64 re) (sin.f64 im)) < 2.11999999999999989e-21 or 1 < (*.f64 (exp.f64 re) (sin.f64 im)) Initial program 100.0%
Taylor expanded in im around 0
lower-*.f64N/A
lower-exp.f6494.3
Applied rewrites94.3%
if 2.11999999999999989e-21 < (*.f64 (exp.f64 re) (sin.f64 im)) < 1Initial program 100.0%
Taylor expanded in re around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6499.0
Applied rewrites99.0%
Final simplification92.9%
herbie shell --seed 2024228
(FPCore (re im)
:name "math.exp on complex, imaginary part"
:precision binary64
(* (exp re) (sin im)))