
(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 14 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) (+ (* 0.5 (/ 1.0 (exp im))) (* 0.5 (exp im)))))
double code(double re, double im) {
return cos(re) * ((0.5 * (1.0 / exp(im))) + (0.5 * exp(im)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = cos(re) * ((0.5d0 * (1.0d0 / exp(im))) + (0.5d0 * exp(im)))
end function
public static double code(double re, double im) {
return Math.cos(re) * ((0.5 * (1.0 / Math.exp(im))) + (0.5 * Math.exp(im)));
}
def code(re, im): return math.cos(re) * ((0.5 * (1.0 / math.exp(im))) + (0.5 * math.exp(im)))
function code(re, im) return Float64(cos(re) * Float64(Float64(0.5 * Float64(1.0 / exp(im))) + Float64(0.5 * exp(im)))) end
function tmp = code(re, im) tmp = cos(re) * ((0.5 * (1.0 / exp(im))) + (0.5 * exp(im))); end
code[re_, im_] := N[(N[Cos[re], $MachinePrecision] * N[(N[(0.5 * N[(1.0 / N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos re \cdot \left(0.5 \cdot \frac{1}{e^{im}} + 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 inf 100.0%
Final simplification100.0%
(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 6.8)
(* (* (cos re) 0.5) (+ 2.0 (* im im)))
(if (<= im 1.2e+77)
(+ 0.5 (* 0.5 (exp im)))
(* 0.041666666666666664 (* (cos re) (pow im 4.0))))))
double code(double re, double im) {
double tmp;
if (im <= 6.8) {
tmp = (cos(re) * 0.5) * (2.0 + (im * im));
} else if (im <= 1.2e+77) {
tmp = 0.5 + (0.5 * exp(im));
} else {
tmp = 0.041666666666666664 * (cos(re) * pow(im, 4.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.8d0) then
tmp = (cos(re) * 0.5d0) * (2.0d0 + (im * im))
else if (im <= 1.2d+77) then
tmp = 0.5d0 + (0.5d0 * exp(im))
else
tmp = 0.041666666666666664d0 * (cos(re) * (im ** 4.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 6.8) {
tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
} else if (im <= 1.2e+77) {
tmp = 0.5 + (0.5 * Math.exp(im));
} else {
tmp = 0.041666666666666664 * (Math.cos(re) * Math.pow(im, 4.0));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 6.8: tmp = (math.cos(re) * 0.5) * (2.0 + (im * im)) elif im <= 1.2e+77: tmp = 0.5 + (0.5 * math.exp(im)) else: tmp = 0.041666666666666664 * (math.cos(re) * math.pow(im, 4.0)) return tmp
function code(re, im) tmp = 0.0 if (im <= 6.8) tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im))); elseif (im <= 1.2e+77) tmp = Float64(0.5 + Float64(0.5 * exp(im))); else tmp = Float64(0.041666666666666664 * Float64(cos(re) * (im ^ 4.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 6.8) tmp = (cos(re) * 0.5) * (2.0 + (im * im)); elseif (im <= 1.2e+77) tmp = 0.5 + (0.5 * exp(im)); else tmp = 0.041666666666666664 * (cos(re) * (im ^ 4.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 6.8], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.2e+77], N[(0.5 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.041666666666666664 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 6.8:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\
\mathbf{elif}\;im \leq 1.2 \cdot 10^{+77}:\\
\;\;\;\;0.5 + 0.5 \cdot e^{im}\\
\mathbf{else}:\\
\;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\
\end{array}
\end{array}
if im < 6.79999999999999982Initial program 100.0%
Taylor expanded in im around 0 83.7%
unpow283.7%
Simplified83.7%
if 6.79999999999999982 < im < 1.1999999999999999e77Initial 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 inf 100.0%
Taylor expanded in re around 0 64.7%
Taylor expanded in im around 0 64.7%
Taylor expanded in im around inf 64.7%
if 1.1999999999999999e77 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
unpow2100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification85.2%
(FPCore (re im)
:precision binary64
(if (<= im 0.0148)
(* (* (cos re) 0.5) (+ 2.0 (* im im)))
(if (<= im 1.2e+77)
(* 0.5 (+ (exp im) (exp (- im))))
(* 0.041666666666666664 (* (cos re) (pow im 4.0))))))
double code(double re, double im) {
double tmp;
if (im <= 0.0148) {
tmp = (cos(re) * 0.5) * (2.0 + (im * im));
} else if (im <= 1.2e+77) {
tmp = 0.5 * (exp(im) + exp(-im));
} else {
tmp = 0.041666666666666664 * (cos(re) * pow(im, 4.0));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 0.0148d0) then
tmp = (cos(re) * 0.5d0) * (2.0d0 + (im * im))
else if (im <= 1.2d+77) then
tmp = 0.5d0 * (exp(im) + exp(-im))
else
tmp = 0.041666666666666664d0 * (cos(re) * (im ** 4.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 0.0148) {
tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
} else if (im <= 1.2e+77) {
tmp = 0.5 * (Math.exp(im) + Math.exp(-im));
} else {
tmp = 0.041666666666666664 * (Math.cos(re) * Math.pow(im, 4.0));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 0.0148: tmp = (math.cos(re) * 0.5) * (2.0 + (im * im)) elif im <= 1.2e+77: tmp = 0.5 * (math.exp(im) + math.exp(-im)) else: tmp = 0.041666666666666664 * (math.cos(re) * math.pow(im, 4.0)) return tmp
function code(re, im) tmp = 0.0 if (im <= 0.0148) tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im))); elseif (im <= 1.2e+77) tmp = Float64(0.5 * Float64(exp(im) + exp(Float64(-im)))); else tmp = Float64(0.041666666666666664 * Float64(cos(re) * (im ^ 4.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 0.0148) tmp = (cos(re) * 0.5) * (2.0 + (im * im)); elseif (im <= 1.2e+77) tmp = 0.5 * (exp(im) + exp(-im)); else tmp = 0.041666666666666664 * (cos(re) * (im ^ 4.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 0.0148], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.2e+77], N[(0.5 * N[(N[Exp[im], $MachinePrecision] + N[Exp[(-im)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.041666666666666664 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.0148:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\
\mathbf{elif}\;im \leq 1.2 \cdot 10^{+77}:\\
\;\;\;\;0.5 \cdot \left(e^{im} + e^{-im}\right)\\
\mathbf{else}:\\
\;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\
\end{array}
\end{array}
if im < 0.014800000000000001Initial program 100.0%
Taylor expanded in im around 0 83.9%
unpow283.9%
Simplified83.9%
if 0.014800000000000001 < im < 1.1999999999999999e77Initial program 99.9%
Taylor expanded in re around 0 66.6%
if 1.1999999999999999e77 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
unpow2100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification85.5%
(FPCore (re im) :precision binary64 (* (cos re) (+ 0.5 (* 0.5 (exp im)))))
double code(double re, double im) {
return cos(re) * (0.5 + (0.5 * exp(im)));
}
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
public static double code(double re, double im) {
return Math.cos(re) * (0.5 + (0.5 * Math.exp(im)));
}
def code(re, im): return math.cos(re) * (0.5 + (0.5 * math.exp(im)))
function code(re, im) return Float64(cos(re) * Float64(0.5 + Float64(0.5 * exp(im)))) end
function tmp = code(re, im) tmp = cos(re) * (0.5 + (0.5 * exp(im))); end
code[re_, im_] := N[(N[Cos[re], $MachinePrecision] * N[(0.5 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\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 inf 100.0%
Taylor expanded in im around 0 74.0%
Final simplification74.0%
(FPCore (re im) :precision binary64 (if (or (<= im 2.7) (not (<= im 1.3e+152))) (* (* (cos re) 0.5) (+ 2.0 (* im im))) (+ 0.5 (* 0.5 (exp im)))))
double code(double re, double im) {
double tmp;
if ((im <= 2.7) || !(im <= 1.3e+152)) {
tmp = (cos(re) * 0.5) * (2.0 + (im * im));
} else {
tmp = 0.5 + (0.5 * exp(im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((im <= 2.7d0) .or. (.not. (im <= 1.3d+152))) then
tmp = (cos(re) * 0.5d0) * (2.0d0 + (im * im))
else
tmp = 0.5d0 + (0.5d0 * exp(im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((im <= 2.7) || !(im <= 1.3e+152)) {
tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
} else {
tmp = 0.5 + (0.5 * Math.exp(im));
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= 2.7) or not (im <= 1.3e+152): tmp = (math.cos(re) * 0.5) * (2.0 + (im * im)) else: tmp = 0.5 + (0.5 * math.exp(im)) return tmp
function code(re, im) tmp = 0.0 if ((im <= 2.7) || !(im <= 1.3e+152)) tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im))); else tmp = Float64(0.5 + Float64(0.5 * exp(im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((im <= 2.7) || ~((im <= 1.3e+152))) tmp = (cos(re) * 0.5) * (2.0 + (im * im)); else tmp = 0.5 + (0.5 * exp(im)); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, 2.7], N[Not[LessEqual[im, 1.3e+152]], $MachinePrecision]], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 2.7 \lor \neg \left(im \leq 1.3 \cdot 10^{+152}\right):\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 + 0.5 \cdot e^{im}\\
\end{array}
\end{array}
if im < 2.7000000000000002 or 1.3e152 < im Initial program 100.0%
Taylor expanded in im around 0 85.3%
unpow285.3%
Simplified85.3%
if 2.7000000000000002 < im < 1.3e152Initial 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 inf 100.0%
Taylor expanded in re around 0 69.0%
Taylor expanded in im around 0 69.0%
Taylor expanded in im around inf 69.0%
Final simplification83.4%
(FPCore (re im)
:precision binary64
(if (<= im 3.0)
(cos re)
(if (<= im 1.3e+152)
(+ 0.5 (* 0.5 (exp im)))
(* 0.5 (* (cos re) (* im im))))))
double code(double re, double im) {
double tmp;
if (im <= 3.0) {
tmp = cos(re);
} else if (im <= 1.3e+152) {
tmp = 0.5 + (0.5 * exp(im));
} else {
tmp = 0.5 * (cos(re) * (im * im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 3.0d0) then
tmp = cos(re)
else if (im <= 1.3d+152) then
tmp = 0.5d0 + (0.5d0 * exp(im))
else
tmp = 0.5d0 * (cos(re) * (im * im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 3.0) {
tmp = Math.cos(re);
} else if (im <= 1.3e+152) {
tmp = 0.5 + (0.5 * Math.exp(im));
} else {
tmp = 0.5 * (Math.cos(re) * (im * im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 3.0: tmp = math.cos(re) elif im <= 1.3e+152: tmp = 0.5 + (0.5 * math.exp(im)) else: tmp = 0.5 * (math.cos(re) * (im * im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 3.0) tmp = cos(re); elseif (im <= 1.3e+152) tmp = Float64(0.5 + Float64(0.5 * exp(im))); else tmp = Float64(0.5 * Float64(cos(re) * Float64(im * im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 3.0) tmp = cos(re); elseif (im <= 1.3e+152) tmp = 0.5 + (0.5 * exp(im)); else tmp = 0.5 * (cos(re) * (im * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 3.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.3e+152], N[(0.5 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 3:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.3 \cdot 10^{+152}:\\
\;\;\;\;0.5 + 0.5 \cdot e^{im}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot im\right)\right)\\
\end{array}
\end{array}
if im < 3Initial 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 67.0%
if 3 < im < 1.3e152Initial 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 inf 100.0%
Taylor expanded in re around 0 69.0%
Taylor expanded in im around 0 69.0%
Taylor expanded in im around inf 69.0%
if 1.3e152 < im Initial program 100.0%
Taylor expanded in im around 0 94.7%
unpow294.7%
Simplified94.7%
Taylor expanded in im around inf 94.7%
*-commutative94.7%
unpow294.7%
Simplified94.7%
Final simplification70.7%
(FPCore (re im)
:precision binary64
(if (<= im 9.2e+14)
(cos re)
(if (<= im 5.3e+67)
(* (* im im) (+ 0.5 (* (* re re) -0.25)))
(* 0.041666666666666664 (pow im 4.0)))))
double code(double re, double im) {
double tmp;
if (im <= 9.2e+14) {
tmp = cos(re);
} else if (im <= 5.3e+67) {
tmp = (im * im) * (0.5 + ((re * re) * -0.25));
} else {
tmp = 0.041666666666666664 * pow(im, 4.0);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 9.2d+14) then
tmp = cos(re)
else if (im <= 5.3d+67) then
tmp = (im * im) * (0.5d0 + ((re * re) * (-0.25d0)))
else
tmp = 0.041666666666666664d0 * (im ** 4.0d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 9.2e+14) {
tmp = Math.cos(re);
} else if (im <= 5.3e+67) {
tmp = (im * im) * (0.5 + ((re * re) * -0.25));
} else {
tmp = 0.041666666666666664 * Math.pow(im, 4.0);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 9.2e+14: tmp = math.cos(re) elif im <= 5.3e+67: tmp = (im * im) * (0.5 + ((re * re) * -0.25)) else: tmp = 0.041666666666666664 * math.pow(im, 4.0) return tmp
function code(re, im) tmp = 0.0 if (im <= 9.2e+14) tmp = cos(re); elseif (im <= 5.3e+67) tmp = Float64(Float64(im * im) * Float64(0.5 + Float64(Float64(re * re) * -0.25))); else tmp = Float64(0.041666666666666664 * (im ^ 4.0)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 9.2e+14) tmp = cos(re); elseif (im <= 5.3e+67) tmp = (im * im) * (0.5 + ((re * re) * -0.25)); else tmp = 0.041666666666666664 * (im ^ 4.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 9.2e+14], N[Cos[re], $MachinePrecision], If[LessEqual[im, 5.3e+67], N[(N[(im * im), $MachinePrecision] * N[(0.5 + N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.041666666666666664 * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 9.2 \cdot 10^{+14}:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 5.3 \cdot 10^{+67}:\\
\;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\
\mathbf{else}:\\
\;\;\;\;0.041666666666666664 \cdot {im}^{4}\\
\end{array}
\end{array}
if im < 9.2e14Initial 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 66.1%
if 9.2e14 < im < 5.3e67Initial program 100.0%
Taylor expanded in im around 0 3.9%
unpow23.9%
Simplified3.9%
Taylor expanded in im around inf 3.9%
*-commutative3.9%
unpow23.9%
Simplified3.9%
Taylor expanded in re around 0 50.6%
unpow250.6%
associate-*l*50.6%
+-commutative50.6%
associate-*r*50.6%
associate-*l*50.6%
unpow250.6%
distribute-rgt-out50.6%
unpow250.6%
*-commutative50.6%
unpow250.6%
Simplified50.6%
if 5.3e67 < im Initial program 100.0%
Taylor expanded in im around 0 96.0%
unpow296.0%
*-commutative96.0%
Simplified96.0%
Taylor expanded in im around inf 96.0%
*-commutative96.0%
Simplified96.0%
Taylor expanded in re around 0 70.0%
Final simplification66.0%
(FPCore (re im) :precision binary64 (if (<= im 3.0) (cos re) (+ 0.5 (* 0.5 (exp im)))))
double code(double re, double im) {
double tmp;
if (im <= 3.0) {
tmp = cos(re);
} else {
tmp = 0.5 + (0.5 * exp(im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 3.0d0) then
tmp = cos(re)
else
tmp = 0.5d0 + (0.5d0 * exp(im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 3.0) {
tmp = Math.cos(re);
} else {
tmp = 0.5 + (0.5 * Math.exp(im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 3.0: tmp = math.cos(re) else: tmp = 0.5 + (0.5 * math.exp(im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 3.0) tmp = cos(re); else tmp = Float64(0.5 + Float64(0.5 * exp(im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 3.0) tmp = cos(re); else tmp = 0.5 + (0.5 * exp(im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 3.0], N[Cos[re], $MachinePrecision], N[(0.5 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 3:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;0.5 + 0.5 \cdot e^{im}\\
\end{array}
\end{array}
if im < 3Initial 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 67.0%
if 3 < im Initial program 100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-lft-in100.0%
distribute-lft-in100.0%
distribute-rgt-in100.0%
*-commutative100.0%
fma-def100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
Taylor expanded in re around 0 70.5%
Taylor expanded in im around 0 70.5%
Taylor expanded in im around inf 70.5%
Final simplification67.8%
(FPCore (re im) :precision binary64 (if (<= im 7e+14) (cos re) (* (* im im) (+ 0.5 (* (* re re) -0.25)))))
double code(double re, double im) {
double tmp;
if (im <= 7e+14) {
tmp = cos(re);
} else {
tmp = (im * im) * (0.5 + ((re * re) * -0.25));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 7d+14) then
tmp = cos(re)
else
tmp = (im * im) * (0.5d0 + ((re * re) * (-0.25d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 7e+14) {
tmp = Math.cos(re);
} else {
tmp = (im * im) * (0.5 + ((re * re) * -0.25));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 7e+14: tmp = math.cos(re) else: tmp = (im * im) * (0.5 + ((re * re) * -0.25)) return tmp
function code(re, im) tmp = 0.0 if (im <= 7e+14) tmp = cos(re); else tmp = Float64(Float64(im * im) * Float64(0.5 + Float64(Float64(re * re) * -0.25))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 7e+14) tmp = cos(re); else tmp = (im * im) * (0.5 + ((re * re) * -0.25)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 7e+14], 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}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 7 \cdot 10^{+14}:\\
\;\;\;\;\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 < 7e14Initial 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 66.1%
if 7e14 < im Initial program 100.0%
Taylor expanded in im around 0 54.6%
unpow254.6%
Simplified54.6%
Taylor expanded in im around inf 54.6%
*-commutative54.6%
unpow254.6%
Simplified54.6%
Taylor expanded in re around 0 20.1%
unpow220.1%
associate-*l*20.1%
+-commutative20.1%
associate-*r*20.1%
associate-*l*20.1%
unpow220.1%
distribute-rgt-out61.5%
unpow261.5%
*-commutative61.5%
unpow261.5%
Simplified61.5%
Final simplification65.0%
(FPCore (re im) :precision binary64 (if (<= im 5.5e+15) (* 0.5 (+ 2.0 (* im im))) (* (* im im) (+ 0.5 (* (* re re) -0.25)))))
double code(double re, double im) {
double tmp;
if (im <= 5.5e+15) {
tmp = 0.5 * (2.0 + (im * im));
} else {
tmp = (im * im) * (0.5 + ((re * re) * -0.25));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 5.5d+15) then
tmp = 0.5d0 * (2.0d0 + (im * im))
else
tmp = (im * im) * (0.5d0 + ((re * re) * (-0.25d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 5.5e+15) {
tmp = 0.5 * (2.0 + (im * im));
} else {
tmp = (im * im) * (0.5 + ((re * re) * -0.25));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 5.5e+15: tmp = 0.5 * (2.0 + (im * im)) else: tmp = (im * im) * (0.5 + ((re * re) * -0.25)) return tmp
function code(re, im) tmp = 0.0 if (im <= 5.5e+15) 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
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 5.5e+15) tmp = 0.5 * (2.0 + (im * im)); else tmp = (im * im) * (0.5 + ((re * re) * -0.25)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 5.5e+15], 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}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 5.5 \cdot 10^{+15}:\\
\;\;\;\;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 < 5.5e15Initial 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 inf 100.0%
Taylor expanded in re around 0 58.5%
distribute-lft-out58.5%
rec-exp58.5%
Applied egg-rr58.5%
Taylor expanded in im around 0 44.4%
unpow282.5%
Simplified44.4%
if 5.5e15 < im Initial program 100.0%
Taylor expanded in im around 0 54.6%
unpow254.6%
Simplified54.6%
Taylor expanded in im around inf 54.6%
*-commutative54.6%
unpow254.6%
Simplified54.6%
Taylor expanded in re around 0 20.1%
unpow220.1%
associate-*l*20.1%
+-commutative20.1%
associate-*r*20.1%
associate-*l*20.1%
unpow220.1%
distribute-rgt-out61.5%
unpow261.5%
*-commutative61.5%
unpow261.5%
Simplified61.5%
Final simplification48.3%
(FPCore (re im) :precision binary64 (if (<= im 1.4) 1.0 (* 0.5 (* im im))))
double code(double re, double im) {
double tmp;
if (im <= 1.4) {
tmp = 1.0;
} else {
tmp = 0.5 * (im * im);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 1.4d0) then
tmp = 1.0d0
else
tmp = 0.5d0 * (im * im)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.4) {
tmp = 1.0;
} else {
tmp = 0.5 * (im * im);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.4: tmp = 1.0 else: tmp = 0.5 * (im * im) return tmp
function code(re, im) tmp = 0.0 if (im <= 1.4) tmp = 1.0; else tmp = Float64(0.5 * Float64(im * im)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.4) tmp = 1.0; else tmp = 0.5 * (im * im); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.4], 1.0, N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.4:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot im\right)\\
\end{array}
\end{array}
if im < 1.3999999999999999Initial 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 inf 100.0%
Taylor expanded in re around 0 57.9%
Taylor expanded in im around 0 31.0%
Taylor expanded in im around 0 31.6%
if 1.3999999999999999 < im Initial program 100.0%
Taylor expanded in im around 0 52.1%
unpow252.1%
Simplified52.1%
Taylor expanded in im around inf 52.1%
*-commutative52.1%
unpow252.1%
Simplified52.1%
Taylor expanded in re around 0 39.5%
unpow239.5%
Simplified39.5%
Final simplification33.5%
(FPCore (re im) :precision binary64 (* 0.5 (+ 2.0 (* im im))))
double code(double re, double im) {
return 0.5 * (2.0 + (im * im));
}
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
public static double code(double re, double im) {
return 0.5 * (2.0 + (im * im));
}
def code(re, im): return 0.5 * (2.0 + (im * im))
function code(re, im) return Float64(0.5 * Float64(2.0 + Float64(im * im))) end
function tmp = code(re, im) tmp = 0.5 * (2.0 + (im * im)); end
code[re_, im_] := N[(0.5 * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(2 + im \cdot 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 inf 100.0%
Taylor expanded in re around 0 60.9%
distribute-lft-out60.9%
rec-exp60.9%
Applied egg-rr60.9%
Taylor expanded in im around 0 43.7%
unpow276.2%
Simplified43.7%
Final simplification43.7%
(FPCore (re im) :precision binary64 1.0)
double code(double re, double im) {
return 1.0;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 1.0d0
end function
public static double code(double re, double im) {
return 1.0;
}
def code(re, im): return 1.0
function code(re, im) return 1.0 end
function tmp = code(re, im) tmp = 1.0; end
code[re_, im_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 100.0%
*-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 inf 100.0%
Taylor expanded in re around 0 60.9%
Taylor expanded in im around 0 40.4%
Taylor expanded in im around 0 24.7%
Final simplification24.7%
herbie shell --seed 2023230
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))