math.log10 on complex, real part

Percentage Accurate: 51.8% → 98.9%
Time: 7.4s
Alternatives: 4
Speedup: 1.5×

Specification

?
\[\begin{array}{l} \\ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \end{array} \]
(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:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 4 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 51.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \end{array} \]
(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}

Alternative 1: 98.9% accurate, 0.6× speedup?

\[\begin{array}{l} re_m = \left|re\right| \\ im_m = \left|im\right| \\ [re_m, im_m] = \mathsf{sort}([re_m, im_m])\\ \\ \begin{array}{l} t_0 := {\log 10}^{-0.5}\\ \left(t\_0 \cdot t\_0\right) \cdot \log im\_m \end{array} \end{array} \]
re_m = (fabs.f64 re)
im_m = (fabs.f64 im)
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
(FPCore (re_m im_m)
 :precision binary64
 (let* ((t_0 (pow (log 10.0) -0.5))) (* (* t_0 t_0) (log im_m))))
re_m = fabs(re);
im_m = fabs(im);
assert(re_m < im_m);
double code(double re_m, double im_m) {
	double t_0 = pow(log(10.0), -0.5);
	return (t_0 * t_0) * log(im_m);
}
re_m = abs(re)
im_m = abs(im)
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
real(8) function code(re_m, im_m)
    real(8), intent (in) :: re_m
    real(8), intent (in) :: im_m
    real(8) :: t_0
    t_0 = log(10.0d0) ** (-0.5d0)
    code = (t_0 * t_0) * log(im_m)
end function
re_m = Math.abs(re);
im_m = Math.abs(im);
assert re_m < im_m;
public static double code(double re_m, double im_m) {
	double t_0 = Math.pow(Math.log(10.0), -0.5);
	return (t_0 * t_0) * Math.log(im_m);
}
re_m = math.fabs(re)
im_m = math.fabs(im)
[re_m, im_m] = sort([re_m, im_m])
def code(re_m, im_m):
	t_0 = math.pow(math.log(10.0), -0.5)
	return (t_0 * t_0) * math.log(im_m)
re_m = abs(re)
im_m = abs(im)
re_m, im_m = sort([re_m, im_m])
function code(re_m, im_m)
	t_0 = log(10.0) ^ -0.5
	return Float64(Float64(t_0 * t_0) * log(im_m))
end
re_m = abs(re);
im_m = abs(im);
re_m, im_m = num2cell(sort([re_m, im_m])){:}
function tmp = code(re_m, im_m)
	t_0 = log(10.0) ^ -0.5;
	tmp = (t_0 * t_0) * log(im_m);
end
re_m = N[Abs[re], $MachinePrecision]
im_m = N[Abs[im], $MachinePrecision]
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
code[re$95$m_, im$95$m_] := Block[{t$95$0 = N[Power[N[Log[10.0], $MachinePrecision], -0.5], $MachinePrecision]}, N[(N[(t$95$0 * t$95$0), $MachinePrecision] * N[Log[im$95$m], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
re_m = \left|re\right|
\\
im_m = \left|im\right|
\\
[re_m, im_m] = \mathsf{sort}([re_m, im_m])\\
\\
\begin{array}{l}
t_0 := {\log 10}^{-0.5}\\
\left(t\_0 \cdot t\_0\right) \cdot \log im\_m
\end{array}
\end{array}
Derivation
  1. Initial program 53.6%

    \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \]
  2. Step-by-step derivation
    1. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\log \left(\sqrt{re \cdot re + im \cdot im}\right), \color{blue}{\log 10}\right) \]
    2. log-lowering-log.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{log.f64}\left(\left(\sqrt{re \cdot re + im \cdot im}\right)\right), \log \color{blue}{10}\right) \]
    3. hypot-defineN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{log.f64}\left(\left(\mathsf{hypot}\left(re, im\right)\right)\right), \log 10\right) \]
    4. hypot-lowering-hypot.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{log.f64}\left(\mathsf{hypot.f64}\left(re, im\right)\right), \log 10\right) \]
    5. log-lowering-log.f6499.1%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{log.f64}\left(\mathsf{hypot.f64}\left(re, im\right)\right), \mathsf{log.f64}\left(10\right)\right) \]
  3. Simplified99.1%

    \[\leadsto \color{blue}{\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 10}} \]
  4. Add Preprocessing
  5. Taylor expanded in re around 0

    \[\leadsto \color{blue}{\frac{\log im}{\log 10}} \]
  6. Step-by-step derivation
    1. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\log im, \color{blue}{\log 10}\right) \]
    2. log-lowering-log.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{log.f64}\left(im\right), \log \color{blue}{10}\right) \]
    3. log-lowering-log.f6426.0%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{log.f64}\left(10\right)\right) \]
  7. Simplified26.0%

    \[\leadsto \color{blue}{\frac{\log im}{\log 10}} \]
  8. Step-by-step derivation
    1. clear-numN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\log 10}{\log im}}} \]
    2. associate-/r/N/A

      \[\leadsto \frac{1}{\log 10} \cdot \color{blue}{\log im} \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{\log 10}\right), \color{blue}{\log im}\right) \]
    4. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \log 10\right), \log \color{blue}{im}\right) \]
    5. log-lowering-log.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \mathsf{log.f64}\left(10\right)\right), \log im\right) \]
    6. log-lowering-log.f6425.9%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \mathsf{log.f64}\left(10\right)\right), \mathsf{log.f64}\left(im\right)\right) \]
  9. Applied egg-rr25.9%

    \[\leadsto \color{blue}{\frac{1}{\log 10} \cdot \log im} \]
  10. Step-by-step derivation
    1. inv-powN/A

      \[\leadsto \mathsf{*.f64}\left(\left({\log 10}^{-1}\right), \mathsf{log.f64}\left(\color{blue}{im}\right)\right) \]
    2. sqr-powN/A

      \[\leadsto \mathsf{*.f64}\left(\left({\log 10}^{\left(\frac{-1}{2}\right)} \cdot {\log 10}^{\left(\frac{-1}{2}\right)}\right), \mathsf{log.f64}\left(\color{blue}{im}\right)\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left({\log 10}^{\left(\frac{-1}{2}\right)}\right), \left({\log 10}^{\left(\frac{-1}{2}\right)}\right)\right), \mathsf{log.f64}\left(\color{blue}{im}\right)\right) \]
    4. metadata-evalN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left({\log 10}^{\frac{-1}{2}}\right), \left({\log 10}^{\left(\frac{-1}{2}\right)}\right)\right), \mathsf{log.f64}\left(im\right)\right) \]
    5. metadata-evalN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left({\log 10}^{\left(\frac{1}{-2}\right)}\right), \left({\log 10}^{\left(\frac{-1}{2}\right)}\right)\right), \mathsf{log.f64}\left(im\right)\right) \]
    6. pow-lowering-pow.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(\log 10, \left(\frac{1}{-2}\right)\right), \left({\log 10}^{\left(\frac{-1}{2}\right)}\right)\right), \mathsf{log.f64}\left(im\right)\right) \]
    7. log-lowering-log.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{log.f64}\left(10\right), \left(\frac{1}{-2}\right)\right), \left({\log 10}^{\left(\frac{-1}{2}\right)}\right)\right), \mathsf{log.f64}\left(im\right)\right) \]
    8. metadata-evalN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{log.f64}\left(10\right), \frac{-1}{2}\right), \left({\log 10}^{\left(\frac{-1}{2}\right)}\right)\right), \mathsf{log.f64}\left(im\right)\right) \]
    9. metadata-evalN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{log.f64}\left(10\right), \frac{-1}{2}\right), \left({\log 10}^{\frac{-1}{2}}\right)\right), \mathsf{log.f64}\left(im\right)\right) \]
    10. metadata-evalN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{log.f64}\left(10\right), \frac{-1}{2}\right), \left({\log 10}^{\left(\frac{1}{-2}\right)}\right)\right), \mathsf{log.f64}\left(im\right)\right) \]
    11. pow-lowering-pow.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{log.f64}\left(10\right), \frac{-1}{2}\right), \mathsf{pow.f64}\left(\log 10, \left(\frac{1}{-2}\right)\right)\right), \mathsf{log.f64}\left(im\right)\right) \]
    12. log-lowering-log.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{log.f64}\left(10\right), \frac{-1}{2}\right), \mathsf{pow.f64}\left(\mathsf{log.f64}\left(10\right), \left(\frac{1}{-2}\right)\right)\right), \mathsf{log.f64}\left(im\right)\right) \]
    13. metadata-eval26.1%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(\mathsf{log.f64}\left(10\right), \frac{-1}{2}\right), \mathsf{pow.f64}\left(\mathsf{log.f64}\left(10\right), \frac{-1}{2}\right)\right), \mathsf{log.f64}\left(im\right)\right) \]
  11. Applied egg-rr26.1%

    \[\leadsto \color{blue}{\left({\log 10}^{-0.5} \cdot {\log 10}^{-0.5}\right)} \cdot \log im \]
  12. Add Preprocessing

Alternative 2: 99.1% accurate, 1.0× speedup?

\[\begin{array}{l} re_m = \left|re\right| \\ im_m = \left|im\right| \\ [re_m, im_m] = \mathsf{sort}([re_m, im_m])\\ \\ \frac{\log \left(\mathsf{hypot}\left(re\_m, im\_m\right)\right)}{\log 10} \end{array} \]
re_m = (fabs.f64 re)
im_m = (fabs.f64 im)
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
(FPCore (re_m im_m) :precision binary64 (/ (log (hypot re_m im_m)) (log 10.0)))
re_m = fabs(re);
im_m = fabs(im);
assert(re_m < im_m);
double code(double re_m, double im_m) {
	return log(hypot(re_m, im_m)) / log(10.0);
}
re_m = Math.abs(re);
im_m = Math.abs(im);
assert re_m < im_m;
public static double code(double re_m, double im_m) {
	return Math.log(Math.hypot(re_m, im_m)) / Math.log(10.0);
}
re_m = math.fabs(re)
im_m = math.fabs(im)
[re_m, im_m] = sort([re_m, im_m])
def code(re_m, im_m):
	return math.log(math.hypot(re_m, im_m)) / math.log(10.0)
re_m = abs(re)
im_m = abs(im)
re_m, im_m = sort([re_m, im_m])
function code(re_m, im_m)
	return Float64(log(hypot(re_m, im_m)) / log(10.0))
end
re_m = abs(re);
im_m = abs(im);
re_m, im_m = num2cell(sort([re_m, im_m])){:}
function tmp = code(re_m, im_m)
	tmp = log(hypot(re_m, im_m)) / log(10.0);
end
re_m = N[Abs[re], $MachinePrecision]
im_m = N[Abs[im], $MachinePrecision]
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
code[re$95$m_, im$95$m_] := N[(N[Log[N[Sqrt[re$95$m ^ 2 + im$95$m ^ 2], $MachinePrecision]], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
re_m = \left|re\right|
\\
im_m = \left|im\right|
\\
[re_m, im_m] = \mathsf{sort}([re_m, im_m])\\
\\
\frac{\log \left(\mathsf{hypot}\left(re\_m, im\_m\right)\right)}{\log 10}
\end{array}
Derivation
  1. Initial program 53.6%

    \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \]
  2. Step-by-step derivation
    1. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\log \left(\sqrt{re \cdot re + im \cdot im}\right), \color{blue}{\log 10}\right) \]
    2. log-lowering-log.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{log.f64}\left(\left(\sqrt{re \cdot re + im \cdot im}\right)\right), \log \color{blue}{10}\right) \]
    3. hypot-defineN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{log.f64}\left(\left(\mathsf{hypot}\left(re, im\right)\right)\right), \log 10\right) \]
    4. hypot-lowering-hypot.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{log.f64}\left(\mathsf{hypot.f64}\left(re, im\right)\right), \log 10\right) \]
    5. log-lowering-log.f6499.1%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{log.f64}\left(\mathsf{hypot.f64}\left(re, im\right)\right), \mathsf{log.f64}\left(10\right)\right) \]
  3. Simplified99.1%

    \[\leadsto \color{blue}{\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 10}} \]
  4. Add Preprocessing
  5. Add Preprocessing

Alternative 3: 98.5% accurate, 1.5× speedup?

\[\begin{array}{l} re_m = \left|re\right| \\ im_m = \left|im\right| \\ [re_m, im_m] = \mathsf{sort}([re_m, im_m])\\ \\ \frac{1}{\frac{\log 10}{\log im\_m}} \end{array} \]
re_m = (fabs.f64 re)
im_m = (fabs.f64 im)
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
(FPCore (re_m im_m) :precision binary64 (/ 1.0 (/ (log 10.0) (log im_m))))
re_m = fabs(re);
im_m = fabs(im);
assert(re_m < im_m);
double code(double re_m, double im_m) {
	return 1.0 / (log(10.0) / log(im_m));
}
re_m = abs(re)
im_m = abs(im)
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
real(8) function code(re_m, im_m)
    real(8), intent (in) :: re_m
    real(8), intent (in) :: im_m
    code = 1.0d0 / (log(10.0d0) / log(im_m))
end function
re_m = Math.abs(re);
im_m = Math.abs(im);
assert re_m < im_m;
public static double code(double re_m, double im_m) {
	return 1.0 / (Math.log(10.0) / Math.log(im_m));
}
re_m = math.fabs(re)
im_m = math.fabs(im)
[re_m, im_m] = sort([re_m, im_m])
def code(re_m, im_m):
	return 1.0 / (math.log(10.0) / math.log(im_m))
re_m = abs(re)
im_m = abs(im)
re_m, im_m = sort([re_m, im_m])
function code(re_m, im_m)
	return Float64(1.0 / Float64(log(10.0) / log(im_m)))
end
re_m = abs(re);
im_m = abs(im);
re_m, im_m = num2cell(sort([re_m, im_m])){:}
function tmp = code(re_m, im_m)
	tmp = 1.0 / (log(10.0) / log(im_m));
end
re_m = N[Abs[re], $MachinePrecision]
im_m = N[Abs[im], $MachinePrecision]
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
code[re$95$m_, im$95$m_] := N[(1.0 / N[(N[Log[10.0], $MachinePrecision] / N[Log[im$95$m], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
re_m = \left|re\right|
\\
im_m = \left|im\right|
\\
[re_m, im_m] = \mathsf{sort}([re_m, im_m])\\
\\
\frac{1}{\frac{\log 10}{\log im\_m}}
\end{array}
Derivation
  1. Initial program 53.6%

    \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \]
  2. Step-by-step derivation
    1. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\log \left(\sqrt{re \cdot re + im \cdot im}\right), \color{blue}{\log 10}\right) \]
    2. log-lowering-log.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{log.f64}\left(\left(\sqrt{re \cdot re + im \cdot im}\right)\right), \log \color{blue}{10}\right) \]
    3. hypot-defineN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{log.f64}\left(\left(\mathsf{hypot}\left(re, im\right)\right)\right), \log 10\right) \]
    4. hypot-lowering-hypot.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{log.f64}\left(\mathsf{hypot.f64}\left(re, im\right)\right), \log 10\right) \]
    5. log-lowering-log.f6499.1%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{log.f64}\left(\mathsf{hypot.f64}\left(re, im\right)\right), \mathsf{log.f64}\left(10\right)\right) \]
  3. Simplified99.1%

    \[\leadsto \color{blue}{\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 10}} \]
  4. Add Preprocessing
  5. Taylor expanded in re around 0

    \[\leadsto \color{blue}{\frac{\log im}{\log 10}} \]
  6. Step-by-step derivation
    1. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\log im, \color{blue}{\log 10}\right) \]
    2. log-lowering-log.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{log.f64}\left(im\right), \log \color{blue}{10}\right) \]
    3. log-lowering-log.f6426.0%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{log.f64}\left(10\right)\right) \]
  7. Simplified26.0%

    \[\leadsto \color{blue}{\frac{\log im}{\log 10}} \]
  8. Step-by-step derivation
    1. clear-numN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\log 10}{\log im}}} \]
    2. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{\log 10}{\log im}\right)}\right) \]
    3. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\log 10, \color{blue}{\log im}\right)\right) \]
    4. log-lowering-log.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{log.f64}\left(10\right), \log \color{blue}{im}\right)\right) \]
    5. log-lowering-log.f6426.0%

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{log.f64}\left(10\right), \mathsf{log.f64}\left(im\right)\right)\right) \]
  9. Applied egg-rr26.0%

    \[\leadsto \color{blue}{\frac{1}{\frac{\log 10}{\log im}}} \]
  10. Add Preprocessing

Alternative 4: 98.5% accurate, 1.5× speedup?

\[\begin{array}{l} re_m = \left|re\right| \\ im_m = \left|im\right| \\ [re_m, im_m] = \mathsf{sort}([re_m, im_m])\\ \\ \frac{\log im\_m}{\log 10} \end{array} \]
re_m = (fabs.f64 re)
im_m = (fabs.f64 im)
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
(FPCore (re_m im_m) :precision binary64 (/ (log im_m) (log 10.0)))
re_m = fabs(re);
im_m = fabs(im);
assert(re_m < im_m);
double code(double re_m, double im_m) {
	return log(im_m) / log(10.0);
}
re_m = abs(re)
im_m = abs(im)
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
real(8) function code(re_m, im_m)
    real(8), intent (in) :: re_m
    real(8), intent (in) :: im_m
    code = log(im_m) / log(10.0d0)
end function
re_m = Math.abs(re);
im_m = Math.abs(im);
assert re_m < im_m;
public static double code(double re_m, double im_m) {
	return Math.log(im_m) / Math.log(10.0);
}
re_m = math.fabs(re)
im_m = math.fabs(im)
[re_m, im_m] = sort([re_m, im_m])
def code(re_m, im_m):
	return math.log(im_m) / math.log(10.0)
re_m = abs(re)
im_m = abs(im)
re_m, im_m = sort([re_m, im_m])
function code(re_m, im_m)
	return Float64(log(im_m) / log(10.0))
end
re_m = abs(re);
im_m = abs(im);
re_m, im_m = num2cell(sort([re_m, im_m])){:}
function tmp = code(re_m, im_m)
	tmp = log(im_m) / log(10.0);
end
re_m = N[Abs[re], $MachinePrecision]
im_m = N[Abs[im], $MachinePrecision]
NOTE: re_m and im_m should be sorted in increasing order before calling this function.
code[re$95$m_, im$95$m_] := N[(N[Log[im$95$m], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
re_m = \left|re\right|
\\
im_m = \left|im\right|
\\
[re_m, im_m] = \mathsf{sort}([re_m, im_m])\\
\\
\frac{\log im\_m}{\log 10}
\end{array}
Derivation
  1. Initial program 53.6%

    \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \]
  2. Step-by-step derivation
    1. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\log \left(\sqrt{re \cdot re + im \cdot im}\right), \color{blue}{\log 10}\right) \]
    2. log-lowering-log.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{log.f64}\left(\left(\sqrt{re \cdot re + im \cdot im}\right)\right), \log \color{blue}{10}\right) \]
    3. hypot-defineN/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{log.f64}\left(\left(\mathsf{hypot}\left(re, im\right)\right)\right), \log 10\right) \]
    4. hypot-lowering-hypot.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{log.f64}\left(\mathsf{hypot.f64}\left(re, im\right)\right), \log 10\right) \]
    5. log-lowering-log.f6499.1%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{log.f64}\left(\mathsf{hypot.f64}\left(re, im\right)\right), \mathsf{log.f64}\left(10\right)\right) \]
  3. Simplified99.1%

    \[\leadsto \color{blue}{\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 10}} \]
  4. Add Preprocessing
  5. Taylor expanded in re around 0

    \[\leadsto \color{blue}{\frac{\log im}{\log 10}} \]
  6. Step-by-step derivation
    1. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\log im, \color{blue}{\log 10}\right) \]
    2. log-lowering-log.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{log.f64}\left(im\right), \log \color{blue}{10}\right) \]
    3. log-lowering-log.f6426.0%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{log.f64}\left(im\right), \mathsf{log.f64}\left(10\right)\right) \]
  7. Simplified26.0%

    \[\leadsto \color{blue}{\frac{\log im}{\log 10}} \]
  8. Add Preprocessing

Reproduce

?
herbie shell --seed 2024155 
(FPCore (re im)
  :name "math.log10 on complex, real part"
  :precision binary64
  (/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))