
(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 11 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 (* (* 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}
Initial program 100.0%
Final simplification100.0%
(FPCore (re im) :precision binary64 (if (or (<= im 640.0) (not (<= im 1.1e+141))) (* (* 0.5 (cos re)) (fma im im 2.0)) (+ 1.0 (log1p (expm1 (* (pow re 2.0) -0.5))))))
double code(double re, double im) {
double tmp;
if ((im <= 640.0) || !(im <= 1.1e+141)) {
tmp = (0.5 * cos(re)) * fma(im, im, 2.0);
} else {
tmp = 1.0 + log1p(expm1((pow(re, 2.0) * -0.5)));
}
return tmp;
}
function code(re, im) tmp = 0.0 if ((im <= 640.0) || !(im <= 1.1e+141)) tmp = Float64(Float64(0.5 * cos(re)) * fma(im, im, 2.0)); else tmp = Float64(1.0 + log1p(expm1(Float64((re ^ 2.0) * -0.5)))); end return tmp end
code[re_, im_] := If[Or[LessEqual[im, 640.0], N[Not[LessEqual[im, 1.1e+141]], $MachinePrecision]], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[Log[1 + N[(Exp[N[(N[Power[re, 2.0], $MachinePrecision] * -0.5), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 640 \lor \neg \left(im \leq 1.1 \cdot 10^{+141}\right):\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \mathsf{fma}\left(im, im, 2\right)\\
\mathbf{else}:\\
\;\;\;\;1 + \mathsf{log1p}\left(\mathsf{expm1}\left({re}^{2} \cdot -0.5\right)\right)\\
\end{array}
\end{array}
if im < 640 or 1.1e141 < im Initial program 100.0%
Taylor expanded in im around 0 88.0%
+-commutative88.0%
unpow288.0%
fma-define88.0%
Simplified88.0%
if 640 < im < 1.1e141Initial program 100.0%
Taylor expanded in im around 0 5.0%
+-commutative5.0%
unpow25.0%
fma-define5.0%
Simplified5.0%
Taylor expanded in re around 0 17.6%
associate-*r*17.6%
distribute-rgt-out17.6%
+-commutative17.6%
unpow217.6%
fma-undefine17.6%
+-commutative17.6%
Simplified17.6%
Taylor expanded in im around 0 8.3%
distribute-rgt-in8.3%
metadata-eval8.3%
*-commutative8.3%
associate-*l*8.3%
metadata-eval8.3%
Simplified8.3%
log1p-expm1-u25.1%
Applied egg-rr25.1%
Final simplification79.6%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (cos re))))
(if (<= im 2.3e-6)
(* t_0 (fma im im 2.0))
(if (<= im 1.35e+154)
(* (fma im im 2.0) (+ 0.5 (* (pow re 2.0) -0.25)))
(* t_0 (pow im 2.0))))))
double code(double re, double im) {
double t_0 = 0.5 * cos(re);
double tmp;
if (im <= 2.3e-6) {
tmp = t_0 * fma(im, im, 2.0);
} else if (im <= 1.35e+154) {
tmp = fma(im, im, 2.0) * (0.5 + (pow(re, 2.0) * -0.25));
} else {
tmp = t_0 * pow(im, 2.0);
}
return tmp;
}
function code(re, im) t_0 = Float64(0.5 * cos(re)) tmp = 0.0 if (im <= 2.3e-6) tmp = Float64(t_0 * fma(im, im, 2.0)); elseif (im <= 1.35e+154) tmp = Float64(fma(im, im, 2.0) * Float64(0.5 + Float64((re ^ 2.0) * -0.25))); else tmp = Float64(t_0 * (im ^ 2.0)); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, 2.3e-6], N[(t$95$0 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(N[(im * im + 2.0), $MachinePrecision] * N[(0.5 + N[(N[Power[re, 2.0], $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \cos re\\
\mathbf{if}\;im \leq 2.3 \cdot 10^{-6}:\\
\;\;\;\;t\_0 \cdot \mathsf{fma}\left(im, im, 2\right)\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\mathsf{fma}\left(im, im, 2\right) \cdot \left(0.5 + {re}^{2} \cdot -0.25\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot {im}^{2}\\
\end{array}
\end{array}
if im < 2.3e-6Initial program 100.0%
Taylor expanded in im around 0 87.2%
+-commutative87.2%
unpow287.2%
fma-define87.2%
Simplified87.2%
if 2.3e-6 < im < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in im around 0 9.6%
+-commutative9.6%
unpow29.6%
fma-define9.6%
Simplified9.6%
Taylor expanded in re around 0 20.3%
associate-*r*20.3%
distribute-rgt-out20.3%
+-commutative20.3%
unpow220.3%
fma-undefine20.3%
+-commutative20.3%
Simplified20.3%
if 1.35000000000000003e154 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
+-commutative100.0%
unpow2100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
Simplified100.0%
Final simplification78.6%
(FPCore (re im) :precision binary64 (if (or (<= im 6600000000.0) (not (<= im 8.5e+118))) (* (* 0.5 (cos re)) (fma im im 2.0)) (+ 1.0 (sqrt (* (pow re 4.0) 0.25)))))
double code(double re, double im) {
double tmp;
if ((im <= 6600000000.0) || !(im <= 8.5e+118)) {
tmp = (0.5 * cos(re)) * fma(im, im, 2.0);
} else {
tmp = 1.0 + sqrt((pow(re, 4.0) * 0.25));
}
return tmp;
}
function code(re, im) tmp = 0.0 if ((im <= 6600000000.0) || !(im <= 8.5e+118)) tmp = Float64(Float64(0.5 * cos(re)) * fma(im, im, 2.0)); else tmp = Float64(1.0 + sqrt(Float64((re ^ 4.0) * 0.25))); end return tmp end
code[re_, im_] := If[Or[LessEqual[im, 6600000000.0], N[Not[LessEqual[im, 8.5e+118]], $MachinePrecision]], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[Sqrt[N[(N[Power[re, 4.0], $MachinePrecision] * 0.25), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 6600000000 \lor \neg \left(im \leq 8.5 \cdot 10^{+118}\right):\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \mathsf{fma}\left(im, im, 2\right)\\
\mathbf{else}:\\
\;\;\;\;1 + \sqrt{{re}^{4} \cdot 0.25}\\
\end{array}
\end{array}
if im < 6.6e9 or 8.50000000000000033e118 < im Initial program 100.0%
Taylor expanded in im around 0 84.8%
+-commutative84.8%
unpow284.8%
fma-define84.8%
Simplified84.8%
if 6.6e9 < im < 8.50000000000000033e118Initial program 100.0%
Taylor expanded in im around 0 4.7%
+-commutative4.7%
unpow24.7%
fma-define4.7%
Simplified4.7%
Taylor expanded in re around 0 10.7%
associate-*r*10.7%
distribute-rgt-out10.7%
+-commutative10.7%
unpow210.7%
fma-undefine10.7%
+-commutative10.7%
Simplified10.7%
Taylor expanded in im around 0 6.2%
distribute-rgt-in6.2%
metadata-eval6.2%
*-commutative6.2%
associate-*l*6.2%
metadata-eval6.2%
Simplified6.2%
add-sqr-sqrt0.8%
sqrt-unprod29.8%
swap-sqr29.8%
pow-prod-up29.8%
metadata-eval29.8%
metadata-eval29.8%
Applied egg-rr29.8%
Final simplification79.4%
(FPCore (re im)
:precision binary64
(if (<= im 2.3e-6)
(cos re)
(if (<= im 3.8e+133)
(+ 1.0 (* (pow re 2.0) -0.5))
(* (* 0.5 (cos re)) (pow im 2.0)))))
double code(double re, double im) {
double tmp;
if (im <= 2.3e-6) {
tmp = cos(re);
} else if (im <= 3.8e+133) {
tmp = 1.0 + (pow(re, 2.0) * -0.5);
} else {
tmp = (0.5 * cos(re)) * pow(im, 2.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.3d-6) then
tmp = cos(re)
else if (im <= 3.8d+133) then
tmp = 1.0d0 + ((re ** 2.0d0) * (-0.5d0))
else
tmp = (0.5d0 * cos(re)) * (im ** 2.0d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 2.3e-6) {
tmp = Math.cos(re);
} else if (im <= 3.8e+133) {
tmp = 1.0 + (Math.pow(re, 2.0) * -0.5);
} else {
tmp = (0.5 * Math.cos(re)) * Math.pow(im, 2.0);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 2.3e-6: tmp = math.cos(re) elif im <= 3.8e+133: tmp = 1.0 + (math.pow(re, 2.0) * -0.5) else: tmp = (0.5 * math.cos(re)) * math.pow(im, 2.0) return tmp
function code(re, im) tmp = 0.0 if (im <= 2.3e-6) tmp = cos(re); elseif (im <= 3.8e+133) tmp = Float64(1.0 + Float64((re ^ 2.0) * -0.5)); else tmp = Float64(Float64(0.5 * cos(re)) * (im ^ 2.0)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 2.3e-6) tmp = cos(re); elseif (im <= 3.8e+133) tmp = 1.0 + ((re ^ 2.0) * -0.5); else tmp = (0.5 * cos(re)) * (im ^ 2.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 2.3e-6], N[Cos[re], $MachinePrecision], If[LessEqual[im, 3.8e+133], N[(1.0 + N[(N[Power[re, 2.0], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 2.3 \cdot 10^{-6}:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 3.8 \cdot 10^{+133}:\\
\;\;\;\;1 + {re}^{2} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot {im}^{2}\\
\end{array}
\end{array}
if im < 2.3e-6Initial program 100.0%
Taylor expanded in im around 0 87.2%
+-commutative87.2%
unpow287.2%
fma-define87.2%
Simplified87.2%
Taylor expanded in im around 0 73.1%
if 2.3e-6 < im < 3.8000000000000002e133Initial program 100.0%
Taylor expanded in im around 0 9.8%
+-commutative9.8%
unpow29.8%
fma-define9.8%
Simplified9.8%
Taylor expanded in re around 0 19.9%
associate-*r*19.9%
distribute-rgt-out19.9%
+-commutative19.9%
unpow219.9%
fma-undefine19.9%
+-commutative19.9%
Simplified19.9%
Taylor expanded in im around 0 12.0%
distribute-rgt-in12.0%
metadata-eval12.0%
*-commutative12.0%
associate-*l*12.0%
metadata-eval12.0%
Simplified12.0%
if 3.8000000000000002e133 < im Initial program 100.0%
Taylor expanded in im around 0 85.5%
+-commutative85.5%
unpow285.5%
fma-define85.5%
Simplified85.5%
Taylor expanded in im around inf 85.5%
*-commutative85.5%
associate-*l*85.5%
*-commutative85.5%
Simplified85.5%
Final simplification67.4%
(FPCore (re im)
:precision binary64
(if (<= im 1950000.0)
(cos re)
(if (<= im 5.2e+118)
(+ 1.0 (sqrt (* (pow re 4.0) 0.25)))
(* (* 0.5 (cos re)) (pow im 2.0)))))
double code(double re, double im) {
double tmp;
if (im <= 1950000.0) {
tmp = cos(re);
} else if (im <= 5.2e+118) {
tmp = 1.0 + sqrt((pow(re, 4.0) * 0.25));
} else {
tmp = (0.5 * cos(re)) * pow(im, 2.0);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 1950000.0d0) then
tmp = cos(re)
else if (im <= 5.2d+118) then
tmp = 1.0d0 + sqrt(((re ** 4.0d0) * 0.25d0))
else
tmp = (0.5d0 * cos(re)) * (im ** 2.0d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1950000.0) {
tmp = Math.cos(re);
} else if (im <= 5.2e+118) {
tmp = 1.0 + Math.sqrt((Math.pow(re, 4.0) * 0.25));
} else {
tmp = (0.5 * Math.cos(re)) * Math.pow(im, 2.0);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1950000.0: tmp = math.cos(re) elif im <= 5.2e+118: tmp = 1.0 + math.sqrt((math.pow(re, 4.0) * 0.25)) else: tmp = (0.5 * math.cos(re)) * math.pow(im, 2.0) return tmp
function code(re, im) tmp = 0.0 if (im <= 1950000.0) tmp = cos(re); elseif (im <= 5.2e+118) tmp = Float64(1.0 + sqrt(Float64((re ^ 4.0) * 0.25))); else tmp = Float64(Float64(0.5 * cos(re)) * (im ^ 2.0)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1950000.0) tmp = cos(re); elseif (im <= 5.2e+118) tmp = 1.0 + sqrt(((re ^ 4.0) * 0.25)); else tmp = (0.5 * cos(re)) * (im ^ 2.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1950000.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 5.2e+118], N[(1.0 + N[Sqrt[N[(N[Power[re, 4.0], $MachinePrecision] * 0.25), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1950000:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 5.2 \cdot 10^{+118}:\\
\;\;\;\;1 + \sqrt{{re}^{4} \cdot 0.25}\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot {im}^{2}\\
\end{array}
\end{array}
if im < 1.95e6Initial program 100.0%
Taylor expanded in im around 0 86.8%
+-commutative86.8%
unpow286.8%
fma-define86.8%
Simplified86.8%
Taylor expanded in im around 0 72.6%
if 1.95e6 < im < 5.20000000000000032e118Initial program 100.0%
Taylor expanded in im around 0 4.6%
+-commutative4.6%
unpow24.6%
fma-define4.6%
Simplified4.6%
Taylor expanded in re around 0 10.2%
associate-*r*10.2%
distribute-rgt-out10.2%
+-commutative10.2%
unpow210.2%
fma-undefine10.2%
+-commutative10.2%
Simplified10.2%
Taylor expanded in im around 0 6.0%
distribute-rgt-in6.0%
metadata-eval6.0%
*-commutative6.0%
associate-*l*6.0%
metadata-eval6.0%
Simplified6.0%
add-sqr-sqrt0.8%
sqrt-unprod27.8%
swap-sqr27.8%
pow-prod-up27.8%
metadata-eval27.8%
metadata-eval27.8%
Applied egg-rr27.8%
if 5.20000000000000032e118 < im Initial program 100.0%
Taylor expanded in im around 0 80.5%
+-commutative80.5%
unpow280.5%
fma-define80.5%
Simplified80.5%
Taylor expanded in im around inf 80.5%
*-commutative80.5%
associate-*l*80.5%
*-commutative80.5%
Simplified80.5%
Final simplification69.3%
(FPCore (re im)
:precision binary64
(if (<= im 2.3e-6)
(cos re)
(if (<= im 5.2e+140)
(+ 1.0 (* (pow re 2.0) -0.5))
(* 0.5 (fma im im 2.0)))))
double code(double re, double im) {
double tmp;
if (im <= 2.3e-6) {
tmp = cos(re);
} else if (im <= 5.2e+140) {
tmp = 1.0 + (pow(re, 2.0) * -0.5);
} else {
tmp = 0.5 * fma(im, im, 2.0);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 2.3e-6) tmp = cos(re); elseif (im <= 5.2e+140) tmp = Float64(1.0 + Float64((re ^ 2.0) * -0.5)); else tmp = Float64(0.5 * fma(im, im, 2.0)); end return tmp end
code[re_, im_] := If[LessEqual[im, 2.3e-6], N[Cos[re], $MachinePrecision], If[LessEqual[im, 5.2e+140], N[(1.0 + N[(N[Power[re, 2.0], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 2.3 \cdot 10^{-6}:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 5.2 \cdot 10^{+140}:\\
\;\;\;\;1 + {re}^{2} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{fma}\left(im, im, 2\right)\\
\end{array}
\end{array}
if im < 2.3e-6Initial program 100.0%
Taylor expanded in im around 0 87.2%
+-commutative87.2%
unpow287.2%
fma-define87.2%
Simplified87.2%
Taylor expanded in im around 0 73.1%
if 2.3e-6 < im < 5.2000000000000002e140Initial program 100.0%
Taylor expanded in im around 0 9.6%
+-commutative9.6%
unpow29.6%
fma-define9.6%
Simplified9.6%
Taylor expanded in re around 0 21.5%
associate-*r*21.5%
distribute-rgt-out21.5%
+-commutative21.5%
unpow221.5%
fma-undefine21.5%
+-commutative21.5%
Simplified21.5%
Taylor expanded in im around 0 11.3%
distribute-rgt-in11.3%
metadata-eval11.3%
*-commutative11.3%
associate-*l*11.3%
metadata-eval11.3%
Simplified11.3%
if 5.2000000000000002e140 < im Initial program 100.0%
Taylor expanded in im around 0 91.2%
+-commutative91.2%
unpow291.2%
fma-define91.2%
Simplified91.2%
Taylor expanded in re around 0 76.3%
+-commutative76.3%
unpow276.3%
fma-undefine76.3%
Simplified76.3%
Final simplification65.0%
(FPCore (re im) :precision binary64 (if (<= im 780.0) (cos re) (if (<= im 2.35e+138) (* (pow re 2.0) -0.5) (* 0.5 (fma im im 2.0)))))
double code(double re, double im) {
double tmp;
if (im <= 780.0) {
tmp = cos(re);
} else if (im <= 2.35e+138) {
tmp = pow(re, 2.0) * -0.5;
} else {
tmp = 0.5 * fma(im, im, 2.0);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 780.0) tmp = cos(re); elseif (im <= 2.35e+138) tmp = Float64((re ^ 2.0) * -0.5); else tmp = Float64(0.5 * fma(im, im, 2.0)); end return tmp end
code[re_, im_] := If[LessEqual[im, 780.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 2.35e+138], N[(N[Power[re, 2.0], $MachinePrecision] * -0.5), $MachinePrecision], N[(0.5 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 780:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 2.35 \cdot 10^{+138}:\\
\;\;\;\;{re}^{2} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{fma}\left(im, im, 2\right)\\
\end{array}
\end{array}
if im < 780Initial program 100.0%
Taylor expanded in im around 0 87.2%
+-commutative87.2%
unpow287.2%
fma-define87.2%
Simplified87.2%
Taylor expanded in im around 0 73.0%
if 780 < im < 2.3499999999999999e138Initial program 100.0%
Taylor expanded in im around 0 5.0%
+-commutative5.0%
unpow25.0%
fma-define5.0%
Simplified5.0%
Taylor expanded in re around 0 17.6%
associate-*r*17.6%
distribute-rgt-out17.6%
+-commutative17.6%
unpow217.6%
fma-undefine17.6%
+-commutative17.6%
Simplified17.6%
Taylor expanded in re around inf 15.9%
Taylor expanded in im around 0 7.5%
if 2.3499999999999999e138 < im Initial program 100.0%
Taylor expanded in im around 0 91.2%
+-commutative91.2%
unpow291.2%
fma-define91.2%
Simplified91.2%
Taylor expanded in re around 0 76.3%
+-commutative76.3%
unpow276.3%
fma-undefine76.3%
Simplified76.3%
Final simplification64.8%
(FPCore (re im) :precision binary64 (if (<= im 620.0) (cos re) (if (<= im 1.1e+141) (* (pow re 2.0) -0.5) (* 0.5 (pow im 2.0)))))
double code(double re, double im) {
double tmp;
if (im <= 620.0) {
tmp = cos(re);
} else if (im <= 1.1e+141) {
tmp = pow(re, 2.0) * -0.5;
} else {
tmp = 0.5 * pow(im, 2.0);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 620.0d0) then
tmp = cos(re)
else if (im <= 1.1d+141) then
tmp = (re ** 2.0d0) * (-0.5d0)
else
tmp = 0.5d0 * (im ** 2.0d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 620.0) {
tmp = Math.cos(re);
} else if (im <= 1.1e+141) {
tmp = Math.pow(re, 2.0) * -0.5;
} else {
tmp = 0.5 * Math.pow(im, 2.0);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 620.0: tmp = math.cos(re) elif im <= 1.1e+141: tmp = math.pow(re, 2.0) * -0.5 else: tmp = 0.5 * math.pow(im, 2.0) return tmp
function code(re, im) tmp = 0.0 if (im <= 620.0) tmp = cos(re); elseif (im <= 1.1e+141) tmp = Float64((re ^ 2.0) * -0.5); else tmp = Float64(0.5 * (im ^ 2.0)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 620.0) tmp = cos(re); elseif (im <= 1.1e+141) tmp = (re ^ 2.0) * -0.5; else tmp = 0.5 * (im ^ 2.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 620.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.1e+141], N[(N[Power[re, 2.0], $MachinePrecision] * -0.5), $MachinePrecision], N[(0.5 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 620:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.1 \cdot 10^{+141}:\\
\;\;\;\;{re}^{2} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {im}^{2}\\
\end{array}
\end{array}
if im < 620Initial program 100.0%
Taylor expanded in im around 0 87.2%
+-commutative87.2%
unpow287.2%
fma-define87.2%
Simplified87.2%
Taylor expanded in im around 0 73.0%
if 620 < im < 1.1e141Initial program 100.0%
Taylor expanded in im around 0 5.0%
+-commutative5.0%
unpow25.0%
fma-define5.0%
Simplified5.0%
Taylor expanded in re around 0 17.6%
associate-*r*17.6%
distribute-rgt-out17.6%
+-commutative17.6%
unpow217.6%
fma-undefine17.6%
+-commutative17.6%
Simplified17.6%
Taylor expanded in re around inf 15.9%
Taylor expanded in im around 0 7.5%
if 1.1e141 < im Initial program 100.0%
Taylor expanded in im around 0 91.2%
+-commutative91.2%
unpow291.2%
fma-define91.2%
Simplified91.2%
Taylor expanded in im around inf 91.2%
*-commutative91.2%
associate-*l*91.2%
*-commutative91.2%
Simplified91.2%
Taylor expanded in re around 0 76.3%
Final simplification64.8%
(FPCore (re im) :precision binary64 (if (<= im 700.0) (cos re) (* (pow re 2.0) -0.5)))
double code(double re, double im) {
double tmp;
if (im <= 700.0) {
tmp = cos(re);
} else {
tmp = pow(re, 2.0) * -0.5;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 700.0d0) then
tmp = cos(re)
else
tmp = (re ** 2.0d0) * (-0.5d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 700.0) {
tmp = Math.cos(re);
} else {
tmp = Math.pow(re, 2.0) * -0.5;
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 700.0: tmp = math.cos(re) else: tmp = math.pow(re, 2.0) * -0.5 return tmp
function code(re, im) tmp = 0.0 if (im <= 700.0) tmp = cos(re); else tmp = Float64((re ^ 2.0) * -0.5); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 700.0) tmp = cos(re); else tmp = (re ^ 2.0) * -0.5; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 700.0], N[Cos[re], $MachinePrecision], N[(N[Power[re, 2.0], $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 700:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;{re}^{2} \cdot -0.5\\
\end{array}
\end{array}
if im < 700Initial program 100.0%
Taylor expanded in im around 0 87.2%
+-commutative87.2%
unpow287.2%
fma-define87.2%
Simplified87.2%
Taylor expanded in im around 0 73.0%
if 700 < im Initial program 100.0%
Taylor expanded in im around 0 52.1%
+-commutative52.1%
unpow252.1%
fma-define52.1%
Simplified52.1%
Taylor expanded in re around 0 8.5%
associate-*r*8.5%
distribute-rgt-out37.8%
+-commutative37.8%
unpow237.8%
fma-undefine37.8%
+-commutative37.8%
Simplified37.8%
Taylor expanded in re around inf 15.4%
Taylor expanded in im around 0 5.5%
Final simplification53.2%
(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%
Taylor expanded in im around 0 77.0%
+-commutative77.0%
unpow277.0%
fma-define77.0%
Simplified77.0%
Taylor expanded in im around 0 52.5%
Final simplification52.5%
herbie shell --seed 2024044
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))