
(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 5 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 (<= re 5e+15) (exp re) (* (exp re) (+ 1.0 (* -0.5 (* im im))))))
double code(double re, double im) {
double tmp;
if (re <= 5e+15) {
tmp = exp(re);
} else {
tmp = exp(re) * (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 <= 5d+15) then
tmp = exp(re)
else
tmp = exp(re) * (1.0d0 + ((-0.5d0) * (im * im)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 5e+15) {
tmp = Math.exp(re);
} else {
tmp = Math.exp(re) * (1.0 + (-0.5 * (im * im)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 5e+15: tmp = math.exp(re) else: tmp = math.exp(re) * (1.0 + (-0.5 * (im * im))) return tmp
function code(re, im) tmp = 0.0 if (re <= 5e+15) tmp = exp(re); else tmp = Float64(exp(re) * Float64(1.0 + Float64(-0.5 * Float64(im * im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 5e+15) tmp = exp(re); else tmp = exp(re) * (1.0 + (-0.5 * (im * im))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 5e+15], N[Exp[re], $MachinePrecision], N[(N[Exp[re], $MachinePrecision] * N[(1.0 + N[(-0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 5 \cdot 10^{+15}:\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;e^{re} \cdot \left(1 + -0.5 \cdot \left(im \cdot im\right)\right)\\
\end{array}
\end{array}
if re < 5e15Initial program 100.0%
Taylor expanded in im around 0 61.0%
unpow261.0%
Simplified61.0%
Taylor expanded in im around 0 69.3%
if 5e15 < re Initial program 100.0%
Taylor expanded in im around 0 80.6%
unpow280.6%
Simplified80.6%
Final simplification72.0%
(FPCore (re im) :precision binary64 (exp re))
double code(double re, double im) {
return exp(re);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = exp(re)
end function
public static double code(double re, double im) {
return Math.exp(re);
}
def code(re, im): return math.exp(re)
function code(re, im) return exp(re) end
function tmp = code(re, im) tmp = exp(re); end
code[re_, im_] := N[Exp[re], $MachinePrecision]
\begin{array}{l}
\\
e^{re}
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 65.8%
unpow265.8%
Simplified65.8%
Taylor expanded in im around 0 69.7%
Final simplification69.7%
(FPCore (re im) :precision binary64 (* -0.5 (* re (* im im))))
double code(double re, double im) {
return -0.5 * (re * (im * im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (-0.5d0) * (re * (im * im))
end function
public static double code(double re, double im) {
return -0.5 * (re * (im * im));
}
def code(re, im): return -0.5 * (re * (im * im))
function code(re, im) return Float64(-0.5 * Float64(re * Float64(im * im))) end
function tmp = code(re, im) tmp = -0.5 * (re * (im * im)); end
code[re_, im_] := N[(-0.5 * N[(re * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-0.5 \cdot \left(re \cdot \left(im \cdot im\right)\right)
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 65.8%
unpow265.8%
Simplified65.8%
Taylor expanded in im around inf 25.4%
unpow225.4%
associate-*r*25.4%
*-commutative25.4%
associate-*l*25.4%
Simplified25.4%
Taylor expanded in re around 0 13.3%
associate-*r*13.3%
distribute-rgt-out13.4%
unpow213.4%
Simplified13.4%
Taylor expanded in re around inf 13.7%
unpow213.7%
Simplified13.7%
Final simplification13.7%
(FPCore (re im) :precision binary64 (* -0.5 (* im im)))
double code(double re, double im) {
return -0.5 * (im * im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (-0.5d0) * (im * im)
end function
public static double code(double re, double im) {
return -0.5 * (im * im);
}
def code(re, im): return -0.5 * (im * im)
function code(re, im) return Float64(-0.5 * Float64(im * im)) end
function tmp = code(re, im) tmp = -0.5 * (im * im); end
code[re_, im_] := N[(-0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-0.5 \cdot \left(im \cdot im\right)
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 65.8%
unpow265.8%
Simplified65.8%
Taylor expanded in im around inf 25.4%
unpow225.4%
associate-*r*25.4%
*-commutative25.4%
associate-*l*25.4%
Simplified25.4%
Taylor expanded in re around 0 12.2%
unpow212.2%
Simplified12.2%
Final simplification12.2%
herbie shell --seed 2023193
(FPCore (re im)
:name "math.exp on complex, real part"
:precision binary64
(* (exp re) (cos im)))