
(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 16 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 (<= (cos re) 0.996)
(*
(* 0.5 (cos re))
(+ 2.0 (+ (* im im) (* 0.08333333333333333 (pow im 4.0)))))
(* 0.5 (+ (exp (- im)) (exp im)))))
double code(double re, double im) {
double tmp;
if (cos(re) <= 0.996) {
tmp = (0.5 * cos(re)) * (2.0 + ((im * im) + (0.08333333333333333 * pow(im, 4.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 (cos(re) <= 0.996d0) then
tmp = (0.5d0 * cos(re)) * (2.0d0 + ((im * im) + (0.08333333333333333d0 * (im ** 4.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 (Math.cos(re) <= 0.996) {
tmp = (0.5 * Math.cos(re)) * (2.0 + ((im * im) + (0.08333333333333333 * Math.pow(im, 4.0))));
} else {
tmp = 0.5 * (Math.exp(-im) + Math.exp(im));
}
return tmp;
}
def code(re, im): tmp = 0 if math.cos(re) <= 0.996: tmp = (0.5 * math.cos(re)) * (2.0 + ((im * im) + (0.08333333333333333 * math.pow(im, 4.0)))) else: tmp = 0.5 * (math.exp(-im) + math.exp(im)) return tmp
function code(re, im) tmp = 0.0 if (cos(re) <= 0.996) tmp = Float64(Float64(0.5 * cos(re)) * Float64(2.0 + Float64(Float64(im * im) + Float64(0.08333333333333333 * (im ^ 4.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 (cos(re) <= 0.996) tmp = (0.5 * cos(re)) * (2.0 + ((im * im) + (0.08333333333333333 * (im ^ 4.0)))); else tmp = 0.5 * (exp(-im) + exp(im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Cos[re], $MachinePrecision], 0.996], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(2.0 + N[(N[(im * im), $MachinePrecision] + N[(0.08333333333333333 * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos re \leq 0.996:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(2 + \left(im \cdot im + 0.08333333333333333 \cdot {im}^{4}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\
\end{array}
\end{array}
if (cos.f64 re) < 0.996Initial program 100.0%
Taylor expanded in im around 0 89.6%
unpow289.6%
Simplified89.6%
if 0.996 < (cos.f64 re) Initial program 100.0%
Taylor expanded in re around 0 99.0%
Final simplification94.2%
(FPCore (re im)
:precision binary64
(if (<= (cos re) 0.996)
(*
(* 0.5 (cos re))
(+ 2.0 (* (* im im) (+ 1.0 (* im (* im 0.08333333333333333))))))
(* 0.5 (+ (exp (- im)) (exp im)))))
double code(double re, double im) {
double tmp;
if (cos(re) <= 0.996) {
tmp = (0.5 * cos(re)) * (2.0 + ((im * im) * (1.0 + (im * (im * 0.08333333333333333)))));
} 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 (cos(re) <= 0.996d0) then
tmp = (0.5d0 * cos(re)) * (2.0d0 + ((im * im) * (1.0d0 + (im * (im * 0.08333333333333333d0)))))
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 (Math.cos(re) <= 0.996) {
tmp = (0.5 * Math.cos(re)) * (2.0 + ((im * im) * (1.0 + (im * (im * 0.08333333333333333)))));
} else {
tmp = 0.5 * (Math.exp(-im) + Math.exp(im));
}
return tmp;
}
def code(re, im): tmp = 0 if math.cos(re) <= 0.996: tmp = (0.5 * math.cos(re)) * (2.0 + ((im * im) * (1.0 + (im * (im * 0.08333333333333333))))) else: tmp = 0.5 * (math.exp(-im) + math.exp(im)) return tmp
function code(re, im) tmp = 0.0 if (cos(re) <= 0.996) tmp = Float64(Float64(0.5 * cos(re)) * Float64(2.0 + Float64(Float64(im * im) * Float64(1.0 + Float64(im * Float64(im * 0.08333333333333333)))))); 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 (cos(re) <= 0.996) tmp = (0.5 * cos(re)) * (2.0 + ((im * im) * (1.0 + (im * (im * 0.08333333333333333))))); else tmp = 0.5 * (exp(-im) + exp(im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Cos[re], $MachinePrecision], 0.996], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(2.0 + N[(N[(im * im), $MachinePrecision] * N[(1.0 + N[(im * N[(im * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos re \leq 0.996:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(2 + \left(im \cdot im\right) \cdot \left(1 + im \cdot \left(im \cdot 0.08333333333333333\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(e^{-im} + e^{im}\right)\\
\end{array}
\end{array}
if (cos.f64 re) < 0.996Initial program 100.0%
Taylor expanded in im around 0 89.6%
unpow289.6%
Simplified89.6%
+-commutative89.6%
*-commutative89.6%
metadata-eval89.6%
pow-sqr89.6%
pow-prod-down89.6%
pow289.6%
associate-*l*89.0%
fma-def89.0%
Applied egg-rr89.0%
fma-udef89.0%
*-commutative89.0%
*-commutative89.0%
distribute-lft1-in89.0%
*-commutative89.0%
associate-*l*89.0%
Simplified89.0%
if 0.996 < (cos.f64 re) Initial program 100.0%
Taylor expanded in re around 0 99.0%
Final simplification93.8%
(FPCore (re im) :precision binary64 (if (<= (cos re) 0.999999) (* (* 0.5 (cos re)) (+ 2.0 (* im im))) (* 0.5 (+ 2.0 (+ (* im im) (* 0.08333333333333333 (pow im 4.0)))))))
double code(double re, double im) {
double tmp;
if (cos(re) <= 0.999999) {
tmp = (0.5 * cos(re)) * (2.0 + (im * im));
} else {
tmp = 0.5 * (2.0 + ((im * im) + (0.08333333333333333 * 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 (cos(re) <= 0.999999d0) then
tmp = (0.5d0 * cos(re)) * (2.0d0 + (im * im))
else
tmp = 0.5d0 * (2.0d0 + ((im * im) + (0.08333333333333333d0 * (im ** 4.0d0))))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (Math.cos(re) <= 0.999999) {
tmp = (0.5 * Math.cos(re)) * (2.0 + (im * im));
} else {
tmp = 0.5 * (2.0 + ((im * im) + (0.08333333333333333 * Math.pow(im, 4.0))));
}
return tmp;
}
def code(re, im): tmp = 0 if math.cos(re) <= 0.999999: tmp = (0.5 * math.cos(re)) * (2.0 + (im * im)) else: tmp = 0.5 * (2.0 + ((im * im) + (0.08333333333333333 * math.pow(im, 4.0)))) return tmp
function code(re, im) tmp = 0.0 if (cos(re) <= 0.999999) tmp = Float64(Float64(0.5 * cos(re)) * Float64(2.0 + Float64(im * im))); else tmp = Float64(0.5 * Float64(2.0 + Float64(Float64(im * im) + Float64(0.08333333333333333 * (im ^ 4.0))))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (cos(re) <= 0.999999) tmp = (0.5 * cos(re)) * (2.0 + (im * im)); else tmp = 0.5 * (2.0 + ((im * im) + (0.08333333333333333 * (im ^ 4.0)))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Cos[re], $MachinePrecision], 0.999999], N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(2.0 + N[(N[(im * im), $MachinePrecision] + N[(0.08333333333333333 * N[Power[im, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos re \leq 0.999999:\\
\;\;\;\;\left(0.5 \cdot \cos re\right) \cdot \left(2 + im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 + \left(im \cdot im + 0.08333333333333333 \cdot {im}^{4}\right)\right)\\
\end{array}
\end{array}
if (cos.f64 re) < 0.999998999999999971Initial program 100.0%
Taylor expanded in im around 0 79.1%
unpow279.1%
Simplified79.1%
if 0.999998999999999971 < (cos.f64 re) Initial program 100.0%
Taylor expanded in re around 0 100.0%
Taylor expanded in im around 0 85.2%
unpow285.2%
Simplified85.2%
Final simplification81.9%
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ 2.0 (* (* im im) (+ 1.0 (* im (* im 0.08333333333333333)))))))
double code(double re, double im) {
return (0.5 * cos(re)) * (2.0 + ((im * im) * (1.0 + (im * (im * 0.08333333333333333)))));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * (2.0d0 + ((im * im) * (1.0d0 + (im * (im * 0.08333333333333333d0)))))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (2.0 + ((im * im) * (1.0 + (im * (im * 0.08333333333333333)))));
}
def code(re, im): return (0.5 * math.cos(re)) * (2.0 + ((im * im) * (1.0 + (im * (im * 0.08333333333333333)))))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(2.0 + Float64(Float64(im * im) * Float64(1.0 + Float64(im * Float64(im * 0.08333333333333333)))))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (2.0 + ((im * im) * (1.0 + (im * (im * 0.08333333333333333))))); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(2.0 + N[(N[(im * im), $MachinePrecision] * N[(1.0 + N[(im * N[(im * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(2 + \left(im \cdot im\right) \cdot \left(1 + im \cdot \left(im \cdot 0.08333333333333333\right)\right)\right)
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 87.2%
unpow287.2%
Simplified87.2%
+-commutative87.2%
*-commutative87.2%
metadata-eval87.2%
pow-sqr87.2%
pow-prod-down87.2%
pow287.2%
associate-*l*86.9%
fma-def86.9%
Applied egg-rr86.9%
fma-udef86.9%
*-commutative86.9%
*-commutative86.9%
distribute-lft1-in86.9%
*-commutative86.9%
associate-*l*86.9%
Simplified86.9%
Final simplification86.9%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* (cos re) (* 0.5 (* im im)))))
(if (<= im -1.45)
t_0
(if (<= im 700.0)
(cos re)
(if (<= im 1.35e+154) (* 2.0 (* re (* re (fma im im 2.0)))) t_0)))))
double code(double re, double im) {
double t_0 = cos(re) * (0.5 * (im * im));
double tmp;
if (im <= -1.45) {
tmp = t_0;
} else if (im <= 700.0) {
tmp = cos(re);
} else if (im <= 1.35e+154) {
tmp = 2.0 * (re * (re * fma(im, im, 2.0)));
} else {
tmp = t_0;
}
return tmp;
}
function code(re, im) t_0 = Float64(cos(re) * Float64(0.5 * Float64(im * im))) tmp = 0.0 if (im <= -1.45) tmp = t_0; elseif (im <= 700.0) tmp = cos(re); elseif (im <= 1.35e+154) tmp = Float64(2.0 * Float64(re * Float64(re * fma(im, im, 2.0)))); else tmp = t_0; end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -1.45], t$95$0, If[LessEqual[im, 700.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.35e+154], N[(2.0 * N[(re * N[(re * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\
\mathbf{if}\;im \leq -1.45:\\
\;\;\;\;t_0\\
\mathbf{elif}\;im \leq 700:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;2 \cdot \left(re \cdot \left(re \cdot \mathsf{fma}\left(im, im, 2\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if im < -1.44999999999999996 or 1.35000000000000003e154 < im Initial program 100.0%
Taylor expanded in im around 0 67.0%
unpow267.0%
Simplified67.0%
Taylor expanded in im around inf 67.0%
unpow267.0%
associate-*r*67.0%
*-commutative67.0%
associate-*r*67.0%
Simplified67.0%
if -1.44999999999999996 < im < 700Initial program 100.0%
Taylor expanded in im around 0 99.5%
unpow299.5%
Simplified99.5%
+-commutative99.5%
*-commutative99.5%
metadata-eval99.5%
pow-sqr99.5%
pow-prod-down99.5%
pow299.5%
associate-*l*99.5%
fma-def99.5%
Applied egg-rr99.5%
fma-udef99.5%
*-commutative99.5%
*-commutative99.5%
distribute-lft1-in99.5%
*-commutative99.5%
associate-*l*99.5%
Simplified99.5%
Taylor expanded in im around 0 98.3%
if 700 < im < 1.35000000000000003e154Initial program 100.0%
Taylor expanded in im around 0 4.9%
unpow24.9%
Simplified4.9%
Applied egg-rr1.4%
*-commutative1.4%
Simplified1.4%
Taylor expanded in re around 0 35.2%
*-commutative35.2%
unpow235.2%
Simplified35.2%
Taylor expanded in re around inf 36.1%
unpow236.1%
*-commutative36.1%
+-commutative36.1%
unpow236.1%
fma-udef36.1%
associate-*l*36.1%
Simplified36.1%
Final simplification80.5%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* (cos re) (* 0.5 (* im im)))))
(if (<= im -1.45)
t_0
(if (<= im 720.0)
(cos re)
(if (<= im 3.05e+153)
(* (+ 2.0 (* im im)) (* 0.5 (* re (* re 4.0))))
t_0)))))
double code(double re, double im) {
double t_0 = cos(re) * (0.5 * (im * im));
double tmp;
if (im <= -1.45) {
tmp = t_0;
} else if (im <= 720.0) {
tmp = cos(re);
} else if (im <= 3.05e+153) {
tmp = (2.0 + (im * im)) * (0.5 * (re * (re * 4.0)));
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: tmp
t_0 = cos(re) * (0.5d0 * (im * im))
if (im <= (-1.45d0)) then
tmp = t_0
else if (im <= 720.0d0) then
tmp = cos(re)
else if (im <= 3.05d+153) then
tmp = (2.0d0 + (im * im)) * (0.5d0 * (re * (re * 4.0d0)))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = Math.cos(re) * (0.5 * (im * im));
double tmp;
if (im <= -1.45) {
tmp = t_0;
} else if (im <= 720.0) {
tmp = Math.cos(re);
} else if (im <= 3.05e+153) {
tmp = (2.0 + (im * im)) * (0.5 * (re * (re * 4.0)));
} else {
tmp = t_0;
}
return tmp;
}
def code(re, im): t_0 = math.cos(re) * (0.5 * (im * im)) tmp = 0 if im <= -1.45: tmp = t_0 elif im <= 720.0: tmp = math.cos(re) elif im <= 3.05e+153: tmp = (2.0 + (im * im)) * (0.5 * (re * (re * 4.0))) else: tmp = t_0 return tmp
function code(re, im) t_0 = Float64(cos(re) * Float64(0.5 * Float64(im * im))) tmp = 0.0 if (im <= -1.45) tmp = t_0; elseif (im <= 720.0) tmp = cos(re); elseif (im <= 3.05e+153) tmp = Float64(Float64(2.0 + Float64(im * im)) * Float64(0.5 * Float64(re * Float64(re * 4.0)))); else tmp = t_0; end return tmp end
function tmp_2 = code(re, im) t_0 = cos(re) * (0.5 * (im * im)); tmp = 0.0; if (im <= -1.45) tmp = t_0; elseif (im <= 720.0) tmp = cos(re); elseif (im <= 3.05e+153) tmp = (2.0 + (im * im)) * (0.5 * (re * (re * 4.0))); else tmp = t_0; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -1.45], t$95$0, If[LessEqual[im, 720.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 3.05e+153], N[(N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision] * N[(0.5 * N[(re * N[(re * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\
\mathbf{if}\;im \leq -1.45:\\
\;\;\;\;t_0\\
\mathbf{elif}\;im \leq 720:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 3.05 \cdot 10^{+153}:\\
\;\;\;\;\left(2 + im \cdot im\right) \cdot \left(0.5 \cdot \left(re \cdot \left(re \cdot 4\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if im < -1.44999999999999996 or 3.0499999999999999e153 < im Initial program 100.0%
Taylor expanded in im around 0 67.0%
unpow267.0%
Simplified67.0%
Taylor expanded in im around inf 67.0%
unpow267.0%
associate-*r*67.0%
*-commutative67.0%
associate-*r*67.0%
Simplified67.0%
if -1.44999999999999996 < im < 720Initial program 100.0%
Taylor expanded in im around 0 99.5%
unpow299.5%
Simplified99.5%
+-commutative99.5%
*-commutative99.5%
metadata-eval99.5%
pow-sqr99.5%
pow-prod-down99.5%
pow299.5%
associate-*l*99.5%
fma-def99.5%
Applied egg-rr99.5%
fma-udef99.5%
*-commutative99.5%
*-commutative99.5%
distribute-lft1-in99.5%
*-commutative99.5%
associate-*l*99.5%
Simplified99.5%
Taylor expanded in im around 0 98.3%
if 720 < im < 3.0499999999999999e153Initial program 100.0%
Taylor expanded in im around 0 4.9%
unpow24.9%
Simplified4.9%
Applied egg-rr1.4%
*-commutative1.4%
Simplified1.4%
Taylor expanded in re around 0 35.2%
*-commutative35.2%
unpow235.2%
Simplified35.2%
Taylor expanded in re around inf 36.1%
unpow236.1%
*-commutative36.1%
associate-*l*36.1%
Simplified36.1%
Final simplification80.5%
(FPCore (re im) :precision binary64 (* (* 0.5 (cos re)) (+ 2.0 (* im im))))
double code(double re, double im) {
return (0.5 * cos(re)) * (2.0 + (im * im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * cos(re)) * (2.0d0 + (im * im))
end function
public static double code(double re, double im) {
return (0.5 * Math.cos(re)) * (2.0 + (im * im));
}
def code(re, im): return (0.5 * math.cos(re)) * (2.0 + (im * im))
function code(re, im) return Float64(Float64(0.5 * cos(re)) * Float64(2.0 + Float64(im * im))) end
function tmp = code(re, im) tmp = (0.5 * cos(re)) * (2.0 + (im * im)); end
code[re_, im_] := N[(N[(0.5 * N[Cos[re], $MachinePrecision]), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \cos re\right) \cdot \left(2 + im \cdot im\right)
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 78.2%
unpow278.2%
Simplified78.2%
Final simplification78.2%
(FPCore (re im)
:precision binary64
(let* ((t_0 (+ 2.0 (* im im)))
(t_1 (* t_0 (* 0.5 (+ 1.0 (* -0.5 (* re re)))))))
(if (<= im -1e+24)
t_1
(if (<= im 1100.0)
(cos re)
(if (<= im 1.2e+83) (* t_0 (* 0.5 (* re (* re 4.0)))) t_1)))))
double code(double re, double im) {
double t_0 = 2.0 + (im * im);
double t_1 = t_0 * (0.5 * (1.0 + (-0.5 * (re * re))));
double tmp;
if (im <= -1e+24) {
tmp = t_1;
} else if (im <= 1100.0) {
tmp = cos(re);
} else if (im <= 1.2e+83) {
tmp = t_0 * (0.5 * (re * (re * 4.0)));
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 2.0d0 + (im * im)
t_1 = t_0 * (0.5d0 * (1.0d0 + ((-0.5d0) * (re * re))))
if (im <= (-1d+24)) then
tmp = t_1
else if (im <= 1100.0d0) then
tmp = cos(re)
else if (im <= 1.2d+83) then
tmp = t_0 * (0.5d0 * (re * (re * 4.0d0)))
else
tmp = t_1
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 2.0 + (im * im);
double t_1 = t_0 * (0.5 * (1.0 + (-0.5 * (re * re))));
double tmp;
if (im <= -1e+24) {
tmp = t_1;
} else if (im <= 1100.0) {
tmp = Math.cos(re);
} else if (im <= 1.2e+83) {
tmp = t_0 * (0.5 * (re * (re * 4.0)));
} else {
tmp = t_1;
}
return tmp;
}
def code(re, im): t_0 = 2.0 + (im * im) t_1 = t_0 * (0.5 * (1.0 + (-0.5 * (re * re)))) tmp = 0 if im <= -1e+24: tmp = t_1 elif im <= 1100.0: tmp = math.cos(re) elif im <= 1.2e+83: tmp = t_0 * (0.5 * (re * (re * 4.0))) else: tmp = t_1 return tmp
function code(re, im) t_0 = Float64(2.0 + Float64(im * im)) t_1 = Float64(t_0 * Float64(0.5 * Float64(1.0 + Float64(-0.5 * Float64(re * re))))) tmp = 0.0 if (im <= -1e+24) tmp = t_1; elseif (im <= 1100.0) tmp = cos(re); elseif (im <= 1.2e+83) tmp = Float64(t_0 * Float64(0.5 * Float64(re * Float64(re * 4.0)))); else tmp = t_1; end return tmp end
function tmp_2 = code(re, im) t_0 = 2.0 + (im * im); t_1 = t_0 * (0.5 * (1.0 + (-0.5 * (re * re)))); tmp = 0.0; if (im <= -1e+24) tmp = t_1; elseif (im <= 1100.0) tmp = cos(re); elseif (im <= 1.2e+83) tmp = t_0 * (0.5 * (re * (re * 4.0))); else tmp = t_1; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 * N[(0.5 * N[(1.0 + N[(-0.5 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -1e+24], t$95$1, If[LessEqual[im, 1100.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 1.2e+83], N[(t$95$0 * N[(0.5 * N[(re * N[(re * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 2 + im \cdot im\\
t_1 := t_0 \cdot \left(0.5 \cdot \left(1 + -0.5 \cdot \left(re \cdot re\right)\right)\right)\\
\mathbf{if}\;im \leq -1 \cdot 10^{+24}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;im \leq 1100:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 1.2 \cdot 10^{+83}:\\
\;\;\;\;t_0 \cdot \left(0.5 \cdot \left(re \cdot \left(re \cdot 4\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if im < -9.9999999999999998e23 or 1.19999999999999996e83 < im Initial program 100.0%
Taylor expanded in im around 0 65.3%
unpow265.3%
Simplified65.3%
Taylor expanded in re around 0 55.7%
unpow255.7%
Simplified55.7%
if -9.9999999999999998e23 < im < 1100Initial program 100.0%
Taylor expanded in im around 0 95.5%
unpow295.5%
Simplified95.5%
+-commutative95.5%
*-commutative95.5%
metadata-eval95.5%
pow-sqr95.5%
pow-prod-down95.5%
pow295.5%
associate-*l*95.5%
fma-def95.5%
Applied egg-rr95.5%
fma-udef95.5%
*-commutative95.5%
*-commutative95.5%
distribute-lft1-in95.5%
*-commutative95.5%
associate-*l*95.5%
Simplified95.5%
Taylor expanded in im around 0 94.3%
if 1100 < im < 1.19999999999999996e83Initial program 100.0%
Taylor expanded in im around 0 3.7%
unpow23.7%
Simplified3.7%
Applied egg-rr0.5%
*-commutative0.5%
Simplified0.5%
Taylor expanded in re around 0 36.3%
*-commutative36.3%
unpow236.3%
Simplified36.3%
Taylor expanded in re around inf 37.5%
unpow237.5%
*-commutative37.5%
associate-*l*37.5%
Simplified37.5%
Final simplification75.6%
(FPCore (re im)
:precision binary64
(let* ((t_0 (+ 2.0 (* im im))))
(if (<= im 520.0)
(* 0.5 t_0)
(if (<= im 5e+83)
(* t_0 (* 0.5 (* re (* re 4.0))))
(* t_0 (* 0.5 (+ 1.0 (* -0.5 (* re re)))))))))
double code(double re, double im) {
double t_0 = 2.0 + (im * im);
double tmp;
if (im <= 520.0) {
tmp = 0.5 * t_0;
} else if (im <= 5e+83) {
tmp = t_0 * (0.5 * (re * (re * 4.0)));
} else {
tmp = t_0 * (0.5 * (1.0 + (-0.5 * (re * re))));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: tmp
t_0 = 2.0d0 + (im * im)
if (im <= 520.0d0) then
tmp = 0.5d0 * t_0
else if (im <= 5d+83) then
tmp = t_0 * (0.5d0 * (re * (re * 4.0d0)))
else
tmp = t_0 * (0.5d0 * (1.0d0 + ((-0.5d0) * (re * re))))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 2.0 + (im * im);
double tmp;
if (im <= 520.0) {
tmp = 0.5 * t_0;
} else if (im <= 5e+83) {
tmp = t_0 * (0.5 * (re * (re * 4.0)));
} else {
tmp = t_0 * (0.5 * (1.0 + (-0.5 * (re * re))));
}
return tmp;
}
def code(re, im): t_0 = 2.0 + (im * im) tmp = 0 if im <= 520.0: tmp = 0.5 * t_0 elif im <= 5e+83: tmp = t_0 * (0.5 * (re * (re * 4.0))) else: tmp = t_0 * (0.5 * (1.0 + (-0.5 * (re * re)))) return tmp
function code(re, im) t_0 = Float64(2.0 + Float64(im * im)) tmp = 0.0 if (im <= 520.0) tmp = Float64(0.5 * t_0); elseif (im <= 5e+83) tmp = Float64(t_0 * Float64(0.5 * Float64(re * Float64(re * 4.0)))); else tmp = Float64(t_0 * Float64(0.5 * Float64(1.0 + Float64(-0.5 * Float64(re * re))))); end return tmp end
function tmp_2 = code(re, im) t_0 = 2.0 + (im * im); tmp = 0.0; if (im <= 520.0) tmp = 0.5 * t_0; elseif (im <= 5e+83) tmp = t_0 * (0.5 * (re * (re * 4.0))); else tmp = t_0 * (0.5 * (1.0 + (-0.5 * (re * re)))); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, 520.0], N[(0.5 * t$95$0), $MachinePrecision], If[LessEqual[im, 5e+83], N[(t$95$0 * N[(0.5 * N[(re * N[(re * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[(0.5 * N[(1.0 + N[(-0.5 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 2 + im \cdot im\\
\mathbf{if}\;im \leq 520:\\
\;\;\;\;0.5 \cdot t_0\\
\mathbf{elif}\;im \leq 5 \cdot 10^{+83}:\\
\;\;\;\;t_0 \cdot \left(0.5 \cdot \left(re \cdot \left(re \cdot 4\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot \left(0.5 \cdot \left(1 + -0.5 \cdot \left(re \cdot re\right)\right)\right)\\
\end{array}
\end{array}
if im < 520Initial program 100.0%
Taylor expanded in re around 0 59.8%
Taylor expanded in im around 0 48.3%
unpow283.4%
Simplified48.3%
if 520 < im < 5.00000000000000029e83Initial program 100.0%
Taylor expanded in im around 0 3.7%
unpow23.7%
Simplified3.7%
Applied egg-rr0.5%
*-commutative0.5%
Simplified0.5%
Taylor expanded in re around 0 36.3%
*-commutative36.3%
unpow236.3%
Simplified36.3%
Taylor expanded in re around inf 37.5%
unpow237.5%
*-commutative37.5%
associate-*l*37.5%
Simplified37.5%
if 5.00000000000000029e83 < im Initial program 100.0%
Taylor expanded in im around 0 77.3%
unpow277.3%
Simplified77.3%
Taylor expanded in re around 0 65.3%
unpow265.3%
Simplified65.3%
Final simplification50.2%
(FPCore (re im) :precision binary64 (if (<= re -3.45e+25) (* im (* im (* (* re re) -0.25))) (* 0.5 (+ 2.0 (* im im)))))
double code(double re, double im) {
double tmp;
if (re <= -3.45e+25) {
tmp = im * (im * ((re * re) * -0.25));
} else {
tmp = 0.5 * (2.0 + (im * im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-3.45d+25)) then
tmp = im * (im * ((re * re) * (-0.25d0)))
else
tmp = 0.5d0 * (2.0d0 + (im * im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -3.45e+25) {
tmp = im * (im * ((re * re) * -0.25));
} else {
tmp = 0.5 * (2.0 + (im * im));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -3.45e+25: tmp = im * (im * ((re * re) * -0.25)) else: tmp = 0.5 * (2.0 + (im * im)) return tmp
function code(re, im) tmp = 0.0 if (re <= -3.45e+25) tmp = Float64(im * Float64(im * Float64(Float64(re * re) * -0.25))); else tmp = Float64(0.5 * Float64(2.0 + Float64(im * im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -3.45e+25) tmp = im * (im * ((re * re) * -0.25)); else tmp = 0.5 * (2.0 + (im * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -3.45e+25], N[(im * N[(im * N[(N[(re * re), $MachinePrecision] * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.45 \cdot 10^{+25}:\\
\;\;\;\;im \cdot \left(im \cdot \left(\left(re \cdot re\right) \cdot -0.25\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(2 + im \cdot im\right)\\
\end{array}
\end{array}
if re < -3.4499999999999999e25Initial program 100.0%
Taylor expanded in im around 0 78.4%
unpow278.4%
Simplified78.4%
Taylor expanded in re around 0 25.9%
unpow225.9%
Simplified25.9%
Taylor expanded in im around inf 26.0%
associate-*r*26.0%
+-commutative26.0%
fma-def26.0%
unpow226.0%
*-commutative26.0%
unpow226.0%
associate-*l*26.2%
fma-udef26.2%
unpow226.2%
*-commutative26.2%
fma-def26.2%
unpow226.2%
Simplified26.2%
Taylor expanded in re around inf 26.2%
unpow226.2%
associate-*r*26.2%
*-commutative26.2%
Simplified26.2%
if -3.4499999999999999e25 < re Initial program 100.0%
Taylor expanded in re around 0 73.1%
Taylor expanded in im around 0 54.2%
unpow278.1%
Simplified54.2%
Final simplification47.1%
(FPCore (re im) :precision binary64 (if (or (<= im -2000000000000.0) (not (<= im 1.4))) (* 0.5 (* im im)) 1.0))
double code(double re, double im) {
double tmp;
if ((im <= -2000000000000.0) || !(im <= 1.4)) {
tmp = 0.5 * (im * im);
} else {
tmp = 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 <= (-2000000000000.0d0)) .or. (.not. (im <= 1.4d0))) then
tmp = 0.5d0 * (im * im)
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((im <= -2000000000000.0) || !(im <= 1.4)) {
tmp = 0.5 * (im * im);
} else {
tmp = 1.0;
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= -2000000000000.0) or not (im <= 1.4): tmp = 0.5 * (im * im) else: tmp = 1.0 return tmp
function code(re, im) tmp = 0.0 if ((im <= -2000000000000.0) || !(im <= 1.4)) tmp = Float64(0.5 * Float64(im * im)); else tmp = 1.0; end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((im <= -2000000000000.0) || ~((im <= 1.4))) tmp = 0.5 * (im * im); else tmp = 1.0; end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, -2000000000000.0], N[Not[LessEqual[im, 1.4]], $MachinePrecision]], N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq -2000000000000 \lor \neg \left(im \leq 1.4\right):\\
\;\;\;\;0.5 \cdot \left(im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if im < -2e12 or 1.3999999999999999 < im Initial program 100.0%
Taylor expanded in im around 0 56.6%
unpow256.6%
Simplified56.6%
Taylor expanded in re around 0 48.1%
unpow248.1%
Simplified48.1%
Taylor expanded in im around inf 48.1%
associate-*r*48.1%
+-commutative48.1%
fma-def48.1%
unpow248.1%
*-commutative48.1%
unpow248.1%
associate-*l*48.1%
fma-udef48.1%
unpow248.1%
*-commutative48.1%
fma-def48.1%
unpow248.1%
Simplified48.1%
Taylor expanded in re around 0 39.4%
*-commutative39.4%
unpow239.4%
Simplified39.4%
if -2e12 < im < 1.3999999999999999Initial program 100.0%
Taylor expanded in re around 0 50.5%
Taylor expanded in im around 0 49.9%
Final simplification45.0%
(FPCore (re im) :precision binary64 -1.0)
double code(double re, double im) {
return -1.0;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = -1.0d0
end function
public static double code(double re, double im) {
return -1.0;
}
def code(re, im): return -1.0
function code(re, im) return -1.0 end
function tmp = code(re, im) tmp = -1.0; end
code[re_, im_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 61.6%
Applied egg-rr4.2%
Final simplification4.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%
Taylor expanded in re around 0 61.6%
Applied egg-rr8.2%
Final simplification8.2%
(FPCore (re im) :precision binary64 0.75)
double code(double re, double im) {
return 0.75;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.75d0
end function
public static double code(double re, double im) {
return 0.75;
}
def code(re, im): return 0.75
function code(re, im) return 0.75 end
function tmp = code(re, im) tmp = 0.75; end
code[re_, im_] := 0.75
\begin{array}{l}
\\
0.75
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 61.6%
Applied egg-rr9.2%
Final simplification9.2%
(FPCore (re im) :precision binary64 1.0)
double code(double re, double im) {
return 1.0;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 1.0d0
end function
public static double code(double re, double im) {
return 1.0;
}
def code(re, im): return 1.0
function code(re, im) return 1.0 end
function tmp = code(re, im) tmp = 1.0; end
code[re_, im_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 61.6%
Taylor expanded in im around 0 27.7%
Final simplification27.7%
herbie shell --seed 2023187
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))