math.log10 on complex, real part

Percentage Accurate: 51.4% → 99.5%
Time: 12.9s
Alternatives: 6
Speedup: 1.0×

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 6 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.4% 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.5% accurate, 0.6× speedup?

\[\begin{array}{l} \\ {\left(\frac{1}{\sqrt{\log 10}}\right)}^{2} \cdot \log \left(\mathsf{hypot}\left(im, re\right)\right) \end{array} \]
(FPCore (re im)
 :precision binary64
 (* (pow (/ 1.0 (sqrt (log 10.0))) 2.0) (log (hypot im re))))
double code(double re, double im) {
	return pow((1.0 / sqrt(log(10.0))), 2.0) * log(hypot(im, re));
}
public static double code(double re, double im) {
	return Math.pow((1.0 / Math.sqrt(Math.log(10.0))), 2.0) * Math.log(Math.hypot(im, re));
}
def code(re, im):
	return math.pow((1.0 / math.sqrt(math.log(10.0))), 2.0) * math.log(math.hypot(im, re))
function code(re, im)
	return Float64((Float64(1.0 / sqrt(log(10.0))) ^ 2.0) * log(hypot(im, re)))
end
function tmp = code(re, im)
	tmp = ((1.0 / sqrt(log(10.0))) ^ 2.0) * log(hypot(im, re));
end
code[re_, im_] := N[(N[Power[N[(1.0 / N[Sqrt[N[Log[10.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * N[Log[N[Sqrt[im ^ 2 + re ^ 2], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
{\left(\frac{1}{\sqrt{\log 10}}\right)}^{2} \cdot \log \left(\mathsf{hypot}\left(im, re\right)\right)
\end{array}
Derivation
  1. Initial program 53.8%

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

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)}{\log 10} \]
    2. +-commutative53.8%

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)}{\log 10} \]
    3. sqr-neg53.8%

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{\left(-re\right) \cdot \left(-re\right)} + im \cdot im}\right)}{\log 10} \]
    4. sqr-neg53.8%

      \[\leadsto \frac{\log \left(\sqrt{\left(-re\right) \cdot \left(-re\right) + \color{blue}{\left(-im\right) \cdot \left(-im\right)}}\right)}{\log 10} \]
    5. sqr-neg53.8%

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re} + \left(-im\right) \cdot \left(-im\right)}\right)}{\log 10} \]
    6. sqr-neg53.8%

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)}{\log 10} \]
    7. hypot-define99.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. Add Preprocessing
  5. Step-by-step derivation
    1. *-un-lft-identity99.0%

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

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

      \[\leadsto \color{blue}{\frac{1}{\sqrt{\log 10}} \cdot \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\sqrt{\log 10}}} \]
    4. pow1/299.1%

      \[\leadsto \frac{1}{\color{blue}{{\log 10}^{0.5}}} \cdot \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\sqrt{\log 10}} \]
    5. pow-flip99.1%

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

      \[\leadsto {\log 10}^{\color{blue}{-0.5}} \cdot \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\sqrt{\log 10}} \]
  6. Applied egg-rr99.1%

    \[\leadsto \color{blue}{{\log 10}^{-0.5} \cdot \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\sqrt{\log 10}}} \]
  7. Step-by-step derivation
    1. *-commutative99.1%

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

      \[\leadsto \color{blue}{\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot {\log 10}^{-0.5}}{\sqrt{\log 10}}} \]
    3. associate-/l*99.5%

      \[\leadsto \color{blue}{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \frac{{\log 10}^{-0.5}}{\sqrt{\log 10}}} \]
    4. hypot-undefine54.1%

      \[\leadsto \log \color{blue}{\left(\sqrt{re \cdot re + im \cdot im}\right)} \cdot \frac{{\log 10}^{-0.5}}{\sqrt{\log 10}} \]
    5. unpow254.1%

      \[\leadsto \log \left(\sqrt{\color{blue}{{re}^{2}} + im \cdot im}\right) \cdot \frac{{\log 10}^{-0.5}}{\sqrt{\log 10}} \]
    6. unpow254.1%

      \[\leadsto \log \left(\sqrt{{re}^{2} + \color{blue}{{im}^{2}}}\right) \cdot \frac{{\log 10}^{-0.5}}{\sqrt{\log 10}} \]
    7. +-commutative54.1%

      \[\leadsto \log \left(\sqrt{\color{blue}{{im}^{2} + {re}^{2}}}\right) \cdot \frac{{\log 10}^{-0.5}}{\sqrt{\log 10}} \]
    8. unpow254.1%

      \[\leadsto \log \left(\sqrt{\color{blue}{im \cdot im} + {re}^{2}}\right) \cdot \frac{{\log 10}^{-0.5}}{\sqrt{\log 10}} \]
    9. unpow254.1%

      \[\leadsto \log \left(\sqrt{im \cdot im + \color{blue}{re \cdot re}}\right) \cdot \frac{{\log 10}^{-0.5}}{\sqrt{\log 10}} \]
    10. hypot-define99.5%

      \[\leadsto \log \color{blue}{\left(\mathsf{hypot}\left(im, re\right)\right)} \cdot \frac{{\log 10}^{-0.5}}{\sqrt{\log 10}} \]
  8. Simplified99.5%

    \[\leadsto \color{blue}{\log \left(\mathsf{hypot}\left(im, re\right)\right) \cdot \frac{{\log 10}^{-0.5}}{\sqrt{\log 10}}} \]
  9. Step-by-step derivation
    1. add-log-exp99.5%

      \[\leadsto \color{blue}{\log \left(e^{\log \left(\mathsf{hypot}\left(im, re\right)\right) \cdot \frac{{\log 10}^{-0.5}}{\sqrt{\log 10}}}\right)} \]
    2. exp-to-pow99.8%

      \[\leadsto \log \color{blue}{\left({\left(\mathsf{hypot}\left(im, re\right)\right)}^{\left(\frac{{\log 10}^{-0.5}}{\sqrt{\log 10}}\right)}\right)} \]
    3. hypot-undefine54.2%

      \[\leadsto \log \left({\color{blue}{\left(\sqrt{im \cdot im + re \cdot re}\right)}}^{\left(\frac{{\log 10}^{-0.5}}{\sqrt{\log 10}}\right)}\right) \]
    4. +-commutative54.2%

      \[\leadsto \log \left({\left(\sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)}^{\left(\frac{{\log 10}^{-0.5}}{\sqrt{\log 10}}\right)}\right) \]
    5. hypot-undefine99.8%

      \[\leadsto \log \left({\color{blue}{\left(\mathsf{hypot}\left(re, im\right)\right)}}^{\left(\frac{{\log 10}^{-0.5}}{\sqrt{\log 10}}\right)}\right) \]
    6. exp-to-pow99.5%

      \[\leadsto \log \color{blue}{\left(e^{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \frac{{\log 10}^{-0.5}}{\sqrt{\log 10}}}\right)} \]
    7. add-log-exp99.5%

      \[\leadsto \color{blue}{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \frac{{\log 10}^{-0.5}}{\sqrt{\log 10}}} \]
    8. pow1/299.5%

      \[\leadsto \log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \frac{{\log 10}^{-0.5}}{\color{blue}{{\log 10}^{0.5}}} \]
    9. pow-div98.5%

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

      \[\leadsto \log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot {\log 10}^{\color{blue}{-1}} \]
    11. inv-pow98.5%

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

      \[\leadsto \color{blue}{\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 10}} \]
    13. frac-2neg99.0%

      \[\leadsto \color{blue}{\frac{-\log \left(\mathsf{hypot}\left(re, im\right)\right)}{-\log 10}} \]
    14. hypot-undefine53.8%

      \[\leadsto \frac{-\log \color{blue}{\left(\sqrt{re \cdot re + im \cdot im}\right)}}{-\log 10} \]
    15. +-commutative53.8%

      \[\leadsto \frac{-\log \left(\sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)}{-\log 10} \]
    16. hypot-undefine99.0%

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

    \[\leadsto \color{blue}{\frac{-\log \left(\mathsf{hypot}\left(im, re\right)\right)}{\log 0.1}} \]
  11. Step-by-step derivation
    1. neg-mul-199.1%

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

      \[\leadsto \color{blue}{\frac{-1}{\log 0.1} \cdot \log \left(\mathsf{hypot}\left(im, re\right)\right)} \]
    3. add-sqr-sqrt99.5%

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

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

      \[\leadsto \sqrt{\frac{\color{blue}{-1}}{\log 0.1}} \cdot \left(\sqrt{\frac{-1}{\log 0.1}} \cdot \log \left(\mathsf{hypot}\left(im, re\right)\right)\right) \]
    6. metadata-eval99.4%

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

      \[\leadsto \sqrt{\frac{-1}{\color{blue}{-\log 10}}} \cdot \left(\sqrt{\frac{-1}{\log 0.1}} \cdot \log \left(\mathsf{hypot}\left(im, re\right)\right)\right) \]
    8. frac-2neg99.4%

      \[\leadsto \sqrt{\color{blue}{\frac{1}{\log 10}}} \cdot \left(\sqrt{\frac{-1}{\log 0.1}} \cdot \log \left(\mathsf{hypot}\left(im, re\right)\right)\right) \]
    9. sqrt-div99.4%

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\sqrt{\log 10}} \cdot \left(\frac{\color{blue}{1}}{\sqrt{\log 10}} \cdot \log \left(\mathsf{hypot}\left(im, re\right)\right)\right) \]
  12. Applied egg-rr99.4%

    \[\leadsto \color{blue}{\frac{1}{\sqrt{\log 10}} \cdot \left(\frac{1}{\sqrt{\log 10}} \cdot \log \left(\mathsf{hypot}\left(im, re\right)\right)\right)} \]
  13. Step-by-step derivation
    1. associate-*r*99.5%

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

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

    \[\leadsto \color{blue}{{\left(\frac{1}{\sqrt{\log 10}}\right)}^{2} \cdot \log \left(\mathsf{hypot}\left(im, re\right)\right)} \]
  15. Final simplification99.5%

    \[\leadsto {\left(\frac{1}{\sqrt{\log 10}}\right)}^{2} \cdot \log \left(\mathsf{hypot}\left(im, re\right)\right) \]
  16. Add Preprocessing

Alternative 2: 26.5% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \log \left({im}^{\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-1}{\mathsf{log1p}\left(-0.9\right)}\right)\right)\right)}\right) \end{array} \]
(FPCore (re im)
 :precision binary64
 (log (pow im (log1p (expm1 (/ -1.0 (log1p -0.9)))))))
double code(double re, double im) {
	return log(pow(im, log1p(expm1((-1.0 / log1p(-0.9))))));
}
public static double code(double re, double im) {
	return Math.log(Math.pow(im, Math.log1p(Math.expm1((-1.0 / Math.log1p(-0.9))))));
}
def code(re, im):
	return math.log(math.pow(im, math.log1p(math.expm1((-1.0 / math.log1p(-0.9))))))
function code(re, im)
	return log((im ^ log1p(expm1(Float64(-1.0 / log1p(-0.9))))))
end
code[re_, im_] := N[Log[N[Power[im, N[Log[1 + N[(Exp[N[(-1.0 / N[Log[1 + -0.9], $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\log \left({im}^{\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-1}{\mathsf{log1p}\left(-0.9\right)}\right)\right)\right)}\right)
\end{array}
Derivation
  1. Initial program 53.8%

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

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)}{\log 10} \]
    2. +-commutative53.8%

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)}{\log 10} \]
    3. sqr-neg53.8%

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{\left(-re\right) \cdot \left(-re\right)} + im \cdot im}\right)}{\log 10} \]
    4. sqr-neg53.8%

      \[\leadsto \frac{\log \left(\sqrt{\left(-re\right) \cdot \left(-re\right) + \color{blue}{\left(-im\right) \cdot \left(-im\right)}}\right)}{\log 10} \]
    5. sqr-neg53.8%

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re} + \left(-im\right) \cdot \left(-im\right)}\right)}{\log 10} \]
    6. sqr-neg53.8%

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)}{\log 10} \]
    7. hypot-define99.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. Add Preprocessing
  5. Taylor expanded in re around 0 24.3%

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

      \[\leadsto \color{blue}{\log im \cdot \frac{1}{\log 10}} \]
    2. inv-pow24.2%

      \[\leadsto \log im \cdot \color{blue}{{\log 10}^{-1}} \]
    3. metadata-eval24.2%

      \[\leadsto \log im \cdot {\log 10}^{\color{blue}{\left(-0.5 - 0.5\right)}} \]
    4. pow-div24.4%

      \[\leadsto \log im \cdot \color{blue}{\frac{{\log 10}^{-0.5}}{{\log 10}^{0.5}}} \]
    5. pow1/224.4%

      \[\leadsto \log im \cdot \frac{{\log 10}^{-0.5}}{\color{blue}{\sqrt{\log 10}}} \]
    6. add-log-exp24.4%

      \[\leadsto \color{blue}{\log \left(e^{\log im \cdot \frac{{\log 10}^{-0.5}}{\sqrt{\log 10}}}\right)} \]
    7. exp-to-pow24.5%

      \[\leadsto \log \color{blue}{\left({im}^{\left(\frac{{\log 10}^{-0.5}}{\sqrt{\log 10}}\right)}\right)} \]
    8. pow1/224.5%

      \[\leadsto \log \left({im}^{\left(\frac{{\log 10}^{-0.5}}{\color{blue}{{\log 10}^{0.5}}}\right)}\right) \]
    9. pow-div24.2%

      \[\leadsto \log \left({im}^{\color{blue}{\left({\log 10}^{\left(-0.5 - 0.5\right)}\right)}}\right) \]
    10. metadata-eval24.2%

      \[\leadsto \log \left({im}^{\left({\log 10}^{\color{blue}{-1}}\right)}\right) \]
    11. inv-pow24.2%

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

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

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

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

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

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

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

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

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

      \[\leadsto \log \left({im}^{\color{blue}{\left(\frac{1}{\log 10}\right)}}\right) \]
    5. log1p-expm1-u24.5%

      \[\leadsto \log \left({im}^{\color{blue}{\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{1}{\log 10}\right)\right)\right)}}\right) \]
    6. frac-2neg24.5%

      \[\leadsto \log \left({im}^{\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\frac{-1}{-\log 10}}\right)\right)\right)}\right) \]
    7. metadata-eval24.5%

      \[\leadsto \log \left({im}^{\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\color{blue}{-1}}{-\log 10}\right)\right)\right)}\right) \]
    8. log1p-expm1-u24.5%

      \[\leadsto \log \left({im}^{\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-1}{\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(-\log 10\right)\right)}}\right)\right)\right)}\right) \]
    9. neg-log24.5%

      \[\leadsto \log \left({im}^{\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-1}{\mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\log \left(\frac{1}{10}\right)}\right)\right)}\right)\right)\right)}\right) \]
    10. metadata-eval24.5%

      \[\leadsto \log \left({im}^{\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-1}{\mathsf{log1p}\left(\mathsf{expm1}\left(\log \color{blue}{0.1}\right)\right)}\right)\right)\right)}\right) \]
    11. expm1-undefine24.5%

      \[\leadsto \log \left({im}^{\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-1}{\mathsf{log1p}\left(\color{blue}{e^{\log 0.1} - 1}\right)}\right)\right)\right)}\right) \]
    12. rem-exp-log24.5%

      \[\leadsto \log \left({im}^{\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-1}{\mathsf{log1p}\left(\color{blue}{0.1} - 1\right)}\right)\right)\right)}\right) \]
    13. metadata-eval24.5%

      \[\leadsto \log \left({im}^{\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-1}{\mathsf{log1p}\left(\color{blue}{-0.9}\right)}\right)\right)\right)}\right) \]
  9. Applied egg-rr24.5%

    \[\leadsto \log \left({im}^{\color{blue}{\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-1}{\mathsf{log1p}\left(-0.9\right)}\right)\right)\right)}}\right) \]
  10. Final simplification24.5%

    \[\leadsto \log \left({im}^{\left(\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{-1}{\mathsf{log1p}\left(-0.9\right)}\right)\right)\right)}\right) \]
  11. Add Preprocessing

Alternative 3: 99.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{-\log 0.1} \end{array} \]
(FPCore (re im) :precision binary64 (/ (log (hypot re im)) (- (log 0.1))))
double code(double re, double im) {
	return log(hypot(re, im)) / -log(0.1);
}
public static double code(double re, double im) {
	return Math.log(Math.hypot(re, im)) / -Math.log(0.1);
}
def code(re, im):
	return math.log(math.hypot(re, im)) / -math.log(0.1)
function code(re, im)
	return Float64(log(hypot(re, im)) / Float64(-log(0.1)))
end
function tmp = code(re, im)
	tmp = log(hypot(re, im)) / -log(0.1);
end
code[re_, im_] := N[(N[Log[N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]], $MachinePrecision] / (-N[Log[0.1], $MachinePrecision])), $MachinePrecision]
\begin{array}{l}

\\
\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{-\log 0.1}
\end{array}
Derivation
  1. Initial program 53.8%

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

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)}{\log 10} \]
    2. +-commutative53.8%

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)}{\log 10} \]
    3. sqr-neg53.8%

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{\left(-re\right) \cdot \left(-re\right)} + im \cdot im}\right)}{\log 10} \]
    4. sqr-neg53.8%

      \[\leadsto \frac{\log \left(\sqrt{\left(-re\right) \cdot \left(-re\right) + \color{blue}{\left(-im\right) \cdot \left(-im\right)}}\right)}{\log 10} \]
    5. sqr-neg53.8%

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re} + \left(-im\right) \cdot \left(-im\right)}\right)}{\log 10} \]
    6. sqr-neg53.8%

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)}{\log 10} \]
    7. hypot-define99.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. Add Preprocessing
  5. 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.1%

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

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

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

      \[\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} \]
    4. distribute-neg-frac99.1%

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

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

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

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

Alternative 4: 99.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 10} \end{array} \]
(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}
Derivation
  1. Initial program 53.8%

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

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)}{\log 10} \]
    2. +-commutative53.8%

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)}{\log 10} \]
    3. sqr-neg53.8%

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{\left(-re\right) \cdot \left(-re\right)} + im \cdot im}\right)}{\log 10} \]
    4. sqr-neg53.8%

      \[\leadsto \frac{\log \left(\sqrt{\left(-re\right) \cdot \left(-re\right) + \color{blue}{\left(-im\right) \cdot \left(-im\right)}}\right)}{\log 10} \]
    5. sqr-neg53.8%

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re} + \left(-im\right) \cdot \left(-im\right)}\right)}{\log 10} \]
    6. sqr-neg53.8%

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)}{\log 10} \]
    7. hypot-define99.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. Add Preprocessing
  5. Final simplification99.0%

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

Alternative 5: 26.3% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \frac{\log im}{-\log 0.1} \end{array} \]
(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}
Derivation
  1. Initial program 53.8%

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

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)}{\log 10} \]
    2. +-commutative53.8%

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)}{\log 10} \]
    3. sqr-neg53.8%

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{\left(-re\right) \cdot \left(-re\right)} + im \cdot im}\right)}{\log 10} \]
    4. sqr-neg53.8%

      \[\leadsto \frac{\log \left(\sqrt{\left(-re\right) \cdot \left(-re\right) + \color{blue}{\left(-im\right) \cdot \left(-im\right)}}\right)}{\log 10} \]
    5. sqr-neg53.8%

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re} + \left(-im\right) \cdot \left(-im\right)}\right)}{\log 10} \]
    6. sqr-neg53.8%

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)}{\log 10} \]
    7. hypot-define99.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. Add Preprocessing
  5. Taylor expanded in re around 0 24.3%

    \[\leadsto \color{blue}{\frac{\log im}{\log 10}} \]
  6. Step-by-step derivation
    1. clear-num24.3%

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

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

      \[\leadsto \color{blue}{\frac{-1}{-\log 10}} \cdot \log im \]
    4. metadata-eval24.2%

      \[\leadsto \frac{\color{blue}{-1}}{-\log 10} \cdot \log im \]
    5. neg-log24.3%

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

      \[\leadsto \frac{-1}{\log \color{blue}{0.1}} \cdot \log im \]
  7. Applied egg-rr24.3%

    \[\leadsto \color{blue}{\frac{-1}{\log 0.1} \cdot \log im} \]
  8. Step-by-step derivation
    1. associate-*l/24.4%

      \[\leadsto \color{blue}{\frac{-1 \cdot \log im}{\log 0.1}} \]
    2. neg-mul-124.4%

      \[\leadsto \frac{\color{blue}{-\log im}}{\log 0.1} \]
  9. Simplified24.4%

    \[\leadsto \color{blue}{\frac{-\log im}{\log 0.1}} \]
  10. Final simplification24.4%

    \[\leadsto \frac{\log im}{-\log 0.1} \]
  11. Add Preprocessing

Alternative 6: 26.4% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \frac{\log im}{\log 10} \end{array} \]
(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}
Derivation
  1. Initial program 53.8%

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

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{im \cdot im + re \cdot re}}\right)}{\log 10} \]
    2. +-commutative53.8%

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re + im \cdot im}}\right)}{\log 10} \]
    3. sqr-neg53.8%

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{\left(-re\right) \cdot \left(-re\right)} + im \cdot im}\right)}{\log 10} \]
    4. sqr-neg53.8%

      \[\leadsto \frac{\log \left(\sqrt{\left(-re\right) \cdot \left(-re\right) + \color{blue}{\left(-im\right) \cdot \left(-im\right)}}\right)}{\log 10} \]
    5. sqr-neg53.8%

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{re \cdot re} + \left(-im\right) \cdot \left(-im\right)}\right)}{\log 10} \]
    6. sqr-neg53.8%

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + \color{blue}{im \cdot im}}\right)}{\log 10} \]
    7. hypot-define99.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. Add Preprocessing
  5. Taylor expanded in re around 0 24.3%

    \[\leadsto \color{blue}{\frac{\log im}{\log 10}} \]
  6. Final simplification24.3%

    \[\leadsto \frac{\log im}{\log 10} \]
  7. Add Preprocessing

Reproduce

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