
(FPCore (re im) :precision binary64 (* (exp re) (cos im)))
double code(double re, double im) {
return exp(re) * cos(im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = exp(re) * cos(im)
end function
public static double code(double re, double im) {
return Math.exp(re) * Math.cos(im);
}
def code(re, im): return math.exp(re) * math.cos(im)
function code(re, im) return Float64(exp(re) * cos(im)) end
function tmp = code(re, im) tmp = exp(re) * cos(im); end
code[re_, im_] := N[(N[Exp[re], $MachinePrecision] * N[Cos[im], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{re} \cdot \cos im
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* (exp re) (cos im)))
double code(double re, double im) {
return exp(re) * cos(im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = exp(re) * cos(im)
end function
public static double code(double re, double im) {
return Math.exp(re) * Math.cos(im);
}
def code(re, im): return math.exp(re) * math.cos(im)
function code(re, im) return Float64(exp(re) * cos(im)) end
function tmp = code(re, im) tmp = exp(re) * cos(im); end
code[re_, im_] := N[(N[Exp[re], $MachinePrecision] * N[Cos[im], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{re} \cdot \cos im
\end{array}
(FPCore (re im) :precision binary64 (* (exp re) (cos im)))
double code(double re, double im) {
return exp(re) * cos(im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = exp(re) * cos(im)
end function
public static double code(double re, double im) {
return Math.exp(re) * Math.cos(im);
}
def code(re, im): return math.exp(re) * math.cos(im)
function code(re, im) return Float64(exp(re) * cos(im)) end
function tmp = code(re, im) tmp = exp(re) * cos(im); end
code[re_, im_] := N[(N[Exp[re], $MachinePrecision] * N[Cos[im], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{re} \cdot \cos im
\end{array}
Initial program 100.0%
(FPCore (re im)
:precision binary64
(if (<= re -0.026)
(exp re)
(if (or (<= re 1.3e-8) (not (<= re 1.05e+103)))
(*
(cos im)
(+ 1.0 (* re (+ 1.0 (* re (+ 0.5 (* re 0.16666666666666666)))))))
(pow E re))))
double code(double re, double im) {
double tmp;
if (re <= -0.026) {
tmp = exp(re);
} else if ((re <= 1.3e-8) || !(re <= 1.05e+103)) {
tmp = cos(im) * (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666))))));
} else {
tmp = pow(((double) M_E), re);
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= -0.026) {
tmp = Math.exp(re);
} else if ((re <= 1.3e-8) || !(re <= 1.05e+103)) {
tmp = Math.cos(im) * (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666))))));
} else {
tmp = Math.pow(Math.E, re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.026: tmp = math.exp(re) elif (re <= 1.3e-8) or not (re <= 1.05e+103): tmp = math.cos(im) * (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))) else: tmp = math.pow(math.e, re) return tmp
function code(re, im) tmp = 0.0 if (re <= -0.026) tmp = exp(re); elseif ((re <= 1.3e-8) || !(re <= 1.05e+103)) tmp = Float64(cos(im) * Float64(1.0 + Float64(re * Float64(1.0 + Float64(re * Float64(0.5 + Float64(re * 0.16666666666666666))))))); else tmp = exp(1) ^ re; end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -0.026) tmp = exp(re); elseif ((re <= 1.3e-8) || ~((re <= 1.05e+103))) tmp = cos(im) * (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))); else tmp = 2.71828182845904523536 ^ re; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.026], N[Exp[re], $MachinePrecision], If[Or[LessEqual[re, 1.3e-8], N[Not[LessEqual[re, 1.05e+103]], $MachinePrecision]], N[(N[Cos[im], $MachinePrecision] * N[(1.0 + N[(re * N[(1.0 + N[(re * N[(0.5 + N[(re * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[E, re], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.026:\\
\;\;\;\;e^{re}\\
\mathbf{elif}\;re \leq 1.3 \cdot 10^{-8} \lor \neg \left(re \leq 1.05 \cdot 10^{+103}\right):\\
\;\;\;\;\cos im \cdot \left(1 + re \cdot \left(1 + re \cdot \left(0.5 + re \cdot 0.16666666666666666\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;{e}^{re}\\
\end{array}
\end{array}
if re < -0.0259999999999999988Initial program 100.0%
Taylor expanded in im around 0 100.0%
if -0.0259999999999999988 < re < 1.3000000000000001e-8 or 1.0500000000000001e103 < re Initial program 100.0%
Taylor expanded in re around 0 99.9%
*-commutative99.9%
Simplified99.9%
if 1.3000000000000001e-8 < re < 1.0500000000000001e103Initial program 100.0%
Taylor expanded in im around 0 75.9%
*-un-lft-identity75.9%
exp-prod75.9%
exp-1-e75.9%
Applied egg-rr75.9%
Final simplification97.7%
(FPCore (re im) :precision binary64 (if (or (<= re -0.005) (and (not (<= re 1.3e-8)) (<= re 1.9e+154))) (exp re) (* (cos im) (+ 1.0 (* re (+ 1.0 (* re 0.5)))))))
double code(double re, double im) {
double tmp;
if ((re <= -0.005) || (!(re <= 1.3e-8) && (re <= 1.9e+154))) {
tmp = exp(re);
} else {
tmp = cos(im) * (1.0 + (re * (1.0 + (re * 0.5))));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((re <= (-0.005d0)) .or. (.not. (re <= 1.3d-8)) .and. (re <= 1.9d+154)) then
tmp = exp(re)
else
tmp = cos(im) * (1.0d0 + (re * (1.0d0 + (re * 0.5d0))))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((re <= -0.005) || (!(re <= 1.3e-8) && (re <= 1.9e+154))) {
tmp = Math.exp(re);
} else {
tmp = Math.cos(im) * (1.0 + (re * (1.0 + (re * 0.5))));
}
return tmp;
}
def code(re, im): tmp = 0 if (re <= -0.005) or (not (re <= 1.3e-8) and (re <= 1.9e+154)): tmp = math.exp(re) else: tmp = math.cos(im) * (1.0 + (re * (1.0 + (re * 0.5)))) return tmp
function code(re, im) tmp = 0.0 if ((re <= -0.005) || (!(re <= 1.3e-8) && (re <= 1.9e+154))) tmp = exp(re); else tmp = Float64(cos(im) * Float64(1.0 + Float64(re * Float64(1.0 + Float64(re * 0.5))))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((re <= -0.005) || (~((re <= 1.3e-8)) && (re <= 1.9e+154))) tmp = exp(re); else tmp = cos(im) * (1.0 + (re * (1.0 + (re * 0.5)))); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[re, -0.005], And[N[Not[LessEqual[re, 1.3e-8]], $MachinePrecision], LessEqual[re, 1.9e+154]]], N[Exp[re], $MachinePrecision], N[(N[Cos[im], $MachinePrecision] * N[(1.0 + N[(re * N[(1.0 + N[(re * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.005 \lor \neg \left(re \leq 1.3 \cdot 10^{-8}\right) \land re \leq 1.9 \cdot 10^{+154}:\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;\cos im \cdot \left(1 + re \cdot \left(1 + re \cdot 0.5\right)\right)\\
\end{array}
\end{array}
if re < -0.0050000000000000001 or 1.3000000000000001e-8 < re < 1.8999999999999999e154Initial program 100.0%
Taylor expanded in im around 0 88.3%
if -0.0050000000000000001 < re < 1.3000000000000001e-8 or 1.8999999999999999e154 < re Initial program 100.0%
Taylor expanded in re around 0 99.7%
*-commutative99.7%
Simplified99.7%
Final simplification95.6%
(FPCore (re im)
:precision binary64
(if (<= re -0.044)
(exp re)
(if (<= re 1.3e-8)
(* (cos im) (+ re 1.0))
(if (<= re 4.1e+105)
(pow E re)
(*
(+ 1.0 (* re (+ 1.0 (* re (+ 0.5 (* re 0.16666666666666666))))))
(+ 1.0 (* -0.5 (* im im))))))))
double code(double re, double im) {
double tmp;
if (re <= -0.044) {
tmp = exp(re);
} else if (re <= 1.3e-8) {
tmp = cos(im) * (re + 1.0);
} else if (re <= 4.1e+105) {
tmp = pow(((double) M_E), re);
} else {
tmp = (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))) * (1.0 + (-0.5 * (im * im)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= -0.044) {
tmp = Math.exp(re);
} else if (re <= 1.3e-8) {
tmp = Math.cos(im) * (re + 1.0);
} else if (re <= 4.1e+105) {
tmp = Math.pow(Math.E, re);
} else {
tmp = (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))) * (1.0 + (-0.5 * (im * im)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.044: tmp = math.exp(re) elif re <= 1.3e-8: tmp = math.cos(im) * (re + 1.0) elif re <= 4.1e+105: tmp = math.pow(math.e, re) else: tmp = (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))) * (1.0 + (-0.5 * (im * im))) return tmp
function code(re, im) tmp = 0.0 if (re <= -0.044) tmp = exp(re); elseif (re <= 1.3e-8) tmp = Float64(cos(im) * Float64(re + 1.0)); elseif (re <= 4.1e+105) tmp = exp(1) ^ re; else tmp = Float64(Float64(1.0 + Float64(re * Float64(1.0 + Float64(re * Float64(0.5 + Float64(re * 0.16666666666666666)))))) * Float64(1.0 + Float64(-0.5 * Float64(im * im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -0.044) tmp = exp(re); elseif (re <= 1.3e-8) tmp = cos(im) * (re + 1.0); elseif (re <= 4.1e+105) tmp = 2.71828182845904523536 ^ re; else tmp = (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))) * (1.0 + (-0.5 * (im * im))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.044], N[Exp[re], $MachinePrecision], If[LessEqual[re, 1.3e-8], N[(N[Cos[im], $MachinePrecision] * N[(re + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 4.1e+105], N[Power[E, re], $MachinePrecision], N[(N[(1.0 + N[(re * N[(1.0 + N[(re * N[(0.5 + N[(re * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(-0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.044:\\
\;\;\;\;e^{re}\\
\mathbf{elif}\;re \leq 1.3 \cdot 10^{-8}:\\
\;\;\;\;\cos im \cdot \left(re + 1\right)\\
\mathbf{elif}\;re \leq 4.1 \cdot 10^{+105}:\\
\;\;\;\;{e}^{re}\\
\mathbf{else}:\\
\;\;\;\;\left(1 + re \cdot \left(1 + re \cdot \left(0.5 + re \cdot 0.16666666666666666\right)\right)\right) \cdot \left(1 + -0.5 \cdot \left(im \cdot im\right)\right)\\
\end{array}
\end{array}
if re < -0.043999999999999997Initial program 100.0%
Taylor expanded in im around 0 100.0%
if -0.043999999999999997 < re < 1.3000000000000001e-8Initial program 100.0%
Taylor expanded in re around 0 99.3%
distribute-rgt1-in99.3%
Simplified99.3%
if 1.3000000000000001e-8 < re < 4.1000000000000002e105Initial program 100.0%
Taylor expanded in im around 0 75.9%
*-un-lft-identity75.9%
exp-prod75.9%
exp-1-e75.9%
Applied egg-rr75.9%
if 4.1000000000000002e105 < re Initial program 100.0%
Taylor expanded in re around 0 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in im around 0 84.1%
unpow284.1%
Applied egg-rr84.1%
Final simplification94.6%
(FPCore (re im)
:precision binary64
(if (<= re -0.0014)
(exp re)
(if (<= re 1.16e-8)
(cos im)
(if (<= re 1e+103)
(pow E re)
(*
(+ 1.0 (* re (+ 1.0 (* re (+ 0.5 (* re 0.16666666666666666))))))
(+ 1.0 (* -0.5 (* im im))))))))
double code(double re, double im) {
double tmp;
if (re <= -0.0014) {
tmp = exp(re);
} else if (re <= 1.16e-8) {
tmp = cos(im);
} else if (re <= 1e+103) {
tmp = pow(((double) M_E), re);
} else {
tmp = (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))) * (1.0 + (-0.5 * (im * im)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= -0.0014) {
tmp = Math.exp(re);
} else if (re <= 1.16e-8) {
tmp = Math.cos(im);
} else if (re <= 1e+103) {
tmp = Math.pow(Math.E, re);
} else {
tmp = (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))) * (1.0 + (-0.5 * (im * im)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.0014: tmp = math.exp(re) elif re <= 1.16e-8: tmp = math.cos(im) elif re <= 1e+103: tmp = math.pow(math.e, re) else: tmp = (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))) * (1.0 + (-0.5 * (im * im))) return tmp
function code(re, im) tmp = 0.0 if (re <= -0.0014) tmp = exp(re); elseif (re <= 1.16e-8) tmp = cos(im); elseif (re <= 1e+103) tmp = exp(1) ^ re; else tmp = Float64(Float64(1.0 + Float64(re * Float64(1.0 + Float64(re * Float64(0.5 + Float64(re * 0.16666666666666666)))))) * Float64(1.0 + Float64(-0.5 * Float64(im * im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -0.0014) tmp = exp(re); elseif (re <= 1.16e-8) tmp = cos(im); elseif (re <= 1e+103) tmp = 2.71828182845904523536 ^ re; else tmp = (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))) * (1.0 + (-0.5 * (im * im))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.0014], N[Exp[re], $MachinePrecision], If[LessEqual[re, 1.16e-8], N[Cos[im], $MachinePrecision], If[LessEqual[re, 1e+103], N[Power[E, re], $MachinePrecision], N[(N[(1.0 + N[(re * N[(1.0 + N[(re * N[(0.5 + N[(re * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(-0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.0014:\\
\;\;\;\;e^{re}\\
\mathbf{elif}\;re \leq 1.16 \cdot 10^{-8}:\\
\;\;\;\;\cos im\\
\mathbf{elif}\;re \leq 10^{+103}:\\
\;\;\;\;{e}^{re}\\
\mathbf{else}:\\
\;\;\;\;\left(1 + re \cdot \left(1 + re \cdot \left(0.5 + re \cdot 0.16666666666666666\right)\right)\right) \cdot \left(1 + -0.5 \cdot \left(im \cdot im\right)\right)\\
\end{array}
\end{array}
if re < -0.00139999999999999999Initial program 100.0%
Taylor expanded in im around 0 100.0%
if -0.00139999999999999999 < re < 1.15999999999999996e-8Initial program 100.0%
Taylor expanded in re around 0 98.6%
if 1.15999999999999996e-8 < re < 1e103Initial program 100.0%
Taylor expanded in im around 0 75.9%
*-un-lft-identity75.9%
exp-prod75.9%
exp-1-e75.9%
Applied egg-rr75.9%
if 1e103 < re Initial program 100.0%
Taylor expanded in re around 0 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in im around 0 84.1%
unpow284.1%
Applied egg-rr84.1%
(FPCore (re im)
:precision binary64
(if (<= re -0.0014)
(exp re)
(if (<= re 1.3e-8)
(cos im)
(if (<= re 1.05e+103)
(exp re)
(*
(+ 1.0 (* re (+ 1.0 (* re (+ 0.5 (* re 0.16666666666666666))))))
(+ 1.0 (* -0.5 (* im im))))))))
double code(double re, double im) {
double tmp;
if (re <= -0.0014) {
tmp = exp(re);
} else if (re <= 1.3e-8) {
tmp = cos(im);
} else if (re <= 1.05e+103) {
tmp = exp(re);
} else {
tmp = (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))) * (1.0 + (-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 (re <= (-0.0014d0)) then
tmp = exp(re)
else if (re <= 1.3d-8) then
tmp = cos(im)
else if (re <= 1.05d+103) then
tmp = exp(re)
else
tmp = (1.0d0 + (re * (1.0d0 + (re * (0.5d0 + (re * 0.16666666666666666d0)))))) * (1.0d0 + ((-0.5d0) * (im * im)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -0.0014) {
tmp = Math.exp(re);
} else if (re <= 1.3e-8) {
tmp = Math.cos(im);
} else if (re <= 1.05e+103) {
tmp = Math.exp(re);
} else {
tmp = (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))) * (1.0 + (-0.5 * (im * im)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.0014: tmp = math.exp(re) elif re <= 1.3e-8: tmp = math.cos(im) elif re <= 1.05e+103: tmp = math.exp(re) else: tmp = (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))) * (1.0 + (-0.5 * (im * im))) return tmp
function code(re, im) tmp = 0.0 if (re <= -0.0014) tmp = exp(re); elseif (re <= 1.3e-8) tmp = cos(im); elseif (re <= 1.05e+103) tmp = exp(re); else tmp = Float64(Float64(1.0 + Float64(re * Float64(1.0 + Float64(re * Float64(0.5 + Float64(re * 0.16666666666666666)))))) * Float64(1.0 + Float64(-0.5 * Float64(im * im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -0.0014) tmp = exp(re); elseif (re <= 1.3e-8) tmp = cos(im); elseif (re <= 1.05e+103) tmp = exp(re); else tmp = (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))) * (1.0 + (-0.5 * (im * im))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.0014], N[Exp[re], $MachinePrecision], If[LessEqual[re, 1.3e-8], N[Cos[im], $MachinePrecision], If[LessEqual[re, 1.05e+103], N[Exp[re], $MachinePrecision], N[(N[(1.0 + N[(re * N[(1.0 + N[(re * N[(0.5 + N[(re * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(-0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.0014:\\
\;\;\;\;e^{re}\\
\mathbf{elif}\;re \leq 1.3 \cdot 10^{-8}:\\
\;\;\;\;\cos im\\
\mathbf{elif}\;re \leq 1.05 \cdot 10^{+103}:\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;\left(1 + re \cdot \left(1 + re \cdot \left(0.5 + re \cdot 0.16666666666666666\right)\right)\right) \cdot \left(1 + -0.5 \cdot \left(im \cdot im\right)\right)\\
\end{array}
\end{array}
if re < -0.00139999999999999999 or 1.3000000000000001e-8 < re < 1.0500000000000001e103Initial program 100.0%
Taylor expanded in im around 0 92.8%
if -0.00139999999999999999 < re < 1.3000000000000001e-8Initial program 100.0%
Taylor expanded in re around 0 98.6%
if 1.0500000000000001e103 < re Initial program 100.0%
Taylor expanded in re around 0 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in im around 0 84.1%
unpow284.1%
Applied egg-rr84.1%
(FPCore (re im)
:precision binary64
(if (<= re 1.2e-8)
(cos im)
(*
(+ 1.0 (* re (+ 1.0 (* re (+ 0.5 (* re 0.16666666666666666))))))
(+ 1.0 (* -0.5 (* im im))))))
double code(double re, double im) {
double tmp;
if (re <= 1.2e-8) {
tmp = cos(im);
} else {
tmp = (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))) * (1.0 + (-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 (re <= 1.2d-8) then
tmp = cos(im)
else
tmp = (1.0d0 + (re * (1.0d0 + (re * (0.5d0 + (re * 0.16666666666666666d0)))))) * (1.0d0 + ((-0.5d0) * (im * im)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 1.2e-8) {
tmp = Math.cos(im);
} else {
tmp = (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))) * (1.0 + (-0.5 * (im * im)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 1.2e-8: tmp = math.cos(im) else: tmp = (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))) * (1.0 + (-0.5 * (im * im))) return tmp
function code(re, im) tmp = 0.0 if (re <= 1.2e-8) tmp = cos(im); else tmp = Float64(Float64(1.0 + Float64(re * Float64(1.0 + Float64(re * Float64(0.5 + Float64(re * 0.16666666666666666)))))) * Float64(1.0 + Float64(-0.5 * Float64(im * im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 1.2e-8) tmp = cos(im); else tmp = (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))) * (1.0 + (-0.5 * (im * im))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 1.2e-8], N[Cos[im], $MachinePrecision], N[(N[(1.0 + N[(re * N[(1.0 + N[(re * N[(0.5 + N[(re * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(-0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 1.2 \cdot 10^{-8}:\\
\;\;\;\;\cos im\\
\mathbf{else}:\\
\;\;\;\;\left(1 + re \cdot \left(1 + re \cdot \left(0.5 + re \cdot 0.16666666666666666\right)\right)\right) \cdot \left(1 + -0.5 \cdot \left(im \cdot im\right)\right)\\
\end{array}
\end{array}
if re < 1.19999999999999999e-8Initial program 100.0%
Taylor expanded in re around 0 70.2%
if 1.19999999999999999e-8 < re Initial program 100.0%
Taylor expanded in re around 0 68.8%
*-commutative68.8%
Simplified68.8%
Taylor expanded in im around 0 63.4%
unpow263.4%
Applied egg-rr63.4%
(FPCore (re im)
:precision binary64
(if (<= re 9e-41)
1.0
(*
(+ 1.0 (* re (+ 1.0 (* re (+ 0.5 (* re 0.16666666666666666))))))
(+ 1.0 (* -0.5 (* im im))))))
double code(double re, double im) {
double tmp;
if (re <= 9e-41) {
tmp = 1.0;
} else {
tmp = (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))) * (1.0 + (-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 (re <= 9d-41) then
tmp = 1.0d0
else
tmp = (1.0d0 + (re * (1.0d0 + (re * (0.5d0 + (re * 0.16666666666666666d0)))))) * (1.0d0 + ((-0.5d0) * (im * im)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 9e-41) {
tmp = 1.0;
} else {
tmp = (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))) * (1.0 + (-0.5 * (im * im)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 9e-41: tmp = 1.0 else: tmp = (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))) * (1.0 + (-0.5 * (im * im))) return tmp
function code(re, im) tmp = 0.0 if (re <= 9e-41) tmp = 1.0; else tmp = Float64(Float64(1.0 + Float64(re * Float64(1.0 + Float64(re * Float64(0.5 + Float64(re * 0.16666666666666666)))))) * Float64(1.0 + Float64(-0.5 * Float64(im * im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 9e-41) tmp = 1.0; else tmp = (1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))) * (1.0 + (-0.5 * (im * im))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 9e-41], 1.0, N[(N[(1.0 + N[(re * N[(1.0 + N[(re * N[(0.5 + N[(re * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(-0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 9 \cdot 10^{-41}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\left(1 + re \cdot \left(1 + re \cdot \left(0.5 + re \cdot 0.16666666666666666\right)\right)\right) \cdot \left(1 + -0.5 \cdot \left(im \cdot im\right)\right)\\
\end{array}
\end{array}
if re < 9e-41Initial program 100.0%
Taylor expanded in im around 0 68.0%
Taylor expanded in re around 0 38.3%
if 9e-41 < re Initial program 100.0%
Taylor expanded in re around 0 70.9%
*-commutative70.9%
Simplified70.9%
Taylor expanded in im around 0 60.6%
unpow260.6%
Applied egg-rr60.6%
(FPCore (re im) :precision binary64 (if (<= im 6.8e+135) (+ 1.0 (* re (+ 1.0 (* re (+ 0.5 (* re 0.16666666666666666)))))) (* (+ 1.0 (* re (+ 1.0 (* re 0.5)))) (+ 1.0 (* -0.5 (* im im))))))
double code(double re, double im) {
double tmp;
if (im <= 6.8e+135) {
tmp = 1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))));
} else {
tmp = (1.0 + (re * (1.0 + (re * 0.5)))) * (1.0 + (-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 <= 6.8d+135) then
tmp = 1.0d0 + (re * (1.0d0 + (re * (0.5d0 + (re * 0.16666666666666666d0)))))
else
tmp = (1.0d0 + (re * (1.0d0 + (re * 0.5d0)))) * (1.0d0 + ((-0.5d0) * (im * im)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 6.8e+135) {
tmp = 1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))));
} else {
tmp = (1.0 + (re * (1.0 + (re * 0.5)))) * (1.0 + (-0.5 * (im * im)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 6.8e+135: tmp = 1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666))))) else: tmp = (1.0 + (re * (1.0 + (re * 0.5)))) * (1.0 + (-0.5 * (im * im))) return tmp
function code(re, im) tmp = 0.0 if (im <= 6.8e+135) tmp = Float64(1.0 + Float64(re * Float64(1.0 + Float64(re * Float64(0.5 + Float64(re * 0.16666666666666666)))))); else tmp = Float64(Float64(1.0 + Float64(re * Float64(1.0 + Float64(re * 0.5)))) * Float64(1.0 + Float64(-0.5 * Float64(im * im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 6.8e+135) tmp = 1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666))))); else tmp = (1.0 + (re * (1.0 + (re * 0.5)))) * (1.0 + (-0.5 * (im * im))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 6.8e+135], N[(1.0 + N[(re * N[(1.0 + N[(re * N[(0.5 + N[(re * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(re * N[(1.0 + N[(re * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(-0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 6.8 \cdot 10^{+135}:\\
\;\;\;\;1 + re \cdot \left(1 + re \cdot \left(0.5 + re \cdot 0.16666666666666666\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 + re \cdot \left(1 + re \cdot 0.5\right)\right) \cdot \left(1 + -0.5 \cdot \left(im \cdot im\right)\right)\\
\end{array}
\end{array}
if im < 6.80000000000000019e135Initial program 100.0%
Taylor expanded in im around 0 74.0%
Taylor expanded in re around 0 45.1%
*-commutative69.8%
Simplified45.1%
if 6.80000000000000019e135 < im Initial program 100.0%
Taylor expanded in re around 0 66.6%
*-commutative66.6%
Simplified66.6%
Taylor expanded in im around 0 15.8%
unpow215.8%
Applied egg-rr15.8%
(FPCore (re im) :precision binary64 (+ 1.0 (* re (+ 1.0 (* re (+ 0.5 (* re 0.16666666666666666)))))))
double code(double re, double im) {
return 1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 1.0d0 + (re * (1.0d0 + (re * (0.5d0 + (re * 0.16666666666666666d0)))))
end function
public static double code(double re, double im) {
return 1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))));
}
def code(re, im): return 1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666)))))
function code(re, im) return Float64(1.0 + Float64(re * Float64(1.0 + Float64(re * Float64(0.5 + Float64(re * 0.16666666666666666)))))) end
function tmp = code(re, im) tmp = 1.0 + (re * (1.0 + (re * (0.5 + (re * 0.16666666666666666))))); end
code[re_, im_] := N[(1.0 + N[(re * N[(1.0 + N[(re * N[(0.5 + N[(re * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + re \cdot \left(1 + re \cdot \left(0.5 + re \cdot 0.16666666666666666\right)\right)
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 67.9%
Taylor expanded in re around 0 40.2%
*-commutative70.2%
Simplified40.2%
(FPCore (re im) :precision binary64 (+ 1.0 (* re (+ 1.0 (* re 0.5)))))
double code(double re, double im) {
return 1.0 + (re * (1.0 + (re * 0.5)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 1.0d0 + (re * (1.0d0 + (re * 0.5d0)))
end function
public static double code(double re, double im) {
return 1.0 + (re * (1.0 + (re * 0.5)));
}
def code(re, im): return 1.0 + (re * (1.0 + (re * 0.5)))
function code(re, im) return Float64(1.0 + Float64(re * Float64(1.0 + Float64(re * 0.5)))) end
function tmp = code(re, im) tmp = 1.0 + (re * (1.0 + (re * 0.5))); end
code[re_, im_] := N[(1.0 + N[(re * N[(1.0 + N[(re * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + re \cdot \left(1 + re \cdot 0.5\right)
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 67.9%
Taylor expanded in re around 0 37.6%
*-commutative65.5%
Simplified37.6%
(FPCore (re im) :precision binary64 (+ re 1.0))
double code(double re, double im) {
return re + 1.0;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = re + 1.0d0
end function
public static double code(double re, double im) {
return re + 1.0;
}
def code(re, im): return re + 1.0
function code(re, im) return Float64(re + 1.0) end
function tmp = code(re, im) tmp = re + 1.0; end
code[re_, im_] := N[(re + 1.0), $MachinePrecision]
\begin{array}{l}
\\
re + 1
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 53.7%
distribute-rgt1-in53.7%
Simplified53.7%
Taylor expanded in im around 0 29.2%
+-commutative29.2%
Simplified29.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 im around 0 67.9%
Taylor expanded in re around 0 28.7%
herbie shell --seed 2024158
(FPCore (re im)
:name "math.exp on complex, real part"
:precision binary64
(* (exp re) (cos im)))