
(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}
NOTE: im should be positive before calling this function (FPCore (re im) :precision binary64 (* (cos re) (fma 0.5 (exp im) (/ 0.5 (exp im)))))
im = abs(im);
double code(double re, double im) {
return cos(re) * fma(0.5, exp(im), (0.5 / exp(im)));
}
im = abs(im) function code(re, im) return Float64(cos(re) * fma(0.5, exp(im), Float64(0.5 / exp(im)))) end
NOTE: im should be positive before calling this function 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}
im = |im|\\
\\
\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%
NOTE: im should be positive before calling this function (FPCore (re im) :precision binary64 (* (* (cos re) 0.5) (+ (exp im) (exp (- im)))))
im = abs(im);
double code(double re, double im) {
return (cos(re) * 0.5) * (exp(im) + exp(-im));
}
NOTE: im should be positive before calling this function
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
im = Math.abs(im);
public static double code(double re, double im) {
return (Math.cos(re) * 0.5) * (Math.exp(im) + Math.exp(-im));
}
im = abs(im) def code(re, im): return (math.cos(re) * 0.5) * (math.exp(im) + math.exp(-im))
im = abs(im) function code(re, im) return Float64(Float64(cos(re) * 0.5) * Float64(exp(im) + exp(Float64(-im)))) end
im = abs(im) function tmp = code(re, im) tmp = (cos(re) * 0.5) * (exp(im) + exp(-im)); end
NOTE: im should be positive before calling this function 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}
im = |im|\\
\\
\left(\cos re \cdot 0.5\right) \cdot \left(e^{im} + e^{-im}\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
NOTE: im should be positive before calling this function
(FPCore (re im)
:precision binary64
(if (<= im 900.0)
(* (* (cos re) 0.5) (+ 2.0 (* im im)))
(if (<= im 7.5e+76)
(* 0.5 (log1p (expm1 (* im im))))
(* 0.041666666666666664 (* (cos re) (pow im 4.0))))))im = abs(im);
double code(double re, double im) {
double tmp;
if (im <= 900.0) {
tmp = (cos(re) * 0.5) * (2.0 + (im * im));
} else if (im <= 7.5e+76) {
tmp = 0.5 * log1p(expm1((im * im)));
} else {
tmp = 0.041666666666666664 * (cos(re) * pow(im, 4.0));
}
return tmp;
}
im = Math.abs(im);
public static double code(double re, double im) {
double tmp;
if (im <= 900.0) {
tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
} else if (im <= 7.5e+76) {
tmp = 0.5 * Math.log1p(Math.expm1((im * im)));
} else {
tmp = 0.041666666666666664 * (Math.cos(re) * Math.pow(im, 4.0));
}
return tmp;
}
im = abs(im) def code(re, im): tmp = 0 if im <= 900.0: tmp = (math.cos(re) * 0.5) * (2.0 + (im * im)) elif im <= 7.5e+76: tmp = 0.5 * math.log1p(math.expm1((im * im))) else: tmp = 0.041666666666666664 * (math.cos(re) * math.pow(im, 4.0)) return tmp
im = abs(im) function code(re, im) tmp = 0.0 if (im <= 900.0) tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im))); elseif (im <= 7.5e+76) tmp = Float64(0.5 * log1p(expm1(Float64(im * im)))); else tmp = Float64(0.041666666666666664 * Float64(cos(re) * (im ^ 4.0))); end return tmp end
NOTE: im should be positive before calling this function code[re_, im_] := If[LessEqual[im, 900.0], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 7.5e+76], N[(0.5 * N[Log[1 + N[(Exp[N[(im * im), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.041666666666666664 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;im \leq 900:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\
\mathbf{elif}\;im \leq 7.5 \cdot 10^{+76}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot im\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\
\end{array}
\end{array}
if im < 900Initial program 100.0%
Taylor expanded in im around 0 85.0%
unpow285.0%
Simplified85.0%
if 900 < im < 7.4999999999999995e76Initial program 100.0%
Taylor expanded in im around 0 3.9%
unpow23.9%
Simplified3.9%
Taylor expanded in im around inf 3.9%
unpow23.9%
associate-*r*3.9%
*-commutative3.9%
associate-*l*3.9%
Simplified3.9%
Taylor expanded in re around 0 3.3%
pow23.3%
log1p-expm1-u84.2%
Applied egg-rr84.2%
if 7.4999999999999995e76 < im Initial program 100.0%
Taylor expanded in im around 0 98.2%
unpow298.2%
*-commutative98.2%
Simplified98.2%
Taylor expanded in im around inf 98.2%
Final simplification87.4%
NOTE: im should be positive before calling this function (FPCore (re im) :precision binary64 (if (or (<= im 900.0) (not (<= im 2.6e+151))) (* (* (cos re) 0.5) (+ 2.0 (* im im))) (* 0.5 (log1p (expm1 (* im im))))))
im = abs(im);
double code(double re, double im) {
double tmp;
if ((im <= 900.0) || !(im <= 2.6e+151)) {
tmp = (cos(re) * 0.5) * (2.0 + (im * im));
} else {
tmp = 0.5 * log1p(expm1((im * im)));
}
return tmp;
}
im = Math.abs(im);
public static double code(double re, double im) {
double tmp;
if ((im <= 900.0) || !(im <= 2.6e+151)) {
tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
} else {
tmp = 0.5 * Math.log1p(Math.expm1((im * im)));
}
return tmp;
}
im = abs(im) def code(re, im): tmp = 0 if (im <= 900.0) or not (im <= 2.6e+151): tmp = (math.cos(re) * 0.5) * (2.0 + (im * im)) else: tmp = 0.5 * math.log1p(math.expm1((im * im))) return tmp
im = abs(im) function code(re, im) tmp = 0.0 if ((im <= 900.0) || !(im <= 2.6e+151)) tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im))); else tmp = Float64(0.5 * log1p(expm1(Float64(im * im)))); end return tmp end
NOTE: im should be positive before calling this function code[re_, im_] := If[Or[LessEqual[im, 900.0], N[Not[LessEqual[im, 2.6e+151]], $MachinePrecision]], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Log[1 + N[(Exp[N[(im * im), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;im \leq 900 \lor \neg \left(im \leq 2.6 \cdot 10^{+151}\right):\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(im \cdot im\right)\right)\\
\end{array}
\end{array}
if im < 900 or 2.60000000000000013e151 < im Initial program 100.0%
Taylor expanded in im around 0 86.7%
unpow286.7%
Simplified86.7%
if 900 < im < 2.60000000000000013e151Initial program 100.0%
Taylor expanded in im around 0 4.9%
unpow24.9%
Simplified4.9%
Taylor expanded in im around inf 4.9%
unpow24.9%
associate-*r*4.9%
*-commutative4.9%
associate-*l*4.9%
Simplified4.9%
Taylor expanded in re around 0 3.6%
pow23.6%
log1p-expm1-u74.3%
Applied egg-rr74.3%
Final simplification85.0%
NOTE: im should be positive before calling this function (FPCore (re im) :precision binary64 (if (or (<= im 8.2e+42) (not (<= im 2.6e+151))) (* (* (cos re) 0.5) (+ 2.0 (* im im))) (* 0.5 (cbrt (pow im 6.0)))))
im = abs(im);
double code(double re, double im) {
double tmp;
if ((im <= 8.2e+42) || !(im <= 2.6e+151)) {
tmp = (cos(re) * 0.5) * (2.0 + (im * im));
} else {
tmp = 0.5 * cbrt(pow(im, 6.0));
}
return tmp;
}
im = Math.abs(im);
public static double code(double re, double im) {
double tmp;
if ((im <= 8.2e+42) || !(im <= 2.6e+151)) {
tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
} else {
tmp = 0.5 * Math.cbrt(Math.pow(im, 6.0));
}
return tmp;
}
im = abs(im) function code(re, im) tmp = 0.0 if ((im <= 8.2e+42) || !(im <= 2.6e+151)) tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im))); else tmp = Float64(0.5 * cbrt((im ^ 6.0))); end return tmp end
NOTE: im should be positive before calling this function code[re_, im_] := If[Or[LessEqual[im, 8.2e+42], N[Not[LessEqual[im, 2.6e+151]], $MachinePrecision]], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Power[N[Power[im, 6.0], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;im \leq 8.2 \cdot 10^{+42} \lor \neg \left(im \leq 2.6 \cdot 10^{+151}\right):\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt[3]{{im}^{6}}\\
\end{array}
\end{array}
if im < 8.2000000000000001e42 or 2.60000000000000013e151 < im Initial program 100.0%
Taylor expanded in im around 0 82.8%
unpow282.8%
Simplified82.8%
if 8.2000000000000001e42 < im < 2.60000000000000013e151Initial program 100.0%
Taylor expanded in im around 0 5.6%
unpow25.6%
Simplified5.6%
Taylor expanded in im around inf 5.6%
unpow25.6%
associate-*r*5.6%
*-commutative5.6%
associate-*l*5.6%
Simplified5.6%
Taylor expanded in re around 0 3.9%
add-cbrt-cube62.8%
pow262.8%
pow262.8%
pow262.8%
pow362.8%
pow262.8%
pow-pow62.8%
metadata-eval62.8%
Applied egg-rr62.8%
Final simplification80.9%
NOTE: im should be positive before calling this function (FPCore (re im) :precision binary64 (* (cos re) (+ 0.5 (* 0.5 (exp im)))))
im = abs(im);
double code(double re, double im) {
return cos(re) * (0.5 + (0.5 * exp(im)));
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = cos(re) * (0.5d0 + (0.5d0 * exp(im)))
end function
im = Math.abs(im);
public static double code(double re, double im) {
return Math.cos(re) * (0.5 + (0.5 * Math.exp(im)));
}
im = abs(im) def code(re, im): return math.cos(re) * (0.5 + (0.5 * math.exp(im)))
im = abs(im) function code(re, im) return Float64(cos(re) * Float64(0.5 + Float64(0.5 * exp(im)))) end
im = abs(im) function tmp = code(re, im) tmp = cos(re) * (0.5 + (0.5 * exp(im))); end
NOTE: im should be positive before calling this function code[re_, im_] := N[(N[Cos[re], $MachinePrecision] * N[(0.5 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im = |im|\\
\\
\cos re \cdot \left(0.5 + 0.5 \cdot 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%
Taylor expanded in im around 0 78.6%
fma-udef78.6%
Applied egg-rr78.6%
Final simplification78.6%
NOTE: im should be positive before calling this function
(FPCore (re im)
:precision binary64
(if (<= im 350.0)
(cos re)
(if (<= im 1.35e+154)
(* (* im im) (+ 0.5 (* (* re re) -0.25)))
(* (cos re) (* 0.5 (* im im))))))im = abs(im);
double code(double re, double im) {
double tmp;
if (im <= 350.0) {
tmp = cos(re);
} else if (im <= 1.35e+154) {
tmp = (im * im) * (0.5 + ((re * re) * -0.25));
} else {
tmp = cos(re) * (0.5 * (im * im));
}
return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 350.0d0) then
tmp = cos(re)
else if (im <= 1.35d+154) then
tmp = (im * im) * (0.5d0 + ((re * re) * (-0.25d0)))
else
tmp = cos(re) * (0.5d0 * (im * im))
end if
code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
double tmp;
if (im <= 350.0) {
tmp = Math.cos(re);
} else if (im <= 1.35e+154) {
tmp = (im * im) * (0.5 + ((re * re) * -0.25));
} else {
tmp = Math.cos(re) * (0.5 * (im * im));
}
return tmp;
}
im = abs(im) def code(re, im): tmp = 0 if im <= 350.0: tmp = math.cos(re) elif im <= 1.35e+154: tmp = (im * im) * (0.5 + ((re * re) * -0.25)) else: tmp = math.cos(re) * (0.5 * (im * im)) return tmp
im = abs(im) function code(re, im) tmp = 0.0 if (im <= 350.0) tmp = cos(re); elseif (im <= 1.35e+154) tmp = Float64(Float64(im * im) * Float64(0.5 + Float64(Float64(re * re) * -0.25))); else tmp = Float64(cos(re) * Float64(0.5 * Float64(im * im))); end return tmp end
im = abs(im) function tmp_2 = code(re, im) tmp = 0.0; if (im <= 350.0) tmp = cos(re); elseif (im <= 1.35e+154) tmp = (im * im) * (0.5 + ((re * re) * -0.25)); else tmp = cos(re) * (0.5 * (im * im)); end tmp_2 = tmp; end
NOTE: im should be positive before calling this function code[re_, im_] := If[LessEqual[im, 350.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(N[(im * im), $MachinePrecision] * N[(0.5 + N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;im \leq 350:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\
\end{array}
\end{array}
if im < 350Initial 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 71.0%
Taylor expanded in im around 0 71.7%
if 350 < im < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in im around 0 5.1%
unpow25.1%
Simplified5.1%
Taylor expanded in im around inf 5.1%
unpow25.1%
associate-*r*5.1%
*-commutative5.1%
associate-*l*5.1%
Simplified5.1%
Taylor expanded in re around 0 24.8%
associate-*r*24.8%
distribute-rgt-out24.8%
unpow224.8%
+-commutative24.8%
*-commutative24.8%
unpow224.8%
Simplified24.8%
if 1.35000000000000003e154 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
unpow2100.0%
associate-*r*100.0%
*-commutative100.0%
associate-*l*100.0%
Simplified100.0%
Final simplification68.3%
NOTE: im should be positive before calling this function
(FPCore (re im)
:precision binary64
(if (<= im 390.0)
(* (* (cos re) 0.5) (+ 2.0 (* im im)))
(if (<= im 1.35e+154)
(* (* im im) (+ 0.5 (* (* re re) -0.25)))
(* (cos re) (* 0.5 (* im im))))))im = abs(im);
double code(double re, double im) {
double tmp;
if (im <= 390.0) {
tmp = (cos(re) * 0.5) * (2.0 + (im * im));
} else if (im <= 1.35e+154) {
tmp = (im * im) * (0.5 + ((re * re) * -0.25));
} else {
tmp = cos(re) * (0.5 * (im * im));
}
return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 390.0d0) then
tmp = (cos(re) * 0.5d0) * (2.0d0 + (im * im))
else if (im <= 1.35d+154) then
tmp = (im * im) * (0.5d0 + ((re * re) * (-0.25d0)))
else
tmp = cos(re) * (0.5d0 * (im * im))
end if
code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
double tmp;
if (im <= 390.0) {
tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
} else if (im <= 1.35e+154) {
tmp = (im * im) * (0.5 + ((re * re) * -0.25));
} else {
tmp = Math.cos(re) * (0.5 * (im * im));
}
return tmp;
}
im = abs(im) def code(re, im): tmp = 0 if im <= 390.0: tmp = (math.cos(re) * 0.5) * (2.0 + (im * im)) elif im <= 1.35e+154: tmp = (im * im) * (0.5 + ((re * re) * -0.25)) else: tmp = math.cos(re) * (0.5 * (im * im)) return tmp
im = abs(im) function code(re, im) tmp = 0.0 if (im <= 390.0) tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im))); elseif (im <= 1.35e+154) tmp = Float64(Float64(im * im) * Float64(0.5 + Float64(Float64(re * re) * -0.25))); else tmp = Float64(cos(re) * Float64(0.5 * Float64(im * im))); end return tmp end
im = abs(im) function tmp_2 = code(re, im) tmp = 0.0; if (im <= 390.0) tmp = (cos(re) * 0.5) * (2.0 + (im * im)); elseif (im <= 1.35e+154) tmp = (im * im) * (0.5 + ((re * re) * -0.25)); else tmp = cos(re) * (0.5 * (im * im)); end tmp_2 = tmp; end
NOTE: im should be positive before calling this function code[re_, im_] := If[LessEqual[im, 390.0], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(N[(im * im), $MachinePrecision] * N[(0.5 + N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;im \leq 390:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\
\end{array}
\end{array}
if im < 390Initial program 100.0%
Taylor expanded in im around 0 85.5%
unpow285.5%
Simplified85.5%
if 390 < im < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in im around 0 5.1%
unpow25.1%
Simplified5.1%
Taylor expanded in im around inf 5.1%
unpow25.1%
associate-*r*5.1%
*-commutative5.1%
associate-*l*5.1%
Simplified5.1%
Taylor expanded in re around 0 24.8%
associate-*r*24.8%
distribute-rgt-out24.8%
unpow224.8%
+-commutative24.8%
*-commutative24.8%
unpow224.8%
Simplified24.8%
if 1.35000000000000003e154 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
unpow2100.0%
associate-*r*100.0%
*-commutative100.0%
associate-*l*100.0%
Simplified100.0%
Final simplification78.4%
NOTE: im should be positive before calling this function (FPCore (re im) :precision binary64 (if (<= im 520.0) (cos re) (* (* im im) (+ 0.5 (* (* re re) -0.25)))))
im = abs(im);
double code(double re, double im) {
double tmp;
if (im <= 520.0) {
tmp = cos(re);
} else {
tmp = (im * im) * (0.5 + ((re * re) * -0.25));
}
return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 520.0d0) then
tmp = cos(re)
else
tmp = (im * im) * (0.5d0 + ((re * re) * (-0.25d0)))
end if
code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
double tmp;
if (im <= 520.0) {
tmp = Math.cos(re);
} else {
tmp = (im * im) * (0.5 + ((re * re) * -0.25));
}
return tmp;
}
im = abs(im) def code(re, im): tmp = 0 if im <= 520.0: tmp = math.cos(re) else: tmp = (im * im) * (0.5 + ((re * re) * -0.25)) return tmp
im = abs(im) function code(re, im) tmp = 0.0 if (im <= 520.0) tmp = cos(re); else tmp = Float64(Float64(im * im) * Float64(0.5 + Float64(Float64(re * re) * -0.25))); end return tmp end
im = abs(im) function tmp_2 = code(re, im) tmp = 0.0; if (im <= 520.0) tmp = cos(re); else tmp = (im * im) * (0.5 + ((re * re) * -0.25)); end tmp_2 = tmp; end
NOTE: im should be positive before calling this function code[re_, im_] := If[LessEqual[im, 520.0], N[Cos[re], $MachinePrecision], N[(N[(im * im), $MachinePrecision] * N[(0.5 + N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;im \leq 520:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\
\end{array}
\end{array}
if im < 520Initial 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 71.0%
Taylor expanded in im around 0 71.7%
if 520 < im Initial program 100.0%
Taylor expanded in im around 0 47.6%
unpow247.6%
Simplified47.6%
Taylor expanded in im around inf 47.6%
unpow247.6%
associate-*r*47.6%
*-commutative47.6%
associate-*l*47.6%
Simplified47.6%
Taylor expanded in re around 0 13.7%
associate-*r*13.7%
distribute-rgt-out48.0%
unpow248.0%
+-commutative48.0%
*-commutative48.0%
unpow248.0%
Simplified48.0%
Final simplification65.5%
NOTE: im should be positive before calling this function (FPCore (re im) :precision binary64 (if (<= im 125.0) (* 0.5 (+ 2.0 (* im im))) (* (* im im) (+ 0.5 (* (* re re) -0.25)))))
im = abs(im);
double code(double re, double im) {
double tmp;
if (im <= 125.0) {
tmp = 0.5 * (2.0 + (im * im));
} else {
tmp = (im * im) * (0.5 + ((re * re) * -0.25));
}
return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 125.0d0) then
tmp = 0.5d0 * (2.0d0 + (im * im))
else
tmp = (im * im) * (0.5d0 + ((re * re) * (-0.25d0)))
end if
code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
double tmp;
if (im <= 125.0) {
tmp = 0.5 * (2.0 + (im * im));
} else {
tmp = (im * im) * (0.5 + ((re * re) * -0.25));
}
return tmp;
}
im = abs(im) def code(re, im): tmp = 0 if im <= 125.0: tmp = 0.5 * (2.0 + (im * im)) else: tmp = (im * im) * (0.5 + ((re * re) * -0.25)) return tmp
im = abs(im) function code(re, im) tmp = 0.0 if (im <= 125.0) tmp = Float64(0.5 * Float64(2.0 + Float64(im * im))); else tmp = Float64(Float64(im * im) * Float64(0.5 + Float64(Float64(re * re) * -0.25))); end return tmp end
im = abs(im) function tmp_2 = code(re, im) tmp = 0.0; if (im <= 125.0) tmp = 0.5 * (2.0 + (im * im)); else tmp = (im * im) * (0.5 + ((re * re) * -0.25)); end tmp_2 = tmp; end
NOTE: im should be positive before calling this function code[re_, im_] := If[LessEqual[im, 125.0], N[(0.5 * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(im * im), $MachinePrecision] * N[(0.5 + N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;im \leq 125:\\
\;\;\;\;0.5 \cdot \left(2 + im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\
\end{array}
\end{array}
if im < 125Initial program 100.0%
Taylor expanded in im around 0 85.5%
unpow285.5%
Simplified85.5%
Taylor expanded in re around 0 44.6%
add-cbrt-cube52.5%
pow252.5%
pow252.5%
pow252.5%
pow352.5%
pow252.5%
pow-pow52.5%
metadata-eval52.5%
Applied egg-rr52.5%
Taylor expanded in im around 0 44.6%
unpow244.6%
Simplified44.6%
if 125 < im Initial program 100.0%
Taylor expanded in im around 0 47.6%
unpow247.6%
Simplified47.6%
Taylor expanded in im around inf 47.6%
unpow247.6%
associate-*r*47.6%
*-commutative47.6%
associate-*l*47.6%
Simplified47.6%
Taylor expanded in re around 0 13.7%
associate-*r*13.7%
distribute-rgt-out48.0%
unpow248.0%
+-commutative48.0%
*-commutative48.0%
unpow248.0%
Simplified48.0%
Final simplification45.5%
NOTE: im should be positive before calling this function (FPCore (re im) :precision binary64 (if (<= re 8.2e+16) (* 0.5 (+ 2.0 (* im im))) (* -0.25 (* (* re im) (* re im)))))
im = abs(im);
double code(double re, double im) {
double tmp;
if (re <= 8.2e+16) {
tmp = 0.5 * (2.0 + (im * im));
} else {
tmp = -0.25 * ((re * im) * (re * im));
}
return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= 8.2d+16) then
tmp = 0.5d0 * (2.0d0 + (im * im))
else
tmp = (-0.25d0) * ((re * im) * (re * im))
end if
code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
double tmp;
if (re <= 8.2e+16) {
tmp = 0.5 * (2.0 + (im * im));
} else {
tmp = -0.25 * ((re * im) * (re * im));
}
return tmp;
}
im = abs(im) def code(re, im): tmp = 0 if re <= 8.2e+16: tmp = 0.5 * (2.0 + (im * im)) else: tmp = -0.25 * ((re * im) * (re * im)) return tmp
im = abs(im) function code(re, im) tmp = 0.0 if (re <= 8.2e+16) tmp = Float64(0.5 * Float64(2.0 + Float64(im * im))); else tmp = Float64(-0.25 * Float64(Float64(re * im) * Float64(re * im))); end return tmp end
im = abs(im) function tmp_2 = code(re, im) tmp = 0.0; if (re <= 8.2e+16) tmp = 0.5 * (2.0 + (im * im)); else tmp = -0.25 * ((re * im) * (re * im)); end tmp_2 = tmp; end
NOTE: im should be positive before calling this function code[re_, im_] := If[LessEqual[re, 8.2e+16], N[(0.5 * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-0.25 * N[(N[(re * im), $MachinePrecision] * N[(re * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;re \leq 8.2 \cdot 10^{+16}:\\
\;\;\;\;0.5 \cdot \left(2 + im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;-0.25 \cdot \left(\left(re \cdot im\right) \cdot \left(re \cdot im\right)\right)\\
\end{array}
\end{array}
if re < 8.2e16Initial program 100.0%
Taylor expanded in im around 0 71.4%
unpow271.4%
Simplified71.4%
Taylor expanded in re around 0 46.5%
add-cbrt-cube60.7%
pow260.7%
pow260.7%
pow260.7%
pow360.7%
pow260.7%
pow-pow60.7%
metadata-eval60.7%
Applied egg-rr60.7%
Taylor expanded in im around 0 46.5%
unpow246.5%
Simplified46.5%
if 8.2e16 < re Initial program 100.0%
Taylor expanded in im around 0 88.1%
unpow288.1%
Simplified88.1%
Taylor expanded in im around inf 28.1%
unpow228.1%
associate-*r*28.1%
*-commutative28.1%
associate-*l*28.1%
Simplified28.1%
Taylor expanded in re around 0 7.6%
associate-*r*7.6%
distribute-rgt-out18.5%
unpow218.5%
+-commutative18.5%
*-commutative18.5%
unpow218.5%
Simplified18.5%
Taylor expanded in re around inf 18.5%
unpow218.5%
unpow218.5%
*-commutative18.5%
unswap-sqr19.1%
Simplified19.1%
Final simplification39.6%
NOTE: im should be positive before calling this function (FPCore (re im) :precision binary64 (* 0.5 (+ 2.0 (* im im))))
im = abs(im);
double code(double re, double im) {
return 0.5 * (2.0 + (im * im));
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * (2.0d0 + (im * im))
end function
im = Math.abs(im);
public static double code(double re, double im) {
return 0.5 * (2.0 + (im * im));
}
im = abs(im) def code(re, im): return 0.5 * (2.0 + (im * im))
im = abs(im) function code(re, im) return Float64(0.5 * Float64(2.0 + Float64(im * im))) end
im = abs(im) function tmp = code(re, im) tmp = 0.5 * (2.0 + (im * im)); end
NOTE: im should be positive before calling this function code[re_, im_] := N[(0.5 * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im = |im|\\
\\
0.5 \cdot \left(2 + im \cdot im\right)
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 75.5%
unpow275.5%
Simplified75.5%
Taylor expanded in re around 0 40.0%
add-cbrt-cube51.4%
pow251.4%
pow251.4%
pow251.4%
pow351.4%
pow251.4%
pow-pow51.4%
metadata-eval51.4%
Applied egg-rr51.4%
Taylor expanded in im around 0 40.0%
unpow240.0%
Simplified40.0%
Final simplification40.0%
NOTE: im should be positive before calling this function (FPCore (re im) :precision binary64 (* 0.5 (* im im)))
im = abs(im);
double code(double re, double im) {
return 0.5 * (im * im);
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * (im * im)
end function
im = Math.abs(im);
public static double code(double re, double im) {
return 0.5 * (im * im);
}
im = abs(im) def code(re, im): return 0.5 * (im * im)
im = abs(im) function code(re, im) return Float64(0.5 * Float64(im * im)) end
im = abs(im) function tmp = code(re, im) tmp = 0.5 * (im * im); end
NOTE: im should be positive before calling this function code[re_, im_] := N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im = |im|\\
\\
0.5 \cdot \left(im \cdot im\right)
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 75.5%
unpow275.5%
Simplified75.5%
Taylor expanded in im around inf 25.4%
unpow225.4%
associate-*r*25.4%
*-commutative25.4%
associate-*l*25.4%
Simplified25.4%
Taylor expanded in re around 0 16.2%
unpow216.2%
Simplified16.2%
Final simplification16.2%
herbie shell --seed 2023222
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))