
(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) (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%
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 1.35) (+ (cos re) (* (cos re) (* 0.5 (* im im)))) (* (cos re) (+ 0.001953125 (* 0.5 (exp im))))))
double code(double re, double im) {
double tmp;
if (im <= 1.35) {
tmp = cos(re) + (cos(re) * (0.5 * (im * im)));
} else {
tmp = cos(re) * (0.001953125 + (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 <= 1.35d0) then
tmp = cos(re) + (cos(re) * (0.5d0 * (im * im)))
else
tmp = cos(re) * (0.001953125d0 + (0.5d0 * exp(im)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.35) {
tmp = Math.cos(re) + (Math.cos(re) * (0.5 * (im * im)));
} else {
tmp = Math.cos(re) * (0.001953125 + (0.5 * Math.exp(im)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.35: tmp = math.cos(re) + (math.cos(re) * (0.5 * (im * im))) else: tmp = math.cos(re) * (0.001953125 + (0.5 * math.exp(im))) return tmp
function code(re, im) tmp = 0.0 if (im <= 1.35) tmp = Float64(cos(re) + Float64(cos(re) * Float64(0.5 * Float64(im * im)))); else tmp = Float64(cos(re) * Float64(0.001953125 + Float64(0.5 * exp(im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.35) tmp = cos(re) + (cos(re) * (0.5 * (im * im))); else tmp = cos(re) * (0.001953125 + (0.5 * exp(im))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.35], N[(N[Cos[re], $MachinePrecision] + N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(0.001953125 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.35:\\
\;\;\;\;\cos re + \cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left(0.001953125 + 0.5 \cdot e^{im}\right)\\
\end{array}
\end{array}
if im < 1.3500000000000001Initial program 100.0%
Taylor expanded in im around 0 84.5%
unpow284.5%
Simplified84.5%
+-commutative84.5%
distribute-lft-in84.5%
*-commutative84.5%
associate-*l*84.5%
*-commutative84.5%
associate-*r*84.5%
metadata-eval84.5%
*-un-lft-identity84.5%
Applied egg-rr84.5%
if 1.3500000000000001 < im Initial program 100.0%
Simplified100.0%
Applied egg-rr99.2%
Taylor expanded in re around inf 99.2%
Final simplification88.3%
(FPCore (re im) :precision binary64 (if (<= im 1.35) (* (* (cos re) 0.5) (+ (* im im) 2.0)) (* (cos re) (+ 0.001953125 (* 0.5 (exp im))))))
double code(double re, double im) {
double tmp;
if (im <= 1.35) {
tmp = (cos(re) * 0.5) * ((im * im) + 2.0);
} else {
tmp = cos(re) * (0.001953125 + (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 <= 1.35d0) then
tmp = (cos(re) * 0.5d0) * ((im * im) + 2.0d0)
else
tmp = cos(re) * (0.001953125d0 + (0.5d0 * exp(im)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.35) {
tmp = (Math.cos(re) * 0.5) * ((im * im) + 2.0);
} else {
tmp = Math.cos(re) * (0.001953125 + (0.5 * Math.exp(im)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.35: tmp = (math.cos(re) * 0.5) * ((im * im) + 2.0) else: tmp = math.cos(re) * (0.001953125 + (0.5 * math.exp(im))) return tmp
function code(re, im) tmp = 0.0 if (im <= 1.35) tmp = Float64(Float64(cos(re) * 0.5) * Float64(Float64(im * im) + 2.0)); else tmp = Float64(cos(re) * Float64(0.001953125 + Float64(0.5 * exp(im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.35) tmp = (cos(re) * 0.5) * ((im * im) + 2.0); else tmp = cos(re) * (0.001953125 + (0.5 * exp(im))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.35], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(N[(im * im), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(0.001953125 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.35:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(im \cdot im + 2\right)\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left(0.001953125 + 0.5 \cdot e^{im}\right)\\
\end{array}
\end{array}
if im < 1.3500000000000001Initial program 100.0%
Taylor expanded in im around 0 84.5%
unpow284.5%
Simplified84.5%
if 1.3500000000000001 < im Initial program 100.0%
Simplified100.0%
Applied egg-rr99.2%
Taylor expanded in re around inf 99.2%
Final simplification88.3%
(FPCore (re im)
:precision binary64
(if (<= im 6.2)
(* (* (cos re) 0.5) (+ (* im im) 2.0))
(if (<= im 1.3e+103)
(+ 0.001953125 (* 0.5 (exp im)))
(*
(cos re)
(+
(+ 0.501953125 (* 0.5 im))
(* (* im im) (+ (* im 0.08333333333333333) 0.25)))))))
double code(double re, double im) {
double tmp;
if (im <= 6.2) {
tmp = (cos(re) * 0.5) * ((im * im) + 2.0);
} else if (im <= 1.3e+103) {
tmp = 0.001953125 + (0.5 * exp(im));
} else {
tmp = cos(re) * ((0.501953125 + (0.5 * im)) + ((im * im) * ((im * 0.08333333333333333) + 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 <= 6.2d0) then
tmp = (cos(re) * 0.5d0) * ((im * im) + 2.0d0)
else if (im <= 1.3d+103) then
tmp = 0.001953125d0 + (0.5d0 * exp(im))
else
tmp = cos(re) * ((0.501953125d0 + (0.5d0 * im)) + ((im * im) * ((im * 0.08333333333333333d0) + 0.25d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 6.2) {
tmp = (Math.cos(re) * 0.5) * ((im * im) + 2.0);
} else if (im <= 1.3e+103) {
tmp = 0.001953125 + (0.5 * Math.exp(im));
} else {
tmp = Math.cos(re) * ((0.501953125 + (0.5 * im)) + ((im * im) * ((im * 0.08333333333333333) + 0.25)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 6.2: tmp = (math.cos(re) * 0.5) * ((im * im) + 2.0) elif im <= 1.3e+103: tmp = 0.001953125 + (0.5 * math.exp(im)) else: tmp = math.cos(re) * ((0.501953125 + (0.5 * im)) + ((im * im) * ((im * 0.08333333333333333) + 0.25))) return tmp
function code(re, im) tmp = 0.0 if (im <= 6.2) tmp = Float64(Float64(cos(re) * 0.5) * Float64(Float64(im * im) + 2.0)); elseif (im <= 1.3e+103) tmp = Float64(0.001953125 + Float64(0.5 * exp(im))); else tmp = Float64(cos(re) * Float64(Float64(0.501953125 + Float64(0.5 * im)) + Float64(Float64(im * im) * Float64(Float64(im * 0.08333333333333333) + 0.25)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 6.2) tmp = (cos(re) * 0.5) * ((im * im) + 2.0); elseif (im <= 1.3e+103) tmp = 0.001953125 + (0.5 * exp(im)); else tmp = cos(re) * ((0.501953125 + (0.5 * im)) + ((im * im) * ((im * 0.08333333333333333) + 0.25))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 6.2], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(N[(im * im), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.3e+103], N[(0.001953125 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(N[(0.501953125 + N[(0.5 * im), $MachinePrecision]), $MachinePrecision] + N[(N[(im * im), $MachinePrecision] * N[(N[(im * 0.08333333333333333), $MachinePrecision] + 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 6.2:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(im \cdot im + 2\right)\\
\mathbf{elif}\;im \leq 1.3 \cdot 10^{+103}:\\
\;\;\;\;0.001953125 + 0.5 \cdot e^{im}\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left(\left(0.501953125 + 0.5 \cdot im\right) + \left(im \cdot im\right) \cdot \left(im \cdot 0.08333333333333333 + 0.25\right)\right)\\
\end{array}
\end{array}
if im < 6.20000000000000018Initial program 100.0%
Taylor expanded in im around 0 84.2%
unpow284.2%
Simplified84.2%
if 6.20000000000000018 < im < 1.3000000000000001e103Initial program 100.0%
Simplified100.0%
Applied egg-rr100.0%
Taylor expanded in re around 0 64.6%
if 1.3000000000000001e103 < im Initial program 100.0%
Simplified100.0%
Applied egg-rr100.0%
Taylor expanded in im around 0 100.0%
associate-+r+100.0%
+-commutative100.0%
+-commutative100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
associate-*r*100.0%
unpow2100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
distribute-lft-out100.0%
cube-mult100.0%
associate-*r*100.0%
Simplified100.0%
Final simplification84.7%
(FPCore (re im)
:precision binary64
(if (<= im 6.2)
(cos re)
(if (<= im 2.3e+154)
(+ 0.001953125 (* 0.5 (exp im)))
(if (<= im 5e+165)
(* 0.5 (* im (+ im (* -0.5 (* im (* re re))))))
(* 0.5 (fma im im 2.0))))))
double code(double re, double im) {
double tmp;
if (im <= 6.2) {
tmp = cos(re);
} else if (im <= 2.3e+154) {
tmp = 0.001953125 + (0.5 * exp(im));
} else if (im <= 5e+165) {
tmp = 0.5 * (im * (im + (-0.5 * (im * (re * re)))));
} else {
tmp = 0.5 * fma(im, im, 2.0);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 6.2) tmp = cos(re); elseif (im <= 2.3e+154) tmp = Float64(0.001953125 + Float64(0.5 * exp(im))); elseif (im <= 5e+165) tmp = Float64(0.5 * Float64(im * Float64(im + Float64(-0.5 * Float64(im * Float64(re * re)))))); else tmp = Float64(0.5 * fma(im, im, 2.0)); end return tmp end
code[re_, im_] := If[LessEqual[im, 6.2], N[Cos[re], $MachinePrecision], If[LessEqual[im, 2.3e+154], N[(0.001953125 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 5e+165], N[(0.5 * N[(im * N[(im + N[(-0.5 * N[(im * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 6.2:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 2.3 \cdot 10^{+154}:\\
\;\;\;\;0.001953125 + 0.5 \cdot e^{im}\\
\mathbf{elif}\;im \leq 5 \cdot 10^{+165}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(im + -0.5 \cdot \left(im \cdot \left(re \cdot re\right)\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{fma}\left(im, im, 2\right)\\
\end{array}
\end{array}
if im < 6.20000000000000018Initial program 100.0%
Taylor expanded in im around 0 84.2%
unpow284.2%
Simplified84.2%
Taylor expanded in im around 0 64.6%
if 6.20000000000000018 < im < 2.3e154Initial program 100.0%
Simplified100.0%
Applied egg-rr100.0%
Taylor expanded in re around 0 65.2%
if 2.3e154 < im < 4.9999999999999997e165Initial program 100.0%
Taylor expanded in im around 0 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
unpow2100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in re around 0 100.0%
unpow2100.0%
Simplified100.0%
if 4.9999999999999997e165 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in re around 0 96.2%
unpow296.2%
+-commutative96.2%
fma-udef96.2%
Simplified96.2%
Final simplification68.4%
(FPCore (re im)
:precision binary64
(if (<= im 6.2)
(cos re)
(if (<= im 1.35e+154)
(+ 0.001953125 (* 0.5 (exp im)))
(* 0.5 (* im (* (cos re) im))))))
double code(double re, double im) {
double tmp;
if (im <= 6.2) {
tmp = cos(re);
} else if (im <= 1.35e+154) {
tmp = 0.001953125 + (0.5 * exp(im));
} else {
tmp = 0.5 * (im * (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 <= 6.2d0) then
tmp = cos(re)
else if (im <= 1.35d+154) then
tmp = 0.001953125d0 + (0.5d0 * exp(im))
else
tmp = 0.5d0 * (im * (cos(re) * im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 6.2) {
tmp = Math.cos(re);
} else if (im <= 1.35e+154) {
tmp = 0.001953125 + (0.5 * Math.exp(im));
} else {
tmp = 0.5 * (im * (Math.cos(re) * im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 6.2: tmp = math.cos(re) elif im <= 1.35e+154: tmp = 0.001953125 + (0.5 * math.exp(im)) else: tmp = 0.5 * (im * (math.cos(re) * im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 6.2) tmp = cos(re); elseif (im <= 1.35e+154) tmp = Float64(0.001953125 + Float64(0.5 * exp(im))); else tmp = Float64(0.5 * Float64(im * Float64(cos(re) * im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 6.2) tmp = cos(re); elseif (im <= 1.35e+154) tmp = 0.001953125 + (0.5 * exp(im)); else tmp = 0.5 * (im * (cos(re) * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 6.2], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(0.001953125 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[(N[Cos[re], $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 6.2:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;0.001953125 + 0.5 \cdot e^{im}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(\cos re \cdot im\right)\right)\\
\end{array}
\end{array}
if im < 6.20000000000000018Initial program 100.0%
Taylor expanded in im around 0 84.2%
unpow284.2%
Simplified84.2%
Taylor expanded in im around 0 64.6%
if 6.20000000000000018 < im < 1.35000000000000003e154Initial program 100.0%
Simplified100.0%
Applied egg-rr100.0%
Taylor expanded in re around 0 65.2%
if 1.35000000000000003e154 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
unpow2100.0%
associate-*l*100.0%
Simplified100.0%
Final simplification68.8%
(FPCore (re im)
:precision binary64
(if (<= im 6.2)
(* (* (cos re) 0.5) (+ (* im im) 2.0))
(if (<= im 1.5e+154)
(+ 0.001953125 (* 0.5 (exp im)))
(* 0.5 (* im (* (cos re) im))))))
double code(double re, double im) {
double tmp;
if (im <= 6.2) {
tmp = (cos(re) * 0.5) * ((im * im) + 2.0);
} else if (im <= 1.5e+154) {
tmp = 0.001953125 + (0.5 * exp(im));
} else {
tmp = 0.5 * (im * (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 <= 6.2d0) then
tmp = (cos(re) * 0.5d0) * ((im * im) + 2.0d0)
else if (im <= 1.5d+154) then
tmp = 0.001953125d0 + (0.5d0 * exp(im))
else
tmp = 0.5d0 * (im * (cos(re) * im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 6.2) {
tmp = (Math.cos(re) * 0.5) * ((im * im) + 2.0);
} else if (im <= 1.5e+154) {
tmp = 0.001953125 + (0.5 * Math.exp(im));
} else {
tmp = 0.5 * (im * (Math.cos(re) * im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 6.2: tmp = (math.cos(re) * 0.5) * ((im * im) + 2.0) elif im <= 1.5e+154: tmp = 0.001953125 + (0.5 * math.exp(im)) else: tmp = 0.5 * (im * (math.cos(re) * im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 6.2) tmp = Float64(Float64(cos(re) * 0.5) * Float64(Float64(im * im) + 2.0)); elseif (im <= 1.5e+154) tmp = Float64(0.001953125 + Float64(0.5 * exp(im))); else tmp = Float64(0.5 * Float64(im * Float64(cos(re) * im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 6.2) tmp = (cos(re) * 0.5) * ((im * im) + 2.0); elseif (im <= 1.5e+154) tmp = 0.001953125 + (0.5 * exp(im)); else tmp = 0.5 * (im * (cos(re) * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 6.2], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(N[(im * im), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.5e+154], N[(0.001953125 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[(N[Cos[re], $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 6.2:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(im \cdot im + 2\right)\\
\mathbf{elif}\;im \leq 1.5 \cdot 10^{+154}:\\
\;\;\;\;0.001953125 + 0.5 \cdot e^{im}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(\cos re \cdot im\right)\right)\\
\end{array}
\end{array}
if im < 6.20000000000000018Initial program 100.0%
Taylor expanded in im around 0 84.2%
unpow284.2%
Simplified84.2%
if 6.20000000000000018 < im < 1.50000000000000013e154Initial program 100.0%
Simplified100.0%
Applied egg-rr100.0%
Taylor expanded in re around 0 65.2%
if 1.50000000000000013e154 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
unpow2100.0%
associate-*l*100.0%
Simplified100.0%
Final simplification83.5%
(FPCore (re im)
:precision binary64
(if (<= im 30500000000.0)
(cos re)
(if (<= im 1.35e+165)
(* 0.5 (* im (+ im (* -0.5 (* im (* re re))))))
(* 0.5 (fma im im 2.0)))))
double code(double re, double im) {
double tmp;
if (im <= 30500000000.0) {
tmp = cos(re);
} else if (im <= 1.35e+165) {
tmp = 0.5 * (im * (im + (-0.5 * (im * (re * re)))));
} else {
tmp = 0.5 * fma(im, im, 2.0);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 30500000000.0) tmp = cos(re); elseif (im <= 1.35e+165) tmp = Float64(0.5 * Float64(im * Float64(im + Float64(-0.5 * Float64(im * Float64(re * re)))))); else tmp = Float64(0.5 * fma(im, im, 2.0)); end return tmp end
code[re_, im_] := If[LessEqual[im, 30500000000.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.35e+165], N[(0.5 * N[(im * N[(im + N[(-0.5 * N[(im * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 30500000000:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+165}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(im + -0.5 \cdot \left(im \cdot \left(re \cdot re\right)\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{fma}\left(im, im, 2\right)\\
\end{array}
\end{array}
if im < 3.05e10Initial program 100.0%
Taylor expanded in im around 0 81.8%
unpow281.8%
Simplified81.8%
Taylor expanded in im around 0 62.8%
if 3.05e10 < im < 1.35e165Initial program 100.0%
Taylor expanded in im around 0 17.1%
unpow217.1%
Simplified17.1%
Taylor expanded in im around inf 17.1%
unpow217.1%
associate-*l*17.1%
Simplified17.1%
Taylor expanded in re around 0 37.8%
unpow237.8%
Simplified37.8%
if 1.35e165 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in re around 0 96.2%
unpow296.2%
+-commutative96.2%
fma-udef96.2%
Simplified96.2%
Final simplification63.1%
(FPCore (re im)
:precision binary64
(if (<= im 100000000000.0)
(cos re)
(if (<= im 1e+165)
(* 0.5 (* im (+ im (* -0.5 (* im (* re re))))))
(* im (* 0.5 im)))))
double code(double re, double im) {
double tmp;
if (im <= 100000000000.0) {
tmp = cos(re);
} else if (im <= 1e+165) {
tmp = 0.5 * (im * (im + (-0.5 * (im * (re * re)))));
} else {
tmp = im * (0.5 * im);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 100000000000.0d0) then
tmp = cos(re)
else if (im <= 1d+165) then
tmp = 0.5d0 * (im * (im + ((-0.5d0) * (im * (re * re)))))
else
tmp = im * (0.5d0 * im)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 100000000000.0) {
tmp = Math.cos(re);
} else if (im <= 1e+165) {
tmp = 0.5 * (im * (im + (-0.5 * (im * (re * re)))));
} else {
tmp = im * (0.5 * im);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 100000000000.0: tmp = math.cos(re) elif im <= 1e+165: tmp = 0.5 * (im * (im + (-0.5 * (im * (re * re))))) else: tmp = im * (0.5 * im) return tmp
function code(re, im) tmp = 0.0 if (im <= 100000000000.0) tmp = cos(re); elseif (im <= 1e+165) tmp = Float64(0.5 * Float64(im * Float64(im + Float64(-0.5 * Float64(im * Float64(re * re)))))); else tmp = Float64(im * Float64(0.5 * im)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 100000000000.0) tmp = cos(re); elseif (im <= 1e+165) tmp = 0.5 * (im * (im + (-0.5 * (im * (re * re))))); else tmp = im * (0.5 * im); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 100000000000.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1e+165], N[(0.5 * N[(im * N[(im + N[(-0.5 * N[(im * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(im * N[(0.5 * im), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 100000000000:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 10^{+165}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(im + -0.5 \cdot \left(im \cdot \left(re \cdot re\right)\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;im \cdot \left(0.5 \cdot im\right)\\
\end{array}
\end{array}
if im < 1e11Initial program 100.0%
Taylor expanded in im around 0 81.8%
unpow281.8%
Simplified81.8%
Taylor expanded in im around 0 62.8%
if 1e11 < im < 9.99999999999999899e164Initial program 100.0%
Taylor expanded in im around 0 17.1%
unpow217.1%
Simplified17.1%
Taylor expanded in im around inf 17.1%
unpow217.1%
associate-*l*17.1%
Simplified17.1%
Taylor expanded in re around 0 37.8%
unpow237.8%
Simplified37.8%
if 9.99999999999999899e164 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
unpow2100.0%
associate-*r*100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in re around 0 96.2%
unpow296.2%
associate-*r*96.2%
*-commutative96.2%
Simplified96.2%
Final simplification63.1%
(FPCore (re im)
:precision binary64
(if (<= im 7.8e+58)
(+ 1.0 (* -0.5 (* re re)))
(*
0.5
(*
im
(+
im
(* im (* (* re re) (+ -0.5 (* (* re re) 0.041666666666666664)))))))))
double code(double re, double im) {
double tmp;
if (im <= 7.8e+58) {
tmp = 1.0 + (-0.5 * (re * re));
} else {
tmp = 0.5 * (im * (im + (im * ((re * re) * (-0.5 + ((re * re) * 0.041666666666666664))))));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 7.8d+58) then
tmp = 1.0d0 + ((-0.5d0) * (re * re))
else
tmp = 0.5d0 * (im * (im + (im * ((re * re) * ((-0.5d0) + ((re * re) * 0.041666666666666664d0))))))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 7.8e+58) {
tmp = 1.0 + (-0.5 * (re * re));
} else {
tmp = 0.5 * (im * (im + (im * ((re * re) * (-0.5 + ((re * re) * 0.041666666666666664))))));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 7.8e+58: tmp = 1.0 + (-0.5 * (re * re)) else: tmp = 0.5 * (im * (im + (im * ((re * re) * (-0.5 + ((re * re) * 0.041666666666666664)))))) return tmp
function code(re, im) tmp = 0.0 if (im <= 7.8e+58) tmp = Float64(1.0 + Float64(-0.5 * Float64(re * re))); else tmp = Float64(0.5 * Float64(im * Float64(im + Float64(im * Float64(Float64(re * re) * Float64(-0.5 + Float64(Float64(re * re) * 0.041666666666666664))))))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 7.8e+58) tmp = 1.0 + (-0.5 * (re * re)); else tmp = 0.5 * (im * (im + (im * ((re * re) * (-0.5 + ((re * re) * 0.041666666666666664)))))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 7.8e+58], N[(1.0 + N[(-0.5 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[(im + N[(im * N[(N[(re * re), $MachinePrecision] * N[(-0.5 + N[(N[(re * re), $MachinePrecision] * 0.041666666666666664), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 7.8 \cdot 10^{+58}:\\
\;\;\;\;1 + -0.5 \cdot \left(re \cdot re\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(im + im \cdot \left(\left(re \cdot re\right) \cdot \left(-0.5 + \left(re \cdot re\right) \cdot 0.041666666666666664\right)\right)\right)\right)\\
\end{array}
\end{array}
if im < 7.8000000000000002e58Initial program 100.0%
Taylor expanded in im around 0 76.7%
unpow276.7%
Simplified76.7%
Taylor expanded in re around 0 37.1%
+-commutative37.1%
unpow237.1%
+-commutative37.1%
fma-udef37.1%
associate-*r*37.1%
unpow237.1%
+-commutative37.1%
fma-udef37.1%
distribute-rgt-out50.3%
*-commutative50.3%
unpow250.3%
Simplified50.3%
Taylor expanded in im around 0 38.9%
distribute-lft-in38.9%
metadata-eval38.9%
associate-*r*38.9%
metadata-eval38.9%
unpow238.9%
Simplified38.9%
if 7.8000000000000002e58 < im Initial program 100.0%
Taylor expanded in im around 0 70.3%
unpow270.3%
Simplified70.3%
Taylor expanded in im around inf 70.3%
unpow270.3%
associate-*l*70.3%
Simplified70.3%
Taylor expanded in re around 0 44.6%
*-commutative44.6%
associate-*r*44.6%
*-commutative44.6%
associate-*r*44.6%
distribute-rgt-out46.9%
metadata-eval46.9%
pow-sqr46.9%
associate-*r*46.9%
distribute-rgt-out60.5%
unpow260.5%
unpow260.5%
Simplified60.5%
Final simplification42.6%
(FPCore (re im)
:precision binary64
(if (<= im 6.2)
(+ 1.0 (* -0.5 (* re re)))
(if (<= im 2e+165)
(* 0.5 (* im (+ im (* -0.5 (* im (* re re))))))
(* im (* 0.5 im)))))
double code(double re, double im) {
double tmp;
if (im <= 6.2) {
tmp = 1.0 + (-0.5 * (re * re));
} else if (im <= 2e+165) {
tmp = 0.5 * (im * (im + (-0.5 * (im * (re * re)))));
} else {
tmp = im * (0.5 * im);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 6.2d0) then
tmp = 1.0d0 + ((-0.5d0) * (re * re))
else if (im <= 2d+165) then
tmp = 0.5d0 * (im * (im + ((-0.5d0) * (im * (re * re)))))
else
tmp = im * (0.5d0 * im)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 6.2) {
tmp = 1.0 + (-0.5 * (re * re));
} else if (im <= 2e+165) {
tmp = 0.5 * (im * (im + (-0.5 * (im * (re * re)))));
} else {
tmp = im * (0.5 * im);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 6.2: tmp = 1.0 + (-0.5 * (re * re)) elif im <= 2e+165: tmp = 0.5 * (im * (im + (-0.5 * (im * (re * re))))) else: tmp = im * (0.5 * im) return tmp
function code(re, im) tmp = 0.0 if (im <= 6.2) tmp = Float64(1.0 + Float64(-0.5 * Float64(re * re))); elseif (im <= 2e+165) tmp = Float64(0.5 * Float64(im * Float64(im + Float64(-0.5 * Float64(im * Float64(re * re)))))); else tmp = Float64(im * Float64(0.5 * im)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 6.2) tmp = 1.0 + (-0.5 * (re * re)); elseif (im <= 2e+165) tmp = 0.5 * (im * (im + (-0.5 * (im * (re * re))))); else tmp = im * (0.5 * im); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 6.2], N[(1.0 + N[(-0.5 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 2e+165], N[(0.5 * N[(im * N[(im + N[(-0.5 * N[(im * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(im * N[(0.5 * im), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 6.2:\\
\;\;\;\;1 + -0.5 \cdot \left(re \cdot re\right)\\
\mathbf{elif}\;im \leq 2 \cdot 10^{+165}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \left(im + -0.5 \cdot \left(im \cdot \left(re \cdot re\right)\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;im \cdot \left(0.5 \cdot im\right)\\
\end{array}
\end{array}
if im < 6.20000000000000018Initial program 100.0%
Taylor expanded in im around 0 84.2%
unpow284.2%
Simplified84.2%
Taylor expanded in re around 0 38.5%
+-commutative38.5%
unpow238.5%
+-commutative38.5%
fma-udef38.5%
associate-*r*38.5%
unpow238.5%
+-commutative38.5%
fma-udef38.5%
distribute-rgt-out53.1%
*-commutative53.1%
unpow253.1%
Simplified53.1%
Taylor expanded in im around 0 40.6%
distribute-lft-in40.6%
metadata-eval40.6%
associate-*r*40.6%
metadata-eval40.6%
unpow240.6%
Simplified40.6%
if 6.20000000000000018 < im < 1.9999999999999998e165Initial program 100.0%
Taylor expanded in im around 0 15.4%
unpow215.4%
Simplified15.4%
Taylor expanded in im around inf 15.4%
unpow215.4%
associate-*l*15.4%
Simplified15.4%
Taylor expanded in re around 0 32.6%
unpow232.6%
Simplified32.6%
if 1.9999999999999998e165 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
unpow2100.0%
associate-*r*100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in re around 0 96.2%
unpow296.2%
associate-*r*96.2%
*-commutative96.2%
Simplified96.2%
Final simplification45.0%
(FPCore (re im) :precision binary64 (if (<= im 1e+165) (+ 1.0 (* -0.5 (* re re))) (* im (* 0.5 im))))
double code(double re, double im) {
double tmp;
if (im <= 1e+165) {
tmp = 1.0 + (-0.5 * (re * re));
} else {
tmp = im * (0.5 * im);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 1d+165) then
tmp = 1.0d0 + ((-0.5d0) * (re * re))
else
tmp = im * (0.5d0 * im)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1e+165) {
tmp = 1.0 + (-0.5 * (re * re));
} else {
tmp = im * (0.5 * im);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1e+165: tmp = 1.0 + (-0.5 * (re * re)) else: tmp = im * (0.5 * im) return tmp
function code(re, im) tmp = 0.0 if (im <= 1e+165) tmp = Float64(1.0 + Float64(-0.5 * Float64(re * re))); else tmp = Float64(im * Float64(0.5 * im)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1e+165) tmp = 1.0 + (-0.5 * (re * re)); else tmp = im * (0.5 * im); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1e+165], N[(1.0 + N[(-0.5 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(im * N[(0.5 * im), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 10^{+165}:\\
\;\;\;\;1 + -0.5 \cdot \left(re \cdot re\right)\\
\mathbf{else}:\\
\;\;\;\;im \cdot \left(0.5 \cdot im\right)\\
\end{array}
\end{array}
if im < 9.99999999999999899e164Initial program 100.0%
Taylor expanded in im around 0 72.8%
unpow272.8%
Simplified72.8%
Taylor expanded in re around 0 35.8%
+-commutative35.8%
unpow235.8%
+-commutative35.8%
fma-udef35.8%
associate-*r*35.8%
unpow235.8%
+-commutative35.8%
fma-udef35.8%
distribute-rgt-out49.7%
*-commutative49.7%
unpow249.7%
Simplified49.7%
Taylor expanded in im around 0 37.4%
distribute-lft-in37.4%
metadata-eval37.4%
associate-*r*37.4%
metadata-eval37.4%
unpow237.4%
Simplified37.4%
if 9.99999999999999899e164 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
unpow2100.0%
associate-*r*100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in re around 0 96.2%
unpow296.2%
associate-*r*96.2%
*-commutative96.2%
Simplified96.2%
Final simplification43.3%
(FPCore (re im) :precision binary64 (* im (* 0.5 im)))
double code(double re, double im) {
return im * (0.5 * im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = im * (0.5d0 * im)
end function
public static double code(double re, double im) {
return im * (0.5 * im);
}
def code(re, im): return im * (0.5 * im)
function code(re, im) return Float64(im * Float64(0.5 * im)) end
function tmp = code(re, im) tmp = im * (0.5 * im); end
code[re_, im_] := N[(im * N[(0.5 * im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
im \cdot \left(0.5 \cdot im\right)
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 75.6%
unpow275.6%
Simplified75.6%
Taylor expanded in im around inf 29.7%
unpow229.7%
associate-*r*29.7%
*-commutative29.7%
Simplified29.7%
Taylor expanded in re around 0 24.9%
unpow224.9%
associate-*r*24.9%
*-commutative24.9%
Simplified24.9%
Final simplification24.9%
herbie shell --seed 2023293
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))