Average Error: 30.6 → 16.6
Time: 58.0s
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.1445595143448033 \cdot 10^{+98}:\\ \;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;re \le -3.146303720846409 \cdot 10^{-200}:\\ \;\;\;\;\left(\log \left(\sqrt{im \cdot im + re \cdot re}\right) \cdot \log base\right) \cdot \frac{1}{\log base \cdot \log base}\\ \mathbf{elif}\;re \le -6.6938203042161946 \cdot 10^{-217}:\\ \;\;\;\;\frac{\log im \cdot \log base}{\log base \cdot \log base}\\ \mathbf{else}:\\ \;\;\;\;\left(\log \left(\sqrt{im \cdot im + re \cdot re}\right) \cdot \log base\right) \cdot \frac{1}{\log base \cdot \log base}\\ \end{array}\]
\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.1445595143448033 \cdot 10^{+98}:\\
\;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\

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

\mathbf{elif}\;re \le -6.6938203042161946 \cdot 10^{-217}:\\
\;\;\;\;\frac{\log im \cdot \log base}{\log base \cdot \log base}\\

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

\end{array}
double f(double re, double im, double base) {
        double r1520782 = re;
        double r1520783 = r1520782 * r1520782;
        double r1520784 = im;
        double r1520785 = r1520784 * r1520784;
        double r1520786 = r1520783 + r1520785;
        double r1520787 = sqrt(r1520786);
        double r1520788 = log(r1520787);
        double r1520789 = base;
        double r1520790 = log(r1520789);
        double r1520791 = r1520788 * r1520790;
        double r1520792 = atan2(r1520784, r1520782);
        double r1520793 = 0.0;
        double r1520794 = r1520792 * r1520793;
        double r1520795 = r1520791 + r1520794;
        double r1520796 = r1520790 * r1520790;
        double r1520797 = r1520793 * r1520793;
        double r1520798 = r1520796 + r1520797;
        double r1520799 = r1520795 / r1520798;
        return r1520799;
}

double f(double re, double im, double base) {
        double r1520800 = re;
        double r1520801 = -2.1445595143448033e+98;
        bool r1520802 = r1520800 <= r1520801;
        double r1520803 = -1.0;
        double r1520804 = r1520803 / r1520800;
        double r1520805 = log(r1520804);
        double r1520806 = base;
        double r1520807 = log(r1520806);
        double r1520808 = r1520805 / r1520807;
        double r1520809 = -r1520808;
        double r1520810 = -3.146303720846409e-200;
        bool r1520811 = r1520800 <= r1520810;
        double r1520812 = im;
        double r1520813 = r1520812 * r1520812;
        double r1520814 = r1520800 * r1520800;
        double r1520815 = r1520813 + r1520814;
        double r1520816 = sqrt(r1520815);
        double r1520817 = log(r1520816);
        double r1520818 = r1520817 * r1520807;
        double r1520819 = 1.0;
        double r1520820 = r1520807 * r1520807;
        double r1520821 = r1520819 / r1520820;
        double r1520822 = r1520818 * r1520821;
        double r1520823 = -6.6938203042161946e-217;
        bool r1520824 = r1520800 <= r1520823;
        double r1520825 = log(r1520812);
        double r1520826 = r1520825 * r1520807;
        double r1520827 = r1520826 / r1520820;
        double r1520828 = r1520824 ? r1520827 : r1520822;
        double r1520829 = r1520811 ? r1520822 : r1520828;
        double r1520830 = r1520802 ? r1520809 : r1520829;
        return r1520830;
}

Error

Bits error versus re

Bits error versus im

Bits error versus base

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if re < -2.1445595143448033e+98

    1. Initial program 50.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. Simplified50.0

      \[\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. Simplified8.8

      \[\leadsto \color{blue}{-\frac{\log \left(\frac{-1}{re}\right)}{\log base}}\]
    5. Using strategy rm
    6. Applied div-inv8.8

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

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

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

    if -2.1445595143448033e+98 < re < -3.146303720846409e-200 or -6.6938203042161946e-217 < re

    1. Initial program 20.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. Simplified20.2

      \[\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 div-inv20.2

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

    if -3.146303720846409e-200 < re < -6.6938203042161946e-217

    1. Initial program 27.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. Simplified27.7

      \[\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 31.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \le -2.1445595143448033 \cdot 10^{+98}:\\ \;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;re \le -3.146303720846409 \cdot 10^{-200}:\\ \;\;\;\;\left(\log \left(\sqrt{im \cdot im + re \cdot re}\right) \cdot \log base\right) \cdot \frac{1}{\log base \cdot \log base}\\ \mathbf{elif}\;re \le -6.6938203042161946 \cdot 10^{-217}:\\ \;\;\;\;\frac{\log im \cdot \log base}{\log base \cdot \log base}\\ \mathbf{else}:\\ \;\;\;\;\left(\log \left(\sqrt{im \cdot im + re \cdot re}\right) \cdot \log base\right) \cdot \frac{1}{\log base \cdot \log base}\\ \end{array}\]

Reproduce

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