Average Error: 31.1 → 17.3
Time: 1.1m
Precision: 64
\[\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}\]
\[\begin{array}{l} \mathbf{if}\;re \le -2.881017364964909 \cdot 10^{+137}:\\ \;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;re \le -3.2287882184845622 \cdot 10^{-164}:\\ \;\;\;\;\frac{\log \left(\sqrt{im \cdot im + re \cdot re}\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array}\]
double f(double re, double im, double base) {
        double r1532263 = re;
        double r1532264 = r1532263 * r1532263;
        double r1532265 = im;
        double r1532266 = r1532265 * r1532265;
        double r1532267 = r1532264 + r1532266;
        double r1532268 = sqrt(r1532267);
        double r1532269 = log(r1532268);
        double r1532270 = base;
        double r1532271 = log(r1532270);
        double r1532272 = r1532269 * r1532271;
        double r1532273 = atan2(r1532265, r1532263);
        double r1532274 = 0.0;
        double r1532275 = r1532273 * r1532274;
        double r1532276 = r1532272 + r1532275;
        double r1532277 = r1532271 * r1532271;
        double r1532278 = r1532274 * r1532274;
        double r1532279 = r1532277 + r1532278;
        double r1532280 = r1532276 / r1532279;
        return r1532280;
}

double f(double re, double im, double base) {
        double r1532281 = re;
        double r1532282 = -2.881017364964909e+137;
        bool r1532283 = r1532281 <= r1532282;
        double r1532284 = -1.0;
        double r1532285 = r1532284 / r1532281;
        double r1532286 = log(r1532285);
        double r1532287 = base;
        double r1532288 = log(r1532287);
        double r1532289 = r1532286 / r1532288;
        double r1532290 = -r1532289;
        double r1532291 = -3.2287882184845622e-164;
        bool r1532292 = r1532281 <= r1532291;
        double r1532293 = im;
        double r1532294 = r1532293 * r1532293;
        double r1532295 = r1532281 * r1532281;
        double r1532296 = r1532294 + r1532295;
        double r1532297 = sqrt(r1532296);
        double r1532298 = log(r1532297);
        double r1532299 = r1532298 / r1532288;
        double r1532300 = log(r1532293);
        double r1532301 = r1532300 / r1532288;
        double r1532302 = r1532292 ? r1532299 : r1532301;
        double r1532303 = r1532283 ? r1532290 : r1532302;
        return r1532303;
}

\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}
\begin{array}{l}
\mathbf{if}\;re \le -2.881017364964909 \cdot 10^{+137}:\\
\;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\

\mathbf{elif}\;re \le -3.2287882184845622 \cdot 10^{-164}:\\
\;\;\;\;\frac{\log \left(\sqrt{im \cdot im + re \cdot re}\right)}{\log base}\\

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

\end{array}

Error

Bits error versus re

Bits error versus im

Bits error versus base

Derivation

  1. Split input into 3 regimes
  2. if re < -2.881017364964909e+137

    1. Initial program 57.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. Simplified57.6

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base}}\]
    3. Taylor expanded around -inf 62.8

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

      \[\leadsto \color{blue}{-\frac{\log \left(\frac{-1}{re}\right)}{\log base}}\]
    5. Taylor expanded around -inf 7.0

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

    if -2.881017364964909e+137 < re < -3.2287882184845622e-164

    1. Initial program 16.1

      \[\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. Simplified16.1

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base}}\]
    3. Using strategy rm
    4. Applied times-frac16.0

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

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

    if -3.2287882184845622e-164 < re

    1. Initial program 30.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. Simplified30.6

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\log base \cdot \log base}}\]
    3. Taylor expanded around 0 32.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -2.881017364964909 \cdot 10^{+137}:\\ \;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;re \le -3.2287882184845622 \cdot 10^{-164}:\\ \;\;\;\;\frac{\log \left(\sqrt{im \cdot im + re \cdot re}\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array}\]

Reproduce

herbie shell --seed 2019101 
(FPCore (re im base)
  :name "math.log/2 on complex, real part"
  (/ (+ (* (log (sqrt (+ (* re re) (* im im)))) (log base)) (* (atan2 im re) 0)) (+ (* (log base) (log base)) (* 0 0))))