
(FPCore (re im) :precision binary64 (log (sqrt (+ (* re re) (* im im)))))
double code(double re, double im) {
return log(sqrt(((re * re) + (im * im))));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = log(sqrt(((re * re) + (im * im))))
end function
public static double code(double re, double im) {
return Math.log(Math.sqrt(((re * re) + (im * im))));
}
def code(re, im): return math.log(math.sqrt(((re * re) + (im * im))))
function code(re, im) return log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) end
function tmp = code(re, im) tmp = log(sqrt(((re * re) + (im * im)))); end
code[re_, im_] := N[Log[N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(\sqrt{re \cdot re + im \cdot im}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (log (sqrt (+ (* re re) (* im im)))))
double code(double re, double im) {
return log(sqrt(((re * re) + (im * im))));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = log(sqrt(((re * re) + (im * im))))
end function
public static double code(double re, double im) {
return Math.log(Math.sqrt(((re * re) + (im * im))));
}
def code(re, im): return math.log(math.sqrt(((re * re) + (im * im))))
function code(re, im) return log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) end
function tmp = code(re, im) tmp = log(sqrt(((re * re) + (im * im)))); end
code[re_, im_] := N[Log[N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(\sqrt{re \cdot re + im \cdot im}\right)
\end{array}
(FPCore (re im) :precision binary64 (log (hypot re im)))
double code(double re, double im) {
return log(hypot(re, im));
}
public static double code(double re, double im) {
return Math.log(Math.hypot(re, im));
}
def code(re, im): return math.log(math.hypot(re, im))
function code(re, im) return log(hypot(re, im)) end
function tmp = code(re, im) tmp = log(hypot(re, im)); end
code[re_, im_] := N[Log[N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(\mathsf{hypot}\left(re, im\right)\right)
\end{array}
Initial program 49.9%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
sqr-neg-revN/A
sqr-neg-revN/A
lower-hypot.f64N/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
sqr-neg-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
sqr-neg-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1100.0
Applied rewrites100.0%
(FPCore (re im) :precision binary64 (fma (* 0.5 (/ re im)) (/ re im) (log im)))
double code(double re, double im) {
return fma((0.5 * (re / im)), (re / im), log(im));
}
function code(re, im) return fma(Float64(0.5 * Float64(re / im)), Float64(re / im), log(im)) end
code[re_, im_] := N[(N[(0.5 * N[(re / im), $MachinePrecision]), $MachinePrecision] * N[(re / im), $MachinePrecision] + N[Log[im], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(0.5 \cdot \frac{re}{im}, \frac{re}{im}, \log im\right)
\end{array}
Initial program 49.9%
Taylor expanded in re around 0
lower-log.f6427.4
Applied rewrites27.4%
Taylor expanded in re around 0
+-commutativeN/A
unpow2N/A
unpow2N/A
times-fracN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
lower-log.f6425.5
Applied rewrites25.5%
(FPCore (re im) :precision binary64 (log im))
double code(double re, double im) {
return log(im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = log(im)
end function
public static double code(double re, double im) {
return Math.log(im);
}
def code(re, im): return math.log(im)
function code(re, im) return log(im) end
function tmp = code(re, im) tmp = log(im); end
code[re_, im_] := N[Log[im], $MachinePrecision]
\begin{array}{l}
\\
\log im
\end{array}
Initial program 49.9%
Taylor expanded in re around 0
lower-log.f6427.4
Applied rewrites27.4%
(FPCore (re im) :precision binary64 (/ (* (* (/ 0.5 im) re) re) im))
double code(double re, double im) {
return (((0.5 / im) * re) * re) / im;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (((0.5d0 / im) * re) * re) / im
end function
public static double code(double re, double im) {
return (((0.5 / im) * re) * re) / im;
}
def code(re, im): return (((0.5 / im) * re) * re) / im
function code(re, im) return Float64(Float64(Float64(Float64(0.5 / im) * re) * re) / im) end
function tmp = code(re, im) tmp = (((0.5 / im) * re) * re) / im; end
code[re_, im_] := N[(N[(N[(N[(0.5 / im), $MachinePrecision] * re), $MachinePrecision] * re), $MachinePrecision] / im), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\frac{0.5}{im} \cdot re\right) \cdot re}{im}
\end{array}
Initial program 49.9%
Taylor expanded in re around 0
lower-log.f6427.4
Applied rewrites27.4%
Taylor expanded in re around 0
+-commutativeN/A
unpow2N/A
unpow2N/A
times-fracN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
lower-log.f6425.5
Applied rewrites25.5%
Taylor expanded in re around inf
Applied rewrites2.9%
Applied rewrites3.2%
(FPCore (re im) :precision binary64 (* (/ re im) (* (/ re im) 0.5)))
double code(double re, double im) {
return (re / im) * ((re / im) * 0.5);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (re / im) * ((re / im) * 0.5d0)
end function
public static double code(double re, double im) {
return (re / im) * ((re / im) * 0.5);
}
def code(re, im): return (re / im) * ((re / im) * 0.5)
function code(re, im) return Float64(Float64(re / im) * Float64(Float64(re / im) * 0.5)) end
function tmp = code(re, im) tmp = (re / im) * ((re / im) * 0.5); end
code[re_, im_] := N[(N[(re / im), $MachinePrecision] * N[(N[(re / im), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{re}{im} \cdot \left(\frac{re}{im} \cdot 0.5\right)
\end{array}
Initial program 49.9%
Taylor expanded in re around 0
lower-log.f6427.4
Applied rewrites27.4%
Taylor expanded in re around 0
+-commutativeN/A
unpow2N/A
unpow2N/A
times-fracN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
lower-log.f6425.5
Applied rewrites25.5%
Taylor expanded in re around inf
Applied rewrites2.9%
Applied rewrites3.2%
(FPCore (re im) :precision binary64 (* (* (/ re im) (/ 0.5 im)) re))
double code(double re, double im) {
return ((re / im) * (0.5 / im)) * re;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = ((re / im) * (0.5d0 / im)) * re
end function
public static double code(double re, double im) {
return ((re / im) * (0.5 / im)) * re;
}
def code(re, im): return ((re / im) * (0.5 / im)) * re
function code(re, im) return Float64(Float64(Float64(re / im) * Float64(0.5 / im)) * re) end
function tmp = code(re, im) tmp = ((re / im) * (0.5 / im)) * re; end
code[re_, im_] := N[(N[(N[(re / im), $MachinePrecision] * N[(0.5 / im), $MachinePrecision]), $MachinePrecision] * re), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{re}{im} \cdot \frac{0.5}{im}\right) \cdot re
\end{array}
Initial program 49.9%
Taylor expanded in re around 0
lower-log.f6427.4
Applied rewrites27.4%
Taylor expanded in re around 0
+-commutativeN/A
unpow2N/A
unpow2N/A
times-fracN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
lower-log.f6425.5
Applied rewrites25.5%
Taylor expanded in re around inf
Applied rewrites2.9%
Applied rewrites3.2%
(FPCore (re im) :precision binary64 (* (/ (* 0.5 re) (* im im)) re))
double code(double re, double im) {
return ((0.5 * re) / (im * im)) * re;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = ((0.5d0 * re) / (im * im)) * re
end function
public static double code(double re, double im) {
return ((0.5 * re) / (im * im)) * re;
}
def code(re, im): return ((0.5 * re) / (im * im)) * re
function code(re, im) return Float64(Float64(Float64(0.5 * re) / Float64(im * im)) * re) end
function tmp = code(re, im) tmp = ((0.5 * re) / (im * im)) * re; end
code[re_, im_] := N[(N[(N[(0.5 * re), $MachinePrecision] / N[(im * im), $MachinePrecision]), $MachinePrecision] * re), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5 \cdot re}{im \cdot im} \cdot re
\end{array}
Initial program 49.9%
Taylor expanded in re around 0
lower-log.f6427.4
Applied rewrites27.4%
Taylor expanded in re around 0
+-commutativeN/A
unpow2N/A
unpow2N/A
times-fracN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
lower-log.f6425.5
Applied rewrites25.5%
Taylor expanded in re around inf
Applied rewrites2.9%
Applied rewrites2.9%
(FPCore (re im) :precision binary64 (* (* (/ 0.5 (* im im)) re) re))
double code(double re, double im) {
return ((0.5 / (im * im)) * re) * re;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = ((0.5d0 / (im * im)) * re) * re
end function
public static double code(double re, double im) {
return ((0.5 / (im * im)) * re) * re;
}
def code(re, im): return ((0.5 / (im * im)) * re) * re
function code(re, im) return Float64(Float64(Float64(0.5 / Float64(im * im)) * re) * re) end
function tmp = code(re, im) tmp = ((0.5 / (im * im)) * re) * re; end
code[re_, im_] := N[(N[(N[(0.5 / N[(im * im), $MachinePrecision]), $MachinePrecision] * re), $MachinePrecision] * re), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{0.5}{im \cdot im} \cdot re\right) \cdot re
\end{array}
Initial program 49.9%
Taylor expanded in re around 0
lower-log.f6427.4
Applied rewrites27.4%
Taylor expanded in re around 0
+-commutativeN/A
unpow2N/A
unpow2N/A
times-fracN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
lower-log.f6425.5
Applied rewrites25.5%
Taylor expanded in re around inf
Applied rewrites2.9%
herbie shell --seed 2024319
(FPCore (re im)
:name "math.log/1 on complex, real part"
:precision binary64
(log (sqrt (+ (* re re) (* im im)))))