
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp(-im) + exp(im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * (exp(-im) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp(-im) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp(-im) + exp(im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * (exp(-im) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp(-im) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
\end{array}
(FPCore (re im) :precision binary64 (* (cos re) (fma 0.5 (exp im) (/ 0.5 (exp im)))))
double code(double re, double im) {
return cos(re) * fma(0.5, exp(im), (0.5 / exp(im)));
}
function code(re, im) return Float64(cos(re) * fma(0.5, exp(im), Float64(0.5 / exp(im)))) end
code[re_, im_] := N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[Exp[im], $MachinePrecision] + N[(0.5 / N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right)
\end{array}
Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (re im) :precision binary64 (* (* (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 0.00068)
(cos re)
(if (<= im 1.3e+103)
(* 0.5 (+ (exp im) (exp (- im))))
(*
(cos re)
(+ 1.0 (* im (+ 0.5 (* im (+ 0.25 (* im 0.08333333333333333))))))))))
double code(double re, double im) {
double tmp;
if (im <= 0.00068) {
tmp = cos(re);
} else if (im <= 1.3e+103) {
tmp = 0.5 * (exp(im) + exp(-im));
} else {
tmp = cos(re) * (1.0 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333))))));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 0.00068d0) then
tmp = cos(re)
else if (im <= 1.3d+103) then
tmp = 0.5d0 * (exp(im) + exp(-im))
else
tmp = cos(re) * (1.0d0 + (im * (0.5d0 + (im * (0.25d0 + (im * 0.08333333333333333d0))))))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 0.00068) {
tmp = Math.cos(re);
} else if (im <= 1.3e+103) {
tmp = 0.5 * (Math.exp(im) + Math.exp(-im));
} else {
tmp = Math.cos(re) * (1.0 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333))))));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 0.00068: tmp = math.cos(re) elif im <= 1.3e+103: tmp = 0.5 * (math.exp(im) + math.exp(-im)) else: tmp = math.cos(re) * (1.0 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333)))))) return tmp
function code(re, im) tmp = 0.0 if (im <= 0.00068) tmp = cos(re); elseif (im <= 1.3e+103) tmp = Float64(0.5 * Float64(exp(im) + exp(Float64(-im)))); else tmp = Float64(cos(re) * Float64(1.0 + Float64(im * Float64(0.5 + Float64(im * Float64(0.25 + Float64(im * 0.08333333333333333))))))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 0.00068) tmp = cos(re); elseif (im <= 1.3e+103) tmp = 0.5 * (exp(im) + exp(-im)); else tmp = cos(re) * (1.0 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333)))))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 0.00068], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.3e+103], N[(0.5 * N[(N[Exp[im], $MachinePrecision] + N[Exp[(-im)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(1.0 + N[(im * N[(0.5 + N[(im * N[(0.25 + N[(im * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.00068:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.3 \cdot 10^{+103}:\\
\;\;\;\;0.5 \cdot \left(e^{im} + e^{-im}\right)\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.25 + im \cdot 0.08333333333333333\right)\right)\right)\\
\end{array}
\end{array}
if im < 6.8e-4Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 65.0%
if 6.8e-4 < im < 1.3000000000000001e103Initial program 99.9%
Taylor expanded in re around 0 72.7%
if 1.3000000000000001e103 < im Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in im around 0 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification72.0%
(FPCore (re im)
:precision binary64
(if (<= im 0.0055)
(* (cos re) (* 0.5 (fma im im 2.0)))
(if (<= im 1.2e+103)
(* 0.5 (+ (exp im) (exp (- im))))
(*
(cos re)
(+ 1.0 (* im (+ 0.5 (* im (+ 0.25 (* im 0.08333333333333333))))))))))
double code(double re, double im) {
double tmp;
if (im <= 0.0055) {
tmp = cos(re) * (0.5 * fma(im, im, 2.0));
} else if (im <= 1.2e+103) {
tmp = 0.5 * (exp(im) + exp(-im));
} else {
tmp = cos(re) * (1.0 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333))))));
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 0.0055) tmp = Float64(cos(re) * Float64(0.5 * fma(im, im, 2.0))); elseif (im <= 1.2e+103) tmp = Float64(0.5 * Float64(exp(im) + exp(Float64(-im)))); else tmp = Float64(cos(re) * Float64(1.0 + Float64(im * Float64(0.5 + Float64(im * Float64(0.25 + Float64(im * 0.08333333333333333))))))); end return tmp end
code[re_, im_] := If[LessEqual[im, 0.0055], N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.2e+103], N[(0.5 * N[(N[Exp[im], $MachinePrecision] + N[Exp[(-im)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(1.0 + N[(im * N[(0.5 + N[(im * N[(0.25 + N[(im * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.0055:\\
\;\;\;\;\cos re \cdot \left(0.5 \cdot \mathsf{fma}\left(im, im, 2\right)\right)\\
\mathbf{elif}\;im \leq 1.2 \cdot 10^{+103}:\\
\;\;\;\;0.5 \cdot \left(e^{im} + e^{-im}\right)\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.25 + im \cdot 0.08333333333333333\right)\right)\right)\\
\end{array}
\end{array}
if im < 0.0054999999999999997Initial program 100.0%
Taylor expanded in im around 0 83.9%
Taylor expanded in re around inf 83.9%
associate-*r*83.9%
*-commutative83.9%
associate-*l*83.9%
+-commutative83.9%
unpow283.9%
fma-define83.9%
Simplified83.9%
if 0.0054999999999999997 < im < 1.1999999999999999e103Initial program 99.9%
Taylor expanded in re around 0 72.7%
if 1.1999999999999999e103 < im Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in im around 0 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification85.8%
(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%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 73.0%
Taylor expanded in re around inf 73.0%
*-commutative73.0%
Simplified73.0%
Final simplification73.0%
(FPCore (re im)
:precision binary64
(if (<= im 0.76)
(cos re)
(if (<= im 1.3e+103)
(+ 0.5 (* 0.5 (exp im)))
(*
(cos re)
(+ 1.0 (* im (+ 0.5 (* im (+ 0.25 (* im 0.08333333333333333))))))))))
double code(double re, double im) {
double tmp;
if (im <= 0.76) {
tmp = cos(re);
} else if (im <= 1.3e+103) {
tmp = 0.5 + (0.5 * exp(im));
} else {
tmp = cos(re) * (1.0 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333))))));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 0.76d0) then
tmp = cos(re)
else if (im <= 1.3d+103) then
tmp = 0.5d0 + (0.5d0 * exp(im))
else
tmp = cos(re) * (1.0d0 + (im * (0.5d0 + (im * (0.25d0 + (im * 0.08333333333333333d0))))))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 0.76) {
tmp = Math.cos(re);
} else if (im <= 1.3e+103) {
tmp = 0.5 + (0.5 * Math.exp(im));
} else {
tmp = Math.cos(re) * (1.0 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333))))));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 0.76: tmp = math.cos(re) elif im <= 1.3e+103: tmp = 0.5 + (0.5 * math.exp(im)) else: tmp = math.cos(re) * (1.0 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333)))))) return tmp
function code(re, im) tmp = 0.0 if (im <= 0.76) tmp = cos(re); elseif (im <= 1.3e+103) tmp = Float64(0.5 + Float64(0.5 * exp(im))); else tmp = Float64(cos(re) * Float64(1.0 + Float64(im * Float64(0.5 + Float64(im * Float64(0.25 + Float64(im * 0.08333333333333333))))))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 0.76) tmp = cos(re); elseif (im <= 1.3e+103) tmp = 0.5 + (0.5 * exp(im)); else tmp = cos(re) * (1.0 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333)))))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 0.76], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.3e+103], N[(0.5 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(1.0 + N[(im * N[(0.5 + N[(im * N[(0.25 + N[(im * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.76:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.3 \cdot 10^{+103}:\\
\;\;\;\;0.5 + 0.5 \cdot e^{im}\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left(1 + im \cdot \left(0.5 + im \cdot \left(0.25 + im \cdot 0.08333333333333333\right)\right)\right)\\
\end{array}
\end{array}
if im < 0.76000000000000001Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 64.8%
if 0.76000000000000001 < im < 1.3000000000000001e103Initial program 99.9%
cos-neg99.9%
*-commutative99.9%
associate-*l*99.9%
+-commutative99.9%
distribute-rgt-in99.9%
cancel-sign-sub99.9%
distribute-lft-neg-in99.9%
cos-neg99.9%
*-commutative99.9%
fma-neg99.9%
remove-double-neg99.9%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 93.4%
Taylor expanded in re around 0 64.9%
if 1.3000000000000001e103 < im Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in im around 0 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification71.1%
(FPCore (re im)
:precision binary64
(if (<= im 0.76)
(cos re)
(if (<= im 2.7e+154)
(+ 0.5 (* 0.5 (exp im)))
(* (cos re) (+ 1.0 (* im (+ 0.5 (* im 0.25))))))))
double code(double re, double im) {
double tmp;
if (im <= 0.76) {
tmp = cos(re);
} else if (im <= 2.7e+154) {
tmp = 0.5 + (0.5 * exp(im));
} else {
tmp = cos(re) * (1.0 + (im * (0.5 + (im * 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 <= 0.76d0) then
tmp = cos(re)
else if (im <= 2.7d+154) then
tmp = 0.5d0 + (0.5d0 * exp(im))
else
tmp = cos(re) * (1.0d0 + (im * (0.5d0 + (im * 0.25d0))))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 0.76) {
tmp = Math.cos(re);
} else if (im <= 2.7e+154) {
tmp = 0.5 + (0.5 * Math.exp(im));
} else {
tmp = Math.cos(re) * (1.0 + (im * (0.5 + (im * 0.25))));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 0.76: tmp = math.cos(re) elif im <= 2.7e+154: tmp = 0.5 + (0.5 * math.exp(im)) else: tmp = math.cos(re) * (1.0 + (im * (0.5 + (im * 0.25)))) return tmp
function code(re, im) tmp = 0.0 if (im <= 0.76) tmp = cos(re); elseif (im <= 2.7e+154) tmp = Float64(0.5 + Float64(0.5 * exp(im))); else tmp = Float64(cos(re) * Float64(1.0 + Float64(im * Float64(0.5 + Float64(im * 0.25))))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 0.76) tmp = cos(re); elseif (im <= 2.7e+154) tmp = 0.5 + (0.5 * exp(im)); else tmp = cos(re) * (1.0 + (im * (0.5 + (im * 0.25)))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 0.76], N[Cos[re], $MachinePrecision], If[LessEqual[im, 2.7e+154], N[(0.5 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(1.0 + N[(im * N[(0.5 + N[(im * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.76:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 2.7 \cdot 10^{+154}:\\
\;\;\;\;0.5 + 0.5 \cdot e^{im}\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left(1 + im \cdot \left(0.5 + im \cdot 0.25\right)\right)\\
\end{array}
\end{array}
if im < 0.76000000000000001Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 64.8%
if 0.76000000000000001 < im < 2.70000000000000006e154Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 96.1%
Taylor expanded in re around 0 73.2%
if 2.70000000000000006e154 < im Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in im around 0 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification70.4%
(FPCore (re im) :precision binary64 (if (<= im 0.76) (cos re) (+ 0.5 (* 0.5 (exp im)))))
double code(double re, double im) {
double tmp;
if (im <= 0.76) {
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 <= 0.76d0) 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 <= 0.76) {
tmp = Math.cos(re);
} else {
tmp = 0.5 + (0.5 * Math.exp(im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 0.76: tmp = math.cos(re) else: tmp = 0.5 + (0.5 * math.exp(im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 0.76) 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 <= 0.76) tmp = cos(re); else tmp = 0.5 + (0.5 * exp(im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 0.76], 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 0.76:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;0.5 + 0.5 \cdot e^{im}\\
\end{array}
\end{array}
if im < 0.76000000000000001Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 64.8%
if 0.76000000000000001 < im Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 97.9%
Taylor expanded in re around 0 72.6%
Final simplification66.8%
(FPCore (re im) :precision binary64 (if (<= im 1.75e+45) (cos re) (+ 1.0 (* im (+ 0.5 (* im (+ 0.25 (* im 0.08333333333333333))))))))
double code(double re, double im) {
double tmp;
if (im <= 1.75e+45) {
tmp = cos(re);
} else {
tmp = 1.0 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333)))));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 1.75d+45) then
tmp = cos(re)
else
tmp = 1.0d0 + (im * (0.5d0 + (im * (0.25d0 + (im * 0.08333333333333333d0)))))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.75e+45) {
tmp = Math.cos(re);
} else {
tmp = 1.0 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333)))));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.75e+45: tmp = math.cos(re) else: tmp = 1.0 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333))))) return tmp
function code(re, im) tmp = 0.0 if (im <= 1.75e+45) tmp = cos(re); else tmp = Float64(1.0 + Float64(im * Float64(0.5 + Float64(im * Float64(0.25 + Float64(im * 0.08333333333333333)))))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.75e+45) tmp = cos(re); else tmp = 1.0 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333))))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.75e+45], N[Cos[re], $MachinePrecision], N[(1.0 + N[(im * N[(0.5 + N[(im * N[(0.25 + N[(im * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.75 \cdot 10^{+45}:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;1 + im \cdot \left(0.5 + im \cdot \left(0.25 + im \cdot 0.08333333333333333\right)\right)\\
\end{array}
\end{array}
if im < 1.75000000000000011e45Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 62.2%
if 1.75000000000000011e45 < im Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in re around 0 75.9%
Taylor expanded in im around 0 61.3%
*-commutative61.3%
Simplified61.3%
Final simplification62.0%
(FPCore (re im) :precision binary64 (+ 1.0 (* im (+ 0.5 (* im (+ 0.25 (* im 0.08333333333333333)))))))
double code(double re, double im) {
return 1.0 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333)))));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 1.0d0 + (im * (0.5d0 + (im * (0.25d0 + (im * 0.08333333333333333d0)))))
end function
public static double code(double re, double im) {
return 1.0 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333)))));
}
def code(re, im): return 1.0 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333)))))
function code(re, im) return Float64(1.0 + Float64(im * Float64(0.5 + Float64(im * Float64(0.25 + Float64(im * 0.08333333333333333)))))) end
function tmp = code(re, im) tmp = 1.0 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333))))); end
code[re_, im_] := N[(1.0 + N[(im * N[(0.5 + N[(im * N[(0.25 + N[(im * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + im \cdot \left(0.5 + im \cdot \left(0.25 + im \cdot 0.08333333333333333\right)\right)
\end{array}
Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 73.0%
Taylor expanded in re around 0 46.2%
Taylor expanded in im around 0 45.7%
*-commutative45.7%
Simplified45.7%
Final simplification45.7%
(FPCore (re im) :precision binary64 (+ 1.0 (* im (+ 0.5 (* im 0.25)))))
double code(double re, double im) {
return 1.0 + (im * (0.5 + (im * 0.25)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 1.0d0 + (im * (0.5d0 + (im * 0.25d0)))
end function
public static double code(double re, double im) {
return 1.0 + (im * (0.5 + (im * 0.25)));
}
def code(re, im): return 1.0 + (im * (0.5 + (im * 0.25)))
function code(re, im) return Float64(1.0 + Float64(im * Float64(0.5 + Float64(im * 0.25)))) end
function tmp = code(re, im) tmp = 1.0 + (im * (0.5 + (im * 0.25))); end
code[re_, im_] := N[(1.0 + N[(im * N[(0.5 + N[(im * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + im \cdot \left(0.5 + im \cdot 0.25\right)
\end{array}
Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 73.0%
Taylor expanded in re around 0 46.2%
Taylor expanded in im around 0 47.3%
Final simplification47.3%
(FPCore (re im) :precision binary64 (+ 1.0 (* 0.5 im)))
double code(double re, double im) {
return 1.0 + (0.5 * im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 1.0d0 + (0.5d0 * im)
end function
public static double code(double re, double im) {
return 1.0 + (0.5 * im);
}
def code(re, im): return 1.0 + (0.5 * im)
function code(re, im) return Float64(1.0 + Float64(0.5 * im)) end
function tmp = code(re, im) tmp = 1.0 + (0.5 * im); end
code[re_, im_] := N[(1.0 + N[(0.5 * im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + 0.5 \cdot im
\end{array}
Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 73.0%
Taylor expanded in re around 0 46.2%
Taylor expanded in im around 0 28.2%
Final simplification28.2%
(FPCore (re im) :precision binary64 1.0)
double code(double re, double im) {
return 1.0;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 1.0d0
end function
public static double code(double re, double im) {
return 1.0;
}
def code(re, im): return 1.0
function code(re, im) return 1.0 end
function tmp = code(re, im) tmp = 1.0; end
code[re_, im_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-rgt-in100.0%
cancel-sign-sub100.0%
distribute-lft-neg-in100.0%
cos-neg100.0%
*-commutative100.0%
fma-neg100.0%
remove-double-neg100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 73.0%
Taylor expanded in re around 0 46.2%
Taylor expanded in im around 0 28.2%
Final simplification28.2%
herbie shell --seed 2024055
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))