
(FPCore (re im) :precision binary64 (* (exp re) (sin im)))
double code(double re, double im) {
return exp(re) * sin(im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = exp(re) * sin(im)
end function
public static double code(double re, double im) {
return Math.exp(re) * Math.sin(im);
}
def code(re, im): return math.exp(re) * math.sin(im)
function code(re, im) return Float64(exp(re) * sin(im)) end
function tmp = code(re, im) tmp = exp(re) * sin(im); end
code[re_, im_] := N[(N[Exp[re], $MachinePrecision] * N[Sin[im], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{re} \cdot \sin im
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* (exp re) (sin im)))
double code(double re, double im) {
return exp(re) * sin(im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = exp(re) * sin(im)
end function
public static double code(double re, double im) {
return Math.exp(re) * Math.sin(im);
}
def code(re, im): return math.exp(re) * math.sin(im)
function code(re, im) return Float64(exp(re) * sin(im)) end
function tmp = code(re, im) tmp = exp(re) * sin(im); end
code[re_, im_] := N[(N[Exp[re], $MachinePrecision] * N[Sin[im], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{re} \cdot \sin im
\end{array}
(FPCore (re im) :precision binary64 (let* ((t_0 (sqrt (exp re)))) (* t_0 (* (sin im) t_0))))
double code(double re, double im) {
double t_0 = sqrt(exp(re));
return t_0 * (sin(im) * t_0);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
t_0 = sqrt(exp(re))
code = t_0 * (sin(im) * t_0)
end function
public static double code(double re, double im) {
double t_0 = Math.sqrt(Math.exp(re));
return t_0 * (Math.sin(im) * t_0);
}
def code(re, im): t_0 = math.sqrt(math.exp(re)) return t_0 * (math.sin(im) * t_0)
function code(re, im) t_0 = sqrt(exp(re)) return Float64(t_0 * Float64(sin(im) * t_0)) end
function tmp = code(re, im) t_0 = sqrt(exp(re)); tmp = t_0 * (sin(im) * t_0); end
code[re_, im_] := Block[{t$95$0 = N[Sqrt[N[Exp[re], $MachinePrecision]], $MachinePrecision]}, N[(t$95$0 * N[(N[Sin[im], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{e^{re}}\\
t\_0 \cdot \left(\sin im \cdot t\_0\right)
\end{array}
\end{array}
Initial program 100.0%
add-cbrt-cube83.6%
pow383.6%
Applied egg-rr83.6%
rem-cbrt-cube100.0%
*-commutative100.0%
add-sqr-sqrt100.0%
associate-*r*100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (re im) :precision binary64 (* (sin im) (exp re)))
double code(double re, double im) {
return sin(im) * exp(re);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sin(im) * exp(re)
end function
public static double code(double re, double im) {
return Math.sin(im) * Math.exp(re);
}
def code(re, im): return math.sin(im) * math.exp(re)
function code(re, im) return Float64(sin(im) * exp(re)) end
function tmp = code(re, im) tmp = sin(im) * exp(re); end
code[re_, im_] := N[(N[Sin[im], $MachinePrecision] * N[Exp[re], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin im \cdot e^{re}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (re im) :precision binary64 (* im (exp re)))
double code(double re, double im) {
return im * exp(re);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = im * exp(re)
end function
public static double code(double re, double im) {
return im * Math.exp(re);
}
def code(re, im): return im * math.exp(re)
function code(re, im) return Float64(im * exp(re)) end
function tmp = code(re, im) tmp = im * exp(re); end
code[re_, im_] := N[(im * N[Exp[re], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
im \cdot e^{re}
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 68.2%
Final simplification68.2%
(FPCore (re im) :precision binary64 (sin im))
double code(double re, double im) {
return sin(im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sin(im)
end function
public static double code(double re, double im) {
return Math.sin(im);
}
def code(re, im): return math.sin(im)
function code(re, im) return sin(im) end
function tmp = code(re, im) tmp = sin(im); end
code[re_, im_] := N[Sin[im], $MachinePrecision]
\begin{array}{l}
\\
\sin im
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 49.0%
Final simplification49.0%
(FPCore (re im) :precision binary64 (+ im (* im re)))
double code(double re, double im) {
return im + (im * re);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = im + (im * re)
end function
public static double code(double re, double im) {
return im + (im * re);
}
def code(re, im): return im + (im * re)
function code(re, im) return Float64(im + Float64(im * re)) end
function tmp = code(re, im) tmp = im + (im * re); end
code[re_, im_] := N[(im + N[(im * re), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
im + im \cdot re
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 68.2%
Taylor expanded in re around 0 29.3%
Final simplification29.3%
(FPCore (re im) :precision binary64 (* im re))
double code(double re, double im) {
return im * re;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = im * re
end function
public static double code(double re, double im) {
return im * re;
}
def code(re, im): return im * re
function code(re, im) return Float64(im * re) end
function tmp = code(re, im) tmp = im * re; end
code[re_, im_] := N[(im * re), $MachinePrecision]
\begin{array}{l}
\\
im \cdot re
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 68.2%
Taylor expanded in re around 0 29.3%
Taylor expanded in re around inf 7.8%
*-commutative7.8%
Simplified7.8%
Final simplification7.8%
(FPCore (re im) :precision binary64 im)
double code(double re, double im) {
return im;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = im
end function
public static double code(double re, double im) {
return im;
}
def code(re, im): return im
function code(re, im) return im end
function tmp = code(re, im) tmp = im; end
code[re_, im_] := im
\begin{array}{l}
\\
im
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 68.2%
Taylor expanded in re around 0 25.4%
Final simplification25.4%
herbie shell --seed 2024033
(FPCore (re im)
:name "math.exp on complex, imaginary part"
:precision binary64
(* (exp re) (sin im)))