
(FPCore (re im) :precision binary64 (/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))
double code(double re, double im) {
return log(sqrt(((re * re) + (im * im)))) / log(10.0);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = log(sqrt(((re * re) + (im * im)))) / log(10.0d0)
end function
public static double code(double re, double im) {
return Math.log(Math.sqrt(((re * re) + (im * im)))) / Math.log(10.0);
}
def code(re, im): return math.log(math.sqrt(((re * re) + (im * im)))) / math.log(10.0)
function code(re, im) return Float64(log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) / log(10.0)) end
function tmp = code(re, im) tmp = log(sqrt(((re * re) + (im * im)))) / log(10.0); end
code[re_, im_] := N[(N[Log[N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))
double code(double re, double im) {
return log(sqrt(((re * re) + (im * im)))) / log(10.0);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = log(sqrt(((re * re) + (im * im)))) / log(10.0d0)
end function
public static double code(double re, double im) {
return Math.log(Math.sqrt(((re * re) + (im * im)))) / Math.log(10.0);
}
def code(re, im): return math.log(math.sqrt(((re * re) + (im * im)))) / math.log(10.0)
function code(re, im) return Float64(log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) / log(10.0)) end
function tmp = code(re, im) tmp = log(sqrt(((re * re) + (im * im)))) / log(10.0); end
code[re_, im_] := N[(N[Log[N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}
\end{array}
(FPCore (re im) :precision binary64 (/ (log (hypot im re)) (- (log 0.1))))
double code(double re, double im) {
return log(hypot(im, re)) / -log(0.1);
}
public static double code(double re, double im) {
return Math.log(Math.hypot(im, re)) / -Math.log(0.1);
}
def code(re, im): return math.log(math.hypot(im, re)) / -math.log(0.1)
function code(re, im) return Float64(log(hypot(im, re)) / Float64(-log(0.1))) end
function tmp = code(re, im) tmp = log(hypot(im, re)) / -log(0.1); end
code[re_, im_] := N[(N[Log[N[Sqrt[im ^ 2 + re ^ 2], $MachinePrecision]], $MachinePrecision] / (-N[Log[0.1], $MachinePrecision])), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log \left(\mathsf{hypot}\left(im, re\right)\right)}{-\log 0.1}
\end{array}
Initial program 54.6%
lift-/.f64N/A
frac-2negN/A
lower-/.f64N/A
lower-neg.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f64N/A
lift-log.f64N/A
neg-logN/A
lower-log.f64N/A
metadata-eval99.1
Applied rewrites99.1%
Final simplification99.1%
(FPCore (re im) :precision binary64 (/ (log (hypot re im)) (log 10.0)))
double code(double re, double im) {
return log(hypot(re, im)) / log(10.0);
}
public static double code(double re, double im) {
return Math.log(Math.hypot(re, im)) / Math.log(10.0);
}
def code(re, im): return math.log(math.hypot(re, im)) / math.log(10.0)
function code(re, im) return Float64(log(hypot(re, im)) / log(10.0)) end
function tmp = code(re, im) tmp = log(hypot(re, im)) / log(10.0); end
code[re_, im_] := N[(N[Log[N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 10}
\end{array}
Initial program 54.6%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6499.0
Applied rewrites99.0%
(FPCore (re im) :precision binary64 (/ (fma (/ (* 0.5 re) im) (/ re im) (log im)) (- (log 0.1))))
double code(double re, double im) {
return fma(((0.5 * re) / im), (re / im), log(im)) / -log(0.1);
}
function code(re, im) return Float64(fma(Float64(Float64(0.5 * re) / im), Float64(re / im), log(im)) / Float64(-log(0.1))) end
code[re_, im_] := N[(N[(N[(N[(0.5 * re), $MachinePrecision] / im), $MachinePrecision] * N[(re / im), $MachinePrecision] + N[Log[im], $MachinePrecision]), $MachinePrecision] / (-N[Log[0.1], $MachinePrecision])), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(\frac{0.5 \cdot re}{im}, \frac{re}{im}, \log im\right)}{-\log 0.1}
\end{array}
Initial program 54.6%
lift-/.f64N/A
frac-2negN/A
lower-/.f64N/A
lower-neg.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f64N/A
lift-log.f64N/A
neg-logN/A
lower-log.f64N/A
metadata-eval99.1
Applied rewrites99.1%
Taylor expanded in re around 0
+-commutativeN/A
*-commutativeN/A
associate-*l/N/A
*-commutativeN/A
unpow2N/A
associate-*r*N/A
unpow2N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-log.f6423.7
Applied rewrites23.7%
Final simplification23.7%
(FPCore (re im) :precision binary64 (/ (fma (/ (* 0.5 re) im) (/ re im) (log im)) (log 10.0)))
double code(double re, double im) {
return fma(((0.5 * re) / im), (re / im), log(im)) / log(10.0);
}
function code(re, im) return Float64(fma(Float64(Float64(0.5 * re) / im), Float64(re / im), log(im)) / log(10.0)) end
code[re_, im_] := N[(N[(N[(N[(0.5 * re), $MachinePrecision] / im), $MachinePrecision] * N[(re / im), $MachinePrecision] + N[Log[im], $MachinePrecision]), $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(\frac{0.5 \cdot re}{im}, \frac{re}{im}, \log im\right)}{\log 10}
\end{array}
Initial program 54.6%
Taylor expanded in re around 0
lower-log.f6425.3
Applied rewrites25.3%
Taylor expanded in re around 0
associate-/r*N/A
associate-*r/N/A
div-add-revN/A
+-commutativeN/A
lower-/.f64N/A
Applied rewrites23.7%
(FPCore (re im) :precision binary64 (/ (log im) (- (log 0.1))))
double code(double re, double im) {
return log(im) / -log(0.1);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = log(im) / -log(0.1d0)
end function
public static double code(double re, double im) {
return Math.log(im) / -Math.log(0.1);
}
def code(re, im): return math.log(im) / -math.log(0.1)
function code(re, im) return Float64(log(im) / Float64(-log(0.1))) end
function tmp = code(re, im) tmp = log(im) / -log(0.1); end
code[re_, im_] := N[(N[Log[im], $MachinePrecision] / (-N[Log[0.1], $MachinePrecision])), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log im}{-\log 0.1}
\end{array}
Initial program 54.6%
Taylor expanded in re around 0
lower-log.f6425.3
Applied rewrites25.3%
lift-/.f64N/A
frac-2neg-revN/A
lift-log.f64N/A
neg-logN/A
metadata-evalN/A
lift-log.f64N/A
lower-/.f64N/A
lower-neg.f6425.4
Applied rewrites25.4%
Final simplification25.4%
(FPCore (re im) :precision binary64 (/ (log im) (log 10.0)))
double code(double re, double im) {
return log(im) / log(10.0);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = log(im) / log(10.0d0)
end function
public static double code(double re, double im) {
return Math.log(im) / Math.log(10.0);
}
def code(re, im): return math.log(im) / math.log(10.0)
function code(re, im) return Float64(log(im) / log(10.0)) end
function tmp = code(re, im) tmp = log(im) / log(10.0); end
code[re_, im_] := N[(N[Log[im], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log im}{\log 10}
\end{array}
Initial program 54.6%
Taylor expanded in re around 0
lower-log.f6425.3
Applied rewrites25.3%
(FPCore (re im) :precision binary64 (/ (* (* (/ re im) re) -0.5) (* im (log 0.1))))
double code(double re, double im) {
return (((re / im) * re) * -0.5) / (im * log(0.1));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (((re / im) * re) * (-0.5d0)) / (im * log(0.1d0))
end function
public static double code(double re, double im) {
return (((re / im) * re) * -0.5) / (im * Math.log(0.1));
}
def code(re, im): return (((re / im) * re) * -0.5) / (im * math.log(0.1))
function code(re, im) return Float64(Float64(Float64(Float64(re / im) * re) * -0.5) / Float64(im * log(0.1))) end
function tmp = code(re, im) tmp = (((re / im) * re) * -0.5) / (im * log(0.1)); end
code[re_, im_] := N[(N[(N[(N[(re / im), $MachinePrecision] * re), $MachinePrecision] * -0.5), $MachinePrecision] / N[(im * N[Log[0.1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(\frac{re}{im} \cdot re\right) \cdot -0.5}{im \cdot \log 0.1}
\end{array}
Initial program 54.6%
Taylor expanded in re around 0
lower-log.f6425.3
Applied rewrites25.3%
Taylor expanded in re around 0
associate-/r*N/A
associate-*r/N/A
div-add-revN/A
+-commutativeN/A
lower-/.f64N/A
Applied rewrites23.7%
Taylor expanded in re around inf
Applied rewrites3.3%
Applied rewrites3.3%
(FPCore (re im) :precision binary64 (* (/ 0.5 (log 10.0)) (* re (/ re (* im im)))))
double code(double re, double im) {
return (0.5 / log(10.0)) * (re * (re / (im * im)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 / log(10.0d0)) * (re * (re / (im * im)))
end function
public static double code(double re, double im) {
return (0.5 / Math.log(10.0)) * (re * (re / (im * im)));
}
def code(re, im): return (0.5 / math.log(10.0)) * (re * (re / (im * im)))
function code(re, im) return Float64(Float64(0.5 / log(10.0)) * Float64(re * Float64(re / Float64(im * im)))) end
function tmp = code(re, im) tmp = (0.5 / log(10.0)) * (re * (re / (im * im))); end
code[re_, im_] := N[(N[(0.5 / N[Log[10.0], $MachinePrecision]), $MachinePrecision] * N[(re * N[(re / N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.5}{\log 10} \cdot \left(re \cdot \frac{re}{im \cdot im}\right)
\end{array}
Initial program 54.6%
Taylor expanded in re around 0
lower-log.f6425.3
Applied rewrites25.3%
Taylor expanded in re around 0
associate-/r*N/A
associate-*r/N/A
div-add-revN/A
+-commutativeN/A
lower-/.f64N/A
Applied rewrites23.7%
Taylor expanded in re around inf
Applied rewrites3.3%
Applied rewrites2.9%
(FPCore (re im) :precision binary64 (/ (* (* 0.5 re) re) (* (* im im) (log 10.0))))
double code(double re, double im) {
return ((0.5 * re) * re) / ((im * im) * log(10.0));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = ((0.5d0 * re) * re) / ((im * im) * log(10.0d0))
end function
public static double code(double re, double im) {
return ((0.5 * re) * re) / ((im * im) * Math.log(10.0));
}
def code(re, im): return ((0.5 * re) * re) / ((im * im) * math.log(10.0))
function code(re, im) return Float64(Float64(Float64(0.5 * re) * re) / Float64(Float64(im * im) * log(10.0))) end
function tmp = code(re, im) tmp = ((0.5 * re) * re) / ((im * im) * log(10.0)); end
code[re_, im_] := N[(N[(N[(0.5 * re), $MachinePrecision] * re), $MachinePrecision] / N[(N[(im * im), $MachinePrecision] * N[Log[10.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(0.5 \cdot re\right) \cdot re}{\left(im \cdot im\right) \cdot \log 10}
\end{array}
Initial program 54.6%
Taylor expanded in re around 0
lower-log.f6425.3
Applied rewrites25.3%
Taylor expanded in re around 0
associate-/r*N/A
associate-*r/N/A
div-add-revN/A
+-commutativeN/A
lower-/.f64N/A
Applied rewrites23.7%
Taylor expanded in re around inf
Applied rewrites3.3%
Applied rewrites2.6%
herbie shell --seed 2024326
(FPCore (re im)
:name "math.log10 on complex, real part"
:precision binary64
(/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))