
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(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 * cos(re)) * (exp((0.0d0 - im)) - exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp((0.0 - im)) - Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[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 \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(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 * cos(re)) * (exp((0.0d0 - im)) - exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp((0.0 - im)) - Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[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 \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)
\end{array}
(FPCore (re im) :precision binary64 (* 0.5 (* im (log1p (expm1 (* (cos re) (fma -0.3333333333333333 (pow im 2.0) -2.0)))))))
double code(double re, double im) {
return 0.5 * (im * log1p(expm1((cos(re) * fma(-0.3333333333333333, pow(im, 2.0), -2.0)))));
}
function code(re, im) return Float64(0.5 * Float64(im * log1p(expm1(Float64(cos(re) * fma(-0.3333333333333333, (im ^ 2.0), -2.0)))))) end
code[re_, im_] := N[(0.5 * N[(im * N[Log[1 + N[(Exp[N[(N[Cos[re], $MachinePrecision] * N[(-0.3333333333333333 * N[Power[im, 2.0], $MachinePrecision] + -2.0), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(im \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos re \cdot \mathsf{fma}\left(-0.3333333333333333, {im}^{2}, -2\right)\right)\right)\right)
\end{array}
Initial program 51.2%
/-rgt-identity51.2%
exp-051.2%
associate-*l/51.2%
cos-neg51.2%
associate-*l*51.2%
associate-*r/51.2%
exp-051.2%
/-rgt-identity51.2%
*-commutative51.2%
neg-sub051.2%
cos-neg51.2%
Simplified51.2%
Taylor expanded in im around 0 83.9%
+-commutative83.9%
associate-*r*83.9%
distribute-rgt-out83.9%
metadata-eval83.9%
sub-neg83.9%
*-commutative83.9%
log1p-expm1-u99.2%
*-commutative99.2%
fma-neg99.2%
metadata-eval99.2%
Applied egg-rr99.2%
(FPCore (re im) :precision binary64 (* 0.5 (log1p (expm1 (* (cos re) (* im -2.0))))))
double code(double re, double im) {
return 0.5 * log1p(expm1((cos(re) * (im * -2.0))));
}
public static double code(double re, double im) {
return 0.5 * Math.log1p(Math.expm1((Math.cos(re) * (im * -2.0))));
}
def code(re, im): return 0.5 * math.log1p(math.expm1((math.cos(re) * (im * -2.0))))
function code(re, im) return Float64(0.5 * log1p(expm1(Float64(cos(re) * Float64(im * -2.0))))) end
code[re_, im_] := N[(0.5 * N[Log[1 + N[(Exp[N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\cos re \cdot \left(im \cdot -2\right)\right)\right)
\end{array}
Initial program 51.2%
/-rgt-identity51.2%
exp-051.2%
associate-*l/51.2%
cos-neg51.2%
associate-*l*51.2%
associate-*r/51.2%
exp-051.2%
/-rgt-identity51.2%
*-commutative51.2%
neg-sub051.2%
cos-neg51.2%
Simplified51.2%
Taylor expanded in im around 0 55.6%
*-commutative55.6%
associate-*r*55.6%
*-commutative55.6%
log1p-expm1-u99.2%
*-commutative99.2%
associate-*r*99.2%
*-commutative99.2%
Applied egg-rr99.2%
(FPCore (re im)
:precision binary64
(if (or (<= im 480.0) (not (<= im 8.4e+101)))
(*
0.5
(* (cos re) (+ (* im -2.0) (* im (* -0.3333333333333333 (pow im 2.0))))))
(* 0.5 (log1p (expm1 (* im -2.0))))))
double code(double re, double im) {
double tmp;
if ((im <= 480.0) || !(im <= 8.4e+101)) {
tmp = 0.5 * (cos(re) * ((im * -2.0) + (im * (-0.3333333333333333 * pow(im, 2.0)))));
} else {
tmp = 0.5 * log1p(expm1((im * -2.0)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if ((im <= 480.0) || !(im <= 8.4e+101)) {
tmp = 0.5 * (Math.cos(re) * ((im * -2.0) + (im * (-0.3333333333333333 * Math.pow(im, 2.0)))));
} else {
tmp = 0.5 * Math.log1p(Math.expm1((im * -2.0)));
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= 480.0) or not (im <= 8.4e+101): tmp = 0.5 * (math.cos(re) * ((im * -2.0) + (im * (-0.3333333333333333 * math.pow(im, 2.0))))) else: tmp = 0.5 * math.log1p(math.expm1((im * -2.0))) return tmp
function code(re, im) tmp = 0.0 if ((im <= 480.0) || !(im <= 8.4e+101)) tmp = Float64(0.5 * Float64(cos(re) * Float64(Float64(im * -2.0) + Float64(im * Float64(-0.3333333333333333 * (im ^ 2.0)))))); else tmp = Float64(0.5 * log1p(expm1(Float64(im * -2.0)))); end return tmp end
code[re_, im_] := If[Or[LessEqual[im, 480.0], N[Not[LessEqual[im, 8.4e+101]], $MachinePrecision]], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(N[(im * -2.0), $MachinePrecision] + N[(im * N[(-0.3333333333333333 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Log[1 + N[(Exp[N[(im * -2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 480 \lor \neg \left(im \leq 8.4 \cdot 10^{+101}\right):\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2 + im \cdot \left(-0.3333333333333333 \cdot {im}^{2}\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\
\end{array}
\end{array}
if im < 480 or 8.4000000000000001e101 < im Initial program 46.6%
/-rgt-identity46.6%
exp-046.6%
associate-*l/46.6%
cos-neg46.6%
associate-*l*46.6%
associate-*r/46.6%
exp-046.6%
/-rgt-identity46.6%
*-commutative46.6%
neg-sub046.6%
cos-neg46.6%
Simplified46.6%
Taylor expanded in im around 0 91.2%
sub-neg91.2%
metadata-eval91.2%
distribute-rgt-in91.2%
*-commutative91.2%
Applied egg-rr91.2%
if 480 < im < 8.4000000000000001e101Initial program 100.0%
/-rgt-identity100.0%
exp-0100.0%
associate-*l/100.0%
cos-neg100.0%
associate-*l*100.0%
associate-*r/100.0%
exp-0100.0%
/-rgt-identity100.0%
*-commutative100.0%
neg-sub0100.0%
cos-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 3.6%
*-commutative3.6%
associate-*r*3.6%
*-commutative3.6%
log1p-expm1-u100.0%
*-commutative100.0%
associate-*r*100.0%
*-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in re around 0 77.3%
expm1-define77.3%
*-commutative77.3%
Simplified77.3%
Final simplification90.0%
(FPCore (re im)
:precision binary64
(if (<= im 430.0)
(* 0.5 (* (cos re) (* im (- (* -0.3333333333333333 (pow im 2.0)) 2.0))))
(if (<= im 8.4e+101)
(* 0.5 (log1p (expm1 (* im -2.0))))
(* (* (cos re) (pow im 3.0)) -0.16666666666666666))))
double code(double re, double im) {
double tmp;
if (im <= 430.0) {
tmp = 0.5 * (cos(re) * (im * ((-0.3333333333333333 * pow(im, 2.0)) - 2.0)));
} else if (im <= 8.4e+101) {
tmp = 0.5 * log1p(expm1((im * -2.0)));
} else {
tmp = (cos(re) * pow(im, 3.0)) * -0.16666666666666666;
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (im <= 430.0) {
tmp = 0.5 * (Math.cos(re) * (im * ((-0.3333333333333333 * Math.pow(im, 2.0)) - 2.0)));
} else if (im <= 8.4e+101) {
tmp = 0.5 * Math.log1p(Math.expm1((im * -2.0)));
} else {
tmp = (Math.cos(re) * Math.pow(im, 3.0)) * -0.16666666666666666;
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 430.0: tmp = 0.5 * (math.cos(re) * (im * ((-0.3333333333333333 * math.pow(im, 2.0)) - 2.0))) elif im <= 8.4e+101: tmp = 0.5 * math.log1p(math.expm1((im * -2.0))) else: tmp = (math.cos(re) * math.pow(im, 3.0)) * -0.16666666666666666 return tmp
function code(re, im) tmp = 0.0 if (im <= 430.0) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * Float64(Float64(-0.3333333333333333 * (im ^ 2.0)) - 2.0)))); elseif (im <= 8.4e+101) tmp = Float64(0.5 * log1p(expm1(Float64(im * -2.0)))); else tmp = Float64(Float64(cos(re) * (im ^ 3.0)) * -0.16666666666666666); end return tmp end
code[re_, im_] := If[LessEqual[im, 430.0], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * N[(N[(-0.3333333333333333 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision] - 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 8.4e+101], N[(0.5 * N[Log[1 + N[(Exp[N[(im * -2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[re], $MachinePrecision] * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision] * -0.16666666666666666), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 430:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot \left(-0.3333333333333333 \cdot {im}^{2} - 2\right)\right)\right)\\
\mathbf{elif}\;im \leq 8.4 \cdot 10^{+101}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\cos re \cdot {im}^{3}\right) \cdot -0.16666666666666666\\
\end{array}
\end{array}
if im < 430Initial program 33.6%
/-rgt-identity33.6%
exp-033.6%
associate-*l/33.6%
cos-neg33.6%
associate-*l*33.6%
associate-*r/33.6%
exp-033.6%
/-rgt-identity33.6%
*-commutative33.6%
neg-sub033.6%
cos-neg33.6%
Simplified33.6%
Taylor expanded in im around 0 89.5%
if 430 < im < 8.4000000000000001e101Initial program 100.0%
/-rgt-identity100.0%
exp-0100.0%
associate-*l/100.0%
cos-neg100.0%
associate-*l*100.0%
associate-*r/100.0%
exp-0100.0%
/-rgt-identity100.0%
*-commutative100.0%
neg-sub0100.0%
cos-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 3.6%
*-commutative3.6%
associate-*r*3.6%
*-commutative3.6%
log1p-expm1-u100.0%
*-commutative100.0%
associate-*r*100.0%
*-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in re around 0 77.3%
expm1-define77.3%
*-commutative77.3%
Simplified77.3%
if 8.4000000000000001e101 < im Initial program 100.0%
/-rgt-identity100.0%
exp-0100.0%
associate-*l/100.0%
cos-neg100.0%
associate-*l*100.0%
associate-*r/100.0%
exp-0100.0%
/-rgt-identity100.0%
*-commutative100.0%
neg-sub0100.0%
cos-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 98.1%
Taylor expanded in im around inf 98.1%
Taylor expanded in im around 0 98.1%
*-commutative98.1%
*-commutative98.1%
Simplified98.1%
Final simplification90.0%
(FPCore (re im)
:precision binary64
(if (<= im 12.0)
(* 0.5 (* (cos re) (* im -2.0)))
(if (<= im 8.4e+101)
(* 0.5 (log1p (expm1 (* im -2.0))))
(* (* (cos re) (pow im 3.0)) -0.16666666666666666))))
double code(double re, double im) {
double tmp;
if (im <= 12.0) {
tmp = 0.5 * (cos(re) * (im * -2.0));
} else if (im <= 8.4e+101) {
tmp = 0.5 * log1p(expm1((im * -2.0)));
} else {
tmp = (cos(re) * pow(im, 3.0)) * -0.16666666666666666;
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (im <= 12.0) {
tmp = 0.5 * (Math.cos(re) * (im * -2.0));
} else if (im <= 8.4e+101) {
tmp = 0.5 * Math.log1p(Math.expm1((im * -2.0)));
} else {
tmp = (Math.cos(re) * Math.pow(im, 3.0)) * -0.16666666666666666;
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 12.0: tmp = 0.5 * (math.cos(re) * (im * -2.0)) elif im <= 8.4e+101: tmp = 0.5 * math.log1p(math.expm1((im * -2.0))) else: tmp = (math.cos(re) * math.pow(im, 3.0)) * -0.16666666666666666 return tmp
function code(re, im) tmp = 0.0 if (im <= 12.0) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * -2.0))); elseif (im <= 8.4e+101) tmp = Float64(0.5 * log1p(expm1(Float64(im * -2.0)))); else tmp = Float64(Float64(cos(re) * (im ^ 3.0)) * -0.16666666666666666); end return tmp end
code[re_, im_] := If[LessEqual[im, 12.0], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 8.4e+101], N[(0.5 * N[Log[1 + N[(Exp[N[(im * -2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[re], $MachinePrecision] * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision] * -0.16666666666666666), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 12:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\
\mathbf{elif}\;im \leq 8.4 \cdot 10^{+101}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\cos re \cdot {im}^{3}\right) \cdot -0.16666666666666666\\
\end{array}
\end{array}
if im < 12Initial program 33.2%
/-rgt-identity33.2%
exp-033.2%
associate-*l/33.2%
cos-neg33.2%
associate-*l*33.2%
associate-*r/33.2%
exp-033.2%
/-rgt-identity33.2%
*-commutative33.2%
neg-sub033.2%
cos-neg33.2%
Simplified33.2%
Taylor expanded in im around 0 74.1%
if 12 < im < 8.4000000000000001e101Initial program 99.9%
/-rgt-identity99.9%
exp-099.9%
associate-*l/99.9%
cos-neg99.9%
associate-*l*99.9%
associate-*r/99.9%
exp-099.9%
/-rgt-identity99.9%
*-commutative99.9%
neg-sub099.9%
cos-neg99.9%
Simplified99.9%
Taylor expanded in im around 0 4.0%
*-commutative4.0%
associate-*r*4.0%
*-commutative4.0%
log1p-expm1-u96.2%
*-commutative96.2%
associate-*r*96.2%
*-commutative96.2%
Applied egg-rr96.2%
Taylor expanded in re around 0 74.5%
expm1-define74.5%
*-commutative74.5%
Simplified74.5%
if 8.4000000000000001e101 < im Initial program 100.0%
/-rgt-identity100.0%
exp-0100.0%
associate-*l/100.0%
cos-neg100.0%
associate-*l*100.0%
associate-*r/100.0%
exp-0100.0%
/-rgt-identity100.0%
*-commutative100.0%
neg-sub0100.0%
cos-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 98.1%
Taylor expanded in im around inf 98.1%
Taylor expanded in im around 0 98.1%
*-commutative98.1%
*-commutative98.1%
Simplified98.1%
Final simplification78.5%
(FPCore (re im)
:precision binary64
(if (<= im 12.5)
(* 0.5 (* (cos re) (* im -2.0)))
(if (<= im 2.5e+133)
(* 0.5 (log1p (expm1 (* im -2.0))))
(if (<= im 4.2e+143)
(* 0.5 (* im (+ -2.0 (* re re))))
(* (pow im 3.0) -0.16666666666666666)))))
double code(double re, double im) {
double tmp;
if (im <= 12.5) {
tmp = 0.5 * (cos(re) * (im * -2.0));
} else if (im <= 2.5e+133) {
tmp = 0.5 * log1p(expm1((im * -2.0)));
} else if (im <= 4.2e+143) {
tmp = 0.5 * (im * (-2.0 + (re * re)));
} else {
tmp = pow(im, 3.0) * -0.16666666666666666;
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (im <= 12.5) {
tmp = 0.5 * (Math.cos(re) * (im * -2.0));
} else if (im <= 2.5e+133) {
tmp = 0.5 * Math.log1p(Math.expm1((im * -2.0)));
} else if (im <= 4.2e+143) {
tmp = 0.5 * (im * (-2.0 + (re * re)));
} else {
tmp = Math.pow(im, 3.0) * -0.16666666666666666;
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 12.5: tmp = 0.5 * (math.cos(re) * (im * -2.0)) elif im <= 2.5e+133: tmp = 0.5 * math.log1p(math.expm1((im * -2.0))) elif im <= 4.2e+143: tmp = 0.5 * (im * (-2.0 + (re * re))) else: tmp = math.pow(im, 3.0) * -0.16666666666666666 return tmp
function code(re, im) tmp = 0.0 if (im <= 12.5) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * -2.0))); elseif (im <= 2.5e+133) tmp = Float64(0.5 * log1p(expm1(Float64(im * -2.0)))); elseif (im <= 4.2e+143) tmp = Float64(0.5 * Float64(im * Float64(-2.0 + Float64(re * re)))); else tmp = Float64((im ^ 3.0) * -0.16666666666666666); end return tmp end
code[re_, im_] := If[LessEqual[im, 12.5], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 2.5e+133], N[(0.5 * N[Log[1 + N[(Exp[N[(im * -2.0), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 4.2e+143], N[(0.5 * N[(im * N[(-2.0 + N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 12.5:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\
\mathbf{elif}\;im \leq 2.5 \cdot 10^{+133}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot -2\right)\right)\\
\mathbf{elif}\;im \leq 4.2 \cdot 10^{+143}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(-2 + re \cdot re\right)\right)\\
\mathbf{else}:\\
\;\;\;\;{im}^{3} \cdot -0.16666666666666666\\
\end{array}
\end{array}
if im < 12.5Initial program 33.2%
/-rgt-identity33.2%
exp-033.2%
associate-*l/33.2%
cos-neg33.2%
associate-*l*33.2%
associate-*r/33.2%
exp-033.2%
/-rgt-identity33.2%
*-commutative33.2%
neg-sub033.2%
cos-neg33.2%
Simplified33.2%
Taylor expanded in im around 0 74.1%
if 12.5 < im < 2.4999999999999998e133Initial program 99.9%
/-rgt-identity99.9%
exp-099.9%
associate-*l/99.9%
cos-neg99.9%
associate-*l*99.9%
associate-*r/99.9%
exp-099.9%
/-rgt-identity99.9%
*-commutative99.9%
neg-sub099.9%
cos-neg99.9%
Simplified99.9%
Taylor expanded in im around 0 4.0%
*-commutative4.0%
associate-*r*4.0%
*-commutative4.0%
log1p-expm1-u97.0%
*-commutative97.0%
associate-*r*97.0%
*-commutative97.0%
Applied egg-rr97.0%
Taylor expanded in re around 0 76.3%
expm1-define76.3%
*-commutative76.3%
Simplified76.3%
if 2.4999999999999998e133 < im < 4.19999999999999975e143Initial program 100.0%
/-rgt-identity100.0%
exp-0100.0%
associate-*l/100.0%
cos-neg100.0%
associate-*l*100.0%
associate-*r/100.0%
exp-0100.0%
/-rgt-identity100.0%
*-commutative100.0%
neg-sub0100.0%
cos-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 4.5%
Taylor expanded in re around 0 76.3%
+-commutative76.3%
*-commutative76.3%
distribute-lft-out76.3%
Simplified76.3%
unpow276.3%
Applied egg-rr76.3%
if 4.19999999999999975e143 < im Initial program 100.0%
/-rgt-identity100.0%
exp-0100.0%
associate-*l/100.0%
cos-neg100.0%
associate-*l*100.0%
associate-*r/100.0%
exp-0100.0%
/-rgt-identity100.0%
*-commutative100.0%
neg-sub0100.0%
cos-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in im around inf 100.0%
Taylor expanded in re around 0 80.6%
*-commutative80.6%
Simplified80.6%
Final simplification75.3%
(FPCore (re im) :precision binary64 (if (<= im 3.4e+37) (* 0.5 (* (cos re) (* im -2.0))) (* (pow im 3.0) -0.16666666666666666)))
double code(double re, double im) {
double tmp;
if (im <= 3.4e+37) {
tmp = 0.5 * (cos(re) * (im * -2.0));
} else {
tmp = pow(im, 3.0) * -0.16666666666666666;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 3.4d+37) then
tmp = 0.5d0 * (cos(re) * (im * (-2.0d0)))
else
tmp = (im ** 3.0d0) * (-0.16666666666666666d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 3.4e+37) {
tmp = 0.5 * (Math.cos(re) * (im * -2.0));
} else {
tmp = Math.pow(im, 3.0) * -0.16666666666666666;
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 3.4e+37: tmp = 0.5 * (math.cos(re) * (im * -2.0)) else: tmp = math.pow(im, 3.0) * -0.16666666666666666 return tmp
function code(re, im) tmp = 0.0 if (im <= 3.4e+37) tmp = Float64(0.5 * Float64(cos(re) * Float64(im * -2.0))); else tmp = Float64((im ^ 3.0) * -0.16666666666666666); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 3.4e+37) tmp = 0.5 * (cos(re) * (im * -2.0)); else tmp = (im ^ 3.0) * -0.16666666666666666; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 3.4e+37], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 3.4 \cdot 10^{+37}:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot -2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;{im}^{3} \cdot -0.16666666666666666\\
\end{array}
\end{array}
if im < 3.40000000000000006e37Initial program 36.6%
/-rgt-identity36.6%
exp-036.6%
associate-*l/36.6%
cos-neg36.6%
associate-*l*36.6%
associate-*r/36.6%
exp-036.6%
/-rgt-identity36.6%
*-commutative36.6%
neg-sub036.6%
cos-neg36.6%
Simplified36.6%
Taylor expanded in im around 0 70.6%
if 3.40000000000000006e37 < im Initial program 100.0%
/-rgt-identity100.0%
exp-0100.0%
associate-*l/100.0%
cos-neg100.0%
associate-*l*100.0%
associate-*r/100.0%
exp-0100.0%
/-rgt-identity100.0%
*-commutative100.0%
neg-sub0100.0%
cos-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 78.0%
Taylor expanded in im around inf 78.0%
Taylor expanded in re around 0 58.9%
*-commutative58.9%
Simplified58.9%
Final simplification67.9%
(FPCore (re im) :precision binary64 (if (<= im 2.4) (* 0.5 (* im -2.0)) (* (pow im 3.0) -0.16666666666666666)))
double code(double re, double im) {
double tmp;
if (im <= 2.4) {
tmp = 0.5 * (im * -2.0);
} else {
tmp = pow(im, 3.0) * -0.16666666666666666;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 2.4d0) then
tmp = 0.5d0 * (im * (-2.0d0))
else
tmp = (im ** 3.0d0) * (-0.16666666666666666d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 2.4) {
tmp = 0.5 * (im * -2.0);
} else {
tmp = Math.pow(im, 3.0) * -0.16666666666666666;
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 2.4: tmp = 0.5 * (im * -2.0) else: tmp = math.pow(im, 3.0) * -0.16666666666666666 return tmp
function code(re, im) tmp = 0.0 if (im <= 2.4) tmp = Float64(0.5 * Float64(im * -2.0)); else tmp = Float64((im ^ 3.0) * -0.16666666666666666); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 2.4) tmp = 0.5 * (im * -2.0); else tmp = (im ^ 3.0) * -0.16666666666666666; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 2.4], N[(0.5 * N[(im * -2.0), $MachinePrecision]), $MachinePrecision], N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 2.4:\\
\;\;\;\;0.5 \cdot \left(im \cdot -2\right)\\
\mathbf{else}:\\
\;\;\;\;{im}^{3} \cdot -0.16666666666666666\\
\end{array}
\end{array}
if im < 2.39999999999999991Initial program 33.2%
/-rgt-identity33.2%
exp-033.2%
associate-*l/33.2%
cos-neg33.2%
associate-*l*33.2%
associate-*r/33.2%
exp-033.2%
/-rgt-identity33.2%
*-commutative33.2%
neg-sub033.2%
cos-neg33.2%
Simplified33.2%
Taylor expanded in im around 0 74.1%
Taylor expanded in re around 0 41.5%
*-commutative41.5%
Simplified41.5%
if 2.39999999999999991 < im Initial program 100.0%
/-rgt-identity100.0%
exp-0100.0%
associate-*l/100.0%
cos-neg100.0%
associate-*l*100.0%
associate-*r/100.0%
exp-0100.0%
/-rgt-identity100.0%
*-commutative100.0%
neg-sub0100.0%
cos-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 67.4%
Taylor expanded in im around inf 67.4%
Taylor expanded in re around 0 50.9%
*-commutative50.9%
Simplified50.9%
(FPCore (re im) :precision binary64 (if (<= im 186.0) (* 0.5 (* im -2.0)) (* 0.5 (* im (+ -2.0 (* re re))))))
double code(double re, double im) {
double tmp;
if (im <= 186.0) {
tmp = 0.5 * (im * -2.0);
} else {
tmp = 0.5 * (im * (-2.0 + (re * re)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 186.0d0) then
tmp = 0.5d0 * (im * (-2.0d0))
else
tmp = 0.5d0 * (im * ((-2.0d0) + (re * re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 186.0) {
tmp = 0.5 * (im * -2.0);
} else {
tmp = 0.5 * (im * (-2.0 + (re * re)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 186.0: tmp = 0.5 * (im * -2.0) else: tmp = 0.5 * (im * (-2.0 + (re * re))) return tmp
function code(re, im) tmp = 0.0 if (im <= 186.0) tmp = Float64(0.5 * Float64(im * -2.0)); else tmp = Float64(0.5 * Float64(im * Float64(-2.0 + Float64(re * re)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 186.0) tmp = 0.5 * (im * -2.0); else tmp = 0.5 * (im * (-2.0 + (re * re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 186.0], N[(0.5 * N[(im * -2.0), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[(-2.0 + N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 186:\\
\;\;\;\;0.5 \cdot \left(im \cdot -2\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(-2 + re \cdot re\right)\right)\\
\end{array}
\end{array}
if im < 186Initial program 33.6%
/-rgt-identity33.6%
exp-033.6%
associate-*l/33.6%
cos-neg33.6%
associate-*l*33.6%
associate-*r/33.6%
exp-033.6%
/-rgt-identity33.6%
*-commutative33.6%
neg-sub033.6%
cos-neg33.6%
Simplified33.6%
Taylor expanded in im around 0 73.8%
Taylor expanded in re around 0 41.4%
*-commutative41.4%
Simplified41.4%
if 186 < im Initial program 100.0%
/-rgt-identity100.0%
exp-0100.0%
associate-*l/100.0%
cos-neg100.0%
associate-*l*100.0%
associate-*r/100.0%
exp-0100.0%
/-rgt-identity100.0%
*-commutative100.0%
neg-sub0100.0%
cos-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 5.2%
Taylor expanded in re around 0 21.9%
+-commutative21.9%
*-commutative21.9%
distribute-lft-out21.9%
Simplified21.9%
unpow221.9%
Applied egg-rr21.9%
Final simplification36.2%
(FPCore (re im) :precision binary64 (* 0.5 (* im -2.0)))
double code(double re, double im) {
return 0.5 * (im * -2.0);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * (im * (-2.0d0))
end function
public static double code(double re, double im) {
return 0.5 * (im * -2.0);
}
def code(re, im): return 0.5 * (im * -2.0)
function code(re, im) return Float64(0.5 * Float64(im * -2.0)) end
function tmp = code(re, im) tmp = 0.5 * (im * -2.0); end
code[re_, im_] := N[(0.5 * N[(im * -2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(im \cdot -2\right)
\end{array}
Initial program 51.2%
/-rgt-identity51.2%
exp-051.2%
associate-*l/51.2%
cos-neg51.2%
associate-*l*51.2%
associate-*r/51.2%
exp-051.2%
/-rgt-identity51.2%
*-commutative51.2%
neg-sub051.2%
cos-neg51.2%
Simplified51.2%
Taylor expanded in im around 0 55.6%
Taylor expanded in re around 0 31.5%
*-commutative31.5%
Simplified31.5%
(FPCore (re im)
:precision binary64
(if (< (fabs im) 1.0)
(-
(*
(cos re)
(+
(+ im (* (* (* 0.16666666666666666 im) im) im))
(* (* (* (* (* 0.008333333333333333 im) im) im) im) im))))
(* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im)))))
double code(double re, double im) {
double tmp;
if (fabs(im) < 1.0) {
tmp = -(cos(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im)));
} else {
tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (abs(im) < 1.0d0) then
tmp = -(cos(re) * ((im + (((0.16666666666666666d0 * im) * im) * im)) + (((((0.008333333333333333d0 * im) * im) * im) * im) * im)))
else
tmp = (0.5d0 * cos(re)) * (exp((0.0d0 - im)) - exp(im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (Math.abs(im) < 1.0) {
tmp = -(Math.cos(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im)));
} else {
tmp = (0.5 * Math.cos(re)) * (Math.exp((0.0 - im)) - Math.exp(im));
}
return tmp;
}
def code(re, im): tmp = 0 if math.fabs(im) < 1.0: tmp = -(math.cos(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im))) else: tmp = (0.5 * math.cos(re)) * (math.exp((0.0 - im)) - math.exp(im)) return tmp
function code(re, im) tmp = 0.0 if (abs(im) < 1.0) tmp = Float64(-Float64(cos(re) * Float64(Float64(im + Float64(Float64(Float64(0.16666666666666666 * im) * im) * im)) + Float64(Float64(Float64(Float64(Float64(0.008333333333333333 * im) * im) * im) * im) * im)))); else tmp = Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(0.0 - im)) - exp(im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (abs(im) < 1.0) tmp = -(cos(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im))); else tmp = (0.5 * cos(re)) * (exp((0.0 - im)) - exp(im)); end tmp_2 = tmp; end
code[re_, im_] := If[Less[N[Abs[im], $MachinePrecision], 1.0], (-N[(N[Cos[re], $MachinePrecision] * N[(N[(im + N[(N[(N[(0.16666666666666666 * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[(N[(0.008333333333333333 * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|im\right| < 1:\\
\;\;\;\;-\cos re \cdot \left(\left(im + \left(\left(0.16666666666666666 \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(0.008333333333333333 \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(e^{0 - im} - e^{im}\right)\\
\end{array}
\end{array}
herbie shell --seed 2024108
(FPCore (re im)
:name "math.sin on complex, imaginary part"
:precision binary64
:alt
(if (< (fabs im) 1.0) (- (* (cos re) (+ (+ im (* (* (* 0.16666666666666666 im) im) im)) (* (* (* (* (* 0.008333333333333333 im) im) im) im) im)))) (* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))
(* (* 0.5 (cos re)) (- (exp (- 0.0 im)) (exp im))))