
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp(-im) + exp(im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * (exp(-im) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp(-im) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp(-im) + exp(im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * (exp(-im) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp(-im) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
\end{array}
(FPCore (re im) :precision binary64 (* (* 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 485000.0)
(cos re)
(if (<= im 3.9e+48)
(+ 0.25 (* 0.25 (log1p (expm1 re))))
(if (<= im 1.35e+154)
(* 0.5 (+ 2.0 (* 0.08333333333333333 (pow im 4.0))))
(* (cos re) (* 0.5 (pow im 2.0)))))))
double code(double re, double im) {
double tmp;
if (im <= 485000.0) {
tmp = cos(re);
} else if (im <= 3.9e+48) {
tmp = 0.25 + (0.25 * log1p(expm1(re)));
} else if (im <= 1.35e+154) {
tmp = 0.5 * (2.0 + (0.08333333333333333 * pow(im, 4.0)));
} else {
tmp = cos(re) * (0.5 * pow(im, 2.0));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (im <= 485000.0) {
tmp = Math.cos(re);
} else if (im <= 3.9e+48) {
tmp = 0.25 + (0.25 * Math.log1p(Math.expm1(re)));
} else if (im <= 1.35e+154) {
tmp = 0.5 * (2.0 + (0.08333333333333333 * Math.pow(im, 4.0)));
} else {
tmp = Math.cos(re) * (0.5 * Math.pow(im, 2.0));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 485000.0: tmp = math.cos(re) elif im <= 3.9e+48: tmp = 0.25 + (0.25 * math.log1p(math.expm1(re))) elif im <= 1.35e+154: tmp = 0.5 * (2.0 + (0.08333333333333333 * math.pow(im, 4.0))) else: tmp = math.cos(re) * (0.5 * math.pow(im, 2.0)) return tmp
function code(re, im) tmp = 0.0 if (im <= 485000.0) tmp = cos(re); elseif (im <= 3.9e+48) tmp = Float64(0.25 + Float64(0.25 * log1p(expm1(re)))); elseif (im <= 1.35e+154) tmp = Float64(0.5 * Float64(2.0 + Float64(0.08333333333333333 * (im ^ 4.0)))); else tmp = Float64(cos(re) * Float64(0.5 * (im ^ 2.0))); end return tmp end
code[re_, im_] := If[LessEqual[im, 485000.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 3.9e+48], N[(0.25 + N[(0.25 * N[Log[1 + N[(Exp[re] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(0.5 * N[(2.0 + N[(0.08333333333333333 * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 485000:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 3.9 \cdot 10^{+48}:\\
\;\;\;\;0.25 + 0.25 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(re\right)\right)\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot \left(2 + 0.08333333333333333 \cdot {im}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left(0.5 \cdot {im}^{2}\right)\\
\end{array}
\end{array}
if im < 485000Initial program 100.0%
Taylor expanded in im around 0 66.7%
if 485000 < im < 3.9000000000000001e48Initial program 100.0%
Applied egg-rr1.7%
*-commutative1.7%
Simplified1.7%
Taylor expanded in re around 0 15.2%
*-commutative15.2%
Simplified15.2%
Applied egg-rr29.5%
if 3.9000000000000001e48 < im < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in re around 0 85.7%
*-commutative85.7%
Simplified85.7%
Taylor expanded in im around 0 79.0%
*-commutative79.0%
Simplified79.0%
Taylor expanded in im around inf 79.0%
if 1.35000000000000003e154 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
+-commutative100.0%
unpow2100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
associate-*r*100.0%
Simplified100.0%
Final simplification71.3%
(FPCore (re im)
:precision binary64
(if (<= im 1.9e-5)
(cos re)
(if (<= im 1.35e+154)
(* 0.5 (+ (exp (- im)) (exp im)))
(* (cos re) (* 0.5 (pow im 2.0))))))
double code(double re, double im) {
double tmp;
if (im <= 1.9e-5) {
tmp = cos(re);
} else if (im <= 1.35e+154) {
tmp = 0.5 * (exp(-im) + exp(im));
} else {
tmp = cos(re) * (0.5 * pow(im, 2.0));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 1.9d-5) then
tmp = cos(re)
else if (im <= 1.35d+154) then
tmp = 0.5d0 * (exp(-im) + exp(im))
else
tmp = cos(re) * (0.5d0 * (im ** 2.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.9e-5) {
tmp = Math.cos(re);
} else if (im <= 1.35e+154) {
tmp = 0.5 * (Math.exp(-im) + Math.exp(im));
} else {
tmp = Math.cos(re) * (0.5 * Math.pow(im, 2.0));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.9e-5: tmp = math.cos(re) elif im <= 1.35e+154: tmp = 0.5 * (math.exp(-im) + math.exp(im)) else: tmp = math.cos(re) * (0.5 * math.pow(im, 2.0)) return tmp
function code(re, im) tmp = 0.0 if (im <= 1.9e-5) tmp = cos(re); elseif (im <= 1.35e+154) tmp = Float64(0.5 * Float64(exp(Float64(-im)) + exp(im))); else tmp = Float64(cos(re) * Float64(0.5 * (im ^ 2.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.9e-5) tmp = cos(re); elseif (im <= 1.35e+154) tmp = 0.5 * (exp(-im) + exp(im)); else tmp = cos(re) * (0.5 * (im ^ 2.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.9e-5], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.9 \cdot 10^{-5}:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left(0.5 \cdot {im}^{2}\right)\\
\end{array}
\end{array}
if im < 1.9000000000000001e-5Initial program 100.0%
Taylor expanded in im around 0 67.5%
if 1.9000000000000001e-5 < im < 1.35000000000000003e154Initial program 99.9%
Taylor expanded in re around 0 69.0%
*-commutative69.0%
Simplified69.0%
if 1.35000000000000003e154 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
+-commutative100.0%
unpow2100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
associate-*r*100.0%
Simplified100.0%
Final simplification72.5%
(FPCore (re im)
:precision binary64
(if (<= im 1.8)
(* (* 0.5 (cos re)) (fma im im 2.0))
(if (<= im 1.35e+154)
(* 0.5 (+ (exp (- im)) (exp im)))
(* (cos re) (* 0.5 (pow im 2.0))))))
double code(double re, double im) {
double tmp;
if (im <= 1.8) {
tmp = (0.5 * cos(re)) * fma(im, im, 2.0);
} else if (im <= 1.35e+154) {
tmp = 0.5 * (exp(-im) + exp(im));
} else {
tmp = cos(re) * (0.5 * pow(im, 2.0));
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 1.8) tmp = Float64(Float64(0.5 * cos(re)) * fma(im, im, 2.0)); elseif (im <= 1.35e+154) tmp = Float64(0.5 * Float64(exp(Float64(-im)) + exp(im))); else tmp = Float64(cos(re) * Float64(0.5 * (im ^ 2.0))); end return tmp end
code[re_, im_] := If[LessEqual[im, 1.8], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.8:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \mathsf{fma}\left(im, im, 2\right)\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left(0.5 \cdot {im}^{2}\right)\\
\end{array}
\end{array}
if im < 1.80000000000000004Initial program 100.0%
Taylor expanded in im around 0 81.9%
+-commutative81.9%
unpow281.9%
fma-define81.9%
Simplified81.9%
if 1.80000000000000004 < im < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in re around 0 72.7%
*-commutative72.7%
Simplified72.7%
if 1.35000000000000003e154 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
+-commutative100.0%
unpow2100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
associate-*r*100.0%
Simplified100.0%
Final simplification83.8%
(FPCore (re im)
:precision binary64
(if (<= im 485000.0)
(cos re)
(if (<= im 3.9e+48)
(+ 0.25 (* 0.25 (log1p (expm1 re))))
(* 0.5 (+ 2.0 (* 0.08333333333333333 (pow im 4.0)))))))
double code(double re, double im) {
double tmp;
if (im <= 485000.0) {
tmp = cos(re);
} else if (im <= 3.9e+48) {
tmp = 0.25 + (0.25 * log1p(expm1(re)));
} else {
tmp = 0.5 * (2.0 + (0.08333333333333333 * pow(im, 4.0)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (im <= 485000.0) {
tmp = Math.cos(re);
} else if (im <= 3.9e+48) {
tmp = 0.25 + (0.25 * Math.log1p(Math.expm1(re)));
} else {
tmp = 0.5 * (2.0 + (0.08333333333333333 * Math.pow(im, 4.0)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 485000.0: tmp = math.cos(re) elif im <= 3.9e+48: tmp = 0.25 + (0.25 * math.log1p(math.expm1(re))) else: tmp = 0.5 * (2.0 + (0.08333333333333333 * math.pow(im, 4.0))) return tmp
function code(re, im) tmp = 0.0 if (im <= 485000.0) tmp = cos(re); elseif (im <= 3.9e+48) tmp = Float64(0.25 + Float64(0.25 * log1p(expm1(re)))); else tmp = Float64(0.5 * Float64(2.0 + Float64(0.08333333333333333 * (im ^ 4.0)))); end return tmp end
code[re_, im_] := If[LessEqual[im, 485000.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 3.9e+48], N[(0.25 + N[(0.25 * N[Log[1 + N[(Exp[re] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(2.0 + N[(0.08333333333333333 * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 485000:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 3.9 \cdot 10^{+48}:\\
\;\;\;\;0.25 + 0.25 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(re\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 + 0.08333333333333333 \cdot {im}^{4}\right)\\
\end{array}
\end{array}
if im < 485000Initial program 100.0%
Taylor expanded in im around 0 66.7%
if 485000 < im < 3.9000000000000001e48Initial program 100.0%
Applied egg-rr1.7%
*-commutative1.7%
Simplified1.7%
Taylor expanded in re around 0 15.2%
*-commutative15.2%
Simplified15.2%
Applied egg-rr29.5%
if 3.9000000000000001e48 < im Initial program 100.0%
Taylor expanded in re around 0 75.0%
*-commutative75.0%
Simplified75.0%
Taylor expanded in im around 0 73.2%
*-commutative73.2%
Simplified73.2%
Taylor expanded in im around inf 73.2%
Final simplification67.0%
(FPCore (re im)
:precision binary64
(if (<= im 4.6e+26)
(cos re)
(if (<= im 1.22e+121)
(+ 1.0 (* 0.5 (pow re 2.0)))
(* 0.5 (fma im im 2.0)))))
double code(double re, double im) {
double tmp;
if (im <= 4.6e+26) {
tmp = cos(re);
} else if (im <= 1.22e+121) {
tmp = 1.0 + (0.5 * pow(re, 2.0));
} else {
tmp = 0.5 * fma(im, im, 2.0);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 4.6e+26) tmp = cos(re); elseif (im <= 1.22e+121) tmp = Float64(1.0 + Float64(0.5 * (re ^ 2.0))); else tmp = Float64(0.5 * fma(im, im, 2.0)); end return tmp end
code[re_, im_] := If[LessEqual[im, 4.6e+26], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.22e+121], N[(1.0 + N[(0.5 * N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 4.6 \cdot 10^{+26}:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.22 \cdot 10^{+121}:\\
\;\;\;\;1 + 0.5 \cdot {re}^{2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{fma}\left(im, im, 2\right)\\
\end{array}
\end{array}
if im < 4.6000000000000001e26Initial program 100.0%
Taylor expanded in im around 0 65.4%
if 4.6000000000000001e26 < im < 1.22000000000000011e121Initial program 100.0%
Taylor expanded in im around 0 4.7%
+-commutative4.7%
unpow24.7%
fma-define4.7%
Simplified4.7%
Taylor expanded in im around inf 4.7%
associate-*r*4.7%
Simplified4.7%
Applied egg-rr3.1%
unpow-13.1%
Simplified3.1%
Taylor expanded in re around 0 26.7%
if 1.22000000000000011e121 < im Initial program 100.0%
Taylor expanded in im around 0 89.3%
+-commutative89.3%
unpow289.3%
fma-define89.3%
Simplified89.3%
Taylor expanded in re around 0 63.7%
+-commutative63.7%
unpow263.7%
fma-undefine63.7%
Simplified63.7%
Final simplification63.3%
(FPCore (re im) :precision binary64 (if (<= im 6.8e+26) (cos re) (if (<= im 1.36e+121) (+ 0.25 (* 0.25 (* re re))) (* 0.5 (fma im im 2.0)))))
double code(double re, double im) {
double tmp;
if (im <= 6.8e+26) {
tmp = cos(re);
} else if (im <= 1.36e+121) {
tmp = 0.25 + (0.25 * (re * re));
} else {
tmp = 0.5 * fma(im, im, 2.0);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 6.8e+26) tmp = cos(re); elseif (im <= 1.36e+121) tmp = Float64(0.25 + Float64(0.25 * Float64(re * re))); else tmp = Float64(0.5 * fma(im, im, 2.0)); end return tmp end
code[re_, im_] := If[LessEqual[im, 6.8e+26], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.36e+121], N[(0.25 + N[(0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 6.8 \cdot 10^{+26}:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.36 \cdot 10^{+121}:\\
\;\;\;\;0.25 + 0.25 \cdot \left(re \cdot re\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{fma}\left(im, im, 2\right)\\
\end{array}
\end{array}
if im < 6.8000000000000005e26Initial program 100.0%
Taylor expanded in im around 0 65.4%
if 6.8000000000000005e26 < im < 1.36e121Initial program 100.0%
Applied egg-rr2.5%
*-commutative2.5%
Simplified2.5%
Taylor expanded in re around 0 26.7%
*-commutative26.7%
Simplified26.7%
Applied egg-rr26.7%
if 1.36e121 < im Initial program 100.0%
Taylor expanded in im around 0 89.3%
+-commutative89.3%
unpow289.3%
fma-define89.3%
Simplified89.3%
Taylor expanded in re around 0 63.7%
+-commutative63.7%
unpow263.7%
fma-undefine63.7%
Simplified63.7%
Final simplification63.3%
(FPCore (re im) :precision binary64 (if (<= im 4.1e+26) (cos re) (if (<= im 1.36e+121) (+ 0.25 (* 0.25 (* re re))) (* 0.5 (pow im 2.0)))))
double code(double re, double im) {
double tmp;
if (im <= 4.1e+26) {
tmp = cos(re);
} else if (im <= 1.36e+121) {
tmp = 0.25 + (0.25 * (re * re));
} else {
tmp = 0.5 * pow(im, 2.0);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 4.1d+26) then
tmp = cos(re)
else if (im <= 1.36d+121) then
tmp = 0.25d0 + (0.25d0 * (re * re))
else
tmp = 0.5d0 * (im ** 2.0d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 4.1e+26) {
tmp = Math.cos(re);
} else if (im <= 1.36e+121) {
tmp = 0.25 + (0.25 * (re * re));
} else {
tmp = 0.5 * Math.pow(im, 2.0);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 4.1e+26: tmp = math.cos(re) elif im <= 1.36e+121: tmp = 0.25 + (0.25 * (re * re)) else: tmp = 0.5 * math.pow(im, 2.0) return tmp
function code(re, im) tmp = 0.0 if (im <= 4.1e+26) tmp = cos(re); elseif (im <= 1.36e+121) tmp = Float64(0.25 + Float64(0.25 * Float64(re * re))); else tmp = Float64(0.5 * (im ^ 2.0)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 4.1e+26) tmp = cos(re); elseif (im <= 1.36e+121) tmp = 0.25 + (0.25 * (re * re)); else tmp = 0.5 * (im ^ 2.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 4.1e+26], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.36e+121], N[(0.25 + N[(0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 4.1 \cdot 10^{+26}:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.36 \cdot 10^{+121}:\\
\;\;\;\;0.25 + 0.25 \cdot \left(re \cdot re\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {im}^{2}\\
\end{array}
\end{array}
if im < 4.09999999999999983e26Initial program 100.0%
Taylor expanded in im around 0 65.4%
if 4.09999999999999983e26 < im < 1.36e121Initial program 100.0%
Applied egg-rr2.5%
*-commutative2.5%
Simplified2.5%
Taylor expanded in re around 0 26.7%
*-commutative26.7%
Simplified26.7%
Applied egg-rr26.7%
if 1.36e121 < im Initial program 100.0%
Taylor expanded in im around 0 89.3%
+-commutative89.3%
unpow289.3%
fma-define89.3%
Simplified89.3%
Taylor expanded in re around 0 63.7%
+-commutative63.7%
unpow263.7%
fma-undefine63.7%
Simplified63.7%
Taylor expanded in im around inf 63.7%
*-commutative63.7%
Simplified63.7%
Final simplification63.3%
(FPCore (re im) :precision binary64 (if (<= im 9.5e+29) (cos re) (* 0.5 (+ 2.0 (* 0.08333333333333333 (pow im 4.0))))))
double code(double re, double im) {
double tmp;
if (im <= 9.5e+29) {
tmp = cos(re);
} else {
tmp = 0.5 * (2.0 + (0.08333333333333333 * pow(im, 4.0)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 9.5d+29) then
tmp = cos(re)
else
tmp = 0.5d0 * (2.0d0 + (0.08333333333333333d0 * (im ** 4.0d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 9.5e+29) {
tmp = Math.cos(re);
} else {
tmp = 0.5 * (2.0 + (0.08333333333333333 * Math.pow(im, 4.0)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 9.5e+29: tmp = math.cos(re) else: tmp = 0.5 * (2.0 + (0.08333333333333333 * math.pow(im, 4.0))) return tmp
function code(re, im) tmp = 0.0 if (im <= 9.5e+29) tmp = cos(re); else tmp = Float64(0.5 * Float64(2.0 + Float64(0.08333333333333333 * (im ^ 4.0)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 9.5e+29) tmp = cos(re); else tmp = 0.5 * (2.0 + (0.08333333333333333 * (im ^ 4.0))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 9.5e+29], N[Cos[re], $MachinePrecision], N[(0.5 * N[(2.0 + N[(0.08333333333333333 * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 9.5 \cdot 10^{+29}:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 + 0.08333333333333333 \cdot {im}^{4}\right)\\
\end{array}
\end{array}
if im < 9.5000000000000003e29Initial program 100.0%
Taylor expanded in im around 0 64.8%
if 9.5000000000000003e29 < im Initial program 100.0%
Taylor expanded in re around 0 75.5%
*-commutative75.5%
Simplified75.5%
Taylor expanded in im around 0 71.9%
*-commutative71.9%
Simplified71.9%
Taylor expanded in im around inf 71.9%
Final simplification66.3%
(FPCore (re im) :precision binary64 (if (<= im 4.2e+26) (cos re) (+ 0.25 (* 0.25 (* re re)))))
double code(double re, double im) {
double tmp;
if (im <= 4.2e+26) {
tmp = cos(re);
} else {
tmp = 0.25 + (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 <= 4.2d+26) then
tmp = cos(re)
else
tmp = 0.25d0 + (0.25d0 * (re * re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 4.2e+26) {
tmp = Math.cos(re);
} else {
tmp = 0.25 + (0.25 * (re * re));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 4.2e+26: tmp = math.cos(re) else: tmp = 0.25 + (0.25 * (re * re)) return tmp
function code(re, im) tmp = 0.0 if (im <= 4.2e+26) tmp = cos(re); else tmp = Float64(0.25 + Float64(0.25 * Float64(re * re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 4.2e+26) tmp = cos(re); else tmp = 0.25 + (0.25 * (re * re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 4.2e+26], N[Cos[re], $MachinePrecision], N[(0.25 + N[(0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 4.2 \cdot 10^{+26}:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;0.25 + 0.25 \cdot \left(re \cdot re\right)\\
\end{array}
\end{array}
if im < 4.2000000000000002e26Initial program 100.0%
Taylor expanded in im around 0 65.4%
if 4.2000000000000002e26 < im Initial program 100.0%
Applied egg-rr2.5%
*-commutative2.5%
Simplified2.5%
Taylor expanded in re around 0 14.9%
*-commutative14.9%
Simplified14.9%
Applied egg-rr14.9%
Final simplification54.6%
(FPCore (re im) :precision binary64 (if (<= im 485000.0) 1.0 (+ 0.25 (* 0.25 (* re re)))))
double code(double re, double im) {
double tmp;
if (im <= 485000.0) {
tmp = 1.0;
} else {
tmp = 0.25 + (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 <= 485000.0d0) then
tmp = 1.0d0
else
tmp = 0.25d0 + (0.25d0 * (re * re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 485000.0) {
tmp = 1.0;
} else {
tmp = 0.25 + (0.25 * (re * re));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 485000.0: tmp = 1.0 else: tmp = 0.25 + (0.25 * (re * re)) return tmp
function code(re, im) tmp = 0.0 if (im <= 485000.0) tmp = 1.0; else tmp = Float64(0.25 + Float64(0.25 * Float64(re * re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 485000.0) tmp = 1.0; else tmp = 0.25 + (0.25 * (re * re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 485000.0], 1.0, N[(0.25 + N[(0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 485000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.25 + 0.25 \cdot \left(re \cdot re\right)\\
\end{array}
\end{array}
if im < 485000Initial program 100.0%
Applied egg-rr39.1%
+-inverses39.1%
+-rgt-identity39.1%
*-inverses39.1%
Simplified39.1%
if 485000 < im Initial program 100.0%
Applied egg-rr2.4%
*-commutative2.4%
Simplified2.4%
Taylor expanded in re around 0 13.9%
*-commutative13.9%
Simplified13.9%
Applied egg-rr13.9%
Final simplification33.3%
(FPCore (re im) :precision binary64 0.25)
double code(double re, double im) {
return 0.25;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.25d0
end function
public static double code(double re, double im) {
return 0.25;
}
def code(re, im): return 0.25
function code(re, im) return 0.25 end
function tmp = code(re, im) tmp = 0.25; end
code[re_, im_] := 0.25
\begin{array}{l}
\\
0.25
\end{array}
Initial program 100.0%
Applied egg-rr7.9%
*-commutative7.9%
Simplified7.9%
Taylor expanded in re around 0 7.9%
Final simplification7.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-rr30.6%
+-inverses30.6%
+-rgt-identity30.6%
*-inverses30.6%
Simplified30.6%
Final simplification30.6%
herbie shell --seed 2024059
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))