
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp(-im) + exp(im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * (exp(-im) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp(-im) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp(-im) + exp(im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * (exp(-im) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp(-im) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
\end{array}
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (exp(-im) + exp(im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * (exp(-im) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (Math.exp(-im) + Math.exp(im));
}
def code(re, im): return (0.5 * math.cos(re)) * (math.exp(-im) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(exp(Float64(-im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (exp(-im) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(e^{-im} + e^{im}\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (re im)
:precision binary64
(if (<= im 8000.0)
(cos re)
(if (<= im 6.8e+69)
(+ 0.25 (pow re -2.0))
(* 0.041666666666666664 (* (cos re) (pow im 4.0))))))
double code(double re, double im) {
double tmp;
if (im <= 8000.0) {
tmp = cos(re);
} else if (im <= 6.8e+69) {
tmp = 0.25 + pow(re, -2.0);
} else {
tmp = 0.041666666666666664 * (cos(re) * pow(im, 4.0));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 8000.0d0) then
tmp = cos(re)
else if (im <= 6.8d+69) then
tmp = 0.25d0 + (re ** (-2.0d0))
else
tmp = 0.041666666666666664d0 * (cos(re) * (im ** 4.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 8000.0) {
tmp = Math.cos(re);
} else if (im <= 6.8e+69) {
tmp = 0.25 + Math.pow(re, -2.0);
} else {
tmp = 0.041666666666666664 * (Math.cos(re) * Math.pow(im, 4.0));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 8000.0: tmp = math.cos(re) elif im <= 6.8e+69: tmp = 0.25 + math.pow(re, -2.0) else: tmp = 0.041666666666666664 * (math.cos(re) * math.pow(im, 4.0)) return tmp
function code(re, im) tmp = 0.0 if (im <= 8000.0) tmp = cos(re); elseif (im <= 6.8e+69) tmp = Float64(0.25 + (re ^ -2.0)); else tmp = Float64(0.041666666666666664 * Float64(cos(re) * (im ^ 4.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 8000.0) tmp = cos(re); elseif (im <= 6.8e+69) tmp = 0.25 + (re ^ -2.0); else tmp = 0.041666666666666664 * (cos(re) * (im ^ 4.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 8000.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 6.8e+69], N[(0.25 + N[Power[re, -2.0], $MachinePrecision]), $MachinePrecision], N[(0.041666666666666664 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 8000:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 6.8 \cdot 10^{+69}:\\
\;\;\;\;0.25 + {re}^{-2}\\
\mathbf{else}:\\
\;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\
\end{array}
\end{array}
if im < 8e3Initial program 100.0%
Taylor expanded in im around 0 68.8%
if 8e3 < im < 6.79999999999999973e69Initial program 100.0%
Applied egg-rr2.3%
Taylor expanded in re around 0 3.1%
*-commutative3.1%
Simplified3.1%
Applied egg-rr19.0%
if 6.79999999999999973e69 < im Initial program 100.0%
Taylor expanded in im around 0 97.9%
+-commutative97.9%
fma-define97.9%
associate-*r*97.9%
distribute-rgt-out97.9%
*-commutative97.9%
Simplified97.9%
Taylor expanded in im around inf 97.9%
Final simplification71.5%
(FPCore (re im)
:precision binary64
(if (<= im 0.0019)
(cos re)
(if (<= im 1.16e+77)
(* 0.5 (+ (exp (- im)) (exp im)))
(* 0.041666666666666664 (* (cos re) (pow im 4.0))))))
double code(double re, double im) {
double tmp;
if (im <= 0.0019) {
tmp = cos(re);
} else if (im <= 1.16e+77) {
tmp = 0.5 * (exp(-im) + exp(im));
} else {
tmp = 0.041666666666666664 * (cos(re) * pow(im, 4.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.0019d0) then
tmp = cos(re)
else if (im <= 1.16d+77) then
tmp = 0.5d0 * (exp(-im) + exp(im))
else
tmp = 0.041666666666666664d0 * (cos(re) * (im ** 4.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 0.0019) {
tmp = Math.cos(re);
} else if (im <= 1.16e+77) {
tmp = 0.5 * (Math.exp(-im) + Math.exp(im));
} else {
tmp = 0.041666666666666664 * (Math.cos(re) * Math.pow(im, 4.0));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 0.0019: tmp = math.cos(re) elif im <= 1.16e+77: tmp = 0.5 * (math.exp(-im) + math.exp(im)) else: tmp = 0.041666666666666664 * (math.cos(re) * math.pow(im, 4.0)) return tmp
function code(re, im) tmp = 0.0 if (im <= 0.0019) tmp = cos(re); elseif (im <= 1.16e+77) tmp = Float64(0.5 * Float64(exp(Float64(-im)) + exp(im))); else tmp = Float64(0.041666666666666664 * Float64(cos(re) * (im ^ 4.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 0.0019) tmp = cos(re); elseif (im <= 1.16e+77) tmp = 0.5 * (exp(-im) + exp(im)); else tmp = 0.041666666666666664 * (cos(re) * (im ^ 4.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 0.0019], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.16e+77], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.041666666666666664 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.0019:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.16 \cdot 10^{+77}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\
\mathbf{else}:\\
\;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\
\end{array}
\end{array}
if im < 0.0019Initial program 100.0%
Taylor expanded in im around 0 69.4%
if 0.0019 < im < 1.1600000000000001e77Initial program 99.9%
Taylor expanded in re around 0 73.2%
if 1.1600000000000001e77 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
+-commutative100.0%
fma-define100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
Final simplification74.8%
(FPCore (re im)
:precision binary64
(if (<= im 0.035)
(* (* 0.5 (cos re)) (fma im im 2.0))
(if (<= im 1.16e+77)
(* 0.5 (+ (exp (- im)) (exp im)))
(* 0.041666666666666664 (* (cos re) (pow im 4.0))))))
double code(double re, double im) {
double tmp;
if (im <= 0.035) {
tmp = (0.5 * cos(re)) * fma(im, im, 2.0);
} else if (im <= 1.16e+77) {
tmp = 0.5 * (exp(-im) + exp(im));
} else {
tmp = 0.041666666666666664 * (cos(re) * pow(im, 4.0));
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 0.035) tmp = Float64(Float64(0.5 * cos(re)) * fma(im, im, 2.0)); elseif (im <= 1.16e+77) tmp = Float64(0.5 * Float64(exp(Float64(-im)) + exp(im))); else tmp = Float64(0.041666666666666664 * Float64(cos(re) * (im ^ 4.0))); end return tmp end
code[re_, im_] := If[LessEqual[im, 0.035], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.16e+77], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.041666666666666664 * N[(N[Cos[re], $MachinePrecision] * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.035:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \mathsf{fma}\left(im, im, 2\right)\\
\mathbf{elif}\;im \leq 1.16 \cdot 10^{+77}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\
\mathbf{else}:\\
\;\;\;\;0.041666666666666664 \cdot \left(\cos re \cdot {im}^{4}\right)\\
\end{array}
\end{array}
if im < 0.035000000000000003Initial program 100.0%
Taylor expanded in im around 0 83.7%
+-commutative83.7%
unpow283.7%
fma-define83.7%
Simplified83.7%
if 0.035000000000000003 < im < 1.1600000000000001e77Initial program 99.9%
Taylor expanded in re around 0 73.2%
if 1.1600000000000001e77 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
+-commutative100.0%
fma-define100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
Final simplification85.8%
(FPCore (re im)
:precision binary64
(if (<= im 8000.0)
(cos re)
(if (<= im 1.8e+95)
(+ 0.25 (pow re -2.0))
(* (fma im im 2.0) (+ 0.5 (* (* re re) -0.25))))))
double code(double re, double im) {
double tmp;
if (im <= 8000.0) {
tmp = cos(re);
} else if (im <= 1.8e+95) {
tmp = 0.25 + pow(re, -2.0);
} else {
tmp = fma(im, im, 2.0) * (0.5 + ((re * re) * -0.25));
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 8000.0) tmp = cos(re); elseif (im <= 1.8e+95) tmp = Float64(0.25 + (re ^ -2.0)); else tmp = Float64(fma(im, im, 2.0) * Float64(0.5 + Float64(Float64(re * re) * -0.25))); end return tmp end
code[re_, im_] := If[LessEqual[im, 8000.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.8e+95], N[(0.25 + N[Power[re, -2.0], $MachinePrecision]), $MachinePrecision], N[(N[(im * im + 2.0), $MachinePrecision] * N[(0.5 + N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 8000:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.8 \cdot 10^{+95}:\\
\;\;\;\;0.25 + {re}^{-2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(im, im, 2\right) \cdot \left(0.5 + \left(re \cdot re\right) \cdot -0.25\right)\\
\end{array}
\end{array}
if im < 8e3Initial program 100.0%
Taylor expanded in im around 0 68.8%
if 8e3 < im < 1.79999999999999989e95Initial program 100.0%
Applied egg-rr2.3%
Taylor expanded in re around 0 3.1%
*-commutative3.1%
Simplified3.1%
Applied egg-rr16.0%
if 1.79999999999999989e95 < im Initial program 100.0%
Taylor expanded in im around 0 73.0%
+-commutative73.0%
unpow273.0%
fma-define73.0%
Simplified73.0%
Taylor expanded in re around 0 13.3%
associate-*r*13.3%
distribute-rgt-out64.5%
+-commutative64.5%
unpow264.5%
fma-undefine64.5%
*-commutative64.5%
Simplified64.5%
Applied egg-rr64.5%
Final simplification65.0%
(FPCore (re im)
:precision binary64
(if (<= im 8000.0)
(cos re)
(if (<= im 2e+95)
(+ 0.25 (pow re -2.0))
(* (fma im im 2.0) (+ 0.5 (* re -0.25))))))
double code(double re, double im) {
double tmp;
if (im <= 8000.0) {
tmp = cos(re);
} else if (im <= 2e+95) {
tmp = 0.25 + pow(re, -2.0);
} else {
tmp = fma(im, im, 2.0) * (0.5 + (re * -0.25));
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 8000.0) tmp = cos(re); elseif (im <= 2e+95) tmp = Float64(0.25 + (re ^ -2.0)); else tmp = Float64(fma(im, im, 2.0) * Float64(0.5 + Float64(re * -0.25))); end return tmp end
code[re_, im_] := If[LessEqual[im, 8000.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 2e+95], N[(0.25 + N[Power[re, -2.0], $MachinePrecision]), $MachinePrecision], N[(N[(im * im + 2.0), $MachinePrecision] * N[(0.5 + N[(re * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 8000:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 2 \cdot 10^{+95}:\\
\;\;\;\;0.25 + {re}^{-2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(im, im, 2\right) \cdot \left(0.5 + re \cdot -0.25\right)\\
\end{array}
\end{array}
if im < 8e3Initial program 100.0%
Taylor expanded in im around 0 68.8%
if 8e3 < im < 2.00000000000000004e95Initial program 100.0%
Applied egg-rr2.3%
Taylor expanded in re around 0 3.1%
*-commutative3.1%
Simplified3.1%
Applied egg-rr16.0%
if 2.00000000000000004e95 < im Initial program 100.0%
Taylor expanded in im around 0 73.0%
+-commutative73.0%
unpow273.0%
fma-define73.0%
Simplified73.0%
Taylor expanded in re around 0 13.3%
associate-*r*13.3%
distribute-rgt-out64.5%
+-commutative64.5%
unpow264.5%
fma-undefine64.5%
*-commutative64.5%
Simplified64.5%
Applied egg-rr76.4%
rem-log-exp74.2%
Simplified74.2%
Final simplification66.6%
(FPCore (re im) :precision binary64 (if (<= im 8000.0) (cos re) (if (<= im 1.35e+154) (+ 0.25 (pow re -2.0)) (* 0.5 (fma im im 2.0)))))
double code(double re, double im) {
double tmp;
if (im <= 8000.0) {
tmp = cos(re);
} else if (im <= 1.35e+154) {
tmp = 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 <= 8000.0) tmp = cos(re); elseif (im <= 1.35e+154) tmp = 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, 8000.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(0.25 + N[Power[re, -2.0], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 8000:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;0.25 + {re}^{-2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \mathsf{fma}\left(im, im, 2\right)\\
\end{array}
\end{array}
if im < 8e3Initial program 100.0%
Taylor expanded in im around 0 68.8%
if 8e3 < im < 1.35000000000000003e154Initial program 100.0%
Applied egg-rr2.1%
Taylor expanded in re around 0 6.2%
*-commutative6.2%
Simplified6.2%
Applied egg-rr17.0%
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 re around 0 72.4%
+-commutative72.4%
unpow272.4%
fma-undefine72.4%
Simplified72.4%
Final simplification63.8%
(FPCore (re im) :precision binary64 (if (<= im 8000.0) (cos re) (+ 0.25 (pow re -2.0))))
double code(double re, double im) {
double tmp;
if (im <= 8000.0) {
tmp = cos(re);
} else {
tmp = 0.25 + pow(re, -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 <= 8000.0d0) then
tmp = cos(re)
else
tmp = 0.25d0 + (re ** (-2.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 8000.0) {
tmp = Math.cos(re);
} else {
tmp = 0.25 + Math.pow(re, -2.0);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 8000.0: tmp = math.cos(re) else: tmp = 0.25 + math.pow(re, -2.0) return tmp
function code(re, im) tmp = 0.0 if (im <= 8000.0) tmp = cos(re); else tmp = Float64(0.25 + (re ^ -2.0)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 8000.0) tmp = cos(re); else tmp = 0.25 + (re ^ -2.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 8000.0], N[Cos[re], $MachinePrecision], N[(0.25 + N[Power[re, -2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 8000:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;0.25 + {re}^{-2}\\
\end{array}
\end{array}
if im < 8e3Initial program 100.0%
Taylor expanded in im around 0 68.8%
if 8e3 < im Initial program 100.0%
Applied egg-rr2.3%
Taylor expanded in re around 0 7.9%
*-commutative7.9%
Simplified7.9%
Applied egg-rr18.5%
Final simplification57.8%
(FPCore (re im) :precision binary64 (if (<= im 320000000.0) (cos re) (+ 0.25 (* 0.25 (* re re)))))
double code(double re, double im) {
double tmp;
if (im <= 320000000.0) {
tmp = cos(re);
} else {
tmp = 0.25 + (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 <= 320000000.0d0) then
tmp = cos(re)
else
tmp = 0.25d0 + (0.25d0 * (re * re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 320000000.0) {
tmp = Math.cos(re);
} else {
tmp = 0.25 + (0.25 * (re * re));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 320000000.0: tmp = math.cos(re) else: tmp = 0.25 + (0.25 * (re * re)) return tmp
function code(re, im) tmp = 0.0 if (im <= 320000000.0) tmp = cos(re); else tmp = Float64(0.25 + Float64(0.25 * Float64(re * re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 320000000.0) tmp = cos(re); else tmp = 0.25 + (0.25 * (re * re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 320000000.0], N[Cos[re], $MachinePrecision], N[(0.25 + N[(0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 320000000:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;0.25 + 0.25 \cdot \left(re \cdot re\right)\\
\end{array}
\end{array}
if im < 3.2e8Initial program 100.0%
Taylor expanded in im around 0 68.5%
if 3.2e8 < im Initial program 100.0%
Applied egg-rr2.3%
Taylor expanded in re around 0 8.0%
*-commutative8.0%
Simplified8.0%
Applied egg-rr8.0%
Final simplification55.5%
(FPCore (re im) :precision binary64 (if (<= im 900000000.0) 1.0 (+ 0.25 (* 0.25 (* re re)))))
double code(double re, double im) {
double tmp;
if (im <= 900000000.0) {
tmp = 1.0;
} else {
tmp = 0.25 + (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 <= 900000000.0d0) then
tmp = 1.0d0
else
tmp = 0.25d0 + (0.25d0 * (re * re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 900000000.0) {
tmp = 1.0;
} else {
tmp = 0.25 + (0.25 * (re * re));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 900000000.0: tmp = 1.0 else: tmp = 0.25 + (0.25 * (re * re)) return tmp
function code(re, im) tmp = 0.0 if (im <= 900000000.0) tmp = 1.0; else tmp = Float64(0.25 + Float64(0.25 * Float64(re * re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 900000000.0) tmp = 1.0; else tmp = 0.25 + (0.25 * (re * re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 900000000.0], 1.0, N[(0.25 + N[(0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 900000000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.25 + 0.25 \cdot \left(re \cdot re\right)\\
\end{array}
\end{array}
if im < 9e8Initial program 100.0%
Applied egg-rr39.8%
+-inverses39.8%
+-rgt-identity39.8%
*-inverses39.8%
Simplified39.8%
if 9e8 < im Initial program 100.0%
Applied egg-rr2.3%
Taylor expanded in re around 0 8.0%
*-commutative8.0%
Simplified8.0%
Applied egg-rr8.0%
Final simplification33.0%
(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.4%
pow-base-12.4%
metadata-eval2.4%
Simplified2.4%
Final simplification2.4%
(FPCore (re im) :precision binary64 0.25)
double code(double re, double im) {
return 0.25;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.25d0
end function
public static double code(double re, double im) {
return 0.25;
}
def code(re, im): return 0.25
function code(re, im) return 0.25 end
function tmp = code(re, im) tmp = 0.25; end
code[re_, im_] := 0.25
\begin{array}{l}
\\
0.25
\end{array}
Initial program 100.0%
Applied egg-rr8.5%
Taylor expanded in re around 0 8.7%
Final simplification8.7%
(FPCore (re im) :precision binary64 1.0)
double code(double re, double im) {
return 1.0;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 1.0d0
end function
public static double code(double re, double im) {
return 1.0;
}
def code(re, im): return 1.0
function code(re, im) return 1.0 end
function tmp = code(re, im) tmp = 1.0; end
code[re_, im_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 100.0%
Applied egg-rr31.7%
+-inverses31.7%
+-rgt-identity31.7%
*-inverses31.7%
Simplified31.7%
Final simplification31.7%
herbie shell --seed 2024110
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))