
(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 7 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%
Final simplification100.0%
(FPCore (re im) :precision binary64 (if (or (<= (exp re) 0.999) (not (<= (exp re) 1.000000000002))) (exp re) (* (cos im) (+ re 1.0))))
double code(double re, double im) {
double tmp;
if ((exp(re) <= 0.999) || !(exp(re) <= 1.000000000002)) {
tmp = exp(re);
} else {
tmp = cos(im) * (re + 1.0);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((exp(re) <= 0.999d0) .or. (.not. (exp(re) <= 1.000000000002d0))) then
tmp = exp(re)
else
tmp = cos(im) * (re + 1.0d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((Math.exp(re) <= 0.999) || !(Math.exp(re) <= 1.000000000002)) {
tmp = Math.exp(re);
} else {
tmp = Math.cos(im) * (re + 1.0);
}
return tmp;
}
def code(re, im): tmp = 0 if (math.exp(re) <= 0.999) or not (math.exp(re) <= 1.000000000002): tmp = math.exp(re) else: tmp = math.cos(im) * (re + 1.0) return tmp
function code(re, im) tmp = 0.0 if ((exp(re) <= 0.999) || !(exp(re) <= 1.000000000002)) tmp = exp(re); else tmp = Float64(cos(im) * Float64(re + 1.0)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((exp(re) <= 0.999) || ~((exp(re) <= 1.000000000002))) tmp = exp(re); else tmp = cos(im) * (re + 1.0); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[N[Exp[re], $MachinePrecision], 0.999], N[Not[LessEqual[N[Exp[re], $MachinePrecision], 1.000000000002]], $MachinePrecision]], N[Exp[re], $MachinePrecision], N[(N[Cos[im], $MachinePrecision] * N[(re + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{re} \leq 0.999 \lor \neg \left(e^{re} \leq 1.000000000002\right):\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;\cos im \cdot \left(re + 1\right)\\
\end{array}
\end{array}
if (exp.f64 re) < 0.998999999999999999 or 1.00000000000199996 < (exp.f64 re) Initial program 100.0%
Taylor expanded in im around 0 86.1%
if 0.998999999999999999 < (exp.f64 re) < 1.00000000000199996Initial program 100.0%
Taylor expanded in re around 0 99.8%
distribute-rgt1-in99.8%
Simplified99.8%
Final simplification92.5%
(FPCore (re im) :precision binary64 (if (or (<= (exp re) 0.999) (not (<= (exp re) 1.000000000002))) (exp re) (cos im)))
double code(double re, double im) {
double tmp;
if ((exp(re) <= 0.999) || !(exp(re) <= 1.000000000002)) {
tmp = exp(re);
} else {
tmp = cos(im);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((exp(re) <= 0.999d0) .or. (.not. (exp(re) <= 1.000000000002d0))) then
tmp = exp(re)
else
tmp = cos(im)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((Math.exp(re) <= 0.999) || !(Math.exp(re) <= 1.000000000002)) {
tmp = Math.exp(re);
} else {
tmp = Math.cos(im);
}
return tmp;
}
def code(re, im): tmp = 0 if (math.exp(re) <= 0.999) or not (math.exp(re) <= 1.000000000002): tmp = math.exp(re) else: tmp = math.cos(im) return tmp
function code(re, im) tmp = 0.0 if ((exp(re) <= 0.999) || !(exp(re) <= 1.000000000002)) tmp = exp(re); else tmp = cos(im); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((exp(re) <= 0.999) || ~((exp(re) <= 1.000000000002))) tmp = exp(re); else tmp = cos(im); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[N[Exp[re], $MachinePrecision], 0.999], N[Not[LessEqual[N[Exp[re], $MachinePrecision], 1.000000000002]], $MachinePrecision]], N[Exp[re], $MachinePrecision], N[Cos[im], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{re} \leq 0.999 \lor \neg \left(e^{re} \leq 1.000000000002\right):\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;\cos im\\
\end{array}
\end{array}
if (exp.f64 re) < 0.998999999999999999 or 1.00000000000199996 < (exp.f64 re) Initial program 100.0%
Taylor expanded in im around 0 86.1%
if 0.998999999999999999 < (exp.f64 re) < 1.00000000000199996Initial program 100.0%
Taylor expanded in re around 0 98.7%
Final simplification92.0%
(FPCore (re im) :precision binary64 (if (or (<= re -0.00185) (and (not (<= re 4e-12)) (<= re 2.9e+149))) (exp re) (* (cos im) (+ (* re (* re 0.5)) (+ re 1.0)))))
double code(double re, double im) {
double tmp;
if ((re <= -0.00185) || (!(re <= 4e-12) && (re <= 2.9e+149))) {
tmp = exp(re);
} else {
tmp = cos(im) * ((re * (re * 0.5)) + (re + 1.0));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((re <= (-0.00185d0)) .or. (.not. (re <= 4d-12)) .and. (re <= 2.9d+149)) then
tmp = exp(re)
else
tmp = cos(im) * ((re * (re * 0.5d0)) + (re + 1.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((re <= -0.00185) || (!(re <= 4e-12) && (re <= 2.9e+149))) {
tmp = Math.exp(re);
} else {
tmp = Math.cos(im) * ((re * (re * 0.5)) + (re + 1.0));
}
return tmp;
}
def code(re, im): tmp = 0 if (re <= -0.00185) or (not (re <= 4e-12) and (re <= 2.9e+149)): tmp = math.exp(re) else: tmp = math.cos(im) * ((re * (re * 0.5)) + (re + 1.0)) return tmp
function code(re, im) tmp = 0.0 if ((re <= -0.00185) || (!(re <= 4e-12) && (re <= 2.9e+149))) tmp = exp(re); else tmp = Float64(cos(im) * Float64(Float64(re * Float64(re * 0.5)) + Float64(re + 1.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((re <= -0.00185) || (~((re <= 4e-12)) && (re <= 2.9e+149))) tmp = exp(re); else tmp = cos(im) * ((re * (re * 0.5)) + (re + 1.0)); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[re, -0.00185], And[N[Not[LessEqual[re, 4e-12]], $MachinePrecision], LessEqual[re, 2.9e+149]]], N[Exp[re], $MachinePrecision], N[(N[Cos[im], $MachinePrecision] * N[(N[(re * N[(re * 0.5), $MachinePrecision]), $MachinePrecision] + N[(re + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.00185 \lor \neg \left(re \leq 4 \cdot 10^{-12}\right) \land re \leq 2.9 \cdot 10^{+149}:\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;\cos im \cdot \left(re \cdot \left(re \cdot 0.5\right) + \left(re + 1\right)\right)\\
\end{array}
\end{array}
if re < -0.0018500000000000001 or 3.99999999999999992e-12 < re < 2.9000000000000002e149Initial program 100.0%
Taylor expanded in im around 0 91.8%
if -0.0018500000000000001 < re < 3.99999999999999992e-12 or 2.9000000000000002e149 < re Initial program 100.0%
add-exp-log74.0%
*-un-lft-identity74.0%
exp-prod74.0%
exp-1-e74.0%
log-prod74.0%
add-log-exp74.0%
Applied egg-rr74.0%
Taylor expanded in re around 0 99.4%
Simplified99.4%
Final simplification96.5%
(FPCore (re im) :precision binary64 (cos im))
double code(double re, double im) {
return cos(im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = cos(im)
end function
public static double code(double re, double im) {
return Math.cos(im);
}
def code(re, im): return math.cos(im)
function code(re, im) return cos(im) end
function tmp = code(re, im) tmp = cos(im); end
code[re_, im_] := N[Cos[im], $MachinePrecision]
\begin{array}{l}
\\
\cos im
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 48.4%
Final simplification48.4%
(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 49.6%
distribute-rgt1-in49.6%
Simplified49.6%
Taylor expanded in im around 0 28.2%
+-commutative28.2%
Simplified28.2%
Final simplification28.2%
(FPCore (re im) :precision binary64 re)
double code(double re, double im) {
return re;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = re
end function
public static double code(double re, double im) {
return re;
}
def code(re, im): return re
function code(re, im) return re end
function tmp = code(re, im) tmp = re; end
code[re_, im_] := re
\begin{array}{l}
\\
re
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 49.6%
distribute-rgt1-in49.6%
Simplified49.6%
Taylor expanded in re around inf 3.9%
*-commutative3.9%
Simplified3.9%
Taylor expanded in im around 0 3.5%
Final simplification3.5%
herbie shell --seed 2024067
(FPCore (re im)
:name "math.exp on complex, real part"
:precision binary64
(* (exp re) (cos im)))