math.log10 on complex, real part

Percentage Accurate: 52.0% → 99.0%
Time: 7.7s
Alternatives: 5
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 5 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: 52.0% 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: 99.0% accurate, 0.6× speedup?

\[\begin{array}{l} re = |re|\\ im = |im|\\ [re, im] = \mathsf{sort}([re, im])\\ \\ \log \left({im}^{\left({\left({\log 10}^{-0.5}\right)}^{2}\right)}\right) \end{array} \]
NOTE: re should be positive before calling this function
NOTE: im should be positive before calling this function
NOTE: re and im should be sorted in increasing order before calling this function.
(FPCore (re im)
 :precision binary64
 (log (pow im (pow (pow (log 10.0) -0.5) 2.0))))
re = abs(re);
im = abs(im);
assert(re < im);
double code(double re, double im) {
	return log(pow(im, pow(pow(log(10.0), -0.5), 2.0)));
}
NOTE: re should be positive before calling this function
NOTE: im should be positive before calling this function
NOTE: re and im should be sorted in increasing order before calling this function.
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = log((im ** ((log(10.0d0) ** (-0.5d0)) ** 2.0d0)))
end function
re = Math.abs(re);
im = Math.abs(im);
assert re < im;
public static double code(double re, double im) {
	return Math.log(Math.pow(im, Math.pow(Math.pow(Math.log(10.0), -0.5), 2.0)));
}
re = abs(re)
im = abs(im)
[re, im] = sort([re, im])
def code(re, im):
	return math.log(math.pow(im, math.pow(math.pow(math.log(10.0), -0.5), 2.0)))
re = abs(re)
im = abs(im)
re, im = sort([re, im])
function code(re, im)
	return log((im ^ ((log(10.0) ^ -0.5) ^ 2.0)))
end
re = abs(re)
im = abs(im)
re, im = num2cell(sort([re, im])){:}
function tmp = code(re, im)
	tmp = log((im ^ ((log(10.0) ^ -0.5) ^ 2.0)));
end
NOTE: re should be positive before calling this function
NOTE: im should be positive before calling this function
NOTE: re and im should be sorted in increasing order before calling this function.
code[re_, im_] := N[Log[N[Power[im, N[Power[N[Power[N[Log[10.0], $MachinePrecision], -0.5], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
re = |re|\\
im = |im|\\
[re, im] = \mathsf{sort}([re, im])\\
\\
\log \left({im}^{\left({\left({\log 10}^{-0.5}\right)}^{2}\right)}\right)
\end{array}
Derivation
  1. Initial program 57.1%

    \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \]
  2. Step-by-step derivation
    1. hypot-def99.0%

      \[\leadsto \frac{\log \color{blue}{\left(\mathsf{hypot}\left(re, im\right)\right)}}{\log 10} \]
  3. Simplified99.0%

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

    \[\leadsto \color{blue}{\frac{\log im}{\log 10}} \]
  5. Step-by-step derivation
    1. frac-2neg28.1%

      \[\leadsto \color{blue}{\frac{-\log im}{-\log 10}} \]
    2. div-inv28.0%

      \[\leadsto \color{blue}{\left(-\log im\right) \cdot \frac{1}{-\log 10}} \]
    3. neg-log28.1%

      \[\leadsto \left(-\log im\right) \cdot \frac{1}{\color{blue}{\log \left(\frac{1}{10}\right)}} \]
    4. metadata-eval28.1%

      \[\leadsto \left(-\log im\right) \cdot \frac{1}{\log \color{blue}{0.1}} \]
  6. Applied egg-rr28.1%

    \[\leadsto \color{blue}{\left(-\log im\right) \cdot \frac{1}{\log 0.1}} \]
  7. Step-by-step derivation
    1. log-rec28.1%

      \[\leadsto \color{blue}{\log \left(\frac{1}{im}\right)} \cdot \frac{1}{\log 0.1} \]
    2. associate-*r/28.1%

      \[\leadsto \color{blue}{\frac{\log \left(\frac{1}{im}\right) \cdot 1}{\log 0.1}} \]
    3. *-rgt-identity28.1%

      \[\leadsto \frac{\color{blue}{\log \left(\frac{1}{im}\right)}}{\log 0.1} \]
    4. log-rec28.1%

      \[\leadsto \frac{\color{blue}{-\log im}}{\log 0.1} \]
  8. Simplified28.1%

    \[\leadsto \color{blue}{\frac{-\log im}{\log 0.1}} \]
  9. Step-by-step derivation
    1. metadata-eval28.1%

      \[\leadsto \frac{-\log im}{\log \color{blue}{\left(\frac{1}{10}\right)}} \]
    2. neg-log28.1%

      \[\leadsto \frac{-\log im}{\color{blue}{-\log 10}} \]
    3. frac-2neg28.1%

      \[\leadsto \color{blue}{\frac{\log im}{\log 10}} \]
    4. rem-cbrt-cube28.1%

      \[\leadsto \color{blue}{\sqrt[3]{{\left(\frac{\log im}{\log 10}\right)}^{3}}} \]
    5. add-log-exp28.1%

      \[\leadsto \color{blue}{\log \left(e^{\sqrt[3]{{\left(\frac{\log im}{\log 10}\right)}^{3}}}\right)} \]
    6. rem-cbrt-cube28.1%

      \[\leadsto \log \left(e^{\color{blue}{\frac{\log im}{\log 10}}}\right) \]
    7. div-inv28.0%

      \[\leadsto \log \left(e^{\color{blue}{\log im \cdot \frac{1}{\log 10}}}\right) \]
    8. inv-pow28.0%

      \[\leadsto \log \left(e^{\log im \cdot \color{blue}{{\log 10}^{-1}}}\right) \]
    9. metadata-eval28.0%

      \[\leadsto \log \left(e^{\log im \cdot {\log 10}^{\color{blue}{\left(-0.5 + -0.5\right)}}}\right) \]
    10. pow-prod-up28.2%

      \[\leadsto \log \left(e^{\log im \cdot \color{blue}{\left({\log 10}^{-0.5} \cdot {\log 10}^{-0.5}\right)}}\right) \]
    11. exp-to-pow28.3%

      \[\leadsto \log \color{blue}{\left({im}^{\left({\log 10}^{-0.5} \cdot {\log 10}^{-0.5}\right)}\right)} \]
    12. pow-prod-up28.0%

      \[\leadsto \log \left({im}^{\color{blue}{\left({\log 10}^{\left(-0.5 + -0.5\right)}\right)}}\right) \]
    13. metadata-eval28.0%

      \[\leadsto \log \left({im}^{\left({\log 10}^{\color{blue}{-1}}\right)}\right) \]
    14. inv-pow28.0%

      \[\leadsto \log \left({im}^{\color{blue}{\left(\frac{1}{\log 10}\right)}}\right) \]
    15. frac-2neg28.0%

      \[\leadsto \log \left({im}^{\color{blue}{\left(\frac{-1}{-\log 10}\right)}}\right) \]
    16. metadata-eval28.0%

      \[\leadsto \log \left({im}^{\left(\frac{\color{blue}{-1}}{-\log 10}\right)}\right) \]
    17. neg-log28.1%

      \[\leadsto \log \left({im}^{\left(\frac{-1}{\color{blue}{\log \left(\frac{1}{10}\right)}}\right)}\right) \]
    18. metadata-eval28.1%

      \[\leadsto \log \left({im}^{\left(\frac{-1}{\log \color{blue}{0.1}}\right)}\right) \]
  10. Applied egg-rr28.1%

    \[\leadsto \color{blue}{\log \left({im}^{\left(\frac{-1}{\log 0.1}\right)}\right)} \]
  11. Step-by-step derivation
    1. metadata-eval28.1%

      \[\leadsto \log \left({im}^{\left(\frac{\color{blue}{-1}}{\log 0.1}\right)}\right) \]
    2. metadata-eval28.1%

      \[\leadsto \log \left({im}^{\left(\frac{-1}{\log \color{blue}{\left(\frac{1}{10}\right)}}\right)}\right) \]
    3. neg-log28.0%

      \[\leadsto \log \left({im}^{\left(\frac{-1}{\color{blue}{-\log 10}}\right)}\right) \]
    4. frac-2neg28.0%

      \[\leadsto \log \left({im}^{\color{blue}{\left(\frac{1}{\log 10}\right)}}\right) \]
    5. inv-pow28.0%

      \[\leadsto \log \left({im}^{\color{blue}{\left({\log 10}^{-1}\right)}}\right) \]
    6. metadata-eval28.0%

      \[\leadsto \log \left({im}^{\left({\log 10}^{\color{blue}{\left(2 \cdot -0.5\right)}}\right)}\right) \]
    7. pow-sqr28.3%

      \[\leadsto \log \left({im}^{\color{blue}{\left({\log 10}^{-0.5} \cdot {\log 10}^{-0.5}\right)}}\right) \]
    8. pow228.3%

      \[\leadsto \log \left({im}^{\color{blue}{\left({\left({\log 10}^{-0.5}\right)}^{2}\right)}}\right) \]
  12. Applied egg-rr28.3%

    \[\leadsto \log \left({im}^{\color{blue}{\left({\left({\log 10}^{-0.5}\right)}^{2}\right)}}\right) \]
  13. Final simplification28.3%

    \[\leadsto \log \left({im}^{\left({\left({\log 10}^{-0.5}\right)}^{2}\right)}\right) \]

Alternative 2: 99.0% accurate, 1.0× speedup?

\[\begin{array}{l} re = |re|\\ im = |im|\\ [re, im] = \mathsf{sort}([re, im])\\ \\ -\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 0.1} \end{array} \]
NOTE: re should be positive before calling this function
NOTE: im should be positive before calling this function
NOTE: re and im should be sorted in increasing order before calling this function.
(FPCore (re im) :precision binary64 (- (/ (log (hypot re im)) (log 0.1))))
re = abs(re);
im = abs(im);
assert(re < im);
double code(double re, double im) {
	return -(log(hypot(re, im)) / log(0.1));
}
re = Math.abs(re);
im = Math.abs(im);
assert re < im;
public static double code(double re, double im) {
	return -(Math.log(Math.hypot(re, im)) / Math.log(0.1));
}
re = abs(re)
im = abs(im)
[re, im] = sort([re, im])
def code(re, im):
	return -(math.log(math.hypot(re, im)) / math.log(0.1))
re = abs(re)
im = abs(im)
re, im = sort([re, im])
function code(re, im)
	return Float64(-Float64(log(hypot(re, im)) / log(0.1)))
end
re = abs(re)
im = abs(im)
re, im = num2cell(sort([re, im])){:}
function tmp = code(re, im)
	tmp = -(log(hypot(re, im)) / log(0.1));
end
NOTE: re should be positive before calling this function
NOTE: im should be positive before calling this function
NOTE: re and im should be sorted in increasing order before calling this function.
code[re_, im_] := (-N[(N[Log[N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]], $MachinePrecision] / N[Log[0.1], $MachinePrecision]), $MachinePrecision])
\begin{array}{l}
re = |re|\\
im = |im|\\
[re, im] = \mathsf{sort}([re, im])\\
\\
-\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 0.1}
\end{array}
Derivation
  1. Initial program 57.1%

    \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \]
  2. Step-by-step derivation
    1. hypot-def99.0%

      \[\leadsto \frac{\log \color{blue}{\left(\mathsf{hypot}\left(re, im\right)\right)}}{\log 10} \]
  3. Simplified99.0%

    \[\leadsto \color{blue}{\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 10}} \]
  4. Step-by-step derivation
    1. div-inv98.5%

      \[\leadsto \color{blue}{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \frac{1}{\log 10}} \]
    2. frac-2neg98.5%

      \[\leadsto \log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \color{blue}{\frac{-1}{-\log 10}} \]
    3. metadata-eval98.5%

      \[\leadsto \log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \frac{\color{blue}{-1}}{-\log 10} \]
    4. neg-log99.0%

      \[\leadsto \log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \frac{-1}{\color{blue}{\log \left(\frac{1}{10}\right)}} \]
    5. metadata-eval99.0%

      \[\leadsto \log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \frac{-1}{\log \color{blue}{0.1}} \]
  5. Applied egg-rr99.0%

    \[\leadsto \color{blue}{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \frac{-1}{\log 0.1}} \]
  6. Step-by-step derivation
    1. *-commutative99.0%

      \[\leadsto \color{blue}{\frac{-1}{\log 0.1} \cdot \log \left(\mathsf{hypot}\left(re, im\right)\right)} \]
    2. associate-*l/99.1%

      \[\leadsto \color{blue}{\frac{-1 \cdot \log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 0.1}} \]
    3. neg-mul-199.1%

      \[\leadsto \frac{\color{blue}{-\log \left(\mathsf{hypot}\left(re, im\right)\right)}}{\log 0.1} \]
  7. Simplified99.1%

    \[\leadsto \color{blue}{\frac{-\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 0.1}} \]
  8. Final simplification99.1%

    \[\leadsto -\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 0.1} \]

Alternative 3: 99.1% accurate, 1.0× speedup?

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

    \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \]
  2. Step-by-step derivation
    1. hypot-def99.0%

      \[\leadsto \frac{\log \color{blue}{\left(\mathsf{hypot}\left(re, im\right)\right)}}{\log 10} \]
  3. Simplified99.0%

    \[\leadsto \color{blue}{\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 10}} \]
  4. Final simplification99.0%

    \[\leadsto \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 10} \]

Alternative 4: 98.3% accurate, 1.5× speedup?

\[\begin{array}{l} re = |re|\\ im = |im|\\ [re, im] = \mathsf{sort}([re, im])\\ \\ \frac{-\log im}{\log 0.1} \end{array} \]
NOTE: re should be positive before calling this function
NOTE: im should be positive before calling this function
NOTE: re and im should be sorted in increasing order before calling this function.
(FPCore (re im) :precision binary64 (/ (- (log im)) (log 0.1)))
re = abs(re);
im = abs(im);
assert(re < im);
double code(double re, double im) {
	return -log(im) / log(0.1);
}
NOTE: re should be positive before calling this function
NOTE: im should be positive before calling this function
NOTE: re and im should be sorted in increasing order before calling this function.
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = -log(im) / log(0.1d0)
end function
re = Math.abs(re);
im = Math.abs(im);
assert re < im;
public static double code(double re, double im) {
	return -Math.log(im) / Math.log(0.1);
}
re = abs(re)
im = abs(im)
[re, im] = sort([re, im])
def code(re, im):
	return -math.log(im) / math.log(0.1)
re = abs(re)
im = abs(im)
re, im = sort([re, im])
function code(re, im)
	return Float64(Float64(-log(im)) / log(0.1))
end
re = abs(re)
im = abs(im)
re, im = num2cell(sort([re, im])){:}
function tmp = code(re, im)
	tmp = -log(im) / log(0.1);
end
NOTE: re should be positive before calling this function
NOTE: im should be positive before calling this function
NOTE: re and im should be sorted in increasing order before calling this function.
code[re_, im_] := N[((-N[Log[im], $MachinePrecision]) / N[Log[0.1], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
re = |re|\\
im = |im|\\
[re, im] = \mathsf{sort}([re, im])\\
\\
\frac{-\log im}{\log 0.1}
\end{array}
Derivation
  1. Initial program 57.1%

    \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \]
  2. Step-by-step derivation
    1. hypot-def99.0%

      \[\leadsto \frac{\log \color{blue}{\left(\mathsf{hypot}\left(re, im\right)\right)}}{\log 10} \]
  3. Simplified99.0%

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

    \[\leadsto \color{blue}{\frac{\log im}{\log 10}} \]
  5. Step-by-step derivation
    1. frac-2neg28.1%

      \[\leadsto \color{blue}{\frac{-\log im}{-\log 10}} \]
    2. div-inv28.0%

      \[\leadsto \color{blue}{\left(-\log im\right) \cdot \frac{1}{-\log 10}} \]
    3. neg-log28.1%

      \[\leadsto \left(-\log im\right) \cdot \frac{1}{\color{blue}{\log \left(\frac{1}{10}\right)}} \]
    4. metadata-eval28.1%

      \[\leadsto \left(-\log im\right) \cdot \frac{1}{\log \color{blue}{0.1}} \]
  6. Applied egg-rr28.1%

    \[\leadsto \color{blue}{\left(-\log im\right) \cdot \frac{1}{\log 0.1}} \]
  7. Step-by-step derivation
    1. log-rec28.1%

      \[\leadsto \color{blue}{\log \left(\frac{1}{im}\right)} \cdot \frac{1}{\log 0.1} \]
    2. associate-*r/28.1%

      \[\leadsto \color{blue}{\frac{\log \left(\frac{1}{im}\right) \cdot 1}{\log 0.1}} \]
    3. *-rgt-identity28.1%

      \[\leadsto \frac{\color{blue}{\log \left(\frac{1}{im}\right)}}{\log 0.1} \]
    4. log-rec28.1%

      \[\leadsto \frac{\color{blue}{-\log im}}{\log 0.1} \]
  8. Simplified28.1%

    \[\leadsto \color{blue}{\frac{-\log im}{\log 0.1}} \]
  9. Final simplification28.1%

    \[\leadsto \frac{-\log im}{\log 0.1} \]

Alternative 5: 98.4% accurate, 1.5× speedup?

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

    \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10} \]
  2. Step-by-step derivation
    1. hypot-def99.0%

      \[\leadsto \frac{\log \color{blue}{\left(\mathsf{hypot}\left(re, im\right)\right)}}{\log 10} \]
  3. Simplified99.0%

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

    \[\leadsto \color{blue}{\frac{\log im}{\log 10}} \]
  5. Final simplification28.1%

    \[\leadsto \frac{\log im}{\log 10} \]

Reproduce

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