
(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 15 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp(-im) + exp(im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * (exp(-im) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp(-im) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
\end{array}
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp(-im) + exp(im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * (exp(-im) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp(-im) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (re im)
:precision binary64
(if (<= im 0.95)
(*
(* 0.5 (cos re))
(+ (+ 2.0 (* im im)) (* 0.08333333333333333 (pow im 4.0))))
(if (<= im 4e+48)
(* 0.5 (+ (exp (- im)) (exp im)))
(* (pow im 6.0) (* (cos re) 0.001388888888888889)))))
double code(double re, double im) {
double tmp;
if (im <= 0.95) {
tmp = (0.5 * cos(re)) * ((2.0 + (im * im)) + (0.08333333333333333 * pow(im, 4.0)));
} else if (im <= 4e+48) {
tmp = 0.5 * (exp(-im) + exp(im));
} else {
tmp = pow(im, 6.0) * (cos(re) * 0.001388888888888889);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 0.95d0) then
tmp = (0.5d0 * cos(re)) * ((2.0d0 + (im * im)) + (0.08333333333333333d0 * (im ** 4.0d0)))
else if (im <= 4d+48) then
tmp = 0.5d0 * (exp(-im) + exp(im))
else
tmp = (im ** 6.0d0) * (cos(re) * 0.001388888888888889d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 0.95) {
tmp = (0.5 * Math.cos(re)) * ((2.0 + (im * im)) + (0.08333333333333333 * Math.pow(im, 4.0)));
} else if (im <= 4e+48) {
tmp = 0.5 * (Math.exp(-im) + Math.exp(im));
} else {
tmp = Math.pow(im, 6.0) * (Math.cos(re) * 0.001388888888888889);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 0.95: tmp = (0.5 * math.cos(re)) * ((2.0 + (im * im)) + (0.08333333333333333 * math.pow(im, 4.0))) elif im <= 4e+48: tmp = 0.5 * (math.exp(-im) + math.exp(im)) else: tmp = math.pow(im, 6.0) * (math.cos(re) * 0.001388888888888889) return tmp
function code(re, im) tmp = 0.0 if (im <= 0.95) tmp = Float64(Float64(0.5 * cos(re)) * Float64(Float64(2.0 + Float64(im * im)) + Float64(0.08333333333333333 * (im ^ 4.0)))); elseif (im <= 4e+48) tmp = Float64(0.5 * Float64(exp(Float64(-im)) + exp(im))); else tmp = Float64((im ^ 6.0) * Float64(cos(re) * 0.001388888888888889)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 0.95) tmp = (0.5 * cos(re)) * ((2.0 + (im * im)) + (0.08333333333333333 * (im ^ 4.0))); elseif (im <= 4e+48) tmp = 0.5 * (exp(-im) + exp(im)); else tmp = (im ^ 6.0) * (cos(re) * 0.001388888888888889); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 0.95], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision] + N[(0.08333333333333333 * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 4e+48], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[im, 6.0], $MachinePrecision] * N[(N[Cos[re], $MachinePrecision] * 0.001388888888888889), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.95:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(\left(2 + im \cdot im\right) + 0.08333333333333333 \cdot {im}^{4}\right)\\
\mathbf{elif}\;im \leq 4 \cdot 10^{+48}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\
\mathbf{else}:\\
\;\;\;\;{im}^{6} \cdot \left(\cos re \cdot 0.001388888888888889\right)\\
\end{array}
\end{array}
if im < 0.94999999999999996Initial program 100.0%
Taylor expanded in im around 0 93.0%
associate-+r+93.0%
unpow293.0%
Simplified93.0%
if 0.94999999999999996 < im < 4.00000000000000018e48Initial program 99.8%
Taylor expanded in re around 0 59.9%
*-commutative59.9%
Simplified59.9%
if 4.00000000000000018e48 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
associate-+r+100.0%
unpow2100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
*-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
Simplified100.0%
Final simplification93.4%
(FPCore (re im)
:precision binary64
(if (<= im 5.6e-10)
(cos re)
(if (<= im 2.05e+152)
(* 0.5 (+ (exp (- im)) (exp im)))
(* im (* (* 0.5 (cos re)) im)))))
double code(double re, double im) {
double tmp;
if (im <= 5.6e-10) {
tmp = cos(re);
} else if (im <= 2.05e+152) {
tmp = 0.5 * (exp(-im) + exp(im));
} else {
tmp = im * ((0.5 * cos(re)) * 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.6d-10) then
tmp = cos(re)
else if (im <= 2.05d+152) then
tmp = 0.5d0 * (exp(-im) + exp(im))
else
tmp = im * ((0.5d0 * cos(re)) * im)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 5.6e-10) {
tmp = Math.cos(re);
} else if (im <= 2.05e+152) {
tmp = 0.5 * (Math.exp(-im) + Math.exp(im));
} else {
tmp = im * ((0.5 * Math.cos(re)) * im);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 5.6e-10: tmp = math.cos(re) elif im <= 2.05e+152: tmp = 0.5 * (math.exp(-im) + math.exp(im)) else: tmp = im * ((0.5 * math.cos(re)) * im) return tmp
function code(re, im) tmp = 0.0 if (im <= 5.6e-10) tmp = cos(re); elseif (im <= 2.05e+152) tmp = Float64(0.5 * Float64(exp(Float64(-im)) + exp(im))); else tmp = Float64(im * Float64(Float64(0.5 * cos(re)) * im)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 5.6e-10) tmp = cos(re); elseif (im <= 2.05e+152) tmp = 0.5 * (exp(-im) + exp(im)); else tmp = im * ((0.5 * cos(re)) * im); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 5.6e-10], N[Cos[re], $MachinePrecision], If[LessEqual[im, 2.05e+152], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(im * N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 5.6 \cdot 10^{-10}:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 2.05 \cdot 10^{+152}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\
\mathbf{else}:\\
\;\;\;\;im \cdot \left(\left(0.5 \cdot \cos re\right) \cdot im\right)\\
\end{array}
\end{array}
if im < 5.60000000000000031e-10Initial program 100.0%
Taylor expanded in im around 0 61.6%
if 5.60000000000000031e-10 < im < 2.0499999999999999e152Initial program 99.8%
Taylor expanded in re around 0 73.9%
*-commutative73.9%
Simplified73.9%
if 2.0499999999999999e152 < im Initial program 100.0%
Taylor expanded in im around 0 97.0%
unpow297.0%
Simplified97.0%
Taylor expanded in im around inf 97.0%
associate-*r*97.0%
*-commutative97.0%
unpow297.0%
associate-*l*97.0%
Simplified97.0%
Final simplification66.9%
(FPCore (re im)
:precision binary64
(if (<= im 5.6e-10)
(cos re)
(if (<= im 4e+48)
(* 0.5 (+ (exp (- im)) (exp im)))
(* (pow im 6.0) (* (cos re) 0.001388888888888889)))))
double code(double re, double im) {
double tmp;
if (im <= 5.6e-10) {
tmp = cos(re);
} else if (im <= 4e+48) {
tmp = 0.5 * (exp(-im) + exp(im));
} else {
tmp = pow(im, 6.0) * (cos(re) * 0.001388888888888889);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 5.6d-10) then
tmp = cos(re)
else if (im <= 4d+48) then
tmp = 0.5d0 * (exp(-im) + exp(im))
else
tmp = (im ** 6.0d0) * (cos(re) * 0.001388888888888889d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 5.6e-10) {
tmp = Math.cos(re);
} else if (im <= 4e+48) {
tmp = 0.5 * (Math.exp(-im) + Math.exp(im));
} else {
tmp = Math.pow(im, 6.0) * (Math.cos(re) * 0.001388888888888889);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 5.6e-10: tmp = math.cos(re) elif im <= 4e+48: tmp = 0.5 * (math.exp(-im) + math.exp(im)) else: tmp = math.pow(im, 6.0) * (math.cos(re) * 0.001388888888888889) return tmp
function code(re, im) tmp = 0.0 if (im <= 5.6e-10) tmp = cos(re); elseif (im <= 4e+48) tmp = Float64(0.5 * Float64(exp(Float64(-im)) + exp(im))); else tmp = Float64((im ^ 6.0) * Float64(cos(re) * 0.001388888888888889)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 5.6e-10) tmp = cos(re); elseif (im <= 4e+48) tmp = 0.5 * (exp(-im) + exp(im)); else tmp = (im ^ 6.0) * (cos(re) * 0.001388888888888889); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 5.6e-10], N[Cos[re], $MachinePrecision], If[LessEqual[im, 4e+48], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[im, 6.0], $MachinePrecision] * N[(N[Cos[re], $MachinePrecision] * 0.001388888888888889), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 5.6 \cdot 10^{-10}:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 4 \cdot 10^{+48}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\
\mathbf{else}:\\
\;\;\;\;{im}^{6} \cdot \left(\cos re \cdot 0.001388888888888889\right)\\
\end{array}
\end{array}
if im < 5.60000000000000031e-10Initial program 100.0%
Taylor expanded in im around 0 61.6%
if 5.60000000000000031e-10 < im < 4.00000000000000018e48Initial program 99.6%
Taylor expanded in re around 0 57.9%
*-commutative57.9%
Simplified57.9%
if 4.00000000000000018e48 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
associate-+r+100.0%
unpow2100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
*-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
Simplified100.0%
Final simplification68.4%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (cos re))) (t_1 (+ 2.0 (* im im))))
(if (<= im 1020.0)
(* t_0 t_1)
(if (<= im 1.35e+154)
(fma 0.5 t_1 (* -0.25 (* t_1 (* re re))))
(* im (* t_0 im))))))
double code(double re, double im) {
double t_0 = 0.5 * cos(re);
double t_1 = 2.0 + (im * im);
double tmp;
if (im <= 1020.0) {
tmp = t_0 * t_1;
} else if (im <= 1.35e+154) {
tmp = fma(0.5, t_1, (-0.25 * (t_1 * (re * re))));
} else {
tmp = im * (t_0 * im);
}
return tmp;
}
function code(re, im) t_0 = Float64(0.5 * cos(re)) t_1 = Float64(2.0 + Float64(im * im)) tmp = 0.0 if (im <= 1020.0) tmp = Float64(t_0 * t_1); elseif (im <= 1.35e+154) tmp = fma(0.5, t_1, Float64(-0.25 * Float64(t_1 * Float64(re * re)))); else tmp = Float64(im * Float64(t_0 * im)); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, 1020.0], N[(t$95$0 * t$95$1), $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(0.5 * t$95$1 + N[(-0.25 * N[(t$95$1 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(im * N[(t$95$0 * im), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \cos re\\
t_1 := 2 + im \cdot im\\
\mathbf{if}\;im \leq 1020:\\
\;\;\;\;t_0 \cdot t_1\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\mathsf{fma}\left(0.5, t_1, -0.25 \cdot \left(t_1 \cdot \left(re \cdot re\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;im \cdot \left(t_0 \cdot im\right)\\
\end{array}
\end{array}
if im < 1020Initial program 100.0%
Taylor expanded in im around 0 81.0%
unpow281.0%
Simplified81.0%
if 1020 < im < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in im around 0 6.2%
unpow26.2%
Simplified6.2%
Taylor expanded in re around 0 25.0%
fma-def25.0%
unpow225.0%
*-commutative25.0%
unpow225.0%
unpow225.0%
Simplified25.0%
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%
associate-*r*100.0%
*-commutative100.0%
unpow2100.0%
associate-*l*100.0%
Simplified100.0%
Final simplification78.0%
(FPCore (re im)
:precision binary64
(if (<= im 1020.0)
(cos re)
(if (<= im 1.95e+154)
(* im (* im (fma -0.25 (* re re) 0.5)))
(* im (* (* 0.5 (cos re)) im)))))
double code(double re, double im) {
double tmp;
if (im <= 1020.0) {
tmp = cos(re);
} else if (im <= 1.95e+154) {
tmp = im * (im * fma(-0.25, (re * re), 0.5));
} else {
tmp = im * ((0.5 * cos(re)) * im);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 1020.0) tmp = cos(re); elseif (im <= 1.95e+154) tmp = Float64(im * Float64(im * fma(-0.25, Float64(re * re), 0.5))); else tmp = Float64(im * Float64(Float64(0.5 * cos(re)) * im)); end return tmp end
code[re_, im_] := If[LessEqual[im, 1020.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.95e+154], N[(im * N[(im * N[(-0.25 * N[(re * re), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(im * N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1020:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.95 \cdot 10^{+154}:\\
\;\;\;\;im \cdot \left(im \cdot \mathsf{fma}\left(-0.25, re \cdot re, 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;im \cdot \left(\left(0.5 \cdot \cos re\right) \cdot im\right)\\
\end{array}
\end{array}
if im < 1020Initial program 100.0%
Taylor expanded in im around 0 61.1%
if 1020 < im < 1.9500000000000001e154Initial program 100.0%
Taylor expanded in im around 0 6.2%
unpow26.2%
Simplified6.2%
Taylor expanded in re around 0 25.0%
fma-def25.0%
unpow225.0%
*-commutative25.0%
unpow225.0%
unpow225.0%
Simplified25.0%
Taylor expanded in im around inf 25.0%
unpow225.0%
*-commutative25.0%
unpow225.0%
associate-*l*25.0%
+-commutative25.0%
fma-def25.0%
Simplified25.0%
if 1.9500000000000001e154 < 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%
associate-*r*100.0%
*-commutative100.0%
unpow2100.0%
associate-*l*100.0%
Simplified100.0%
Final simplification62.1%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (cos re))))
(if (<= im 1100.0)
(* t_0 (+ 2.0 (* im im)))
(if (<= im 2.7e+154)
(* im (* im (fma -0.25 (* re re) 0.5)))
(* im (* t_0 im))))))
double code(double re, double im) {
double t_0 = 0.5 * cos(re);
double tmp;
if (im <= 1100.0) {
tmp = t_0 * (2.0 + (im * im));
} else if (im <= 2.7e+154) {
tmp = im * (im * fma(-0.25, (re * re), 0.5));
} else {
tmp = im * (t_0 * im);
}
return tmp;
}
function code(re, im) t_0 = Float64(0.5 * cos(re)) tmp = 0.0 if (im <= 1100.0) tmp = Float64(t_0 * Float64(2.0 + Float64(im * im))); elseif (im <= 2.7e+154) tmp = Float64(im * Float64(im * fma(-0.25, Float64(re * re), 0.5))); else tmp = Float64(im * Float64(t_0 * im)); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, 1100.0], N[(t$95$0 * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 2.7e+154], N[(im * N[(im * N[(-0.25 * N[(re * re), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(im * N[(t$95$0 * im), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \cos re\\
\mathbf{if}\;im \leq 1100:\\
\;\;\;\;t_0 \cdot \left(2 + im \cdot im\right)\\
\mathbf{elif}\;im \leq 2.7 \cdot 10^{+154}:\\
\;\;\;\;im \cdot \left(im \cdot \mathsf{fma}\left(-0.25, re \cdot re, 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;im \cdot \left(t_0 \cdot im\right)\\
\end{array}
\end{array}
if im < 1100Initial program 100.0%
Taylor expanded in im around 0 81.0%
unpow281.0%
Simplified81.0%
if 1100 < im < 2.70000000000000006e154Initial program 100.0%
Taylor expanded in im around 0 6.2%
unpow26.2%
Simplified6.2%
Taylor expanded in re around 0 25.0%
fma-def25.0%
unpow225.0%
*-commutative25.0%
unpow225.0%
unpow225.0%
Simplified25.0%
Taylor expanded in im around inf 25.0%
unpow225.0%
*-commutative25.0%
unpow225.0%
associate-*l*25.0%
+-commutative25.0%
fma-def25.0%
Simplified25.0%
if 2.70000000000000006e154 < 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%
associate-*r*100.0%
*-commutative100.0%
unpow2100.0%
associate-*l*100.0%
Simplified100.0%
Final simplification78.0%
(FPCore (re im)
:precision binary64
(if (<= im 2800.0)
(cos re)
(if (<= im 2.56e+154)
(* (* im im) (+ 0.5 (* -0.25 (* re re))))
(* im (* (* 0.5 (cos re)) im)))))
double code(double re, double im) {
double tmp;
if (im <= 2800.0) {
tmp = cos(re);
} else if (im <= 2.56e+154) {
tmp = (im * im) * (0.5 + (-0.25 * (re * re)));
} else {
tmp = im * ((0.5 * cos(re)) * im);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 2800.0d0) then
tmp = cos(re)
else if (im <= 2.56d+154) then
tmp = (im * im) * (0.5d0 + ((-0.25d0) * (re * re)))
else
tmp = im * ((0.5d0 * cos(re)) * im)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 2800.0) {
tmp = Math.cos(re);
} else if (im <= 2.56e+154) {
tmp = (im * im) * (0.5 + (-0.25 * (re * re)));
} else {
tmp = im * ((0.5 * Math.cos(re)) * im);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 2800.0: tmp = math.cos(re) elif im <= 2.56e+154: tmp = (im * im) * (0.5 + (-0.25 * (re * re))) else: tmp = im * ((0.5 * math.cos(re)) * im) return tmp
function code(re, im) tmp = 0.0 if (im <= 2800.0) tmp = cos(re); elseif (im <= 2.56e+154) tmp = Float64(Float64(im * im) * Float64(0.5 + Float64(-0.25 * Float64(re * re)))); else tmp = Float64(im * Float64(Float64(0.5 * cos(re)) * im)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 2800.0) tmp = cos(re); elseif (im <= 2.56e+154) tmp = (im * im) * (0.5 + (-0.25 * (re * re))); else tmp = im * ((0.5 * cos(re)) * im); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 2800.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 2.56e+154], N[(N[(im * im), $MachinePrecision] * N[(0.5 + N[(-0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(im * N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 2800:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 2.56 \cdot 10^{+154}:\\
\;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right)\\
\mathbf{else}:\\
\;\;\;\;im \cdot \left(\left(0.5 \cdot \cos re\right) \cdot im\right)\\
\end{array}
\end{array}
if im < 2800Initial program 100.0%
Taylor expanded in im around 0 61.1%
if 2800 < im < 2.5600000000000001e154Initial program 100.0%
Taylor expanded in im around 0 6.2%
unpow26.2%
Simplified6.2%
Taylor expanded in re around 0 25.0%
fma-def25.0%
unpow225.0%
*-commutative25.0%
unpow225.0%
unpow225.0%
Simplified25.0%
Taylor expanded in im around inf 25.0%
unpow225.0%
*-commutative25.0%
unpow225.0%
Simplified25.0%
if 2.5600000000000001e154 < 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%
associate-*r*100.0%
*-commutative100.0%
unpow2100.0%
associate-*l*100.0%
Simplified100.0%
Final simplification62.1%
(FPCore (re im)
:precision binary64
(if (<= im 1020.0)
(cos re)
(if (or (<= im 2e+154) (and (not (<= im 5e+240)) (<= im 1.16e+275)))
(* (* im im) (+ 0.5 (* -0.25 (* re re))))
(+ 1.0 (* 0.5 (* im im))))))
double code(double re, double im) {
double tmp;
if (im <= 1020.0) {
tmp = cos(re);
} else if ((im <= 2e+154) || (!(im <= 5e+240) && (im <= 1.16e+275))) {
tmp = (im * im) * (0.5 + (-0.25 * (re * re)));
} else {
tmp = 1.0 + (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 <= 1020.0d0) then
tmp = cos(re)
else if ((im <= 2d+154) .or. (.not. (im <= 5d+240)) .and. (im <= 1.16d+275)) then
tmp = (im * im) * (0.5d0 + ((-0.25d0) * (re * re)))
else
tmp = 1.0d0 + (0.5d0 * (im * im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1020.0) {
tmp = Math.cos(re);
} else if ((im <= 2e+154) || (!(im <= 5e+240) && (im <= 1.16e+275))) {
tmp = (im * im) * (0.5 + (-0.25 * (re * re)));
} else {
tmp = 1.0 + (0.5 * (im * im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1020.0: tmp = math.cos(re) elif (im <= 2e+154) or (not (im <= 5e+240) and (im <= 1.16e+275)): tmp = (im * im) * (0.5 + (-0.25 * (re * re))) else: tmp = 1.0 + (0.5 * (im * im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 1020.0) tmp = cos(re); elseif ((im <= 2e+154) || (!(im <= 5e+240) && (im <= 1.16e+275))) tmp = Float64(Float64(im * im) * Float64(0.5 + Float64(-0.25 * Float64(re * re)))); else tmp = Float64(1.0 + Float64(0.5 * Float64(im * im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1020.0) tmp = cos(re); elseif ((im <= 2e+154) || (~((im <= 5e+240)) && (im <= 1.16e+275))) tmp = (im * im) * (0.5 + (-0.25 * (re * re))); else tmp = 1.0 + (0.5 * (im * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1020.0], N[Cos[re], $MachinePrecision], If[Or[LessEqual[im, 2e+154], And[N[Not[LessEqual[im, 5e+240]], $MachinePrecision], LessEqual[im, 1.16e+275]]], N[(N[(im * im), $MachinePrecision] * N[(0.5 + N[(-0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1020:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 2 \cdot 10^{+154} \lor \neg \left(im \leq 5 \cdot 10^{+240}\right) \land im \leq 1.16 \cdot 10^{+275}:\\
\;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right)\\
\mathbf{else}:\\
\;\;\;\;1 + 0.5 \cdot \left(im \cdot im\right)\\
\end{array}
\end{array}
if im < 1020Initial program 100.0%
Taylor expanded in im around 0 61.1%
if 1020 < im < 2.00000000000000007e154 or 5.0000000000000003e240 < im < 1.16e275Initial program 100.0%
Taylor expanded in im around 0 32.6%
unpow232.6%
Simplified32.6%
Taylor expanded in re around 0 18.0%
fma-def18.0%
unpow218.0%
*-commutative18.0%
unpow218.0%
unpow218.0%
Simplified18.0%
Taylor expanded in im around inf 43.0%
unpow243.0%
*-commutative43.0%
unpow243.0%
Simplified43.0%
if 2.00000000000000007e154 < im < 5.0000000000000003e240 or 1.16e275 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in re around 0 84.2%
distribute-rgt-in84.2%
metadata-eval84.2%
unpow284.2%
Simplified84.2%
Final simplification60.5%
(FPCore (re im)
:precision binary64
(if (or (<= im 1100.0)
(not
(or (<= im 1.5e+154) (and (not (<= im 3.2e+241)) (<= im 1e+275)))))
(+ 1.0 (* 0.5 (* im im)))
(* (* im im) (+ 0.5 (* -0.25 (* re re))))))
double code(double re, double im) {
double tmp;
if ((im <= 1100.0) || !((im <= 1.5e+154) || (!(im <= 3.2e+241) && (im <= 1e+275)))) {
tmp = 1.0 + (0.5 * (im * im));
} else {
tmp = (im * im) * (0.5 + (-0.25 * (re * re)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((im <= 1100.0d0) .or. (.not. (im <= 1.5d+154) .or. (.not. (im <= 3.2d+241)) .and. (im <= 1d+275))) then
tmp = 1.0d0 + (0.5d0 * (im * im))
else
tmp = (im * im) * (0.5d0 + ((-0.25d0) * (re * re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((im <= 1100.0) || !((im <= 1.5e+154) || (!(im <= 3.2e+241) && (im <= 1e+275)))) {
tmp = 1.0 + (0.5 * (im * im));
} else {
tmp = (im * im) * (0.5 + (-0.25 * (re * re)));
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= 1100.0) or not ((im <= 1.5e+154) or (not (im <= 3.2e+241) and (im <= 1e+275))): tmp = 1.0 + (0.5 * (im * im)) else: tmp = (im * im) * (0.5 + (-0.25 * (re * re))) return tmp
function code(re, im) tmp = 0.0 if ((im <= 1100.0) || !((im <= 1.5e+154) || (!(im <= 3.2e+241) && (im <= 1e+275)))) tmp = Float64(1.0 + Float64(0.5 * Float64(im * im))); else tmp = Float64(Float64(im * im) * Float64(0.5 + Float64(-0.25 * Float64(re * re)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((im <= 1100.0) || ~(((im <= 1.5e+154) || (~((im <= 3.2e+241)) && (im <= 1e+275))))) tmp = 1.0 + (0.5 * (im * im)); else tmp = (im * im) * (0.5 + (-0.25 * (re * re))); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, 1100.0], N[Not[Or[LessEqual[im, 1.5e+154], And[N[Not[LessEqual[im, 3.2e+241]], $MachinePrecision], LessEqual[im, 1e+275]]]], $MachinePrecision]], N[(1.0 + N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(im * im), $MachinePrecision] * N[(0.5 + N[(-0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1100 \lor \neg \left(im \leq 1.5 \cdot 10^{+154} \lor \neg \left(im \leq 3.2 \cdot 10^{+241}\right) \land im \leq 10^{+275}\right):\\
\;\;\;\;1 + 0.5 \cdot \left(im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right)\\
\end{array}
\end{array}
if im < 1100 or 1.50000000000000013e154 < im < 3.20000000000000004e241 or 9.9999999999999996e274 < im Initial program 100.0%
Taylor expanded in im around 0 82.6%
unpow282.6%
Simplified82.6%
Taylor expanded in re around 0 49.1%
distribute-rgt-in49.1%
metadata-eval49.1%
unpow249.1%
Simplified49.1%
if 1100 < im < 1.50000000000000013e154 or 3.20000000000000004e241 < im < 9.9999999999999996e274Initial program 100.0%
Taylor expanded in im around 0 32.6%
unpow232.6%
Simplified32.6%
Taylor expanded in re around 0 18.0%
fma-def18.0%
unpow218.0%
*-commutative18.0%
unpow218.0%
unpow218.0%
Simplified18.0%
Taylor expanded in im around inf 43.0%
unpow243.0%
*-commutative43.0%
unpow243.0%
Simplified43.0%
Final simplification48.4%
(FPCore (re im) :precision binary64 (if (or (<= im 1020.0) (not (<= im 1.35e+154))) (+ 1.0 (* 0.5 (* im im))) (* (+ 0.5 (* -0.25 (* re re))) 10077696.0)))
double code(double re, double im) {
double tmp;
if ((im <= 1020.0) || !(im <= 1.35e+154)) {
tmp = 1.0 + (0.5 * (im * im));
} else {
tmp = (0.5 + (-0.25 * (re * re))) * 10077696.0;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((im <= 1020.0d0) .or. (.not. (im <= 1.35d+154))) then
tmp = 1.0d0 + (0.5d0 * (im * im))
else
tmp = (0.5d0 + ((-0.25d0) * (re * re))) * 10077696.0d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((im <= 1020.0) || !(im <= 1.35e+154)) {
tmp = 1.0 + (0.5 * (im * im));
} else {
tmp = (0.5 + (-0.25 * (re * re))) * 10077696.0;
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= 1020.0) or not (im <= 1.35e+154): tmp = 1.0 + (0.5 * (im * im)) else: tmp = (0.5 + (-0.25 * (re * re))) * 10077696.0 return tmp
function code(re, im) tmp = 0.0 if ((im <= 1020.0) || !(im <= 1.35e+154)) tmp = Float64(1.0 + Float64(0.5 * Float64(im * im))); else tmp = Float64(Float64(0.5 + Float64(-0.25 * Float64(re * re))) * 10077696.0); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((im <= 1020.0) || ~((im <= 1.35e+154))) tmp = 1.0 + (0.5 * (im * im)); else tmp = (0.5 + (-0.25 * (re * re))) * 10077696.0; end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, 1020.0], N[Not[LessEqual[im, 1.35e+154]], $MachinePrecision]], N[(1.0 + N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 + N[(-0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 10077696.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1020 \lor \neg \left(im \leq 1.35 \cdot 10^{+154}\right):\\
\;\;\;\;1 + 0.5 \cdot \left(im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right) \cdot 10077696\\
\end{array}
\end{array}
if im < 1020 or 1.35000000000000003e154 < im Initial program 100.0%
Taylor expanded in im around 0 83.3%
unpow283.3%
Simplified83.3%
Taylor expanded in re around 0 50.3%
distribute-rgt-in50.3%
metadata-eval50.3%
unpow250.3%
Simplified50.3%
if 1020 < im < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in re around 0 0.0%
associate-*r*0.0%
distribute-rgt-out69.6%
unpow269.6%
Simplified69.6%
Applied egg-rr23.3%
Final simplification47.8%
(FPCore (re im) :precision binary64 (if (or (<= im 2800.0) (not (<= im 1.3e+154))) (+ 1.0 (* 0.5 (* im im))) (+ 1.0 (* (* re re) -0.5))))
double code(double re, double im) {
double tmp;
if ((im <= 2800.0) || !(im <= 1.3e+154)) {
tmp = 1.0 + (0.5 * (im * im));
} else {
tmp = 1.0 + ((re * re) * -0.5);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((im <= 2800.0d0) .or. (.not. (im <= 1.3d+154))) then
tmp = 1.0d0 + (0.5d0 * (im * im))
else
tmp = 1.0d0 + ((re * re) * (-0.5d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((im <= 2800.0) || !(im <= 1.3e+154)) {
tmp = 1.0 + (0.5 * (im * im));
} else {
tmp = 1.0 + ((re * re) * -0.5);
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= 2800.0) or not (im <= 1.3e+154): tmp = 1.0 + (0.5 * (im * im)) else: tmp = 1.0 + ((re * re) * -0.5) return tmp
function code(re, im) tmp = 0.0 if ((im <= 2800.0) || !(im <= 1.3e+154)) tmp = Float64(1.0 + Float64(0.5 * Float64(im * im))); else tmp = Float64(1.0 + Float64(Float64(re * re) * -0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((im <= 2800.0) || ~((im <= 1.3e+154))) tmp = 1.0 + (0.5 * (im * im)); else tmp = 1.0 + ((re * re) * -0.5); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, 2800.0], N[Not[LessEqual[im, 1.3e+154]], $MachinePrecision]], N[(1.0 + N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(N[(re * re), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 2800 \lor \neg \left(im \leq 1.3 \cdot 10^{+154}\right):\\
\;\;\;\;1 + 0.5 \cdot \left(im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;1 + \left(re \cdot re\right) \cdot -0.5\\
\end{array}
\end{array}
if im < 2800 or 1.29999999999999994e154 < im Initial program 100.0%
Taylor expanded in im around 0 83.3%
unpow283.3%
Simplified83.3%
Taylor expanded in re around 0 50.3%
distribute-rgt-in50.3%
metadata-eval50.3%
unpow250.3%
Simplified50.3%
if 2800 < im < 1.29999999999999994e154Initial program 100.0%
Taylor expanded in im around 0 6.2%
unpow26.2%
Simplified6.2%
Taylor expanded in re around 0 25.0%
fma-def25.0%
unpow225.0%
*-commutative25.0%
unpow225.0%
unpow225.0%
Simplified25.0%
Taylor expanded in im around 0 23.3%
+-commutative23.3%
unpow223.3%
Simplified23.3%
Final simplification47.8%
(FPCore (re im) :precision binary64 (+ 1.0 (* 0.5 (* im im))))
double code(double re, double im) {
return 1.0 + (0.5 * (im * im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 1.0d0 + (0.5d0 * (im * im))
end function
public static double code(double re, double im) {
return 1.0 + (0.5 * (im * im));
}
def code(re, im): return 1.0 + (0.5 * (im * im))
function code(re, im) return Float64(1.0 + Float64(0.5 * Float64(im * im))) end
function tmp = code(re, im) tmp = 1.0 + (0.5 * (im * im)); end
code[re_, im_] := N[(1.0 + N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + 0.5 \cdot \left(im \cdot im\right)
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 76.4%
unpow276.4%
Simplified76.4%
Taylor expanded in re around 0 46.2%
distribute-rgt-in46.2%
metadata-eval46.2%
unpow246.2%
Simplified46.2%
Final simplification46.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%
Taylor expanded in im around 0 76.4%
unpow276.4%
Simplified76.4%
Applied egg-rr3.4%
+-commutative3.4%
Simplified3.4%
Taylor expanded in re around 0 3.9%
Final simplification3.9%
(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%
Applied egg-rr24.9%
+-inverses24.9%
+-rgt-identity24.9%
*-inverses24.9%
Simplified24.9%
Final simplification24.9%
herbie shell --seed 2023208
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))