math.log/2 on complex, imaginary part

Percentage Accurate: 49.7% → 99.5%
Time: 9.0s
Alternatives: 3
Speedup: 3.0×

Specification

?
\[\begin{array}{l} \\ \frac{\tan^{-1}_* \frac{im}{re} \cdot \log base - \log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \end{array} \]
(FPCore (re im base)
 :precision binary64
 (/
  (- (* (atan2 im re) (log base)) (* (log (sqrt (+ (* re re) (* im im)))) 0.0))
  (+ (* (log base) (log base)) (* 0.0 0.0))))
double code(double re, double im, double base) {
	return ((atan2(im, re) * log(base)) - (log(sqrt(((re * re) + (im * im)))) * 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 = ((atan2(im, re) * log(base)) - (log(sqrt(((re * re) + (im * im)))) * 0.0d0)) / ((log(base) * log(base)) + (0.0d0 * 0.0d0))
end function
public static double code(double re, double im, double base) {
	return ((Math.atan2(im, re) * Math.log(base)) - (Math.log(Math.sqrt(((re * re) + (im * im)))) * 0.0)) / ((Math.log(base) * Math.log(base)) + (0.0 * 0.0));
}
def code(re, im, base):
	return ((math.atan2(im, re) * math.log(base)) - (math.log(math.sqrt(((re * re) + (im * im)))) * 0.0)) / ((math.log(base) * math.log(base)) + (0.0 * 0.0))
function code(re, im, base)
	return Float64(Float64(Float64(atan(im, re) * log(base)) - Float64(log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) * 0.0)) / Float64(Float64(log(base) * log(base)) + Float64(0.0 * 0.0)))
end
function tmp = code(re, im, base)
	tmp = ((atan2(im, re) * log(base)) - (log(sqrt(((re * re) + (im * im)))) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.0));
end
code[re_, im_, base_] := N[(N[(N[(N[ArcTan[im / re], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] - N[(N[Log[N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $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{\tan^{-1}_* \frac{im}{re} \cdot \log base - \log \left(\sqrt{re \cdot re + im \cdot im}\right) \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 3 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: 49.7% accurate, 1.0× speedup?

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

Alternative 1: 99.5% accurate, 3.0× speedup?

\[\begin{array}{l} \\ \frac{\tan^{-1}_* \frac{im}{re}}{\log base} \end{array} \]
(FPCore (re im base) :precision binary64 (/ (atan2 im re) (log base)))
double code(double re, double im, double base) {
	return atan2(im, re) / 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 = atan2(im, re) / log(base)
end function
public static double code(double re, double im, double base) {
	return Math.atan2(im, re) / Math.log(base);
}
def code(re, im, base):
	return math.atan2(im, re) / math.log(base)
function code(re, im, base)
	return Float64(atan(im, re) / log(base))
end
function tmp = code(re, im, base)
	tmp = atan2(im, re) / log(base);
end
code[re_, im_, base_] := N[(N[ArcTan[im / re], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\tan^{-1}_* \frac{im}{re}}{\log base}
\end{array}
Derivation
  1. Initial program 54.3%

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

      \[\leadsto \frac{\tan^{-1}_* \frac{im}{re} \cdot \log base - \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0} \]
    2. --rgt-identity99.4%

      \[\leadsto \frac{\color{blue}{\tan^{-1}_* \frac{im}{re} \cdot \log base}}{\log base \cdot \log base + 0 \cdot 0} \]
    3. metadata-eval99.4%

      \[\leadsto \frac{\tan^{-1}_* \frac{im}{re} \cdot \log base}{\log base \cdot \log base + \color{blue}{0}} \]
    4. +-rgt-identity99.4%

      \[\leadsto \frac{\tan^{-1}_* \frac{im}{re} \cdot \log base}{\color{blue}{\log base \cdot \log base}} \]
    5. times-frac99.5%

      \[\leadsto \color{blue}{\frac{\tan^{-1}_* \frac{im}{re}}{\log base} \cdot \frac{\log base}{\log base}} \]
    6. *-inverses99.5%

      \[\leadsto \frac{\tan^{-1}_* \frac{im}{re}}{\log base} \cdot \color{blue}{1} \]
    7. *-rgt-identity99.5%

      \[\leadsto \color{blue}{\frac{\tan^{-1}_* \frac{im}{re}}{\log base}} \]
  3. Simplified99.5%

    \[\leadsto \color{blue}{\frac{\tan^{-1}_* \frac{im}{re}}{\log base}} \]
  4. Final simplification99.5%

    \[\leadsto \frac{\tan^{-1}_* \frac{im}{re}}{\log base} \]

Alternative 2: 19.5% accurate, 5.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -\tan^{-1}_* \frac{im}{re}\\ \mathbf{if}\;base \leq 1:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{-1}\\ \end{array} \end{array} \]
(FPCore (re im base)
 :precision binary64
 (let* ((t_0 (- (atan2 im re)))) (if (<= base 1.0) t_0 (/ t_0 -1.0))))
double code(double re, double im, double base) {
	double t_0 = -atan2(im, re);
	double tmp;
	if (base <= 1.0) {
		tmp = t_0;
	} else {
		tmp = t_0 / -1.0;
	}
	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 = -atan2(im, re)
    if (base <= 1.0d0) then
        tmp = t_0
    else
        tmp = t_0 / (-1.0d0)
    end if
    code = tmp
end function
public static double code(double re, double im, double base) {
	double t_0 = -Math.atan2(im, re);
	double tmp;
	if (base <= 1.0) {
		tmp = t_0;
	} else {
		tmp = t_0 / -1.0;
	}
	return tmp;
}
def code(re, im, base):
	t_0 = -math.atan2(im, re)
	tmp = 0
	if base <= 1.0:
		tmp = t_0
	else:
		tmp = t_0 / -1.0
	return tmp
function code(re, im, base)
	t_0 = Float64(-atan(im, re))
	tmp = 0.0
	if (base <= 1.0)
		tmp = t_0;
	else
		tmp = Float64(t_0 / -1.0);
	end
	return tmp
end
function tmp_2 = code(re, im, base)
	t_0 = -atan2(im, re);
	tmp = 0.0;
	if (base <= 1.0)
		tmp = t_0;
	else
		tmp = t_0 / -1.0;
	end
	tmp_2 = tmp;
end
code[re_, im_, base_] := Block[{t$95$0 = (-N[ArcTan[im / re], $MachinePrecision])}, If[LessEqual[base, 1.0], t$95$0, N[(t$95$0 / -1.0), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -\tan^{-1}_* \frac{im}{re}\\
\mathbf{if}\;base \leq 1:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\frac{t_0}{-1}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if base < 1

    1. Initial program 58.2%

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

        \[\leadsto \frac{\tan^{-1}_* \frac{im}{re} \cdot \log base - \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0} \]
      2. --rgt-identity99.3%

        \[\leadsto \frac{\color{blue}{\tan^{-1}_* \frac{im}{re} \cdot \log base}}{\log base \cdot \log base + 0 \cdot 0} \]
      3. metadata-eval99.3%

        \[\leadsto \frac{\tan^{-1}_* \frac{im}{re} \cdot \log base}{\log base \cdot \log base + \color{blue}{0}} \]
      4. +-rgt-identity99.3%

        \[\leadsto \frac{\tan^{-1}_* \frac{im}{re} \cdot \log base}{\color{blue}{\log base \cdot \log base}} \]
      5. times-frac99.5%

        \[\leadsto \color{blue}{\frac{\tan^{-1}_* \frac{im}{re}}{\log base} \cdot \frac{\log base}{\log base}} \]
      6. *-inverses99.5%

        \[\leadsto \frac{\tan^{-1}_* \frac{im}{re}}{\log base} \cdot \color{blue}{1} \]
      7. *-rgt-identity99.5%

        \[\leadsto \color{blue}{\frac{\tan^{-1}_* \frac{im}{re}}{\log base}} \]
    3. Simplified99.5%

      \[\leadsto \color{blue}{\frac{\tan^{-1}_* \frac{im}{re}}{\log base}} \]
    4. Taylor expanded in base around inf 99.5%

      \[\leadsto \color{blue}{-1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\log \left(\frac{1}{base}\right)}} \]
    5. Step-by-step derivation
      1. inv-pow99.5%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\log \color{blue}{\left({base}^{-1}\right)}} \]
      2. add-cube-cbrt99.4%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\log \left({\color{blue}{\left(\left(\sqrt[3]{base} \cdot \sqrt[3]{base}\right) \cdot \sqrt[3]{base}\right)}}^{-1}\right)} \]
      3. unpow-prod-down99.4%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\log \color{blue}{\left({\left(\sqrt[3]{base} \cdot \sqrt[3]{base}\right)}^{-1} \cdot {\left(\sqrt[3]{base}\right)}^{-1}\right)}} \]
      4. log-prod99.3%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\color{blue}{\log \left({\left(\sqrt[3]{base} \cdot \sqrt[3]{base}\right)}^{-1}\right) + \log \left({\left(\sqrt[3]{base}\right)}^{-1}\right)}} \]
      5. pow299.3%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\log \left({\color{blue}{\left({\left(\sqrt[3]{base}\right)}^{2}\right)}}^{-1}\right) + \log \left({\left(\sqrt[3]{base}\right)}^{-1}\right)} \]
    6. Applied egg-rr99.3%

      \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\color{blue}{\log \left({\left({\left(\sqrt[3]{base}\right)}^{2}\right)}^{-1}\right) + \log \left({\left(\sqrt[3]{base}\right)}^{-1}\right)}} \]
    7. Step-by-step derivation
      1. log-pow99.3%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\color{blue}{-1 \cdot \log \left({\left(\sqrt[3]{base}\right)}^{2}\right)} + \log \left({\left(\sqrt[3]{base}\right)}^{-1}\right)} \]
      2. log-pow99.3%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \log \left({\left(\sqrt[3]{base}\right)}^{2}\right) + \color{blue}{-1 \cdot \log \left(\sqrt[3]{base}\right)}} \]
      3. distribute-lft-out99.3%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\color{blue}{-1 \cdot \left(\log \left({\left(\sqrt[3]{base}\right)}^{2}\right) + \log \left(\sqrt[3]{base}\right)\right)}} \]
      4. log-pow99.3%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \left(\color{blue}{2 \cdot \log \left(\sqrt[3]{base}\right)} + \log \left(\sqrt[3]{base}\right)\right)} \]
      5. distribute-lft1-in99.3%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \color{blue}{\left(\left(2 + 1\right) \cdot \log \left(\sqrt[3]{base}\right)\right)}} \]
      6. metadata-eval99.3%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \left(\color{blue}{3} \cdot \log \left(\sqrt[3]{base}\right)\right)} \]
    8. Simplified99.3%

      \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\color{blue}{-1 \cdot \left(3 \cdot \log \left(\sqrt[3]{base}\right)\right)}} \]
    9. Step-by-step derivation
      1. *-un-lft-identity99.3%

        \[\leadsto -1 \cdot \frac{\color{blue}{1 \cdot \tan^{-1}_* \frac{im}{re}}}{-1 \cdot \left(3 \cdot \log \left(\sqrt[3]{base}\right)\right)} \]
      2. add-sqr-sqrt98.9%

        \[\leadsto -1 \cdot \frac{1 \cdot \tan^{-1}_* \frac{im}{re}}{\color{blue}{\sqrt{-1 \cdot \left(3 \cdot \log \left(\sqrt[3]{base}\right)\right)} \cdot \sqrt{-1 \cdot \left(3 \cdot \log \left(\sqrt[3]{base}\right)\right)}}} \]
      3. times-frac99.1%

        \[\leadsto -1 \cdot \color{blue}{\left(\frac{1}{\sqrt{-1 \cdot \left(3 \cdot \log \left(\sqrt[3]{base}\right)\right)}} \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\sqrt{-1 \cdot \left(3 \cdot \log \left(\sqrt[3]{base}\right)\right)}}\right)} \]
    10. Applied egg-rr0.0%

      \[\leadsto -1 \cdot \color{blue}{\left(\sqrt{\log base} \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\sqrt{\log base}}\right)} \]
    11. Step-by-step derivation
      1. associate-*r/0.0%

        \[\leadsto -1 \cdot \color{blue}{\frac{\sqrt{\log base} \cdot \tan^{-1}_* \frac{im}{re}}{\sqrt{\log base}}} \]
      2. *-commutative0.0%

        \[\leadsto -1 \cdot \frac{\color{blue}{\tan^{-1}_* \frac{im}{re} \cdot \sqrt{\log base}}}{\sqrt{\log base}} \]
      3. associate-/l*0.0%

        \[\leadsto -1 \cdot \color{blue}{\frac{\tan^{-1}_* \frac{im}{re}}{\frac{\sqrt{\log base}}{\sqrt{\log base}}}} \]
      4. rem-square-sqrt0.0%

        \[\leadsto -1 \cdot \frac{\color{blue}{\sqrt{\tan^{-1}_* \frac{im}{re}} \cdot \sqrt{\tan^{-1}_* \frac{im}{re}}}}{\frac{\sqrt{\log base}}{\sqrt{\log base}}} \]
      5. *-inverses14.8%

        \[\leadsto -1 \cdot \frac{\sqrt{\tan^{-1}_* \frac{im}{re}} \cdot \sqrt{\tan^{-1}_* \frac{im}{re}}}{\color{blue}{1}} \]
      6. associate-*r/14.8%

        \[\leadsto -1 \cdot \color{blue}{\left(\sqrt{\tan^{-1}_* \frac{im}{re}} \cdot \frac{\sqrt{\tan^{-1}_* \frac{im}{re}}}{1}\right)} \]
      7. /-rgt-identity14.8%

        \[\leadsto -1 \cdot \left(\sqrt{\tan^{-1}_* \frac{im}{re}} \cdot \color{blue}{\sqrt{\tan^{-1}_* \frac{im}{re}}}\right) \]
      8. rem-square-sqrt20.7%

        \[\leadsto -1 \cdot \color{blue}{\tan^{-1}_* \frac{im}{re}} \]
    12. Simplified20.7%

      \[\leadsto -1 \cdot \color{blue}{\tan^{-1}_* \frac{im}{re}} \]

    if 1 < base

    1. Initial program 50.1%

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

        \[\leadsto \frac{\tan^{-1}_* \frac{im}{re} \cdot \log base - \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0} \]
      2. --rgt-identity99.4%

        \[\leadsto \frac{\color{blue}{\tan^{-1}_* \frac{im}{re} \cdot \log base}}{\log base \cdot \log base + 0 \cdot 0} \]
      3. metadata-eval99.4%

        \[\leadsto \frac{\tan^{-1}_* \frac{im}{re} \cdot \log base}{\log base \cdot \log base + \color{blue}{0}} \]
      4. +-rgt-identity99.4%

        \[\leadsto \frac{\tan^{-1}_* \frac{im}{re} \cdot \log base}{\color{blue}{\log base \cdot \log base}} \]
      5. times-frac99.5%

        \[\leadsto \color{blue}{\frac{\tan^{-1}_* \frac{im}{re}}{\log base} \cdot \frac{\log base}{\log base}} \]
      6. *-inverses99.5%

        \[\leadsto \frac{\tan^{-1}_* \frac{im}{re}}{\log base} \cdot \color{blue}{1} \]
      7. *-rgt-identity99.5%

        \[\leadsto \color{blue}{\frac{\tan^{-1}_* \frac{im}{re}}{\log base}} \]
    3. Simplified99.5%

      \[\leadsto \color{blue}{\frac{\tan^{-1}_* \frac{im}{re}}{\log base}} \]
    4. Taylor expanded in base around inf 99.6%

      \[\leadsto \color{blue}{-1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\log \left(\frac{1}{base}\right)}} \]
    5. Step-by-step derivation
      1. inv-pow99.6%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\log \color{blue}{\left({base}^{-1}\right)}} \]
      2. add-cube-cbrt99.5%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\log \left({\color{blue}{\left(\left(\sqrt[3]{base} \cdot \sqrt[3]{base}\right) \cdot \sqrt[3]{base}\right)}}^{-1}\right)} \]
      3. unpow-prod-down99.5%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\log \color{blue}{\left({\left(\sqrt[3]{base} \cdot \sqrt[3]{base}\right)}^{-1} \cdot {\left(\sqrt[3]{base}\right)}^{-1}\right)}} \]
      4. log-prod99.5%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\color{blue}{\log \left({\left(\sqrt[3]{base} \cdot \sqrt[3]{base}\right)}^{-1}\right) + \log \left({\left(\sqrt[3]{base}\right)}^{-1}\right)}} \]
      5. pow299.5%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\log \left({\color{blue}{\left({\left(\sqrt[3]{base}\right)}^{2}\right)}}^{-1}\right) + \log \left({\left(\sqrt[3]{base}\right)}^{-1}\right)} \]
    6. Applied egg-rr99.5%

      \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\color{blue}{\log \left({\left({\left(\sqrt[3]{base}\right)}^{2}\right)}^{-1}\right) + \log \left({\left(\sqrt[3]{base}\right)}^{-1}\right)}} \]
    7. Step-by-step derivation
      1. log-pow99.5%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\color{blue}{-1 \cdot \log \left({\left(\sqrt[3]{base}\right)}^{2}\right)} + \log \left({\left(\sqrt[3]{base}\right)}^{-1}\right)} \]
      2. log-pow99.5%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \log \left({\left(\sqrt[3]{base}\right)}^{2}\right) + \color{blue}{-1 \cdot \log \left(\sqrt[3]{base}\right)}} \]
      3. distribute-lft-out99.5%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\color{blue}{-1 \cdot \left(\log \left({\left(\sqrt[3]{base}\right)}^{2}\right) + \log \left(\sqrt[3]{base}\right)\right)}} \]
      4. log-pow99.5%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \left(\color{blue}{2 \cdot \log \left(\sqrt[3]{base}\right)} + \log \left(\sqrt[3]{base}\right)\right)} \]
      5. distribute-lft1-in99.5%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \color{blue}{\left(\left(2 + 1\right) \cdot \log \left(\sqrt[3]{base}\right)\right)}} \]
      6. metadata-eval99.5%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \left(\color{blue}{3} \cdot \log \left(\sqrt[3]{base}\right)\right)} \]
    8. Simplified99.5%

      \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\color{blue}{-1 \cdot \left(3 \cdot \log \left(\sqrt[3]{base}\right)\right)}} \]
    9. Step-by-step derivation
      1. add-log-exp99.5%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \color{blue}{\log \left(e^{3 \cdot \log \left(\sqrt[3]{base}\right)}\right)}} \]
      2. *-commutative99.5%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \log \left(e^{\color{blue}{\log \left(\sqrt[3]{base}\right) \cdot 3}}\right)} \]
      3. exp-to-pow99.5%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \log \color{blue}{\left({\left(\sqrt[3]{base}\right)}^{3}\right)}} \]
      4. pow399.5%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \log \color{blue}{\left(\left(\sqrt[3]{base} \cdot \sqrt[3]{base}\right) \cdot \sqrt[3]{base}\right)}} \]
      5. add-cube-cbrt99.5%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \log \color{blue}{base}} \]
      6. /-rgt-identity99.5%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \color{blue}{\frac{\log base}{1}}} \]
      7. add-sqr-sqrt99.1%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \frac{\color{blue}{\sqrt{\log base} \cdot \sqrt{\log base}}}{1}} \]
      8. associate-/l*99.1%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \color{blue}{\frac{\sqrt{\log base}}{\frac{1}{\sqrt{\log base}}}}} \]
      9. metadata-eval99.1%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \frac{\sqrt{\log base}}{\frac{\color{blue}{\sqrt{1}}}{\sqrt{\log base}}}} \]
      10. /-rgt-identity99.1%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \frac{\sqrt{\log base}}{\frac{\sqrt{1}}{\sqrt{\color{blue}{\frac{\log base}{1}}}}}} \]
      11. sqrt-div99.3%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \frac{\sqrt{\log base}}{\color{blue}{\sqrt{\frac{1}{\frac{\log base}{1}}}}}} \]
      12. clear-num99.3%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \frac{\sqrt{\log base}}{\sqrt{\color{blue}{\frac{1}{\log base}}}}} \]
      13. add-exp-log99.0%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \frac{\sqrt{\log base}}{\sqrt{\frac{1}{\color{blue}{e^{\log \log base}}}}}} \]
      14. exp-neg99.0%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \frac{\sqrt{\log base}}{\sqrt{\color{blue}{e^{-\log \log base}}}}} \]
      15. add-sqr-sqrt0.0%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \frac{\sqrt{\log base}}{\sqrt{e^{\color{blue}{\sqrt{-\log \log base} \cdot \sqrt{-\log \log base}}}}}} \]
      16. sqrt-unprod21.9%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \frac{\sqrt{\log base}}{\sqrt{e^{\color{blue}{\sqrt{\left(-\log \log base\right) \cdot \left(-\log \log base\right)}}}}}} \]
      17. sqr-neg21.9%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \frac{\sqrt{\log base}}{\sqrt{e^{\sqrt{\color{blue}{\log \log base \cdot \log \log base}}}}}} \]
      18. sqrt-unprod21.9%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \frac{\sqrt{\log base}}{\sqrt{e^{\color{blue}{\sqrt{\log \log base} \cdot \sqrt{\log \log base}}}}}} \]
      19. add-sqr-sqrt21.9%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \frac{\sqrt{\log base}}{\sqrt{e^{\color{blue}{\log \log base}}}}} \]
      20. add-exp-log21.9%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \frac{\sqrt{\log base}}{\sqrt{\color{blue}{\log base}}}} \]
    10. Applied egg-rr21.9%

      \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \color{blue}{\frac{\sqrt{\log base}}{\sqrt{\log base}}}} \]
    11. Step-by-step derivation
      1. *-inverses21.9%

        \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \color{blue}{1}} \]
    12. Simplified21.9%

      \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \color{blue}{1}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification21.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;base \leq 1:\\ \;\;\;\;-\tan^{-1}_* \frac{im}{re}\\ \mathbf{else}:\\ \;\;\;\;\frac{-\tan^{-1}_* \frac{im}{re}}{-1}\\ \end{array} \]

Alternative 3: 13.9% accurate, 6.0× speedup?

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

\\
-\tan^{-1}_* \frac{im}{re}
\end{array}
Derivation
  1. Initial program 54.3%

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

      \[\leadsto \frac{\tan^{-1}_* \frac{im}{re} \cdot \log base - \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0} \]
    2. --rgt-identity99.4%

      \[\leadsto \frac{\color{blue}{\tan^{-1}_* \frac{im}{re} \cdot \log base}}{\log base \cdot \log base + 0 \cdot 0} \]
    3. metadata-eval99.4%

      \[\leadsto \frac{\tan^{-1}_* \frac{im}{re} \cdot \log base}{\log base \cdot \log base + \color{blue}{0}} \]
    4. +-rgt-identity99.4%

      \[\leadsto \frac{\tan^{-1}_* \frac{im}{re} \cdot \log base}{\color{blue}{\log base \cdot \log base}} \]
    5. times-frac99.5%

      \[\leadsto \color{blue}{\frac{\tan^{-1}_* \frac{im}{re}}{\log base} \cdot \frac{\log base}{\log base}} \]
    6. *-inverses99.5%

      \[\leadsto \frac{\tan^{-1}_* \frac{im}{re}}{\log base} \cdot \color{blue}{1} \]
    7. *-rgt-identity99.5%

      \[\leadsto \color{blue}{\frac{\tan^{-1}_* \frac{im}{re}}{\log base}} \]
  3. Simplified99.5%

    \[\leadsto \color{blue}{\frac{\tan^{-1}_* \frac{im}{re}}{\log base}} \]
  4. Taylor expanded in base around inf 99.5%

    \[\leadsto \color{blue}{-1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\log \left(\frac{1}{base}\right)}} \]
  5. Step-by-step derivation
    1. inv-pow99.5%

      \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\log \color{blue}{\left({base}^{-1}\right)}} \]
    2. add-cube-cbrt99.5%

      \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\log \left({\color{blue}{\left(\left(\sqrt[3]{base} \cdot \sqrt[3]{base}\right) \cdot \sqrt[3]{base}\right)}}^{-1}\right)} \]
    3. unpow-prod-down99.5%

      \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\log \color{blue}{\left({\left(\sqrt[3]{base} \cdot \sqrt[3]{base}\right)}^{-1} \cdot {\left(\sqrt[3]{base}\right)}^{-1}\right)}} \]
    4. log-prod99.4%

      \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\color{blue}{\log \left({\left(\sqrt[3]{base} \cdot \sqrt[3]{base}\right)}^{-1}\right) + \log \left({\left(\sqrt[3]{base}\right)}^{-1}\right)}} \]
    5. pow299.4%

      \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\log \left({\color{blue}{\left({\left(\sqrt[3]{base}\right)}^{2}\right)}}^{-1}\right) + \log \left({\left(\sqrt[3]{base}\right)}^{-1}\right)} \]
  6. Applied egg-rr99.4%

    \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\color{blue}{\log \left({\left({\left(\sqrt[3]{base}\right)}^{2}\right)}^{-1}\right) + \log \left({\left(\sqrt[3]{base}\right)}^{-1}\right)}} \]
  7. Step-by-step derivation
    1. log-pow99.4%

      \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\color{blue}{-1 \cdot \log \left({\left(\sqrt[3]{base}\right)}^{2}\right)} + \log \left({\left(\sqrt[3]{base}\right)}^{-1}\right)} \]
    2. log-pow99.4%

      \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \log \left({\left(\sqrt[3]{base}\right)}^{2}\right) + \color{blue}{-1 \cdot \log \left(\sqrt[3]{base}\right)}} \]
    3. distribute-lft-out99.4%

      \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\color{blue}{-1 \cdot \left(\log \left({\left(\sqrt[3]{base}\right)}^{2}\right) + \log \left(\sqrt[3]{base}\right)\right)}} \]
    4. log-pow99.4%

      \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \left(\color{blue}{2 \cdot \log \left(\sqrt[3]{base}\right)} + \log \left(\sqrt[3]{base}\right)\right)} \]
    5. distribute-lft1-in99.4%

      \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \color{blue}{\left(\left(2 + 1\right) \cdot \log \left(\sqrt[3]{base}\right)\right)}} \]
    6. metadata-eval99.4%

      \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{-1 \cdot \left(\color{blue}{3} \cdot \log \left(\sqrt[3]{base}\right)\right)} \]
  8. Simplified99.4%

    \[\leadsto -1 \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\color{blue}{-1 \cdot \left(3 \cdot \log \left(\sqrt[3]{base}\right)\right)}} \]
  9. Step-by-step derivation
    1. *-un-lft-identity99.4%

      \[\leadsto -1 \cdot \frac{\color{blue}{1 \cdot \tan^{-1}_* \frac{im}{re}}}{-1 \cdot \left(3 \cdot \log \left(\sqrt[3]{base}\right)\right)} \]
    2. add-sqr-sqrt51.4%

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

      \[\leadsto -1 \cdot \color{blue}{\left(\frac{1}{\sqrt{-1 \cdot \left(3 \cdot \log \left(\sqrt[3]{base}\right)\right)}} \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\sqrt{-1 \cdot \left(3 \cdot \log \left(\sqrt[3]{base}\right)\right)}}\right)} \]
  10. Applied egg-rr5.3%

    \[\leadsto -1 \cdot \color{blue}{\left(\sqrt{\log base} \cdot \frac{\tan^{-1}_* \frac{im}{re}}{\sqrt{\log base}}\right)} \]
  11. Step-by-step derivation
    1. associate-*r/5.3%

      \[\leadsto -1 \cdot \color{blue}{\frac{\sqrt{\log base} \cdot \tan^{-1}_* \frac{im}{re}}{\sqrt{\log base}}} \]
    2. *-commutative5.3%

      \[\leadsto -1 \cdot \frac{\color{blue}{\tan^{-1}_* \frac{im}{re} \cdot \sqrt{\log base}}}{\sqrt{\log base}} \]
    3. associate-/l*5.3%

      \[\leadsto -1 \cdot \color{blue}{\frac{\tan^{-1}_* \frac{im}{re}}{\frac{\sqrt{\log base}}{\sqrt{\log base}}}} \]
    4. rem-square-sqrt4.5%

      \[\leadsto -1 \cdot \frac{\color{blue}{\sqrt{\tan^{-1}_* \frac{im}{re}} \cdot \sqrt{\tan^{-1}_* \frac{im}{re}}}}{\frac{\sqrt{\log base}}{\sqrt{\log base}}} \]
    5. *-inverses12.2%

      \[\leadsto -1 \cdot \frac{\sqrt{\tan^{-1}_* \frac{im}{re}} \cdot \sqrt{\tan^{-1}_* \frac{im}{re}}}{\color{blue}{1}} \]
    6. associate-*r/12.2%

      \[\leadsto -1 \cdot \color{blue}{\left(\sqrt{\tan^{-1}_* \frac{im}{re}} \cdot \frac{\sqrt{\tan^{-1}_* \frac{im}{re}}}{1}\right)} \]
    7. /-rgt-identity12.2%

      \[\leadsto -1 \cdot \left(\sqrt{\tan^{-1}_* \frac{im}{re}} \cdot \color{blue}{\sqrt{\tan^{-1}_* \frac{im}{re}}}\right) \]
    8. rem-square-sqrt16.0%

      \[\leadsto -1 \cdot \color{blue}{\tan^{-1}_* \frac{im}{re}} \]
  12. Simplified16.0%

    \[\leadsto -1 \cdot \color{blue}{\tan^{-1}_* \frac{im}{re}} \]
  13. Final simplification16.0%

    \[\leadsto -\tan^{-1}_* \frac{im}{re} \]

Reproduce

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