
(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 15 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 (<= im 260.0)
(cos re)
(if (<= im 1.95e+93)
(pow re -2.0)
(if (<= im 1.3e+154) (log1p (expm1 re)) (* 0.5 (fma im im 2.0))))))
double code(double re, double im) {
double tmp;
if (im <= 260.0) {
tmp = cos(re);
} else if (im <= 1.95e+93) {
tmp = pow(re, -2.0);
} else if (im <= 1.3e+154) {
tmp = log1p(expm1(re));
} else {
tmp = 0.5 * fma(im, im, 2.0);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 260.0) tmp = cos(re); elseif (im <= 1.95e+93) tmp = re ^ -2.0; elseif (im <= 1.3e+154) tmp = log1p(expm1(re)); else tmp = Float64(0.5 * fma(im, im, 2.0)); end return tmp end
code[re_, im_] := If[LessEqual[im, 260.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.95e+93], N[Power[re, -2.0], $MachinePrecision], If[LessEqual[im, 1.3e+154], N[Log[1 + N[(Exp[re] - 1), $MachinePrecision]], $MachinePrecision], N[(0.5 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 260:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.95 \cdot 10^{+93}:\\
\;\;\;\;{re}^{-2}\\
\mathbf{elif}\;im \leq 1.3 \cdot 10^{+154}:\\
\;\;\;\;\mathsf{log1p}\left(\mathsf{expm1}\left(re\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{fma}\left(im, im, 2\right)\\
\end{array}
\end{array}
if im < 260Initial program 100.0%
Taylor expanded in im around 0 58.6%
if 260 < im < 1.9500000000000001e93Initial program 100.0%
Taylor expanded in im around 0 4.2%
+-commutative4.2%
unpow24.2%
fma-define4.2%
Simplified4.2%
Taylor expanded in im around inf 4.2%
*-commutative4.2%
associate-*r*4.2%
Simplified4.2%
Taylor expanded in re around 0 7.7%
associate-*r*7.7%
+-commutative7.7%
*-commutative7.7%
*-commutative7.7%
associate-*l*7.7%
distribute-lft-out7.7%
Simplified7.7%
Applied egg-rr31.4%
if 1.9500000000000001e93 < im < 1.29999999999999994e154Initial program 100.0%
Taylor expanded in im around 0 8.5%
+-commutative8.5%
unpow28.5%
fma-define8.5%
Simplified8.5%
Taylor expanded in im around inf 8.5%
*-commutative8.5%
associate-*r*8.5%
Simplified8.5%
Taylor expanded in re around 0 37.3%
associate-*r*37.3%
+-commutative37.3%
*-commutative37.3%
*-commutative37.3%
associate-*l*37.3%
distribute-lft-out37.3%
Simplified37.3%
Applied egg-rr41.7%
if 1.29999999999999994e154 < im Initial program 100.0%
Taylor expanded in re around 0 93.5%
Taylor expanded in im around 0 93.5%
+-commutative93.5%
unpow293.5%
fma-define93.5%
Simplified93.5%
Final simplification59.5%
(FPCore (re im)
:precision binary64
(if (<= im 0.00019)
(cos re)
(if (<= im 1.35e+154)
(* 0.5 (+ (exp (- im)) (exp im)))
(* (* 0.5 (cos re)) (pow im 2.0)))))
double code(double re, double im) {
double tmp;
if (im <= 0.00019) {
tmp = cos(re);
} else if (im <= 1.35e+154) {
tmp = 0.5 * (exp(-im) + exp(im));
} else {
tmp = (0.5 * cos(re)) * pow(im, 2.0);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 0.00019d0) then
tmp = cos(re)
else if (im <= 1.35d+154) then
tmp = 0.5d0 * (exp(-im) + exp(im))
else
tmp = (0.5d0 * cos(re)) * (im ** 2.0d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 0.00019) {
tmp = Math.cos(re);
} else if (im <= 1.35e+154) {
tmp = 0.5 * (Math.exp(-im) + Math.exp(im));
} else {
tmp = (0.5 * Math.cos(re)) * Math.pow(im, 2.0);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 0.00019: tmp = math.cos(re) elif im <= 1.35e+154: tmp = 0.5 * (math.exp(-im) + math.exp(im)) else: tmp = (0.5 * math.cos(re)) * math.pow(im, 2.0) return tmp
function code(re, im) tmp = 0.0 if (im <= 0.00019) tmp = cos(re); elseif (im <= 1.35e+154) tmp = Float64(0.5 * Float64(exp(Float64(-im)) + exp(im))); else tmp = Float64(Float64(0.5 * cos(re)) * (im ^ 2.0)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 0.00019) tmp = cos(re); elseif (im <= 1.35e+154) tmp = 0.5 * (exp(-im) + exp(im)); else tmp = (0.5 * cos(re)) * (im ^ 2.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 0.00019], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.00019:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot {im}^{2}\\
\end{array}
\end{array}
if im < 1.9000000000000001e-4Initial program 100.0%
Taylor expanded in im around 0 59.3%
if 1.9000000000000001e-4 < im < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in re around 0 78.1%
if 1.35000000000000003e154 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
+-commutative100.0%
unpow2100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
*-commutative100.0%
associate-*r*100.0%
Simplified100.0%
Final simplification67.5%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (cos re))))
(if (<= im 0.155)
(* t_0 (fma im im 2.0))
(if (<= im 1.35e+154)
(* 0.5 (+ (exp (- im)) (exp im)))
(* t_0 (pow im 2.0))))))
double code(double re, double im) {
double t_0 = 0.5 * cos(re);
double tmp;
if (im <= 0.155) {
tmp = t_0 * fma(im, im, 2.0);
} else if (im <= 1.35e+154) {
tmp = 0.5 * (exp(-im) + exp(im));
} else {
tmp = t_0 * pow(im, 2.0);
}
return tmp;
}
function code(re, im) t_0 = Float64(0.5 * cos(re)) tmp = 0.0 if (im <= 0.155) tmp = Float64(t_0 * fma(im, im, 2.0)); elseif (im <= 1.35e+154) tmp = Float64(0.5 * Float64(exp(Float64(-im)) + exp(im))); else tmp = Float64(t_0 * (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.155], N[(t$95$0 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \cos re\\
\mathbf{if}\;im \leq 0.155:\\
\;\;\;\;t\_0 \cdot \mathsf{fma}\left(im, im, 2\right)\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot {im}^{2}\\
\end{array}
\end{array}
if im < 0.154999999999999999Initial program 100.0%
Taylor expanded in im around 0 80.9%
+-commutative80.9%
unpow280.9%
fma-define80.9%
Simplified80.9%
if 0.154999999999999999 < im < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in re around 0 79.5%
if 1.35000000000000003e154 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
+-commutative100.0%
unpow2100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
*-commutative100.0%
associate-*r*100.0%
Simplified100.0%
Final simplification83.0%
(FPCore (re im) :precision binary64 (if (<= im 9.4e-5) (cos re) (* 0.5 (+ (exp (- im)) (exp im)))))
double code(double re, double im) {
double tmp;
if (im <= 9.4e-5) {
tmp = cos(re);
} else {
tmp = 0.5 * (exp(-im) + exp(im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 9.4d-5) then
tmp = cos(re)
else
tmp = 0.5d0 * (exp(-im) + exp(im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 9.4e-5) {
tmp = Math.cos(re);
} else {
tmp = 0.5 * (Math.exp(-im) + Math.exp(im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 9.4e-5: tmp = math.cos(re) else: tmp = 0.5 * (math.exp(-im) + math.exp(im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 9.4e-5) tmp = cos(re); else tmp = Float64(0.5 * Float64(exp(Float64(-im)) + exp(im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 9.4e-5) tmp = cos(re); else tmp = 0.5 * (exp(-im) + exp(im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 9.4e-5], N[Cos[re], $MachinePrecision], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 9.4 \cdot 10^{-5}:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\
\end{array}
\end{array}
if im < 9.39999999999999945e-5Initial program 100.0%
Taylor expanded in im around 0 59.3%
if 9.39999999999999945e-5 < im Initial program 100.0%
Taylor expanded in re around 0 84.5%
Final simplification66.7%
(FPCore (re im)
:precision binary64
(if (<= im 260.0)
(cos re)
(if (<= im 1.2e+93)
(pow re -2.0)
(if (<= im 2.6e+106)
(fma re re -2.0)
(if (<= im 6.2e+115)
(pow re -2.0)
(if (<= im 2.7e+153) (- -2.0 (* re re)) (* 0.5 (fma im im 2.0))))))))
double code(double re, double im) {
double tmp;
if (im <= 260.0) {
tmp = cos(re);
} else if (im <= 1.2e+93) {
tmp = pow(re, -2.0);
} else if (im <= 2.6e+106) {
tmp = fma(re, re, -2.0);
} else if (im <= 6.2e+115) {
tmp = pow(re, -2.0);
} else if (im <= 2.7e+153) {
tmp = -2.0 - (re * re);
} else {
tmp = 0.5 * fma(im, im, 2.0);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 260.0) tmp = cos(re); elseif (im <= 1.2e+93) tmp = re ^ -2.0; elseif (im <= 2.6e+106) tmp = fma(re, re, -2.0); elseif (im <= 6.2e+115) tmp = re ^ -2.0; elseif (im <= 2.7e+153) tmp = Float64(-2.0 - Float64(re * re)); else tmp = Float64(0.5 * fma(im, im, 2.0)); end return tmp end
code[re_, im_] := If[LessEqual[im, 260.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.2e+93], N[Power[re, -2.0], $MachinePrecision], If[LessEqual[im, 2.6e+106], N[(re * re + -2.0), $MachinePrecision], If[LessEqual[im, 6.2e+115], N[Power[re, -2.0], $MachinePrecision], If[LessEqual[im, 2.7e+153], N[(-2.0 - N[(re * re), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 260:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.2 \cdot 10^{+93}:\\
\;\;\;\;{re}^{-2}\\
\mathbf{elif}\;im \leq 2.6 \cdot 10^{+106}:\\
\;\;\;\;\mathsf{fma}\left(re, re, -2\right)\\
\mathbf{elif}\;im \leq 6.2 \cdot 10^{+115}:\\
\;\;\;\;{re}^{-2}\\
\mathbf{elif}\;im \leq 2.7 \cdot 10^{+153}:\\
\;\;\;\;-2 - re \cdot re\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{fma}\left(im, im, 2\right)\\
\end{array}
\end{array}
if im < 260Initial program 100.0%
Taylor expanded in im around 0 58.6%
if 260 < im < 1.20000000000000005e93 or 2.6000000000000002e106 < im < 6.2000000000000001e115Initial program 100.0%
Taylor expanded in im around 0 4.2%
+-commutative4.2%
unpow24.2%
fma-define4.2%
Simplified4.2%
Taylor expanded in im around inf 4.2%
*-commutative4.2%
associate-*r*4.2%
Simplified4.2%
Taylor expanded in re around 0 7.7%
associate-*r*7.7%
+-commutative7.7%
*-commutative7.7%
*-commutative7.7%
associate-*l*7.7%
distribute-lft-out7.7%
Simplified7.7%
Applied egg-rr31.4%
if 1.20000000000000005e93 < im < 2.6000000000000002e106Initial program 100.0%
Taylor expanded in im around 0 5.5%
+-commutative5.5%
unpow25.5%
fma-define5.5%
Simplified5.5%
Taylor expanded in im around inf 5.5%
*-commutative5.5%
associate-*r*5.5%
Simplified5.5%
Taylor expanded in re around 0 0.0%
associate-*r*0.0%
+-commutative0.0%
*-commutative0.0%
*-commutative0.0%
associate-*l*0.0%
distribute-lft-out0.0%
Simplified0.0%
Applied egg-rr100.0%
if 6.2000000000000001e115 < im < 2.7000000000000001e153Initial program 100.0%
Taylor expanded in im around 0 9.2%
+-commutative9.2%
unpow29.2%
fma-define9.2%
Simplified9.2%
Taylor expanded in im around inf 9.2%
*-commutative9.2%
associate-*r*9.2%
Simplified9.2%
Taylor expanded in re around 0 45.3%
associate-*r*45.3%
+-commutative45.3%
*-commutative45.3%
*-commutative45.3%
associate-*l*45.3%
distribute-lft-out45.3%
Simplified45.3%
Applied egg-rr23.6%
if 2.7000000000000001e153 < im Initial program 100.0%
Taylor expanded in re around 0 93.5%
Taylor expanded in im around 0 93.5%
+-commutative93.5%
unpow293.5%
fma-define93.5%
Simplified93.5%
Final simplification59.2%
(FPCore (re im)
:precision binary64
(if (<= im 242.0)
(cos re)
(if (<= im 9.8e+92)
(pow re -2.0)
(if (<= im 4.2e+108)
(fma re re -2.0)
(if (<= im 1.4e+116)
(pow re -2.0)
(if (<= im 7.2e+152) (- -2.0 (* re re)) (* 0.5 (pow im 2.0))))))))
double code(double re, double im) {
double tmp;
if (im <= 242.0) {
tmp = cos(re);
} else if (im <= 9.8e+92) {
tmp = pow(re, -2.0);
} else if (im <= 4.2e+108) {
tmp = fma(re, re, -2.0);
} else if (im <= 1.4e+116) {
tmp = pow(re, -2.0);
} else if (im <= 7.2e+152) {
tmp = -2.0 - (re * re);
} else {
tmp = 0.5 * pow(im, 2.0);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 242.0) tmp = cos(re); elseif (im <= 9.8e+92) tmp = re ^ -2.0; elseif (im <= 4.2e+108) tmp = fma(re, re, -2.0); elseif (im <= 1.4e+116) tmp = re ^ -2.0; elseif (im <= 7.2e+152) tmp = Float64(-2.0 - Float64(re * re)); else tmp = Float64(0.5 * (im ^ 2.0)); end return tmp end
code[re_, im_] := If[LessEqual[im, 242.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 9.8e+92], N[Power[re, -2.0], $MachinePrecision], If[LessEqual[im, 4.2e+108], N[(re * re + -2.0), $MachinePrecision], If[LessEqual[im, 1.4e+116], N[Power[re, -2.0], $MachinePrecision], If[LessEqual[im, 7.2e+152], N[(-2.0 - N[(re * re), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 242:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 9.8 \cdot 10^{+92}:\\
\;\;\;\;{re}^{-2}\\
\mathbf{elif}\;im \leq 4.2 \cdot 10^{+108}:\\
\;\;\;\;\mathsf{fma}\left(re, re, -2\right)\\
\mathbf{elif}\;im \leq 1.4 \cdot 10^{+116}:\\
\;\;\;\;{re}^{-2}\\
\mathbf{elif}\;im \leq 7.2 \cdot 10^{+152}:\\
\;\;\;\;-2 - re \cdot re\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot {im}^{2}\\
\end{array}
\end{array}
if im < 242Initial program 100.0%
Taylor expanded in im around 0 58.6%
if 242 < im < 9.8000000000000003e92 or 4.20000000000000019e108 < im < 1.40000000000000002e116Initial program 100.0%
Taylor expanded in im around 0 4.2%
+-commutative4.2%
unpow24.2%
fma-define4.2%
Simplified4.2%
Taylor expanded in im around inf 4.2%
*-commutative4.2%
associate-*r*4.2%
Simplified4.2%
Taylor expanded in re around 0 7.7%
associate-*r*7.7%
+-commutative7.7%
*-commutative7.7%
*-commutative7.7%
associate-*l*7.7%
distribute-lft-out7.7%
Simplified7.7%
Applied egg-rr31.4%
if 9.8000000000000003e92 < im < 4.20000000000000019e108Initial program 100.0%
Taylor expanded in im around 0 5.5%
+-commutative5.5%
unpow25.5%
fma-define5.5%
Simplified5.5%
Taylor expanded in im around inf 5.5%
*-commutative5.5%
associate-*r*5.5%
Simplified5.5%
Taylor expanded in re around 0 0.0%
associate-*r*0.0%
+-commutative0.0%
*-commutative0.0%
*-commutative0.0%
associate-*l*0.0%
distribute-lft-out0.0%
Simplified0.0%
Applied egg-rr100.0%
if 1.40000000000000002e116 < im < 7.1999999999999998e152Initial program 100.0%
Taylor expanded in im around 0 9.2%
+-commutative9.2%
unpow29.2%
fma-define9.2%
Simplified9.2%
Taylor expanded in im around inf 9.2%
*-commutative9.2%
associate-*r*9.2%
Simplified9.2%
Taylor expanded in re around 0 45.3%
associate-*r*45.3%
+-commutative45.3%
*-commutative45.3%
*-commutative45.3%
associate-*l*45.3%
distribute-lft-out45.3%
Simplified45.3%
Applied egg-rr23.6%
if 7.1999999999999998e152 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
+-commutative100.0%
unpow2100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
*-commutative100.0%
associate-*r*100.0%
Simplified100.0%
Taylor expanded in re around 0 93.5%
*-commutative93.5%
Simplified93.5%
Final simplification59.2%
(FPCore (re im)
:precision binary64
(if (<= im 260.0)
(cos re)
(if (<= im 1.56e+93)
(pow re -2.0)
(if (<= im 2.5e+106)
(fma re re -2.0)
(if (<= im 1.05e+152)
(- -2.0 (* re re))
(if (<= im 9.8e+179) (fma re re -2.0) (pow re -2.0)))))))
double code(double re, double im) {
double tmp;
if (im <= 260.0) {
tmp = cos(re);
} else if (im <= 1.56e+93) {
tmp = pow(re, -2.0);
} else if (im <= 2.5e+106) {
tmp = fma(re, re, -2.0);
} else if (im <= 1.05e+152) {
tmp = -2.0 - (re * re);
} else if (im <= 9.8e+179) {
tmp = fma(re, re, -2.0);
} else {
tmp = pow(re, -2.0);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 260.0) tmp = cos(re); elseif (im <= 1.56e+93) tmp = re ^ -2.0; elseif (im <= 2.5e+106) tmp = fma(re, re, -2.0); elseif (im <= 1.05e+152) tmp = Float64(-2.0 - Float64(re * re)); elseif (im <= 9.8e+179) tmp = fma(re, re, -2.0); else tmp = re ^ -2.0; end return tmp end
code[re_, im_] := If[LessEqual[im, 260.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.56e+93], N[Power[re, -2.0], $MachinePrecision], If[LessEqual[im, 2.5e+106], N[(re * re + -2.0), $MachinePrecision], If[LessEqual[im, 1.05e+152], N[(-2.0 - N[(re * re), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 9.8e+179], N[(re * re + -2.0), $MachinePrecision], N[Power[re, -2.0], $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 260:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.56 \cdot 10^{+93}:\\
\;\;\;\;{re}^{-2}\\
\mathbf{elif}\;im \leq 2.5 \cdot 10^{+106}:\\
\;\;\;\;\mathsf{fma}\left(re, re, -2\right)\\
\mathbf{elif}\;im \leq 1.05 \cdot 10^{+152}:\\
\;\;\;\;-2 - re \cdot re\\
\mathbf{elif}\;im \leq 9.8 \cdot 10^{+179}:\\
\;\;\;\;\mathsf{fma}\left(re, re, -2\right)\\
\mathbf{else}:\\
\;\;\;\;{re}^{-2}\\
\end{array}
\end{array}
if im < 260Initial program 100.0%
Taylor expanded in im around 0 58.6%
if 260 < im < 1.56000000000000004e93 or 9.7999999999999997e179 < im Initial program 100.0%
Taylor expanded in im around 0 57.2%
+-commutative57.2%
unpow257.2%
fma-define57.2%
Simplified57.2%
Taylor expanded in im around inf 57.2%
*-commutative57.2%
associate-*r*57.2%
Simplified57.2%
Taylor expanded in re around 0 3.5%
associate-*r*3.5%
+-commutative3.5%
*-commutative3.5%
*-commutative3.5%
associate-*l*3.5%
distribute-lft-out24.7%
Simplified24.7%
Applied egg-rr25.6%
if 1.56000000000000004e93 < im < 2.4999999999999999e106 or 1.0500000000000001e152 < im < 9.7999999999999997e179Initial program 100.0%
Taylor expanded in im around 0 58.8%
+-commutative58.8%
unpow258.8%
fma-define58.8%
Simplified58.8%
Taylor expanded in im around inf 58.8%
*-commutative58.8%
associate-*r*58.8%
Simplified58.8%
Taylor expanded in re around 0 0.0%
associate-*r*0.0%
+-commutative0.0%
*-commutative0.0%
*-commutative0.0%
associate-*l*0.0%
distribute-lft-out33.3%
Simplified33.3%
Applied egg-rr56.4%
if 2.4999999999999999e106 < im < 1.0500000000000001e152Initial program 100.0%
Taylor expanded in im around 0 8.9%
+-commutative8.9%
unpow28.9%
fma-define8.9%
Simplified8.9%
Taylor expanded in im around inf 8.9%
*-commutative8.9%
associate-*r*8.9%
Simplified8.9%
Taylor expanded in re around 0 48.8%
associate-*r*48.8%
+-commutative48.8%
*-commutative48.8%
*-commutative48.8%
associate-*l*48.8%
distribute-lft-out48.8%
Simplified48.8%
Applied egg-rr25.4%
Final simplification50.8%
(FPCore (re im)
:precision binary64
(if (<= im 250.0)
(cos re)
(if (<= im 8.4e+92)
(pow re -2.0)
(if (<= im 1.4e+153)
(+ 0.25 (* 0.25 (pow re 2.0)))
(* 0.5 (fma im im 2.0))))))
double code(double re, double im) {
double tmp;
if (im <= 250.0) {
tmp = cos(re);
} else if (im <= 8.4e+92) {
tmp = pow(re, -2.0);
} else if (im <= 1.4e+153) {
tmp = 0.25 + (0.25 * pow(re, 2.0));
} else {
tmp = 0.5 * fma(im, im, 2.0);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 250.0) tmp = cos(re); elseif (im <= 8.4e+92) tmp = re ^ -2.0; elseif (im <= 1.4e+153) tmp = Float64(0.25 + Float64(0.25 * (re ^ 2.0))); else tmp = Float64(0.5 * fma(im, im, 2.0)); end return tmp end
code[re_, im_] := If[LessEqual[im, 250.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 8.4e+92], N[Power[re, -2.0], $MachinePrecision], If[LessEqual[im, 1.4e+153], N[(0.25 + N[(0.25 * N[Power[re, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 250:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 8.4 \cdot 10^{+92}:\\
\;\;\;\;{re}^{-2}\\
\mathbf{elif}\;im \leq 1.4 \cdot 10^{+153}:\\
\;\;\;\;0.25 + 0.25 \cdot {re}^{2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{fma}\left(im, im, 2\right)\\
\end{array}
\end{array}
if im < 250Initial program 100.0%
Taylor expanded in im around 0 58.6%
if 250 < im < 8.39999999999999944e92Initial program 100.0%
Taylor expanded in im around 0 4.2%
+-commutative4.2%
unpow24.2%
fma-define4.2%
Simplified4.2%
Taylor expanded in im around inf 4.2%
*-commutative4.2%
associate-*r*4.2%
Simplified4.2%
Taylor expanded in re around 0 7.7%
associate-*r*7.7%
+-commutative7.7%
*-commutative7.7%
*-commutative7.7%
associate-*l*7.7%
distribute-lft-out7.7%
Simplified7.7%
Applied egg-rr31.4%
if 8.39999999999999944e92 < im < 1.39999999999999993e153Initial program 100.0%
Applied egg-rr2.2%
Taylor expanded in re around 0 30.8%
*-commutative30.8%
Simplified30.8%
if 1.39999999999999993e153 < im Initial program 100.0%
Taylor expanded in re around 0 93.5%
Taylor expanded in im around 0 93.5%
+-commutative93.5%
unpow293.5%
fma-define93.5%
Simplified93.5%
Final simplification58.8%
(FPCore (re im)
:precision binary64
(if (<= im 260.0)
(cos re)
(if (or (<= im 1.1e+116) (not (<= im 2.85e+165)))
(pow re -2.0)
(- -2.0 (* re re)))))
double code(double re, double im) {
double tmp;
if (im <= 260.0) {
tmp = cos(re);
} else if ((im <= 1.1e+116) || !(im <= 2.85e+165)) {
tmp = pow(re, -2.0);
} else {
tmp = -2.0 - (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 <= 260.0d0) then
tmp = cos(re)
else if ((im <= 1.1d+116) .or. (.not. (im <= 2.85d+165))) then
tmp = re ** (-2.0d0)
else
tmp = (-2.0d0) - (re * re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 260.0) {
tmp = Math.cos(re);
} else if ((im <= 1.1e+116) || !(im <= 2.85e+165)) {
tmp = Math.pow(re, -2.0);
} else {
tmp = -2.0 - (re * re);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 260.0: tmp = math.cos(re) elif (im <= 1.1e+116) or not (im <= 2.85e+165): tmp = math.pow(re, -2.0) else: tmp = -2.0 - (re * re) return tmp
function code(re, im) tmp = 0.0 if (im <= 260.0) tmp = cos(re); elseif ((im <= 1.1e+116) || !(im <= 2.85e+165)) tmp = re ^ -2.0; else tmp = Float64(-2.0 - Float64(re * re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 260.0) tmp = cos(re); elseif ((im <= 1.1e+116) || ~((im <= 2.85e+165))) tmp = re ^ -2.0; else tmp = -2.0 - (re * re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 260.0], N[Cos[re], $MachinePrecision], If[Or[LessEqual[im, 1.1e+116], N[Not[LessEqual[im, 2.85e+165]], $MachinePrecision]], N[Power[re, -2.0], $MachinePrecision], N[(-2.0 - N[(re * re), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 260:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.1 \cdot 10^{+116} \lor \neg \left(im \leq 2.85 \cdot 10^{+165}\right):\\
\;\;\;\;{re}^{-2}\\
\mathbf{else}:\\
\;\;\;\;-2 - re \cdot re\\
\end{array}
\end{array}
if im < 260Initial program 100.0%
Taylor expanded in im around 0 58.6%
if 260 < im < 1.1e116 or 2.85000000000000013e165 < im Initial program 100.0%
Taylor expanded in im around 0 56.7%
+-commutative56.7%
unpow256.7%
fma-define56.7%
Simplified56.7%
Taylor expanded in im around inf 56.7%
*-commutative56.7%
associate-*r*56.7%
Simplified56.7%
Taylor expanded in re around 0 3.1%
associate-*r*3.1%
+-commutative3.1%
*-commutative3.1%
*-commutative3.1%
associate-*l*3.1%
distribute-lft-out23.8%
Simplified23.8%
Applied egg-rr23.0%
if 1.1e116 < im < 2.85000000000000013e165Initial program 100.0%
Taylor expanded in im around 0 20.6%
+-commutative20.6%
unpow220.6%
fma-define20.6%
Simplified20.6%
Taylor expanded in im around inf 20.6%
*-commutative20.6%
associate-*r*20.6%
Simplified20.6%
Taylor expanded in re around 0 39.7%
associate-*r*39.7%
+-commutative39.7%
*-commutative39.7%
*-commutative39.7%
associate-*l*39.7%
distribute-lft-out52.2%
Simplified52.2%
Applied egg-rr20.7%
Final simplification48.9%
(FPCore (re im) :precision binary64 (if (<= im 3.8e+18) (cos re) (- -2.0 (* re re))))
double code(double re, double im) {
double tmp;
if (im <= 3.8e+18) {
tmp = cos(re);
} else {
tmp = -2.0 - (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 <= 3.8d+18) then
tmp = cos(re)
else
tmp = (-2.0d0) - (re * re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 3.8e+18) {
tmp = Math.cos(re);
} else {
tmp = -2.0 - (re * re);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 3.8e+18: tmp = math.cos(re) else: tmp = -2.0 - (re * re) return tmp
function code(re, im) tmp = 0.0 if (im <= 3.8e+18) tmp = cos(re); else tmp = Float64(-2.0 - Float64(re * re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 3.8e+18) tmp = cos(re); else tmp = -2.0 - (re * re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 3.8e+18], N[Cos[re], $MachinePrecision], N[(-2.0 - N[(re * re), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 3.8 \cdot 10^{+18}:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;-2 - re \cdot re\\
\end{array}
\end{array}
if im < 3.8e18Initial program 100.0%
Taylor expanded in im around 0 57.2%
if 3.8e18 < im Initial program 100.0%
Taylor expanded in im around 0 51.8%
+-commutative51.8%
unpow251.8%
fma-define51.8%
Simplified51.8%
Taylor expanded in im around inf 51.8%
*-commutative51.8%
associate-*r*51.8%
Simplified51.8%
Taylor expanded in re around 0 12.3%
associate-*r*12.3%
+-commutative12.3%
*-commutative12.3%
*-commutative12.3%
associate-*l*12.3%
distribute-lft-out32.6%
Simplified32.6%
Applied egg-rr8.7%
Final simplification45.1%
(FPCore (re im) :precision binary64 (if (<= im 4.8e+20) 1.0 (- -2.0 (* re re))))
double code(double re, double im) {
double tmp;
if (im <= 4.8e+20) {
tmp = 1.0;
} else {
tmp = -2.0 - (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 <= 4.8d+20) then
tmp = 1.0d0
else
tmp = (-2.0d0) - (re * re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 4.8e+20) {
tmp = 1.0;
} else {
tmp = -2.0 - (re * re);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 4.8e+20: tmp = 1.0 else: tmp = -2.0 - (re * re) return tmp
function code(re, im) tmp = 0.0 if (im <= 4.8e+20) tmp = 1.0; else tmp = Float64(-2.0 - Float64(re * re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 4.8e+20) tmp = 1.0; else tmp = -2.0 - (re * re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 4.8e+20], 1.0, N[(-2.0 - N[(re * re), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 4.8 \cdot 10^{+20}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;-2 - re \cdot re\\
\end{array}
\end{array}
if im < 4.8e20Initial program 100.0%
Applied egg-rr33.8%
+-inverses33.8%
+-rgt-identity33.8%
*-inverses33.8%
Simplified33.8%
if 4.8e20 < im Initial program 100.0%
Taylor expanded in im around 0 51.8%
+-commutative51.8%
unpow251.8%
fma-define51.8%
Simplified51.8%
Taylor expanded in im around inf 51.8%
*-commutative51.8%
associate-*r*51.8%
Simplified51.8%
Taylor expanded in re around 0 12.3%
associate-*r*12.3%
+-commutative12.3%
*-commutative12.3%
*-commutative12.3%
associate-*l*12.3%
distribute-lft-out32.6%
Simplified32.6%
Applied egg-rr8.7%
Final simplification27.5%
(FPCore (re im) :precision binary64 0.0)
double code(double re, double im) {
return 0.0;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.0d0
end function
public static double code(double re, double im) {
return 0.0;
}
def code(re, im): return 0.0
function code(re, im) return 0.0 end
function tmp = code(re, im) tmp = 0.0; end
code[re_, im_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 100.0%
Applied egg-rr2.2%
pow-base-12.2%
metadata-eval2.2%
Simplified2.2%
Final simplification2.2%
(FPCore (re im) :precision binary64 0.25)
double code(double re, double im) {
return 0.25;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.25d0
end function
public static double code(double re, double im) {
return 0.25;
}
def code(re, im): return 0.25
function code(re, im) return 0.25 end
function tmp = code(re, im) tmp = 0.25; end
code[re_, im_] := 0.25
\begin{array}{l}
\\
0.25
\end{array}
Initial program 100.0%
Applied egg-rr7.7%
Taylor expanded in re around 0 7.6%
Final simplification7.6%
(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-rr26.0%
+-inverses26.0%
+-rgt-identity26.0%
*-inverses26.0%
Simplified26.0%
Final simplification26.0%
herbie shell --seed 2024131
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))