
(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 13 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%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.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.9999) (* (cos re) (+ 1.0 (* 0.001388888888888889 (pow im 6.0)))) (+ (* 0.5 (exp im)) (* 0.5 (/ 1.0 (exp im))))))
double code(double re, double im) {
double tmp;
if (cos(re) <= 0.9999) {
tmp = cos(re) * (1.0 + (0.001388888888888889 * pow(im, 6.0)));
} else {
tmp = (0.5 * exp(im)) + (0.5 * (1.0 / 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.9999d0) then
tmp = cos(re) * (1.0d0 + (0.001388888888888889d0 * (im ** 6.0d0)))
else
tmp = (0.5d0 * exp(im)) + (0.5d0 * (1.0d0 / exp(im)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (Math.cos(re) <= 0.9999) {
tmp = Math.cos(re) * (1.0 + (0.001388888888888889 * Math.pow(im, 6.0)));
} else {
tmp = (0.5 * Math.exp(im)) + (0.5 * (1.0 / Math.exp(im)));
}
return tmp;
}
def code(re, im): tmp = 0 if math.cos(re) <= 0.9999: tmp = math.cos(re) * (1.0 + (0.001388888888888889 * math.pow(im, 6.0))) else: tmp = (0.5 * math.exp(im)) + (0.5 * (1.0 / math.exp(im))) return tmp
function code(re, im) tmp = 0.0 if (cos(re) <= 0.9999) tmp = Float64(cos(re) * Float64(1.0 + Float64(0.001388888888888889 * (im ^ 6.0)))); else tmp = Float64(Float64(0.5 * exp(im)) + Float64(0.5 * Float64(1.0 / exp(im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (cos(re) <= 0.9999) tmp = cos(re) * (1.0 + (0.001388888888888889 * (im ^ 6.0))); else tmp = (0.5 * exp(im)) + (0.5 * (1.0 / exp(im))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Cos[re], $MachinePrecision], 0.9999], N[(N[Cos[re], $MachinePrecision] * N[(1.0 + N[(0.001388888888888889 * N[Power[im, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(1.0 / N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos re \leq 0.9999:\\
\;\;\;\;\cos re \cdot \left(1 + 0.001388888888888889 \cdot {im}^{6}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot e^{im} + 0.5 \cdot \frac{1}{e^{im}}\\
\end{array}
\end{array}
if (cos.f64 re) < 0.99990000000000001Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 91.7%
Taylor expanded in im around inf 91.6%
if 0.99990000000000001 < (cos.f64 re) Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in re around 0 100.0%
Final simplification95.6%
(FPCore (re im) :precision binary64 (if (<= (cos re) 0.9999) (* (cos re) (+ 1.0 (* 0.001388888888888889 (pow im 6.0)))) (* 0.5 (+ (exp im) (exp (- im))))))
double code(double re, double im) {
double tmp;
if (cos(re) <= 0.9999) {
tmp = cos(re) * (1.0 + (0.001388888888888889 * pow(im, 6.0)));
} 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.9999d0) then
tmp = cos(re) * (1.0d0 + (0.001388888888888889d0 * (im ** 6.0d0)))
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.9999) {
tmp = Math.cos(re) * (1.0 + (0.001388888888888889 * Math.pow(im, 6.0)));
} else {
tmp = 0.5 * (Math.exp(im) + Math.exp(-im));
}
return tmp;
}
def code(re, im): tmp = 0 if math.cos(re) <= 0.9999: tmp = math.cos(re) * (1.0 + (0.001388888888888889 * math.pow(im, 6.0))) else: tmp = 0.5 * (math.exp(im) + math.exp(-im)) return tmp
function code(re, im) tmp = 0.0 if (cos(re) <= 0.9999) tmp = Float64(cos(re) * Float64(1.0 + Float64(0.001388888888888889 * (im ^ 6.0)))); 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.9999) tmp = cos(re) * (1.0 + (0.001388888888888889 * (im ^ 6.0))); else tmp = 0.5 * (exp(im) + exp(-im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Cos[re], $MachinePrecision], 0.9999], N[(N[Cos[re], $MachinePrecision] * N[(1.0 + N[(0.001388888888888889 * N[Power[im, 6.0], $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.9999:\\
\;\;\;\;\cos re \cdot \left(1 + 0.001388888888888889 \cdot {im}^{6}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(e^{im} + e^{-im}\right)\\
\end{array}
\end{array}
if (cos.f64 re) < 0.99990000000000001Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 91.7%
Taylor expanded in im around inf 91.6%
if 0.99990000000000001 < (cos.f64 re) Initial program 100.0%
Taylor expanded in re around 0 100.0%
Final simplification95.6%
(FPCore (re im) :precision binary64 (if (<= im 1.35) (* (cos re) (* 0.5 (fma im im 2.0))) (* (cos re) (fma 0.5 (exp im) 0.0))))
double code(double re, double im) {
double tmp;
if (im <= 1.35) {
tmp = cos(re) * (0.5 * fma(im, im, 2.0));
} else {
tmp = cos(re) * fma(0.5, exp(im), 0.0);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 1.35) tmp = Float64(cos(re) * Float64(0.5 * fma(im, im, 2.0))); else tmp = Float64(cos(re) * fma(0.5, exp(im), 0.0)); end return tmp end
code[re_, im_] := If[LessEqual[im, 1.35], N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[(im * im + 2.0), $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 1.35:\\
\;\;\;\;\cos re \cdot \left(0.5 \cdot \mathsf{fma}\left(im, im, 2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \mathsf{fma}\left(0.5, e^{im}, 0\right)\\
\end{array}
\end{array}
if im < 1.3500000000000001Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 92.7%
Taylor expanded in im around 0 81.3%
associate-*r*81.3%
distribute-rgt1-in81.3%
metadata-eval81.3%
distribute-lft-in81.3%
+-commutative81.3%
*-commutative81.3%
+-commutative81.3%
unpow281.3%
fma-define81.3%
Simplified81.3%
if 1.3500000000000001 < im Initial program 99.9%
cos-neg99.9%
*-commutative99.9%
associate-*l*99.9%
+-commutative99.9%
distribute-rgt-in99.9%
cancel-sign-sub99.9%
distribute-lft-neg-in99.9%
cos-neg99.9%
*-commutative99.9%
fma-neg99.9%
remove-double-neg99.9%
exp-neg99.9%
associate-*l/99.9%
metadata-eval99.9%
Simplified99.9%
Applied egg-rr98.8%
Final simplification85.3%
(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
(if (<= im 1.3e+19)
(cos re)
(if (<= im 1e+48)
(sqrt (* (pow im 12.0) 1.9290123456790124e-6))
(* 0.001388888888888889 (* (cos re) (pow im 6.0))))))
double code(double re, double im) {
double tmp;
if (im <= 1.3e+19) {
tmp = cos(re);
} else if (im <= 1e+48) {
tmp = sqrt((pow(im, 12.0) * 1.9290123456790124e-6));
} else {
tmp = 0.001388888888888889 * (cos(re) * pow(im, 6.0));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 1.3d+19) then
tmp = cos(re)
else if (im <= 1d+48) then
tmp = sqrt(((im ** 12.0d0) * 1.9290123456790124d-6))
else
tmp = 0.001388888888888889d0 * (cos(re) * (im ** 6.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.3e+19) {
tmp = Math.cos(re);
} else if (im <= 1e+48) {
tmp = Math.sqrt((Math.pow(im, 12.0) * 1.9290123456790124e-6));
} else {
tmp = 0.001388888888888889 * (Math.cos(re) * Math.pow(im, 6.0));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.3e+19: tmp = math.cos(re) elif im <= 1e+48: tmp = math.sqrt((math.pow(im, 12.0) * 1.9290123456790124e-6)) else: tmp = 0.001388888888888889 * (math.cos(re) * math.pow(im, 6.0)) return tmp
function code(re, im) tmp = 0.0 if (im <= 1.3e+19) tmp = cos(re); elseif (im <= 1e+48) tmp = sqrt(Float64((im ^ 12.0) * 1.9290123456790124e-6)); else tmp = Float64(0.001388888888888889 * Float64(cos(re) * (im ^ 6.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.3e+19) tmp = cos(re); elseif (im <= 1e+48) tmp = sqrt(((im ^ 12.0) * 1.9290123456790124e-6)); else tmp = 0.001388888888888889 * (cos(re) * (im ^ 6.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.3e+19], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1e+48], N[Sqrt[N[(N[Power[im, 12.0], $MachinePrecision] * 1.9290123456790124e-6), $MachinePrecision]], $MachinePrecision], N[(0.001388888888888889 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.3 \cdot 10^{+19}:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 10^{+48}:\\
\;\;\;\;\sqrt{{im}^{12} \cdot 1.9290123456790124 \cdot 10^{-6}}\\
\mathbf{else}:\\
\;\;\;\;0.001388888888888889 \cdot \left(\cos re \cdot {im}^{6}\right)\\
\end{array}
\end{array}
if im < 1.3e19Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 63.6%
if 1.3e19 < im < 1.00000000000000004e48Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 5.1%
Taylor expanded in im around inf 5.1%
Taylor expanded in re around 0 5.1%
add-sqr-sqrt5.1%
sqrt-unprod42.6%
*-commutative42.6%
*-commutative42.6%
swap-sqr42.6%
pow-prod-up42.6%
metadata-eval42.6%
metadata-eval42.6%
Applied egg-rr42.6%
if 1.00000000000000004e48 < im Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 98.2%
Taylor expanded in im around inf 98.2%
Final simplification70.0%
(FPCore (re im)
:precision binary64
(if (<= im 6.8e-7)
(cos re)
(if (<= im 1e+48)
(* 0.5 (+ (exp im) (exp (- im))))
(* 0.001388888888888889 (* (cos re) (pow im 6.0))))))
double code(double re, double im) {
double tmp;
if (im <= 6.8e-7) {
tmp = cos(re);
} else if (im <= 1e+48) {
tmp = 0.5 * (exp(im) + exp(-im));
} else {
tmp = 0.001388888888888889 * (cos(re) * pow(im, 6.0));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 6.8d-7) then
tmp = cos(re)
else if (im <= 1d+48) then
tmp = 0.5d0 * (exp(im) + exp(-im))
else
tmp = 0.001388888888888889d0 * (cos(re) * (im ** 6.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 6.8e-7) {
tmp = Math.cos(re);
} else if (im <= 1e+48) {
tmp = 0.5 * (Math.exp(im) + Math.exp(-im));
} else {
tmp = 0.001388888888888889 * (Math.cos(re) * Math.pow(im, 6.0));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 6.8e-7: tmp = math.cos(re) elif im <= 1e+48: tmp = 0.5 * (math.exp(im) + math.exp(-im)) else: tmp = 0.001388888888888889 * (math.cos(re) * math.pow(im, 6.0)) return tmp
function code(re, im) tmp = 0.0 if (im <= 6.8e-7) tmp = cos(re); elseif (im <= 1e+48) tmp = Float64(0.5 * Float64(exp(im) + exp(Float64(-im)))); else tmp = Float64(0.001388888888888889 * Float64(cos(re) * (im ^ 6.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 6.8e-7) tmp = cos(re); elseif (im <= 1e+48) tmp = 0.5 * (exp(im) + exp(-im)); else tmp = 0.001388888888888889 * (cos(re) * (im ^ 6.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 6.8e-7], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1e+48], N[(0.5 * N[(N[Exp[im], $MachinePrecision] + N[Exp[(-im)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.001388888888888889 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 6.8 \cdot 10^{-7}:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 10^{+48}:\\
\;\;\;\;0.5 \cdot \left(e^{im} + e^{-im}\right)\\
\mathbf{else}:\\
\;\;\;\;0.001388888888888889 \cdot \left(\cos re \cdot {im}^{6}\right)\\
\end{array}
\end{array}
if im < 6.79999999999999948e-7Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 64.6%
if 6.79999999999999948e-7 < im < 1.00000000000000004e48Initial program 99.5%
Taylor expanded in re around 0 79.7%
if 1.00000000000000004e48 < im Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 98.2%
Taylor expanded in im around inf 98.2%
Final simplification71.7%
(FPCore (re im)
:precision binary64
(if (<= im 6.8e-7)
(* (cos re) (* 0.5 (fma im im 2.0)))
(if (<= im 1e+48)
(* 0.5 (+ (exp im) (exp (- im))))
(* 0.001388888888888889 (* (cos re) (pow im 6.0))))))
double code(double re, double im) {
double tmp;
if (im <= 6.8e-7) {
tmp = cos(re) * (0.5 * fma(im, im, 2.0));
} else if (im <= 1e+48) {
tmp = 0.5 * (exp(im) + exp(-im));
} else {
tmp = 0.001388888888888889 * (cos(re) * pow(im, 6.0));
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 6.8e-7) tmp = Float64(cos(re) * Float64(0.5 * fma(im, im, 2.0))); elseif (im <= 1e+48) tmp = Float64(0.5 * Float64(exp(im) + exp(Float64(-im)))); else tmp = Float64(0.001388888888888889 * Float64(cos(re) * (im ^ 6.0))); end return tmp end
code[re_, im_] := If[LessEqual[im, 6.8e-7], N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1e+48], N[(0.5 * N[(N[Exp[im], $MachinePrecision] + N[Exp[(-im)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.001388888888888889 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 6.8 \cdot 10^{-7}:\\
\;\;\;\;\cos re \cdot \left(0.5 \cdot \mathsf{fma}\left(im, im, 2\right)\right)\\
\mathbf{elif}\;im \leq 10^{+48}:\\
\;\;\;\;0.5 \cdot \left(e^{im} + e^{-im}\right)\\
\mathbf{else}:\\
\;\;\;\;0.001388888888888889 \cdot \left(\cos re \cdot {im}^{6}\right)\\
\end{array}
\end{array}
if im < 6.79999999999999948e-7Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 92.8%
Taylor expanded in im around 0 81.5%
associate-*r*81.5%
distribute-rgt1-in81.5%
metadata-eval81.5%
distribute-lft-in81.5%
+-commutative81.5%
*-commutative81.5%
+-commutative81.5%
unpow281.5%
fma-define81.5%
Simplified81.5%
if 6.79999999999999948e-7 < im < 1.00000000000000004e48Initial program 99.5%
Taylor expanded in re around 0 79.7%
if 1.00000000000000004e48 < im Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 98.2%
Taylor expanded in im around inf 98.2%
Final simplification84.7%
(FPCore (re im) :precision binary64 (if (<= im 1.5e+19) (cos re) (sqrt (* (pow im 12.0) 1.9290123456790124e-6))))
double code(double re, double im) {
double tmp;
if (im <= 1.5e+19) {
tmp = cos(re);
} else {
tmp = sqrt((pow(im, 12.0) * 1.9290123456790124e-6));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 1.5d+19) then
tmp = cos(re)
else
tmp = sqrt(((im ** 12.0d0) * 1.9290123456790124d-6))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.5e+19) {
tmp = Math.cos(re);
} else {
tmp = Math.sqrt((Math.pow(im, 12.0) * 1.9290123456790124e-6));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.5e+19: tmp = math.cos(re) else: tmp = math.sqrt((math.pow(im, 12.0) * 1.9290123456790124e-6)) return tmp
function code(re, im) tmp = 0.0 if (im <= 1.5e+19) tmp = cos(re); else tmp = sqrt(Float64((im ^ 12.0) * 1.9290123456790124e-6)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.5e+19) tmp = cos(re); else tmp = sqrt(((im ^ 12.0) * 1.9290123456790124e-6)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.5e+19], N[Cos[re], $MachinePrecision], N[Sqrt[N[(N[Power[im, 12.0], $MachinePrecision] * 1.9290123456790124e-6), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.5 \cdot 10^{+19}:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;\sqrt{{im}^{12} \cdot 1.9290123456790124 \cdot 10^{-6}}\\
\end{array}
\end{array}
if im < 1.5e19Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 63.6%
if 1.5e19 < im Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 89.7%
Taylor expanded in im around inf 89.7%
Taylor expanded in re around 0 71.4%
add-sqr-sqrt71.4%
sqrt-unprod74.8%
*-commutative74.8%
*-commutative74.8%
swap-sqr74.8%
pow-prod-up74.8%
metadata-eval74.8%
metadata-eval74.8%
Applied egg-rr74.8%
Final simplification66.0%
(FPCore (re im) :precision binary64 (if (<= im 2.1e+20) (cos re) (+ 1.0 (* 0.001388888888888889 (pow im 6.0)))))
double code(double re, double im) {
double tmp;
if (im <= 2.1e+20) {
tmp = cos(re);
} else {
tmp = 1.0 + (0.001388888888888889 * pow(im, 6.0));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 2.1d+20) then
tmp = cos(re)
else
tmp = 1.0d0 + (0.001388888888888889d0 * (im ** 6.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 2.1e+20) {
tmp = Math.cos(re);
} else {
tmp = 1.0 + (0.001388888888888889 * Math.pow(im, 6.0));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 2.1e+20: tmp = math.cos(re) else: tmp = 1.0 + (0.001388888888888889 * math.pow(im, 6.0)) return tmp
function code(re, im) tmp = 0.0 if (im <= 2.1e+20) tmp = cos(re); else tmp = Float64(1.0 + Float64(0.001388888888888889 * (im ^ 6.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 2.1e+20) tmp = cos(re); else tmp = 1.0 + (0.001388888888888889 * (im ^ 6.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 2.1e+20], N[Cos[re], $MachinePrecision], N[(1.0 + N[(0.001388888888888889 * N[Power[im, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 2.1 \cdot 10^{+20}:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;1 + 0.001388888888888889 \cdot {im}^{6}\\
\end{array}
\end{array}
if im < 2.1e20Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 63.6%
if 2.1e20 < im Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 89.7%
Taylor expanded in im around inf 89.7%
Taylor expanded in re around 0 71.4%
Final simplification65.3%
(FPCore (re im) :precision binary64 (if (<= im 1.3e+19) (cos re) (* 0.001388888888888889 (pow im 6.0))))
double code(double re, double im) {
double tmp;
if (im <= 1.3e+19) {
tmp = cos(re);
} else {
tmp = 0.001388888888888889 * pow(im, 6.0);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 1.3d+19) then
tmp = cos(re)
else
tmp = 0.001388888888888889d0 * (im ** 6.0d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.3e+19) {
tmp = Math.cos(re);
} else {
tmp = 0.001388888888888889 * Math.pow(im, 6.0);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.3e+19: tmp = math.cos(re) else: tmp = 0.001388888888888889 * math.pow(im, 6.0) return tmp
function code(re, im) tmp = 0.0 if (im <= 1.3e+19) tmp = cos(re); else tmp = Float64(0.001388888888888889 * (im ^ 6.0)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.3e+19) tmp = cos(re); else tmp = 0.001388888888888889 * (im ^ 6.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.3e+19], N[Cos[re], $MachinePrecision], N[(0.001388888888888889 * N[Power[im, 6.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.3 \cdot 10^{+19}:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;0.001388888888888889 \cdot {im}^{6}\\
\end{array}
\end{array}
if im < 1.3e19Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 63.6%
if 1.3e19 < im Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 89.7%
Taylor expanded in im around inf 89.7%
Taylor expanded in re around 0 71.4%
Final simplification65.3%
(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%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 50.6%
Final simplification50.6%
(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%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 91.1%
Applied egg-rr26.4%
*-inverses26.4%
Simplified26.4%
Final simplification26.4%
herbie shell --seed 2024077
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))