
(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 10 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.024) (not (<= im 1.4e+154))) (* (cos re) (+ (* 0.5 (* im im)) 1.0)) (* 0.5 (+ (exp (- im)) (exp im)))))
double code(double re, double im) {
double tmp;
if ((im <= 0.024) || !(im <= 1.4e+154)) {
tmp = cos(re) * ((0.5 * (im * im)) + 1.0);
} else {
tmp = 0.5 * (exp(-im) + exp(im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((im <= 0.024d0) .or. (.not. (im <= 1.4d+154))) then
tmp = cos(re) * ((0.5d0 * (im * im)) + 1.0d0)
else
tmp = 0.5d0 * (exp(-im) + exp(im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((im <= 0.024) || !(im <= 1.4e+154)) {
tmp = Math.cos(re) * ((0.5 * (im * im)) + 1.0);
} else {
tmp = 0.5 * (Math.exp(-im) + Math.exp(im));
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= 0.024) or not (im <= 1.4e+154): tmp = math.cos(re) * ((0.5 * (im * im)) + 1.0) else: tmp = 0.5 * (math.exp(-im) + math.exp(im)) return tmp
function code(re, im) tmp = 0.0 if ((im <= 0.024) || !(im <= 1.4e+154)) tmp = Float64(cos(re) * Float64(Float64(0.5 * Float64(im * im)) + 1.0)); else tmp = Float64(0.5 * Float64(exp(Float64(-im)) + exp(im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((im <= 0.024) || ~((im <= 1.4e+154))) tmp = cos(re) * ((0.5 * (im * im)) + 1.0); else tmp = 0.5 * (exp(-im) + exp(im)); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, 0.024], N[Not[LessEqual[im, 1.4e+154]], $MachinePrecision]], N[(N[Cos[re], $MachinePrecision] * N[(N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.024 \lor \neg \left(im \leq 1.4 \cdot 10^{+154}\right):\\
\;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right) + 1\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\
\end{array}
\end{array}
if im < 0.024 or 1.4e154 < im Initial program 100.0%
Taylor expanded in im around 0 85.8%
associate-*r*85.8%
distribute-rgt1-in85.8%
*-commutative85.8%
Applied egg-rr85.8%
unpow225.3%
Applied egg-rr85.8%
if 0.024 < im < 1.4e154Initial program 100.0%
Taylor expanded in re around 0 83.3%
Final simplification85.5%
(FPCore (re im)
:precision binary64
(if (<= im 0.027)
(+ (cos re) (* 0.5 (* (cos re) (* im im))))
(if (<= im 1.4e+154)
(* 0.5 (+ (exp (- im)) (exp im)))
(* (cos re) (+ (* 0.5 (* im im)) 1.0)))))
double code(double re, double im) {
double tmp;
if (im <= 0.027) {
tmp = cos(re) + (0.5 * (cos(re) * (im * im)));
} else if (im <= 1.4e+154) {
tmp = 0.5 * (exp(-im) + exp(im));
} else {
tmp = cos(re) * ((0.5 * (im * im)) + 1.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.027d0) then
tmp = cos(re) + (0.5d0 * (cos(re) * (im * im)))
else if (im <= 1.4d+154) then
tmp = 0.5d0 * (exp(-im) + exp(im))
else
tmp = cos(re) * ((0.5d0 * (im * im)) + 1.0d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 0.027) {
tmp = Math.cos(re) + (0.5 * (Math.cos(re) * (im * im)));
} else if (im <= 1.4e+154) {
tmp = 0.5 * (Math.exp(-im) + Math.exp(im));
} else {
tmp = Math.cos(re) * ((0.5 * (im * im)) + 1.0);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 0.027: tmp = math.cos(re) + (0.5 * (math.cos(re) * (im * im))) elif im <= 1.4e+154: tmp = 0.5 * (math.exp(-im) + math.exp(im)) else: tmp = math.cos(re) * ((0.5 * (im * im)) + 1.0) return tmp
function code(re, im) tmp = 0.0 if (im <= 0.027) tmp = Float64(cos(re) + Float64(0.5 * Float64(cos(re) * Float64(im * im)))); elseif (im <= 1.4e+154) tmp = Float64(0.5 * Float64(exp(Float64(-im)) + exp(im))); else tmp = Float64(cos(re) * Float64(Float64(0.5 * Float64(im * im)) + 1.0)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 0.027) tmp = cos(re) + (0.5 * (cos(re) * (im * im))); elseif (im <= 1.4e+154) tmp = 0.5 * (exp(-im) + exp(im)); else tmp = cos(re) * ((0.5 * (im * im)) + 1.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 0.027], N[(N[Cos[re], $MachinePrecision] + N[(0.5 * N[(N[Cos[re], $MachinePrecision] * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.4e+154], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[re], $MachinePrecision] * N[(N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.027:\\
\;\;\;\;\cos re + 0.5 \cdot \left(\cos re \cdot \left(im \cdot im\right)\right)\\
\mathbf{elif}\;im \leq 1.4 \cdot 10^{+154}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\
\mathbf{else}:\\
\;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right) + 1\right)\\
\end{array}
\end{array}
if im < 0.0269999999999999997Initial program 100.0%
Taylor expanded in im around 0 83.0%
unpow215.5%
Applied egg-rr83.0%
if 0.0269999999999999997 < im < 1.4e154Initial program 100.0%
Taylor expanded in re around 0 83.3%
if 1.4e154 < im Initial program 100.0%
Taylor expanded in im around 0 100.0%
associate-*r*100.0%
distribute-rgt1-in100.0%
*-commutative100.0%
Applied egg-rr100.0%
unpow275.7%
Applied egg-rr100.0%
Final simplification85.5%
(FPCore (re im) :precision binary64 (if (or (<= im 8.4e+74) (not (<= im 1.4e+154))) (* (cos re) (+ (* 0.5 (* im im)) 1.0)) (* 0.5 (sqrt (pow im 4.0)))))
double code(double re, double im) {
double tmp;
if ((im <= 8.4e+74) || !(im <= 1.4e+154)) {
tmp = cos(re) * ((0.5 * (im * im)) + 1.0);
} else {
tmp = 0.5 * sqrt(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 <= 8.4d+74) .or. (.not. (im <= 1.4d+154))) then
tmp = cos(re) * ((0.5d0 * (im * im)) + 1.0d0)
else
tmp = 0.5d0 * sqrt((im ** 4.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((im <= 8.4e+74) || !(im <= 1.4e+154)) {
tmp = Math.cos(re) * ((0.5 * (im * im)) + 1.0);
} else {
tmp = 0.5 * Math.sqrt(Math.pow(im, 4.0));
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= 8.4e+74) or not (im <= 1.4e+154): tmp = math.cos(re) * ((0.5 * (im * im)) + 1.0) else: tmp = 0.5 * math.sqrt(math.pow(im, 4.0)) return tmp
function code(re, im) tmp = 0.0 if ((im <= 8.4e+74) || !(im <= 1.4e+154)) tmp = Float64(cos(re) * Float64(Float64(0.5 * Float64(im * im)) + 1.0)); else tmp = Float64(0.5 * sqrt((im ^ 4.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((im <= 8.4e+74) || ~((im <= 1.4e+154))) tmp = cos(re) * ((0.5 * (im * im)) + 1.0); else tmp = 0.5 * sqrt((im ^ 4.0)); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, 8.4e+74], N[Not[LessEqual[im, 1.4e+154]], $MachinePrecision]], N[(N[Cos[re], $MachinePrecision] * N[(N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[Power[im, 4.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 8.4 \cdot 10^{+74} \lor \neg \left(im \leq 1.4 \cdot 10^{+154}\right):\\
\;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right) + 1\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{{im}^{4}}\\
\end{array}
\end{array}
if im < 8.3999999999999995e74 or 1.4e154 < im Initial program 100.0%
Taylor expanded in im around 0 82.0%
associate-*r*82.0%
distribute-rgt1-in82.0%
*-commutative82.0%
Applied egg-rr82.0%
unpow224.3%
Applied egg-rr82.0%
if 8.3999999999999995e74 < im < 1.4e154Initial program 100.0%
Taylor expanded in im around 0 6.0%
Taylor expanded in im around inf 6.0%
*-commutative6.0%
associate-*r*6.0%
*-commutative6.0%
Simplified6.0%
Taylor expanded in re around 0 5.4%
add-sqr-sqrt5.4%
sqrt-unprod79.4%
pow-prod-up79.4%
metadata-eval79.4%
Applied egg-rr79.4%
Final simplification81.8%
(FPCore (re im) :precision binary64 (if (or (<= im 7.5e+22) (not (<= im 6.6e+145))) (* (cos re) (+ (* 0.5 (* im im)) 1.0)) (* (* im im) (+ 0.5 (* (pow re 2.0) -0.25)))))
double code(double re, double im) {
double tmp;
if ((im <= 7.5e+22) || !(im <= 6.6e+145)) {
tmp = cos(re) * ((0.5 * (im * im)) + 1.0);
} else {
tmp = (im * im) * (0.5 + (pow(re, 2.0) * -0.25));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((im <= 7.5d+22) .or. (.not. (im <= 6.6d+145))) then
tmp = cos(re) * ((0.5d0 * (im * im)) + 1.0d0)
else
tmp = (im * im) * (0.5d0 + ((re ** 2.0d0) * (-0.25d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((im <= 7.5e+22) || !(im <= 6.6e+145)) {
tmp = Math.cos(re) * ((0.5 * (im * im)) + 1.0);
} else {
tmp = (im * im) * (0.5 + (Math.pow(re, 2.0) * -0.25));
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= 7.5e+22) or not (im <= 6.6e+145): tmp = math.cos(re) * ((0.5 * (im * im)) + 1.0) else: tmp = (im * im) * (0.5 + (math.pow(re, 2.0) * -0.25)) return tmp
function code(re, im) tmp = 0.0 if ((im <= 7.5e+22) || !(im <= 6.6e+145)) tmp = Float64(cos(re) * Float64(Float64(0.5 * Float64(im * im)) + 1.0)); else tmp = Float64(Float64(im * im) * Float64(0.5 + Float64((re ^ 2.0) * -0.25))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((im <= 7.5e+22) || ~((im <= 6.6e+145))) tmp = cos(re) * ((0.5 * (im * im)) + 1.0); else tmp = (im * im) * (0.5 + ((re ^ 2.0) * -0.25)); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, 7.5e+22], N[Not[LessEqual[im, 6.6e+145]], $MachinePrecision]], N[(N[Cos[re], $MachinePrecision] * N[(N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(im * im), $MachinePrecision] * N[(0.5 + N[(N[Power[re, 2.0], $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 7.5 \cdot 10^{+22} \lor \neg \left(im \leq 6.6 \cdot 10^{+145}\right):\\
\;\;\;\;\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right) + 1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(im \cdot im\right) \cdot \left(0.5 + {re}^{2} \cdot -0.25\right)\\
\end{array}
\end{array}
if im < 7.5000000000000002e22 or 6.60000000000000054e145 < im Initial program 100.0%
Taylor expanded in im around 0 84.0%
associate-*r*84.0%
distribute-rgt1-in84.0%
*-commutative84.0%
Applied egg-rr84.0%
unpow224.9%
Applied egg-rr84.0%
if 7.5000000000000002e22 < im < 6.60000000000000054e145Initial program 100.0%
Taylor expanded in im around 0 5.3%
Taylor expanded in im around inf 5.3%
*-commutative5.3%
associate-*r*5.3%
*-commutative5.3%
Simplified5.3%
Taylor expanded in re around 0 23.3%
*-commutative23.3%
associate-*l*23.3%
*-commutative23.3%
distribute-lft-out23.3%
Simplified23.3%
unpow24.4%
Applied egg-rr23.3%
Final simplification78.1%
(FPCore (re im) :precision binary64 (if (<= im 0.0255) (cos re) (+ 1.0 (* 0.5 (pow im 2.0)))))
double code(double re, double im) {
double tmp;
if (im <= 0.0255) {
tmp = cos(re);
} else {
tmp = 1.0 + (0.5 * 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.0255d0) then
tmp = cos(re)
else
tmp = 1.0d0 + (0.5d0 * (im ** 2.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 0.0255) {
tmp = Math.cos(re);
} else {
tmp = 1.0 + (0.5 * Math.pow(im, 2.0));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 0.0255: tmp = math.cos(re) else: tmp = 1.0 + (0.5 * math.pow(im, 2.0)) return tmp
function code(re, im) tmp = 0.0 if (im <= 0.0255) tmp = cos(re); else tmp = Float64(1.0 + Float64(0.5 * (im ^ 2.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 0.0255) tmp = cos(re); else tmp = 1.0 + (0.5 * (im ^ 2.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 0.0255], N[Cos[re], $MachinePrecision], N[(1.0 + N[(0.5 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.0255:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;1 + 0.5 \cdot {im}^{2}\\
\end{array}
\end{array}
if im < 0.0254999999999999984Initial program 100.0%
Taylor expanded in im around 0 66.5%
if 0.0254999999999999984 < im Initial program 100.0%
Taylor expanded in im around 0 57.5%
Taylor expanded in re around 0 43.8%
Final simplification60.5%
(FPCore (re im) :precision binary64 (* (cos re) (+ (* 0.5 (* im im)) 1.0)))
double code(double re, double im) {
return cos(re) * ((0.5 * (im * im)) + 1.0);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = cos(re) * ((0.5d0 * (im * im)) + 1.0d0)
end function
public static double code(double re, double im) {
return Math.cos(re) * ((0.5 * (im * im)) + 1.0);
}
def code(re, im): return math.cos(re) * ((0.5 * (im * im)) + 1.0)
function code(re, im) return Float64(cos(re) * Float64(Float64(0.5 * Float64(im * im)) + 1.0)) end
function tmp = code(re, im) tmp = cos(re) * ((0.5 * (im * im)) + 1.0); end
code[re_, im_] := N[(N[Cos[re], $MachinePrecision] * N[(N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos re \cdot \left(0.5 \cdot \left(im \cdot im\right) + 1\right)
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 76.3%
associate-*r*76.3%
distribute-rgt1-in76.3%
*-commutative76.3%
Applied egg-rr76.3%
unpow222.9%
Applied egg-rr76.3%
Final simplification76.3%
(FPCore (re im) :precision binary64 (if (<= im 3.6e+31) (cos re) (* 0.5 (* im im))))
double code(double re, double im) {
double tmp;
if (im <= 3.6e+31) {
tmp = cos(re);
} else {
tmp = 0.5 * (im * im);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 3.6d+31) then
tmp = cos(re)
else
tmp = 0.5d0 * (im * im)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 3.6e+31) {
tmp = Math.cos(re);
} else {
tmp = 0.5 * (im * im);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 3.6e+31: tmp = math.cos(re) else: tmp = 0.5 * (im * im) return tmp
function code(re, im) tmp = 0.0 if (im <= 3.6e+31) tmp = cos(re); else tmp = Float64(0.5 * Float64(im * im)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 3.6e+31) tmp = cos(re); else tmp = 0.5 * (im * im); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 3.6e+31], N[Cos[re], $MachinePrecision], N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 3.6 \cdot 10^{+31}:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot im\right)\\
\end{array}
\end{array}
if im < 3.59999999999999996e31Initial program 100.0%
Taylor expanded in im around 0 64.5%
if 3.59999999999999996e31 < im Initial program 100.0%
Taylor expanded in im around 0 62.9%
Taylor expanded in im around inf 62.9%
*-commutative62.9%
associate-*r*62.9%
*-commutative62.9%
Simplified62.9%
Taylor expanded in re around 0 47.8%
unpow247.8%
Applied egg-rr47.8%
Final simplification60.6%
(FPCore (re im) :precision binary64 (if (<= im 0.71) 0.25 (* 0.5 (* im im))))
double code(double re, double im) {
double tmp;
if (im <= 0.71) {
tmp = 0.25;
} else {
tmp = 0.5 * (im * 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.71d0) then
tmp = 0.25d0
else
tmp = 0.5d0 * (im * im)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 0.71) {
tmp = 0.25;
} else {
tmp = 0.5 * (im * im);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 0.71: tmp = 0.25 else: tmp = 0.5 * (im * im) return tmp
function code(re, im) tmp = 0.0 if (im <= 0.71) tmp = 0.25; else tmp = Float64(0.5 * Float64(im * im)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 0.71) tmp = 0.25; else tmp = 0.5 * (im * im); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 0.71], 0.25, N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 0.71:\\
\;\;\;\;0.25\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot im\right)\\
\end{array}
\end{array}
if im < 0.70999999999999996Initial program 100.0%
Applied egg-rr10.1%
Taylor expanded in re around 0 10.2%
if 0.70999999999999996 < im Initial program 100.0%
Taylor expanded in im around 0 57.5%
Taylor expanded in im around inf 57.5%
*-commutative57.5%
associate-*r*57.5%
*-commutative57.5%
Simplified57.5%
Taylor expanded in re around 0 43.8%
unpow243.8%
Applied egg-rr43.8%
Final simplification19.0%
(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.1%
Taylor expanded in re around 0 8.2%
Final simplification8.2%
herbie shell --seed 2024020
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))