
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp(-im) + exp(im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * (exp(-im) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp(-im) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp(-im) + exp(im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * (exp(-im) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp(-im) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
\end{array}
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp(-im) + exp(im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * (exp(-im) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp(-im) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (re im) :precision binary64 (if (or (<= im 0.0134) (not (<= im 1.5e+154))) (fma 0.5 (* (cos re) (* im im)) (cos re)) (* (+ (exp (- im)) (exp im)) (+ 0.5 (* -0.25 (* re re))))))
double code(double re, double im) {
double tmp;
if ((im <= 0.0134) || !(im <= 1.5e+154)) {
tmp = fma(0.5, (cos(re) * (im * im)), cos(re));
} else {
tmp = (exp(-im) + exp(im)) * (0.5 + (-0.25 * (re * re)));
}
return tmp;
}
function code(re, im) tmp = 0.0 if ((im <= 0.0134) || !(im <= 1.5e+154)) tmp = fma(0.5, Float64(cos(re) * Float64(im * im)), cos(re)); else tmp = Float64(Float64(exp(Float64(-im)) + exp(im)) * Float64(0.5 + Float64(-0.25 * Float64(re * re)))); end return tmp end
code[re_, im_] := If[Or[LessEqual[im, 0.0134], N[Not[LessEqual[im, 1.5e+154]], $MachinePrecision]], N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * im), $MachinePrecision]), $MachinePrecision] + N[Cos[re], $MachinePrecision]), $MachinePrecision], N[(N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[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 0.0134 \lor \neg \left(im \leq 1.5 \cdot 10^{+154}\right):\\
\;\;\;\;\mathsf{fma}\left(0.5, \cos re \cdot \left(im \cdot im\right), \cos re\right)\\
\mathbf{else}:\\
\;\;\;\;\left(e^{-im} + e^{im}\right) \cdot \left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right)\\
\end{array}
\end{array}
if im < 0.0134000000000000005 or 1.50000000000000013e154 < im Initial program 100.0%
Taylor expanded in im around 0 83.5%
Simplified83.5%
if 0.0134000000000000005 < im < 1.50000000000000013e154Initial program 100.0%
Taylor expanded in re around 0 3.2%
Simplified72.0%
Final simplification82.1%
(FPCore (re im)
:precision binary64
(let* ((t_0 (+ (exp (- im)) (exp im))))
(if (<= im 0.0065)
(+ (cos re) (* 0.5 (* im im)))
(if (or (<= im 6.6e+122) (not (<= im 2e+198)))
(* t_0 (+ 0.5 (* -0.25 (* re re))))
(* 0.5 t_0)))))
double code(double re, double im) {
double t_0 = exp(-im) + exp(im);
double tmp;
if (im <= 0.0065) {
tmp = cos(re) + (0.5 * (im * im));
} else if ((im <= 6.6e+122) || !(im <= 2e+198)) {
tmp = t_0 * (0.5 + (-0.25 * (re * re)));
} else {
tmp = 0.5 * t_0;
}
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 <= 0.0065d0) then
tmp = cos(re) + (0.5d0 * (im * im))
else if ((im <= 6.6d+122) .or. (.not. (im <= 2d+198))) then
tmp = t_0 * (0.5d0 + ((-0.25d0) * (re * re)))
else
tmp = 0.5d0 * t_0
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 <= 0.0065) {
tmp = Math.cos(re) + (0.5 * (im * im));
} else if ((im <= 6.6e+122) || !(im <= 2e+198)) {
tmp = t_0 * (0.5 + (-0.25 * (re * re)));
} else {
tmp = 0.5 * t_0;
}
return tmp;
}
def code(re, im): t_0 = math.exp(-im) + math.exp(im) tmp = 0 if im <= 0.0065: tmp = math.cos(re) + (0.5 * (im * im)) elif (im <= 6.6e+122) or not (im <= 2e+198): tmp = t_0 * (0.5 + (-0.25 * (re * re))) else: tmp = 0.5 * t_0 return tmp
function code(re, im) t_0 = Float64(exp(Float64(-im)) + exp(im)) tmp = 0.0 if (im <= 0.0065) tmp = Float64(cos(re) + Float64(0.5 * Float64(im * im))); elseif ((im <= 6.6e+122) || !(im <= 2e+198)) tmp = Float64(t_0 * Float64(0.5 + Float64(-0.25 * Float64(re * re)))); else tmp = Float64(0.5 * t_0); end return tmp end
function tmp_2 = code(re, im) t_0 = exp(-im) + exp(im); tmp = 0.0; if (im <= 0.0065) tmp = cos(re) + (0.5 * (im * im)); elseif ((im <= 6.6e+122) || ~((im <= 2e+198))) tmp = t_0 * (0.5 + (-0.25 * (re * re))); else tmp = 0.5 * t_0; 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, 0.0065], N[(N[Cos[re], $MachinePrecision] + N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[im, 6.6e+122], N[Not[LessEqual[im, 2e+198]], $MachinePrecision]], N[(t$95$0 * N[(0.5 + N[(-0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * t$95$0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-im} + e^{im}\\
\mathbf{if}\;im \leq 0.0065:\\
\;\;\;\;\cos re + 0.5 \cdot \left(im \cdot im\right)\\
\mathbf{elif}\;im \leq 6.6 \cdot 10^{+122} \lor \neg \left(im \leq 2 \cdot 10^{+198}\right):\\
\;\;\;\;t_0 \cdot \left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot t_0\\
\end{array}
\end{array}
if im < 0.0064999999999999997Initial program 100.0%
Taylor expanded in im around 0 80.8%
Simplified80.8%
Taylor expanded in re around 0 78.3%
unpow278.3%
Simplified78.3%
fma-udef78.3%
Applied egg-rr78.3%
if 0.0064999999999999997 < im < 6.5999999999999998e122 or 2.00000000000000004e198 < im Initial program 100.0%
Taylor expanded in re around 0 2.2%
Simplified85.5%
if 6.5999999999999998e122 < im < 2.00000000000000004e198Initial program 100.0%
Taylor expanded in re around 0 75.0%
Final simplification79.4%
(FPCore (re im) :precision binary64 (if (<= im 0.00185) (+ (cos re) (* 0.5 (* im im))) (* 0.5 (+ (exp (- im)) (exp im)))))
double code(double re, double im) {
double tmp;
if (im <= 0.00185) {
tmp = cos(re) + (0.5 * (im * im));
} 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 <= 0.00185d0) then
tmp = cos(re) + (0.5d0 * (im * im))
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 <= 0.00185) {
tmp = Math.cos(re) + (0.5 * (im * im));
} else {
tmp = 0.5 * (Math.exp(-im) + Math.exp(im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 0.00185: tmp = math.cos(re) + (0.5 * (im * im)) else: tmp = 0.5 * (math.exp(-im) + math.exp(im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 0.00185) tmp = Float64(cos(re) + Float64(0.5 * Float64(im * im))); 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 <= 0.00185) tmp = cos(re) + (0.5 * (im * im)); else tmp = 0.5 * (exp(-im) + exp(im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 0.00185], N[(N[Cos[re], $MachinePrecision] + N[(0.5 * N[(im * im), $MachinePrecision]), $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 0.00185:\\
\;\;\;\;\cos re + 0.5 \cdot \left(im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\
\end{array}
\end{array}
if im < 0.0018500000000000001Initial program 100.0%
Taylor expanded in im around 0 80.8%
Simplified80.8%
Taylor expanded in re around 0 78.3%
unpow278.3%
Simplified78.3%
fma-udef78.3%
Applied egg-rr78.3%
if 0.0018500000000000001 < im Initial program 100.0%
Taylor expanded in re around 0 68.8%
Final simplification75.9%
(FPCore (re im) :precision binary64 (let* ((t_0 (* 0.5 (* im im)))) (if (<= im 380.0) (+ (cos re) t_0) (log1p (expm1 t_0)))))
double code(double re, double im) {
double t_0 = 0.5 * (im * im);
double tmp;
if (im <= 380.0) {
tmp = cos(re) + t_0;
} else {
tmp = log1p(expm1(t_0));
}
return tmp;
}
public static double code(double re, double im) {
double t_0 = 0.5 * (im * im);
double tmp;
if (im <= 380.0) {
tmp = Math.cos(re) + t_0;
} else {
tmp = Math.log1p(Math.expm1(t_0));
}
return tmp;
}
def code(re, im): t_0 = 0.5 * (im * im) tmp = 0 if im <= 380.0: tmp = math.cos(re) + t_0 else: tmp = math.log1p(math.expm1(t_0)) return tmp
function code(re, im) t_0 = Float64(0.5 * Float64(im * im)) tmp = 0.0 if (im <= 380.0) tmp = Float64(cos(re) + t_0); else tmp = log1p(expm1(t_0)); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, 380.0], N[(N[Cos[re], $MachinePrecision] + t$95$0), $MachinePrecision], N[Log[1 + N[(Exp[t$95$0] - 1), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(im \cdot im\right)\\
\mathbf{if}\;im \leq 380:\\
\;\;\;\;\cos re + t_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(t_0\right)\right)\\
\end{array}
\end{array}
if im < 380Initial program 100.0%
Taylor expanded in im around 0 80.3%
Simplified80.3%
Taylor expanded in re around 0 77.7%
unpow277.7%
Simplified77.7%
fma-udef77.7%
Applied egg-rr77.7%
if 380 < im Initial program 100.0%
Taylor expanded in im around 0 54.3%
Simplified54.3%
Taylor expanded in re around 0 37.3%
unpow237.3%
Simplified37.3%
Taylor expanded in im around inf 37.3%
unpow237.3%
Simplified37.3%
log1p-expm1-u69.4%
Applied egg-rr69.4%
Final simplification75.7%
(FPCore (re im) :precision binary64 (if (<= im 1e+51) (+ (cos re) (* 0.5 (* im im))) (cbrt (* 0.125 (pow im 6.0)))))
double code(double re, double im) {
double tmp;
if (im <= 1e+51) {
tmp = cos(re) + (0.5 * (im * im));
} else {
tmp = cbrt((0.125 * pow(im, 6.0)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (im <= 1e+51) {
tmp = Math.cos(re) + (0.5 * (im * im));
} else {
tmp = Math.cbrt((0.125 * Math.pow(im, 6.0)));
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 1e+51) tmp = Float64(cos(re) + Float64(0.5 * Float64(im * im))); else tmp = cbrt(Float64(0.125 * (im ^ 6.0))); end return tmp end
code[re_, im_] := If[LessEqual[im, 1e+51], N[(N[Cos[re], $MachinePrecision] + N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[N[(0.125 * N[Power[im, 6.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 10^{+51}:\\
\;\;\;\;\cos re + 0.5 \cdot \left(im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{0.125 \cdot {im}^{6}}\\
\end{array}
\end{array}
if im < 1e51Initial program 100.0%
Taylor expanded in im around 0 75.4%
Simplified75.4%
Taylor expanded in re around 0 73.1%
unpow273.1%
Simplified73.1%
fma-udef73.1%
Applied egg-rr73.1%
if 1e51 < im Initial program 100.0%
Taylor expanded in im around 0 67.8%
Simplified67.8%
Taylor expanded in re around 0 46.4%
unpow246.4%
Simplified46.4%
Taylor expanded in im around inf 46.4%
unpow246.4%
Simplified46.4%
add-cbrt-cube65.3%
pow1/365.3%
pow365.3%
unpow-prod-down65.3%
metadata-eval65.3%
pow-prod-down65.3%
pow-prod-up65.3%
metadata-eval65.3%
Applied egg-rr65.3%
unpow1/365.3%
Simplified65.3%
Final simplification71.6%
(FPCore (re im) :precision binary64 (+ (cos re) (* 0.5 (* im im))))
double code(double re, double im) {
return cos(re) + (0.5 * (im * im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = cos(re) + (0.5d0 * (im * im))
end function
public static double code(double re, double im) {
return Math.cos(re) + (0.5 * (im * im));
}
def code(re, im): return math.cos(re) + (0.5 * (im * im))
function code(re, im) return Float64(cos(re) + Float64(0.5 * Float64(im * im))) end
function tmp = code(re, im) tmp = cos(re) + (0.5 * (im * im)); end
code[re_, im_] := N[(N[Cos[re], $MachinePrecision] + N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos re + 0.5 \cdot \left(im \cdot im\right)
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 74.0%
Simplified74.0%
Taylor expanded in re around 0 68.0%
unpow268.0%
Simplified68.0%
fma-udef68.0%
Applied egg-rr68.0%
Final simplification68.0%
(FPCore (re im) :precision binary64 (if (<= im 680.0) (cos re) (if (<= im 2.6e+131) (+ 1.0 (* re (* re -0.5))) (+ (* 0.5 (* im im)) 1.0))))
double code(double re, double im) {
double tmp;
if (im <= 680.0) {
tmp = cos(re);
} else if (im <= 2.6e+131) {
tmp = 1.0 + (re * (re * -0.5));
} else {
tmp = (0.5 * (im * im)) + 1.0;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 680.0d0) then
tmp = cos(re)
else if (im <= 2.6d+131) then
tmp = 1.0d0 + (re * (re * (-0.5d0)))
else
tmp = (0.5d0 * (im * im)) + 1.0d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 680.0) {
tmp = Math.cos(re);
} else if (im <= 2.6e+131) {
tmp = 1.0 + (re * (re * -0.5));
} else {
tmp = (0.5 * (im * im)) + 1.0;
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 680.0: tmp = math.cos(re) elif im <= 2.6e+131: tmp = 1.0 + (re * (re * -0.5)) else: tmp = (0.5 * (im * im)) + 1.0 return tmp
function code(re, im) tmp = 0.0 if (im <= 680.0) tmp = cos(re); elseif (im <= 2.6e+131) tmp = Float64(1.0 + Float64(re * Float64(re * -0.5))); else tmp = Float64(Float64(0.5 * Float64(im * im)) + 1.0); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 680.0) tmp = cos(re); elseif (im <= 2.6e+131) tmp = 1.0 + (re * (re * -0.5)); else tmp = (0.5 * (im * im)) + 1.0; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 680.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 2.6e+131], N[(1.0 + N[(re * N[(re * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 680:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 2.6 \cdot 10^{+131}:\\
\;\;\;\;1 + re \cdot \left(re \cdot -0.5\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot im\right) + 1\\
\end{array}
\end{array}
if im < 680Initial program 100.0%
Taylor expanded in im around 0 63.4%
if 680 < im < 2.6e131Initial program 100.0%
Taylor expanded in im around 0 4.6%
Simplified4.6%
Taylor expanded in re around 0 3.0%
unpow23.0%
Simplified3.0%
Taylor expanded in re around 0 18.8%
fma-def18.8%
unpow218.8%
unpow218.8%
Simplified18.8%
Taylor expanded in im around 0 18.3%
unpow218.3%
associate-*r*18.3%
*-commutative18.3%
Simplified18.3%
if 2.6e131 < im Initial program 100.0%
Taylor expanded in im around 0 87.9%
Simplified87.9%
Taylor expanded in re around 0 60.6%
unpow260.6%
Simplified60.6%
Taylor expanded in re around 0 60.6%
unpow260.6%
Simplified60.6%
Final simplification58.6%
(FPCore (re im) :precision binary64 (if (or (<= im 1.22e+14) (not (<= im 1.95e+152))) (+ (* 0.5 (* im im)) 1.0) (+ 0.25 (* (* re re) 0.25))))
double code(double re, double im) {
double tmp;
if ((im <= 1.22e+14) || !(im <= 1.95e+152)) {
tmp = (0.5 * (im * im)) + 1.0;
} 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 ((im <= 1.22d+14) .or. (.not. (im <= 1.95d+152))) then
tmp = (0.5d0 * (im * im)) + 1.0d0
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 ((im <= 1.22e+14) || !(im <= 1.95e+152)) {
tmp = (0.5 * (im * im)) + 1.0;
} else {
tmp = 0.25 + ((re * re) * 0.25);
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= 1.22e+14) or not (im <= 1.95e+152): tmp = (0.5 * (im * im)) + 1.0 else: tmp = 0.25 + ((re * re) * 0.25) return tmp
function code(re, im) tmp = 0.0 if ((im <= 1.22e+14) || !(im <= 1.95e+152)) tmp = Float64(Float64(0.5 * Float64(im * im)) + 1.0); 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 ((im <= 1.22e+14) || ~((im <= 1.95e+152))) tmp = (0.5 * (im * im)) + 1.0; else tmp = 0.25 + ((re * re) * 0.25); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, 1.22e+14], N[Not[LessEqual[im, 1.95e+152]], $MachinePrecision]], N[(N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], N[(0.25 + N[(N[(re * re), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.22 \cdot 10^{+14} \lor \neg \left(im \leq 1.95 \cdot 10^{+152}\right):\\
\;\;\;\;0.5 \cdot \left(im \cdot im\right) + 1\\
\mathbf{else}:\\
\;\;\;\;0.25 + \left(re \cdot re\right) \cdot 0.25\\
\end{array}
\end{array}
if im < 1.22e14 or 1.95000000000000006e152 < im Initial program 100.0%
Taylor expanded in im around 0 82.4%
Simplified82.4%
Taylor expanded in re around 0 75.9%
unpow275.9%
Simplified75.9%
Taylor expanded in re around 0 51.3%
unpow251.3%
Simplified51.3%
if 1.22e14 < im < 1.95000000000000006e152Initial program 100.0%
Applied egg-rr2.3%
Taylor expanded in re around 0 16.3%
*-commutative16.3%
unpow216.3%
Simplified16.3%
Final simplification47.4%
(FPCore (re im) :precision binary64 (if (or (<= im 86.0) (not (<= im 4.2e+130))) (+ (* 0.5 (* im im)) 1.0) (+ 1.0 (* re (* re -0.5)))))
double code(double re, double im) {
double tmp;
if ((im <= 86.0) || !(im <= 4.2e+130)) {
tmp = (0.5 * (im * im)) + 1.0;
} else {
tmp = 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 <= 86.0d0) .or. (.not. (im <= 4.2d+130))) then
tmp = (0.5d0 * (im * im)) + 1.0d0
else
tmp = 1.0d0 + (re * (re * (-0.5d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((im <= 86.0) || !(im <= 4.2e+130)) {
tmp = (0.5 * (im * im)) + 1.0;
} else {
tmp = 1.0 + (re * (re * -0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= 86.0) or not (im <= 4.2e+130): tmp = (0.5 * (im * im)) + 1.0 else: tmp = 1.0 + (re * (re * -0.5)) return tmp
function code(re, im) tmp = 0.0 if ((im <= 86.0) || !(im <= 4.2e+130)) tmp = Float64(Float64(0.5 * Float64(im * im)) + 1.0); else tmp = Float64(1.0 + Float64(re * Float64(re * -0.5))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((im <= 86.0) || ~((im <= 4.2e+130))) tmp = (0.5 * (im * im)) + 1.0; else tmp = 1.0 + (re * (re * -0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, 86.0], N[Not[LessEqual[im, 4.2e+130]], $MachinePrecision]], N[(N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], N[(1.0 + N[(re * N[(re * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 86 \lor \neg \left(im \leq 4.2 \cdot 10^{+130}\right):\\
\;\;\;\;0.5 \cdot \left(im \cdot im\right) + 1\\
\mathbf{else}:\\
\;\;\;\;1 + re \cdot \left(re \cdot -0.5\right)\\
\end{array}
\end{array}
if im < 86 or 4.19999999999999981e130 < im Initial program 100.0%
Taylor expanded in im around 0 81.8%
Simplified81.8%
Taylor expanded in re around 0 75.3%
unpow275.3%
Simplified75.3%
Taylor expanded in re around 0 50.9%
unpow250.9%
Simplified50.9%
if 86 < im < 4.19999999999999981e130Initial program 100.0%
Taylor expanded in im around 0 4.6%
Simplified4.6%
Taylor expanded in re around 0 2.9%
unpow22.9%
Simplified2.9%
Taylor expanded in re around 0 18.2%
fma-def18.2%
unpow218.2%
unpow218.2%
Simplified18.2%
Taylor expanded in im around 0 17.7%
unpow217.7%
associate-*r*17.7%
*-commutative17.7%
Simplified17.7%
Final simplification47.6%
(FPCore (re im) :precision binary64 (if (<= im 1.22e+14) 0.25 (if (<= im 1.5e+152) (+ 0.25 (* (* re re) 0.25)) (* 0.5 (* im im)))))
double code(double re, double im) {
double tmp;
if (im <= 1.22e+14) {
tmp = 0.25;
} else if (im <= 1.5e+152) {
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 <= 1.22d+14) then
tmp = 0.25d0
else if (im <= 1.5d+152) 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 <= 1.22e+14) {
tmp = 0.25;
} else if (im <= 1.5e+152) {
tmp = 0.25 + ((re * re) * 0.25);
} else {
tmp = 0.5 * (im * im);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.22e+14: tmp = 0.25 elif im <= 1.5e+152: tmp = 0.25 + ((re * re) * 0.25) else: tmp = 0.5 * (im * im) return tmp
function code(re, im) tmp = 0.0 if (im <= 1.22e+14) tmp = 0.25; elseif (im <= 1.5e+152) 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 <= 1.22e+14) tmp = 0.25; elseif (im <= 1.5e+152) tmp = 0.25 + ((re * re) * 0.25); else tmp = 0.5 * (im * im); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.22e+14], 0.25, If[LessEqual[im, 1.5e+152], 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 1.22 \cdot 10^{+14}:\\
\;\;\;\;0.25\\
\mathbf{elif}\;im \leq 1.5 \cdot 10^{+152}:\\
\;\;\;\;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 < 1.22e14Initial program 100.0%
Applied egg-rr9.5%
Taylor expanded in re around 0 9.7%
if 1.22e14 < im < 1.49999999999999995e152Initial program 100.0%
Applied egg-rr2.3%
Taylor expanded in re around 0 16.3%
*-commutative16.3%
unpow216.3%
Simplified16.3%
if 1.49999999999999995e152 < im Initial program 100.0%
Taylor expanded in im around 0 97.4%
Simplified97.4%
Taylor expanded in re around 0 67.1%
unpow267.1%
Simplified67.1%
Taylor expanded in im around inf 67.1%
unpow267.1%
Simplified67.1%
Final simplification17.8%
(FPCore (re im) :precision binary64 (if (<= im 155.0) 0.25 (* 0.5 (* im im))))
double code(double re, double im) {
double tmp;
if (im <= 155.0) {
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 <= 155.0d0) 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 <= 155.0) {
tmp = 0.25;
} else {
tmp = 0.5 * (im * im);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 155.0: tmp = 0.25 else: tmp = 0.5 * (im * im) return tmp
function code(re, im) tmp = 0.0 if (im <= 155.0) 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 <= 155.0) tmp = 0.25; else tmp = 0.5 * (im * im); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 155.0], 0.25, N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 155:\\
\;\;\;\;0.25\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot im\right)\\
\end{array}
\end{array}
if im < 155Initial program 100.0%
Applied egg-rr9.6%
Taylor expanded in re around 0 9.7%
if 155 < im Initial program 100.0%
Taylor expanded in im around 0 54.3%
Simplified54.3%
Taylor expanded in re around 0 37.3%
unpow237.3%
Simplified37.3%
Taylor expanded in im around inf 37.3%
unpow237.3%
Simplified37.3%
Final simplification16.4%
(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.8%
Taylor expanded in re around 0 7.9%
Final simplification7.9%
herbie shell --seed 2023240
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))