
(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 4 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 (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 63.5%
unpow263.5%
Simplified63.5%
Taylor expanded in im around 0 73.4%
Final simplification73.4%
(FPCore (re im) :precision binary64 (* (* im im) (* re -0.5)))
double code(double re, double im) {
return (im * im) * (re * -0.5);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (im * im) * (re * (-0.5d0))
end function
public static double code(double re, double im) {
return (im * im) * (re * -0.5);
}
def code(re, im): return (im * im) * (re * -0.5)
function code(re, im) return Float64(Float64(im * im) * Float64(re * -0.5)) end
function tmp = code(re, im) tmp = (im * im) * (re * -0.5); end
code[re_, im_] := N[(N[(im * im), $MachinePrecision] * N[(re * -0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(im \cdot im\right) \cdot \left(re \cdot -0.5\right)
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 63.5%
unpow263.5%
Simplified63.5%
Taylor expanded in im around inf 27.1%
*-commutative27.1%
associate-*r*27.1%
unpow227.1%
associate-*l*31.4%
*-commutative31.4%
Simplified31.4%
Taylor expanded in re around 0 8.8%
distribute-lft-out8.8%
Simplified8.8%
Taylor expanded in re around inf 12.3%
*-commutative12.3%
unpow212.3%
associate-*l*12.3%
*-commutative12.3%
Simplified12.3%
Final simplification12.3%
(FPCore (re im) :precision binary64 (* im (* im -0.5)))
double code(double re, double im) {
return im * (im * -0.5);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = im * (im * (-0.5d0))
end function
public static double code(double re, double im) {
return im * (im * -0.5);
}
def code(re, im): return im * (im * -0.5)
function code(re, im) return Float64(im * Float64(im * -0.5)) end
function tmp = code(re, im) tmp = im * (im * -0.5); end
code[re_, im_] := N[(im * N[(im * -0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
im \cdot \left(im \cdot -0.5\right)
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 63.5%
unpow263.5%
Simplified63.5%
Taylor expanded in im around inf 27.1%
*-commutative27.1%
associate-*r*27.1%
unpow227.1%
associate-*l*31.4%
*-commutative31.4%
Simplified31.4%
Taylor expanded in re around 0 11.5%
Final simplification11.5%
herbie shell --seed 2023271
(FPCore (re im)
:name "math.exp on complex, real part"
:precision binary64
(* (exp re) (cos im)))