
(FPCore (re im) :precision binary64 (* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))
double code(double re, double im) {
return (0.5 * sin(re)) * (exp((0.0 - 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
public static double code(double re, double 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((0.0 - 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 tmp = code(re, im) tmp = (0.5 * sin(re)) * (exp((0.0 - 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]
\begin{array}{l}
\\
\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 25 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))
double code(double re, double im) {
return (0.5 * sin(re)) * (exp((0.0 - 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
public static double code(double re, double 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((0.0 - 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 tmp = code(re, im) tmp = (0.5 * sin(re)) * (exp((0.0 - 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]
\begin{array}{l}
\\
\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right)
\end{array}
(FPCore (re im) :precision binary64 (fma (* (sin re) (exp (- im))) 0.5 (* (sin re) (* 0.5 (exp im)))))
double code(double re, double im) {
return fma((sin(re) * exp(-im)), 0.5, (sin(re) * (0.5 * exp(im))));
}
function code(re, im) return fma(Float64(sin(re) * exp(Float64(-im))), 0.5, Float64(sin(re) * Float64(0.5 * exp(im)))) end
code[re_, im_] := N[(N[(N[Sin[re], $MachinePrecision] * N[Exp[(-im)], $MachinePrecision]), $MachinePrecision] * 0.5 + N[(N[Sin[re], $MachinePrecision] * N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin re \cdot e^{-im}, 0.5, \sin re \cdot \left(0.5 \cdot e^{im}\right)\right)
\end{array}
Initial program 100.0%
lift-sin.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
distribute-rgt-inN/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lift--.f64N/A
sub0-negN/A
lower-neg.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64100.0
Applied egg-rr100.0%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* (sin re) 0.5)) (t_1 (* t_0 (+ (exp (- im)) (exp im)))))
(if (<= t_1 (- INFINITY))
(* (cosh im) (fma re (* (* re re) -0.16666666666666666) re))
(if (<= t_1 5e+132)
(/
t_0
(/
1.0
(fma
im
(fma
(* im im)
(* im (fma (* im im) 0.002777777777777778 0.08333333333333333))
im)
2.0)))
(*
(cosh im)
(fma
(fma (* re re) 0.008333333333333333 -0.16666666666666666)
(* re (* re re))
re))))))
double code(double re, double im) {
double t_0 = sin(re) * 0.5;
double t_1 = t_0 * (exp(-im) + exp(im));
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = cosh(im) * fma(re, ((re * re) * -0.16666666666666666), re);
} else if (t_1 <= 5e+132) {
tmp = t_0 / (1.0 / fma(im, fma((im * im), (im * fma((im * im), 0.002777777777777778, 0.08333333333333333)), im), 2.0));
} else {
tmp = cosh(im) * fma(fma((re * re), 0.008333333333333333, -0.16666666666666666), (re * (re * re)), re);
}
return tmp;
}
function code(re, im) t_0 = Float64(sin(re) * 0.5) t_1 = Float64(t_0 * Float64(exp(Float64(-im)) + exp(im))) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(cosh(im) * fma(re, Float64(Float64(re * re) * -0.16666666666666666), re)); elseif (t_1 <= 5e+132) tmp = Float64(t_0 / Float64(1.0 / fma(im, fma(Float64(im * im), Float64(im * fma(Float64(im * im), 0.002777777777777778, 0.08333333333333333)), im), 2.0))); else tmp = Float64(cosh(im) * fma(fma(Float64(re * re), 0.008333333333333333, -0.16666666666666666), Float64(re * Float64(re * re)), re)); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(N[Sin[re], $MachinePrecision] * 0.5), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[Cosh[im], $MachinePrecision] * N[(re * N[(N[(re * re), $MachinePrecision] * -0.16666666666666666), $MachinePrecision] + re), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5e+132], N[(t$95$0 / N[(1.0 / N[(im * N[(N[(im * im), $MachinePrecision] * N[(im * N[(N[(im * im), $MachinePrecision] * 0.002777777777777778 + 0.08333333333333333), $MachinePrecision]), $MachinePrecision] + im), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cosh[im], $MachinePrecision] * N[(N[(N[(re * re), $MachinePrecision] * 0.008333333333333333 + -0.16666666666666666), $MachinePrecision] * N[(re * N[(re * re), $MachinePrecision]), $MachinePrecision] + re), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin re \cdot 0.5\\
t_1 := t\_0 \cdot \left(e^{-im} + e^{im}\right)\\
\mathbf{if}\;t\_1 \leq -\infty:\\
\;\;\;\;\cosh im \cdot \mathsf{fma}\left(re, \left(re \cdot re\right) \cdot -0.16666666666666666, re\right)\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+132}:\\
\;\;\;\;\frac{t\_0}{\frac{1}{\mathsf{fma}\left(im, \mathsf{fma}\left(im \cdot im, im \cdot \mathsf{fma}\left(im \cdot im, 0.002777777777777778, 0.08333333333333333\right), im\right), 2\right)}}\\
\mathbf{else}:\\
\;\;\;\;\cosh im \cdot \mathsf{fma}\left(\mathsf{fma}\left(re \cdot re, 0.008333333333333333, -0.16666666666666666\right), re \cdot \left(re \cdot re\right), re\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (+.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < -inf.0Initial program 100.0%
lift-sin.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-+.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
Applied egg-rr100.0%
lift-cosh.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
*-commutativeN/A
lower-*.f64100.0
lift-*.f64N/A
*-lft-identity100.0
Applied egg-rr100.0%
Taylor expanded in re around 0
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6475.7
Simplified75.7%
if -inf.0 < (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (+.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) < 5.0000000000000001e132Initial program 100.0%
Taylor expanded in im around 0
+-commutativeN/A
unpow2N/A
associate-*l*N/A
lower-fma.f64N/A
Simplified99.0%
lift-sin.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
flip-+N/A
clear-numN/A
Applied egg-rr99.0%
if 5.0000000000000001e132 < (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (+.f64 (exp.f64 (-.f64 #s(literal 0 binary64) im)) (exp.f64 im))) Initial program 100.0%
lift-sin.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-+.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-*.f64N/A
Applied egg-rr100.0%
lift-cosh.f64N/A
lift-*.f64N/A
lift-sin.f64N/A
*-commutativeN/A
lower-*.f64100.0
lift-*.f64N/A
*-lft-identity100.0
Applied egg-rr100.0%
Taylor expanded in re around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
unpow2N/A
cube-multN/A
*-commutativeN/A
*-rgt-identityN/A
lower-fma.f64N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6476.1
Simplified76.1%
Final simplification87.5%
herbie shell --seed 2024218
(FPCore (re im)
:name "math.sin on complex, real part"
:precision binary64
(* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))