
(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.4%
unpow263.4%
Simplified63.4%
Taylor expanded in im around 0 71.6%
Final simplification71.6%
(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 63.4%
unpow263.4%
Simplified63.4%
Taylor expanded in im around inf 23.2%
unpow223.2%
associate-*r*23.2%
*-commutative23.2%
associate-*r*23.2%
Simplified23.2%
Taylor expanded in re around 0 11.2%
associate-*r*11.2%
distribute-rgt-out11.3%
unpow211.3%
Simplified11.3%
Taylor expanded in re around inf 11.4%
unpow211.4%
Simplified11.4%
Final simplification11.4%
(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 63.4%
unpow263.4%
Simplified63.4%
Taylor expanded in im around inf 23.2%
unpow223.2%
associate-*r*23.2%
*-commutative23.2%
associate-*r*23.2%
Simplified23.2%
Taylor expanded in re around 0 8.4%
unpow28.4%
Simplified8.4%
Final simplification8.4%
herbie shell --seed 2023189
(FPCore (re im)
:name "math.exp on complex, real part"
:precision binary64
(* (exp re) (cos im)))