
(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 18 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}
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (* (cos re) (fma 0.5 (exp im_m) (/ 0.5 (exp im_m)))))
im_m = fabs(im);
double code(double re, double im_m) {
return cos(re) * fma(0.5, exp(im_m), (0.5 / exp(im_m)));
}
im_m = abs(im) function code(re, im_m) return Float64(cos(re) * fma(0.5, exp(im_m), Float64(0.5 / exp(im_m)))) end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[Exp[im$95$m], $MachinePrecision] + N[(0.5 / N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
\cos re \cdot \mathsf{fma}\left(0.5, e^{im\_m}, \frac{0.5}{e^{im\_m}}\right)
\end{array}
Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
cos-neg100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
fma-define100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (* (* (cos re) 0.5) (+ (exp im_m) (exp (- im_m)))))
im_m = fabs(im);
double code(double re, double im_m) {
return (cos(re) * 0.5) * (exp(im_m) + exp(-im_m));
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
code = (cos(re) * 0.5d0) * (exp(im_m) + exp(-im_m))
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
return (Math.cos(re) * 0.5) * (Math.exp(im_m) + Math.exp(-im_m));
}
im_m = math.fabs(im) def code(re, im_m): return (math.cos(re) * 0.5) * (math.exp(im_m) + math.exp(-im_m))
im_m = abs(im) function code(re, im_m) return Float64(Float64(cos(re) * 0.5) * Float64(exp(im_m) + exp(Float64(-im_m)))) end
im_m = abs(im); function tmp = code(re, im_m) tmp = (cos(re) * 0.5) * (exp(im_m) + exp(-im_m)); end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(N[Exp[im$95$m], $MachinePrecision] + N[Exp[(-im$95$m)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
\left(\cos re \cdot 0.5\right) \cdot \left(e^{im\_m} + e^{-im\_m}\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (or (<= im_m 3.5) (not (<= im_m 5.6e+149))) (* (* (cos re) 0.5) (fma im_m im_m 2.0)) (+ 0.5 (* 0.5 (exp im_m)))))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if ((im_m <= 3.5) || !(im_m <= 5.6e+149)) {
tmp = (cos(re) * 0.5) * fma(im_m, im_m, 2.0);
} else {
tmp = 0.5 + (0.5 * exp(im_m));
}
return tmp;
}
im_m = abs(im) function code(re, im_m) tmp = 0.0 if ((im_m <= 3.5) || !(im_m <= 5.6e+149)) tmp = Float64(Float64(cos(re) * 0.5) * fma(im_m, im_m, 2.0)); else tmp = Float64(0.5 + Float64(0.5 * exp(im_m))); end return tmp end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[Or[LessEqual[im$95$m, 3.5], N[Not[LessEqual[im$95$m, 5.6e+149]], $MachinePrecision]], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(im$95$m * im$95$m + 2.0), $MachinePrecision]), $MachinePrecision], N[(0.5 + N[(0.5 * N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;im\_m \leq 3.5 \lor \neg \left(im\_m \leq 5.6 \cdot 10^{+149}\right):\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \mathsf{fma}\left(im\_m, im\_m, 2\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 + 0.5 \cdot e^{im\_m}\\
\end{array}
\end{array}
if im < 3.5 or 5.5999999999999998e149 < im Initial program 100.0%
Taylor expanded in im around 0 89.0%
+-commutative89.0%
unpow289.0%
fma-define89.0%
Simplified89.0%
if 3.5 < im < 5.5999999999999998e149Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
cos-neg100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
fma-define100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in re around 0 87.9%
Final simplification88.8%
im_m = (fabs.f64 im)
(FPCore (re im_m)
:precision binary64
(if (<= im_m 1.6e-5)
(cos re)
(if (<= im_m 5.6e+149)
(* 0.5 (+ (exp im_m) (exp (- im_m))))
(* (cos re) (+ 1.0 (* im_m (+ 0.5 (* im_m 0.25))))))))im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (im_m <= 1.6e-5) {
tmp = cos(re);
} else if (im_m <= 5.6e+149) {
tmp = 0.5 * (exp(im_m) + exp(-im_m));
} else {
tmp = cos(re) * (1.0 + (im_m * (0.5 + (im_m * 0.25))));
}
return tmp;
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
real(8) :: tmp
if (im_m <= 1.6d-5) then
tmp = cos(re)
else if (im_m <= 5.6d+149) then
tmp = 0.5d0 * (exp(im_m) + exp(-im_m))
else
tmp = cos(re) * (1.0d0 + (im_m * (0.5d0 + (im_m * 0.25d0))))
end if
code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if (im_m <= 1.6e-5) {
tmp = Math.cos(re);
} else if (im_m <= 5.6e+149) {
tmp = 0.5 * (Math.exp(im_m) + Math.exp(-im_m));
} else {
tmp = Math.cos(re) * (1.0 + (im_m * (0.5 + (im_m * 0.25))));
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if im_m <= 1.6e-5: tmp = math.cos(re) elif im_m <= 5.6e+149: tmp = 0.5 * (math.exp(im_m) + math.exp(-im_m)) else: tmp = math.cos(re) * (1.0 + (im_m * (0.5 + (im_m * 0.25)))) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (im_m <= 1.6e-5) tmp = cos(re); elseif (im_m <= 5.6e+149) tmp = Float64(0.5 * Float64(exp(im_m) + exp(Float64(-im_m)))); else tmp = Float64(cos(re) * Float64(1.0 + Float64(im_m * Float64(0.5 + Float64(im_m * 0.25))))); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if (im_m <= 1.6e-5) tmp = cos(re); elseif (im_m <= 5.6e+149) tmp = 0.5 * (exp(im_m) + exp(-im_m)); else tmp = cos(re) * (1.0 + (im_m * (0.5 + (im_m * 0.25)))); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[im$95$m, 1.6e-5], N[Cos[re], $MachinePrecision], If[LessEqual[im$95$m, 5.6e+149], N[(0.5 * N[(N[Exp[im$95$m], $MachinePrecision] + N[Exp[(-im$95$m)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(1.0 + N[(im$95$m * N[(0.5 + N[(im$95$m * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;im\_m \leq 1.6 \cdot 10^{-5}:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im\_m \leq 5.6 \cdot 10^{+149}:\\
\;\;\;\;0.5 \cdot \left(e^{im\_m} + e^{-im\_m}\right)\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot 0.25\right)\right)\\
\end{array}
\end{array}
if im < 1.59999999999999993e-5Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
cos-neg100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
fma-define100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 70.5%
if 1.59999999999999993e-5 < im < 5.5999999999999998e149Initial program 100.0%
Taylor expanded in re around 0 86.5%
if 5.5999999999999998e149 < im Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
cos-neg100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
fma-define100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in im around 0 94.0%
+-commutative94.0%
*-rgt-identity94.0%
associate-*r*94.0%
associate-*r*94.0%
distribute-rgt-out94.0%
+-commutative94.0%
distribute-lft-in94.0%
+-commutative94.0%
unpow294.0%
associate-*r*94.0%
distribute-rgt-out94.0%
*-commutative94.0%
Simplified94.0%
Final simplification75.4%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (* (cos re) (+ 0.5 (* 0.5 (exp im_m)))))
im_m = fabs(im);
double code(double re, double im_m) {
return cos(re) * (0.5 + (0.5 * exp(im_m)));
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
code = cos(re) * (0.5d0 + (0.5d0 * exp(im_m)))
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
return Math.cos(re) * (0.5 + (0.5 * Math.exp(im_m)));
}
im_m = math.fabs(im) def code(re, im_m): return math.cos(re) * (0.5 + (0.5 * math.exp(im_m)))
im_m = abs(im) function code(re, im_m) return Float64(cos(re) * Float64(0.5 + Float64(0.5 * exp(im_m)))) end
im_m = abs(im); function tmp = code(re, im_m) tmp = cos(re) * (0.5 + (0.5 * exp(im_m))); end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := N[(N[Cos[re], $MachinePrecision] * N[(0.5 + N[(0.5 * N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
\cos re \cdot \left(0.5 + 0.5 \cdot e^{im\_m}\right)
\end{array}
Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
cos-neg100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
fma-define100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 76.7%
Taylor expanded in re around inf 76.7%
*-commutative76.7%
Simplified76.7%
Final simplification76.7%
im_m = (fabs.f64 im)
(FPCore (re im_m)
:precision binary64
(if (<= im_m 2.0)
(cos re)
(if (<= im_m 5.6e+149)
(+ 0.5 (* 0.5 (exp im_m)))
(* (cos re) (+ 1.0 (* im_m (+ 0.5 (* im_m 0.25))))))))im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (im_m <= 2.0) {
tmp = cos(re);
} else if (im_m <= 5.6e+149) {
tmp = 0.5 + (0.5 * exp(im_m));
} else {
tmp = cos(re) * (1.0 + (im_m * (0.5 + (im_m * 0.25))));
}
return tmp;
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
real(8) :: tmp
if (im_m <= 2.0d0) then
tmp = cos(re)
else if (im_m <= 5.6d+149) then
tmp = 0.5d0 + (0.5d0 * exp(im_m))
else
tmp = cos(re) * (1.0d0 + (im_m * (0.5d0 + (im_m * 0.25d0))))
end if
code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if (im_m <= 2.0) {
tmp = Math.cos(re);
} else if (im_m <= 5.6e+149) {
tmp = 0.5 + (0.5 * Math.exp(im_m));
} else {
tmp = Math.cos(re) * (1.0 + (im_m * (0.5 + (im_m * 0.25))));
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if im_m <= 2.0: tmp = math.cos(re) elif im_m <= 5.6e+149: tmp = 0.5 + (0.5 * math.exp(im_m)) else: tmp = math.cos(re) * (1.0 + (im_m * (0.5 + (im_m * 0.25)))) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (im_m <= 2.0) tmp = cos(re); elseif (im_m <= 5.6e+149) tmp = Float64(0.5 + Float64(0.5 * exp(im_m))); else tmp = Float64(cos(re) * Float64(1.0 + Float64(im_m * Float64(0.5 + Float64(im_m * 0.25))))); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if (im_m <= 2.0) tmp = cos(re); elseif (im_m <= 5.6e+149) tmp = 0.5 + (0.5 * exp(im_m)); else tmp = cos(re) * (1.0 + (im_m * (0.5 + (im_m * 0.25)))); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[im$95$m, 2.0], N[Cos[re], $MachinePrecision], If[LessEqual[im$95$m, 5.6e+149], N[(0.5 + N[(0.5 * N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(1.0 + N[(im$95$m * N[(0.5 + N[(im$95$m * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;im\_m \leq 2:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im\_m \leq 5.6 \cdot 10^{+149}:\\
\;\;\;\;0.5 + 0.5 \cdot e^{im\_m}\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left(1 + im\_m \cdot \left(0.5 + im\_m \cdot 0.25\right)\right)\\
\end{array}
\end{array}
if im < 2Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
cos-neg100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
fma-define100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 70.3%
if 2 < im < 5.5999999999999998e149Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
cos-neg100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
fma-define100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in re around 0 87.9%
if 5.5999999999999998e149 < im Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
cos-neg100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
fma-define100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in im around 0 94.0%
+-commutative94.0%
*-rgt-identity94.0%
associate-*r*94.0%
associate-*r*94.0%
distribute-rgt-out94.0%
+-commutative94.0%
distribute-lft-in94.0%
+-commutative94.0%
unpow294.0%
associate-*r*94.0%
distribute-rgt-out94.0%
*-commutative94.0%
Simplified94.0%
Final simplification75.2%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (<= im_m 1.6e-5) (cos re) (* 0.5 (fma im_m im_m 2.0))))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (im_m <= 1.6e-5) {
tmp = cos(re);
} else {
tmp = 0.5 * fma(im_m, im_m, 2.0);
}
return tmp;
}
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (im_m <= 1.6e-5) tmp = cos(re); else tmp = Float64(0.5 * fma(im_m, im_m, 2.0)); end return tmp end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[im$95$m, 1.6e-5], N[Cos[re], $MachinePrecision], N[(0.5 * N[(im$95$m * im$95$m + 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;im\_m \leq 1.6 \cdot 10^{-5}:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{fma}\left(im\_m, im\_m, 2\right)\\
\end{array}
\end{array}
if im < 1.59999999999999993e-5Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
cos-neg100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
fma-define100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 70.5%
if 1.59999999999999993e-5 < im Initial program 100.0%
Taylor expanded in re around 0 73.9%
Taylor expanded in im around 0 30.5%
+-commutative30.5%
unpow230.5%
fma-define30.5%
Simplified30.5%
Final simplification60.5%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (<= im_m 2.4) (cos re) (+ 0.5 (* 0.5 (exp im_m)))))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (im_m <= 2.4) {
tmp = cos(re);
} else {
tmp = 0.5 + (0.5 * exp(im_m));
}
return tmp;
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
real(8) :: tmp
if (im_m <= 2.4d0) then
tmp = cos(re)
else
tmp = 0.5d0 + (0.5d0 * exp(im_m))
end if
code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if (im_m <= 2.4) {
tmp = Math.cos(re);
} else {
tmp = 0.5 + (0.5 * Math.exp(im_m));
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if im_m <= 2.4: tmp = math.cos(re) else: tmp = 0.5 + (0.5 * math.exp(im_m)) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (im_m <= 2.4) tmp = cos(re); else tmp = Float64(0.5 + Float64(0.5 * exp(im_m))); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if (im_m <= 2.4) tmp = cos(re); else tmp = 0.5 + (0.5 * exp(im_m)); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[im$95$m, 2.4], N[Cos[re], $MachinePrecision], N[(0.5 + N[(0.5 * N[Exp[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;im\_m \leq 2.4:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;0.5 + 0.5 \cdot e^{im\_m}\\
\end{array}
\end{array}
if im < 2.39999999999999991Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
cos-neg100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
fma-define100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 70.3%
if 2.39999999999999991 < im Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
cos-neg100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
fma-define100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in re around 0 74.2%
Final simplification71.2%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (<= im_m 2.5e+32) (cos re) (+ 1.0 (* im_m (+ 0.5 (* im_m 0.25))))))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (im_m <= 2.5e+32) {
tmp = cos(re);
} else {
tmp = 1.0 + (im_m * (0.5 + (im_m * 0.25)));
}
return tmp;
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
real(8) :: tmp
if (im_m <= 2.5d+32) then
tmp = cos(re)
else
tmp = 1.0d0 + (im_m * (0.5d0 + (im_m * 0.25d0)))
end if
code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if (im_m <= 2.5e+32) {
tmp = Math.cos(re);
} else {
tmp = 1.0 + (im_m * (0.5 + (im_m * 0.25)));
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if im_m <= 2.5e+32: tmp = math.cos(re) else: tmp = 1.0 + (im_m * (0.5 + (im_m * 0.25))) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (im_m <= 2.5e+32) tmp = cos(re); else tmp = Float64(1.0 + Float64(im_m * Float64(0.5 + Float64(im_m * 0.25)))); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if (im_m <= 2.5e+32) tmp = cos(re); else tmp = 1.0 + (im_m * (0.5 + (im_m * 0.25))); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[im$95$m, 2.5e+32], N[Cos[re], $MachinePrecision], N[(1.0 + N[(im$95$m * N[(0.5 + N[(im$95$m * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;im\_m \leq 2.5 \cdot 10^{+32}:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;1 + im\_m \cdot \left(0.5 + im\_m \cdot 0.25\right)\\
\end{array}
\end{array}
if im < 2.4999999999999999e32Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
cos-neg100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
fma-define100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 67.6%
if 2.4999999999999999e32 < im Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
cos-neg100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
fma-define100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in re around 0 74.1%
Taylor expanded in im around 0 33.9%
+-commutative33.9%
*-commutative33.9%
*-commutative33.9%
unpow233.9%
associate-*l*33.9%
distribute-lft-out33.9%
Simplified33.9%
Final simplification60.5%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (+ 1.0 (* im_m (+ 0.5 (* im_m 0.25)))))
im_m = fabs(im);
double code(double re, double im_m) {
return 1.0 + (im_m * (0.5 + (im_m * 0.25)));
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
code = 1.0d0 + (im_m * (0.5d0 + (im_m * 0.25d0)))
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
return 1.0 + (im_m * (0.5 + (im_m * 0.25)));
}
im_m = math.fabs(im) def code(re, im_m): return 1.0 + (im_m * (0.5 + (im_m * 0.25)))
im_m = abs(im) function code(re, im_m) return Float64(1.0 + Float64(im_m * Float64(0.5 + Float64(im_m * 0.25)))) end
im_m = abs(im); function tmp = code(re, im_m) tmp = 1.0 + (im_m * (0.5 + (im_m * 0.25))); end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := N[(1.0 + N[(im$95$m * N[(0.5 + N[(im$95$m * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
1 + im\_m \cdot \left(0.5 + im\_m \cdot 0.25\right)
\end{array}
Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
cos-neg100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
fma-define100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 76.7%
Taylor expanded in re around 0 48.2%
Taylor expanded in im around 0 48.5%
+-commutative48.5%
*-commutative48.5%
*-commutative48.5%
unpow248.5%
associate-*l*48.5%
distribute-lft-out48.5%
Simplified48.5%
Final simplification48.5%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (+ 1.0 (* 0.5 im_m)))
im_m = fabs(im);
double code(double re, double im_m) {
return 1.0 + (0.5 * im_m);
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
code = 1.0d0 + (0.5d0 * im_m)
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
return 1.0 + (0.5 * im_m);
}
im_m = math.fabs(im) def code(re, im_m): return 1.0 + (0.5 * im_m)
im_m = abs(im) function code(re, im_m) return Float64(1.0 + Float64(0.5 * im_m)) end
im_m = abs(im); function tmp = code(re, im_m) tmp = 1.0 + (0.5 * im_m); end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := N[(1.0 + N[(0.5 * im$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
1 + 0.5 \cdot im\_m
\end{array}
Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
cos-neg100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
fma-define100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 76.7%
Taylor expanded in re around 0 48.2%
Taylor expanded in im around 0 31.0%
Final simplification31.0%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 -2.0)
im_m = fabs(im);
double code(double re, double im_m) {
return -2.0;
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
code = -2.0d0
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
return -2.0;
}
im_m = math.fabs(im) def code(re, im_m): return -2.0
im_m = abs(im) function code(re, im_m) return -2.0 end
im_m = abs(im); function tmp = code(re, im_m) tmp = -2.0; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := -2.0
\begin{array}{l}
im_m = \left|im\right|
\\
-2
\end{array}
Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
cos-neg100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
fma-define100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 76.7%
Applied egg-rr3.3%
Final simplification3.3%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 -1.0)
im_m = fabs(im);
double code(double re, double im_m) {
return -1.0;
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
code = -1.0d0
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
return -1.0;
}
im_m = math.fabs(im) def code(re, im_m): return -1.0
im_m = abs(im) function code(re, im_m) return -1.0 end
im_m = abs(im); function tmp = code(re, im_m) tmp = -1.0; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := -1.0
\begin{array}{l}
im_m = \left|im\right|
\\
-1
\end{array}
Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
cos-neg100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
fma-define100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 76.7%
Applied egg-rr3.7%
Final simplification3.7%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 0.041666666666666664)
im_m = fabs(im);
double code(double re, double im_m) {
return 0.041666666666666664;
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
code = 0.041666666666666664d0
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
return 0.041666666666666664;
}
im_m = math.fabs(im) def code(re, im_m): return 0.041666666666666664
im_m = abs(im) function code(re, im_m) return 0.041666666666666664 end
im_m = abs(im); function tmp = code(re, im_m) tmp = 0.041666666666666664; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := 0.041666666666666664
\begin{array}{l}
im_m = \left|im\right|
\\
0.041666666666666664
\end{array}
Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
cos-neg100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
fma-define100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 76.7%
Applied egg-rr7.9%
Final simplification7.9%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 0.125)
im_m = fabs(im);
double code(double re, double im_m) {
return 0.125;
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
code = 0.125d0
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
return 0.125;
}
im_m = math.fabs(im) def code(re, im_m): return 0.125
im_m = abs(im) function code(re, im_m) return 0.125 end
im_m = abs(im); function tmp = code(re, im_m) tmp = 0.125; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := 0.125
\begin{array}{l}
im_m = \left|im\right|
\\
0.125
\end{array}
Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
cos-neg100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
fma-define100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 76.7%
Applied egg-rr8.3%
Final simplification8.3%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 0.25)
im_m = fabs(im);
double code(double re, double im_m) {
return 0.25;
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
code = 0.25d0
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
return 0.25;
}
im_m = math.fabs(im) def code(re, im_m): return 0.25
im_m = abs(im) function code(re, im_m) return 0.25 end
im_m = abs(im); function tmp = code(re, im_m) tmp = 0.25; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := 0.25
\begin{array}{l}
im_m = \left|im\right|
\\
0.25
\end{array}
Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
cos-neg100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
fma-define100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 76.7%
Applied egg-rr8.7%
Final simplification8.7%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 0.5)
im_m = fabs(im);
double code(double re, double im_m) {
return 0.5;
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
code = 0.5d0
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
return 0.5;
}
im_m = math.fabs(im) def code(re, im_m): return 0.5
im_m = abs(im) function code(re, im_m) return 0.5 end
im_m = abs(im); function tmp = code(re, im_m) tmp = 0.5; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := 0.5
\begin{array}{l}
im_m = \left|im\right|
\\
0.5
\end{array}
Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
cos-neg100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
fma-define100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 76.7%
Applied egg-rr9.3%
Final simplification9.3%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 1.0)
im_m = fabs(im);
double code(double re, double im_m) {
return 1.0;
}
im_m = abs(im)
real(8) function code(re, im_m)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
code = 1.0d0
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
return 1.0;
}
im_m = math.fabs(im) def code(re, im_m): return 1.0
im_m = abs(im) function code(re, im_m) return 1.0 end
im_m = abs(im); function tmp = code(re, im_m) tmp = 1.0; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := 1.0
\begin{array}{l}
im_m = \left|im\right|
\\
1
\end{array}
Initial program 100.0%
cos-neg100.0%
*-commutative100.0%
associate-*l*100.0%
cos-neg100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
fma-define100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 76.7%
Taylor expanded in re around 0 48.2%
Taylor expanded in im around 0 31.3%
Final simplification31.3%
herbie shell --seed 2024053
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))