
(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 (* (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%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-lft-in100.0%
distribute-lft-in100.0%
distribute-rgt-in100.0%
*-commutative100.0%
fma-def100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (re im) :precision binary64 (* (* (cos re) 0.5) (+ (exp im) (exp (- im)))))
double code(double re, double im) {
return (cos(re) * 0.5) * (exp(im) + exp(-im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (cos(re) * 0.5d0) * (exp(im) + exp(-im))
end function
public static double code(double re, double im) {
return (Math.cos(re) * 0.5) * (Math.exp(im) + Math.exp(-im));
}
def code(re, im): return (math.cos(re) * 0.5) * (math.exp(im) + math.exp(-im))
function code(re, im) return Float64(Float64(cos(re) * 0.5) * Float64(exp(im) + exp(Float64(-im)))) end
function tmp = code(re, im) tmp = (cos(re) * 0.5) * (exp(im) + exp(-im)); end
code[re_, im_] := N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(N[Exp[im], $MachinePrecision] + N[Exp[(-im)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\cos re \cdot 0.5\right) \cdot \left(e^{im} + e^{-im}\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (re im) :precision binary64 (* (cos re) (fma 0.5 (exp im) 0.5)))
double code(double re, double im) {
return cos(re) * fma(0.5, exp(im), 0.5);
}
function code(re, im) return Float64(cos(re) * fma(0.5, exp(im), 0.5)) end
code[re_, im_] := N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[Exp[im], $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos re \cdot \mathsf{fma}\left(0.5, e^{im}, 0.5\right)
\end{array}
Initial program 100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-lft-in100.0%
distribute-lft-in100.0%
distribute-rgt-in100.0%
*-commutative100.0%
fma-def100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 77.5%
Final simplification77.5%
(FPCore (re im) :precision binary64 (* (* (cos re) 0.5) (+ 2.0 (+ (* im im) (* (pow im 4.0) 0.08333333333333333)))))
double code(double re, double im) {
return (cos(re) * 0.5) * (2.0 + ((im * im) + (pow(im, 4.0) * 0.08333333333333333)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (cos(re) * 0.5d0) * (2.0d0 + ((im * im) + ((im ** 4.0d0) * 0.08333333333333333d0)))
end function
public static double code(double re, double im) {
return (Math.cos(re) * 0.5) * (2.0 + ((im * im) + (Math.pow(im, 4.0) * 0.08333333333333333)));
}
def code(re, im): return (math.cos(re) * 0.5) * (2.0 + ((im * im) + (math.pow(im, 4.0) * 0.08333333333333333)))
function code(re, im) return Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(Float64(im * im) + Float64((im ^ 4.0) * 0.08333333333333333)))) end
function tmp = code(re, im) tmp = (cos(re) * 0.5) * (2.0 + ((im * im) + ((im ^ 4.0) * 0.08333333333333333))); end
code[re_, im_] := N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(N[(im * im), $MachinePrecision] + N[(N[Power[im, 4.0], $MachinePrecision] * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\cos re \cdot 0.5\right) \cdot \left(2 + \left(im \cdot im + {im}^{4} \cdot 0.08333333333333333\right)\right)
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 94.4%
unpow294.4%
*-commutative94.4%
Simplified94.4%
Final simplification94.4%
(FPCore (re im) :precision binary64 (if (<= im 3.7) (* (* (cos re) 0.5) (+ 2.0 (* im im))) (* (pow im 4.0) (* (cos re) 0.041666666666666664))))
double code(double re, double im) {
double tmp;
if (im <= 3.7) {
tmp = (cos(re) * 0.5) * (2.0 + (im * im));
} else {
tmp = pow(im, 4.0) * (cos(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 <= 3.7d0) then
tmp = (cos(re) * 0.5d0) * (2.0d0 + (im * im))
else
tmp = (im ** 4.0d0) * (cos(re) * 0.041666666666666664d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 3.7) {
tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
} else {
tmp = Math.pow(im, 4.0) * (Math.cos(re) * 0.041666666666666664);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 3.7: tmp = (math.cos(re) * 0.5) * (2.0 + (im * im)) else: tmp = math.pow(im, 4.0) * (math.cos(re) * 0.041666666666666664) return tmp
function code(re, im) tmp = 0.0 if (im <= 3.7) tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im))); else tmp = Float64((im ^ 4.0) * Float64(cos(re) * 0.041666666666666664)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 3.7) tmp = (cos(re) * 0.5) * (2.0 + (im * im)); else tmp = (im ^ 4.0) * (cos(re) * 0.041666666666666664); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 3.7], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[im, 4.0], $MachinePrecision] * N[(N[Cos[re], $MachinePrecision] * 0.041666666666666664), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 3.7:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;{im}^{4} \cdot \left(\cos re \cdot 0.041666666666666664\right)\\
\end{array}
\end{array}
if im < 3.7000000000000002Initial program 100.0%
Taylor expanded in im around 0 87.0%
unpow287.0%
Simplified87.0%
if 3.7000000000000002 < im Initial program 100.0%
Taylor expanded in im around 0 91.8%
unpow291.8%
*-commutative91.8%
Simplified91.8%
Taylor expanded in im around inf 91.8%
associate-*r*91.8%
Simplified91.8%
Final simplification88.1%
(FPCore (re im)
:precision binary64
(if (<= im 490.0)
(* (* (cos re) 0.5) (+ 2.0 (* im im)))
(if (<= im 1.35e+154)
(*
(pow im 4.0)
(+ 0.041666666666666664 (* (* re re) -0.020833333333333332)))
(* 0.5 (* (cos re) (* im im))))))
double code(double re, double im) {
double tmp;
if (im <= 490.0) {
tmp = (cos(re) * 0.5) * (2.0 + (im * im));
} else if (im <= 1.35e+154) {
tmp = pow(im, 4.0) * (0.041666666666666664 + ((re * re) * -0.020833333333333332));
} else {
tmp = 0.5 * (cos(re) * (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 <= 490.0d0) then
tmp = (cos(re) * 0.5d0) * (2.0d0 + (im * im))
else if (im <= 1.35d+154) then
tmp = (im ** 4.0d0) * (0.041666666666666664d0 + ((re * re) * (-0.020833333333333332d0)))
else
tmp = 0.5d0 * (cos(re) * (im * im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 490.0) {
tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
} else if (im <= 1.35e+154) {
tmp = Math.pow(im, 4.0) * (0.041666666666666664 + ((re * re) * -0.020833333333333332));
} else {
tmp = 0.5 * (Math.cos(re) * (im * im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 490.0: tmp = (math.cos(re) * 0.5) * (2.0 + (im * im)) elif im <= 1.35e+154: tmp = math.pow(im, 4.0) * (0.041666666666666664 + ((re * re) * -0.020833333333333332)) else: tmp = 0.5 * (math.cos(re) * (im * im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 490.0) tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im))); elseif (im <= 1.35e+154) tmp = Float64((im ^ 4.0) * Float64(0.041666666666666664 + Float64(Float64(re * re) * -0.020833333333333332))); else tmp = Float64(0.5 * Float64(cos(re) * Float64(im * im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 490.0) tmp = (cos(re) * 0.5) * (2.0 + (im * im)); elseif (im <= 1.35e+154) tmp = (im ^ 4.0) * (0.041666666666666664 + ((re * re) * -0.020833333333333332)); else tmp = 0.5 * (cos(re) * (im * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 490.0], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(N[Power[im, 4.0], $MachinePrecision] * N[(0.041666666666666664 + N[(N[(re * re), $MachinePrecision] * -0.020833333333333332), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 490:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;{im}^{4} \cdot \left(0.041666666666666664 + \left(re \cdot re\right) \cdot -0.020833333333333332\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot im\right)\right)\\
\end{array}
\end{array}
if im < 490Initial program 100.0%
Taylor expanded in im around 0 87.0%
unpow287.0%
Simplified87.0%
if 490 < im < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in im around 0 72.1%
unpow272.1%
*-commutative72.1%
Simplified72.1%
+-commutative72.1%
metadata-eval72.1%
pow-prod-up72.1%
pow-prod-down72.1%
pow272.1%
associate-*l*72.1%
fma-def72.1%
Applied egg-rr72.1%
Taylor expanded in im around inf 72.1%
*-commutative72.1%
*-commutative72.1%
associate-*l*72.1%
Simplified72.1%
Taylor expanded in re around 0 72.1%
*-commutative72.1%
unpow272.1%
Simplified72.1%
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%
Simplified100.0%
Final simplification88.1%
(FPCore (re im)
:precision binary64
(if (<= im 1.1e+37)
(cos re)
(if (<= im 1.35e+154)
(+ 1.0 (* (pow im 4.0) 0.041666666666666664))
(* 0.5 (* (cos re) (* im im))))))
double code(double re, double im) {
double tmp;
if (im <= 1.1e+37) {
tmp = cos(re);
} else if (im <= 1.35e+154) {
tmp = 1.0 + (pow(im, 4.0) * 0.041666666666666664);
} else {
tmp = 0.5 * (cos(re) * (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 <= 1.1d+37) then
tmp = cos(re)
else if (im <= 1.35d+154) then
tmp = 1.0d0 + ((im ** 4.0d0) * 0.041666666666666664d0)
else
tmp = 0.5d0 * (cos(re) * (im * im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.1e+37) {
tmp = Math.cos(re);
} else if (im <= 1.35e+154) {
tmp = 1.0 + (Math.pow(im, 4.0) * 0.041666666666666664);
} else {
tmp = 0.5 * (Math.cos(re) * (im * im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.1e+37: tmp = math.cos(re) elif im <= 1.35e+154: tmp = 1.0 + (math.pow(im, 4.0) * 0.041666666666666664) else: tmp = 0.5 * (math.cos(re) * (im * im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 1.1e+37) tmp = cos(re); elseif (im <= 1.35e+154) tmp = Float64(1.0 + Float64((im ^ 4.0) * 0.041666666666666664)); else tmp = Float64(0.5 * Float64(cos(re) * Float64(im * im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.1e+37) tmp = cos(re); elseif (im <= 1.35e+154) tmp = 1.0 + ((im ^ 4.0) * 0.041666666666666664); else tmp = 0.5 * (cos(re) * (im * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.1e+37], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(1.0 + N[(N[Power[im, 4.0], $MachinePrecision] * 0.041666666666666664), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.1 \cdot 10^{+37}:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;1 + {im}^{4} \cdot 0.041666666666666664\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\cos re \cdot \left(im \cdot im\right)\right)\\
\end{array}
\end{array}
if im < 1.1e37Initial program 100.0%
Taylor expanded in im around 0 86.1%
unpow286.1%
Simplified86.1%
Taylor expanded in im around 0 71.1%
if 1.1e37 < im < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in im around 0 81.2%
unpow281.2%
*-commutative81.2%
Simplified81.2%
Taylor expanded in re around 0 54.5%
distribute-lft-in54.5%
metadata-eval54.5%
unpow254.5%
+-commutative54.5%
*-commutative54.5%
fma-udef54.5%
*-commutative54.5%
Simplified54.5%
Taylor expanded in im around inf 54.5%
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%
Simplified100.0%
Final simplification74.8%
(FPCore (re im) :precision binary64 (if (<= re 200.0) (+ 1.0 (* (pow im 4.0) 0.041666666666666664)) (* (* (cos re) 0.5) (+ 2.0 (* im im)))))
double code(double re, double im) {
double tmp;
if (re <= 200.0) {
tmp = 1.0 + (pow(im, 4.0) * 0.041666666666666664);
} else {
tmp = (cos(re) * 0.5) * (2.0 + (im * im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= 200.0d0) then
tmp = 1.0d0 + ((im ** 4.0d0) * 0.041666666666666664d0)
else
tmp = (cos(re) * 0.5d0) * (2.0d0 + (im * im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 200.0) {
tmp = 1.0 + (Math.pow(im, 4.0) * 0.041666666666666664);
} else {
tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 200.0: tmp = 1.0 + (math.pow(im, 4.0) * 0.041666666666666664) else: tmp = (math.cos(re) * 0.5) * (2.0 + (im * im)) return tmp
function code(re, im) tmp = 0.0 if (re <= 200.0) tmp = Float64(1.0 + Float64((im ^ 4.0) * 0.041666666666666664)); else tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 200.0) tmp = 1.0 + ((im ^ 4.0) * 0.041666666666666664); else tmp = (cos(re) * 0.5) * (2.0 + (im * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 200.0], N[(1.0 + N[(N[Power[im, 4.0], $MachinePrecision] * 0.041666666666666664), $MachinePrecision]), $MachinePrecision], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 200:\\
\;\;\;\;1 + {im}^{4} \cdot 0.041666666666666664\\
\mathbf{else}:\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\
\end{array}
\end{array}
if re < 200Initial program 100.0%
Taylor expanded in im around 0 92.8%
unpow292.8%
*-commutative92.8%
Simplified92.8%
Taylor expanded in re around 0 69.8%
distribute-lft-in69.8%
metadata-eval69.8%
unpow269.8%
+-commutative69.8%
*-commutative69.8%
fma-udef69.8%
*-commutative69.8%
Simplified69.8%
Taylor expanded in im around inf 69.2%
if 200 < re Initial program 100.0%
Taylor expanded in im around 0 95.1%
unpow295.1%
Simplified95.1%
Final simplification75.1%
(FPCore (re im) :precision binary64 (if (<= im 1.15e+37) (cos re) (+ 1.0 (* (pow im 4.0) 0.041666666666666664))))
double code(double re, double im) {
double tmp;
if (im <= 1.15e+37) {
tmp = cos(re);
} else {
tmp = 1.0 + (pow(im, 4.0) * 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 <= 1.15d+37) then
tmp = cos(re)
else
tmp = 1.0d0 + ((im ** 4.0d0) * 0.041666666666666664d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.15e+37) {
tmp = Math.cos(re);
} else {
tmp = 1.0 + (Math.pow(im, 4.0) * 0.041666666666666664);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.15e+37: tmp = math.cos(re) else: tmp = 1.0 + (math.pow(im, 4.0) * 0.041666666666666664) return tmp
function code(re, im) tmp = 0.0 if (im <= 1.15e+37) tmp = cos(re); else tmp = Float64(1.0 + Float64((im ^ 4.0) * 0.041666666666666664)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.15e+37) tmp = cos(re); else tmp = 1.0 + ((im ^ 4.0) * 0.041666666666666664); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.15e+37], N[Cos[re], $MachinePrecision], N[(1.0 + N[(N[Power[im, 4.0], $MachinePrecision] * 0.041666666666666664), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.15 \cdot 10^{+37}:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;1 + {im}^{4} \cdot 0.041666666666666664\\
\end{array}
\end{array}
if im < 1.15000000000000001e37Initial program 100.0%
Taylor expanded in im around 0 86.1%
unpow286.1%
Simplified86.1%
Taylor expanded in im around 0 71.1%
if 1.15000000000000001e37 < im Initial program 100.0%
Taylor expanded in im around 0 95.0%
unpow295.0%
*-commutative95.0%
Simplified95.0%
Taylor expanded in re around 0 70.0%
distribute-lft-in70.0%
metadata-eval70.0%
unpow270.0%
+-commutative70.0%
*-commutative70.0%
fma-udef70.0%
*-commutative70.0%
Simplified70.0%
Taylor expanded in im around inf 70.0%
Final simplification70.9%
(FPCore (re im) :precision binary64 (if (<= im 1.1e+37) (cos re) (* (pow im 4.0) 0.041666666666666664)))
double code(double re, double im) {
double tmp;
if (im <= 1.1e+37) {
tmp = cos(re);
} else {
tmp = pow(im, 4.0) * 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 <= 1.1d+37) then
tmp = cos(re)
else
tmp = (im ** 4.0d0) * 0.041666666666666664d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.1e+37) {
tmp = Math.cos(re);
} else {
tmp = Math.pow(im, 4.0) * 0.041666666666666664;
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.1e+37: tmp = math.cos(re) else: tmp = math.pow(im, 4.0) * 0.041666666666666664 return tmp
function code(re, im) tmp = 0.0 if (im <= 1.1e+37) tmp = cos(re); else tmp = Float64((im ^ 4.0) * 0.041666666666666664); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.1e+37) tmp = cos(re); else tmp = (im ^ 4.0) * 0.041666666666666664; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.1e+37], N[Cos[re], $MachinePrecision], N[(N[Power[im, 4.0], $MachinePrecision] * 0.041666666666666664), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.1 \cdot 10^{+37}:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;{im}^{4} \cdot 0.041666666666666664\\
\end{array}
\end{array}
if im < 1.1e37Initial program 100.0%
Taylor expanded in im around 0 86.1%
unpow286.1%
Simplified86.1%
Taylor expanded in im around 0 71.1%
if 1.1e37 < im Initial program 100.0%
Taylor expanded in im around 0 95.0%
unpow295.0%
*-commutative95.0%
Simplified95.0%
+-commutative95.0%
metadata-eval95.0%
pow-prod-up95.0%
pow-prod-down95.0%
pow295.0%
associate-*l*95.0%
fma-def95.0%
Applied egg-rr95.0%
Taylor expanded in im around inf 95.0%
*-commutative95.0%
*-commutative95.0%
associate-*l*95.0%
Simplified95.0%
Taylor expanded in re around 0 70.0%
Final simplification70.9%
(FPCore (re im)
:precision binary64
(if (<= im 420.0)
(cos re)
(if (<= im 5e+172)
(* 0.5 (* (* im im) (+ 1.0 (* re (* re -0.5)))))
(+ 1.0 (* 0.5 (* im im))))))
double code(double re, double im) {
double tmp;
if (im <= 420.0) {
tmp = cos(re);
} else if (im <= 5e+172) {
tmp = 0.5 * ((im * im) * (1.0 + (re * (re * -0.5))));
} 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 <= 420.0d0) then
tmp = cos(re)
else if (im <= 5d+172) then
tmp = 0.5d0 * ((im * im) * (1.0d0 + (re * (re * (-0.5d0)))))
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 <= 420.0) {
tmp = Math.cos(re);
} else if (im <= 5e+172) {
tmp = 0.5 * ((im * im) * (1.0 + (re * (re * -0.5))));
} else {
tmp = 1.0 + (0.5 * (im * im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 420.0: tmp = math.cos(re) elif im <= 5e+172: tmp = 0.5 * ((im * im) * (1.0 + (re * (re * -0.5)))) else: tmp = 1.0 + (0.5 * (im * im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 420.0) tmp = cos(re); elseif (im <= 5e+172) tmp = Float64(0.5 * Float64(Float64(im * im) * Float64(1.0 + Float64(re * Float64(re * -0.5))))); 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 <= 420.0) tmp = cos(re); elseif (im <= 5e+172) tmp = 0.5 * ((im * im) * (1.0 + (re * (re * -0.5)))); else tmp = 1.0 + (0.5 * (im * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 420.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 5e+172], N[(0.5 * N[(N[(im * im), $MachinePrecision] * N[(1.0 + N[(re * N[(re * -0.5), $MachinePrecision]), $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 420:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 5 \cdot 10^{+172}:\\
\;\;\;\;0.5 \cdot \left(\left(im \cdot im\right) \cdot \left(1 + re \cdot \left(re \cdot -0.5\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;1 + 0.5 \cdot \left(im \cdot im\right)\\
\end{array}
\end{array}
if im < 420Initial program 100.0%
Taylor expanded in im around 0 87.0%
unpow287.0%
Simplified87.0%
Taylor expanded in im around 0 71.8%
if 420 < im < 5.0000000000000001e172Initial program 100.0%
Taylor expanded in im around 0 11.1%
unpow211.1%
Simplified11.1%
Taylor expanded in im around inf 11.1%
unpow211.1%
Simplified11.1%
Taylor expanded in re around 0 26.3%
unpow226.3%
unpow226.3%
unpow226.3%
associate-*r*26.3%
distribute-rgt1-in31.9%
+-commutative31.9%
associate-*r*31.9%
Simplified31.9%
if 5.0000000000000001e172 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
unpow2100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in re around 0 75.0%
distribute-lft-in75.0%
metadata-eval75.0%
unpow275.0%
+-commutative75.0%
*-commutative75.0%
fma-udef75.0%
*-commutative75.0%
Simplified75.0%
Taylor expanded in im around 0 75.0%
unpow275.0%
Simplified75.0%
Final simplification69.5%
(FPCore (re im) :precision binary64 (if (or (<= im 880000000000.0) (not (<= im 1e+172))) (+ 1.0 (* 0.5 (* im im))) (* 0.5 (* (* im im) (+ 1.0 (* re (* re -0.5)))))))
double code(double re, double im) {
double tmp;
if ((im <= 880000000000.0) || !(im <= 1e+172)) {
tmp = 1.0 + (0.5 * (im * im));
} else {
tmp = 0.5 * ((im * im) * (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 <= 880000000000.0d0) .or. (.not. (im <= 1d+172))) then
tmp = 1.0d0 + (0.5d0 * (im * im))
else
tmp = 0.5d0 * ((im * im) * (1.0d0 + (re * (re * (-0.5d0)))))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((im <= 880000000000.0) || !(im <= 1e+172)) {
tmp = 1.0 + (0.5 * (im * im));
} else {
tmp = 0.5 * ((im * im) * (1.0 + (re * (re * -0.5))));
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= 880000000000.0) or not (im <= 1e+172): tmp = 1.0 + (0.5 * (im * im)) else: tmp = 0.5 * ((im * im) * (1.0 + (re * (re * -0.5)))) return tmp
function code(re, im) tmp = 0.0 if ((im <= 880000000000.0) || !(im <= 1e+172)) tmp = Float64(1.0 + Float64(0.5 * Float64(im * im))); else tmp = Float64(0.5 * Float64(Float64(im * im) * Float64(1.0 + Float64(re * Float64(re * -0.5))))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((im <= 880000000000.0) || ~((im <= 1e+172))) tmp = 1.0 + (0.5 * (im * im)); else tmp = 0.5 * ((im * im) * (1.0 + (re * (re * -0.5)))); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, 880000000000.0], N[Not[LessEqual[im, 1e+172]], $MachinePrecision]], N[(1.0 + N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(im * im), $MachinePrecision] * N[(1.0 + N[(re * N[(re * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 880000000000 \lor \neg \left(im \leq 10^{+172}\right):\\
\;\;\;\;1 + 0.5 \cdot \left(im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\left(im \cdot im\right) \cdot \left(1 + re \cdot \left(re \cdot -0.5\right)\right)\right)\\
\end{array}
\end{array}
if im < 8.8e11 or 1.0000000000000001e172 < im Initial program 100.0%
Taylor expanded in im around 0 95.6%
unpow295.6%
*-commutative95.6%
Simplified95.6%
Taylor expanded in re around 0 59.5%
distribute-lft-in59.5%
metadata-eval59.5%
unpow259.5%
+-commutative59.5%
*-commutative59.5%
fma-udef59.5%
*-commutative59.5%
Simplified59.5%
Taylor expanded in im around 0 54.3%
unpow254.3%
Simplified54.3%
if 8.8e11 < im < 1.0000000000000001e172Initial program 100.0%
Taylor expanded in im around 0 11.5%
unpow211.5%
Simplified11.5%
Taylor expanded in im around inf 11.5%
unpow211.5%
Simplified11.5%
Taylor expanded in re around 0 27.7%
unpow227.7%
unpow227.7%
unpow227.7%
associate-*r*27.7%
distribute-rgt1-in33.6%
+-commutative33.6%
associate-*r*33.6%
Simplified33.6%
Final simplification52.9%
(FPCore (re im) :precision binary64 (if (or (<= im 4500000000000.0) (not (<= im 1.55e+138))) (+ 1.0 (* 0.5 (* im im))) (* im (* im (* (* re re) -0.25)))))
double code(double re, double im) {
double tmp;
if ((im <= 4500000000000.0) || !(im <= 1.55e+138)) {
tmp = 1.0 + (0.5 * (im * im));
} else {
tmp = im * (im * ((re * re) * -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 <= 4500000000000.0d0) .or. (.not. (im <= 1.55d+138))) then
tmp = 1.0d0 + (0.5d0 * (im * im))
else
tmp = im * (im * ((re * re) * (-0.25d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((im <= 4500000000000.0) || !(im <= 1.55e+138)) {
tmp = 1.0 + (0.5 * (im * im));
} else {
tmp = im * (im * ((re * re) * -0.25));
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= 4500000000000.0) or not (im <= 1.55e+138): tmp = 1.0 + (0.5 * (im * im)) else: tmp = im * (im * ((re * re) * -0.25)) return tmp
function code(re, im) tmp = 0.0 if ((im <= 4500000000000.0) || !(im <= 1.55e+138)) tmp = Float64(1.0 + Float64(0.5 * Float64(im * im))); else tmp = Float64(im * Float64(im * Float64(Float64(re * re) * -0.25))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((im <= 4500000000000.0) || ~((im <= 1.55e+138))) tmp = 1.0 + (0.5 * (im * im)); else tmp = im * (im * ((re * re) * -0.25)); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, 4500000000000.0], N[Not[LessEqual[im, 1.55e+138]], $MachinePrecision]], N[(1.0 + N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(im * N[(im * N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 4500000000000 \lor \neg \left(im \leq 1.55 \cdot 10^{+138}\right):\\
\;\;\;\;1 + 0.5 \cdot \left(im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;im \cdot \left(im \cdot \left(\left(re \cdot re\right) \cdot -0.25\right)\right)\\
\end{array}
\end{array}
if im < 4.5e12 or 1.5499999999999999e138 < im Initial program 100.0%
Taylor expanded in im around 0 95.6%
unpow295.6%
*-commutative95.6%
Simplified95.6%
Taylor expanded in re around 0 60.0%
distribute-lft-in60.0%
metadata-eval60.0%
unpow260.0%
+-commutative60.0%
*-commutative60.0%
fma-udef60.0%
*-commutative60.0%
Simplified60.0%
Taylor expanded in im around 0 54.1%
unpow254.1%
Simplified54.1%
if 4.5e12 < im < 1.5499999999999999e138Initial program 100.0%
Taylor expanded in im around 0 5.4%
unpow25.4%
Simplified5.4%
Taylor expanded in re around 0 32.2%
*-commutative32.2%
unpow232.2%
+-commutative32.2%
fma-udef32.2%
*-commutative32.2%
unpow232.2%
+-commutative32.2%
fma-udef32.2%
associate-*l*32.2%
distribute-lft-out32.2%
unpow232.2%
Simplified32.2%
Taylor expanded in im around inf 32.2%
unpow232.2%
*-commutative32.2%
+-commutative32.2%
unpow232.2%
*-commutative32.2%
associate-*r*32.2%
fma-udef32.2%
associate-*l*32.2%
fma-udef32.2%
associate-*r*32.2%
*-commutative32.2%
fma-def32.2%
Simplified32.2%
Taylor expanded in re around inf 29.5%
*-commutative29.5%
*-commutative29.5%
associate-*r*29.5%
unpow229.5%
Simplified29.5%
Final simplification52.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 94.4%
unpow294.4%
*-commutative94.4%
Simplified94.4%
Taylor expanded in re around 0 59.2%
distribute-lft-in59.2%
metadata-eval59.2%
unpow259.2%
+-commutative59.2%
*-commutative59.2%
fma-udef59.2%
*-commutative59.2%
Simplified59.2%
Taylor expanded in im around 0 51.3%
unpow251.3%
Simplified51.3%
Final simplification51.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 83.7%
unpow283.7%
Simplified83.7%
Taylor expanded in re around 0 32.6%
*-commutative32.6%
unpow232.6%
+-commutative32.6%
fma-udef32.6%
*-commutative32.6%
unpow232.6%
+-commutative32.6%
fma-udef32.6%
associate-*l*32.6%
distribute-lft-out48.2%
unpow248.2%
Simplified48.2%
Taylor expanded in im around inf 21.3%
unpow221.3%
*-commutative21.3%
+-commutative21.3%
unpow221.3%
*-commutative21.3%
associate-*r*21.3%
fma-udef21.3%
associate-*l*21.4%
fma-udef21.4%
associate-*r*21.4%
*-commutative21.4%
fma-def21.4%
Simplified21.4%
Taylor expanded in re around 0 22.8%
Final simplification22.8%
herbie shell --seed 2023238
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))