
(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 12 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 (or (<= im 4.2e-7) (not (<= im 1.35e+154))) (fma 0.5 (* (cos re) (* im im)) (cos re)) (* 0.5 (+ (exp (- im)) (exp im)))))
double code(double re, double im) {
double tmp;
if ((im <= 4.2e-7) || !(im <= 1.35e+154)) {
tmp = fma(0.5, (cos(re) * (im * im)), cos(re));
} else {
tmp = 0.5 * (exp(-im) + exp(im));
}
return tmp;
}
function code(re, im) tmp = 0.0 if ((im <= 4.2e-7) || !(im <= 1.35e+154)) tmp = fma(0.5, Float64(cos(re) * Float64(im * im)), cos(re)); else tmp = Float64(0.5 * Float64(exp(Float64(-im)) + exp(im))); end return tmp end
code[re_, im_] := If[Or[LessEqual[im, 4.2e-7], N[Not[LessEqual[im, 1.35e+154]], $MachinePrecision]], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * im), $MachinePrecision]), $MachinePrecision] + N[Cos[re], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 4.2 \cdot 10^{-7} \lor \neg \left(im \leq 1.35 \cdot 10^{+154}\right):\\
\;\;\;\;\mathsf{fma}\left(0.5, \cos re \cdot \left(im \cdot im\right), \cos re\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\
\end{array}
\end{array}
if im < 4.2e-7 or 1.35000000000000003e154 < im Initial program 100.0%
Taylor expanded in im around 0 81.0%
Simplified81.0%
if 4.2e-7 < im < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in re around 0 90.6%
Final simplification82.2%
(FPCore (re im)
:precision binary64
(let* ((t_0 (+ (exp (- im)) (exp im))))
(if (<= im 4.2e-7)
(cos re)
(if (<= im 9e+127) (* 0.5 t_0) (* t_0 (+ 0.5 (* -0.25 (* re re))))))))
double code(double re, double im) {
double t_0 = exp(-im) + exp(im);
double tmp;
if (im <= 4.2e-7) {
tmp = cos(re);
} else if (im <= 9e+127) {
tmp = 0.5 * t_0;
} else {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = exp(-im) + exp(im)
if (im <= 4.2d-7) then
tmp = cos(re)
else if (im <= 9d+127) then
tmp = 0.5d0 * t_0
else
tmp = t_0 * (0.5d0 + ((-0.25d0) * (re * re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = Math.exp(-im) + Math.exp(im);
double tmp;
if (im <= 4.2e-7) {
tmp = Math.cos(re);
} else if (im <= 9e+127) {
tmp = 0.5 * t_0;
} else {
tmp = t_0 * (0.5 + (-0.25 * (re * re)));
}
return tmp;
}
def code(re, im): t_0 = math.exp(-im) + math.exp(im) tmp = 0 if im <= 4.2e-7: tmp = math.cos(re) elif im <= 9e+127: tmp = 0.5 * t_0 else: tmp = t_0 * (0.5 + (-0.25 * (re * re))) return tmp
function code(re, im) t_0 = Float64(exp(Float64(-im)) + exp(im)) tmp = 0.0 if (im <= 4.2e-7) tmp = cos(re); elseif (im <= 9e+127) tmp = Float64(0.5 * t_0); else tmp = Float64(t_0 * Float64(0.5 + Float64(-0.25 * Float64(re * re)))); end return tmp end
function tmp_2 = code(re, im) t_0 = exp(-im) + exp(im); tmp = 0.0; if (im <= 4.2e-7) tmp = cos(re); elseif (im <= 9e+127) tmp = 0.5 * t_0; else tmp = t_0 * (0.5 + (-0.25 * (re * re))); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, 4.2e-7], N[Cos[re], $MachinePrecision], If[LessEqual[im, 9e+127], N[(0.5 * t$95$0), $MachinePrecision], N[(t$95$0 * N[(0.5 + N[(-0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-im} + e^{im}\\
\mathbf{if}\;im \leq 4.2 \cdot 10^{-7}:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 9 \cdot 10^{+127}:\\
\;\;\;\;0.5 \cdot t_0\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot \left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right)\\
\end{array}
\end{array}
if im < 4.2e-7Initial program 100.0%
Taylor expanded in im around 0 62.9%
if 4.2e-7 < im < 9.00000000000000068e127Initial program 100.0%
Taylor expanded in re around 0 92.9%
if 9.00000000000000068e127 < im Initial program 100.0%
Taylor expanded in re around 0 0.0%
Simplified85.0%
Final simplification69.6%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* re (* re -0.5))))
(if (or (<= im 1.95e+23) (not (<= im 1.35e+154)))
(fma 0.5 (* im im) (cos re))
(+
1.0
(/ (- (* t_0 t_0) (* (pow im 4.0) 0.25)) (- t_0 (* 0.5 (* im im))))))))
double code(double re, double im) {
double t_0 = re * (re * -0.5);
double tmp;
if ((im <= 1.95e+23) || !(im <= 1.35e+154)) {
tmp = fma(0.5, (im * im), cos(re));
} else {
tmp = 1.0 + (((t_0 * t_0) - (pow(im, 4.0) * 0.25)) / (t_0 - (0.5 * (im * im))));
}
return tmp;
}
function code(re, im) t_0 = Float64(re * Float64(re * -0.5)) tmp = 0.0 if ((im <= 1.95e+23) || !(im <= 1.35e+154)) tmp = fma(0.5, Float64(im * im), cos(re)); else tmp = Float64(1.0 + Float64(Float64(Float64(t_0 * t_0) - Float64((im ^ 4.0) * 0.25)) / Float64(t_0 - Float64(0.5 * Float64(im * im))))); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(re * N[(re * -0.5), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[im, 1.95e+23], N[Not[LessEqual[im, 1.35e+154]], $MachinePrecision]], N[(0.5 * N[(im * im), $MachinePrecision] + N[Cos[re], $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(N[Power[im, 4.0], $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision] / N[(t$95$0 - N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := re \cdot \left(re \cdot -0.5\right)\\
\mathbf{if}\;im \leq 1.95 \cdot 10^{+23} \lor \neg \left(im \leq 1.35 \cdot 10^{+154}\right):\\
\;\;\;\;\mathsf{fma}\left(0.5, im \cdot im, \cos re\right)\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{t_0 \cdot t_0 - {im}^{4} \cdot 0.25}{t_0 - 0.5 \cdot \left(im \cdot im\right)}\\
\end{array}
\end{array}
if im < 1.95e23 or 1.35000000000000003e154 < im Initial program 100.0%
Taylor expanded in im around 0 79.7%
Simplified79.7%
Taylor expanded in re around 0 71.2%
unpow271.2%
Simplified71.2%
if 1.95e23 < im < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in im around 0 5.3%
Simplified5.3%
Taylor expanded in re around 0 4.7%
unpow24.7%
Simplified4.7%
Taylor expanded in re around 0 10.6%
+-commutative10.6%
*-commutative10.6%
unpow210.6%
fma-def10.6%
unpow210.6%
Simplified10.6%
fma-udef10.6%
flip-+23.6%
associate-*l*23.6%
associate-*l*23.6%
*-commutative23.6%
*-commutative23.6%
swap-sqr23.6%
pow223.6%
pow223.6%
pow-prod-up23.6%
metadata-eval23.6%
metadata-eval23.6%
associate-*l*23.6%
Applied egg-rr23.6%
Final simplification66.2%
(FPCore (re im) :precision binary64 (if (<= im 4.2e-7) (cos re) (* 0.5 (+ (exp (- im)) (exp im)))))
double code(double re, double im) {
double tmp;
if (im <= 4.2e-7) {
tmp = cos(re);
} else {
tmp = 0.5 * (exp(-im) + exp(im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 4.2d-7) then
tmp = cos(re)
else
tmp = 0.5d0 * (exp(-im) + exp(im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 4.2e-7) {
tmp = Math.cos(re);
} else {
tmp = 0.5 * (Math.exp(-im) + Math.exp(im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 4.2e-7: tmp = math.cos(re) else: tmp = 0.5 * (math.exp(-im) + math.exp(im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 4.2e-7) tmp = cos(re); else tmp = Float64(0.5 * Float64(exp(Float64(-im)) + exp(im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 4.2e-7) tmp = cos(re); else tmp = 0.5 * (exp(-im) + exp(im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 4.2e-7], N[Cos[re], $MachinePrecision], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 4.2 \cdot 10^{-7}:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\
\end{array}
\end{array}
if im < 4.2e-7Initial program 100.0%
Taylor expanded in im around 0 62.9%
if 4.2e-7 < im Initial program 100.0%
Taylor expanded in re around 0 72.1%
Final simplification65.3%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* re (* re -0.5))) (t_1 (* 0.5 (* im im))))
(if (<= im 2.6e+25)
(cos re)
(if (<= im 1.35e+154)
(+ 1.0 (/ (- (* t_0 t_0) (* (pow im 4.0) 0.25)) (- t_0 t_1)))
(+ 1.0 t_1)))))
double code(double re, double im) {
double t_0 = re * (re * -0.5);
double t_1 = 0.5 * (im * im);
double tmp;
if (im <= 2.6e+25) {
tmp = cos(re);
} else if (im <= 1.35e+154) {
tmp = 1.0 + (((t_0 * t_0) - (pow(im, 4.0) * 0.25)) / (t_0 - t_1));
} else {
tmp = 1.0 + t_1;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = re * (re * (-0.5d0))
t_1 = 0.5d0 * (im * im)
if (im <= 2.6d+25) then
tmp = cos(re)
else if (im <= 1.35d+154) then
tmp = 1.0d0 + (((t_0 * t_0) - ((im ** 4.0d0) * 0.25d0)) / (t_0 - t_1))
else
tmp = 1.0d0 + t_1
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = re * (re * -0.5);
double t_1 = 0.5 * (im * im);
double tmp;
if (im <= 2.6e+25) {
tmp = Math.cos(re);
} else if (im <= 1.35e+154) {
tmp = 1.0 + (((t_0 * t_0) - (Math.pow(im, 4.0) * 0.25)) / (t_0 - t_1));
} else {
tmp = 1.0 + t_1;
}
return tmp;
}
def code(re, im): t_0 = re * (re * -0.5) t_1 = 0.5 * (im * im) tmp = 0 if im <= 2.6e+25: tmp = math.cos(re) elif im <= 1.35e+154: tmp = 1.0 + (((t_0 * t_0) - (math.pow(im, 4.0) * 0.25)) / (t_0 - t_1)) else: tmp = 1.0 + t_1 return tmp
function code(re, im) t_0 = Float64(re * Float64(re * -0.5)) t_1 = Float64(0.5 * Float64(im * im)) tmp = 0.0 if (im <= 2.6e+25) tmp = cos(re); elseif (im <= 1.35e+154) tmp = Float64(1.0 + Float64(Float64(Float64(t_0 * t_0) - Float64((im ^ 4.0) * 0.25)) / Float64(t_0 - t_1))); else tmp = Float64(1.0 + t_1); end return tmp end
function tmp_2 = code(re, im) t_0 = re * (re * -0.5); t_1 = 0.5 * (im * im); tmp = 0.0; if (im <= 2.6e+25) tmp = cos(re); elseif (im <= 1.35e+154) tmp = 1.0 + (((t_0 * t_0) - ((im ^ 4.0) * 0.25)) / (t_0 - t_1)); else tmp = 1.0 + t_1; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(re * N[(re * -0.5), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, 2.6e+25], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(1.0 + N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(N[Power[im, 4.0], $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision] / N[(t$95$0 - t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + t$95$1), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := re \cdot \left(re \cdot -0.5\right)\\
t_1 := 0.5 \cdot \left(im \cdot im\right)\\
\mathbf{if}\;im \leq 2.6 \cdot 10^{+25}:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;1 + \frac{t_0 \cdot t_0 - {im}^{4} \cdot 0.25}{t_0 - t_1}\\
\mathbf{else}:\\
\;\;\;\;1 + t_1\\
\end{array}
\end{array}
if im < 2.5999999999999998e25Initial program 100.0%
Taylor expanded in im around 0 61.5%
if 2.5999999999999998e25 < im < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in im around 0 5.4%
Simplified5.4%
Taylor expanded in re around 0 4.8%
unpow24.8%
Simplified4.8%
Taylor expanded in re around 0 10.8%
+-commutative10.8%
*-commutative10.8%
unpow210.8%
fma-def10.8%
unpow210.8%
Simplified10.8%
fma-udef10.8%
flip-+24.3%
associate-*l*24.3%
associate-*l*24.3%
*-commutative24.3%
*-commutative24.3%
swap-sqr24.3%
pow224.3%
pow224.3%
pow-prod-up24.3%
metadata-eval24.3%
metadata-eval24.3%
associate-*l*24.3%
Applied egg-rr24.3%
if 1.35000000000000003e154 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
Simplified100.0%
Taylor expanded in re around 0 55.6%
unpow255.6%
Simplified55.6%
Taylor expanded in re around 0 47.2%
+-commutative47.2%
*-commutative47.2%
unpow247.2%
fma-def47.2%
unpow247.2%
Simplified47.2%
Taylor expanded in re around 0 55.6%
unpow255.6%
Simplified55.6%
Final simplification56.9%
(FPCore (re im)
:precision binary64
(if (<= im 720.0)
(cos re)
(if (<= im 3.5e+151)
(+ 0.25 (* (* re re) 0.25))
(+ 1.0 (* 0.5 (* im im))))))
double code(double re, double im) {
double tmp;
if (im <= 720.0) {
tmp = cos(re);
} else if (im <= 3.5e+151) {
tmp = 0.25 + ((re * re) * 0.25);
} 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 <= 720.0d0) then
tmp = cos(re)
else if (im <= 3.5d+151) then
tmp = 0.25d0 + ((re * re) * 0.25d0)
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 <= 720.0) {
tmp = Math.cos(re);
} else if (im <= 3.5e+151) {
tmp = 0.25 + ((re * re) * 0.25);
} else {
tmp = 1.0 + (0.5 * (im * im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 720.0: tmp = math.cos(re) elif im <= 3.5e+151: tmp = 0.25 + ((re * re) * 0.25) else: tmp = 1.0 + (0.5 * (im * im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 720.0) tmp = cos(re); elseif (im <= 3.5e+151) tmp = Float64(0.25 + Float64(Float64(re * re) * 0.25)); 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 <= 720.0) tmp = cos(re); elseif (im <= 3.5e+151) tmp = 0.25 + ((re * re) * 0.25); else tmp = 1.0 + (0.5 * (im * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 720.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 3.5e+151], N[(0.25 + N[(N[(re * re), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 720:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 3.5 \cdot 10^{+151}:\\
\;\;\;\;0.25 + \left(re \cdot re\right) \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;1 + 0.5 \cdot \left(im \cdot im\right)\\
\end{array}
\end{array}
if im < 720Initial program 100.0%
Taylor expanded in im around 0 63.0%
if 720 < im < 3.5000000000000003e151Initial program 100.0%
Applied egg-rr2.9%
Taylor expanded in re around 0 22.4%
*-commutative22.4%
unpow222.4%
Simplified22.4%
if 3.5000000000000003e151 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
Simplified100.0%
Taylor expanded in re around 0 55.6%
unpow255.6%
Simplified55.6%
Taylor expanded in re around 0 47.2%
+-commutative47.2%
*-commutative47.2%
unpow247.2%
fma-def47.2%
unpow247.2%
Simplified47.2%
Taylor expanded in re around 0 55.6%
unpow255.6%
Simplified55.6%
Final simplification57.0%
(FPCore (re im)
:precision binary64
(if (<= re 5.8e+165)
(+ 1.0 (* 0.5 (* im im)))
(if (or (<= re 6.5e+238) (not (<= re 1.8e+290)))
(+ 1.0 (* (* re re) -0.5))
(+ 0.25 (* (* re re) 0.25)))))
double code(double re, double im) {
double tmp;
if (re <= 5.8e+165) {
tmp = 1.0 + (0.5 * (im * im));
} else if ((re <= 6.5e+238) || !(re <= 1.8e+290)) {
tmp = 1.0 + ((re * re) * -0.5);
} else {
tmp = 0.25 + ((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 (re <= 5.8d+165) then
tmp = 1.0d0 + (0.5d0 * (im * im))
else if ((re <= 6.5d+238) .or. (.not. (re <= 1.8d+290))) then
tmp = 1.0d0 + ((re * re) * (-0.5d0))
else
tmp = 0.25d0 + ((re * re) * 0.25d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 5.8e+165) {
tmp = 1.0 + (0.5 * (im * im));
} else if ((re <= 6.5e+238) || !(re <= 1.8e+290)) {
tmp = 1.0 + ((re * re) * -0.5);
} else {
tmp = 0.25 + ((re * re) * 0.25);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 5.8e+165: tmp = 1.0 + (0.5 * (im * im)) elif (re <= 6.5e+238) or not (re <= 1.8e+290): tmp = 1.0 + ((re * re) * -0.5) else: tmp = 0.25 + ((re * re) * 0.25) return tmp
function code(re, im) tmp = 0.0 if (re <= 5.8e+165) tmp = Float64(1.0 + Float64(0.5 * Float64(im * im))); elseif ((re <= 6.5e+238) || !(re <= 1.8e+290)) tmp = Float64(1.0 + Float64(Float64(re * re) * -0.5)); else tmp = Float64(0.25 + Float64(Float64(re * re) * 0.25)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 5.8e+165) tmp = 1.0 + (0.5 * (im * im)); elseif ((re <= 6.5e+238) || ~((re <= 1.8e+290))) tmp = 1.0 + ((re * re) * -0.5); else tmp = 0.25 + ((re * re) * 0.25); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 5.8e+165], N[(1.0 + N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[re, 6.5e+238], N[Not[LessEqual[re, 1.8e+290]], $MachinePrecision]], N[(1.0 + N[(N[(re * re), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision], N[(0.25 + N[(N[(re * re), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 5.8 \cdot 10^{+165}:\\
\;\;\;\;1 + 0.5 \cdot \left(im \cdot im\right)\\
\mathbf{elif}\;re \leq 6.5 \cdot 10^{+238} \lor \neg \left(re \leq 1.8 \cdot 10^{+290}\right):\\
\;\;\;\;1 + \left(re \cdot re\right) \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;0.25 + \left(re \cdot re\right) \cdot 0.25\\
\end{array}
\end{array}
if re < 5.80000000000000011e165Initial program 100.0%
Taylor expanded in im around 0 71.2%
Simplified71.2%
Taylor expanded in re around 0 65.5%
unpow265.5%
Simplified65.5%
Taylor expanded in re around 0 49.0%
+-commutative49.0%
*-commutative49.0%
unpow249.0%
fma-def49.0%
unpow249.0%
Simplified49.0%
Taylor expanded in re around 0 49.1%
unpow249.1%
Simplified49.1%
if 5.80000000000000011e165 < re < 6.5000000000000005e238 or 1.79999999999999994e290 < re Initial program 99.9%
Taylor expanded in im around 0 92.9%
Simplified92.9%
Taylor expanded in re around 0 61.0%
unpow261.0%
Simplified61.0%
Taylor expanded in re around 0 9.2%
+-commutative9.2%
*-commutative9.2%
unpow29.2%
fma-def9.2%
unpow29.2%
Simplified9.2%
Taylor expanded in re around inf 40.0%
unpow240.0%
Simplified40.0%
if 6.5000000000000005e238 < re < 1.79999999999999994e290Initial program 100.0%
Applied egg-rr4.4%
Taylor expanded in re around 0 56.0%
*-commutative56.0%
unpow256.0%
Simplified56.0%
Final simplification48.9%
(FPCore (re im) :precision binary64 (if (<= im 24.5) (+ 1.0 (* (* re re) -0.5)) (if (<= im 2.8e+151) (+ 0.25 (* (* re re) 0.25)) (* 0.5 (* im im)))))
double code(double re, double im) {
double tmp;
if (im <= 24.5) {
tmp = 1.0 + ((re * re) * -0.5);
} else if (im <= 2.8e+151) {
tmp = 0.25 + ((re * re) * 0.25);
} 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 <= 24.5d0) then
tmp = 1.0d0 + ((re * re) * (-0.5d0))
else if (im <= 2.8d+151) then
tmp = 0.25d0 + ((re * re) * 0.25d0)
else
tmp = 0.5d0 * (im * im)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 24.5) {
tmp = 1.0 + ((re * re) * -0.5);
} else if (im <= 2.8e+151) {
tmp = 0.25 + ((re * re) * 0.25);
} else {
tmp = 0.5 * (im * im);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 24.5: tmp = 1.0 + ((re * re) * -0.5) elif im <= 2.8e+151: tmp = 0.25 + ((re * re) * 0.25) else: tmp = 0.5 * (im * im) return tmp
function code(re, im) tmp = 0.0 if (im <= 24.5) tmp = Float64(1.0 + Float64(Float64(re * re) * -0.5)); elseif (im <= 2.8e+151) tmp = Float64(0.25 + Float64(Float64(re * re) * 0.25)); else tmp = Float64(0.5 * Float64(im * im)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 24.5) tmp = 1.0 + ((re * re) * -0.5); elseif (im <= 2.8e+151) tmp = 0.25 + ((re * re) * 0.25); else tmp = 0.5 * (im * im); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 24.5], N[(1.0 + N[(N[(re * re), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 2.8e+151], N[(0.25 + N[(N[(re * re), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 24.5:\\
\;\;\;\;1 + \left(re \cdot re\right) \cdot -0.5\\
\mathbf{elif}\;im \leq 2.8 \cdot 10^{+151}:\\
\;\;\;\;0.25 + \left(re \cdot re\right) \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot im\right)\\
\end{array}
\end{array}
if im < 24.5Initial program 100.0%
Taylor expanded in im around 0 77.5%
Simplified77.5%
Taylor expanded in re around 0 75.6%
unpow275.6%
Simplified75.6%
Taylor expanded in re around 0 50.8%
+-commutative50.8%
*-commutative50.8%
unpow250.8%
fma-def50.8%
unpow250.8%
Simplified50.8%
Taylor expanded in re around inf 39.2%
unpow239.2%
Simplified39.2%
if 24.5 < im < 2.79999999999999987e151Initial program 100.0%
Applied egg-rr2.9%
Taylor expanded in re around 0 22.4%
*-commutative22.4%
unpow222.4%
Simplified22.4%
if 2.79999999999999987e151 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
Simplified100.0%
Taylor expanded in re around 0 55.6%
unpow255.6%
Simplified55.6%
Taylor expanded in im around inf 55.6%
unpow255.6%
Simplified55.6%
Final simplification39.5%
(FPCore (re im) :precision binary64 (if (<= im 7.5e+150) (+ 0.25 (* (* re re) 0.25)) (* 0.5 (* im im))))
double code(double re, double im) {
double tmp;
if (im <= 7.5e+150) {
tmp = 0.25 + ((re * re) * 0.25);
} 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 <= 7.5d+150) then
tmp = 0.25d0 + ((re * re) * 0.25d0)
else
tmp = 0.5d0 * (im * im)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 7.5e+150) {
tmp = 0.25 + ((re * re) * 0.25);
} else {
tmp = 0.5 * (im * im);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 7.5e+150: tmp = 0.25 + ((re * re) * 0.25) else: tmp = 0.5 * (im * im) return tmp
function code(re, im) tmp = 0.0 if (im <= 7.5e+150) tmp = Float64(0.25 + Float64(Float64(re * re) * 0.25)); else tmp = Float64(0.5 * Float64(im * im)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 7.5e+150) tmp = 0.25 + ((re * re) * 0.25); else tmp = 0.5 * (im * im); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 7.5e+150], N[(0.25 + N[(N[(re * re), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 7.5 \cdot 10^{+150}:\\
\;\;\;\;0.25 + \left(re \cdot re\right) \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot im\right)\\
\end{array}
\end{array}
if im < 7.4999999999999998e150Initial program 100.0%
Applied egg-rr8.6%
Taylor expanded in re around 0 12.5%
*-commutative12.5%
unpow212.5%
Simplified12.5%
if 7.4999999999999998e150 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
Simplified100.0%
Taylor expanded in re around 0 55.6%
unpow255.6%
Simplified55.6%
Taylor expanded in im around inf 55.6%
unpow255.6%
Simplified55.6%
Final simplification18.6%
(FPCore (re im) :precision binary64 (if (<= im 0.71) 0.25 (* 0.5 (* im im))))
double code(double re, double im) {
double tmp;
if (im <= 0.71) {
tmp = 0.25;
} 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 <= 0.71d0) then
tmp = 0.25d0
else
tmp = 0.5d0 * (im * im)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 0.71) {
tmp = 0.25;
} else {
tmp = 0.5 * (im * im);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 0.71: tmp = 0.25 else: tmp = 0.5 * (im * im) return tmp
function code(re, im) tmp = 0.0 if (im <= 0.71) tmp = 0.25; else tmp = Float64(0.5 * Float64(im * im)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 0.71) tmp = 0.25; else tmp = 0.5 * (im * im); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 0.71], 0.25, N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.71:\\
\;\;\;\;0.25\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot im\right)\\
\end{array}
\end{array}
if im < 0.70999999999999996Initial program 100.0%
Applied egg-rr9.6%
Taylor expanded in re around 0 9.6%
if 0.70999999999999996 < im Initial program 100.0%
Taylor expanded in im around 0 56.1%
Simplified56.1%
Taylor expanded in re around 0 32.0%
unpow232.0%
Simplified32.0%
Taylor expanded in im around inf 32.0%
unpow232.0%
Simplified32.0%
Final simplification15.5%
(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.7%
Taylor expanded in re around 0 7.7%
Final simplification7.7%
herbie shell --seed 2023257
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))