
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp(-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(-im) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp(-im) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 19 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp(-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(-im) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp(-im) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
\end{array}
(FPCore (re im) :precision binary64 (* (cos re) (fma 0.5 (exp im) (/ 0.5 (exp im)))))
double code(double re, double im) {
return cos(re) * fma(0.5, exp(im), (0.5 / exp(im)));
}
function code(re, im) return Float64(cos(re) * fma(0.5, exp(im), Float64(0.5 / exp(im)))) end
code[re_, im_] := N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[Exp[im], $MachinePrecision] + N[(0.5 / N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right)
\end{array}
Initial program 100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-lft-in100.0%
distribute-lft-in100.0%
distribute-rgt-in100.0%
*-commutative100.0%
fma-def100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (re im)
:precision binary64
(if (<= (cos re) 0.999999999)
(*
(* (cos re) 0.5)
(+ 2.0 (+ (* im im) (* (pow im 4.0) 0.08333333333333333))))
(* 0.5 (+ (exp im) (exp (- im))))))
double code(double re, double im) {
double tmp;
if (cos(re) <= 0.999999999) {
tmp = (cos(re) * 0.5) * (2.0 + ((im * im) + (pow(im, 4.0) * 0.08333333333333333)));
} else {
tmp = 0.5 * (exp(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 (cos(re) <= 0.999999999d0) then
tmp = (cos(re) * 0.5d0) * (2.0d0 + ((im * im) + ((im ** 4.0d0) * 0.08333333333333333d0)))
else
tmp = 0.5d0 * (exp(im) + exp(-im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (Math.cos(re) <= 0.999999999) {
tmp = (Math.cos(re) * 0.5) * (2.0 + ((im * im) + (Math.pow(im, 4.0) * 0.08333333333333333)));
} else {
tmp = 0.5 * (Math.exp(im) + Math.exp(-im));
}
return tmp;
}
def code(re, im): tmp = 0 if math.cos(re) <= 0.999999999: tmp = (math.cos(re) * 0.5) * (2.0 + ((im * im) + (math.pow(im, 4.0) * 0.08333333333333333))) else: tmp = 0.5 * (math.exp(im) + math.exp(-im)) return tmp
function code(re, im) tmp = 0.0 if (cos(re) <= 0.999999999) tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(Float64(im * im) + Float64((im ^ 4.0) * 0.08333333333333333)))); else tmp = Float64(0.5 * Float64(exp(im) + exp(Float64(-im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (cos(re) <= 0.999999999) tmp = (cos(re) * 0.5) * (2.0 + ((im * im) + ((im ^ 4.0) * 0.08333333333333333))); else tmp = 0.5 * (exp(im) + exp(-im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Cos[re], $MachinePrecision], 0.999999999], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(N[(im * im), $MachinePrecision] + N[(N[Power[im, 4.0], $MachinePrecision] * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Exp[im], $MachinePrecision] + N[Exp[(-im)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos re \leq 0.999999999:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + \left(im \cdot im + {im}^{4} \cdot 0.08333333333333333\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(e^{im} + e^{-im}\right)\\
\end{array}
\end{array}
if (cos.f64 re) < 0.999999999000000028Initial program 100.0%
Taylor expanded in im around 0 88.6%
unpow288.6%
*-commutative88.6%
Simplified88.6%
if 0.999999999000000028 < (cos.f64 re) Initial program 100.0%
Taylor expanded in re around 0 100.0%
Final simplification94.1%
(FPCore (re im)
:precision binary64
(if (<= im -4.5e+72)
(* 0.041666666666666664 (* (cos re) (pow im 4.0)))
(if (<= im -4500.0)
(* 0.5 (+ (exp im) (exp (- im))))
(if (<= im 1.9)
(*
(* (cos re) 0.5)
(+ 2.0 (+ (* im im) (* (pow im 4.0) 0.08333333333333333))))
(* (cos re) (fma 0.5 (exp im) 0.0))))))
double code(double re, double im) {
double tmp;
if (im <= -4.5e+72) {
tmp = 0.041666666666666664 * (cos(re) * pow(im, 4.0));
} else if (im <= -4500.0) {
tmp = 0.5 * (exp(im) + exp(-im));
} else if (im <= 1.9) {
tmp = (cos(re) * 0.5) * (2.0 + ((im * im) + (pow(im, 4.0) * 0.08333333333333333)));
} else {
tmp = cos(re) * fma(0.5, exp(im), 0.0);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= -4.5e+72) tmp = Float64(0.041666666666666664 * Float64(cos(re) * (im ^ 4.0))); elseif (im <= -4500.0) tmp = Float64(0.5 * Float64(exp(im) + exp(Float64(-im)))); elseif (im <= 1.9) tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(Float64(im * im) + Float64((im ^ 4.0) * 0.08333333333333333)))); else tmp = Float64(cos(re) * fma(0.5, exp(im), 0.0)); end return tmp end
code[re_, im_] := If[LessEqual[im, -4.5e+72], N[(0.041666666666666664 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, -4500.0], N[(0.5 * N[(N[Exp[im], $MachinePrecision] + N[Exp[(-im)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.9], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(N[(im * im), $MachinePrecision] + N[(N[Power[im, 4.0], $MachinePrecision] * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[Exp[im], $MachinePrecision] + 0.0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq -4.5 \cdot 10^{+72}:\\
\;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\
\mathbf{elif}\;im \leq -4500:\\
\;\;\;\;0.5 \cdot \left(e^{im} + e^{-im}\right)\\
\mathbf{elif}\;im \leq 1.9:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + \left(im \cdot im + {im}^{4} \cdot 0.08333333333333333\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \mathsf{fma}\left(0.5, e^{im}, 0\right)\\
\end{array}
\end{array}
if im < -4.4999999999999998e72Initial program 100.0%
Taylor expanded in im around 0 98.3%
unpow298.3%
*-commutative98.3%
Simplified98.3%
Taylor expanded in im around inf 98.3%
*-commutative98.3%
Simplified98.3%
if -4.4999999999999998e72 < im < -4500Initial program 100.0%
Taylor expanded in re around 0 72.7%
if -4500 < im < 1.8999999999999999Initial program 100.0%
Taylor expanded in im around 0 99.2%
unpow299.2%
*-commutative99.2%
Simplified99.2%
if 1.8999999999999999 < im Initial program 100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-lft-in100.0%
distribute-lft-in100.0%
distribute-rgt-in100.0%
*-commutative100.0%
fma-def100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Applied egg-rr99.4%
Final simplification97.9%
(FPCore (re im) :precision binary64 (* (* (cos re) 0.5) (+ (exp im) (exp (- im)))))
double code(double re, double im) {
return (cos(re) * 0.5) * (exp(im) + exp(-im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (cos(re) * 0.5d0) * (exp(im) + exp(-im))
end function
public static double code(double re, double im) {
return (Math.cos(re) * 0.5) * (Math.exp(im) + Math.exp(-im));
}
def code(re, im): return (math.cos(re) * 0.5) * (math.exp(im) + math.exp(-im))
function code(re, im) return Float64(Float64(cos(re) * 0.5) * Float64(exp(im) + exp(Float64(-im)))) end
function tmp = code(re, im) tmp = (cos(re) * 0.5) * (exp(im) + exp(-im)); end
code[re_, im_] := N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(N[Exp[im], $MachinePrecision] + N[Exp[(-im)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\cos re \cdot 0.5\right) \cdot \left(e^{im} + e^{-im}\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (+ (exp im) (exp (- im)))))
(t_1 (* 0.041666666666666664 (* (cos re) (pow im 4.0)))))
(if (<= im -4.5e+72)
t_1
(if (<= im -4500.0)
t_0
(if (<= im 0.0285)
(* (* (cos re) 0.5) (+ 2.0 (* im im)))
(if (<= im 4.2e+68) t_0 t_1))))))
double code(double re, double im) {
double t_0 = 0.5 * (exp(im) + exp(-im));
double t_1 = 0.041666666666666664 * (cos(re) * pow(im, 4.0));
double tmp;
if (im <= -4.5e+72) {
tmp = t_1;
} else if (im <= -4500.0) {
tmp = t_0;
} else if (im <= 0.0285) {
tmp = (cos(re) * 0.5) * (2.0 + (im * im));
} else if (im <= 4.2e+68) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 0.5d0 * (exp(im) + exp(-im))
t_1 = 0.041666666666666664d0 * (cos(re) * (im ** 4.0d0))
if (im <= (-4.5d+72)) then
tmp = t_1
else if (im <= (-4500.0d0)) then
tmp = t_0
else if (im <= 0.0285d0) then
tmp = (cos(re) * 0.5d0) * (2.0d0 + (im * im))
else if (im <= 4.2d+68) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 0.5 * (Math.exp(im) + Math.exp(-im));
double t_1 = 0.041666666666666664 * (Math.cos(re) * Math.pow(im, 4.0));
double tmp;
if (im <= -4.5e+72) {
tmp = t_1;
} else if (im <= -4500.0) {
tmp = t_0;
} else if (im <= 0.0285) {
tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
} else if (im <= 4.2e+68) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(re, im): t_0 = 0.5 * (math.exp(im) + math.exp(-im)) t_1 = 0.041666666666666664 * (math.cos(re) * math.pow(im, 4.0)) tmp = 0 if im <= -4.5e+72: tmp = t_1 elif im <= -4500.0: tmp = t_0 elif im <= 0.0285: tmp = (math.cos(re) * 0.5) * (2.0 + (im * im)) elif im <= 4.2e+68: tmp = t_0 else: tmp = t_1 return tmp
function code(re, im) t_0 = Float64(0.5 * Float64(exp(im) + exp(Float64(-im)))) t_1 = Float64(0.041666666666666664 * Float64(cos(re) * (im ^ 4.0))) tmp = 0.0 if (im <= -4.5e+72) tmp = t_1; elseif (im <= -4500.0) tmp = t_0; elseif (im <= 0.0285) tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im))); elseif (im <= 4.2e+68) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * (exp(im) + exp(-im)); t_1 = 0.041666666666666664 * (cos(re) * (im ^ 4.0)); tmp = 0.0; if (im <= -4.5e+72) tmp = t_1; elseif (im <= -4500.0) tmp = t_0; elseif (im <= 0.0285) tmp = (cos(re) * 0.5) * (2.0 + (im * im)); elseif (im <= 4.2e+68) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[(N[Exp[im], $MachinePrecision] + N[Exp[(-im)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.041666666666666664 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -4.5e+72], t$95$1, If[LessEqual[im, -4500.0], t$95$0, If[LessEqual[im, 0.0285], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 4.2e+68], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(e^{im} + e^{-im}\right)\\
t_1 := 0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\
\mathbf{if}\;im \leq -4.5 \cdot 10^{+72}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;im \leq -4500:\\
\;\;\;\;t_0\\
\mathbf{elif}\;im \leq 0.0285:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\
\mathbf{elif}\;im \leq 4.2 \cdot 10^{+68}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if im < -4.4999999999999998e72 or 4.20000000000000002e68 < im Initial program 100.0%
Taylor expanded in im around 0 96.6%
unpow296.6%
*-commutative96.6%
Simplified96.6%
Taylor expanded in im around inf 96.6%
*-commutative96.6%
Simplified96.6%
if -4.4999999999999998e72 < im < -4500 or 0.028500000000000001 < im < 4.20000000000000002e68Initial program 99.9%
Taylor expanded in re around 0 78.5%
if -4500 < im < 0.028500000000000001Initial program 100.0%
Taylor expanded in im around 0 99.0%
unpow299.0%
Simplified99.0%
Final simplification96.2%
(FPCore (re im) :precision binary64 (if (or (<= im -3.7) (not (<= im 3.7))) (* 0.041666666666666664 (* (cos re) (pow im 4.0))) (* (* (cos re) 0.5) (+ 2.0 (* im im)))))
double code(double re, double im) {
double tmp;
if ((im <= -3.7) || !(im <= 3.7)) {
tmp = 0.041666666666666664 * (cos(re) * pow(im, 4.0));
} else {
tmp = (cos(re) * 0.5) * (2.0 + (im * im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((im <= (-3.7d0)) .or. (.not. (im <= 3.7d0))) then
tmp = 0.041666666666666664d0 * (cos(re) * (im ** 4.0d0))
else
tmp = (cos(re) * 0.5d0) * (2.0d0 + (im * im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((im <= -3.7) || !(im <= 3.7)) {
tmp = 0.041666666666666664 * (Math.cos(re) * Math.pow(im, 4.0));
} else {
tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= -3.7) or not (im <= 3.7): tmp = 0.041666666666666664 * (math.cos(re) * math.pow(im, 4.0)) else: tmp = (math.cos(re) * 0.5) * (2.0 + (im * im)) return tmp
function code(re, im) tmp = 0.0 if ((im <= -3.7) || !(im <= 3.7)) tmp = Float64(0.041666666666666664 * Float64(cos(re) * (im ^ 4.0))); else tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((im <= -3.7) || ~((im <= 3.7))) tmp = 0.041666666666666664 * (cos(re) * (im ^ 4.0)); else tmp = (cos(re) * 0.5) * (2.0 + (im * im)); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, -3.7], N[Not[LessEqual[im, 3.7]], $MachinePrecision]], N[(0.041666666666666664 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq -3.7 \lor \neg \left(im \leq 3.7\right):\\
\;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\
\end{array}
\end{array}
if im < -3.7000000000000002 or 3.7000000000000002 < im Initial program 100.0%
Taylor expanded in im around 0 80.8%
unpow280.8%
*-commutative80.8%
Simplified80.8%
Taylor expanded in im around inf 80.8%
*-commutative80.8%
Simplified80.8%
if -3.7000000000000002 < im < 3.7000000000000002Initial program 100.0%
Taylor expanded in im around 0 99.7%
unpow299.7%
Simplified99.7%
Final simplification90.0%
(FPCore (re im) :precision binary64 (if (or (<= im -3.8e+78) (not (<= im 6.4e-9))) (* 0.5 (+ 2.0 (pow im 2.0))) (cos re)))
double code(double re, double im) {
double tmp;
if ((im <= -3.8e+78) || !(im <= 6.4e-9)) {
tmp = 0.5 * (2.0 + pow(im, 2.0));
} else {
tmp = cos(re);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((im <= (-3.8d+78)) .or. (.not. (im <= 6.4d-9))) then
tmp = 0.5d0 * (2.0d0 + (im ** 2.0d0))
else
tmp = cos(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((im <= -3.8e+78) || !(im <= 6.4e-9)) {
tmp = 0.5 * (2.0 + Math.pow(im, 2.0));
} else {
tmp = Math.cos(re);
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= -3.8e+78) or not (im <= 6.4e-9): tmp = 0.5 * (2.0 + math.pow(im, 2.0)) else: tmp = math.cos(re) return tmp
function code(re, im) tmp = 0.0 if ((im <= -3.8e+78) || !(im <= 6.4e-9)) tmp = Float64(0.5 * Float64(2.0 + (im ^ 2.0))); else tmp = cos(re); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((im <= -3.8e+78) || ~((im <= 6.4e-9))) tmp = 0.5 * (2.0 + (im ^ 2.0)); else tmp = cos(re); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, -3.8e+78], N[Not[LessEqual[im, 6.4e-9]], $MachinePrecision]], N[(0.5 * N[(2.0 + N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Cos[re], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq -3.8 \cdot 10^{+78} \lor \neg \left(im \leq 6.4 \cdot 10^{-9}\right):\\
\;\;\;\;0.5 \cdot \left(2 + {im}^{2}\right)\\
\mathbf{else}:\\
\;\;\;\;\cos re\\
\end{array}
\end{array}
if im < -3.7999999999999999e78 or 6.40000000000000023e-9 < im Initial program 100.0%
Taylor expanded in im around 0 60.8%
unpow260.8%
Simplified60.8%
Taylor expanded in re around 0 47.0%
if -3.7999999999999999e78 < im < 6.40000000000000023e-9Initial program 100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-lft-in100.0%
distribute-lft-in100.0%
distribute-rgt-in100.0%
*-commutative100.0%
fma-def100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 89.3%
Final simplification69.5%
(FPCore (re im) :precision binary64 (* (* (cos re) 0.5) (+ 2.0 (* im im))))
double code(double re, double im) {
return (cos(re) * 0.5) * (2.0 + (im * im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (cos(re) * 0.5d0) * (2.0d0 + (im * im))
end function
public static double code(double re, double im) {
return (Math.cos(re) * 0.5) * (2.0 + (im * im));
}
def code(re, im): return (math.cos(re) * 0.5) * (2.0 + (im * im))
function code(re, im) return Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im))) end
function tmp = code(re, im) tmp = (cos(re) * 0.5) * (2.0 + (im * im)); end
code[re_, im_] := N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 76.0%
unpow276.0%
Simplified76.0%
Final simplification76.0%
(FPCore (re im) :precision binary64 (cos re))
double code(double re, double im) {
return cos(re);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = cos(re)
end function
public static double code(double re, double im) {
return Math.cos(re);
}
def code(re, im): return math.cos(re)
function code(re, im) return cos(re) end
function tmp = code(re, im) tmp = cos(re); end
code[re_, im_] := N[Cos[re], $MachinePrecision]
\begin{array}{l}
\\
\cos re
\end{array}
Initial program 100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-lft-in100.0%
distribute-lft-in100.0%
distribute-rgt-in100.0%
*-commutative100.0%
fma-def100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 49.7%
Final simplification49.7%
(FPCore (re im) :precision binary64 -1.0)
double code(double re, double im) {
return -1.0;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = -1.0d0
end function
public static double code(double re, double im) {
return -1.0;
}
def code(re, im): return -1.0
function code(re, im) return -1.0 end
function tmp = code(re, im) tmp = -1.0; end
code[re_, im_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 65.8%
Applied egg-rr3.2%
Final simplification3.2%
(FPCore (re im) :precision binary64 -0.5)
double code(double re, double im) {
return -0.5;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = -0.5d0
end function
public static double code(double re, double im) {
return -0.5;
}
def code(re, im): return -0.5
function code(re, im) return -0.5 end
function tmp = code(re, im) tmp = -0.5; end
code[re_, im_] := -0.5
\begin{array}{l}
\\
-0.5
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 65.8%
Applied egg-rr3.2%
Final simplification3.2%
(FPCore (re im) :precision binary64 0.0009765625)
double code(double re, double im) {
return 0.0009765625;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.0009765625d0
end function
public static double code(double re, double im) {
return 0.0009765625;
}
def code(re, im): return 0.0009765625
function code(re, im) return 0.0009765625 end
function tmp = code(re, im) tmp = 0.0009765625; end
code[re_, im_] := 0.0009765625
\begin{array}{l}
\\
0.0009765625
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 65.8%
Applied egg-rr6.8%
Final simplification6.8%
(FPCore (re im) :precision binary64 0.0078125)
double code(double re, double im) {
return 0.0078125;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.0078125d0
end function
public static double code(double re, double im) {
return 0.0078125;
}
def code(re, im): return 0.0078125
function code(re, im) return 0.0078125 end
function tmp = code(re, im) tmp = 0.0078125; end
code[re_, im_] := 0.0078125
\begin{array}{l}
\\
0.0078125
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 65.8%
Applied egg-rr7.1%
Final simplification7.1%
(FPCore (re im) :precision binary64 0.0625)
double code(double re, double im) {
return 0.0625;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.0625d0
end function
public static double code(double re, double im) {
return 0.0625;
}
def code(re, im): return 0.0625
function code(re, im) return 0.0625 end
function tmp = code(re, im) tmp = 0.0625; end
code[re_, im_] := 0.0625
\begin{array}{l}
\\
0.0625
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 65.8%
Applied egg-rr7.6%
Final simplification7.6%
(FPCore (re im) :precision binary64 0.125)
double code(double re, double im) {
return 0.125;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.125d0
end function
public static double code(double re, double im) {
return 0.125;
}
def code(re, im): return 0.125
function code(re, im) return 0.125 end
function tmp = code(re, im) tmp = 0.125; end
code[re_, im_] := 0.125
\begin{array}{l}
\\
0.125
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 65.8%
Applied egg-rr8.0%
Final simplification8.0%
(FPCore (re im) :precision binary64 0.25)
double code(double re, double im) {
return 0.25;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.25d0
end function
public static double code(double re, double im) {
return 0.25;
}
def code(re, im): return 0.25
function code(re, im) return 0.25 end
function tmp = code(re, im) tmp = 0.25; end
code[re_, im_] := 0.25
\begin{array}{l}
\\
0.25
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 65.8%
Applied egg-rr8.2%
Final simplification8.2%
(FPCore (re im) :precision binary64 0.5)
double code(double re, double im) {
return 0.5;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0
end function
public static double code(double re, double im) {
return 0.5;
}
def code(re, im): return 0.5
function code(re, im) return 0.5 end
function tmp = code(re, im) tmp = 0.5; end
code[re_, im_] := 0.5
\begin{array}{l}
\\
0.5
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 65.8%
Applied egg-rr8.7%
Final simplification8.7%
(FPCore (re im) :precision binary64 0.75)
double code(double re, double im) {
return 0.75;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.75d0
end function
public static double code(double re, double im) {
return 0.75;
}
def code(re, im): return 0.75
function code(re, im) return 0.75 end
function tmp = code(re, im) tmp = 0.75; end
code[re_, im_] := 0.75
\begin{array}{l}
\\
0.75
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 65.8%
Applied egg-rr9.2%
Final simplification9.2%
(FPCore (re im) :precision binary64 1.0)
double code(double re, double im) {
return 1.0;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 1.0d0
end function
public static double code(double re, double im) {
return 1.0;
}
def code(re, im): return 1.0
function code(re, im) return 1.0 end
function tmp = code(re, im) tmp = 1.0; end
code[re_, im_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 65.8%
Taylor expanded in im around 0 29.7%
Final simplification29.7%
herbie shell --seed 2023181
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))