math.log10 on complex, real part

Percentage Accurate: 52.5% → 99.7%
Time: 10.2s
Alternatives: 8
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 8 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.5% 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.7% accurate, 0.5× speedup?

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

\\
\log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left({\left({\log 10}^{-0.5}\right)}^{2}\right)}\right)
\end{array}
Derivation
  1. Initial program 53.9%

    \[\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. add-log-exp99.0%

      \[\leadsto \color{blue}{\log \left(e^{\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 10}}\right)} \]
    2. div-inv98.5%

      \[\leadsto \log \left(e^{\color{blue}{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \frac{1}{\log 10}}}\right) \]
    3. exp-to-pow98.5%

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

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

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

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

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

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

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

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

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

      \[\leadsto \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\color{blue}{\left(\frac{1}{\log 10}\right)}}\right) \]
    5. add-sqr-sqrt98.5%

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

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

      \[\leadsto \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\color{blue}{\left(\frac{1}{\sqrt{\log 10}} \cdot \frac{1}{\sqrt{\log 10}}\right)}}\right) \]
    8. pow299.7%

      \[\leadsto \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\color{blue}{\left({\left(\frac{1}{\sqrt{\log 10}}\right)}^{2}\right)}}\right) \]
    9. pow1/299.7%

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

      \[\leadsto \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left({\color{blue}{\left({\log 10}^{\left(-0.5\right)}\right)}}^{2}\right)}\right) \]
    11. metadata-eval99.7%

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

    \[\leadsto \log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\color{blue}{\left({\left({\log 10}^{-0.5}\right)}^{2}\right)}}\right) \]
  8. Final simplification99.7%

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

Alternative 2: 99.0% accurate, 1.0× speedup?

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

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

    \[\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. *-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}}} \]
  5. Applied egg-rr99.1%

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

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

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

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

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

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

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(-Float64(log(hypot(re, im)) / 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.9%

    \[\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.0%

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

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

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

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

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.9%

    \[\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 5: 27.6% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \frac{-1}{\frac{\log 0.1}{\log im}} \end{array} \]
(FPCore (re im) :precision binary64 (/ -1.0 (/ (log 0.1) (log im))))
double code(double re, double im) {
	return -1.0 / (log(0.1) / log(im));
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = (-1.0d0) / (log(0.1d0) / log(im))
end function
public static double code(double re, double im) {
	return -1.0 / (Math.log(0.1) / Math.log(im));
}
def code(re, im):
	return -1.0 / (math.log(0.1) / math.log(im))
function code(re, im)
	return Float64(-1.0 / Float64(log(0.1) / log(im)))
end
function tmp = code(re, im)
	tmp = -1.0 / (log(0.1) / log(im));
end
code[re_, im_] := N[(-1.0 / N[(N[Log[0.1], $MachinePrecision] / N[Log[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{-1}{\frac{\log 0.1}{\log im}}
\end{array}
Derivation
  1. Initial program 53.9%

    \[\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. add-log-exp99.0%

      \[\leadsto \color{blue}{\log \left(e^{\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 10}}\right)} \]
    2. div-inv98.5%

      \[\leadsto \log \left(e^{\color{blue}{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \frac{1}{\log 10}}}\right) \]
    3. exp-to-pow98.5%

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

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

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

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

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

    \[\leadsto \color{blue}{\log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left(\frac{-1}{\log 0.1}\right)}\right)} \]
  6. Taylor expanded in re around 0 28.8%

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

      \[\leadsto \log \left(e^{\color{blue}{-\frac{\log im}{\log 0.1}}}\right) \]
    2. distribute-neg-frac28.8%

      \[\leadsto \log \left(e^{\color{blue}{\frac{-\log im}{\log 0.1}}}\right) \]
    3. log-rec28.8%

      \[\leadsto \log \left(e^{\frac{\color{blue}{\log \left(\frac{1}{im}\right)}}{\log 0.1}}\right) \]
    4. *-rgt-identity28.8%

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

      \[\leadsto \log \left(e^{\color{blue}{\log \left(\frac{1}{im}\right) \cdot \frac{1}{\log 0.1}}}\right) \]
    6. exp-to-pow28.8%

      \[\leadsto \log \color{blue}{\left({\left(\frac{1}{im}\right)}^{\left(\frac{1}{\log 0.1}\right)}\right)} \]
  8. Simplified28.8%

    \[\leadsto \log \color{blue}{\left({\left(\frac{1}{im}\right)}^{\left(\frac{1}{\log 0.1}\right)}\right)} \]
  9. Step-by-step derivation
    1. pow-to-exp28.8%

      \[\leadsto \log \color{blue}{\left(e^{\log \left(\frac{1}{im}\right) \cdot \frac{1}{\log 0.1}}\right)} \]
    2. neg-log28.8%

      \[\leadsto \log \left(e^{\color{blue}{\left(-\log im\right)} \cdot \frac{1}{\log 0.1}}\right) \]
    3. div-inv28.8%

      \[\leadsto \log \left(e^{\color{blue}{\frac{-\log im}{\log 0.1}}}\right) \]
    4. add-log-exp28.8%

      \[\leadsto \color{blue}{\frac{-\log im}{\log 0.1}} \]
    5. neg-mul-128.8%

      \[\leadsto \frac{\color{blue}{-1 \cdot \log im}}{\log 0.1} \]
    6. associate-/l*28.8%

      \[\leadsto \color{blue}{\frac{-1}{\frac{\log 0.1}{\log im}}} \]
  10. Applied egg-rr28.8%

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

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

Alternative 6: 27.6% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \frac{1}{\frac{\log 10}{\log im}} \end{array} \]
(FPCore (re im) :precision binary64 (/ 1.0 (/ (log 10.0) (log im))))
double code(double re, double im) {
	return 1.0 / (log(10.0) / log(im));
}
real(8) function code(re, im)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    code = 1.0d0 / (log(10.0d0) / log(im))
end function
public static double code(double re, double im) {
	return 1.0 / (Math.log(10.0) / Math.log(im));
}
def code(re, im):
	return 1.0 / (math.log(10.0) / math.log(im))
function code(re, im)
	return Float64(1.0 / Float64(log(10.0) / log(im)))
end
function tmp = code(re, im)
	tmp = 1.0 / (log(10.0) / log(im));
end
code[re_, im_] := N[(1.0 / N[(N[Log[10.0], $MachinePrecision] / N[Log[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{\frac{\log 10}{\log im}}
\end{array}
Derivation
  1. Initial program 53.9%

    \[\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.8%

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

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

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

    \[\leadsto \color{blue}{{\left(\frac{\log 10}{\log im}\right)}^{-1}} \]
  7. Step-by-step derivation
    1. unpow-128.8%

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

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

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

Alternative 7: 27.6% 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(Float64(-log(im)) / 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.9%

    \[\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. add-log-exp99.0%

      \[\leadsto \color{blue}{\log \left(e^{\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log 10}}\right)} \]
    2. div-inv98.5%

      \[\leadsto \log \left(e^{\color{blue}{\log \left(\mathsf{hypot}\left(re, im\right)\right) \cdot \frac{1}{\log 10}}}\right) \]
    3. exp-to-pow98.5%

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

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

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

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

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

    \[\leadsto \color{blue}{\log \left({\left(\mathsf{hypot}\left(re, im\right)\right)}^{\left(\frac{-1}{\log 0.1}\right)}\right)} \]
  6. Taylor expanded in re around 0 28.8%

    \[\leadsto \color{blue}{-1 \cdot \frac{\log im}{\log 0.1}} \]
  7. Step-by-step derivation
    1. neg-mul-128.8%

      \[\leadsto \color{blue}{-\frac{\log im}{\log 0.1}} \]
    2. distribute-neg-frac28.8%

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

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

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

Alternative 8: 27.6% 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.9%

    \[\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.8%

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

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

Reproduce

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