
(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 20 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.036) (not (<= im 1.32e+154))) (* (* 0.5 (cos re)) (+ 2.0 (* im im))) (* (+ (exp (- im)) (exp im)) (+ 0.5 (* -0.25 (* re re))))))
double code(double re, double im) {
double tmp;
if ((im <= 0.036) || !(im <= 1.32e+154)) {
tmp = (0.5 * cos(re)) * (2.0 + (im * im));
} else {
tmp = (exp(-im) + exp(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 <= 0.036d0) .or. (.not. (im <= 1.32d+154))) then
tmp = (0.5d0 * cos(re)) * (2.0d0 + (im * im))
else
tmp = (exp(-im) + exp(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 <= 0.036) || !(im <= 1.32e+154)) {
tmp = (0.5 * Math.cos(re)) * (2.0 + (im * im));
} else {
tmp = (Math.exp(-im) + Math.exp(im)) * (0.5 + (-0.25 * (re * re)));
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= 0.036) or not (im <= 1.32e+154): tmp = (0.5 * math.cos(re)) * (2.0 + (im * im)) else: tmp = (math.exp(-im) + math.exp(im)) * (0.5 + (-0.25 * (re * re))) return tmp
function code(re, im) tmp = 0.0 if ((im <= 0.036) || !(im <= 1.32e+154)) tmp = Float64(Float64(0.5 * cos(re)) * Float64(2.0 + Float64(im * im))); else tmp = Float64(Float64(exp(Float64(-im)) + exp(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 <= 0.036) || ~((im <= 1.32e+154))) tmp = (0.5 * cos(re)) * (2.0 + (im * im)); else tmp = (exp(-im) + exp(im)) * (0.5 + (-0.25 * (re * re))); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, 0.036], N[Not[LessEqual[im, 1.32e+154]], $MachinePrecision]], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $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.036 \lor \neg \left(im \leq 1.32 \cdot 10^{+154}\right):\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(2 + im \cdot im\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.0359999999999999973 or 1.31999999999999998e154 < im Initial program 100.0%
Taylor expanded in im around 0 84.6%
Simplified84.6%
if 0.0359999999999999973 < im < 1.31999999999999998e154Initial program 100.0%
Taylor expanded in re around 0 0.0%
Simplified77.8%
Final simplification83.7%
(FPCore (re im) :precision binary64 (if (or (<= im 0.032) (not (<= im 1.55e+152))) (* (* 0.5 (cos re)) (+ 2.0 (* im im))) (* 0.5 (+ (exp (- im)) (exp im)))))
double code(double re, double im) {
double tmp;
if ((im <= 0.032) || !(im <= 1.55e+152)) {
tmp = (0.5 * cos(re)) * (2.0 + (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.032d0) .or. (.not. (im <= 1.55d+152))) then
tmp = (0.5d0 * cos(re)) * (2.0d0 + (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.032) || !(im <= 1.55e+152)) {
tmp = (0.5 * Math.cos(re)) * (2.0 + (im * im));
} else {
tmp = 0.5 * (Math.exp(-im) + Math.exp(im));
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= 0.032) or not (im <= 1.55e+152): tmp = (0.5 * math.cos(re)) * (2.0 + (im * im)) else: tmp = 0.5 * (math.exp(-im) + math.exp(im)) return tmp
function code(re, im) tmp = 0.0 if ((im <= 0.032) || !(im <= 1.55e+152)) tmp = Float64(Float64(0.5 * cos(re)) * Float64(2.0 + 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.032) || ~((im <= 1.55e+152))) tmp = (0.5 * cos(re)) * (2.0 + (im * im)); else tmp = 0.5 * (exp(-im) + exp(im)); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, 0.032], N[Not[LessEqual[im, 1.55e+152]], $MachinePrecision]], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(2.0 + 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.032 \lor \neg \left(im \leq 1.55 \cdot 10^{+152}\right):\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(2 + im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\
\end{array}
\end{array}
if im < 0.032000000000000001 or 1.55e152 < im Initial program 100.0%
Taylor expanded in im around 0 84.3%
Simplified84.3%
if 0.032000000000000001 < im < 1.55e152Initial program 100.0%
Taylor expanded in re around 0 71.4%
Final simplification82.5%
(FPCore (re im)
:precision binary64
(let* ((t_0 (+ 2.0 (* im im))) (t_1 (* (* 0.5 (cos re)) t_0)))
(if (<= im 31000.0)
t_1
(if (<= im 1e+77)
(* t_0 (+ 0.5 (pow re -2.0)))
(if (<= im 1.55e+152)
(/ (+ 0.5 re) (/ (- 2.0 (* im im)) (- 4.0 (pow im 4.0))))
t_1)))))
double code(double re, double im) {
double t_0 = 2.0 + (im * im);
double t_1 = (0.5 * cos(re)) * t_0;
double tmp;
if (im <= 31000.0) {
tmp = t_1;
} else if (im <= 1e+77) {
tmp = t_0 * (0.5 + pow(re, -2.0));
} else if (im <= 1.55e+152) {
tmp = (0.5 + re) / ((2.0 - (im * im)) / (4.0 - pow(im, 4.0)));
} else {
tmp = 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 = 2.0d0 + (im * im)
t_1 = (0.5d0 * cos(re)) * t_0
if (im <= 31000.0d0) then
tmp = t_1
else if (im <= 1d+77) then
tmp = t_0 * (0.5d0 + (re ** (-2.0d0)))
else if (im <= 1.55d+152) then
tmp = (0.5d0 + re) / ((2.0d0 - (im * im)) / (4.0d0 - (im ** 4.0d0)))
else
tmp = t_1
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 2.0 + (im * im);
double t_1 = (0.5 * Math.cos(re)) * t_0;
double tmp;
if (im <= 31000.0) {
tmp = t_1;
} else if (im <= 1e+77) {
tmp = t_0 * (0.5 + Math.pow(re, -2.0));
} else if (im <= 1.55e+152) {
tmp = (0.5 + re) / ((2.0 - (im * im)) / (4.0 - Math.pow(im, 4.0)));
} else {
tmp = t_1;
}
return tmp;
}
def code(re, im): t_0 = 2.0 + (im * im) t_1 = (0.5 * math.cos(re)) * t_0 tmp = 0 if im <= 31000.0: tmp = t_1 elif im <= 1e+77: tmp = t_0 * (0.5 + math.pow(re, -2.0)) elif im <= 1.55e+152: tmp = (0.5 + re) / ((2.0 - (im * im)) / (4.0 - math.pow(im, 4.0))) else: tmp = t_1 return tmp
function code(re, im) t_0 = Float64(2.0 + Float64(im * im)) t_1 = Float64(Float64(0.5 * cos(re)) * t_0) tmp = 0.0 if (im <= 31000.0) tmp = t_1; elseif (im <= 1e+77) tmp = Float64(t_0 * Float64(0.5 + (re ^ -2.0))); elseif (im <= 1.55e+152) tmp = Float64(Float64(0.5 + re) / Float64(Float64(2.0 - Float64(im * im)) / Float64(4.0 - (im ^ 4.0)))); else tmp = t_1; end return tmp end
function tmp_2 = code(re, im) t_0 = 2.0 + (im * im); t_1 = (0.5 * cos(re)) * t_0; tmp = 0.0; if (im <= 31000.0) tmp = t_1; elseif (im <= 1e+77) tmp = t_0 * (0.5 + (re ^ -2.0)); elseif (im <= 1.55e+152) tmp = (0.5 + re) / ((2.0 - (im * im)) / (4.0 - (im ^ 4.0))); else tmp = t_1; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision]}, If[LessEqual[im, 31000.0], t$95$1, If[LessEqual[im, 1e+77], N[(t$95$0 * N[(0.5 + N[Power[re, -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.55e+152], N[(N[(0.5 + re), $MachinePrecision] / N[(N[(2.0 - N[(im * im), $MachinePrecision]), $MachinePrecision] / N[(4.0 - N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 2 + im \cdot im\\
t_1 := \left(0.5 \cdot \cos re\right) \cdot t_0\\
\mathbf{if}\;im \leq 31000:\\
\;\;\;\;t_1\\
\mathbf{elif}\;im \leq 10^{+77}:\\
\;\;\;\;t_0 \cdot \left(0.5 + {re}^{-2}\right)\\
\mathbf{elif}\;im \leq 1.55 \cdot 10^{+152}:\\
\;\;\;\;\frac{0.5 + re}{\frac{2 - im \cdot im}{4 - {im}^{4}}}\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if im < 31000 or 1.55e152 < im Initial program 100.0%
Taylor expanded in im around 0 84.3%
Simplified84.3%
if 31000 < im < 9.99999999999999983e76Initial program 100.0%
Taylor expanded in re around 0 0.0%
Simplified91.7%
Taylor expanded in im around 0 43.6%
Simplified43.6%
Applied egg-rr42.9%
if 9.99999999999999983e76 < im < 1.55e152Initial program 100.0%
Taylor expanded in re around 0 0.0%
Simplified69.6%
Taylor expanded in im around 0 24.8%
Simplified24.8%
Applied egg-rr25.4%
*-commutative25.4%
flip-+78.3%
associate-*r/78.3%
add-sqr-sqrt43.5%
fabs-sqr43.5%
add-sqr-sqrt69.6%
metadata-eval69.6%
pow269.6%
pow269.6%
pow-prod-up69.6%
metadata-eval69.6%
Applied egg-rr69.6%
associate-/l*69.6%
Simplified69.6%
Final simplification81.0%
(FPCore (re im)
:precision binary64
(let* ((t_0 (+ 2.0 (* im im))))
(if (or (<= im 31000.0) (not (<= im 1.55e+152)))
(* (* 0.5 (cos re)) t_0)
(* t_0 (+ 0.5 (pow re -2.0))))))
double code(double re, double im) {
double t_0 = 2.0 + (im * im);
double tmp;
if ((im <= 31000.0) || !(im <= 1.55e+152)) {
tmp = (0.5 * cos(re)) * t_0;
} else {
tmp = t_0 * (0.5 + pow(re, -2.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 = 2.0d0 + (im * im)
if ((im <= 31000.0d0) .or. (.not. (im <= 1.55d+152))) then
tmp = (0.5d0 * cos(re)) * t_0
else
tmp = t_0 * (0.5d0 + (re ** (-2.0d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 2.0 + (im * im);
double tmp;
if ((im <= 31000.0) || !(im <= 1.55e+152)) {
tmp = (0.5 * Math.cos(re)) * t_0;
} else {
tmp = t_0 * (0.5 + Math.pow(re, -2.0));
}
return tmp;
}
def code(re, im): t_0 = 2.0 + (im * im) tmp = 0 if (im <= 31000.0) or not (im <= 1.55e+152): tmp = (0.5 * math.cos(re)) * t_0 else: tmp = t_0 * (0.5 + math.pow(re, -2.0)) return tmp
function code(re, im) t_0 = Float64(2.0 + Float64(im * im)) tmp = 0.0 if ((im <= 31000.0) || !(im <= 1.55e+152)) tmp = Float64(Float64(0.5 * cos(re)) * t_0); else tmp = Float64(t_0 * Float64(0.5 + (re ^ -2.0))); end return tmp end
function tmp_2 = code(re, im) t_0 = 2.0 + (im * im); tmp = 0.0; if ((im <= 31000.0) || ~((im <= 1.55e+152))) tmp = (0.5 * cos(re)) * t_0; else tmp = t_0 * (0.5 + (re ^ -2.0)); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[im, 31000.0], N[Not[LessEqual[im, 1.55e+152]], $MachinePrecision]], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * t$95$0), $MachinePrecision], N[(t$95$0 * N[(0.5 + N[Power[re, -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 2 + im \cdot im\\
\mathbf{if}\;im \leq 31000 \lor \neg \left(im \leq 1.55 \cdot 10^{+152}\right):\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot t_0\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot \left(0.5 + {re}^{-2}\right)\\
\end{array}
\end{array}
if im < 31000 or 1.55e152 < im Initial program 100.0%
Taylor expanded in im around 0 84.3%
Simplified84.3%
if 31000 < im < 1.55e152Initial program 100.0%
Taylor expanded in re around 0 0.0%
Simplified77.1%
Taylor expanded in im around 0 31.2%
Simplified31.2%
Applied egg-rr45.0%
Final simplification78.9%
(FPCore (re im)
:precision binary64
(let* ((t_0 (+ 2.0 (* im im))))
(if (or (<= im 610.0) (not (<= im 1.32e+154)))
(* (* 0.5 (cos re)) t_0)
(* t_0 (+ 0.5 (* -0.25 (* re re)))))))
double code(double re, double im) {
double t_0 = 2.0 + (im * im);
double tmp;
if ((im <= 610.0) || !(im <= 1.32e+154)) {
tmp = (0.5 * cos(re)) * 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 = 2.0d0 + (im * im)
if ((im <= 610.0d0) .or. (.not. (im <= 1.32d+154))) then
tmp = (0.5d0 * cos(re)) * 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 = 2.0 + (im * im);
double tmp;
if ((im <= 610.0) || !(im <= 1.32e+154)) {
tmp = (0.5 * Math.cos(re)) * t_0;
} else {
tmp = t_0 * (0.5 + (-0.25 * (re * re)));
}
return tmp;
}
def code(re, im): t_0 = 2.0 + (im * im) tmp = 0 if (im <= 610.0) or not (im <= 1.32e+154): tmp = (0.5 * math.cos(re)) * t_0 else: tmp = t_0 * (0.5 + (-0.25 * (re * re))) return tmp
function code(re, im) t_0 = Float64(2.0 + Float64(im * im)) tmp = 0.0 if ((im <= 610.0) || !(im <= 1.32e+154)) tmp = Float64(Float64(0.5 * cos(re)) * 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 = 2.0 + (im * im); tmp = 0.0; if ((im <= 610.0) || ~((im <= 1.32e+154))) tmp = (0.5 * cos(re)) * 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[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[im, 610.0], N[Not[LessEqual[im, 1.32e+154]], $MachinePrecision]], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * 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 := 2 + im \cdot im\\
\mathbf{if}\;im \leq 610 \lor \neg \left(im \leq 1.32 \cdot 10^{+154}\right):\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \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 < 610 or 1.31999999999999998e154 < im Initial program 100.0%
Taylor expanded in im around 0 84.6%
Simplified84.6%
if 610 < im < 1.31999999999999998e154Initial program 100.0%
Taylor expanded in re around 0 0.0%
Simplified77.8%
Taylor expanded in im around 0 33.1%
Simplified33.1%
Final simplification77.4%
(FPCore (re im) :precision binary64 (if (<= im 0.07) (cos re) (* (+ 2.0 (* im im)) (+ 0.5 (* -0.25 (* re re))))))
double code(double re, double im) {
double tmp;
if (im <= 0.07) {
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 <= 0.07d0) 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 <= 0.07) {
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 <= 0.07: 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 <= 0.07) 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 <= 0.07) 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, 0.07], 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 0.07:\\
\;\;\;\;\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 < 0.070000000000000007Initial program 100.0%
Taylor expanded in im around 0 71.0%
if 0.070000000000000007 < im Initial program 100.0%
Taylor expanded in re around 0 0.0%
Simplified80.3%
Taylor expanded in im around 0 56.0%
Simplified56.0%
Final simplification67.1%
(FPCore (re im) :precision binary64 (if (<= im 6.2e-5) 1.0 (* (+ 2.0 (* im im)) (+ 0.5 (* -0.25 (* re re))))))
double code(double re, double im) {
double tmp;
if (im <= 6.2e-5) {
tmp = 1.0;
} 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 <= 6.2d-5) then
tmp = 1.0d0
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 <= 6.2e-5) {
tmp = 1.0;
} else {
tmp = (2.0 + (im * im)) * (0.5 + (-0.25 * (re * re)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 6.2e-5: tmp = 1.0 else: tmp = (2.0 + (im * im)) * (0.5 + (-0.25 * (re * re))) return tmp
function code(re, im) tmp = 0.0 if (im <= 6.2e-5) tmp = 1.0; 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 <= 6.2e-5) tmp = 1.0; else tmp = (2.0 + (im * im)) * (0.5 + (-0.25 * (re * re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 6.2e-5], 1.0, 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 6.2 \cdot 10^{-5}:\\
\;\;\;\;1\\
\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 < 6.20000000000000027e-5Initial program 100.0%
Taylor expanded in re around 0 56.6%
Taylor expanded in im around 0 36.9%
if 6.20000000000000027e-5 < im Initial program 100.0%
Taylor expanded in re around 0 0.0%
Simplified80.3%
Taylor expanded in im around 0 56.0%
Simplified56.0%
Final simplification41.8%
(FPCore (re im)
:precision binary64
(if (<= im 112.0)
(* 0.5 (+ 2.0 (* im im)))
(if (<= im 8.8e+104)
(* (+ 0.5 (* -0.25 (* re re))) 512.0)
(* (* im im) (+ 0.5 re)))))
double code(double re, double im) {
double tmp;
if (im <= 112.0) {
tmp = 0.5 * (2.0 + (im * im));
} else if (im <= 8.8e+104) {
tmp = (0.5 + (-0.25 * (re * re))) * 512.0;
} else {
tmp = (im * im) * (0.5 + re);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 112.0d0) then
tmp = 0.5d0 * (2.0d0 + (im * im))
else if (im <= 8.8d+104) then
tmp = (0.5d0 + ((-0.25d0) * (re * re))) * 512.0d0
else
tmp = (im * im) * (0.5d0 + re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 112.0) {
tmp = 0.5 * (2.0 + (im * im));
} else if (im <= 8.8e+104) {
tmp = (0.5 + (-0.25 * (re * re))) * 512.0;
} else {
tmp = (im * im) * (0.5 + re);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 112.0: tmp = 0.5 * (2.0 + (im * im)) elif im <= 8.8e+104: tmp = (0.5 + (-0.25 * (re * re))) * 512.0 else: tmp = (im * im) * (0.5 + re) return tmp
function code(re, im) tmp = 0.0 if (im <= 112.0) tmp = Float64(0.5 * Float64(2.0 + Float64(im * im))); elseif (im <= 8.8e+104) tmp = Float64(Float64(0.5 + Float64(-0.25 * Float64(re * re))) * 512.0); else tmp = Float64(Float64(im * im) * Float64(0.5 + re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 112.0) tmp = 0.5 * (2.0 + (im * im)); elseif (im <= 8.8e+104) tmp = (0.5 + (-0.25 * (re * re))) * 512.0; else tmp = (im * im) * (0.5 + re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 112.0], N[(0.5 * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 8.8e+104], N[(N[(0.5 + N[(-0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 512.0), $MachinePrecision], N[(N[(im * im), $MachinePrecision] * N[(0.5 + re), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 112:\\
\;\;\;\;0.5 \cdot \left(2 + im \cdot im\right)\\
\mathbf{elif}\;im \leq 8.8 \cdot 10^{+104}:\\
\;\;\;\;\left(0.5 + -0.25 \cdot \left(re \cdot re\right)\right) \cdot 512\\
\mathbf{else}:\\
\;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + re\right)\\
\end{array}
\end{array}
if im < 112Initial program 100.0%
Taylor expanded in re around 0 56.6%
Taylor expanded in im around 0 44.4%
Simplified44.4%
if 112 < im < 8.80000000000000002e104Initial program 100.0%
Taylor expanded in re around 0 0.0%
Simplified90.5%
Applied egg-rr39.8%
if 8.80000000000000002e104 < im Initial program 100.0%
Taylor expanded in re around 0 0.0%
Simplified75.6%
Taylor expanded in im around 0 63.2%
Simplified63.2%
Applied egg-rr61.2%
Taylor expanded in im around inf 61.2%
unpow261.2%
+-commutative61.2%
distribute-lft-in61.2%
fma-def61.2%
rem-square-sqrt27.6%
fabs-sqr27.6%
rem-square-sqrt32.3%
fma-def32.3%
distribute-lft-in65.6%
+-commutative65.6%
*-commutative65.6%
Simplified65.6%
Final simplification47.7%
(FPCore (re im) :precision binary64 (if (<= im 155.0) (* 0.5 (+ 2.0 (* im im))) (if (<= im 1.45e+105) (+ 1.0 (* (* re re) -0.5)) (* (* im im) (+ 0.5 re)))))
double code(double re, double im) {
double tmp;
if (im <= 155.0) {
tmp = 0.5 * (2.0 + (im * im));
} else if (im <= 1.45e+105) {
tmp = 1.0 + ((re * re) * -0.5);
} else {
tmp = (im * im) * (0.5 + re);
}
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.5d0 * (2.0d0 + (im * im))
else if (im <= 1.45d+105) then
tmp = 1.0d0 + ((re * re) * (-0.5d0))
else
tmp = (im * im) * (0.5d0 + re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 155.0) {
tmp = 0.5 * (2.0 + (im * im));
} else if (im <= 1.45e+105) {
tmp = 1.0 + ((re * re) * -0.5);
} else {
tmp = (im * im) * (0.5 + re);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 155.0: tmp = 0.5 * (2.0 + (im * im)) elif im <= 1.45e+105: tmp = 1.0 + ((re * re) * -0.5) else: tmp = (im * im) * (0.5 + re) return tmp
function code(re, im) tmp = 0.0 if (im <= 155.0) tmp = Float64(0.5 * Float64(2.0 + Float64(im * im))); elseif (im <= 1.45e+105) tmp = Float64(1.0 + Float64(Float64(re * re) * -0.5)); else tmp = Float64(Float64(im * im) * Float64(0.5 + re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 155.0) tmp = 0.5 * (2.0 + (im * im)); elseif (im <= 1.45e+105) tmp = 1.0 + ((re * re) * -0.5); else tmp = (im * im) * (0.5 + re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 155.0], N[(0.5 * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.45e+105], N[(1.0 + N[(N[(re * re), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision], N[(N[(im * im), $MachinePrecision] * N[(0.5 + re), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 155:\\
\;\;\;\;0.5 \cdot \left(2 + im \cdot im\right)\\
\mathbf{elif}\;im \leq 1.45 \cdot 10^{+105}:\\
\;\;\;\;1 + \left(re \cdot re\right) \cdot -0.5\\
\mathbf{else}:\\
\;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + re\right)\\
\end{array}
\end{array}
if im < 155Initial program 100.0%
Taylor expanded in re around 0 56.6%
Taylor expanded in im around 0 44.4%
Simplified44.4%
if 155 < im < 1.45000000000000005e105Initial program 100.0%
Taylor expanded in re around 0 0.0%
Simplified90.5%
Taylor expanded in im around 0 40.3%
Simplified40.3%
Taylor expanded in im around 0 39.7%
distribute-rgt-in39.7%
metadata-eval39.7%
unpow239.7%
*-commutative39.7%
associate-*l*39.7%
metadata-eval39.7%
Simplified39.7%
if 1.45000000000000005e105 < im Initial program 100.0%
Taylor expanded in re around 0 0.0%
Simplified75.6%
Taylor expanded in im around 0 63.2%
Simplified63.2%
Applied egg-rr61.2%
Taylor expanded in im around inf 61.2%
unpow261.2%
+-commutative61.2%
distribute-lft-in61.2%
fma-def61.2%
rem-square-sqrt27.6%
fabs-sqr27.6%
rem-square-sqrt32.3%
fma-def32.3%
distribute-lft-in65.6%
+-commutative65.6%
*-commutative65.6%
Simplified65.6%
Final simplification47.7%
(FPCore (re im) :precision binary64 (if (<= im 78000000000000.0) (* 0.5 (+ 2.0 (* im im))) (* (* im im) (+ 0.5 re))))
double code(double re, double im) {
double tmp;
if (im <= 78000000000000.0) {
tmp = 0.5 * (2.0 + (im * im));
} else {
tmp = (im * im) * (0.5 + re);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 78000000000000.0d0) then
tmp = 0.5d0 * (2.0d0 + (im * im))
else
tmp = (im * im) * (0.5d0 + re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 78000000000000.0) {
tmp = 0.5 * (2.0 + (im * im));
} else {
tmp = (im * im) * (0.5 + re);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 78000000000000.0: tmp = 0.5 * (2.0 + (im * im)) else: tmp = (im * im) * (0.5 + re) return tmp
function code(re, im) tmp = 0.0 if (im <= 78000000000000.0) tmp = Float64(0.5 * Float64(2.0 + Float64(im * im))); else tmp = Float64(Float64(im * im) * Float64(0.5 + re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 78000000000000.0) tmp = 0.5 * (2.0 + (im * im)); else tmp = (im * im) * (0.5 + re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 78000000000000.0], N[(0.5 * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(im * im), $MachinePrecision] * N[(0.5 + re), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 78000000000000:\\
\;\;\;\;0.5 \cdot \left(2 + im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + re\right)\\
\end{array}
\end{array}
if im < 7.8e13Initial program 100.0%
Taylor expanded in re around 0 56.3%
Taylor expanded in im around 0 44.2%
Simplified44.2%
if 7.8e13 < im Initial program 100.0%
Taylor expanded in re around 0 0.0%
Simplified80.0%
Taylor expanded in im around 0 55.3%
Simplified55.3%
Applied egg-rr44.7%
Taylor expanded in im around inf 44.7%
unpow244.7%
+-commutative44.7%
distribute-lft-in44.7%
fma-def44.7%
rem-square-sqrt20.9%
fabs-sqr20.9%
rem-square-sqrt31.1%
fma-def31.1%
distribute-lft-in54.1%
+-commutative54.1%
*-commutative54.1%
Simplified54.1%
Final simplification46.7%
(FPCore (re im) :precision binary64 (* 0.5 (+ 2.0 (* im im))))
double code(double re, double im) {
return 0.5 * (2.0 + (im * im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * (2.0d0 + (im * im))
end function
public static double code(double re, double im) {
return 0.5 * (2.0 + (im * im));
}
def code(re, im): return 0.5 * (2.0 + (im * im))
function code(re, im) return Float64(0.5 * Float64(2.0 + Float64(im * im))) end
function tmp = code(re, im) tmp = 0.5 * (2.0 + (im * im)); end
code[re_, im_] := N[(0.5 * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(2 + im \cdot im\right)
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 60.3%
Taylor expanded in im around 0 42.1%
Simplified42.1%
Final simplification42.1%
(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%
Taylor expanded in re around 0 60.3%
Applied egg-rr4.1%
Final simplification4.1%
(FPCore (re im) :precision binary64 0.0078125)
double code(double re, double im) {
return 0.0078125;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.0078125d0
end function
public static double code(double re, double im) {
return 0.0078125;
}
def code(re, im): return 0.0078125
function code(re, im) return 0.0078125 end
function tmp = code(re, im) tmp = 0.0078125; end
code[re_, im_] := 0.0078125
\begin{array}{l}
\\
0.0078125
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 60.3%
Applied egg-rr7.0%
Final simplification7.0%
(FPCore (re im) :precision binary64 0.125)
double code(double re, double im) {
return 0.125;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.125d0
end function
public static double code(double re, double im) {
return 0.125;
}
def code(re, im): return 0.125
function code(re, im) return 0.125 end
function tmp = code(re, im) tmp = 0.125; end
code[re_, im_] := 0.125
\begin{array}{l}
\\
0.125
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 60.3%
Applied egg-rr7.9%
Final simplification7.9%
(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%
Taylor expanded in re around 0 60.3%
Applied egg-rr8.2%
Final simplification8.2%
(FPCore (re im) :precision binary64 0.375)
double code(double re, double im) {
return 0.375;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.375d0
end function
public static double code(double re, double im) {
return 0.375;
}
def code(re, im): return 0.375
function code(re, im) return 0.375 end
function tmp = code(re, im) tmp = 0.375; end
code[re_, im_] := 0.375
\begin{array}{l}
\\
0.375
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 60.3%
Applied egg-rr8.5%
Final simplification8.5%
(FPCore (re im) :precision binary64 0.5)
double code(double re, double im) {
return 0.5;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0
end function
public static double code(double re, double im) {
return 0.5;
}
def code(re, im): return 0.5
function code(re, im) return 0.5 end
function tmp = code(re, im) tmp = 0.5; end
code[re_, im_] := 0.5
\begin{array}{l}
\\
0.5
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 60.3%
Applied egg-rr8.8%
Final simplification8.8%
(FPCore (re im) :precision binary64 0.75)
double code(double re, double im) {
return 0.75;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.75d0
end function
public static double code(double re, double im) {
return 0.75;
}
def code(re, im): return 0.75
function code(re, im) return 0.75 end
function tmp = code(re, im) tmp = 0.75; end
code[re_, im_] := 0.75
\begin{array}{l}
\\
0.75
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 60.3%
Applied egg-rr9.3%
Final simplification9.3%
(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%
Taylor expanded in re around 0 60.3%
Taylor expanded in im around 0 28.0%
Final simplification28.0%
herbie shell --seed 2023283
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))