
(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 7 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 47.8%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f64100.0
Applied rewrites100.0%
(FPCore (re im) :precision binary64 (log (fma (/ re im) (* 0.5 re) im)))
double code(double re, double im) {
return log(fma((re / im), (0.5 * re), im));
}
function code(re, im) return log(fma(Float64(re / im), Float64(0.5 * re), im)) end
code[re_, im_] := N[Log[N[(N[(re / im), $MachinePrecision] * N[(0.5 * re), $MachinePrecision] + im), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\log \left(\mathsf{fma}\left(\frac{re}{im}, 0.5 \cdot re, im\right)\right)
\end{array}
Initial program 47.8%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f64100.0
Applied rewrites100.0%
Taylor expanded in re around 0
+-commutativeN/A
associate-*r/N/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
*-rgt-identityN/A
times-fracN/A
/-rgt-identityN/A
lower-fma.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6431.2
Applied rewrites31.2%
Final simplification31.2%
(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 47.8%
Taylor expanded in re around 0
lower-log.f6431.5
Applied rewrites31.5%
(FPCore (re im) :precision binary64 (* (/ 1.0 (/ (/ im re) re)) (/ 0.5 im)))
double code(double re, double im) {
return (1.0 / ((im / re) / re)) * (0.5 / im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (1.0d0 / ((im / re) / re)) * (0.5d0 / im)
end function
public static double code(double re, double im) {
return (1.0 / ((im / re) / re)) * (0.5 / im);
}
def code(re, im): return (1.0 / ((im / re) / re)) * (0.5 / im)
function code(re, im) return Float64(Float64(1.0 / Float64(Float64(im / re) / re)) * Float64(0.5 / im)) end
function tmp = code(re, im) tmp = (1.0 / ((im / re) / re)) * (0.5 / im); end
code[re_, im_] := N[(N[(1.0 / N[(N[(im / re), $MachinePrecision] / re), $MachinePrecision]), $MachinePrecision] * N[(0.5 / im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\frac{\frac{im}{re}}{re}} \cdot \frac{0.5}{im}
\end{array}
Initial program 47.8%
Taylor expanded in re around 0
+-commutativeN/A
*-lft-identityN/A
associate-*l/N/A
associate-*l*N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
associate-/l*N/A
*-rgt-identityN/A
lower-*.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lower-log.f6429.9
Applied rewrites29.9%
Taylor expanded in re around inf
Applied rewrites3.0%
Applied rewrites3.2%
Applied rewrites3.2%
Final simplification3.2%
(FPCore (re im) :precision binary64 (* (* (/ re im) re) (/ 0.5 im)))
double code(double re, double im) {
return ((re / im) * re) * (0.5 / im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = ((re / im) * re) * (0.5d0 / im)
end function
public static double code(double re, double im) {
return ((re / im) * re) * (0.5 / im);
}
def code(re, im): return ((re / im) * re) * (0.5 / im)
function code(re, im) return Float64(Float64(Float64(re / im) * re) * Float64(0.5 / im)) end
function tmp = code(re, im) tmp = ((re / im) * re) * (0.5 / im); end
code[re_, im_] := N[(N[(N[(re / im), $MachinePrecision] * re), $MachinePrecision] * N[(0.5 / im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{re}{im} \cdot re\right) \cdot \frac{0.5}{im}
\end{array}
Initial program 47.8%
Taylor expanded in re around 0
+-commutativeN/A
*-lft-identityN/A
associate-*l/N/A
associate-*l*N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
associate-/l*N/A
*-rgt-identityN/A
lower-*.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lower-log.f6429.9
Applied rewrites29.9%
Taylor expanded in re around inf
Applied rewrites3.0%
Applied rewrites3.2%
Final simplification3.2%
(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(0.5 / im) * re) * Float64(re / im)) end
function tmp = code(re, im) tmp = ((0.5 / im) * re) * (re / im); end
code[re_, im_] := N[(N[(N[(0.5 / im), $MachinePrecision] * re), $MachinePrecision] * N[(re / im), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{0.5}{im} \cdot re\right) \cdot \frac{re}{im}
\end{array}
Initial program 47.8%
Taylor expanded in re around 0
+-commutativeN/A
*-lft-identityN/A
associate-*l/N/A
associate-*l*N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
associate-/l*N/A
*-rgt-identityN/A
lower-*.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lower-log.f6429.9
Applied rewrites29.9%
Taylor expanded in re around inf
Applied rewrites3.0%
Applied rewrites3.2%
Taylor expanded in re around inf
Applied rewrites3.3%
(FPCore (re im) :precision binary64 (* (* (/ re (* im im)) 0.5) re))
double code(double re, double im) {
return ((re / (im * im)) * 0.5) * re;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = ((re / (im * im)) * 0.5d0) * re
end function
public static double code(double re, double im) {
return ((re / (im * im)) * 0.5) * re;
}
def code(re, im): return ((re / (im * im)) * 0.5) * re
function code(re, im) return Float64(Float64(Float64(re / Float64(im * im)) * 0.5) * re) end
function tmp = code(re, im) tmp = ((re / (im * im)) * 0.5) * re; end
code[re_, im_] := N[(N[(N[(re / N[(im * im), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision] * re), $MachinePrecision]
\begin{array}{l}
\\
\left(\frac{re}{im \cdot im} \cdot 0.5\right) \cdot re
\end{array}
Initial program 47.8%
Taylor expanded in re around 0
+-commutativeN/A
*-lft-identityN/A
associate-*l/N/A
associate-*l*N/A
unpow2N/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
associate-/l*N/A
*-rgt-identityN/A
lower-*.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lower-log.f6429.9
Applied rewrites29.9%
Taylor expanded in re around inf
Applied rewrites3.0%
herbie shell --seed 2024264
(FPCore (re im)
:name "math.log/1 on complex, real part"
:precision binary64
(log (sqrt (+ (* re re) (* im im)))))