
(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 12 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
(let* ((t_0 (+ (exp (- im)) (exp im))))
(if (<= t_0 2.0000002)
(+ (cos re) (* (cos re) (* 0.5 (* im im))))
(* 0.5 t_0))))
double code(double re, double im) {
double t_0 = exp(-im) + exp(im);
double tmp;
if (t_0 <= 2.0000002) {
tmp = cos(re) + (cos(re) * (0.5 * (im * im)));
} else {
tmp = 0.5 * 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 = exp(-im) + exp(im)
if (t_0 <= 2.0000002d0) then
tmp = cos(re) + (cos(re) * (0.5d0 * (im * im)))
else
tmp = 0.5d0 * t_0
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = Math.exp(-im) + Math.exp(im);
double tmp;
if (t_0 <= 2.0000002) {
tmp = Math.cos(re) + (Math.cos(re) * (0.5 * (im * im)));
} else {
tmp = 0.5 * t_0;
}
return tmp;
}
def code(re, im): t_0 = math.exp(-im) + math.exp(im) tmp = 0 if t_0 <= 2.0000002: tmp = math.cos(re) + (math.cos(re) * (0.5 * (im * im))) else: tmp = 0.5 * t_0 return tmp
function code(re, im) t_0 = Float64(exp(Float64(-im)) + exp(im)) tmp = 0.0 if (t_0 <= 2.0000002) tmp = Float64(cos(re) + Float64(cos(re) * Float64(0.5 * Float64(im * im)))); else tmp = Float64(0.5 * t_0); end return tmp end
function tmp_2 = code(re, im) t_0 = exp(-im) + exp(im); tmp = 0.0; if (t_0 <= 2.0000002) tmp = cos(re) + (cos(re) * (0.5 * (im * im))); else tmp = 0.5 * t_0; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[(-im)], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2.0000002], N[(N[Cos[re], $MachinePrecision] + N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-im} + e^{im}\\
\mathbf{if}\;t_0 \leq 2.0000002:\\
\;\;\;\;\cos re + \cos re \cdot \left(0.5 \cdot \left(im \cdot im\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot t_0\\
\end{array}
\end{array}
if (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)) < 2.00000020000000012Initial program 100.0%
Taylor expanded in im around 0 100.0%
Simplified100.0%
fma-udef100.0%
*-commutative100.0%
associate-*r*100.0%
Applied egg-rr100.0%
if 2.00000020000000012 < (+.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)) Initial program 100.0%
Taylor expanded in re around 0 81.7%
Final simplification91.8%
(FPCore (re im)
:precision binary64
(if (<= im -4e+155)
(* im (* 0.5 (* (cos re) im)))
(if (or (<= im -0.00046) (not (<= im 0.0006)))
(* 0.5 (+ (exp (- im)) (exp im)))
(* (cos re) (+ (* 0.5 (* im im)) 1.0)))))
double code(double re, double im) {
double tmp;
if (im <= -4e+155) {
tmp = im * (0.5 * (cos(re) * im));
} else if ((im <= -0.00046) || !(im <= 0.0006)) {
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 <= (-4d+155)) then
tmp = im * (0.5d0 * (cos(re) * im))
else if ((im <= (-0.00046d0)) .or. (.not. (im <= 0.0006d0))) 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 <= -4e+155) {
tmp = im * (0.5 * (Math.cos(re) * im));
} else if ((im <= -0.00046) || !(im <= 0.0006)) {
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 <= -4e+155: tmp = im * (0.5 * (math.cos(re) * im)) elif (im <= -0.00046) or not (im <= 0.0006): 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 <= -4e+155) tmp = Float64(im * Float64(0.5 * Float64(cos(re) * im))); elseif ((im <= -0.00046) || !(im <= 0.0006)) 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 <= -4e+155) tmp = im * (0.5 * (cos(re) * im)); elseif ((im <= -0.00046) || ~((im <= 0.0006))) 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, -4e+155], N[(im * N[(0.5 * N[(N[Cos[re], $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[im, -0.00046], N[Not[LessEqual[im, 0.0006]], $MachinePrecision]], 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 -4 \cdot 10^{+155}:\\
\;\;\;\;im \cdot \left(0.5 \cdot \left(\cos re \cdot im\right)\right)\\
\mathbf{elif}\;im \leq -0.00046 \lor \neg \left(im \leq 0.0006\right):\\
\;\;\;\;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 < -4.00000000000000003e155Initial program 100.0%
Taylor expanded in im around 0 100.0%
Simplified100.0%
Taylor expanded in im around inf 100.0%
unpow2100.0%
associate-*r*100.0%
associate-*r*100.0%
*-commutative100.0%
*-commutative100.0%
Simplified100.0%
if -4.00000000000000003e155 < im < -4.6000000000000001e-4 or 5.99999999999999947e-4 < im Initial program 100.0%
Taylor expanded in re around 0 82.8%
if -4.6000000000000001e-4 < im < 5.99999999999999947e-4Initial program 100.0%
Taylor expanded in im around 0 100.0%
Simplified100.0%
Taylor expanded in re around inf 100.0%
*-commutative100.0%
associate-*l*100.0%
unpow2100.0%
distribute-lft1-in99.9%
+-commutative99.9%
unpow299.9%
*-commutative99.9%
unpow299.9%
Simplified99.9%
Final simplification94.1%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* im (* 0.5 (* (cos re) im))))
(t_1 (* re (* re (* -0.5 (cosh im))))))
(if (<= im -1.4e+141)
t_0
(if (<= im -2.8e+22)
t_1
(if (<= im 19500.0)
(+ (cos re) (* im (* 0.5 im)))
(if (<= im 1.9e+154) t_1 t_0))))))
double code(double re, double im) {
double t_0 = im * (0.5 * (cos(re) * im));
double t_1 = re * (re * (-0.5 * cosh(im)));
double tmp;
if (im <= -1.4e+141) {
tmp = t_0;
} else if (im <= -2.8e+22) {
tmp = t_1;
} else if (im <= 19500.0) {
tmp = cos(re) + (im * (0.5 * im));
} else if (im <= 1.9e+154) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = im * (0.5d0 * (cos(re) * im))
t_1 = re * (re * ((-0.5d0) * cosh(im)))
if (im <= (-1.4d+141)) then
tmp = t_0
else if (im <= (-2.8d+22)) then
tmp = t_1
else if (im <= 19500.0d0) then
tmp = cos(re) + (im * (0.5d0 * im))
else if (im <= 1.9d+154) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = im * (0.5 * (Math.cos(re) * im));
double t_1 = re * (re * (-0.5 * Math.cosh(im)));
double tmp;
if (im <= -1.4e+141) {
tmp = t_0;
} else if (im <= -2.8e+22) {
tmp = t_1;
} else if (im <= 19500.0) {
tmp = Math.cos(re) + (im * (0.5 * im));
} else if (im <= 1.9e+154) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(re, im): t_0 = im * (0.5 * (math.cos(re) * im)) t_1 = re * (re * (-0.5 * math.cosh(im))) tmp = 0 if im <= -1.4e+141: tmp = t_0 elif im <= -2.8e+22: tmp = t_1 elif im <= 19500.0: tmp = math.cos(re) + (im * (0.5 * im)) elif im <= 1.9e+154: tmp = t_1 else: tmp = t_0 return tmp
function code(re, im) t_0 = Float64(im * Float64(0.5 * Float64(cos(re) * im))) t_1 = Float64(re * Float64(re * Float64(-0.5 * cosh(im)))) tmp = 0.0 if (im <= -1.4e+141) tmp = t_0; elseif (im <= -2.8e+22) tmp = t_1; elseif (im <= 19500.0) tmp = Float64(cos(re) + Float64(im * Float64(0.5 * im))); elseif (im <= 1.9e+154) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(re, im) t_0 = im * (0.5 * (cos(re) * im)); t_1 = re * (re * (-0.5 * cosh(im))); tmp = 0.0; if (im <= -1.4e+141) tmp = t_0; elseif (im <= -2.8e+22) tmp = t_1; elseif (im <= 19500.0) tmp = cos(re) + (im * (0.5 * im)); elseif (im <= 1.9e+154) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(im * N[(0.5 * N[(N[Cos[re], $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(re * N[(re * N[(-0.5 * N[Cosh[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -1.4e+141], t$95$0, If[LessEqual[im, -2.8e+22], t$95$1, If[LessEqual[im, 19500.0], N[(N[Cos[re], $MachinePrecision] + N[(im * N[(0.5 * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.9e+154], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := im \cdot \left(0.5 \cdot \left(\cos re \cdot im\right)\right)\\
t_1 := re \cdot \left(re \cdot \left(-0.5 \cdot \cosh im\right)\right)\\
\mathbf{if}\;im \leq -1.4 \cdot 10^{+141}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;im \leq -2.8 \cdot 10^{+22}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;im \leq 19500:\\
\;\;\;\;\cos re + im \cdot \left(0.5 \cdot im\right)\\
\mathbf{elif}\;im \leq 1.9 \cdot 10^{+154}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if im < -1.39999999999999996e141 or 1.8999999999999999e154 < im Initial program 100.0%
Taylor expanded in im around 0 98.4%
Simplified98.4%
Taylor expanded in im around inf 98.4%
unpow298.4%
associate-*r*98.4%
associate-*r*98.4%
*-commutative98.4%
*-commutative98.4%
Simplified98.4%
if -1.39999999999999996e141 < im < -2.8e22 or 19500 < im < 1.8999999999999999e154Initial program 100.0%
Taylor expanded in re around 0 72.0%
Simplified72.0%
Taylor expanded in re around inf 24.0%
*-commutative24.0%
associate-*l*24.0%
unpow224.0%
associate-*l*24.0%
*-commutative24.0%
Simplified24.0%
expm1-log1p-u10.0%
expm1-udef10.0%
cosh-undef10.0%
Applied egg-rr10.0%
expm1-def10.0%
expm1-log1p24.0%
associate-*r*24.0%
metadata-eval24.0%
Simplified24.0%
if -2.8e22 < im < 19500Initial program 100.0%
Taylor expanded in im around 0 95.5%
Simplified95.5%
fma-udef95.5%
*-commutative95.5%
associate-*r*95.5%
Applied egg-rr95.5%
Taylor expanded in re around 0 95.2%
unpow295.2%
associate-*r*95.2%
*-commutative95.2%
Simplified95.2%
Final simplification82.0%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* im (* 0.5 (* (cos re) im)))))
(if (<= im -7.4e+140)
t_0
(if (<= im -2.8e+22)
(* re (* re (* -0.5 (cosh im))))
(if (<= im 1.45) (cos re) t_0)))))
double code(double re, double im) {
double t_0 = im * (0.5 * (cos(re) * im));
double tmp;
if (im <= -7.4e+140) {
tmp = t_0;
} else if (im <= -2.8e+22) {
tmp = re * (re * (-0.5 * cosh(im)));
} else if (im <= 1.45) {
tmp = cos(re);
} 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 = im * (0.5d0 * (cos(re) * im))
if (im <= (-7.4d+140)) then
tmp = t_0
else if (im <= (-2.8d+22)) then
tmp = re * (re * ((-0.5d0) * cosh(im)))
else if (im <= 1.45d0) then
tmp = cos(re)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = im * (0.5 * (Math.cos(re) * im));
double tmp;
if (im <= -7.4e+140) {
tmp = t_0;
} else if (im <= -2.8e+22) {
tmp = re * (re * (-0.5 * Math.cosh(im)));
} else if (im <= 1.45) {
tmp = Math.cos(re);
} else {
tmp = t_0;
}
return tmp;
}
def code(re, im): t_0 = im * (0.5 * (math.cos(re) * im)) tmp = 0 if im <= -7.4e+140: tmp = t_0 elif im <= -2.8e+22: tmp = re * (re * (-0.5 * math.cosh(im))) elif im <= 1.45: tmp = math.cos(re) else: tmp = t_0 return tmp
function code(re, im) t_0 = Float64(im * Float64(0.5 * Float64(cos(re) * im))) tmp = 0.0 if (im <= -7.4e+140) tmp = t_0; elseif (im <= -2.8e+22) tmp = Float64(re * Float64(re * Float64(-0.5 * cosh(im)))); elseif (im <= 1.45) tmp = cos(re); else tmp = t_0; end return tmp end
function tmp_2 = code(re, im) t_0 = im * (0.5 * (cos(re) * im)); tmp = 0.0; if (im <= -7.4e+140) tmp = t_0; elseif (im <= -2.8e+22) tmp = re * (re * (-0.5 * cosh(im))); elseif (im <= 1.45) tmp = cos(re); else tmp = t_0; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(im * N[(0.5 * N[(N[Cos[re], $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -7.4e+140], t$95$0, If[LessEqual[im, -2.8e+22], N[(re * N[(re * N[(-0.5 * N[Cosh[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.45], N[Cos[re], $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := im \cdot \left(0.5 \cdot \left(\cos re \cdot im\right)\right)\\
\mathbf{if}\;im \leq -7.4 \cdot 10^{+140}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;im \leq -2.8 \cdot 10^{+22}:\\
\;\;\;\;re \cdot \left(re \cdot \left(-0.5 \cdot \cosh im\right)\right)\\
\mathbf{elif}\;im \leq 1.45:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if im < -7.40000000000000006e140 or 1.44999999999999996 < im Initial program 100.0%
Taylor expanded in im around 0 69.5%
Simplified69.5%
Taylor expanded in im around inf 69.5%
unpow269.5%
associate-*r*69.5%
associate-*r*69.5%
*-commutative69.5%
*-commutative69.5%
Simplified69.5%
if -7.40000000000000006e140 < im < -2.8e22Initial program 100.0%
Taylor expanded in re around 0 73.1%
Simplified73.1%
Taylor expanded in re around inf 26.9%
*-commutative26.9%
associate-*l*26.9%
unpow226.9%
associate-*l*26.9%
*-commutative26.9%
Simplified26.9%
expm1-log1p-u11.5%
expm1-udef11.5%
cosh-undef11.5%
Applied egg-rr11.5%
expm1-def11.5%
expm1-log1p26.9%
associate-*r*26.9%
metadata-eval26.9%
Simplified26.9%
if -2.8e22 < im < 1.44999999999999996Initial program 100.0%
Taylor expanded in im around 0 95.1%
Final simplification80.1%
(FPCore (re im) :precision binary64 (if (or (<= im -1.4) (not (<= im 1.45))) (* im (* 0.5 (* (cos re) im))) (cos re)))
double code(double re, double im) {
double tmp;
if ((im <= -1.4) || !(im <= 1.45)) {
tmp = im * (0.5 * (cos(re) * im));
} else {
tmp = cos(re);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((im <= (-1.4d0)) .or. (.not. (im <= 1.45d0))) then
tmp = im * (0.5d0 * (cos(re) * im))
else
tmp = cos(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((im <= -1.4) || !(im <= 1.45)) {
tmp = im * (0.5 * (Math.cos(re) * im));
} else {
tmp = Math.cos(re);
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= -1.4) or not (im <= 1.45): tmp = im * (0.5 * (math.cos(re) * im)) else: tmp = math.cos(re) return tmp
function code(re, im) tmp = 0.0 if ((im <= -1.4) || !(im <= 1.45)) tmp = Float64(im * Float64(0.5 * Float64(cos(re) * im))); else tmp = cos(re); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((im <= -1.4) || ~((im <= 1.45))) tmp = im * (0.5 * (cos(re) * im)); else tmp = cos(re); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, -1.4], N[Not[LessEqual[im, 1.45]], $MachinePrecision]], N[(im * N[(0.5 * N[(N[Cos[re], $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Cos[re], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq -1.4 \lor \neg \left(im \leq 1.45\right):\\
\;\;\;\;im \cdot \left(0.5 \cdot \left(\cos re \cdot im\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\cos re\\
\end{array}
\end{array}
if im < -1.3999999999999999 or 1.44999999999999996 < im Initial program 100.0%
Taylor expanded in im around 0 51.6%
Simplified51.6%
Taylor expanded in im around inf 51.6%
unpow251.6%
associate-*r*51.6%
associate-*r*51.6%
*-commutative51.6%
*-commutative51.6%
Simplified51.6%
if -1.3999999999999999 < im < 1.44999999999999996Initial program 100.0%
Taylor expanded in im around 0 98.3%
Final simplification77.9%
(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 78.5%
Simplified78.5%
Taylor expanded in re around inf 78.5%
*-commutative78.5%
associate-*l*78.5%
unpow278.5%
distribute-lft1-in78.5%
+-commutative78.5%
unpow278.5%
*-commutative78.5%
unpow278.5%
Simplified78.5%
Final simplification78.5%
(FPCore (re im)
:precision binary64
(let* ((t_0 (+ (* 0.5 (* im im)) 1.0)))
(if (<= im -0.00046)
(* t_0 (+ 1.0 (* -0.5 (* re re))))
(if (<= im 0.00045) (cos re) t_0))))
double code(double re, double im) {
double t_0 = (0.5 * (im * im)) + 1.0;
double tmp;
if (im <= -0.00046) {
tmp = t_0 * (1.0 + (-0.5 * (re * re)));
} else if (im <= 0.00045) {
tmp = cos(re);
} 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 = (0.5d0 * (im * im)) + 1.0d0
if (im <= (-0.00046d0)) then
tmp = t_0 * (1.0d0 + ((-0.5d0) * (re * re)))
else if (im <= 0.00045d0) then
tmp = cos(re)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = (0.5 * (im * im)) + 1.0;
double tmp;
if (im <= -0.00046) {
tmp = t_0 * (1.0 + (-0.5 * (re * re)));
} else if (im <= 0.00045) {
tmp = Math.cos(re);
} else {
tmp = t_0;
}
return tmp;
}
def code(re, im): t_0 = (0.5 * (im * im)) + 1.0 tmp = 0 if im <= -0.00046: tmp = t_0 * (1.0 + (-0.5 * (re * re))) elif im <= 0.00045: tmp = math.cos(re) else: tmp = t_0 return tmp
function code(re, im) t_0 = Float64(Float64(0.5 * Float64(im * im)) + 1.0) tmp = 0.0 if (im <= -0.00046) tmp = Float64(t_0 * Float64(1.0 + Float64(-0.5 * Float64(re * re)))); elseif (im <= 0.00045) tmp = cos(re); else tmp = t_0; end return tmp end
function tmp_2 = code(re, im) t_0 = (0.5 * (im * im)) + 1.0; tmp = 0.0; if (im <= -0.00046) tmp = t_0 * (1.0 + (-0.5 * (re * re))); elseif (im <= 0.00045) tmp = cos(re); else tmp = t_0; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[im, -0.00046], N[(t$95$0 * N[(1.0 + N[(-0.5 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 0.00045], N[Cos[re], $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(im \cdot im\right) + 1\\
\mathbf{if}\;im \leq -0.00046:\\
\;\;\;\;t_0 \cdot \left(1 + -0.5 \cdot \left(re \cdot re\right)\right)\\
\mathbf{elif}\;im \leq 0.00045:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if im < -4.6000000000000001e-4Initial program 100.0%
Taylor expanded in im around 0 50.5%
Simplified50.5%
Taylor expanded in re around inf 50.5%
*-commutative50.5%
associate-*l*50.5%
unpow250.5%
distribute-lft1-in50.5%
+-commutative50.5%
unpow250.5%
*-commutative50.5%
unpow250.5%
Simplified50.5%
Taylor expanded in re around 0 43.3%
Simplified43.3%
if -4.6000000000000001e-4 < im < 4.4999999999999999e-4Initial program 100.0%
Taylor expanded in im around 0 99.4%
if 4.4999999999999999e-4 < im Initial program 100.0%
Taylor expanded in im around 0 54.1%
Simplified54.1%
Taylor expanded in re around 0 47.8%
*-commutative47.8%
unpow247.8%
Simplified47.8%
Final simplification75.1%
(FPCore (re im) :precision binary64 (if (or (<= im -1.45) (not (<= im 1.45))) (* 0.5 (* im im)) 1.0))
double code(double re, double im) {
double tmp;
if ((im <= -1.45) || !(im <= 1.45)) {
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 <= (-1.45d0)) .or. (.not. (im <= 1.45d0))) 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 <= -1.45) || !(im <= 1.45)) {
tmp = 0.5 * (im * im);
} else {
tmp = 1.0;
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= -1.45) or not (im <= 1.45): tmp = 0.5 * (im * im) else: tmp = 1.0 return tmp
function code(re, im) tmp = 0.0 if ((im <= -1.45) || !(im <= 1.45)) 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 <= -1.45) || ~((im <= 1.45))) tmp = 0.5 * (im * im); else tmp = 1.0; end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, -1.45], N[Not[LessEqual[im, 1.45]], $MachinePrecision]], N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq -1.45 \lor \neg \left(im \leq 1.45\right):\\
\;\;\;\;0.5 \cdot \left(im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if im < -1.44999999999999996 or 1.44999999999999996 < im Initial program 100.0%
Taylor expanded in im around 0 51.6%
Simplified51.6%
fma-udef51.6%
*-commutative51.6%
associate-*r*51.6%
Applied egg-rr51.6%
Taylor expanded in re around 0 43.0%
unpow243.0%
associate-*r*43.0%
*-commutative43.0%
Simplified43.0%
Taylor expanded in im around inf 43.0%
unpow243.0%
Simplified43.0%
if -1.44999999999999996 < im < 1.44999999999999996Initial program 100.0%
Taylor expanded in im around 0 98.3%
Taylor expanded in re around 0 50.1%
Final simplification47.0%
(FPCore (re im) :precision binary64 (+ (* 0.5 (* im im)) 1.0))
double code(double re, double im) {
return (0.5 * (im * im)) + 1.0;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * (im * im)) + 1.0d0
end function
public static double code(double re, double im) {
return (0.5 * (im * im)) + 1.0;
}
def code(re, im): return (0.5 * (im * im)) + 1.0
function code(re, im) return Float64(Float64(0.5 * Float64(im * im)) + 1.0) end
function tmp = code(re, im) tmp = (0.5 * (im * im)) + 1.0; end
code[re_, im_] := N[(N[(0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \left(im \cdot im\right) + 1
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 78.5%
Simplified78.5%
Taylor expanded in re around 0 47.5%
*-commutative47.5%
unpow247.5%
Simplified47.5%
Final simplification47.5%
(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.7%
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%
Taylor expanded in im around 0 56.6%
Taylor expanded in re around 0 29.4%
Final simplification29.4%
herbie shell --seed 2023172
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))