
(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(-im) - exp(im));
}
real(8) function code(re, im)
use fmin_fmax_functions
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(-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(-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[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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(-im) - exp(im));
}
real(8) function code(re, im)
use fmin_fmax_functions
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(-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(-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[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)
(FPCore (re im) :precision binary64 (* (sinh (- im)) (sin re)))
double code(double re, double im) {
return sinh(-im) * sin(re);
}
real(8) function code(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sinh(-im) * sin(re)
end function
public static double code(double re, double im) {
return Math.sinh(-im) * Math.sin(re);
}
def code(re, im): return math.sinh(-im) * math.sin(re)
function code(re, im) return Float64(sinh(Float64(-im)) * sin(re)) end
function tmp = code(re, im) tmp = sinh(-im) * sin(re); end
code[re_, im_] := N[(N[Sinh[(-im)], $MachinePrecision] * N[Sin[re], $MachinePrecision]), $MachinePrecision]
\sinh \left(-im\right) \cdot \sin re
Initial program 65.7%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lift--.f64N/A
sub-negate-revN/A
distribute-lft-neg-outN/A
metadata-evalN/A
mult-flipN/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
sinh-defN/A
sinh-negN/A
lift-neg.f64N/A
lower-*.f64N/A
lower-sinh.f6499.9%
Applied rewrites99.9%
(FPCore (re im)
:precision binary64
(let* ((t_0 (- (fabs im)))
(t_1 (exp (fabs im)))
(t_2 (sin (fabs re)))
(t_3 (* (* 0.5 t_2) (- (exp t_0) t_1))))
(*
(copysign 1.0 re)
(*
(copysign 1.0 im)
(if (<= t_3 (- INFINITY))
(* (* 0.5 (fabs re)) (- 1.0 t_1))
(if (<= t_3 4e-8)
(* t_2 t_0)
(*
(sinh t_0)
(fma
(* (* (fabs re) (fabs re)) (fabs re))
-0.16666666666666666
(fabs re)))))))))double code(double re, double im) {
double t_0 = -fabs(im);
double t_1 = exp(fabs(im));
double t_2 = sin(fabs(re));
double t_3 = (0.5 * t_2) * (exp(t_0) - t_1);
double tmp;
if (t_3 <= -((double) INFINITY)) {
tmp = (0.5 * fabs(re)) * (1.0 - t_1);
} else if (t_3 <= 4e-8) {
tmp = t_2 * t_0;
} else {
tmp = sinh(t_0) * fma(((fabs(re) * fabs(re)) * fabs(re)), -0.16666666666666666, fabs(re));
}
return copysign(1.0, re) * (copysign(1.0, im) * tmp);
}
function code(re, im) t_0 = Float64(-abs(im)) t_1 = exp(abs(im)) t_2 = sin(abs(re)) t_3 = Float64(Float64(0.5 * t_2) * Float64(exp(t_0) - t_1)) tmp = 0.0 if (t_3 <= Float64(-Inf)) tmp = Float64(Float64(0.5 * abs(re)) * Float64(1.0 - t_1)); elseif (t_3 <= 4e-8) tmp = Float64(t_2 * t_0); else tmp = Float64(sinh(t_0) * fma(Float64(Float64(abs(re) * abs(re)) * abs(re)), -0.16666666666666666, abs(re))); end return Float64(copysign(1.0, re) * Float64(copysign(1.0, im) * tmp)) end
code[re_, im_] := Block[{t$95$0 = (-N[Abs[im], $MachinePrecision])}, Block[{t$95$1 = N[Exp[N[Abs[im], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Sin[N[Abs[re], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(N[(0.5 * t$95$2), $MachinePrecision] * N[(N[Exp[t$95$0], $MachinePrecision] - t$95$1), $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$3, (-Infinity)], N[(N[(0.5 * N[Abs[re], $MachinePrecision]), $MachinePrecision] * N[(1.0 - t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 4e-8], N[(t$95$2 * t$95$0), $MachinePrecision], N[(N[Sinh[t$95$0], $MachinePrecision] * N[(N[(N[(N[Abs[re], $MachinePrecision] * N[Abs[re], $MachinePrecision]), $MachinePrecision] * N[Abs[re], $MachinePrecision]), $MachinePrecision] * -0.16666666666666666 + N[Abs[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
t_0 := -\left|im\right|\\
t_1 := e^{\left|im\right|}\\
t_2 := \sin \left(\left|re\right|\right)\\
t_3 := \left(0.5 \cdot t\_2\right) \cdot \left(e^{t\_0} - t\_1\right)\\
\mathsf{copysign}\left(1, re\right) \cdot \left(\mathsf{copysign}\left(1, im\right) \cdot \begin{array}{l}
\mathbf{if}\;t\_3 \leq -\infty:\\
\;\;\;\;\left(0.5 \cdot \left|re\right|\right) \cdot \left(1 - t\_1\right)\\
\mathbf{elif}\;t\_3 \leq 4 \cdot 10^{-8}:\\
\;\;\;\;t\_2 \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sinh t\_0 \cdot \mathsf{fma}\left(\left(\left|re\right| \cdot \left|re\right|\right) \cdot \left|re\right|, -0.16666666666666666, \left|re\right|\right)\\
\end{array}\right)
\end{array}
if (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < -inf.0Initial program 65.7%
Taylor expanded in re around 0
lower-*.f6452.8%
Applied rewrites52.8%
Taylor expanded in im around 0
Applied rewrites34.4%
if -inf.0 < (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < 4.0000000000000001e-8Initial program 65.7%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-sin.f6451.8%
Applied rewrites51.8%
lift-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lift-neg.f64N/A
lower-*.f6451.8%
Applied rewrites51.8%
if 4.0000000000000001e-8 < (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) Initial program 65.7%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lift--.f64N/A
sub-negate-revN/A
distribute-lft-neg-outN/A
metadata-evalN/A
mult-flipN/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
sinh-defN/A
sinh-negN/A
lift-neg.f64N/A
lower-*.f64N/A
lower-sinh.f6499.9%
Applied rewrites99.9%
Taylor expanded in re around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6463.2%
Applied rewrites63.2%
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-lft-inN/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lift-pow.f64N/A
unpow2N/A
cube-unmultN/A
*-lft-identityN/A
*-rgt-identityN/A
lower-fma.f64N/A
*-lft-identityN/A
metadata-evalN/A
pow-plusN/A
lift-pow.f64N/A
lower-*.f6463.2%
lift-pow.f64N/A
unpow2N/A
lower-*.f6463.2%
Applied rewrites63.2%
(FPCore (re im)
:precision binary64
(*
(copysign 1.0 re)
(*
(copysign 1.0 im)
(if (<= (* 0.5 (sin (fabs re))) 0.0001)
(*
(sinh (- (fabs im)))
(fma
(* (* (fabs re) (fabs re)) (fabs re))
-0.16666666666666666
(fabs re)))
(* (* 0.5 (fabs re)) (- 1.0 (exp (fabs im))))))))double code(double re, double im) {
double tmp;
if ((0.5 * sin(fabs(re))) <= 0.0001) {
tmp = sinh(-fabs(im)) * fma(((fabs(re) * fabs(re)) * fabs(re)), -0.16666666666666666, fabs(re));
} else {
tmp = (0.5 * fabs(re)) * (1.0 - exp(fabs(im)));
}
return copysign(1.0, re) * (copysign(1.0, im) * tmp);
}
function code(re, im) tmp = 0.0 if (Float64(0.5 * sin(abs(re))) <= 0.0001) tmp = Float64(sinh(Float64(-abs(im))) * fma(Float64(Float64(abs(re) * abs(re)) * abs(re)), -0.16666666666666666, abs(re))); else tmp = Float64(Float64(0.5 * abs(re)) * Float64(1.0 - exp(abs(im)))); end return Float64(copysign(1.0, re) * Float64(copysign(1.0, im) * tmp)) end
code[re_, im_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(0.5 * N[Sin[N[Abs[re], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.0001], N[(N[Sinh[(-N[Abs[im], $MachinePrecision])], $MachinePrecision] * N[(N[(N[(N[Abs[re], $MachinePrecision] * N[Abs[re], $MachinePrecision]), $MachinePrecision] * N[Abs[re], $MachinePrecision]), $MachinePrecision] * -0.16666666666666666 + N[Abs[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * N[Abs[re], $MachinePrecision]), $MachinePrecision] * N[(1.0 - N[Exp[N[Abs[im], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]
\mathsf{copysign}\left(1, re\right) \cdot \left(\mathsf{copysign}\left(1, im\right) \cdot \begin{array}{l}
\mathbf{if}\;0.5 \cdot \sin \left(\left|re\right|\right) \leq 0.0001:\\
\;\;\;\;\sinh \left(-\left|im\right|\right) \cdot \mathsf{fma}\left(\left(\left|re\right| \cdot \left|re\right|\right) \cdot \left|re\right|, -0.16666666666666666, \left|re\right|\right)\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \left|re\right|\right) \cdot \left(1 - e^{\left|im\right|}\right)\\
\end{array}\right)
if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < 1e-4Initial program 65.7%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lift--.f64N/A
sub-negate-revN/A
distribute-lft-neg-outN/A
metadata-evalN/A
mult-flipN/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
sinh-defN/A
sinh-negN/A
lift-neg.f64N/A
lower-*.f64N/A
lower-sinh.f6499.9%
Applied rewrites99.9%
Taylor expanded in re around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6463.2%
Applied rewrites63.2%
lift-*.f64N/A
lift-+.f64N/A
+-commutativeN/A
distribute-lft-inN/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lift-pow.f64N/A
unpow2N/A
cube-unmultN/A
*-lft-identityN/A
*-rgt-identityN/A
lower-fma.f64N/A
*-lft-identityN/A
metadata-evalN/A
pow-plusN/A
lift-pow.f64N/A
lower-*.f6463.2%
lift-pow.f64N/A
unpow2N/A
lower-*.f6463.2%
Applied rewrites63.2%
if 1e-4 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) Initial program 65.7%
Taylor expanded in re around 0
lower-*.f6452.8%
Applied rewrites52.8%
Taylor expanded in im around 0
Applied rewrites34.4%
(FPCore (re im)
:precision binary64
(*
(copysign 1.0 re)
(if (<= (* 0.5 (sin (fabs re))) -0.004)
(*
(fabs re)
(- (* 0.16666666666666666 (* im (pow (fabs re) 2.0))) im))
(* (sinh (- im)) (* (fabs re) 1.0)))))double code(double re, double im) {
double tmp;
if ((0.5 * sin(fabs(re))) <= -0.004) {
tmp = fabs(re) * ((0.16666666666666666 * (im * pow(fabs(re), 2.0))) - im);
} else {
tmp = sinh(-im) * (fabs(re) * 1.0);
}
return copysign(1.0, re) * tmp;
}
public static double code(double re, double im) {
double tmp;
if ((0.5 * Math.sin(Math.abs(re))) <= -0.004) {
tmp = Math.abs(re) * ((0.16666666666666666 * (im * Math.pow(Math.abs(re), 2.0))) - im);
} else {
tmp = Math.sinh(-im) * (Math.abs(re) * 1.0);
}
return Math.copySign(1.0, re) * tmp;
}
def code(re, im): tmp = 0 if (0.5 * math.sin(math.fabs(re))) <= -0.004: tmp = math.fabs(re) * ((0.16666666666666666 * (im * math.pow(math.fabs(re), 2.0))) - im) else: tmp = math.sinh(-im) * (math.fabs(re) * 1.0) return math.copysign(1.0, re) * tmp
function code(re, im) tmp = 0.0 if (Float64(0.5 * sin(abs(re))) <= -0.004) tmp = Float64(abs(re) * Float64(Float64(0.16666666666666666 * Float64(im * (abs(re) ^ 2.0))) - im)); else tmp = Float64(sinh(Float64(-im)) * Float64(abs(re) * 1.0)); end return Float64(copysign(1.0, re) * tmp) end
function tmp_2 = code(re, im) tmp = 0.0; if ((0.5 * sin(abs(re))) <= -0.004) tmp = abs(re) * ((0.16666666666666666 * (im * (abs(re) ^ 2.0))) - im); else tmp = sinh(-im) * (abs(re) * 1.0); end tmp_2 = (sign(re) * abs(1.0)) * tmp; end
code[re_, im_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(0.5 * N[Sin[N[Abs[re], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.004], N[(N[Abs[re], $MachinePrecision] * N[(N[(0.16666666666666666 * N[(im * N[Power[N[Abs[re], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision], N[(N[Sinh[(-im)], $MachinePrecision] * N[(N[Abs[re], $MachinePrecision] * 1.0), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, re\right) \cdot \begin{array}{l}
\mathbf{if}\;0.5 \cdot \sin \left(\left|re\right|\right) \leq -0.004:\\
\;\;\;\;\left|re\right| \cdot \left(0.16666666666666666 \cdot \left(im \cdot {\left(\left|re\right|\right)}^{2}\right) - im\right)\\
\mathbf{else}:\\
\;\;\;\;\sinh \left(-im\right) \cdot \left(\left|re\right| \cdot 1\right)\\
\end{array}
if (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) < -0.0040000000000000001Initial program 65.7%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-sin.f6451.8%
Applied rewrites51.8%
Taylor expanded in re around 0
lower-*.f6433.6%
Applied rewrites33.6%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6433.6%
Applied rewrites33.6%
Taylor expanded in re around 0
lower-*.f64N/A
lower--.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-pow.f6436.8%
Applied rewrites36.8%
if -0.0040000000000000001 < (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) Initial program 65.7%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lift--.f64N/A
sub-negate-revN/A
distribute-lft-neg-outN/A
metadata-evalN/A
mult-flipN/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
sinh-defN/A
sinh-negN/A
lift-neg.f64N/A
lower-*.f64N/A
lower-sinh.f6499.9%
Applied rewrites99.9%
Taylor expanded in re around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6463.2%
Applied rewrites63.2%
Taylor expanded in re around 0
Applied rewrites63.7%
(FPCore (re im) :precision binary64 (* (sinh (- im)) (* re 1.0)))
double code(double re, double im) {
return sinh(-im) * (re * 1.0);
}
real(8) function code(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sinh(-im) * (re * 1.0d0)
end function
public static double code(double re, double im) {
return Math.sinh(-im) * (re * 1.0);
}
def code(re, im): return math.sinh(-im) * (re * 1.0)
function code(re, im) return Float64(sinh(Float64(-im)) * Float64(re * 1.0)) end
function tmp = code(re, im) tmp = sinh(-im) * (re * 1.0); end
code[re_, im_] := N[(N[Sinh[(-im)], $MachinePrecision] * N[(re * 1.0), $MachinePrecision]), $MachinePrecision]
\sinh \left(-im\right) \cdot \left(re \cdot 1\right)
Initial program 65.7%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lift--.f64N/A
sub-negate-revN/A
distribute-lft-neg-outN/A
metadata-evalN/A
mult-flipN/A
lift-exp.f64N/A
lift-exp.f64N/A
lift-neg.f64N/A
sinh-defN/A
sinh-negN/A
lift-neg.f64N/A
lower-*.f64N/A
lower-sinh.f6499.9%
Applied rewrites99.9%
Taylor expanded in re around 0
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-pow.f6463.2%
Applied rewrites63.2%
Taylor expanded in re around 0
Applied rewrites63.7%
(FPCore (re im)
:precision binary64
(let* ((t_0 (exp (fabs im))))
(*
(copysign 1.0 re)
(*
(copysign 1.0 im)
(if (<=
(* (* 0.5 (sin (fabs re))) (- (exp (- (fabs im))) t_0))
-0.0002)
(* (* 0.5 (fabs re)) (- 1.0 t_0))
(- (* (fabs im) (fabs re))))))))double code(double re, double im) {
double t_0 = exp(fabs(im));
double tmp;
if (((0.5 * sin(fabs(re))) * (exp(-fabs(im)) - t_0)) <= -0.0002) {
tmp = (0.5 * fabs(re)) * (1.0 - t_0);
} else {
tmp = -(fabs(im) * fabs(re));
}
return copysign(1.0, re) * (copysign(1.0, im) * tmp);
}
public static double code(double re, double im) {
double t_0 = Math.exp(Math.abs(im));
double tmp;
if (((0.5 * Math.sin(Math.abs(re))) * (Math.exp(-Math.abs(im)) - t_0)) <= -0.0002) {
tmp = (0.5 * Math.abs(re)) * (1.0 - t_0);
} else {
tmp = -(Math.abs(im) * Math.abs(re));
}
return Math.copySign(1.0, re) * (Math.copySign(1.0, im) * tmp);
}
def code(re, im): t_0 = math.exp(math.fabs(im)) tmp = 0 if ((0.5 * math.sin(math.fabs(re))) * (math.exp(-math.fabs(im)) - t_0)) <= -0.0002: tmp = (0.5 * math.fabs(re)) * (1.0 - t_0) else: tmp = -(math.fabs(im) * math.fabs(re)) return math.copysign(1.0, re) * (math.copysign(1.0, im) * tmp)
function code(re, im) t_0 = exp(abs(im)) tmp = 0.0 if (Float64(Float64(0.5 * sin(abs(re))) * Float64(exp(Float64(-abs(im))) - t_0)) <= -0.0002) tmp = Float64(Float64(0.5 * abs(re)) * Float64(1.0 - t_0)); else tmp = Float64(-Float64(abs(im) * abs(re))); end return Float64(copysign(1.0, re) * Float64(copysign(1.0, im) * tmp)) end
function tmp_2 = code(re, im) t_0 = exp(abs(im)); tmp = 0.0; if (((0.5 * sin(abs(re))) * (exp(-abs(im)) - t_0)) <= -0.0002) tmp = (0.5 * abs(re)) * (1.0 - t_0); else tmp = -(abs(im) * abs(re)); end tmp_2 = (sign(re) * abs(1.0)) * ((sign(im) * abs(1.0)) * tmp); end
code[re_, im_] := Block[{t$95$0 = N[Exp[N[Abs[im], $MachinePrecision]], $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[re]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[im]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(N[(0.5 * N[Sin[N[Abs[re], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-N[Abs[im], $MachinePrecision])], $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision], -0.0002], N[(N[(0.5 * N[Abs[re], $MachinePrecision]), $MachinePrecision] * N[(1.0 - t$95$0), $MachinePrecision]), $MachinePrecision], (-N[(N[Abs[im], $MachinePrecision] * N[Abs[re], $MachinePrecision]), $MachinePrecision])]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
t_0 := e^{\left|im\right|}\\
\mathsf{copysign}\left(1, re\right) \cdot \left(\mathsf{copysign}\left(1, im\right) \cdot \begin{array}{l}
\mathbf{if}\;\left(0.5 \cdot \sin \left(\left|re\right|\right)\right) \cdot \left(e^{-\left|im\right|} - t\_0\right) \leq -0.0002:\\
\;\;\;\;\left(0.5 \cdot \left|re\right|\right) \cdot \left(1 - t\_0\right)\\
\mathbf{else}:\\
\;\;\;\;-\left|im\right| \cdot \left|re\right|\\
\end{array}\right)
\end{array}
if (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) < -2.0000000000000001e-4Initial program 65.7%
Taylor expanded in re around 0
lower-*.f6452.8%
Applied rewrites52.8%
Taylor expanded in im around 0
Applied rewrites34.4%
if -2.0000000000000001e-4 < (*.f64 (*.f64 #s(literal 1/2 binary64) (sin.f64 re)) (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im))) Initial program 65.7%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-sin.f6451.8%
Applied rewrites51.8%
Taylor expanded in re around 0
lower-*.f6433.6%
Applied rewrites33.6%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6433.6%
Applied rewrites33.6%
(FPCore (re im) :precision binary64 (- (* im re)))
double code(double re, double im) {
return -(im * re);
}
real(8) function code(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
code = -(im * re)
end function
public static double code(double re, double im) {
return -(im * re);
}
def code(re, im): return -(im * re)
function code(re, im) return Float64(-Float64(im * re)) end
function tmp = code(re, im) tmp = -(im * re); end
code[re_, im_] := (-N[(im * re), $MachinePrecision])
-im \cdot re
Initial program 65.7%
Taylor expanded in im around 0
lower-*.f64N/A
lower-*.f64N/A
lower-sin.f6451.8%
Applied rewrites51.8%
Taylor expanded in re around 0
lower-*.f6433.6%
Applied rewrites33.6%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f6433.6%
Applied rewrites33.6%
herbie shell --seed 2025313 -o setup:search
(FPCore (re im)
:name "math.cos on complex, imaginary part"
:precision binary64
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))