
(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 16 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 (fma (fma re 0.16666666666666666 0.5) (* re re) re))
(t_1 (* (exp re) (sin im)))
(t_2 (fma re (fma re 0.16666666666666666 0.5) 1.0))
(t_3 (* (exp re) im)))
(if (<= t_1 -1e+185)
(* (* im (* re re)) (fma (* im im) -0.08333333333333333 0.5))
(if (<= t_1 -0.005)
(* (sin im) (fma re t_2 1.0))
(if (<= t_1 1e-128)
t_3
(if (<= t_1 1.0)
(* (sin im) (/ (fma t_0 t_0 -1.0) (fma re t_2 -1.0)))
t_3))))))
double code(double re, double im) {
double t_0 = fma(fma(re, 0.16666666666666666, 0.5), (re * re), re);
double t_1 = exp(re) * sin(im);
double t_2 = fma(re, fma(re, 0.16666666666666666, 0.5), 1.0);
double t_3 = exp(re) * im;
double tmp;
if (t_1 <= -1e+185) {
tmp = (im * (re * re)) * fma((im * im), -0.08333333333333333, 0.5);
} else if (t_1 <= -0.005) {
tmp = sin(im) * fma(re, t_2, 1.0);
} else if (t_1 <= 1e-128) {
tmp = t_3;
} else if (t_1 <= 1.0) {
tmp = sin(im) * (fma(t_0, t_0, -1.0) / fma(re, t_2, -1.0));
} else {
tmp = t_3;
}
return tmp;
}
function code(re, im) t_0 = fma(fma(re, 0.16666666666666666, 0.5), Float64(re * re), re) t_1 = Float64(exp(re) * sin(im)) t_2 = fma(re, fma(re, 0.16666666666666666, 0.5), 1.0) t_3 = Float64(exp(re) * im) tmp = 0.0 if (t_1 <= -1e+185) tmp = Float64(Float64(im * Float64(re * re)) * fma(Float64(im * im), -0.08333333333333333, 0.5)); elseif (t_1 <= -0.005) tmp = Float64(sin(im) * fma(re, t_2, 1.0)); elseif (t_1 <= 1e-128) tmp = t_3; elseif (t_1 <= 1.0) tmp = Float64(sin(im) * Float64(fma(t_0, t_0, -1.0) / fma(re, t_2, -1.0))); else tmp = t_3; end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(N[(re * 0.16666666666666666 + 0.5), $MachinePrecision] * N[(re * re), $MachinePrecision] + re), $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[re], $MachinePrecision] * N[Sin[im], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(re * N[(re * 0.16666666666666666 + 0.5), $MachinePrecision] + 1.0), $MachinePrecision]}, Block[{t$95$3 = N[(N[Exp[re], $MachinePrecision] * im), $MachinePrecision]}, If[LessEqual[t$95$1, -1e+185], N[(N[(im * N[(re * re), $MachinePrecision]), $MachinePrecision] * N[(N[(im * im), $MachinePrecision] * -0.08333333333333333 + 0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, -0.005], N[(N[Sin[im], $MachinePrecision] * N[(re * t$95$2 + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1e-128], t$95$3, If[LessEqual[t$95$1, 1.0], N[(N[Sin[im], $MachinePrecision] * N[(N[(t$95$0 * t$95$0 + -1.0), $MachinePrecision] / N[(re * t$95$2 + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$3]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\mathsf{fma}\left(re, 0.16666666666666666, 0.5\right), re \cdot re, re\right)\\
t_1 := e^{re} \cdot \sin im\\
t_2 := \mathsf{fma}\left(re, \mathsf{fma}\left(re, 0.16666666666666666, 0.5\right), 1\right)\\
t_3 := e^{re} \cdot im\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{+185}:\\
\;\;\;\;\left(im \cdot \left(re \cdot re\right)\right) \cdot \mathsf{fma}\left(im \cdot im, -0.08333333333333333, 0.5\right)\\
\mathbf{elif}\;t\_1 \leq -0.005:\\
\;\;\;\;\sin im \cdot \mathsf{fma}\left(re, t\_2, 1\right)\\
\mathbf{elif}\;t\_1 \leq 10^{-128}:\\
\;\;\;\;t\_3\\
\mathbf{elif}\;t\_1 \leq 1:\\
\;\;\;\;\sin im \cdot \frac{\mathsf{fma}\left(t\_0, t\_0, -1\right)}{\mathsf{fma}\left(re, t\_2, -1\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_3\\
\end{array}
\end{array}
if (*.f64 (exp.f64 re) (sin.f64 im)) < -9.9999999999999998e184Initial program 100.0%
Taylor expanded in re around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6453.1
Simplified53.1%
Taylor expanded in re around inf
lower-*.f64N/A
unpow2N/A
lower-*.f6453.3
Simplified53.3%
Taylor expanded in im around 0
distribute-rgt-inN/A
associate-*r*N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
distribute-rgt-outN/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6449.1
Simplified49.1%
if -9.9999999999999998e184 < (*.f64 (exp.f64 re) (sin.f64 im)) < -0.0050000000000000001Initial program 100.0%
Taylor expanded in re around 0
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6499.2
Simplified99.2%
if -0.0050000000000000001 < (*.f64 (exp.f64 re) (sin.f64 im)) < 1.00000000000000005e-128 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.2
Simplified94.2%
if 1.00000000000000005e-128 < (*.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
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f6499.1
Simplified99.1%
lift-fma.f64N/A
lift-fma.f64N/A
flip-+N/A
lower-/.f64N/A
Applied egg-rr99.1%
Final simplification89.9%
herbie shell --seed 2024218
(FPCore (re im)
:name "math.exp on complex, imaginary part"
:precision binary64
(* (exp re) (sin im)))