math.log/2 on complex, real part

Percentage Accurate: 51.8% → 99.4%
Time: 10.7s
Alternatives: 6
Speedup: 2.0×

Specification

?
\[\begin{array}{l} \\ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \end{array} \]
(FPCore (re im base)
 :precision binary64
 (/
  (+ (* (log (sqrt (+ (* re re) (* im im)))) (log base)) (* (atan2 im re) 0.0))
  (+ (* (log base) (log base)) (* 0.0 0.0))))
double code(double re, double im, double base) {
	return ((log(sqrt(((re * re) + (im * im)))) * log(base)) + (atan2(im, re) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.0));
}
real(8) function code(re, im, base)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8), intent (in) :: base
    code = ((log(sqrt(((re * re) + (im * im)))) * log(base)) + (atan2(im, re) * 0.0d0)) / ((log(base) * log(base)) + (0.0d0 * 0.0d0))
end function
public static double code(double re, double im, double base) {
	return ((Math.log(Math.sqrt(((re * re) + (im * im)))) * Math.log(base)) + (Math.atan2(im, re) * 0.0)) / ((Math.log(base) * Math.log(base)) + (0.0 * 0.0));
}
def code(re, im, base):
	return ((math.log(math.sqrt(((re * re) + (im * im)))) * math.log(base)) + (math.atan2(im, re) * 0.0)) / ((math.log(base) * math.log(base)) + (0.0 * 0.0))
function code(re, im, base)
	return Float64(Float64(Float64(log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) * log(base)) + Float64(atan(im, re) * 0.0)) / Float64(Float64(log(base) * log(base)) + Float64(0.0 * 0.0)))
end
function tmp = code(re, im, base)
	tmp = ((log(sqrt(((re * re) + (im * im)))) * log(base)) + (atan2(im, re) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.0));
end
code[re_, im_, base_] := N[(N[(N[(N[Log[N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] + N[(N[ArcTan[im / re], $MachinePrecision] * 0.0), $MachinePrecision]), $MachinePrecision] / N[(N[(N[Log[base], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] + N[(0.0 * 0.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0}
\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.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \end{array} \]
(FPCore (re im base)
 :precision binary64
 (/
  (+ (* (log (sqrt (+ (* re re) (* im im)))) (log base)) (* (atan2 im re) 0.0))
  (+ (* (log base) (log base)) (* 0.0 0.0))))
double code(double re, double im, double base) {
	return ((log(sqrt(((re * re) + (im * im)))) * log(base)) + (atan2(im, re) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.0));
}
real(8) function code(re, im, base)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8), intent (in) :: base
    code = ((log(sqrt(((re * re) + (im * im)))) * log(base)) + (atan2(im, re) * 0.0d0)) / ((log(base) * log(base)) + (0.0d0 * 0.0d0))
end function
public static double code(double re, double im, double base) {
	return ((Math.log(Math.sqrt(((re * re) + (im * im)))) * Math.log(base)) + (Math.atan2(im, re) * 0.0)) / ((Math.log(base) * Math.log(base)) + (0.0 * 0.0));
}
def code(re, im, base):
	return ((math.log(math.sqrt(((re * re) + (im * im)))) * math.log(base)) + (math.atan2(im, re) * 0.0)) / ((math.log(base) * math.log(base)) + (0.0 * 0.0))
function code(re, im, base)
	return Float64(Float64(Float64(log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) * log(base)) + Float64(atan(im, re) * 0.0)) / Float64(Float64(log(base) * log(base)) + Float64(0.0 * 0.0)))
end
function tmp = code(re, im, base)
	tmp = ((log(sqrt(((re * re) + (im * im)))) * log(base)) + (atan2(im, re) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.0));
end
code[re_, im_, base_] := N[(N[(N[(N[Log[N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] + N[(N[ArcTan[im / re], $MachinePrecision] * 0.0), $MachinePrecision]), $MachinePrecision] / N[(N[(N[Log[base], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] + N[(0.0 * 0.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0}
\end{array}

Alternative 1: 99.4% accurate, 2.0× speedup?

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

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

    \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
  2. Step-by-step derivation
    1. mul0-rgt51.6%

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0} \]
    2. +-rgt-identity51.6%

      \[\leadsto \frac{\color{blue}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}{\log base \cdot \log base + 0 \cdot 0} \]
    3. metadata-eval51.6%

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + \color{blue}{0}} \]
    4. +-rgt-identity51.6%

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{\log base \cdot \log base}} \]
    5. times-frac51.7%

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \frac{\log base}{\log base}} \]
    6. *-inverses51.7%

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \color{blue}{1} \]
    7. *-rgt-identity51.7%

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

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

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

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

Alternative 2: 43.2% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{-\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{if}\;im \leq 1.02 \cdot 10^{-203}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 7.2 \cdot 10^{-165}:\\ \;\;\;\;\frac{1}{\frac{\log base}{\log im}}\\ \mathbf{elif}\;im \leq 2.55 \cdot 10^{-101}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 1.05 \cdot 10^{-61}:\\ \;\;\;\;\log im \cdot \frac{1}{\log base}\\ \mathbf{elif}\;im \leq 2.7 \cdot 10^{-50}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array} \end{array} \]
(FPCore (re im base)
 :precision binary64
 (let* ((t_0 (/ (- (log (/ -1.0 re))) (log base))))
   (if (<= im 1.02e-203)
     t_0
     (if (<= im 7.2e-165)
       (/ 1.0 (/ (log base) (log im)))
       (if (<= im 2.55e-101)
         t_0
         (if (<= im 1.05e-61)
           (* (log im) (/ 1.0 (log base)))
           (if (<= im 2.7e-50) t_0 (/ (log im) (log base)))))))))
double code(double re, double im, double base) {
	double t_0 = -log((-1.0 / re)) / log(base);
	double tmp;
	if (im <= 1.02e-203) {
		tmp = t_0;
	} else if (im <= 7.2e-165) {
		tmp = 1.0 / (log(base) / log(im));
	} else if (im <= 2.55e-101) {
		tmp = t_0;
	} else if (im <= 1.05e-61) {
		tmp = log(im) * (1.0 / log(base));
	} else if (im <= 2.7e-50) {
		tmp = t_0;
	} else {
		tmp = log(im) / log(base);
	}
	return tmp;
}
real(8) function code(re, im, base)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8), intent (in) :: base
    real(8) :: t_0
    real(8) :: tmp
    t_0 = -log(((-1.0d0) / re)) / log(base)
    if (im <= 1.02d-203) then
        tmp = t_0
    else if (im <= 7.2d-165) then
        tmp = 1.0d0 / (log(base) / log(im))
    else if (im <= 2.55d-101) then
        tmp = t_0
    else if (im <= 1.05d-61) then
        tmp = log(im) * (1.0d0 / log(base))
    else if (im <= 2.7d-50) then
        tmp = t_0
    else
        tmp = log(im) / log(base)
    end if
    code = tmp
end function
public static double code(double re, double im, double base) {
	double t_0 = -Math.log((-1.0 / re)) / Math.log(base);
	double tmp;
	if (im <= 1.02e-203) {
		tmp = t_0;
	} else if (im <= 7.2e-165) {
		tmp = 1.0 / (Math.log(base) / Math.log(im));
	} else if (im <= 2.55e-101) {
		tmp = t_0;
	} else if (im <= 1.05e-61) {
		tmp = Math.log(im) * (1.0 / Math.log(base));
	} else if (im <= 2.7e-50) {
		tmp = t_0;
	} else {
		tmp = Math.log(im) / Math.log(base);
	}
	return tmp;
}
def code(re, im, base):
	t_0 = -math.log((-1.0 / re)) / math.log(base)
	tmp = 0
	if im <= 1.02e-203:
		tmp = t_0
	elif im <= 7.2e-165:
		tmp = 1.0 / (math.log(base) / math.log(im))
	elif im <= 2.55e-101:
		tmp = t_0
	elif im <= 1.05e-61:
		tmp = math.log(im) * (1.0 / math.log(base))
	elif im <= 2.7e-50:
		tmp = t_0
	else:
		tmp = math.log(im) / math.log(base)
	return tmp
function code(re, im, base)
	t_0 = Float64(Float64(-log(Float64(-1.0 / re))) / log(base))
	tmp = 0.0
	if (im <= 1.02e-203)
		tmp = t_0;
	elseif (im <= 7.2e-165)
		tmp = Float64(1.0 / Float64(log(base) / log(im)));
	elseif (im <= 2.55e-101)
		tmp = t_0;
	elseif (im <= 1.05e-61)
		tmp = Float64(log(im) * Float64(1.0 / log(base)));
	elseif (im <= 2.7e-50)
		tmp = t_0;
	else
		tmp = Float64(log(im) / log(base));
	end
	return tmp
end
function tmp_2 = code(re, im, base)
	t_0 = -log((-1.0 / re)) / log(base);
	tmp = 0.0;
	if (im <= 1.02e-203)
		tmp = t_0;
	elseif (im <= 7.2e-165)
		tmp = 1.0 / (log(base) / log(im));
	elseif (im <= 2.55e-101)
		tmp = t_0;
	elseif (im <= 1.05e-61)
		tmp = log(im) * (1.0 / log(base));
	elseif (im <= 2.7e-50)
		tmp = t_0;
	else
		tmp = log(im) / log(base);
	end
	tmp_2 = tmp;
end
code[re_, im_, base_] := Block[{t$95$0 = N[((-N[Log[N[(-1.0 / re), $MachinePrecision]], $MachinePrecision]) / N[Log[base], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, 1.02e-203], t$95$0, If[LessEqual[im, 7.2e-165], N[(1.0 / N[(N[Log[base], $MachinePrecision] / N[Log[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 2.55e-101], t$95$0, If[LessEqual[im, 1.05e-61], N[(N[Log[im], $MachinePrecision] * N[(1.0 / N[Log[base], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 2.7e-50], t$95$0, N[(N[Log[im], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{-\log \left(\frac{-1}{re}\right)}{\log base}\\
\mathbf{if}\;im \leq 1.02 \cdot 10^{-203}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;im \leq 7.2 \cdot 10^{-165}:\\
\;\;\;\;\frac{1}{\frac{\log base}{\log im}}\\

\mathbf{elif}\;im \leq 2.55 \cdot 10^{-101}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;im \leq 1.05 \cdot 10^{-61}:\\
\;\;\;\;\log im \cdot \frac{1}{\log base}\\

\mathbf{elif}\;im \leq 2.7 \cdot 10^{-50}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\frac{\log im}{\log base}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if im < 1.02000000000000005e-203 or 7.19999999999999969e-165 < im < 2.5500000000000001e-101 or 1.05e-61 < im < 2.7e-50

    1. Initial program 51.2%

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    2. Step-by-step derivation
      1. mul0-rgt51.2%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0} \]
      2. +-rgt-identity51.2%

        \[\leadsto \frac{\color{blue}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}{\log base \cdot \log base + 0 \cdot 0} \]
      3. metadata-eval51.2%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + \color{blue}{0}} \]
      4. +-rgt-identity51.2%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{\log base \cdot \log base}} \]
      5. times-frac51.3%

        \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \frac{\log base}{\log base}} \]
      6. *-inverses51.3%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \color{blue}{1} \]
      7. *-rgt-identity51.3%

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

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

      \[\leadsto \color{blue}{\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log base}} \]
    4. Taylor expanded in re around -inf 39.4%

      \[\leadsto \color{blue}{-1 \cdot \frac{\log \left(\frac{-1}{re}\right)}{\log base}} \]
    5. Step-by-step derivation
      1. associate-*r/39.4%

        \[\leadsto \color{blue}{\frac{-1 \cdot \log \left(\frac{-1}{re}\right)}{\log base}} \]
      2. mul-1-neg39.4%

        \[\leadsto \frac{\color{blue}{-\log \left(\frac{-1}{re}\right)}}{\log base} \]
    6. Simplified39.4%

      \[\leadsto \color{blue}{\frac{-\log \left(\frac{-1}{re}\right)}{\log base}} \]

    if 1.02000000000000005e-203 < im < 7.19999999999999969e-165

    1. Initial program 56.6%

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    2. Step-by-step derivation
      1. mul0-rgt56.6%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0} \]
      2. +-rgt-identity56.6%

        \[\leadsto \frac{\color{blue}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}{\log base \cdot \log base + 0 \cdot 0} \]
      3. metadata-eval56.6%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + \color{blue}{0}} \]
      4. +-rgt-identity56.6%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{\log base \cdot \log base}} \]
      5. times-frac56.6%

        \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \frac{\log base}{\log base}} \]
      6. *-inverses56.6%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \color{blue}{1} \]
      7. *-rgt-identity56.6%

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

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

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

      \[\leadsto \color{blue}{\frac{\log im}{\log base}} \]
    5. Step-by-step derivation
      1. clear-num25.4%

        \[\leadsto \color{blue}{\frac{1}{\frac{\log base}{\log im}}} \]
      2. inv-pow25.4%

        \[\leadsto \color{blue}{{\left(\frac{\log base}{\log im}\right)}^{-1}} \]
    6. Applied egg-rr25.4%

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

        \[\leadsto \color{blue}{\frac{1}{\frac{\log base}{\log im}}} \]
    8. Simplified25.4%

      \[\leadsto \color{blue}{\frac{1}{\frac{\log base}{\log im}}} \]

    if 2.5500000000000001e-101 < im < 1.05e-61

    1. Initial program 83.3%

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    2. Step-by-step derivation
      1. mul0-rgt83.3%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0} \]
      2. +-rgt-identity83.3%

        \[\leadsto \frac{\color{blue}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}{\log base \cdot \log base + 0 \cdot 0} \]
      3. metadata-eval83.3%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + \color{blue}{0}} \]
      4. +-rgt-identity83.3%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{\log base \cdot \log base}} \]
      5. times-frac83.5%

        \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \frac{\log base}{\log base}} \]
      6. *-inverses83.5%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \color{blue}{1} \]
      7. *-rgt-identity83.5%

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

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

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

      \[\leadsto \color{blue}{\frac{\log im}{\log base}} \]
    5. Step-by-step derivation
      1. clear-num48.7%

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

        \[\leadsto \color{blue}{\frac{1}{\log base} \cdot \log im} \]
    6. Applied egg-rr48.8%

      \[\leadsto \color{blue}{\frac{1}{\log base} \cdot \log im} \]

    if 2.7e-50 < im

    1. Initial program 46.7%

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    2. Step-by-step derivation
      1. mul0-rgt46.7%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0} \]
      2. +-rgt-identity46.7%

        \[\leadsto \frac{\color{blue}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}{\log base \cdot \log base + 0 \cdot 0} \]
      3. metadata-eval46.7%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + \color{blue}{0}} \]
      4. +-rgt-identity46.7%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{\log base \cdot \log base}} \]
      5. times-frac46.6%

        \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \frac{\log base}{\log base}} \]
      6. *-inverses46.6%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \color{blue}{1} \]
      7. *-rgt-identity46.6%

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

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

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

      \[\leadsto \color{blue}{\frac{\log im}{\log base}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification50.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 1.02 \cdot 10^{-203}:\\ \;\;\;\;\frac{-\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;im \leq 7.2 \cdot 10^{-165}:\\ \;\;\;\;\frac{1}{\frac{\log base}{\log im}}\\ \mathbf{elif}\;im \leq 2.55 \cdot 10^{-101}:\\ \;\;\;\;\frac{-\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;im \leq 1.05 \cdot 10^{-61}:\\ \;\;\;\;\log im \cdot \frac{1}{\log base}\\ \mathbf{elif}\;im \leq 2.7 \cdot 10^{-50}:\\ \;\;\;\;\frac{-\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array} \]

Alternative 3: 43.3% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \log \left(\frac{-1}{re}\right)\\ t_1 := \frac{-t_0}{\log base}\\ \mathbf{if}\;im \leq 1.02 \cdot 10^{-203}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 1.7 \cdot 10^{-168}:\\ \;\;\;\;\frac{1}{\frac{\log base}{\log im}}\\ \mathbf{elif}\;im \leq 2.15 \cdot 10^{-102}:\\ \;\;\;\;t_0 \cdot \frac{-1}{\log base}\\ \mathbf{elif}\;im \leq 2.35 \cdot 10^{-61}:\\ \;\;\;\;\log im \cdot \frac{1}{\log base}\\ \mathbf{elif}\;im \leq 3.2 \cdot 10^{-50}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array} \end{array} \]
(FPCore (re im base)
 :precision binary64
 (let* ((t_0 (log (/ -1.0 re))) (t_1 (/ (- t_0) (log base))))
   (if (<= im 1.02e-203)
     t_1
     (if (<= im 1.7e-168)
       (/ 1.0 (/ (log base) (log im)))
       (if (<= im 2.15e-102)
         (* t_0 (/ -1.0 (log base)))
         (if (<= im 2.35e-61)
           (* (log im) (/ 1.0 (log base)))
           (if (<= im 3.2e-50) t_1 (/ (log im) (log base)))))))))
double code(double re, double im, double base) {
	double t_0 = log((-1.0 / re));
	double t_1 = -t_0 / log(base);
	double tmp;
	if (im <= 1.02e-203) {
		tmp = t_1;
	} else if (im <= 1.7e-168) {
		tmp = 1.0 / (log(base) / log(im));
	} else if (im <= 2.15e-102) {
		tmp = t_0 * (-1.0 / log(base));
	} else if (im <= 2.35e-61) {
		tmp = log(im) * (1.0 / log(base));
	} else if (im <= 3.2e-50) {
		tmp = t_1;
	} else {
		tmp = log(im) / log(base);
	}
	return tmp;
}
real(8) function code(re, im, base)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8), intent (in) :: base
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = log(((-1.0d0) / re))
    t_1 = -t_0 / log(base)
    if (im <= 1.02d-203) then
        tmp = t_1
    else if (im <= 1.7d-168) then
        tmp = 1.0d0 / (log(base) / log(im))
    else if (im <= 2.15d-102) then
        tmp = t_0 * ((-1.0d0) / log(base))
    else if (im <= 2.35d-61) then
        tmp = log(im) * (1.0d0 / log(base))
    else if (im <= 3.2d-50) then
        tmp = t_1
    else
        tmp = log(im) / log(base)
    end if
    code = tmp
end function
public static double code(double re, double im, double base) {
	double t_0 = Math.log((-1.0 / re));
	double t_1 = -t_0 / Math.log(base);
	double tmp;
	if (im <= 1.02e-203) {
		tmp = t_1;
	} else if (im <= 1.7e-168) {
		tmp = 1.0 / (Math.log(base) / Math.log(im));
	} else if (im <= 2.15e-102) {
		tmp = t_0 * (-1.0 / Math.log(base));
	} else if (im <= 2.35e-61) {
		tmp = Math.log(im) * (1.0 / Math.log(base));
	} else if (im <= 3.2e-50) {
		tmp = t_1;
	} else {
		tmp = Math.log(im) / Math.log(base);
	}
	return tmp;
}
def code(re, im, base):
	t_0 = math.log((-1.0 / re))
	t_1 = -t_0 / math.log(base)
	tmp = 0
	if im <= 1.02e-203:
		tmp = t_1
	elif im <= 1.7e-168:
		tmp = 1.0 / (math.log(base) / math.log(im))
	elif im <= 2.15e-102:
		tmp = t_0 * (-1.0 / math.log(base))
	elif im <= 2.35e-61:
		tmp = math.log(im) * (1.0 / math.log(base))
	elif im <= 3.2e-50:
		tmp = t_1
	else:
		tmp = math.log(im) / math.log(base)
	return tmp
function code(re, im, base)
	t_0 = log(Float64(-1.0 / re))
	t_1 = Float64(Float64(-t_0) / log(base))
	tmp = 0.0
	if (im <= 1.02e-203)
		tmp = t_1;
	elseif (im <= 1.7e-168)
		tmp = Float64(1.0 / Float64(log(base) / log(im)));
	elseif (im <= 2.15e-102)
		tmp = Float64(t_0 * Float64(-1.0 / log(base)));
	elseif (im <= 2.35e-61)
		tmp = Float64(log(im) * Float64(1.0 / log(base)));
	elseif (im <= 3.2e-50)
		tmp = t_1;
	else
		tmp = Float64(log(im) / log(base));
	end
	return tmp
end
function tmp_2 = code(re, im, base)
	t_0 = log((-1.0 / re));
	t_1 = -t_0 / log(base);
	tmp = 0.0;
	if (im <= 1.02e-203)
		tmp = t_1;
	elseif (im <= 1.7e-168)
		tmp = 1.0 / (log(base) / log(im));
	elseif (im <= 2.15e-102)
		tmp = t_0 * (-1.0 / log(base));
	elseif (im <= 2.35e-61)
		tmp = log(im) * (1.0 / log(base));
	elseif (im <= 3.2e-50)
		tmp = t_1;
	else
		tmp = log(im) / log(base);
	end
	tmp_2 = tmp;
end
code[re_, im_, base_] := Block[{t$95$0 = N[Log[N[(-1.0 / re), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[((-t$95$0) / N[Log[base], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, 1.02e-203], t$95$1, If[LessEqual[im, 1.7e-168], N[(1.0 / N[(N[Log[base], $MachinePrecision] / N[Log[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 2.15e-102], N[(t$95$0 * N[(-1.0 / N[Log[base], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 2.35e-61], N[(N[Log[im], $MachinePrecision] * N[(1.0 / N[Log[base], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 3.2e-50], t$95$1, N[(N[Log[im], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \log \left(\frac{-1}{re}\right)\\
t_1 := \frac{-t_0}{\log base}\\
\mathbf{if}\;im \leq 1.02 \cdot 10^{-203}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;im \leq 1.7 \cdot 10^{-168}:\\
\;\;\;\;\frac{1}{\frac{\log base}{\log im}}\\

\mathbf{elif}\;im \leq 2.15 \cdot 10^{-102}:\\
\;\;\;\;t_0 \cdot \frac{-1}{\log base}\\

\mathbf{elif}\;im \leq 2.35 \cdot 10^{-61}:\\
\;\;\;\;\log im \cdot \frac{1}{\log base}\\

\mathbf{elif}\;im \leq 3.2 \cdot 10^{-50}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;\frac{\log im}{\log base}\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if im < 1.02000000000000005e-203 or 2.3499999999999998e-61 < im < 3.2e-50

    1. Initial program 51.5%

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    2. Step-by-step derivation
      1. mul0-rgt51.5%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0} \]
      2. +-rgt-identity51.5%

        \[\leadsto \frac{\color{blue}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}{\log base \cdot \log base + 0 \cdot 0} \]
      3. metadata-eval51.5%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + \color{blue}{0}} \]
      4. +-rgt-identity51.5%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{\log base \cdot \log base}} \]
      5. times-frac51.6%

        \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \frac{\log base}{\log base}} \]
      6. *-inverses51.6%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \color{blue}{1} \]
      7. *-rgt-identity51.6%

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

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

      \[\leadsto \color{blue}{\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log base}} \]
    4. Taylor expanded in re around -inf 39.5%

      \[\leadsto \color{blue}{-1 \cdot \frac{\log \left(\frac{-1}{re}\right)}{\log base}} \]
    5. Step-by-step derivation
      1. associate-*r/39.5%

        \[\leadsto \color{blue}{\frac{-1 \cdot \log \left(\frac{-1}{re}\right)}{\log base}} \]
      2. mul-1-neg39.5%

        \[\leadsto \frac{\color{blue}{-\log \left(\frac{-1}{re}\right)}}{\log base} \]
    6. Simplified39.5%

      \[\leadsto \color{blue}{\frac{-\log \left(\frac{-1}{re}\right)}{\log base}} \]

    if 1.02000000000000005e-203 < im < 1.70000000000000011e-168

    1. Initial program 56.6%

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    2. Step-by-step derivation
      1. mul0-rgt56.6%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0} \]
      2. +-rgt-identity56.6%

        \[\leadsto \frac{\color{blue}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}{\log base \cdot \log base + 0 \cdot 0} \]
      3. metadata-eval56.6%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + \color{blue}{0}} \]
      4. +-rgt-identity56.6%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{\log base \cdot \log base}} \]
      5. times-frac56.6%

        \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \frac{\log base}{\log base}} \]
      6. *-inverses56.6%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \color{blue}{1} \]
      7. *-rgt-identity56.6%

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

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

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

      \[\leadsto \color{blue}{\frac{\log im}{\log base}} \]
    5. Step-by-step derivation
      1. clear-num25.4%

        \[\leadsto \color{blue}{\frac{1}{\frac{\log base}{\log im}}} \]
      2. inv-pow25.4%

        \[\leadsto \color{blue}{{\left(\frac{\log base}{\log im}\right)}^{-1}} \]
    6. Applied egg-rr25.4%

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

        \[\leadsto \color{blue}{\frac{1}{\frac{\log base}{\log im}}} \]
    8. Simplified25.4%

      \[\leadsto \color{blue}{\frac{1}{\frac{\log base}{\log im}}} \]

    if 1.70000000000000011e-168 < im < 2.1499999999999999e-102

    1. Initial program 46.0%

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    2. Step-by-step derivation
      1. mul0-rgt46.0%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0} \]
      2. +-rgt-identity46.0%

        \[\leadsto \frac{\color{blue}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}{\log base \cdot \log base + 0 \cdot 0} \]
      3. metadata-eval46.0%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + \color{blue}{0}} \]
      4. +-rgt-identity46.0%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{\log base \cdot \log base}} \]
      5. times-frac46.0%

        \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \frac{\log base}{\log base}} \]
      6. *-inverses46.0%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \color{blue}{1} \]
      7. *-rgt-identity46.0%

        \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}} \]
      8. hypot-def99.7%

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

      \[\leadsto \color{blue}{\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\log base}} \]
    4. Step-by-step derivation
      1. clear-num99.3%

        \[\leadsto \color{blue}{\frac{1}{\frac{\log base}{\log \left(\mathsf{hypot}\left(re, im\right)\right)}}} \]
      2. associate-/r/99.7%

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

      \[\leadsto \color{blue}{\frac{1}{\log base} \cdot \log \left(\mathsf{hypot}\left(re, im\right)\right)} \]
    6. Step-by-step derivation
      1. add-exp-log54.6%

        \[\leadsto \color{blue}{e^{\log \left(\frac{1}{\log base}\right)}} \cdot \log \left(\mathsf{hypot}\left(re, im\right)\right) \]
      2. log-rec54.6%

        \[\leadsto e^{\color{blue}{-\log \log base}} \cdot \log \left(\mathsf{hypot}\left(re, im\right)\right) \]
    7. Applied egg-rr54.6%

      \[\leadsto \color{blue}{e^{-\log \log base}} \cdot \log \left(\mathsf{hypot}\left(re, im\right)\right) \]
    8. Taylor expanded in re around -inf 15.8%

      \[\leadsto \color{blue}{-1 \cdot \left(e^{-\log \log base} \cdot \log \left(\frac{-1}{re}\right)\right)} \]
    9. Step-by-step derivation
      1. mul-1-neg15.8%

        \[\leadsto \color{blue}{-e^{-\log \log base} \cdot \log \left(\frac{-1}{re}\right)} \]
      2. *-commutative15.8%

        \[\leadsto -\color{blue}{\log \left(\frac{-1}{re}\right) \cdot e^{-\log \log base}} \]
      3. distribute-rgt-neg-in15.8%

        \[\leadsto \color{blue}{\log \left(\frac{-1}{re}\right) \cdot \left(-e^{-\log \log base}\right)} \]
      4. exp-neg15.8%

        \[\leadsto \log \left(\frac{-1}{re}\right) \cdot \left(-\color{blue}{\frac{1}{e^{\log \log base}}}\right) \]
      5. rem-exp-log38.0%

        \[\leadsto \log \left(\frac{-1}{re}\right) \cdot \left(-\frac{1}{\color{blue}{\log base}}\right) \]
    10. Simplified38.0%

      \[\leadsto \color{blue}{\log \left(\frac{-1}{re}\right) \cdot \left(-\frac{1}{\log base}\right)} \]

    if 2.1499999999999999e-102 < im < 2.3499999999999998e-61

    1. Initial program 83.3%

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    2. Step-by-step derivation
      1. mul0-rgt83.3%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0} \]
      2. +-rgt-identity83.3%

        \[\leadsto \frac{\color{blue}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}{\log base \cdot \log base + 0 \cdot 0} \]
      3. metadata-eval83.3%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + \color{blue}{0}} \]
      4. +-rgt-identity83.3%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{\log base \cdot \log base}} \]
      5. times-frac83.5%

        \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \frac{\log base}{\log base}} \]
      6. *-inverses83.5%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \color{blue}{1} \]
      7. *-rgt-identity83.5%

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

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

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

      \[\leadsto \color{blue}{\frac{\log im}{\log base}} \]
    5. Step-by-step derivation
      1. clear-num48.7%

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

        \[\leadsto \color{blue}{\frac{1}{\log base} \cdot \log im} \]
    6. Applied egg-rr48.8%

      \[\leadsto \color{blue}{\frac{1}{\log base} \cdot \log im} \]

    if 3.2e-50 < im

    1. Initial program 46.7%

      \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    2. Step-by-step derivation
      1. mul0-rgt46.7%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0} \]
      2. +-rgt-identity46.7%

        \[\leadsto \frac{\color{blue}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}{\log base \cdot \log base + 0 \cdot 0} \]
      3. metadata-eval46.7%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + \color{blue}{0}} \]
      4. +-rgt-identity46.7%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{\log base \cdot \log base}} \]
      5. times-frac46.6%

        \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \frac{\log base}{\log base}} \]
      6. *-inverses46.6%

        \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \color{blue}{1} \]
      7. *-rgt-identity46.6%

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

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

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

      \[\leadsto \color{blue}{\frac{\log im}{\log base}} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification50.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 1.02 \cdot 10^{-203}:\\ \;\;\;\;\frac{-\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;im \leq 1.7 \cdot 10^{-168}:\\ \;\;\;\;\frac{1}{\frac{\log base}{\log im}}\\ \mathbf{elif}\;im \leq 2.15 \cdot 10^{-102}:\\ \;\;\;\;\log \left(\frac{-1}{re}\right) \cdot \frac{-1}{\log base}\\ \mathbf{elif}\;im \leq 2.35 \cdot 10^{-61}:\\ \;\;\;\;\log im \cdot \frac{1}{\log base}\\ \mathbf{elif}\;im \leq 3.2 \cdot 10^{-50}:\\ \;\;\;\;\frac{-\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array} \]

Alternative 4: 4.8% accurate, 3.1× speedup?

\[\begin{array}{l} \\ \log base \cdot \log im \end{array} \]
(FPCore (re im base) :precision binary64 (* (log base) (log im)))
double code(double re, double im, double base) {
	return log(base) * log(im);
}
real(8) function code(re, im, base)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8), intent (in) :: base
    code = log(base) * log(im)
end function
public static double code(double re, double im, double base) {
	return Math.log(base) * Math.log(im);
}
def code(re, im, base):
	return math.log(base) * math.log(im)
function code(re, im, base)
	return Float64(log(base) * log(im))
end
function tmp = code(re, im, base)
	tmp = log(base) * log(im);
end
code[re_, im_, base_] := N[(N[Log[base], $MachinePrecision] * N[Log[im], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\log base \cdot \log im
\end{array}
Derivation
  1. Initial program 51.6%

    \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
  2. Step-by-step derivation
    1. mul0-rgt51.6%

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0} \]
    2. +-rgt-identity51.6%

      \[\leadsto \frac{\color{blue}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}{\log base \cdot \log base + 0 \cdot 0} \]
    3. metadata-eval51.6%

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + \color{blue}{0}} \]
    4. +-rgt-identity51.6%

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{\log base \cdot \log base}} \]
    5. times-frac51.7%

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \frac{\log base}{\log base}} \]
    6. *-inverses51.7%

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \color{blue}{1} \]
    7. *-rgt-identity51.7%

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

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

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

    \[\leadsto \color{blue}{\frac{\log im}{\log base}} \]
  5. Step-by-step derivation
    1. log1p-expm1-u27.6%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\log im}{\log base}\right)\right)} \]
  6. Applied egg-rr27.6%

    \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\log im}{\log base}\right)\right)} \]
  7. Step-by-step derivation
    1. log1p-expm1-u27.9%

      \[\leadsto \color{blue}{\frac{\log im}{\log base}} \]
    2. div-inv27.9%

      \[\leadsto \color{blue}{\log im \cdot \frac{1}{\log base}} \]
    3. add-exp-log14.4%

      \[\leadsto \log im \cdot \color{blue}{e^{\log \left(\frac{1}{\log base}\right)}} \]
    4. neg-log14.4%

      \[\leadsto \log im \cdot e^{\color{blue}{-\log \log base}} \]
    5. add-sqr-sqrt0.0%

      \[\leadsto \log im \cdot e^{\color{blue}{\sqrt{-\log \log base} \cdot \sqrt{-\log \log base}}} \]
    6. sqrt-unprod2.6%

      \[\leadsto \log im \cdot e^{\color{blue}{\sqrt{\left(-\log \log base\right) \cdot \left(-\log \log base\right)}}} \]
    7. sqr-neg2.6%

      \[\leadsto \log im \cdot e^{\sqrt{\color{blue}{\log \log base \cdot \log \log base}}} \]
    8. sqrt-unprod2.6%

      \[\leadsto \log im \cdot e^{\color{blue}{\sqrt{\log \log base} \cdot \sqrt{\log \log base}}} \]
    9. add-sqr-sqrt2.6%

      \[\leadsto \log im \cdot e^{\color{blue}{\log \log base}} \]
    10. add-exp-log5.0%

      \[\leadsto \log im \cdot \color{blue}{\log base} \]
  8. Applied egg-rr5.0%

    \[\leadsto \color{blue}{\log im \cdot \log base} \]
  9. Final simplification5.0%

    \[\leadsto \log base \cdot \log im \]

Alternative 5: 26.2% accurate, 3.1× speedup?

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

\\
\frac{\log im}{\log base}
\end{array}
Derivation
  1. Initial program 51.6%

    \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
  2. Step-by-step derivation
    1. mul0-rgt51.6%

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0} \]
    2. +-rgt-identity51.6%

      \[\leadsto \frac{\color{blue}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}{\log base \cdot \log base + 0 \cdot 0} \]
    3. metadata-eval51.6%

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + \color{blue}{0}} \]
    4. +-rgt-identity51.6%

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{\log base \cdot \log base}} \]
    5. times-frac51.7%

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \frac{\log base}{\log base}} \]
    6. *-inverses51.7%

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \color{blue}{1} \]
    7. *-rgt-identity51.7%

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

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

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

    \[\leadsto \color{blue}{\frac{\log im}{\log base}} \]
  5. Final simplification27.9%

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

Alternative 6: 3.9% accurate, 6.2× speedup?

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

\\
\log im
\end{array}
Derivation
  1. Initial program 51.6%

    \[\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
  2. Step-by-step derivation
    1. mul0-rgt51.6%

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base + \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0} \]
    2. +-rgt-identity51.6%

      \[\leadsto \frac{\color{blue}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}{\log base \cdot \log base + 0 \cdot 0} \]
    3. metadata-eval51.6%

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base + \color{blue}{0}} \]
    4. +-rgt-identity51.6%

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{\log base \cdot \log base}} \]
    5. times-frac51.7%

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \frac{\log base}{\log base}} \]
    6. *-inverses51.7%

      \[\leadsto \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base} \cdot \color{blue}{1} \]
    7. *-rgt-identity51.7%

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

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

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

    \[\leadsto \color{blue}{\frac{\log im}{\log base}} \]
  5. Step-by-step derivation
    1. clear-num27.9%

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

      \[\leadsto \color{blue}{\frac{1}{\log base} \cdot \log im} \]
  6. Applied egg-rr27.9%

    \[\leadsto \color{blue}{\frac{1}{\log base} \cdot \log im} \]
  7. Step-by-step derivation
    1. inv-pow27.9%

      \[\leadsto \color{blue}{{\log base}^{-1}} \cdot \log im \]
    2. metadata-eval27.9%

      \[\leadsto {\log base}^{\color{blue}{\left(1 - 2\right)}} \cdot \log im \]
    3. pow-div27.9%

      \[\leadsto \color{blue}{\frac{{\log base}^{1}}{{\log base}^{2}}} \cdot \log im \]
    4. pow127.9%

      \[\leadsto \frac{\color{blue}{\log base}}{{\log base}^{2}} \cdot \log im \]
    5. *-commutative27.9%

      \[\leadsto \color{blue}{\log im \cdot \frac{\log base}{{\log base}^{2}}} \]
    6. associate-*r/28.0%

      \[\leadsto \color{blue}{\frac{\log im \cdot \log base}{{\log base}^{2}}} \]
    7. frac-2neg28.0%

      \[\leadsto \color{blue}{\frac{-\log im \cdot \log base}{-{\log base}^{2}}} \]
    8. *-commutative28.0%

      \[\leadsto \frac{-\color{blue}{\log base \cdot \log im}}{-{\log base}^{2}} \]
    9. add-sqr-sqrt28.0%

      \[\leadsto \frac{-\log base \cdot \log im}{-\color{blue}{\sqrt{{\log base}^{2}} \cdot \sqrt{{\log base}^{2}}}} \]
    10. sqrt-unprod28.0%

      \[\leadsto \frac{-\log base \cdot \log im}{-\color{blue}{\sqrt{{\log base}^{2} \cdot {\log base}^{2}}}} \]
    11. unpow228.0%

      \[\leadsto \frac{-\log base \cdot \log im}{-\sqrt{{\log base}^{2} \cdot \color{blue}{\left(\log base \cdot \log base\right)}}} \]
    12. associate-*r*27.9%

      \[\leadsto \frac{-\log base \cdot \log im}{-\sqrt{\color{blue}{\left({\log base}^{2} \cdot \log base\right) \cdot \log base}}} \]
  8. Applied egg-rr4.3%

    \[\leadsto \color{blue}{\frac{-\log base \cdot \log im}{-\log base}} \]
  9. Step-by-step derivation
    1. distribute-lft-neg-in4.3%

      \[\leadsto \frac{\color{blue}{\left(-\log base\right) \cdot \log im}}{-\log base} \]
    2. *-commutative4.3%

      \[\leadsto \frac{\color{blue}{\log im \cdot \left(-\log base\right)}}{-\log base} \]
    3. associate-/l*4.3%

      \[\leadsto \color{blue}{\frac{\log im}{\frac{-\log base}{-\log base}}} \]
    4. *-inverses4.3%

      \[\leadsto \frac{\log im}{\color{blue}{1}} \]
    5. /-rgt-identity4.3%

      \[\leadsto \color{blue}{\log im} \]
  10. Simplified4.3%

    \[\leadsto \color{blue}{\log im} \]
  11. Final simplification4.3%

    \[\leadsto \log im \]

Reproduce

?
herbie shell --seed 2023174 
(FPCore (re im base)
  :name "math.log/2 on complex, real part"
  :precision binary64
  (/ (+ (* (log (sqrt (+ (* re re) (* im im)))) (log base)) (* (atan2 im re) 0.0)) (+ (* (log base) (log base)) (* 0.0 0.0))))