
(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 11 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}
NOTE: im should be positive before calling this function (FPCore (re im) :precision binary64 (* (cos re) (fma 0.5 (exp im) (/ 0.5 (exp im)))))
im = abs(im);
double code(double re, double im) {
return cos(re) * fma(0.5, exp(im), (0.5 / exp(im)));
}
im = abs(im) function code(re, im) return Float64(cos(re) * fma(0.5, exp(im), Float64(0.5 / exp(im)))) end
NOTE: im should be positive before calling this function code[re_, im_] := N[(N[Cos[re], $MachinePrecision] * N[(0.5 * N[Exp[im], $MachinePrecision] + N[(0.5 / N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im = |im|\\
\\
\cos re \cdot \mathsf{fma}\left(0.5, e^{im}, \frac{0.5}{e^{im}}\right)
\end{array}
Initial program 100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-lft-in100.0%
distribute-lft-in100.0%
distribute-rgt-in100.0%
*-commutative100.0%
fma-def100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.0%
NOTE: im should be positive before calling this function (FPCore (re im) :precision binary64 (* (* (cos re) 0.5) (+ (exp im) (exp (- im)))))
im = abs(im);
double code(double re, double im) {
return (cos(re) * 0.5) * (exp(im) + exp(-im));
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (cos(re) * 0.5d0) * (exp(im) + exp(-im))
end function
im = Math.abs(im);
public static double code(double re, double im) {
return (Math.cos(re) * 0.5) * (Math.exp(im) + Math.exp(-im));
}
im = abs(im) def code(re, im): return (math.cos(re) * 0.5) * (math.exp(im) + math.exp(-im))
im = abs(im) function code(re, im) return Float64(Float64(cos(re) * 0.5) * Float64(exp(im) + exp(Float64(-im)))) end
im = abs(im) function tmp = code(re, im) tmp = (cos(re) * 0.5) * (exp(im) + exp(-im)); end
NOTE: im should be positive before calling this function code[re_, im_] := N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(N[Exp[im], $MachinePrecision] + N[Exp[(-im)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im = |im|\\
\\
\left(\cos re \cdot 0.5\right) \cdot \left(e^{im} + e^{-im}\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
NOTE: im should be positive before calling this function (FPCore (re im) :precision binary64 (if (or (<= im 14000.0) (not (<= im 2e+154))) (* (* (cos re) 0.5) (+ 2.0 (* im im))) (* 0.5 (+ (exp im) (exp (- im))))))
im = abs(im);
double code(double re, double im) {
double tmp;
if ((im <= 14000.0) || !(im <= 2e+154)) {
tmp = (cos(re) * 0.5) * (2.0 + (im * im));
} else {
tmp = 0.5 * (exp(im) + exp(-im));
}
return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((im <= 14000.0d0) .or. (.not. (im <= 2d+154))) then
tmp = (cos(re) * 0.5d0) * (2.0d0 + (im * im))
else
tmp = 0.5d0 * (exp(im) + exp(-im))
end if
code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
double tmp;
if ((im <= 14000.0) || !(im <= 2e+154)) {
tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
} else {
tmp = 0.5 * (Math.exp(im) + Math.exp(-im));
}
return tmp;
}
im = abs(im) def code(re, im): tmp = 0 if (im <= 14000.0) or not (im <= 2e+154): tmp = (math.cos(re) * 0.5) * (2.0 + (im * im)) else: tmp = 0.5 * (math.exp(im) + math.exp(-im)) return tmp
im = abs(im) function code(re, im) tmp = 0.0 if ((im <= 14000.0) || !(im <= 2e+154)) tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im))); else tmp = Float64(0.5 * Float64(exp(im) + exp(Float64(-im)))); end return tmp end
im = abs(im) function tmp_2 = code(re, im) tmp = 0.0; if ((im <= 14000.0) || ~((im <= 2e+154))) tmp = (cos(re) * 0.5) * (2.0 + (im * im)); else tmp = 0.5 * (exp(im) + exp(-im)); end tmp_2 = tmp; end
NOTE: im should be positive before calling this function code[re_, im_] := If[Or[LessEqual[im, 14000.0], N[Not[LessEqual[im, 2e+154]], $MachinePrecision]], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[Exp[im], $MachinePrecision] + N[Exp[(-im)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;im \leq 14000 \lor \neg \left(im \leq 2 \cdot 10^{+154}\right):\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(e^{im} + e^{-im}\right)\\
\end{array}
\end{array}
if im < 14000 or 2.00000000000000007e154 < im Initial program 100.0%
Taylor expanded in im around 0 87.0%
unpow287.0%
Simplified87.0%
if 14000 < im < 2.00000000000000007e154Initial program 100.0%
Taylor expanded in re around 0 83.3%
Final simplification86.6%
NOTE: im should be positive before calling this function (FPCore (re im) :precision binary64 (* (cos re) (+ 0.5 (* 0.5 (exp im)))))
im = abs(im);
double code(double re, double im) {
return cos(re) * (0.5 + (0.5 * exp(im)));
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = cos(re) * (0.5d0 + (0.5d0 * exp(im)))
end function
im = Math.abs(im);
public static double code(double re, double im) {
return Math.cos(re) * (0.5 + (0.5 * Math.exp(im)));
}
im = abs(im) def code(re, im): return math.cos(re) * (0.5 + (0.5 * math.exp(im)))
im = abs(im) function code(re, im) return Float64(cos(re) * Float64(0.5 + Float64(0.5 * exp(im)))) end
im = abs(im) function tmp = code(re, im) tmp = cos(re) * (0.5 + (0.5 * exp(im))); end
NOTE: im should be positive before calling this function code[re_, im_] := N[(N[Cos[re], $MachinePrecision] * N[(0.5 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im = |im|\\
\\
\cos re \cdot \left(0.5 + 0.5 \cdot e^{im}\right)
\end{array}
Initial program 100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-lft-in100.0%
distribute-lft-in100.0%
distribute-rgt-in100.0%
*-commutative100.0%
fma-def100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 77.0%
Taylor expanded in re around inf 77.0%
Final simplification77.0%
NOTE: im should be positive before calling this function (FPCore (re im) :precision binary64 (if (or (<= im 14000.0) (not (<= im 1.35e+154))) (* (* (cos re) 0.5) (+ 2.0 (* im im))) (+ 0.5 (* 0.5 (exp im)))))
im = abs(im);
double code(double re, double im) {
double tmp;
if ((im <= 14000.0) || !(im <= 1.35e+154)) {
tmp = (cos(re) * 0.5) * (2.0 + (im * im));
} else {
tmp = 0.5 + (0.5 * exp(im));
}
return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((im <= 14000.0d0) .or. (.not. (im <= 1.35d+154))) then
tmp = (cos(re) * 0.5d0) * (2.0d0 + (im * im))
else
tmp = 0.5d0 + (0.5d0 * exp(im))
end if
code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
double tmp;
if ((im <= 14000.0) || !(im <= 1.35e+154)) {
tmp = (Math.cos(re) * 0.5) * (2.0 + (im * im));
} else {
tmp = 0.5 + (0.5 * Math.exp(im));
}
return tmp;
}
im = abs(im) def code(re, im): tmp = 0 if (im <= 14000.0) or not (im <= 1.35e+154): tmp = (math.cos(re) * 0.5) * (2.0 + (im * im)) else: tmp = 0.5 + (0.5 * math.exp(im)) return tmp
im = abs(im) function code(re, im) tmp = 0.0 if ((im <= 14000.0) || !(im <= 1.35e+154)) tmp = Float64(Float64(cos(re) * 0.5) * Float64(2.0 + Float64(im * im))); else tmp = Float64(0.5 + Float64(0.5 * exp(im))); end return tmp end
im = abs(im) function tmp_2 = code(re, im) tmp = 0.0; if ((im <= 14000.0) || ~((im <= 1.35e+154))) tmp = (cos(re) * 0.5) * (2.0 + (im * im)); else tmp = 0.5 + (0.5 * exp(im)); end tmp_2 = tmp; end
NOTE: im should be positive before calling this function code[re_, im_] := If[Or[LessEqual[im, 14000.0], N[Not[LessEqual[im, 1.35e+154]], $MachinePrecision]], N[(N[(N[Cos[re], $MachinePrecision] * 0.5), $MachinePrecision] * N[(2.0 + N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;im \leq 14000 \lor \neg \left(im \leq 1.35 \cdot 10^{+154}\right):\\
\;\;\;\;\left(\cos re \cdot 0.5\right) \cdot \left(2 + im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 + 0.5 \cdot e^{im}\\
\end{array}
\end{array}
if im < 14000 or 1.35000000000000003e154 < im Initial program 100.0%
Taylor expanded in im around 0 87.0%
unpow287.0%
Simplified87.0%
if 14000 < im < 1.35000000000000003e154Initial program 100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-lft-in100.0%
distribute-lft-in100.0%
distribute-rgt-in100.0%
*-commutative100.0%
fma-def100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in re around 0 83.3%
Final simplification86.6%
NOTE: im should be positive before calling this function (FPCore (re im) :precision binary64 (if (<= im 14000.0) (cos re) (+ 0.5 (* 0.5 (exp im)))))
im = abs(im);
double code(double re, double im) {
double tmp;
if (im <= 14000.0) {
tmp = cos(re);
} else {
tmp = 0.5 + (0.5 * exp(im));
}
return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 14000.0d0) then
tmp = cos(re)
else
tmp = 0.5d0 + (0.5d0 * exp(im))
end if
code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
double tmp;
if (im <= 14000.0) {
tmp = Math.cos(re);
} else {
tmp = 0.5 + (0.5 * Math.exp(im));
}
return tmp;
}
im = abs(im) def code(re, im): tmp = 0 if im <= 14000.0: tmp = math.cos(re) else: tmp = 0.5 + (0.5 * math.exp(im)) return tmp
im = abs(im) function code(re, im) tmp = 0.0 if (im <= 14000.0) tmp = cos(re); else tmp = Float64(0.5 + Float64(0.5 * exp(im))); end return tmp end
im = abs(im) function tmp_2 = code(re, im) tmp = 0.0; if (im <= 14000.0) tmp = cos(re); else tmp = 0.5 + (0.5 * exp(im)); end tmp_2 = tmp; end
NOTE: im should be positive before calling this function code[re_, im_] := If[LessEqual[im, 14000.0], N[Cos[re], $MachinePrecision], N[(0.5 + N[(0.5 * N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;im \leq 14000:\\
\;\;\;\;\cos re\\
\mathbf{else}:\\
\;\;\;\;0.5 + 0.5 \cdot e^{im}\\
\end{array}
\end{array}
if im < 14000Initial program 100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-lft-in100.0%
distribute-lft-in100.0%
distribute-rgt-in100.0%
*-commutative100.0%
fma-def100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 69.8%
if 14000 < im Initial program 100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-lft-in100.0%
distribute-lft-in100.0%
distribute-rgt-in100.0%
*-commutative100.0%
fma-def100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in re around 0 79.4%
Final simplification72.1%
NOTE: im should be positive before calling this function
(FPCore (re im)
:precision binary64
(if (<= im 160000000.0)
(cos re)
(if (<= im 2.7e+154)
(+
1.0
(/
(* (* im im) (- 0.25 (* (* im im) 0.0625)))
(* im (- 0.5 (* im 0.25)))))
(+ 1.0 (* im (* im 0.25))))))im = abs(im);
double code(double re, double im) {
double tmp;
if (im <= 160000000.0) {
tmp = cos(re);
} else if (im <= 2.7e+154) {
tmp = 1.0 + (((im * im) * (0.25 - ((im * im) * 0.0625))) / (im * (0.5 - (im * 0.25))));
} else {
tmp = 1.0 + (im * (im * 0.25));
}
return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 160000000.0d0) then
tmp = cos(re)
else if (im <= 2.7d+154) then
tmp = 1.0d0 + (((im * im) * (0.25d0 - ((im * im) * 0.0625d0))) / (im * (0.5d0 - (im * 0.25d0))))
else
tmp = 1.0d0 + (im * (im * 0.25d0))
end if
code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
double tmp;
if (im <= 160000000.0) {
tmp = Math.cos(re);
} else if (im <= 2.7e+154) {
tmp = 1.0 + (((im * im) * (0.25 - ((im * im) * 0.0625))) / (im * (0.5 - (im * 0.25))));
} else {
tmp = 1.0 + (im * (im * 0.25));
}
return tmp;
}
im = abs(im) def code(re, im): tmp = 0 if im <= 160000000.0: tmp = math.cos(re) elif im <= 2.7e+154: tmp = 1.0 + (((im * im) * (0.25 - ((im * im) * 0.0625))) / (im * (0.5 - (im * 0.25)))) else: tmp = 1.0 + (im * (im * 0.25)) return tmp
im = abs(im) function code(re, im) tmp = 0.0 if (im <= 160000000.0) tmp = cos(re); elseif (im <= 2.7e+154) tmp = Float64(1.0 + Float64(Float64(Float64(im * im) * Float64(0.25 - Float64(Float64(im * im) * 0.0625))) / Float64(im * Float64(0.5 - Float64(im * 0.25))))); else tmp = Float64(1.0 + Float64(im * Float64(im * 0.25))); end return tmp end
im = abs(im) function tmp_2 = code(re, im) tmp = 0.0; if (im <= 160000000.0) tmp = cos(re); elseif (im <= 2.7e+154) tmp = 1.0 + (((im * im) * (0.25 - ((im * im) * 0.0625))) / (im * (0.5 - (im * 0.25)))); else tmp = 1.0 + (im * (im * 0.25)); end tmp_2 = tmp; end
NOTE: im should be positive before calling this function code[re_, im_] := If[LessEqual[im, 160000000.0], N[Cos[re], $MachinePrecision], If[LessEqual[im, 2.7e+154], N[(1.0 + N[(N[(N[(im * im), $MachinePrecision] * N[(0.25 - N[(N[(im * im), $MachinePrecision] * 0.0625), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(im * N[(0.5 - N[(im * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(im * N[(im * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;im \leq 160000000:\\
\;\;\;\;\cos re\\
\mathbf{elif}\;im \leq 2.7 \cdot 10^{+154}:\\
\;\;\;\;1 + \frac{\left(im \cdot im\right) \cdot \left(0.25 - \left(im \cdot im\right) \cdot 0.0625\right)}{im \cdot \left(0.5 - im \cdot 0.25\right)}\\
\mathbf{else}:\\
\;\;\;\;1 + im \cdot \left(im \cdot 0.25\right)\\
\end{array}
\end{array}
if im < 1.6e8Initial program 100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-lft-in100.0%
distribute-lft-in100.0%
distribute-rgt-in100.0%
*-commutative100.0%
fma-def100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 69.8%
if 1.6e8 < im < 2.70000000000000006e154Initial program 100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-lft-in100.0%
distribute-lft-in100.0%
distribute-rgt-in100.0%
*-commutative100.0%
fma-def100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in re around 0 83.3%
Taylor expanded in im around 0 3.8%
+-commutative3.8%
unpow23.8%
associate-*r*3.8%
distribute-rgt-out3.8%
Simplified3.8%
distribute-lft-in3.8%
*-commutative3.8%
flip-+27.2%
*-commutative27.2%
*-commutative27.2%
swap-sqr27.2%
metadata-eval27.2%
associate-*r*27.2%
*-commutative27.2%
*-commutative27.2%
*-commutative27.2%
Applied egg-rr27.2%
associate-*r*27.2%
swap-sqr27.2%
unpow227.2%
distribute-lft-out--27.2%
unpow227.2%
swap-sqr27.2%
metadata-eval27.2%
*-commutative27.2%
distribute-lft-out--27.2%
Simplified27.2%
if 2.70000000000000006e154 < im Initial program 100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-lft-in100.0%
distribute-lft-in100.0%
distribute-rgt-in100.0%
*-commutative100.0%
fma-def100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in re around 0 76.9%
Taylor expanded in im around 0 76.9%
+-commutative76.9%
unpow276.9%
associate-*r*76.9%
distribute-rgt-out76.9%
Simplified76.9%
Taylor expanded in im around inf 76.9%
unpow276.9%
*-commutative76.9%
associate-*r*76.9%
Simplified76.9%
Final simplification66.9%
NOTE: im should be positive before calling this function
(FPCore (re im)
:precision binary64
(if (<= im 2.7e+154)
(+
1.0
(/ (* (* im im) (- 0.25 (* (* im im) 0.0625))) (* im (- 0.5 (* im 0.25)))))
(+ 1.0 (* im (* im 0.25)))))im = abs(im);
double code(double re, double im) {
double tmp;
if (im <= 2.7e+154) {
tmp = 1.0 + (((im * im) * (0.25 - ((im * im) * 0.0625))) / (im * (0.5 - (im * 0.25))));
} else {
tmp = 1.0 + (im * (im * 0.25));
}
return tmp;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 2.7d+154) then
tmp = 1.0d0 + (((im * im) * (0.25d0 - ((im * im) * 0.0625d0))) / (im * (0.5d0 - (im * 0.25d0))))
else
tmp = 1.0d0 + (im * (im * 0.25d0))
end if
code = tmp
end function
im = Math.abs(im);
public static double code(double re, double im) {
double tmp;
if (im <= 2.7e+154) {
tmp = 1.0 + (((im * im) * (0.25 - ((im * im) * 0.0625))) / (im * (0.5 - (im * 0.25))));
} else {
tmp = 1.0 + (im * (im * 0.25));
}
return tmp;
}
im = abs(im) def code(re, im): tmp = 0 if im <= 2.7e+154: tmp = 1.0 + (((im * im) * (0.25 - ((im * im) * 0.0625))) / (im * (0.5 - (im * 0.25)))) else: tmp = 1.0 + (im * (im * 0.25)) return tmp
im = abs(im) function code(re, im) tmp = 0.0 if (im <= 2.7e+154) tmp = Float64(1.0 + Float64(Float64(Float64(im * im) * Float64(0.25 - Float64(Float64(im * im) * 0.0625))) / Float64(im * Float64(0.5 - Float64(im * 0.25))))); else tmp = Float64(1.0 + Float64(im * Float64(im * 0.25))); end return tmp end
im = abs(im) function tmp_2 = code(re, im) tmp = 0.0; if (im <= 2.7e+154) tmp = 1.0 + (((im * im) * (0.25 - ((im * im) * 0.0625))) / (im * (0.5 - (im * 0.25)))); else tmp = 1.0 + (im * (im * 0.25)); end tmp_2 = tmp; end
NOTE: im should be positive before calling this function code[re_, im_] := If[LessEqual[im, 2.7e+154], N[(1.0 + N[(N[(N[(im * im), $MachinePrecision] * N[(0.25 - N[(N[(im * im), $MachinePrecision] * 0.0625), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(im * N[(0.5 - N[(im * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(im * N[(im * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im = |im|\\
\\
\begin{array}{l}
\mathbf{if}\;im \leq 2.7 \cdot 10^{+154}:\\
\;\;\;\;1 + \frac{\left(im \cdot im\right) \cdot \left(0.25 - \left(im \cdot im\right) \cdot 0.0625\right)}{im \cdot \left(0.5 - im \cdot 0.25\right)}\\
\mathbf{else}:\\
\;\;\;\;1 + im \cdot \left(im \cdot 0.25\right)\\
\end{array}
\end{array}
if im < 2.70000000000000006e154Initial program 100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-lft-in100.0%
distribute-lft-in100.0%
distribute-rgt-in100.0%
*-commutative100.0%
fma-def100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 72.8%
Taylor expanded in re around 0 45.5%
Taylor expanded in im around 0 47.3%
+-commutative47.3%
unpow247.3%
associate-*r*47.3%
distribute-rgt-out47.3%
Simplified47.3%
distribute-lft-in47.3%
*-commutative47.3%
flip-+44.8%
*-commutative44.8%
*-commutative44.8%
swap-sqr44.8%
metadata-eval44.8%
associate-*r*44.8%
*-commutative44.8%
*-commutative44.8%
*-commutative44.8%
Applied egg-rr44.8%
associate-*r*44.8%
swap-sqr44.8%
unpow244.8%
distribute-lft-out--44.8%
unpow244.8%
swap-sqr44.8%
metadata-eval44.8%
*-commutative44.8%
distribute-lft-out--44.8%
Simplified44.8%
if 2.70000000000000006e154 < im Initial program 100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-lft-in100.0%
distribute-lft-in100.0%
distribute-rgt-in100.0%
*-commutative100.0%
fma-def100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in re around 0 76.9%
Taylor expanded in im around 0 76.9%
+-commutative76.9%
unpow276.9%
associate-*r*76.9%
distribute-rgt-out76.9%
Simplified76.9%
Taylor expanded in im around inf 76.9%
unpow276.9%
*-commutative76.9%
associate-*r*76.9%
Simplified76.9%
Final simplification49.7%
NOTE: im should be positive before calling this function (FPCore (re im) :precision binary64 (+ 1.0 (* im (* im 0.25))))
im = abs(im);
double code(double re, double im) {
return 1.0 + (im * (im * 0.25));
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 1.0d0 + (im * (im * 0.25d0))
end function
im = Math.abs(im);
public static double code(double re, double im) {
return 1.0 + (im * (im * 0.25));
}
im = abs(im) def code(re, im): return 1.0 + (im * (im * 0.25))
im = abs(im) function code(re, im) return Float64(1.0 + Float64(im * Float64(im * 0.25))) end
im = abs(im) function tmp = code(re, im) tmp = 1.0 + (im * (im * 0.25)); end
NOTE: im should be positive before calling this function code[re_, im_] := N[(1.0 + N[(im * N[(im * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im = |im|\\
\\
1 + im \cdot \left(im \cdot 0.25\right)
\end{array}
Initial program 100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-lft-in100.0%
distribute-lft-in100.0%
distribute-rgt-in100.0%
*-commutative100.0%
fma-def100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 77.0%
Taylor expanded in re around 0 50.3%
Taylor expanded in im around 0 51.8%
+-commutative51.8%
unpow251.8%
associate-*r*51.8%
distribute-rgt-out51.8%
Simplified51.8%
Taylor expanded in im around inf 52.1%
unpow252.1%
*-commutative52.1%
associate-*r*52.1%
Simplified52.1%
Final simplification52.1%
NOTE: im should be positive before calling this function (FPCore (re im) :precision binary64 (+ 1.0 (* 0.5 im)))
im = abs(im);
double code(double re, double im) {
return 1.0 + (0.5 * im);
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 1.0d0 + (0.5d0 * im)
end function
im = Math.abs(im);
public static double code(double re, double im) {
return 1.0 + (0.5 * im);
}
im = abs(im) def code(re, im): return 1.0 + (0.5 * im)
im = abs(im) function code(re, im) return Float64(1.0 + Float64(0.5 * im)) end
im = abs(im) function tmp = code(re, im) tmp = 1.0 + (0.5 * im); end
NOTE: im should be positive before calling this function code[re_, im_] := N[(1.0 + N[(0.5 * im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im = |im|\\
\\
1 + 0.5 \cdot im
\end{array}
Initial program 100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-lft-in100.0%
distribute-lft-in100.0%
distribute-rgt-in100.0%
*-commutative100.0%
fma-def100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 77.0%
Taylor expanded in re around 0 50.3%
Taylor expanded in im around 0 31.6%
Final simplification31.6%
NOTE: im should be positive before calling this function (FPCore (re im) :precision binary64 1.0)
im = abs(im);
double code(double re, double im) {
return 1.0;
}
NOTE: im should be positive before calling this function
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 1.0d0
end function
im = Math.abs(im);
public static double code(double re, double im) {
return 1.0;
}
im = abs(im) def code(re, im): return 1.0
im = abs(im) function code(re, im) return 1.0 end
im = abs(im) function tmp = code(re, im) tmp = 1.0; end
NOTE: im should be positive before calling this function code[re_, im_] := 1.0
\begin{array}{l}
im = |im|\\
\\
1
\end{array}
Initial program 100.0%
*-commutative100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-lft-in100.0%
distribute-lft-in100.0%
distribute-rgt-in100.0%
*-commutative100.0%
fma-def100.0%
exp-neg100.0%
associate-*l/100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in im around 0 77.0%
Taylor expanded in re around 0 50.3%
Taylor expanded in im around 0 31.7%
Final simplification31.7%
herbie shell --seed 2023188
(FPCore (re im)
:name "math.cos on complex, real part"
:precision binary64
(* (* 0.5 (cos re)) (+ (exp (- im)) (exp im))))