
(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 (<= im 1.12e-7)
(cos re)
(if (<= im 6e+151)
(* (fma im im 2.0) (+ 0.5 (* -0.25 (pow re 2.0))))
(* (* 0.5 (cos re)) (pow im 2.0)))))
double code(double re, double im) {
double tmp;
if (im <= 1.12e-7) {
tmp = cos(re);
} else if (im <= 6e+151) {
tmp = fma(im, im, 2.0) * (0.5 + (-0.25 * pow(re, 2.0)));
} else {
tmp = (0.5 * cos(re)) * pow(im, 2.0);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 1.12e-7) tmp = cos(re); elseif (im <= 6e+151) tmp = Float64(fma(im, im, 2.0) * Float64(0.5 + Float64(-0.25 * (re ^ 2.0)))); else tmp = Float64(Float64(0.5 * cos(re)) * (im ^ 2.0)); end return tmp end
code[re_, im_] := If[LessEqual[im, 1.12e-7], N[Cos[re], $MachinePrecision], If[LessEqual[im, 6e+151], N[(N[(im * im + 2.0), $MachinePrecision] * N[(0.5 + N[(-0.25 * N[Power[re, 2.0], $MachinePrecision]), $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 1.12 \cdot 10^{-7}:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 6 \cdot 10^{+151}:\\
\;\;\;\;\mathsf{fma}\left(im, im, 2\right) \cdot \left(0.5 + -0.25 \cdot {re}^{2}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot {im}^{2}\\
\end{array}
\end{array}
if im < 1.12e-7Initial program 100.0%
Taylor expanded in im around 0 85.2%
+-commutative85.2%
unpow285.2%
fma-def85.2%
Simplified85.2%
Taylor expanded in im around 0 67.6%
if 1.12e-7 < im < 5.9999999999999998e151Initial program 99.8%
Taylor expanded in im around 0 17.8%
+-commutative17.8%
unpow217.8%
fma-def17.8%
Simplified17.8%
Taylor expanded in re around 0 31.1%
associate-*r*31.1%
distribute-rgt-out31.1%
+-commutative31.1%
unpow231.1%
fma-udef31.1%
+-commutative31.1%
Simplified31.1%
if 5.9999999999999998e151 < im Initial program 100.0%
Taylor expanded in im around 0 97.8%
+-commutative97.8%
unpow297.8%
fma-def97.8%
Simplified97.8%
Taylor expanded in im around inf 97.8%
*-commutative97.8%
associate-*l*97.8%
*-commutative97.8%
Simplified97.8%
Final simplification69.6%
(FPCore (re im)
:precision binary64
(if (<= im 1.12e-7)
(cos re)
(if (<= im 1.02e+142)
(+ 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 <= 1.12e-7) {
tmp = cos(re);
} else if (im <= 1.02e+142) {
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 <= 1.12d-7) then
tmp = cos(re)
else if (im <= 1.02d+142) 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 <= 1.12e-7) {
tmp = Math.cos(re);
} else if (im <= 1.02e+142) {
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 <= 1.12e-7: tmp = math.cos(re) elif im <= 1.02e+142: 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 <= 1.12e-7) tmp = cos(re); elseif (im <= 1.02e+142) 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 <= 1.12e-7) tmp = cos(re); elseif (im <= 1.02e+142) 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, 1.12e-7], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.02e+142], 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 1.12 \cdot 10^{-7}:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.02 \cdot 10^{+142}:\\
\;\;\;\;1 + {re}^{2} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot {im}^{2}\\
\end{array}
\end{array}
if im < 1.12e-7Initial program 100.0%
Taylor expanded in im around 0 85.2%
+-commutative85.2%
unpow285.2%
fma-def85.2%
Simplified85.2%
Taylor expanded in im around 0 67.6%
if 1.12e-7 < im < 1.0199999999999999e142Initial program 99.8%
Taylor expanded in im around 0 18.2%
+-commutative18.2%
unpow218.2%
fma-def18.2%
Simplified18.2%
Taylor expanded in re around 0 32.8%
associate-*r*32.8%
distribute-rgt-out32.8%
+-commutative32.8%
unpow232.8%
fma-udef32.8%
+-commutative32.8%
Simplified32.8%
Taylor expanded in im around 0 18.8%
distribute-rgt-in18.8%
metadata-eval18.8%
*-commutative18.8%
associate-*l*18.8%
metadata-eval18.8%
Simplified18.8%
if 1.0199999999999999e142 < im Initial program 100.0%
Taylor expanded in im around 0 95.7%
+-commutative95.7%
unpow295.7%
fma-def95.7%
Simplified95.7%
Taylor expanded in im around inf 95.7%
*-commutative95.7%
associate-*l*95.7%
*-commutative95.7%
Simplified95.7%
Final simplification68.6%
(FPCore (re im)
:precision binary64
(if (<= im 1.12e-7)
(cos re)
(if (<= im 1.12e+142)
(+ 1.0 (* (pow re 2.0) -0.5))
(pow (* im (sqrt 0.5)) 2.0))))
double code(double re, double im) {
double tmp;
if (im <= 1.12e-7) {
tmp = cos(re);
} else if (im <= 1.12e+142) {
tmp = 1.0 + (pow(re, 2.0) * -0.5);
} else {
tmp = pow((im * sqrt(0.5)), 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 <= 1.12d-7) then
tmp = cos(re)
else if (im <= 1.12d+142) then
tmp = 1.0d0 + ((re ** 2.0d0) * (-0.5d0))
else
tmp = (im * sqrt(0.5d0)) ** 2.0d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.12e-7) {
tmp = Math.cos(re);
} else if (im <= 1.12e+142) {
tmp = 1.0 + (Math.pow(re, 2.0) * -0.5);
} else {
tmp = Math.pow((im * Math.sqrt(0.5)), 2.0);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.12e-7: tmp = math.cos(re) elif im <= 1.12e+142: tmp = 1.0 + (math.pow(re, 2.0) * -0.5) else: tmp = math.pow((im * math.sqrt(0.5)), 2.0) return tmp
function code(re, im) tmp = 0.0 if (im <= 1.12e-7) tmp = cos(re); elseif (im <= 1.12e+142) tmp = Float64(1.0 + Float64((re ^ 2.0) * -0.5)); else tmp = Float64(im * sqrt(0.5)) ^ 2.0; end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.12e-7) tmp = cos(re); elseif (im <= 1.12e+142) tmp = 1.0 + ((re ^ 2.0) * -0.5); else tmp = (im * sqrt(0.5)) ^ 2.0; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.12e-7], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.12e+142], N[(1.0 + N[(N[Power[re, 2.0], $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision], N[Power[N[(im * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.12 \cdot 10^{-7}:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.12 \cdot 10^{+142}:\\
\;\;\;\;1 + {re}^{2} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;{\left(im \cdot \sqrt{0.5}\right)}^{2}\\
\end{array}
\end{array}
if im < 1.12e-7Initial program 100.0%
Taylor expanded in im around 0 85.2%
+-commutative85.2%
unpow285.2%
fma-def85.2%
Simplified85.2%
Taylor expanded in im around 0 67.6%
if 1.12e-7 < im < 1.11999999999999996e142Initial program 99.8%
Taylor expanded in im around 0 18.2%
+-commutative18.2%
unpow218.2%
fma-def18.2%
Simplified18.2%
Taylor expanded in re around 0 32.8%
associate-*r*32.8%
distribute-rgt-out32.8%
+-commutative32.8%
unpow232.8%
fma-udef32.8%
+-commutative32.8%
Simplified32.8%
Taylor expanded in im around 0 18.8%
distribute-rgt-in18.8%
metadata-eval18.8%
*-commutative18.8%
associate-*l*18.8%
metadata-eval18.8%
Simplified18.8%
if 1.11999999999999996e142 < im Initial program 100.0%
Taylor expanded in im around 0 95.7%
+-commutative95.7%
unpow295.7%
fma-def95.7%
Simplified95.7%
Taylor expanded in im around inf 95.7%
*-commutative95.7%
associate-*l*95.7%
*-commutative95.7%
Simplified95.7%
add-sqr-sqrt73.7%
pow273.7%
sqrt-prod73.7%
unpow273.7%
sqrt-prod73.7%
add-sqr-sqrt73.7%
Applied egg-rr73.7%
Taylor expanded in re around 0 73.7%
Final simplification65.1%
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (fma im im 2.0)))
double code(double re, double im) {
return (0.5 * cos(re)) * fma(im, im, 2.0);
}
function code(re, im) return Float64(Float64(0.5 * cos(re)) * fma(im, im, 2.0)) end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \mathsf{fma}\left(im, im, 2\right)
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 82.2%
+-commutative82.2%
unpow282.2%
fma-def82.2%
Simplified82.2%
Final simplification82.2%
(FPCore (re im)
:precision binary64
(if (<= im 1.12e-7)
(cos re)
(if (<= im 1.12e+142)
(+ 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 <= 1.12e-7) {
tmp = cos(re);
} else if (im <= 1.12e+142) {
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 <= 1.12e-7) tmp = cos(re); elseif (im <= 1.12e+142) 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, 1.12e-7], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.12e+142], 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 1.12 \cdot 10^{-7}:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.12 \cdot 10^{+142}:\\
\;\;\;\;1 + {re}^{2} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{fma}\left(im, im, 2\right)\\
\end{array}
\end{array}
if im < 1.12e-7Initial program 100.0%
Taylor expanded in im around 0 85.2%
+-commutative85.2%
unpow285.2%
fma-def85.2%
Simplified85.2%
Taylor expanded in im around 0 67.6%
if 1.12e-7 < im < 1.11999999999999996e142Initial program 99.8%
Taylor expanded in im around 0 18.2%
+-commutative18.2%
unpow218.2%
fma-def18.2%
Simplified18.2%
Taylor expanded in re around 0 32.8%
associate-*r*32.8%
distribute-rgt-out32.8%
+-commutative32.8%
unpow232.8%
fma-udef32.8%
+-commutative32.8%
Simplified32.8%
Taylor expanded in im around 0 18.8%
distribute-rgt-in18.8%
metadata-eval18.8%
*-commutative18.8%
associate-*l*18.8%
metadata-eval18.8%
Simplified18.8%
if 1.11999999999999996e142 < im Initial program 100.0%
Taylor expanded in im around 0 95.7%
+-commutative95.7%
unpow295.7%
fma-def95.7%
Simplified95.7%
Taylor expanded in re around 0 73.7%
+-commutative73.7%
unpow273.7%
fma-udef73.7%
Simplified73.7%
Final simplification65.1%
(FPCore (re im) :precision binary64 (if (<= im 680.0) (cos re) (if (<= im 1.1e+142) (* (pow re 2.0) -0.5) (* 0.5 (pow im 2.0)))))
double code(double re, double im) {
double tmp;
if (im <= 680.0) {
tmp = cos(re);
} else if (im <= 1.1e+142) {
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 <= 680.0d0) then
tmp = cos(re)
else if (im <= 1.1d+142) 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 <= 680.0) {
tmp = Math.cos(re);
} else if (im <= 1.1e+142) {
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 <= 680.0: tmp = math.cos(re) elif im <= 1.1e+142: 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 <= 680.0) tmp = cos(re); elseif (im <= 1.1e+142) 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 <= 680.0) tmp = cos(re); elseif (im <= 1.1e+142) tmp = (re ^ 2.0) * -0.5; else tmp = 0.5 * (im ^ 2.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 680.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.1e+142], 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 680:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.1 \cdot 10^{+142}:\\
\;\;\;\;{re}^{2} \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {im}^{2}\\
\end{array}
\end{array}
if im < 680Initial program 100.0%
Taylor expanded in im around 0 84.7%
+-commutative84.7%
unpow284.7%
fma-def84.7%
Simplified84.7%
Taylor expanded in im around 0 67.2%
if 680 < im < 1.09999999999999993e142Initial program 100.0%
Taylor expanded in im around 0 5.3%
+-commutative5.3%
unpow25.3%
fma-def5.3%
Simplified5.3%
Taylor expanded in re around 0 24.0%
associate-*r*24.0%
distribute-rgt-out24.0%
+-commutative24.0%
unpow224.0%
fma-udef24.0%
+-commutative24.0%
Simplified24.0%
Taylor expanded in re around inf 22.5%
associate-*r*22.5%
+-commutative22.5%
unpow222.5%
fma-udef22.5%
*-commutative22.5%
associate-*r*22.5%
Simplified22.5%
Taylor expanded in im around 0 8.9%
*-commutative8.9%
Simplified8.9%
if 1.09999999999999993e142 < im Initial program 100.0%
Taylor expanded in im around 0 95.7%
+-commutative95.7%
unpow295.7%
fma-def95.7%
Simplified95.7%
Taylor expanded in re around 0 73.7%
+-commutative73.7%
unpow273.7%
fma-udef73.7%
Simplified73.7%
Taylor expanded in im around inf 73.7%
Final simplification65.1%
(FPCore (re im) :precision binary64 (if (<= im 1.12e-7) (cos re) (* 0.5 (fma im im 2.0))))
double code(double re, double im) {
double tmp;
if (im <= 1.12e-7) {
tmp = cos(re);
} else {
tmp = 0.5 * fma(im, im, 2.0);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 1.12e-7) tmp = cos(re); else tmp = Float64(0.5 * fma(im, im, 2.0)); end return tmp end
code[re_, im_] := If[LessEqual[im, 1.12e-7], N[Cos[re], $MachinePrecision], N[(0.5 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.12 \cdot 10^{-7}:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{fma}\left(im, im, 2\right)\\
\end{array}
\end{array}
if im < 1.12e-7Initial program 100.0%
Taylor expanded in im around 0 85.2%
+-commutative85.2%
unpow285.2%
fma-def85.2%
Simplified85.2%
Taylor expanded in im around 0 67.6%
if 1.12e-7 < im Initial program 99.9%
Taylor expanded in im around 0 72.0%
+-commutative72.0%
unpow272.0%
fma-def72.0%
Simplified72.0%
Taylor expanded in re around 0 56.4%
+-commutative56.4%
unpow256.4%
fma-udef56.4%
Simplified56.4%
Final simplification65.0%
(FPCore (re im) :precision binary64 (if (<= im 1.22e+85) (cos re) (* 0.5 (pow im 2.0))))
double code(double re, double im) {
double tmp;
if (im <= 1.22e+85) {
tmp = cos(re);
} 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 <= 1.22d+85) then
tmp = cos(re)
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 <= 1.22e+85) {
tmp = Math.cos(re);
} else {
tmp = 0.5 * Math.pow(im, 2.0);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.22e+85: tmp = math.cos(re) else: tmp = 0.5 * math.pow(im, 2.0) return tmp
function code(re, im) tmp = 0.0 if (im <= 1.22e+85) tmp = cos(re); else tmp = Float64(0.5 * (im ^ 2.0)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.22e+85) tmp = cos(re); else tmp = 0.5 * (im ^ 2.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.22e+85], N[Cos[re], $MachinePrecision], N[(0.5 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.22 \cdot 10^{+85}:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {im}^{2}\\
\end{array}
\end{array}
if im < 1.22e85Initial program 100.0%
Taylor expanded in im around 0 82.4%
+-commutative82.4%
unpow282.4%
fma-def82.4%
Simplified82.4%
Taylor expanded in im around 0 65.4%
if 1.22e85 < im Initial program 100.0%
Taylor expanded in im around 0 81.1%
+-commutative81.1%
unpow281.1%
fma-def81.1%
Simplified81.1%
Taylor expanded in re around 0 62.4%
+-commutative62.4%
unpow262.4%
fma-udef62.4%
Simplified62.4%
Taylor expanded in im around inf 62.4%
Final simplification64.8%
(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 82.2%
+-commutative82.2%
unpow282.2%
fma-def82.2%
Simplified82.2%
Taylor expanded in im around 0 53.4%
Final simplification53.4%
(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 im around 0 82.2%
+-commutative82.2%
unpow282.2%
fma-def82.2%
Simplified82.2%
Taylor expanded in re around 0 49.4%
+-commutative49.4%
unpow249.4%
fma-udef49.4%
Simplified49.4%
Taylor expanded in im around 0 28.1%
Final simplification28.1%
herbie shell --seed 2023334
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))