
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp(-im) + exp(im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * (exp(-im) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp(-im) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp(-im) + exp(im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * (exp(-im) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp(-im) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
\end{array}
(FPCore (re im) :precision binary64 (* (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%
(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 (* (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 75.1%
fma-undefine75.1%
Applied egg-rr75.1%
Final simplification75.1%
(FPCore (re im)
:precision binary64
(if (<= im 2.15)
(cos re)
(if (<= im 3.1e+102)
(+ 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 <= 2.15) {
tmp = cos(re);
} else if (im <= 3.1e+102) {
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 <= 2.15d0) then
tmp = cos(re)
else if (im <= 3.1d+102) 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 <= 2.15) {
tmp = Math.cos(re);
} else if (im <= 3.1e+102) {
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 <= 2.15: tmp = math.cos(re) elif im <= 3.1e+102: 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 <= 2.15) tmp = cos(re); elseif (im <= 3.1e+102) 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 <= 2.15) tmp = cos(re); elseif (im <= 3.1e+102) 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, 2.15], N[Cos[re], $MachinePrecision], If[LessEqual[im, 3.1e+102], 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 2.15:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 3.1 \cdot 10^{+102}:\\
\;\;\;\;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 < 2.14999999999999991Initial 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 66.3%
if 2.14999999999999991 < im < 3.09999999999999987e102Initial 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 88.2%
if 3.09999999999999987e102 < 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 98.4%
*-commutative98.4%
Simplified98.4%
(FPCore (re im)
:precision binary64
(if (<= im 1.92)
(cos re)
(if (<= im 2.65e+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 <= 1.92) {
tmp = cos(re);
} else if (im <= 2.65e+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 <= 1.92d0) then
tmp = cos(re)
else if (im <= 2.65d+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 <= 1.92) {
tmp = Math.cos(re);
} else if (im <= 2.65e+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 <= 1.92: tmp = math.cos(re) elif im <= 2.65e+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 <= 1.92) tmp = cos(re); elseif (im <= 2.65e+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 <= 1.92) tmp = cos(re); elseif (im <= 2.65e+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, 1.92], N[Cos[re], $MachinePrecision], If[LessEqual[im, 2.65e+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 1.92:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 2.65 \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 < 1.9199999999999999Initial 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 66.3%
if 1.9199999999999999 < im < 2.65000000000000012e154Initial 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 79.3%
if 2.65000000000000012e154 < 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%
(FPCore (re im) :precision binary64 (if (<= im 5.1) (cos re) (+ 0.5 (* 0.5 (exp im)))))
double code(double re, double im) {
double tmp;
if (im <= 5.1) {
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 <= 5.1d0) 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 <= 5.1) {
tmp = Math.cos(re);
} else {
tmp = 0.5 + (0.5 * Math.exp(im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 5.1: tmp = math.cos(re) else: tmp = 0.5 + (0.5 * math.exp(im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 5.1) 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 <= 5.1) tmp = cos(re); else tmp = 0.5 + (0.5 * exp(im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 5.1], 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 5.1:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;0.5 + 0.5 \cdot e^{im}\\
\end{array}
\end{array}
if im < 5.0999999999999996Initial 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 66.3%
if 5.0999999999999996 < 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 76.8%
(FPCore (re im) :precision binary64 (if (<= im 1450000000000.0) (cos re) (+ 0.5 (+ 0.5 (* im (+ 0.5 (* im (+ 0.25 (* im 0.08333333333333333)))))))))
double code(double re, double im) {
double tmp;
if (im <= 1450000000000.0) {
tmp = cos(re);
} else {
tmp = 0.5 + (0.5 + (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 <= 1450000000000.0d0) then
tmp = cos(re)
else
tmp = 0.5d0 + (0.5d0 + (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 <= 1450000000000.0) {
tmp = Math.cos(re);
} else {
tmp = 0.5 + (0.5 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333))))));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1450000000000.0: tmp = math.cos(re) else: tmp = 0.5 + (0.5 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333)))))) return tmp
function code(re, im) tmp = 0.0 if (im <= 1450000000000.0) tmp = cos(re); else tmp = Float64(0.5 + Float64(0.5 + 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 <= 1450000000000.0) tmp = cos(re); else tmp = 0.5 + (0.5 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333)))))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1450000000000.0], N[Cos[re], $MachinePrecision], N[(0.5 + N[(0.5 + 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 1450000000000:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;0.5 + \left(0.5 + im \cdot \left(0.5 + im \cdot \left(0.25 + im \cdot 0.08333333333333333\right)\right)\right)\\
\end{array}
\end{array}
if im < 1.45e12Initial 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.7%
if 1.45e12 < 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 77.6%
Taylor expanded in im around 0 57.9%
*-commutative57.9%
Simplified57.9%
(FPCore (re im) :precision binary64 (+ 0.5 (+ 0.5 (* im (+ 0.5 (* im (+ 0.25 (* im 0.08333333333333333))))))))
double code(double re, double im) {
return 0.5 + (0.5 + (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 = 0.5d0 + (0.5d0 + (im * (0.5d0 + (im * (0.25d0 + (im * 0.08333333333333333d0))))))
end function
public static double code(double re, double im) {
return 0.5 + (0.5 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333))))));
}
def code(re, im): return 0.5 + (0.5 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333))))))
function code(re, im) return Float64(0.5 + Float64(0.5 + Float64(im * Float64(0.5 + Float64(im * Float64(0.25 + Float64(im * 0.08333333333333333))))))) end
function tmp = code(re, im) tmp = 0.5 + (0.5 + (im * (0.5 + (im * (0.25 + (im * 0.08333333333333333)))))); end
code[re_, im_] := N[(0.5 + N[(0.5 + N[(im * N[(0.5 + N[(im * N[(0.25 + N[(im * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 + \left(0.5 + im \cdot \left(0.5 + im \cdot \left(0.25 + im \cdot 0.08333333333333333\right)\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 75.1%
Taylor expanded in re around 0 45.6%
Taylor expanded in im around 0 43.0%
*-commutative43.0%
Simplified43.0%
(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 75.1%
Taylor expanded in im around 0 74.2%
*-commutative74.2%
Simplified74.2%
Taylor expanded in re around 0 44.9%
Final simplification44.9%
(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 75.1%
Taylor expanded in im around 0 74.2%
*-commutative74.2%
Simplified74.2%
Taylor expanded in im around 0 49.0%
associate-*r*49.0%
*-commutative49.0%
distribute-rgt1-in49.0%
*-commutative49.0%
Simplified49.0%
Taylor expanded in re around 0 25.8%
(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 49.3%
Applied egg-rr27.9%
unpow-127.9%
Simplified27.9%
Taylor expanded in re around 0 25.8%
herbie shell --seed 2024111
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))