Average Error: 30.6 → 12.3
Time: 1.5m
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}\;im \le -9.345057542438802 \cdot 10^{-25}:\\ \;\;\;\;\frac{\log \left(-im\right)}{\log base}\\ \mathbf{elif}\;im \le 6.493602514611967 \cdot 10^{-161}:\\ \;\;\;\;\frac{-\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;im \le 2.6563868423697512 \cdot 10^{+76}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right) \cdot \frac{1}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log \left(\frac{1}{im}\right)}{\log \left(\frac{1}{base}\right)}\\ \end{array}\]
double f(double re, double im, double base) {
        double r4038207 = re;
        double r4038208 = r4038207 * r4038207;
        double r4038209 = im;
        double r4038210 = r4038209 * r4038209;
        double r4038211 = r4038208 + r4038210;
        double r4038212 = sqrt(r4038211);
        double r4038213 = log(r4038212);
        double r4038214 = base;
        double r4038215 = log(r4038214);
        double r4038216 = r4038213 * r4038215;
        double r4038217 = atan2(r4038209, r4038207);
        double r4038218 = 0.0;
        double r4038219 = r4038217 * r4038218;
        double r4038220 = r4038216 + r4038219;
        double r4038221 = r4038215 * r4038215;
        double r4038222 = r4038218 * r4038218;
        double r4038223 = r4038221 + r4038222;
        double r4038224 = r4038220 / r4038223;
        return r4038224;
}

double f(double re, double im, double base) {
        double r4038225 = im;
        double r4038226 = -9.345057542438802e-25;
        bool r4038227 = r4038225 <= r4038226;
        double r4038228 = -r4038225;
        double r4038229 = log(r4038228);
        double r4038230 = base;
        double r4038231 = log(r4038230);
        double r4038232 = r4038229 / r4038231;
        double r4038233 = 6.493602514611967e-161;
        bool r4038234 = r4038225 <= r4038233;
        double r4038235 = -1.0;
        double r4038236 = re;
        double r4038237 = r4038235 / r4038236;
        double r4038238 = log(r4038237);
        double r4038239 = -r4038238;
        double r4038240 = r4038239 / r4038231;
        double r4038241 = 2.6563868423697512e+76;
        bool r4038242 = r4038225 <= r4038241;
        double r4038243 = r4038225 * r4038225;
        double r4038244 = r4038236 * r4038236;
        double r4038245 = r4038243 + r4038244;
        double r4038246 = sqrt(r4038245);
        double r4038247 = log(r4038246);
        double r4038248 = 1.0;
        double r4038249 = r4038248 / r4038231;
        double r4038250 = r4038247 * r4038249;
        double r4038251 = r4038248 / r4038225;
        double r4038252 = log(r4038251);
        double r4038253 = r4038248 / r4038230;
        double r4038254 = log(r4038253);
        double r4038255 = r4038252 / r4038254;
        double r4038256 = r4038242 ? r4038250 : r4038255;
        double r4038257 = r4038234 ? r4038240 : r4038256;
        double r4038258 = r4038227 ? r4038232 : r4038257;
        return r4038258;
}

\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}\;im \le -9.345057542438802 \cdot 10^{-25}:\\
\;\;\;\;\frac{\log \left(-im\right)}{\log base}\\

\mathbf{elif}\;im \le 6.493602514611967 \cdot 10^{-161}:\\
\;\;\;\;\frac{-\log \left(\frac{-1}{re}\right)}{\log base}\\

\mathbf{elif}\;im \le 2.6563868423697512 \cdot 10^{+76}:\\
\;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right) \cdot \frac{1}{\log base}\\

\mathbf{else}:\\
\;\;\;\;\frac{\log \left(\frac{1}{im}\right)}{\log \left(\frac{1}{base}\right)}\\

\end{array}

Error

Bits error versus re

Bits error versus im

Bits error versus base

Derivation

  1. Split input into 4 regimes
  2. if im < -9.345057542438802e-25

    1. Initial program 36.9

      \[\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. Simplified36.9

      \[\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 clear-num36.9

      \[\leadsto \color{blue}{\frac{1}{\frac{\log base \cdot \log base}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}}\]
    5. Using strategy rm
    6. Applied times-frac36.8

      \[\leadsto \frac{1}{\color{blue}{\frac{\log base}{\log \left(\sqrt{re \cdot re + im \cdot im}\right)} \cdot \frac{\log base}{\log base}}}\]
    7. Applied add-cube-cbrt36.8

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\frac{\log base}{\log \left(\sqrt{re \cdot re + im \cdot im}\right)} \cdot \frac{\log base}{\log base}}\]
    8. Applied times-frac36.8

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

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

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

      \[\leadsto \frac{\log \color{blue}{\left(-1 \cdot im\right)}}{\log base} \cdot 1\]
    12. Simplified14.4

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

    if -9.345057542438802e-25 < im < 6.493602514611967e-161

    1. Initial program 25.4

      \[\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. Simplified25.4

      \[\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. Simplified10.9

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

    if 6.493602514611967e-161 < im < 2.6563868423697512e+76

    1. Initial program 15.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. Simplified15.7

      \[\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 clear-num15.7

      \[\leadsto \color{blue}{\frac{1}{\frac{\log base \cdot \log base}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}}\]
    5. Using strategy rm
    6. Applied times-frac15.7

      \[\leadsto \frac{1}{\color{blue}{\frac{\log base}{\log \left(\sqrt{re \cdot re + im \cdot im}\right)} \cdot \frac{\log base}{\log base}}}\]
    7. Applied add-cube-cbrt15.7

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\frac{\log base}{\log \left(\sqrt{re \cdot re + im \cdot im}\right)} \cdot \frac{\log base}{\log base}}\]
    8. Applied times-frac15.7

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

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

      \[\leadsto \frac{\log \left(\sqrt{im \cdot im + re \cdot re}\right)}{\log base} \cdot \color{blue}{1}\]
    11. Using strategy rm
    12. Applied div-inv15.6

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

    if 2.6563868423697512e+76 < im

    1. Initial program 45.9

      \[\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. Simplified45.9

      \[\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 clear-num45.9

      \[\leadsto \color{blue}{\frac{1}{\frac{\log base \cdot \log base}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}}}\]
    5. Using strategy rm
    6. Applied times-frac45.9

      \[\leadsto \frac{1}{\color{blue}{\frac{\log base}{\log \left(\sqrt{re \cdot re + im \cdot im}\right)} \cdot \frac{\log base}{\log base}}}\]
    7. Applied add-cube-cbrt45.9

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{1} \cdot \sqrt[3]{1}\right) \cdot \sqrt[3]{1}}}{\frac{\log base}{\log \left(\sqrt{re \cdot re + im \cdot im}\right)} \cdot \frac{\log base}{\log base}}\]
    8. Applied times-frac45.9

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

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

      \[\leadsto \frac{\log \left(\sqrt{im \cdot im + re \cdot re}\right)}{\log base} \cdot \color{blue}{1}\]
    11. Using strategy rm
    12. Applied div-inv45.9

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

      \[\leadsto \color{blue}{\frac{\log \left(\frac{1}{im}\right)}{\log \left(\frac{1}{base}\right)}} \cdot 1\]
  3. Recombined 4 regimes into one program.
  4. Final simplification12.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \le -9.345057542438802 \cdot 10^{-25}:\\ \;\;\;\;\frac{\log \left(-im\right)}{\log base}\\ \mathbf{elif}\;im \le 6.493602514611967 \cdot 10^{-161}:\\ \;\;\;\;\frac{-\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;im \le 2.6563868423697512 \cdot 10^{+76}:\\ \;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right) \cdot \frac{1}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log \left(\frac{1}{im}\right)}{\log \left(\frac{1}{base}\right)}\\ \end{array}\]

Reproduce

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