
(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.02) (not (<= im 1.35e+154))) (* (* 0.5 (cos re)) (+ (* im im) 2.0)) (* (+ (exp (- im)) (exp im)) (cbrt 0.125))))
double code(double re, double im) {
double tmp;
if ((im <= 0.02) || !(im <= 1.35e+154)) {
tmp = (0.5 * cos(re)) * ((im * im) + 2.0);
} else {
tmp = (exp(-im) + exp(im)) * cbrt(0.125);
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if ((im <= 0.02) || !(im <= 1.35e+154)) {
tmp = (0.5 * Math.cos(re)) * ((im * im) + 2.0);
} else {
tmp = (Math.exp(-im) + Math.exp(im)) * Math.cbrt(0.125);
}
return tmp;
}
function code(re, im) tmp = 0.0 if ((im <= 0.02) || !(im <= 1.35e+154)) tmp = Float64(Float64(0.5 * cos(re)) * Float64(Float64(im * im) + 2.0)); else tmp = Float64(Float64(exp(Float64(-im)) + exp(im)) * cbrt(0.125)); end return tmp end
code[re_, im_] := If[Or[LessEqual[im, 0.02], N[Not[LessEqual[im, 1.35e+154]], $MachinePrecision]], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[(im * im), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision] * N[Power[0.125, 1/3], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.02 \lor \neg \left(im \leq 1.35 \cdot 10^{+154}\right):\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(im \cdot im + 2\right)\\
\mathbf{else}:\\
\;\;\;\;\left(e^{-im} + e^{im}\right) \cdot \sqrt[3]{0.125}\\
\end{array}
\end{array}
if im < 0.0200000000000000004 or 1.35000000000000003e154 < im Initial program 100.0%
Taylor expanded in im around 0 88.2%
unpow288.2%
Simplified88.2%
if 0.0200000000000000004 < im < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in re around 0 0.0%
associate-*r*0.0%
distribute-rgt-out78.1%
unpow278.1%
Simplified78.1%
add-cbrt-cube78.1%
pow378.1%
+-commutative78.1%
fma-def78.1%
Applied egg-rr78.1%
Taylor expanded in re around 0 72.6%
Final simplification86.3%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (cos re))))
(if (<= im 0.105)
(fma (* im im) t_0 (cos re))
(if (<= im 1.35e+154)
(* (+ (exp (- im)) (exp im)) (cbrt 0.125))
(* t_0 (+ (* im im) 2.0))))))
double code(double re, double im) {
double t_0 = 0.5 * cos(re);
double tmp;
if (im <= 0.105) {
tmp = fma((im * im), t_0, cos(re));
} else if (im <= 1.35e+154) {
tmp = (exp(-im) + exp(im)) * cbrt(0.125);
} else {
tmp = t_0 * ((im * im) + 2.0);
}
return tmp;
}
function code(re, im) t_0 = Float64(0.5 * cos(re)) tmp = 0.0 if (im <= 0.105) tmp = fma(Float64(im * im), t_0, cos(re)); elseif (im <= 1.35e+154) tmp = Float64(Float64(exp(Float64(-im)) + exp(im)) * cbrt(0.125)); else tmp = Float64(t_0 * Float64(Float64(im * im) + 2.0)); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, 0.105], N[(N[(im * im), $MachinePrecision] * t$95$0 + N[Cos[re], $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision] * N[Power[0.125, 1/3], $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(N[(im * im), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \cos re\\
\mathbf{if}\;im \leq 0.105:\\
\;\;\;\;\mathsf{fma}\left(im \cdot im, t_0, \cos re\right)\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\left(e^{-im} + e^{im}\right) \cdot \sqrt[3]{0.125}\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot \left(im \cdot im + 2\right)\\
\end{array}
\end{array}
if im < 0.104999999999999996Initial program 100.0%
Taylor expanded in im around 0 86.4%
associate-*r*86.4%
*-commutative86.4%
fma-def86.4%
unpow286.4%
Simplified86.4%
if 0.104999999999999996 < im < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in re around 0 0.0%
associate-*r*0.0%
distribute-rgt-out78.1%
unpow278.1%
Simplified78.1%
add-cbrt-cube78.1%
pow378.1%
+-commutative78.1%
fma-def78.1%
Applied egg-rr78.1%
Taylor expanded in re around 0 72.6%
if 1.35000000000000003e154 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
unpow2100.0%
Simplified100.0%
Final simplification86.3%
(FPCore (re im) :precision binary64 (if (or (<= im 0.017) (not (<= im 1.35e+154))) (* (* 0.5 (cos re)) (+ (* im im) 2.0)) (* 0.5 (+ (exp (- im)) (exp im)))))
double code(double re, double im) {
double tmp;
if ((im <= 0.017) || !(im <= 1.35e+154)) {
tmp = (0.5 * cos(re)) * ((im * im) + 2.0);
} 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.017d0) .or. (.not. (im <= 1.35d+154))) then
tmp = (0.5d0 * cos(re)) * ((im * im) + 2.0d0)
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.017) || !(im <= 1.35e+154)) {
tmp = (0.5 * Math.cos(re)) * ((im * im) + 2.0);
} else {
tmp = 0.5 * (Math.exp(-im) + Math.exp(im));
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= 0.017) or not (im <= 1.35e+154): tmp = (0.5 * math.cos(re)) * ((im * im) + 2.0) else: tmp = 0.5 * (math.exp(-im) + math.exp(im)) return tmp
function code(re, im) tmp = 0.0 if ((im <= 0.017) || !(im <= 1.35e+154)) tmp = Float64(Float64(0.5 * cos(re)) * Float64(Float64(im * im) + 2.0)); 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.017) || ~((im <= 1.35e+154))) tmp = (0.5 * cos(re)) * ((im * im) + 2.0); else tmp = 0.5 * (exp(-im) + exp(im)); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, 0.017], N[Not[LessEqual[im, 1.35e+154]], $MachinePrecision]], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[(im * im), $MachinePrecision] + 2.0), $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.017 \lor \neg \left(im \leq 1.35 \cdot 10^{+154}\right):\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(im \cdot im + 2\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\
\end{array}
\end{array}
if im < 0.017000000000000001 or 1.35000000000000003e154 < im Initial program 100.0%
Taylor expanded in im around 0 88.2%
unpow288.2%
Simplified88.2%
if 0.017000000000000001 < im < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in re around 0 72.6%
*-commutative72.6%
Simplified72.6%
Final simplification86.3%
(FPCore (re im)
:precision binary64
(let* ((t_0 (+ (* im im) 2.0))
(t_1 (+ t_0 (* 0.08333333333333333 (pow im 4.0))))
(t_2 (* (* 0.5 (cos re)) t_0)))
(if (<= im 7700000000000.0)
t_2
(if (<= im 1.3e+97)
(* t_1 (+ 0.5 (* -0.25 (* re re))))
(if (<= im 1.35e+154) (* 0.5 t_1) t_2)))))
double code(double re, double im) {
double t_0 = (im * im) + 2.0;
double t_1 = t_0 + (0.08333333333333333 * pow(im, 4.0));
double t_2 = (0.5 * cos(re)) * t_0;
double tmp;
if (im <= 7700000000000.0) {
tmp = t_2;
} else if (im <= 1.3e+97) {
tmp = t_1 * (0.5 + (-0.25 * (re * re)));
} else if (im <= 1.35e+154) {
tmp = 0.5 * t_1;
} else {
tmp = t_2;
}
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) :: t_2
real(8) :: tmp
t_0 = (im * im) + 2.0d0
t_1 = t_0 + (0.08333333333333333d0 * (im ** 4.0d0))
t_2 = (0.5d0 * cos(re)) * t_0
if (im <= 7700000000000.0d0) then
tmp = t_2
else if (im <= 1.3d+97) then
tmp = t_1 * (0.5d0 + ((-0.25d0) * (re * re)))
else if (im <= 1.35d+154) then
tmp = 0.5d0 * t_1
else
tmp = t_2
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = (im * im) + 2.0;
double t_1 = t_0 + (0.08333333333333333 * Math.pow(im, 4.0));
double t_2 = (0.5 * Math.cos(re)) * t_0;
double tmp;
if (im <= 7700000000000.0) {
tmp = t_2;
} else if (im <= 1.3e+97) {
tmp = t_1 * (0.5 + (-0.25 * (re * re)));
} else if (im <= 1.35e+154) {
tmp = 0.5 * t_1;
} else {
tmp = t_2;
}
return tmp;
}
def code(re, im): t_0 = (im * im) + 2.0 t_1 = t_0 + (0.08333333333333333 * math.pow(im, 4.0)) t_2 = (0.5 * math.cos(re)) * t_0 tmp = 0 if im <= 7700000000000.0: tmp = t_2 elif im <= 1.3e+97: tmp = t_1 * (0.5 + (-0.25 * (re * re))) elif im <= 1.35e+154: tmp = 0.5 * t_1 else: tmp = t_2 return tmp
function code(re, im) t_0 = Float64(Float64(im * im) + 2.0) t_1 = Float64(t_0 + Float64(0.08333333333333333 * (im ^ 4.0))) t_2 = Float64(Float64(0.5 * cos(re)) * t_0) tmp = 0.0 if (im <= 7700000000000.0) tmp = t_2; elseif (im <= 1.3e+97) tmp = Float64(t_1 * Float64(0.5 + Float64(-0.25 * Float64(re * re)))); elseif (im <= 1.35e+154) tmp = Float64(0.5 * t_1); else tmp = t_2; end return tmp end
function tmp_2 = code(re, im) t_0 = (im * im) + 2.0; t_1 = t_0 + (0.08333333333333333 * (im ^ 4.0)); t_2 = (0.5 * cos(re)) * t_0; tmp = 0.0; if (im <= 7700000000000.0) tmp = t_2; elseif (im <= 1.3e+97) tmp = t_1 * (0.5 + (-0.25 * (re * re))); elseif (im <= 1.35e+154) tmp = 0.5 * t_1; else tmp = t_2; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(N[(im * im), $MachinePrecision] + 2.0), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 + N[(0.08333333333333333 * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]}, If[LessEqual[im, 7700000000000.0], t$95$2, If[LessEqual[im, 1.3e+97], N[(t$95$1 * N[(0.5 + N[(-0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(0.5 * t$95$1), $MachinePrecision], t$95$2]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := im \cdot im + 2\\
t_1 := t_0 + 0.08333333333333333 \cdot {im}^{4}\\
t_2 := \left(0.5 \cdot \cos re\right) \cdot t_0\\
\mathbf{if}\;im \leq 7700000000000:\\
\;\;\;\;t_2\\
\mathbf{elif}\;im \leq 1.3 \cdot 10^{+97}:\\
\;\;\;\;t_1 \cdot \left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right)\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot t_1\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}
\end{array}
if im < 7.7e12 or 1.35000000000000003e154 < im Initial program 100.0%
Taylor expanded in im around 0 87.5%
unpow287.5%
Simplified87.5%
if 7.7e12 < im < 1.3e97Initial program 100.0%
Taylor expanded in re around 0 0.0%
associate-*r*0.0%
distribute-rgt-out88.9%
unpow288.9%
Simplified88.9%
Taylor expanded in im around 0 52.5%
Simplified52.5%
if 1.3e97 < im < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in re around 0 75.0%
*-commutative75.0%
Simplified75.0%
Taylor expanded in im around 0 75.0%
Simplified75.0%
Final simplification84.5%
(FPCore (re im)
:precision binary64
(let* ((t_0 (+ (* im im) 2.0)))
(if (or (<= im 1.85e+25) (not (<= im 1.35e+154)))
(* (* 0.5 (cos re)) t_0)
(* 0.5 (+ t_0 (* 0.08333333333333333 (pow im 4.0)))))))
double code(double re, double im) {
double t_0 = (im * im) + 2.0;
double tmp;
if ((im <= 1.85e+25) || !(im <= 1.35e+154)) {
tmp = (0.5 * cos(re)) * t_0;
} else {
tmp = 0.5 * (t_0 + (0.08333333333333333 * pow(im, 4.0)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: tmp
t_0 = (im * im) + 2.0d0
if ((im <= 1.85d+25) .or. (.not. (im <= 1.35d+154))) then
tmp = (0.5d0 * cos(re)) * t_0
else
tmp = 0.5d0 * (t_0 + (0.08333333333333333d0 * (im ** 4.0d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = (im * im) + 2.0;
double tmp;
if ((im <= 1.85e+25) || !(im <= 1.35e+154)) {
tmp = (0.5 * Math.cos(re)) * t_0;
} else {
tmp = 0.5 * (t_0 + (0.08333333333333333 * Math.pow(im, 4.0)));
}
return tmp;
}
def code(re, im): t_0 = (im * im) + 2.0 tmp = 0 if (im <= 1.85e+25) or not (im <= 1.35e+154): tmp = (0.5 * math.cos(re)) * t_0 else: tmp = 0.5 * (t_0 + (0.08333333333333333 * math.pow(im, 4.0))) return tmp
function code(re, im) t_0 = Float64(Float64(im * im) + 2.0) tmp = 0.0 if ((im <= 1.85e+25) || !(im <= 1.35e+154)) tmp = Float64(Float64(0.5 * cos(re)) * t_0); else tmp = Float64(0.5 * Float64(t_0 + Float64(0.08333333333333333 * (im ^ 4.0)))); end return tmp end
function tmp_2 = code(re, im) t_0 = (im * im) + 2.0; tmp = 0.0; if ((im <= 1.85e+25) || ~((im <= 1.35e+154))) tmp = (0.5 * cos(re)) * t_0; else tmp = 0.5 * (t_0 + (0.08333333333333333 * (im ^ 4.0))); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(N[(im * im), $MachinePrecision] + 2.0), $MachinePrecision]}, If[Or[LessEqual[im, 1.85e+25], N[Not[LessEqual[im, 1.35e+154]], $MachinePrecision]], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision], N[(0.5 * N[(t$95$0 + N[(0.08333333333333333 * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := im \cdot im + 2\\
\mathbf{if}\;im \leq 1.85 \cdot 10^{+25} \lor \neg \left(im \leq 1.35 \cdot 10^{+154}\right):\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot t_0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(t_0 + 0.08333333333333333 \cdot {im}^{4}\right)\\
\end{array}
\end{array}
if im < 1.8499999999999999e25 or 1.35000000000000003e154 < im Initial program 100.0%
Taylor expanded in im around 0 86.4%
unpow286.4%
Simplified86.4%
if 1.8499999999999999e25 < im < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in re around 0 74.1%
*-commutative74.1%
Simplified74.1%
Taylor expanded in im around 0 53.5%
Simplified53.5%
Final simplification82.9%
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ (* im im) 2.0)))
double code(double re, double im) {
return (0.5 * cos(re)) * ((im * im) + 2.0);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * ((im * im) + 2.0d0)
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * ((im * im) + 2.0);
}
def code(re, im): return (0.5 * math.cos(re)) * ((im * im) + 2.0)
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(Float64(im * im) + 2.0)) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * ((im * im) + 2.0); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[(im * im), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(im \cdot im + 2\right)
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 77.9%
unpow277.9%
Simplified77.9%
Final simplification77.9%
(FPCore (re im)
:precision binary64
(let* ((t_0 (+ (* im im) 2.0)))
(if (<= im 10500000000000.0)
(cos re)
(if (or (<= im 5e+270) (not (<= im 4e+289)))
(* t_0 (+ 0.5 (* -0.25 (* re re))))
(* 0.5 t_0)))))
double code(double re, double im) {
double t_0 = (im * im) + 2.0;
double tmp;
if (im <= 10500000000000.0) {
tmp = cos(re);
} else if ((im <= 5e+270) || !(im <= 4e+289)) {
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 = (im * im) + 2.0d0
if (im <= 10500000000000.0d0) then
tmp = cos(re)
else if ((im <= 5d+270) .or. (.not. (im <= 4d+289))) 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 = (im * im) + 2.0;
double tmp;
if (im <= 10500000000000.0) {
tmp = Math.cos(re);
} else if ((im <= 5e+270) || !(im <= 4e+289)) {
tmp = t_0 * (0.5 + (-0.25 * (re * re)));
} else {
tmp = 0.5 * t_0;
}
return tmp;
}
def code(re, im): t_0 = (im * im) + 2.0 tmp = 0 if im <= 10500000000000.0: tmp = math.cos(re) elif (im <= 5e+270) or not (im <= 4e+289): tmp = t_0 * (0.5 + (-0.25 * (re * re))) else: tmp = 0.5 * t_0 return tmp
function code(re, im) t_0 = Float64(Float64(im * im) + 2.0) tmp = 0.0 if (im <= 10500000000000.0) tmp = cos(re); elseif ((im <= 5e+270) || !(im <= 4e+289)) 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 = (im * im) + 2.0; tmp = 0.0; if (im <= 10500000000000.0) tmp = cos(re); elseif ((im <= 5e+270) || ~((im <= 4e+289))) 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[(im * im), $MachinePrecision] + 2.0), $MachinePrecision]}, If[LessEqual[im, 10500000000000.0], N[Cos[re], $MachinePrecision], If[Or[LessEqual[im, 5e+270], N[Not[LessEqual[im, 4e+289]], $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 := im \cdot im + 2\\
\mathbf{if}\;im \leq 10500000000000:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 5 \cdot 10^{+270} \lor \neg \left(im \leq 4 \cdot 10^{+289}\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 < 1.05e13Initial program 100.0%
Taylor expanded in im around 0 67.4%
if 1.05e13 < im < 4.99999999999999976e270 or 4.0000000000000002e289 < im Initial program 100.0%
Taylor expanded in re around 0 0.0%
associate-*r*0.0%
distribute-rgt-out77.2%
unpow277.2%
Simplified77.2%
Taylor expanded in im around 0 47.5%
Simplified47.5%
if 4.99999999999999976e270 < im < 4.0000000000000002e289Initial program 100.0%
Taylor expanded in re around 0 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Simplified100.0%
Final simplification63.4%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* re (* re -0.25))) (t_1 (+ (* im im) 2.0)))
(if (<= re 1080000000000.0)
(* 0.5 t_1)
(if (<= re 5.5e+165) (* t_1 t_0) (* -2.0 t_0)))))
double code(double re, double im) {
double t_0 = re * (re * -0.25);
double t_1 = (im * im) + 2.0;
double tmp;
if (re <= 1080000000000.0) {
tmp = 0.5 * t_1;
} else if (re <= 5.5e+165) {
tmp = t_1 * t_0;
} else {
tmp = -2.0 * 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) :: t_1
real(8) :: tmp
t_0 = re * (re * (-0.25d0))
t_1 = (im * im) + 2.0d0
if (re <= 1080000000000.0d0) then
tmp = 0.5d0 * t_1
else if (re <= 5.5d+165) then
tmp = t_1 * t_0
else
tmp = (-2.0d0) * t_0
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = re * (re * -0.25);
double t_1 = (im * im) + 2.0;
double tmp;
if (re <= 1080000000000.0) {
tmp = 0.5 * t_1;
} else if (re <= 5.5e+165) {
tmp = t_1 * t_0;
} else {
tmp = -2.0 * t_0;
}
return tmp;
}
def code(re, im): t_0 = re * (re * -0.25) t_1 = (im * im) + 2.0 tmp = 0 if re <= 1080000000000.0: tmp = 0.5 * t_1 elif re <= 5.5e+165: tmp = t_1 * t_0 else: tmp = -2.0 * t_0 return tmp
function code(re, im) t_0 = Float64(re * Float64(re * -0.25)) t_1 = Float64(Float64(im * im) + 2.0) tmp = 0.0 if (re <= 1080000000000.0) tmp = Float64(0.5 * t_1); elseif (re <= 5.5e+165) tmp = Float64(t_1 * t_0); else tmp = Float64(-2.0 * t_0); end return tmp end
function tmp_2 = code(re, im) t_0 = re * (re * -0.25); t_1 = (im * im) + 2.0; tmp = 0.0; if (re <= 1080000000000.0) tmp = 0.5 * t_1; elseif (re <= 5.5e+165) tmp = t_1 * t_0; else tmp = -2.0 * t_0; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(re * N[(re * -0.25), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(im * im), $MachinePrecision] + 2.0), $MachinePrecision]}, If[LessEqual[re, 1080000000000.0], N[(0.5 * t$95$1), $MachinePrecision], If[LessEqual[re, 5.5e+165], N[(t$95$1 * t$95$0), $MachinePrecision], N[(-2.0 * t$95$0), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := re \cdot \left(re \cdot -0.25\right)\\
t_1 := im \cdot im + 2\\
\mathbf{if}\;re \leq 1080000000000:\\
\;\;\;\;0.5 \cdot t_1\\
\mathbf{elif}\;re \leq 5.5 \cdot 10^{+165}:\\
\;\;\;\;t_1 \cdot t_0\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot t_0\\
\end{array}
\end{array}
if re < 1.08e12Initial program 100.0%
Taylor expanded in re around 0 76.9%
*-commutative76.9%
Simplified76.9%
Taylor expanded in im around 0 56.2%
Simplified56.2%
if 1.08e12 < re < 5.4999999999999998e165Initial program 100.0%
Taylor expanded in re around 0 1.1%
associate-*r*1.1%
distribute-rgt-out41.1%
unpow241.1%
Simplified41.1%
Taylor expanded in im around 0 38.5%
Simplified38.5%
Taylor expanded in re around inf 38.5%
unpow22.1%
associate-*r*2.1%
*-commutative2.1%
Simplified38.5%
if 5.4999999999999998e165 < re Initial program 100.0%
Taylor expanded in re around 0 0.6%
associate-*r*0.6%
distribute-rgt-out20.6%
unpow220.6%
Simplified20.6%
Applied egg-rr26.5%
Taylor expanded in re around inf 26.5%
unpow226.5%
associate-*r*26.5%
*-commutative26.5%
Simplified26.5%
Final simplification51.4%
(FPCore (re im) :precision binary64 (if (<= re 5.5e+165) (* (+ (* im im) 2.0) (+ 0.5 (* -0.25 (* re re)))) (* -2.0 (* re (* re -0.25)))))
double code(double re, double im) {
double tmp;
if (re <= 5.5e+165) {
tmp = ((im * im) + 2.0) * (0.5 + (-0.25 * (re * re)));
} else {
tmp = -2.0 * (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.5d+165) then
tmp = ((im * im) + 2.0d0) * (0.5d0 + ((-0.25d0) * (re * re)))
else
tmp = (-2.0d0) * (re * (re * (-0.25d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 5.5e+165) {
tmp = ((im * im) + 2.0) * (0.5 + (-0.25 * (re * re)));
} else {
tmp = -2.0 * (re * (re * -0.25));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 5.5e+165: tmp = ((im * im) + 2.0) * (0.5 + (-0.25 * (re * re))) else: tmp = -2.0 * (re * (re * -0.25)) return tmp
function code(re, im) tmp = 0.0 if (re <= 5.5e+165) tmp = Float64(Float64(Float64(im * im) + 2.0) * Float64(0.5 + Float64(-0.25 * Float64(re * re)))); else tmp = Float64(-2.0 * Float64(re * Float64(re * -0.25))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 5.5e+165) tmp = ((im * im) + 2.0) * (0.5 + (-0.25 * (re * re))); else tmp = -2.0 * (re * (re * -0.25)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 5.5e+165], N[(N[(N[(im * im), $MachinePrecision] + 2.0), $MachinePrecision] * N[(0.5 + N[(-0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(re * N[(re * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 5.5 \cdot 10^{+165}:\\
\;\;\;\;\left(im \cdot im + 2\right) \cdot \left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right)\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(re \cdot \left(re \cdot -0.25\right)\right)\\
\end{array}
\end{array}
if re < 5.4999999999999998e165Initial program 100.0%
Taylor expanded in re around 0 28.3%
associate-*r*28.3%
distribute-rgt-out66.0%
unpow266.0%
Simplified66.0%
Taylor expanded in im around 0 51.3%
Simplified51.3%
if 5.4999999999999998e165 < re Initial program 100.0%
Taylor expanded in re around 0 0.6%
associate-*r*0.6%
distribute-rgt-out20.6%
unpow220.6%
Simplified20.6%
Applied egg-rr26.5%
Taylor expanded in re around inf 26.5%
unpow226.5%
associate-*r*26.5%
*-commutative26.5%
Simplified26.5%
Final simplification49.3%
(FPCore (re im) :precision binary64 (if (<= im 3600000000.0) 1.0 (* -2.0 (* re (* re -0.25)))))
double code(double re, double im) {
double tmp;
if (im <= 3600000000.0) {
tmp = 1.0;
} else {
tmp = -2.0 * (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 <= 3600000000.0d0) then
tmp = 1.0d0
else
tmp = (-2.0d0) * (re * (re * (-0.25d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 3600000000.0) {
tmp = 1.0;
} else {
tmp = -2.0 * (re * (re * -0.25));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 3600000000.0: tmp = 1.0 else: tmp = -2.0 * (re * (re * -0.25)) return tmp
function code(re, im) tmp = 0.0 if (im <= 3600000000.0) tmp = 1.0; else tmp = Float64(-2.0 * Float64(re * Float64(re * -0.25))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 3600000000.0) tmp = 1.0; else tmp = -2.0 * (re * (re * -0.25)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 3600000000.0], 1.0, N[(-2.0 * N[(re * N[(re * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 3600000000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \left(re \cdot \left(re \cdot -0.25\right)\right)\\
\end{array}
\end{array}
if im < 3.6e9Initial program 100.0%
Applied egg-rr37.3%
+-inverses37.3%
+-rgt-identity37.3%
*-inverses37.3%
Simplified37.3%
if 3.6e9 < im Initial program 100.0%
Taylor expanded in re around 0 0.0%
associate-*r*0.0%
distribute-rgt-out76.7%
unpow276.7%
Simplified76.7%
Applied egg-rr15.9%
Taylor expanded in re around inf 16.6%
unpow216.6%
associate-*r*16.6%
*-commutative16.6%
Simplified16.6%
Final simplification32.4%
(FPCore (re im) :precision binary64 (* 0.5 (+ (* im im) 2.0)))
double code(double re, double im) {
return 0.5 * ((im * im) + 2.0);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * ((im * im) + 2.0d0)
end function
public static double code(double re, double im) {
return 0.5 * ((im * im) + 2.0);
}
def code(re, im): return 0.5 * ((im * im) + 2.0)
function code(re, im) return Float64(0.5 * Float64(Float64(im * im) + 2.0)) end
function tmp = code(re, im) tmp = 0.5 * ((im * im) + 2.0); end
code[re_, im_] := N[(0.5 * N[(N[(im * im), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(im \cdot im + 2\right)
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 65.4%
*-commutative65.4%
Simplified65.4%
Taylor expanded in im around 0 47.7%
Simplified47.7%
Final simplification47.7%
(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-rr29.1%
+-inverses29.1%
+-rgt-identity29.1%
*-inverses29.1%
Simplified29.1%
Final simplification29.1%
herbie shell --seed 2023224
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))