
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp(-im) + exp(im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * (exp(-im) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp(-im) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 15 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp(-im) + exp(im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * (exp(-im) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp(-im) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
\end{array}
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp(-im) + exp(im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * (exp(-im) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp(-im) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (re im)
:precision binary64
(if (<= im 0.035)
(* (* 0.5 (cos re)) (+ 2.0 (* im im)))
(if (<= im 1.15e+77)
(* (+ (exp (- im)) (exp im)) (cbrt 0.125))
(* (cos re) (* (pow im 4.0) 0.041666666666666664)))))
double code(double re, double im) {
double tmp;
if (im <= 0.035) {
tmp = (0.5 * cos(re)) * (2.0 + (im * im));
} else if (im <= 1.15e+77) {
tmp = (exp(-im) + exp(im)) * cbrt(0.125);
} else {
tmp = cos(re) * (pow(im, 4.0) * 0.041666666666666664);
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (im <= 0.035) {
tmp = (0.5 * Math.cos(re)) * (2.0 + (im * im));
} else if (im <= 1.15e+77) {
tmp = (Math.exp(-im) + Math.exp(im)) * Math.cbrt(0.125);
} else {
tmp = Math.cos(re) * (Math.pow(im, 4.0) * 0.041666666666666664);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 0.035) tmp = Float64(Float64(0.5 * cos(re)) * Float64(2.0 + Float64(im * im))); elseif (im <= 1.15e+77) tmp = Float64(Float64(exp(Float64(-im)) + exp(im)) * cbrt(0.125)); else tmp = Float64(cos(re) * Float64((im ^ 4.0) * 0.041666666666666664)); end return tmp end
code[re_, im_] := If[LessEqual[im, 0.035], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.15e+77], N[(N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision] * N[Power[0.125, 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(N[Power[im, 4.0], $MachinePrecision] * 0.041666666666666664), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.035:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(2 + im \cdot im\right)\\
\mathbf{elif}\;im \leq 1.15 \cdot 10^{+77}:\\
\;\;\;\;\left(e^{-im} + e^{im}\right) \cdot \sqrt[3]{0.125}\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left({im}^{4} \cdot 0.041666666666666664\right)\\
\end{array}
\end{array}
if im < 0.035000000000000003Initial program 100.0%
Taylor expanded in im around 0 88.4%
unpow288.4%
Simplified88.4%
if 0.035000000000000003 < im < 1.14999999999999997e77Initial program 100.0%
Taylor expanded in re around 0 0.1%
associate-*r*0.1%
distribute-rgt-out61.2%
unpow261.2%
Simplified61.2%
add-cbrt-cube61.1%
pow361.1%
+-commutative61.1%
fma-def61.1%
Applied egg-rr61.1%
Taylor expanded in re around 0 73.1%
if 1.14999999999999997e77 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
associate-+r+100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
*-commutative100.0%
associate-*l*100.0%
Simplified100.0%
Final simplification89.4%
(FPCore (re im) :precision binary64 (if (<= (cos re) 0.982) (* (* 0.5 (cos re)) (+ 2.0 (* im im))) (+ 1.0 (* 0.5 (+ (* im im) (* (pow im 4.0) 0.08333333333333333))))))
double code(double re, double im) {
double tmp;
if (cos(re) <= 0.982) {
tmp = (0.5 * cos(re)) * (2.0 + (im * im));
} else {
tmp = 1.0 + (0.5 * ((im * im) + (pow(im, 4.0) * 0.08333333333333333)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (cos(re) <= 0.982d0) then
tmp = (0.5d0 * cos(re)) * (2.0d0 + (im * im))
else
tmp = 1.0d0 + (0.5d0 * ((im * im) + ((im ** 4.0d0) * 0.08333333333333333d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (Math.cos(re) <= 0.982) {
tmp = (0.5 * Math.cos(re)) * (2.0 + (im * im));
} else {
tmp = 1.0 + (0.5 * ((im * im) + (Math.pow(im, 4.0) * 0.08333333333333333)));
}
return tmp;
}
def code(re, im): tmp = 0 if math.cos(re) <= 0.982: tmp = (0.5 * math.cos(re)) * (2.0 + (im * im)) else: tmp = 1.0 + (0.5 * ((im * im) + (math.pow(im, 4.0) * 0.08333333333333333))) return tmp
function code(re, im) tmp = 0.0 if (cos(re) <= 0.982) tmp = Float64(Float64(0.5 * cos(re)) * Float64(2.0 + Float64(im * im))); else tmp = Float64(1.0 + Float64(0.5 * Float64(Float64(im * im) + Float64((im ^ 4.0) * 0.08333333333333333)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (cos(re) <= 0.982) tmp = (0.5 * cos(re)) * (2.0 + (im * im)); else tmp = 1.0 + (0.5 * ((im * im) + ((im ^ 4.0) * 0.08333333333333333))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Cos[re], $MachinePrecision], 0.982], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(0.5 * N[(N[(im * im), $MachinePrecision] + N[(N[Power[im, 4.0], $MachinePrecision] * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos re \leq 0.982:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(2 + im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;1 + 0.5 \cdot \left(im \cdot im + {im}^{4} \cdot 0.08333333333333333\right)\\
\end{array}
\end{array}
if (cos.f64 re) < 0.98199999999999998Initial program 100.0%
Taylor expanded in im around 0 83.1%
unpow283.1%
Simplified83.1%
if 0.98199999999999998 < (cos.f64 re) Initial program 100.0%
Taylor expanded in im around 0 88.1%
associate-+r+88.1%
unpow288.1%
Simplified88.1%
Taylor expanded in re around 0 87.5%
distribute-lft-in87.5%
metadata-eval87.5%
unpow287.5%
Simplified87.5%
Final simplification85.4%
(FPCore (re im)
:precision binary64
(if (<= im 560.0)
(* (* 0.5 (cos re)) (+ 2.0 (* im im)))
(if (<= im 2.16e+64)
(*
(+ 2.0 (+ (* im im) (* (pow im 4.0) 0.08333333333333333)))
(+ 0.5 (* -0.25 (* re re))))
(* (cos re) (* (pow im 4.0) 0.041666666666666664)))))
double code(double re, double im) {
double tmp;
if (im <= 560.0) {
tmp = (0.5 * cos(re)) * (2.0 + (im * im));
} else if (im <= 2.16e+64) {
tmp = (2.0 + ((im * im) + (pow(im, 4.0) * 0.08333333333333333))) * (0.5 + (-0.25 * (re * re)));
} else {
tmp = cos(re) * (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 <= 560.0d0) then
tmp = (0.5d0 * cos(re)) * (2.0d0 + (im * im))
else if (im <= 2.16d+64) then
tmp = (2.0d0 + ((im * im) + ((im ** 4.0d0) * 0.08333333333333333d0))) * (0.5d0 + ((-0.25d0) * (re * re)))
else
tmp = cos(re) * ((im ** 4.0d0) * 0.041666666666666664d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 560.0) {
tmp = (0.5 * Math.cos(re)) * (2.0 + (im * im));
} else if (im <= 2.16e+64) {
tmp = (2.0 + ((im * im) + (Math.pow(im, 4.0) * 0.08333333333333333))) * (0.5 + (-0.25 * (re * re)));
} else {
tmp = Math.cos(re) * (Math.pow(im, 4.0) * 0.041666666666666664);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 560.0: tmp = (0.5 * math.cos(re)) * (2.0 + (im * im)) elif im <= 2.16e+64: tmp = (2.0 + ((im * im) + (math.pow(im, 4.0) * 0.08333333333333333))) * (0.5 + (-0.25 * (re * re))) else: tmp = math.cos(re) * (math.pow(im, 4.0) * 0.041666666666666664) return tmp
function code(re, im) tmp = 0.0 if (im <= 560.0) tmp = Float64(Float64(0.5 * cos(re)) * Float64(2.0 + Float64(im * im))); elseif (im <= 2.16e+64) tmp = Float64(Float64(2.0 + Float64(Float64(im * im) + Float64((im ^ 4.0) * 0.08333333333333333))) * Float64(0.5 + Float64(-0.25 * Float64(re * re)))); else tmp = Float64(cos(re) * Float64((im ^ 4.0) * 0.041666666666666664)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 560.0) tmp = (0.5 * cos(re)) * (2.0 + (im * im)); elseif (im <= 2.16e+64) tmp = (2.0 + ((im * im) + ((im ^ 4.0) * 0.08333333333333333))) * (0.5 + (-0.25 * (re * re))); else tmp = cos(re) * ((im ^ 4.0) * 0.041666666666666664); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 560.0], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 2.16e+64], N[(N[(2.0 + N[(N[(im * im), $MachinePrecision] + N[(N[Power[im, 4.0], $MachinePrecision] * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(0.5 + N[(-0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(N[Power[im, 4.0], $MachinePrecision] * 0.041666666666666664), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 560:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(2 + im \cdot im\right)\\
\mathbf{elif}\;im \leq 2.16 \cdot 10^{+64}:\\
\;\;\;\;\left(2 + \left(im \cdot im + {im}^{4} \cdot 0.08333333333333333\right)\right) \cdot \left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left({im}^{4} \cdot 0.041666666666666664\right)\\
\end{array}
\end{array}
if im < 560Initial program 100.0%
Taylor expanded in im around 0 88.0%
unpow288.0%
Simplified88.0%
if 560 < im < 2.16000000000000014e64Initial program 100.0%
Taylor expanded in re around 0 0.0%
associate-*r*0.0%
distribute-rgt-out64.3%
unpow264.3%
Simplified64.3%
Taylor expanded in im around 0 30.4%
unpow230.4%
Simplified30.4%
if 2.16000000000000014e64 < im Initial program 100.0%
Taylor expanded in im around 0 94.3%
associate-+r+94.3%
unpow294.3%
Simplified94.3%
Taylor expanded in im around inf 94.3%
*-commutative94.3%
associate-*l*94.3%
Simplified94.3%
Final simplification86.0%
(FPCore (re im)
:precision binary64
(if (<= im 0.046)
(* (* 0.5 (cos re)) (+ 2.0 (* im im)))
(if (<= im 1.15e+77)
(* 0.5 (+ (exp (- im)) (exp im)))
(* (cos re) (* (pow im 4.0) 0.041666666666666664)))))
double code(double re, double im) {
double tmp;
if (im <= 0.046) {
tmp = (0.5 * cos(re)) * (2.0 + (im * im));
} else if (im <= 1.15e+77) {
tmp = 0.5 * (exp(-im) + exp(im));
} else {
tmp = cos(re) * (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 <= 0.046d0) then
tmp = (0.5d0 * cos(re)) * (2.0d0 + (im * im))
else if (im <= 1.15d+77) then
tmp = 0.5d0 * (exp(-im) + exp(im))
else
tmp = cos(re) * ((im ** 4.0d0) * 0.041666666666666664d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 0.046) {
tmp = (0.5 * Math.cos(re)) * (2.0 + (im * im));
} else if (im <= 1.15e+77) {
tmp = 0.5 * (Math.exp(-im) + Math.exp(im));
} else {
tmp = Math.cos(re) * (Math.pow(im, 4.0) * 0.041666666666666664);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 0.046: tmp = (0.5 * math.cos(re)) * (2.0 + (im * im)) elif im <= 1.15e+77: tmp = 0.5 * (math.exp(-im) + math.exp(im)) else: tmp = math.cos(re) * (math.pow(im, 4.0) * 0.041666666666666664) return tmp
function code(re, im) tmp = 0.0 if (im <= 0.046) tmp = Float64(Float64(0.5 * cos(re)) * Float64(2.0 + Float64(im * im))); elseif (im <= 1.15e+77) tmp = Float64(0.5 * Float64(exp(Float64(-im)) + exp(im))); else tmp = Float64(cos(re) * Float64((im ^ 4.0) * 0.041666666666666664)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 0.046) tmp = (0.5 * cos(re)) * (2.0 + (im * im)); elseif (im <= 1.15e+77) tmp = 0.5 * (exp(-im) + exp(im)); else tmp = cos(re) * ((im ^ 4.0) * 0.041666666666666664); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 0.046], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.15e+77], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(N[Power[im, 4.0], $MachinePrecision] * 0.041666666666666664), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.046:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(2 + im \cdot im\right)\\
\mathbf{elif}\;im \leq 1.15 \cdot 10^{+77}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left({im}^{4} \cdot 0.041666666666666664\right)\\
\end{array}
\end{array}
if im < 0.045999999999999999Initial program 100.0%
Taylor expanded in im around 0 88.4%
unpow288.4%
Simplified88.4%
if 0.045999999999999999 < im < 1.14999999999999997e77Initial program 100.0%
Taylor expanded in re around 0 73.1%
*-commutative73.1%
Simplified73.1%
if 1.14999999999999997e77 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
associate-+r+100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
*-commutative100.0%
associate-*l*100.0%
Simplified100.0%
Final simplification89.4%
(FPCore (re im)
:precision binary64
(if (<= im 520.0)
(* (* 0.5 (cos re)) (+ 2.0 (* im im)))
(if (<= im 2.45e+154)
(*
(+ 2.0 (+ (* im im) (* (pow im 4.0) 0.08333333333333333)))
(+ 0.5 (* -0.25 (* re re))))
(* im (* 0.5 (* (cos re) im))))))
double code(double re, double im) {
double tmp;
if (im <= 520.0) {
tmp = (0.5 * cos(re)) * (2.0 + (im * im));
} else if (im <= 2.45e+154) {
tmp = (2.0 + ((im * im) + (pow(im, 4.0) * 0.08333333333333333))) * (0.5 + (-0.25 * (re * re)));
} else {
tmp = im * (0.5 * (cos(re) * im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 520.0d0) then
tmp = (0.5d0 * cos(re)) * (2.0d0 + (im * im))
else if (im <= 2.45d+154) then
tmp = (2.0d0 + ((im * im) + ((im ** 4.0d0) * 0.08333333333333333d0))) * (0.5d0 + ((-0.25d0) * (re * re)))
else
tmp = im * (0.5d0 * (cos(re) * im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 520.0) {
tmp = (0.5 * Math.cos(re)) * (2.0 + (im * im));
} else if (im <= 2.45e+154) {
tmp = (2.0 + ((im * im) + (Math.pow(im, 4.0) * 0.08333333333333333))) * (0.5 + (-0.25 * (re * re)));
} else {
tmp = im * (0.5 * (Math.cos(re) * im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 520.0: tmp = (0.5 * math.cos(re)) * (2.0 + (im * im)) elif im <= 2.45e+154: tmp = (2.0 + ((im * im) + (math.pow(im, 4.0) * 0.08333333333333333))) * (0.5 + (-0.25 * (re * re))) else: tmp = im * (0.5 * (math.cos(re) * im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 520.0) tmp = Float64(Float64(0.5 * cos(re)) * Float64(2.0 + Float64(im * im))); elseif (im <= 2.45e+154) tmp = Float64(Float64(2.0 + Float64(Float64(im * im) + Float64((im ^ 4.0) * 0.08333333333333333))) * Float64(0.5 + Float64(-0.25 * Float64(re * re)))); else tmp = Float64(im * Float64(0.5 * Float64(cos(re) * im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 520.0) tmp = (0.5 * cos(re)) * (2.0 + (im * im)); elseif (im <= 2.45e+154) tmp = (2.0 + ((im * im) + ((im ^ 4.0) * 0.08333333333333333))) * (0.5 + (-0.25 * (re * re))); else tmp = im * (0.5 * (cos(re) * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 520.0], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 2.45e+154], N[(N[(2.0 + N[(N[(im * im), $MachinePrecision] + N[(N[Power[im, 4.0], $MachinePrecision] * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(0.5 + N[(-0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(im * N[(0.5 * N[(N[Cos[re], $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 520:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(2 + im \cdot im\right)\\
\mathbf{elif}\;im \leq 2.45 \cdot 10^{+154}:\\
\;\;\;\;\left(2 + \left(im \cdot im + {im}^{4} \cdot 0.08333333333333333\right)\right) \cdot \left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right)\\
\mathbf{else}:\\
\;\;\;\;im \cdot \left(0.5 \cdot \left(\cos re \cdot im\right)\right)\\
\end{array}
\end{array}
if im < 520Initial program 100.0%
Taylor expanded in im around 0 88.0%
unpow288.0%
Simplified88.0%
if 520 < im < 2.4500000000000001e154Initial program 100.0%
Taylor expanded in re around 0 0.0%
associate-*r*0.0%
distribute-rgt-out64.3%
unpow264.3%
Simplified64.3%
Taylor expanded in im around 0 40.9%
unpow240.9%
Simplified40.9%
if 2.4500000000000001e154 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
associate-*r*100.0%
unpow2100.0%
associate-*r*100.0%
*-commutative100.0%
associate-*l*100.0%
*-commutative100.0%
Simplified100.0%
Final simplification84.4%
(FPCore (re im)
:precision binary64
(if (<= im 420.0)
(cos re)
(if (<= im 5.7e+138)
(* (+ 2.0 (* im im)) (+ 0.5 (* -0.25 (* re re))))
(* im (* 0.5 (* (cos re) im))))))
double code(double re, double im) {
double tmp;
if (im <= 420.0) {
tmp = cos(re);
} else if (im <= 5.7e+138) {
tmp = (2.0 + (im * im)) * (0.5 + (-0.25 * (re * re)));
} else {
tmp = im * (0.5 * (cos(re) * im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 420.0d0) then
tmp = cos(re)
else if (im <= 5.7d+138) then
tmp = (2.0d0 + (im * im)) * (0.5d0 + ((-0.25d0) * (re * re)))
else
tmp = im * (0.5d0 * (cos(re) * im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 420.0) {
tmp = Math.cos(re);
} else if (im <= 5.7e+138) {
tmp = (2.0 + (im * im)) * (0.5 + (-0.25 * (re * re)));
} else {
tmp = im * (0.5 * (Math.cos(re) * im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 420.0: tmp = math.cos(re) elif im <= 5.7e+138: tmp = (2.0 + (im * im)) * (0.5 + (-0.25 * (re * re))) else: tmp = im * (0.5 * (math.cos(re) * im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 420.0) tmp = cos(re); elseif (im <= 5.7e+138) tmp = Float64(Float64(2.0 + Float64(im * im)) * Float64(0.5 + Float64(-0.25 * Float64(re * re)))); else tmp = Float64(im * Float64(0.5 * Float64(cos(re) * im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 420.0) tmp = cos(re); elseif (im <= 5.7e+138) tmp = (2.0 + (im * im)) * (0.5 + (-0.25 * (re * re))); else tmp = im * (0.5 * (cos(re) * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 420.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 5.7e+138], N[(N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision] * N[(0.5 + N[(-0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(im * N[(0.5 * N[(N[Cos[re], $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 420:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 5.7 \cdot 10^{+138}:\\
\;\;\;\;\left(2 + im \cdot im\right) \cdot \left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right)\\
\mathbf{else}:\\
\;\;\;\;im \cdot \left(0.5 \cdot \left(\cos re \cdot im\right)\right)\\
\end{array}
\end{array}
if im < 420Initial program 100.0%
Taylor expanded in im around 0 73.5%
if 420 < im < 5.69999999999999986e138Initial program 100.0%
Taylor expanded in re around 0 0.0%
associate-*r*0.0%
distribute-rgt-out68.0%
unpow268.0%
Simplified68.0%
Taylor expanded in im around 0 15.0%
unpow215.0%
Simplified15.0%
if 5.69999999999999986e138 < im Initial program 100.0%
Taylor expanded in im around 0 92.7%
unpow292.7%
Simplified92.7%
Taylor expanded in im around inf 92.7%
associate-*r*92.7%
unpow292.7%
associate-*r*92.7%
*-commutative92.7%
associate-*l*92.7%
*-commutative92.7%
Simplified92.7%
Final simplification70.6%
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ 2.0 (* im im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (2.0 + (im * im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * (2.0d0 + (im * im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (2.0 + (im * im));
}
def code(re, im): return (0.5 * math.cos(re)) * (2.0 + (im * im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(2.0 + Float64(im * im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (2.0 + (im * im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(2 + im \cdot im\right)
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 80.5%
unpow280.5%
Simplified80.5%
Final simplification80.5%
(FPCore (re im) :precision binary64 (if (<= im 480.0) (cos re) (* (+ 2.0 (* im im)) (+ 0.5 (* -0.25 (* re re))))))
double code(double re, double im) {
double tmp;
if (im <= 480.0) {
tmp = cos(re);
} else {
tmp = (2.0 + (im * im)) * (0.5 + (-0.25 * (re * re)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 480.0d0) then
tmp = cos(re)
else
tmp = (2.0d0 + (im * im)) * (0.5d0 + ((-0.25d0) * (re * re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 480.0) {
tmp = Math.cos(re);
} else {
tmp = (2.0 + (im * im)) * (0.5 + (-0.25 * (re * re)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 480.0: tmp = math.cos(re) else: tmp = (2.0 + (im * im)) * (0.5 + (-0.25 * (re * re))) return tmp
function code(re, im) tmp = 0.0 if (im <= 480.0) tmp = cos(re); else tmp = Float64(Float64(2.0 + Float64(im * im)) * Float64(0.5 + Float64(-0.25 * Float64(re * re)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 480.0) tmp = cos(re); else tmp = (2.0 + (im * im)) * (0.5 + (-0.25 * (re * re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 480.0], N[Cos[re], $MachinePrecision], N[(N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision] * N[(0.5 + N[(-0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 480:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;\left(2 + im \cdot im\right) \cdot \left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right)\\
\end{array}
\end{array}
if im < 480Initial program 100.0%
Taylor expanded in im around 0 73.5%
if 480 < im Initial program 100.0%
Taylor expanded in re around 0 0.0%
associate-*r*0.0%
distribute-rgt-out71.0%
unpow271.0%
Simplified71.0%
Taylor expanded in im around 0 48.2%
unpow248.2%
Simplified48.2%
Final simplification67.4%
(FPCore (re im) :precision binary64 (if (<= im 170.0) (+ 1.0 (* 0.5 (* im im))) (* (+ 2.0 (* im im)) (+ 0.5 (* -0.25 (* re re))))))
double code(double re, double im) {
double tmp;
if (im <= 170.0) {
tmp = 1.0 + (0.5 * (im * im));
} else {
tmp = (2.0 + (im * im)) * (0.5 + (-0.25 * (re * re)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 170.0d0) then
tmp = 1.0d0 + (0.5d0 * (im * im))
else
tmp = (2.0d0 + (im * im)) * (0.5d0 + ((-0.25d0) * (re * re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 170.0) {
tmp = 1.0 + (0.5 * (im * im));
} else {
tmp = (2.0 + (im * im)) * (0.5 + (-0.25 * (re * re)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 170.0: tmp = 1.0 + (0.5 * (im * im)) else: tmp = (2.0 + (im * im)) * (0.5 + (-0.25 * (re * re))) return tmp
function code(re, im) tmp = 0.0 if (im <= 170.0) tmp = Float64(1.0 + Float64(0.5 * Float64(im * im))); else tmp = Float64(Float64(2.0 + Float64(im * im)) * Float64(0.5 + Float64(-0.25 * Float64(re * re)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 170.0) tmp = 1.0 + (0.5 * (im * im)); else tmp = (2.0 + (im * im)) * (0.5 + (-0.25 * (re * re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 170.0], N[(1.0 + N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision] * N[(0.5 + N[(-0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 170:\\
\;\;\;\;1 + 0.5 \cdot \left(im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;\left(2 + im \cdot im\right) \cdot \left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right)\\
\end{array}
\end{array}
if im < 170Initial program 100.0%
Taylor expanded in im around 0 88.0%
unpow288.0%
Simplified88.0%
Taylor expanded in re around 0 50.9%
distribute-lft-in50.9%
metadata-eval50.9%
unpow250.9%
Simplified50.9%
if 170 < im Initial program 100.0%
Taylor expanded in re around 0 0.0%
associate-*r*0.0%
distribute-rgt-out71.0%
unpow271.0%
Simplified71.0%
Taylor expanded in im around 0 48.2%
unpow248.2%
Simplified48.2%
Final simplification50.2%
(FPCore (re im) :precision binary64 (if (<= re 9e+134) (+ 1.0 (* 0.5 (* im im))) (* 2.0 (+ 0.5 (* -0.25 (* re re))))))
double code(double re, double im) {
double tmp;
if (re <= 9e+134) {
tmp = 1.0 + (0.5 * (im * im));
} else {
tmp = 2.0 * (0.5 + (-0.25 * (re * re)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= 9d+134) then
tmp = 1.0d0 + (0.5d0 * (im * im))
else
tmp = 2.0d0 * (0.5d0 + ((-0.25d0) * (re * re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 9e+134) {
tmp = 1.0 + (0.5 * (im * im));
} else {
tmp = 2.0 * (0.5 + (-0.25 * (re * re)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 9e+134: tmp = 1.0 + (0.5 * (im * im)) else: tmp = 2.0 * (0.5 + (-0.25 * (re * re))) return tmp
function code(re, im) tmp = 0.0 if (re <= 9e+134) tmp = Float64(1.0 + Float64(0.5 * Float64(im * im))); else tmp = Float64(2.0 * Float64(0.5 + Float64(-0.25 * Float64(re * re)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 9e+134) tmp = 1.0 + (0.5 * (im * im)); else tmp = 2.0 * (0.5 + (-0.25 * (re * re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 9e+134], N[(1.0 + N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(0.5 + N[(-0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 9 \cdot 10^{+134}:\\
\;\;\;\;1 + 0.5 \cdot \left(im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right)\\
\end{array}
\end{array}
if re < 8.9999999999999995e134Initial program 100.0%
Taylor expanded in im around 0 79.6%
unpow279.6%
Simplified79.6%
Taylor expanded in re around 0 52.7%
distribute-lft-in52.7%
metadata-eval52.7%
unpow252.7%
Simplified52.7%
if 8.9999999999999995e134 < re Initial program 100.0%
Taylor expanded in re around 0 1.0%
associate-*r*1.0%
distribute-rgt-out29.6%
unpow229.6%
Simplified29.6%
Taylor expanded in im around 0 24.4%
Final simplification48.9%
(FPCore (re im) :precision binary64 (if (<= re 9e+134) (+ 1.0 (* 0.5 (* im im))) (* (+ 0.5 (* -0.25 (* re re))) 262144.0)))
double code(double re, double im) {
double tmp;
if (re <= 9e+134) {
tmp = 1.0 + (0.5 * (im * im));
} else {
tmp = (0.5 + (-0.25 * (re * re))) * 262144.0;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= 9d+134) then
tmp = 1.0d0 + (0.5d0 * (im * im))
else
tmp = (0.5d0 + ((-0.25d0) * (re * re))) * 262144.0d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 9e+134) {
tmp = 1.0 + (0.5 * (im * im));
} else {
tmp = (0.5 + (-0.25 * (re * re))) * 262144.0;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 9e+134: tmp = 1.0 + (0.5 * (im * im)) else: tmp = (0.5 + (-0.25 * (re * re))) * 262144.0 return tmp
function code(re, im) tmp = 0.0 if (re <= 9e+134) tmp = Float64(1.0 + Float64(0.5 * Float64(im * im))); else tmp = Float64(Float64(0.5 + Float64(-0.25 * Float64(re * re))) * 262144.0); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 9e+134) tmp = 1.0 + (0.5 * (im * im)); else tmp = (0.5 + (-0.25 * (re * re))) * 262144.0; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 9e+134], N[(1.0 + N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 + N[(-0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 262144.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 9 \cdot 10^{+134}:\\
\;\;\;\;1 + 0.5 \cdot \left(im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right) \cdot 262144\\
\end{array}
\end{array}
if re < 8.9999999999999995e134Initial program 100.0%
Taylor expanded in im around 0 79.6%
unpow279.6%
Simplified79.6%
Taylor expanded in re around 0 52.7%
distribute-lft-in52.7%
metadata-eval52.7%
unpow252.7%
Simplified52.7%
if 8.9999999999999995e134 < re Initial program 100.0%
Taylor expanded in re around 0 1.0%
associate-*r*1.0%
distribute-rgt-out29.6%
unpow229.6%
Simplified29.6%
Applied egg-rr24.5%
Final simplification48.9%
(FPCore (re im) :precision binary64 (if (<= im 1.42) 1.0 (* 0.5 (* im im))))
double code(double re, double im) {
double tmp;
if (im <= 1.42) {
tmp = 1.0;
} else {
tmp = 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 <= 1.42d0) then
tmp = 1.0d0
else
tmp = 0.5d0 * (im * im)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.42) {
tmp = 1.0;
} else {
tmp = 0.5 * (im * im);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.42: tmp = 1.0 else: tmp = 0.5 * (im * im) return tmp
function code(re, im) tmp = 0.0 if (im <= 1.42) tmp = 1.0; else tmp = Float64(0.5 * Float64(im * im)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.42) tmp = 1.0; else tmp = 0.5 * (im * im); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.42], 1.0, N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.42:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot im\right)\\
\end{array}
\end{array}
if im < 1.4199999999999999Initial program 100.0%
Applied egg-rr40.8%
+-inverses40.8%
+-rgt-identity40.8%
*-inverses40.8%
Simplified40.8%
if 1.4199999999999999 < im Initial program 100.0%
Taylor expanded in im around 0 56.5%
unpow256.5%
Simplified56.5%
Taylor expanded in im around inf 56.5%
*-commutative56.5%
associate-*l*56.5%
*-commutative56.5%
unpow256.5%
Simplified56.5%
Taylor expanded in re around 0 37.0%
unpow237.0%
Simplified37.0%
Final simplification39.9%
(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 80.5%
unpow280.5%
Simplified80.5%
Taylor expanded in re around 0 47.6%
distribute-lft-in47.6%
metadata-eval47.6%
unpow247.6%
Simplified47.6%
Final simplification47.6%
(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-rr31.4%
+-inverses31.4%
+-rgt-identity31.4%
*-inverses31.4%
Simplified31.4%
Final simplification31.4%
herbie shell --seed 2023278
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))