math.log/2 on complex, real part

Percentage Accurate: 51.3% → 99.2%
Time: 20.0s
Alternatives: 5
Speedup: 2.7×

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 5 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 51.3% 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.2% accurate, 0.8× speedup?

\[\begin{array}{l} re_m = \left|re\right| \\ [re_m, im, base] = \mathsf{sort}([re_m, im, base])\\ \\ \frac{\log \left(\mathsf{hypot}\left(e^{\log im}, re\_m\right)\right) \cdot \log base}{{\log base}^{2}} \end{array} \]
re_m = (fabs.f64 re)
NOTE: re_m, im, and base should be sorted in increasing order before calling this function.
(FPCore (re_m im base)
 :precision binary64
 (/ (* (log (hypot (exp (log im)) re_m)) (log base)) (pow (log base) 2.0)))
re_m = fabs(re);
assert(re_m < im && im < base);
double code(double re_m, double im, double base) {
	return (log(hypot(exp(log(im)), re_m)) * log(base)) / pow(log(base), 2.0);
}
re_m = Math.abs(re);
assert re_m < im && im < base;
public static double code(double re_m, double im, double base) {
	return (Math.log(Math.hypot(Math.exp(Math.log(im)), re_m)) * Math.log(base)) / Math.pow(Math.log(base), 2.0);
}
re_m = math.fabs(re)
[re_m, im, base] = sort([re_m, im, base])
def code(re_m, im, base):
	return (math.log(math.hypot(math.exp(math.log(im)), re_m)) * math.log(base)) / math.pow(math.log(base), 2.0)
re_m = abs(re)
re_m, im, base = sort([re_m, im, base])
function code(re_m, im, base)
	return Float64(Float64(log(hypot(exp(log(im)), re_m)) * log(base)) / (log(base) ^ 2.0))
end
re_m = abs(re);
re_m, im, base = num2cell(sort([re_m, im, base])){:}
function tmp = code(re_m, im, base)
	tmp = (log(hypot(exp(log(im)), re_m)) * log(base)) / (log(base) ^ 2.0);
end
re_m = N[Abs[re], $MachinePrecision]
NOTE: re_m, im, and base should be sorted in increasing order before calling this function.
code[re$95$m_, im_, base_] := N[(N[(N[Log[N[Sqrt[N[Exp[N[Log[im], $MachinePrecision]], $MachinePrecision] ^ 2 + re$95$m ^ 2], $MachinePrecision]], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] / N[Power[N[Log[base], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
re_m = \left|re\right|
\\
[re_m, im, base] = \mathsf{sort}([re_m, im, base])\\
\\
\frac{\log \left(\mathsf{hypot}\left(e^{\log im}, re\_m\right)\right) \cdot \log base}{{\log base}^{2}}
\end{array}
Derivation
  1. Initial program 55.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. Add Preprocessing
  3. Step-by-step derivation
    1. +-commutativeN/A

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

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{{im}^{2}} + re \cdot re}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    3. pow-to-expN/A

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{e^{\log im \cdot 2}} + re \cdot re}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    4. exp-lft-sqrN/A

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{e^{\log im} \cdot e^{\log im}} + re \cdot re}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    5. accelerator-lowering-hypot.f64N/A

      \[\leadsto \frac{\log \color{blue}{\left(\mathsf{hypot}\left(e^{\log im}, re\right)\right)} \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    6. exp-lowering-exp.f64N/A

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(\color{blue}{e^{\log im}}, re\right)\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    7. log-lowering-log.f6446.1

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(e^{\color{blue}{\log im}}, re\right)\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
  4. Applied egg-rr46.1%

    \[\leadsto \frac{\log \color{blue}{\left(\mathsf{hypot}\left(e^{\log im}, re\right)\right)} \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
  5. Step-by-step derivation
    1. mul0-rgt46.1

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

    \[\leadsto \frac{\log \left(\mathsf{hypot}\left(e^{\log im}, re\right)\right) \cdot \log base + \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0} \]
  7. Step-by-step derivation
    1. metadata-eval46.1

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(e^{\log im}, re\right)\right) \cdot \log base + 0}{\log base \cdot \log base + \color{blue}{0}} \]
  8. Applied egg-rr46.1%

    \[\leadsto \frac{\log \left(\mathsf{hypot}\left(e^{\log im}, re\right)\right) \cdot \log base + 0}{\log base \cdot \log base + \color{blue}{0}} \]
  9. Step-by-step derivation
    1. pow2N/A

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(e^{\log im}, re\right)\right) \cdot \log base + 0}{\color{blue}{{\log base}^{2}} + 0} \]
    2. pow-lowering-pow.f64N/A

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(e^{\log im}, re\right)\right) \cdot \log base + 0}{\color{blue}{{\log base}^{2}} + 0} \]
    3. log-lowering-log.f6446.1

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(e^{\log im}, re\right)\right) \cdot \log base + 0}{{\color{blue}{\log base}}^{2} + 0} \]
  10. Applied egg-rr46.1%

    \[\leadsto \frac{\log \left(\mathsf{hypot}\left(e^{\log im}, re\right)\right) \cdot \log base + 0}{\color{blue}{{\log base}^{2}} + 0} \]
  11. Final simplification46.1%

    \[\leadsto \frac{\log \left(\mathsf{hypot}\left(e^{\log im}, re\right)\right) \cdot \log base}{{\log base}^{2}} \]
  12. Add Preprocessing

Alternative 2: 99.2% accurate, 1.1× speedup?

\[\begin{array}{l} re_m = \left|re\right| \\ [re_m, im, base] = \mathsf{sort}([re_m, im, base])\\ \\ \frac{\log base \cdot \log \left(\mathsf{hypot}\left(im, re\_m\right)\right)}{\log base \cdot \log base} \end{array} \]
re_m = (fabs.f64 re)
NOTE: re_m, im, and base should be sorted in increasing order before calling this function.
(FPCore (re_m im base)
 :precision binary64
 (/ (* (log base) (log (hypot im re_m))) (* (log base) (log base))))
re_m = fabs(re);
assert(re_m < im && im < base);
double code(double re_m, double im, double base) {
	return (log(base) * log(hypot(im, re_m))) / (log(base) * log(base));
}
re_m = Math.abs(re);
assert re_m < im && im < base;
public static double code(double re_m, double im, double base) {
	return (Math.log(base) * Math.log(Math.hypot(im, re_m))) / (Math.log(base) * Math.log(base));
}
re_m = math.fabs(re)
[re_m, im, base] = sort([re_m, im, base])
def code(re_m, im, base):
	return (math.log(base) * math.log(math.hypot(im, re_m))) / (math.log(base) * math.log(base))
re_m = abs(re)
re_m, im, base = sort([re_m, im, base])
function code(re_m, im, base)
	return Float64(Float64(log(base) * log(hypot(im, re_m))) / Float64(log(base) * log(base)))
end
re_m = abs(re);
re_m, im, base = num2cell(sort([re_m, im, base])){:}
function tmp = code(re_m, im, base)
	tmp = (log(base) * log(hypot(im, re_m))) / (log(base) * log(base));
end
re_m = N[Abs[re], $MachinePrecision]
NOTE: re_m, im, and base should be sorted in increasing order before calling this function.
code[re$95$m_, im_, base_] := N[(N[(N[Log[base], $MachinePrecision] * N[Log[N[Sqrt[im ^ 2 + re$95$m ^ 2], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(N[Log[base], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
re_m = \left|re\right|
\\
[re_m, im, base] = \mathsf{sort}([re_m, im, base])\\
\\
\frac{\log base \cdot \log \left(\mathsf{hypot}\left(im, re\_m\right)\right)}{\log base \cdot \log base}
\end{array}
Derivation
  1. Initial program 55.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. Add Preprocessing
  3. Step-by-step derivation
    1. +-commutativeN/A

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

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{{im}^{2}} + re \cdot re}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    3. pow-to-expN/A

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{e^{\log im \cdot 2}} + re \cdot re}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    4. exp-lft-sqrN/A

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{e^{\log im} \cdot e^{\log im}} + re \cdot re}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    5. accelerator-lowering-hypot.f64N/A

      \[\leadsto \frac{\log \color{blue}{\left(\mathsf{hypot}\left(e^{\log im}, re\right)\right)} \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    6. exp-lowering-exp.f64N/A

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(\color{blue}{e^{\log im}}, re\right)\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    7. log-lowering-log.f6446.1

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(e^{\color{blue}{\log im}}, re\right)\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
  4. Applied egg-rr46.1%

    \[\leadsto \frac{\log \color{blue}{\left(\mathsf{hypot}\left(e^{\log im}, re\right)\right)} \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
  5. Step-by-step derivation
    1. mul0-rgt46.1

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

    \[\leadsto \frac{\log \left(\mathsf{hypot}\left(e^{\log im}, re\right)\right) \cdot \log base + \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0} \]
  7. Step-by-step derivation
    1. metadata-eval46.1

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(e^{\log im}, re\right)\right) \cdot \log base + 0}{\log base \cdot \log base + \color{blue}{0}} \]
  8. Applied egg-rr46.1%

    \[\leadsto \frac{\log \left(\mathsf{hypot}\left(e^{\log im}, re\right)\right) \cdot \log base + 0}{\log base \cdot \log base + \color{blue}{0}} \]
  9. Step-by-step derivation
    1. rem-exp-log99.2

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

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

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

Alternative 3: 76.4% accurate, 1.3× speedup?

\[\begin{array}{l} re_m = \left|re\right| \\ [re_m, im, base] = \mathsf{sort}([re_m, im, base])\\ \\ \frac{\log base \cdot \log \left(\mathsf{fma}\left(re\_m, \frac{re\_m \cdot 0.5}{im}, im\right)\right)}{\log base \cdot \log base} \end{array} \]
re_m = (fabs.f64 re)
NOTE: re_m, im, and base should be sorted in increasing order before calling this function.
(FPCore (re_m im base)
 :precision binary64
 (/
  (* (log base) (log (fma re_m (/ (* re_m 0.5) im) im)))
  (* (log base) (log base))))
re_m = fabs(re);
assert(re_m < im && im < base);
double code(double re_m, double im, double base) {
	return (log(base) * log(fma(re_m, ((re_m * 0.5) / im), im))) / (log(base) * log(base));
}
re_m = abs(re)
re_m, im, base = sort([re_m, im, base])
function code(re_m, im, base)
	return Float64(Float64(log(base) * log(fma(re_m, Float64(Float64(re_m * 0.5) / im), im))) / Float64(log(base) * log(base)))
end
re_m = N[Abs[re], $MachinePrecision]
NOTE: re_m, im, and base should be sorted in increasing order before calling this function.
code[re$95$m_, im_, base_] := N[(N[(N[Log[base], $MachinePrecision] * N[Log[N[(re$95$m * N[(N[(re$95$m * 0.5), $MachinePrecision] / im), $MachinePrecision] + im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(N[Log[base], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
re_m = \left|re\right|
\\
[re_m, im, base] = \mathsf{sort}([re_m, im, base])\\
\\
\frac{\log base \cdot \log \left(\mathsf{fma}\left(re\_m, \frac{re\_m \cdot 0.5}{im}, im\right)\right)}{\log base \cdot \log base}
\end{array}
Derivation
  1. Initial program 55.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. Add Preprocessing
  3. Step-by-step derivation
    1. +-commutativeN/A

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

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{{im}^{2}} + re \cdot re}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    3. pow-to-expN/A

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{e^{\log im \cdot 2}} + re \cdot re}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    4. exp-lft-sqrN/A

      \[\leadsto \frac{\log \left(\sqrt{\color{blue}{e^{\log im} \cdot e^{\log im}} + re \cdot re}\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    5. accelerator-lowering-hypot.f64N/A

      \[\leadsto \frac{\log \color{blue}{\left(\mathsf{hypot}\left(e^{\log im}, re\right)\right)} \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    6. exp-lowering-exp.f64N/A

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(\color{blue}{e^{\log im}}, re\right)\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
    7. log-lowering-log.f6446.1

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(e^{\color{blue}{\log im}}, re\right)\right) \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
  4. Applied egg-rr46.1%

    \[\leadsto \frac{\log \color{blue}{\left(\mathsf{hypot}\left(e^{\log im}, re\right)\right)} \cdot \log base + \tan^{-1}_* \frac{im}{re} \cdot 0}{\log base \cdot \log base + 0 \cdot 0} \]
  5. Step-by-step derivation
    1. mul0-rgt46.1

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

    \[\leadsto \frac{\log \left(\mathsf{hypot}\left(e^{\log im}, re\right)\right) \cdot \log base + \color{blue}{0}}{\log base \cdot \log base + 0 \cdot 0} \]
  7. Step-by-step derivation
    1. metadata-eval46.1

      \[\leadsto \frac{\log \left(\mathsf{hypot}\left(e^{\log im}, re\right)\right) \cdot \log base + 0}{\log base \cdot \log base + \color{blue}{0}} \]
  8. Applied egg-rr46.1%

    \[\leadsto \frac{\log \left(\mathsf{hypot}\left(e^{\log im}, re\right)\right) \cdot \log base + 0}{\log base \cdot \log base + \color{blue}{0}} \]
  9. Taylor expanded in re around 0

    \[\leadsto \frac{\log \color{blue}{\left(im + \frac{1}{2} \cdot \frac{{re}^{2}}{im}\right)} \cdot \log base + 0}{\log base \cdot \log base + 0} \]
  10. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \frac{\log \color{blue}{\left(\frac{1}{2} \cdot \frac{{re}^{2}}{im} + im\right)} \cdot \log base + 0}{\log base \cdot \log base + 0} \]
    2. *-commutativeN/A

      \[\leadsto \frac{\log \left(\color{blue}{\frac{{re}^{2}}{im} \cdot \frac{1}{2}} + im\right) \cdot \log base + 0}{\log base \cdot \log base + 0} \]
    3. associate-*l/N/A

      \[\leadsto \frac{\log \left(\color{blue}{\frac{{re}^{2} \cdot \frac{1}{2}}{im}} + im\right) \cdot \log base + 0}{\log base \cdot \log base + 0} \]
    4. associate-*r/N/A

      \[\leadsto \frac{\log \left(\color{blue}{{re}^{2} \cdot \frac{\frac{1}{2}}{im}} + im\right) \cdot \log base + 0}{\log base \cdot \log base + 0} \]
    5. metadata-evalN/A

      \[\leadsto \frac{\log \left({re}^{2} \cdot \frac{\color{blue}{\frac{1}{2} \cdot 1}}{im} + im\right) \cdot \log base + 0}{\log base \cdot \log base + 0} \]
    6. associate-*r/N/A

      \[\leadsto \frac{\log \left({re}^{2} \cdot \color{blue}{\left(\frac{1}{2} \cdot \frac{1}{im}\right)} + im\right) \cdot \log base + 0}{\log base \cdot \log base + 0} \]
    7. unpow2N/A

      \[\leadsto \frac{\log \left(\color{blue}{\left(re \cdot re\right)} \cdot \left(\frac{1}{2} \cdot \frac{1}{im}\right) + im\right) \cdot \log base + 0}{\log base \cdot \log base + 0} \]
    8. associate-*l*N/A

      \[\leadsto \frac{\log \left(\color{blue}{re \cdot \left(re \cdot \left(\frac{1}{2} \cdot \frac{1}{im}\right)\right)} + im\right) \cdot \log base + 0}{\log base \cdot \log base + 0} \]
    9. accelerator-lowering-fma.f64N/A

      \[\leadsto \frac{\log \color{blue}{\left(\mathsf{fma}\left(re, re \cdot \left(\frac{1}{2} \cdot \frac{1}{im}\right), im\right)\right)} \cdot \log base + 0}{\log base \cdot \log base + 0} \]
    10. associate-*r/N/A

      \[\leadsto \frac{\log \left(\mathsf{fma}\left(re, re \cdot \color{blue}{\frac{\frac{1}{2} \cdot 1}{im}}, im\right)\right) \cdot \log base + 0}{\log base \cdot \log base + 0} \]
    11. metadata-evalN/A

      \[\leadsto \frac{\log \left(\mathsf{fma}\left(re, re \cdot \frac{\color{blue}{\frac{1}{2}}}{im}, im\right)\right) \cdot \log base + 0}{\log base \cdot \log base + 0} \]
    12. associate-*r/N/A

      \[\leadsto \frac{\log \left(\mathsf{fma}\left(re, \color{blue}{\frac{re \cdot \frac{1}{2}}{im}}, im\right)\right) \cdot \log base + 0}{\log base \cdot \log base + 0} \]
    13. /-lowering-/.f64N/A

      \[\leadsto \frac{\log \left(\mathsf{fma}\left(re, \color{blue}{\frac{re \cdot \frac{1}{2}}{im}}, im\right)\right) \cdot \log base + 0}{\log base \cdot \log base + 0} \]
    14. *-lowering-*.f6423.5

      \[\leadsto \frac{\log \left(\mathsf{fma}\left(re, \frac{\color{blue}{re \cdot 0.5}}{im}, im\right)\right) \cdot \log base + 0}{\log base \cdot \log base + 0} \]
  11. Simplified23.5%

    \[\leadsto \frac{\log \color{blue}{\left(\mathsf{fma}\left(re, \frac{re \cdot 0.5}{im}, im\right)\right)} \cdot \log base + 0}{\log base \cdot \log base + 0} \]
  12. Final simplification23.5%

    \[\leadsto \frac{\log base \cdot \log \left(\mathsf{fma}\left(re, \frac{re \cdot 0.5}{im}, im\right)\right)}{\log base \cdot \log base} \]
  13. Add Preprocessing

Alternative 4: 76.7% accurate, 2.7× speedup?

\[\begin{array}{l} re_m = \left|re\right| \\ [re_m, im, base] = \mathsf{sort}([re_m, im, base])\\ \\ \frac{\log im}{\log base} \end{array} \]
re_m = (fabs.f64 re)
NOTE: re_m, im, and base should be sorted in increasing order before calling this function.
(FPCore (re_m im base) :precision binary64 (/ (log im) (log base)))
re_m = fabs(re);
assert(re_m < im && im < base);
double code(double re_m, double im, double base) {
	return log(im) / log(base);
}
re_m = abs(re)
NOTE: re_m, im, and base should be sorted in increasing order before calling this function.
real(8) function code(re_m, im, base)
    real(8), intent (in) :: re_m
    real(8), intent (in) :: im
    real(8), intent (in) :: base
    code = log(im) / log(base)
end function
re_m = Math.abs(re);
assert re_m < im && im < base;
public static double code(double re_m, double im, double base) {
	return Math.log(im) / Math.log(base);
}
re_m = math.fabs(re)
[re_m, im, base] = sort([re_m, im, base])
def code(re_m, im, base):
	return math.log(im) / math.log(base)
re_m = abs(re)
re_m, im, base = sort([re_m, im, base])
function code(re_m, im, base)
	return Float64(log(im) / log(base))
end
re_m = abs(re);
re_m, im, base = num2cell(sort([re_m, im, base])){:}
function tmp = code(re_m, im, base)
	tmp = log(im) / log(base);
end
re_m = N[Abs[re], $MachinePrecision]
NOTE: re_m, im, and base should be sorted in increasing order before calling this function.
code[re$95$m_, im_, base_] := N[(N[Log[im], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
re_m = \left|re\right|
\\
[re_m, im, base] = \mathsf{sort}([re_m, im, base])\\
\\
\frac{\log im}{\log base}
\end{array}
Derivation
  1. Initial program 55.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. Add Preprocessing
  3. Taylor expanded in re around 0

    \[\leadsto \color{blue}{\frac{\log im}{\log base}} \]
  4. Step-by-step derivation
    1. /-lowering-/.f64N/A

      \[\leadsto \color{blue}{\frac{\log im}{\log base}} \]
    2. log-lowering-log.f64N/A

      \[\leadsto \frac{\color{blue}{\log im}}{\log base} \]
    3. log-lowering-log.f6424.3

      \[\leadsto \frac{\log im}{\color{blue}{\log base}} \]
  5. Simplified24.3%

    \[\leadsto \color{blue}{\frac{\log im}{\log base}} \]
  6. Add Preprocessing

Alternative 5: 3.1% accurate, 562.0× speedup?

\[\begin{array}{l} re_m = \left|re\right| \\ [re_m, im, base] = \mathsf{sort}([re_m, im, base])\\ \\ 0 \end{array} \]
re_m = (fabs.f64 re)
NOTE: re_m, im, and base should be sorted in increasing order before calling this function.
(FPCore (re_m im base) :precision binary64 0.0)
re_m = fabs(re);
assert(re_m < im && im < base);
double code(double re_m, double im, double base) {
	return 0.0;
}
re_m = abs(re)
NOTE: re_m, im, and base should be sorted in increasing order before calling this function.
real(8) function code(re_m, im, base)
    real(8), intent (in) :: re_m
    real(8), intent (in) :: im
    real(8), intent (in) :: base
    code = 0.0d0
end function
re_m = Math.abs(re);
assert re_m < im && im < base;
public static double code(double re_m, double im, double base) {
	return 0.0;
}
re_m = math.fabs(re)
[re_m, im, base] = sort([re_m, im, base])
def code(re_m, im, base):
	return 0.0
re_m = abs(re)
re_m, im, base = sort([re_m, im, base])
function code(re_m, im, base)
	return 0.0
end
re_m = abs(re);
re_m, im, base = num2cell(sort([re_m, im, base])){:}
function tmp = code(re_m, im, base)
	tmp = 0.0;
end
re_m = N[Abs[re], $MachinePrecision]
NOTE: re_m, im, and base should be sorted in increasing order before calling this function.
code[re$95$m_, im_, base_] := 0.0
\begin{array}{l}
re_m = \left|re\right|
\\
[re_m, im, base] = \mathsf{sort}([re_m, im, base])\\
\\
0
\end{array}
Derivation
  1. Initial program 55.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. Add Preprocessing
  3. Taylor expanded in re around 0

    \[\leadsto \color{blue}{\frac{\log im}{\log base}} \]
  4. Step-by-step derivation
    1. /-lowering-/.f64N/A

      \[\leadsto \color{blue}{\frac{\log im}{\log base}} \]
    2. log-lowering-log.f64N/A

      \[\leadsto \frac{\color{blue}{\log im}}{\log base} \]
    3. log-lowering-log.f6424.3

      \[\leadsto \frac{\log im}{\color{blue}{\log base}} \]
  5. Simplified24.3%

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

    \[\leadsto \color{blue}{0} \]
  7. Add Preprocessing

Reproduce

?
herbie shell --seed 2024199 
(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))))