?

Average Error: 32.7 → 7.4
Time: 18.0s
Precision: binary64
Cost: 26440

?

\[ \begin{array}{c}[re, im] = \mathsf{sort}([re, im])\\ \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}\;im \leq 4 \cdot 10^{-133}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{elif}\;im \leq 3.3 \cdot 10^{+83}:\\ \;\;\;\;0.5 \cdot \frac{\log \left({re}^{2} + {im}^{2}\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \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))))
(FPCore (re im base)
 :precision binary64
 (if (<= im 4e-133)
   (/ (log (- re)) (log base))
   (if (<= im 3.3e+83)
     (* 0.5 (/ (log (+ (pow re 2.0) (pow im 2.0))) (log base)))
     (/ (log im) (log base)))))
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));
}
double code(double re, double im, double base) {
	double tmp;
	if (im <= 4e-133) {
		tmp = log(-re) / log(base);
	} else if (im <= 3.3e+83) {
		tmp = 0.5 * (log((pow(re, 2.0) + pow(im, 2.0))) / log(base));
	} else {
		tmp = log(im) / log(base);
	}
	return tmp;
}
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
real(8) function code(re, im, base)
    real(8), intent (in) :: re
    real(8), intent (in) :: im
    real(8), intent (in) :: base
    real(8) :: tmp
    if (im <= 4d-133) then
        tmp = log(-re) / log(base)
    else if (im <= 3.3d+83) then
        tmp = 0.5d0 * (log(((re ** 2.0d0) + (im ** 2.0d0))) / log(base))
    else
        tmp = log(im) / log(base)
    end if
    code = tmp
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));
}
public static double code(double re, double im, double base) {
	double tmp;
	if (im <= 4e-133) {
		tmp = Math.log(-re) / Math.log(base);
	} else if (im <= 3.3e+83) {
		tmp = 0.5 * (Math.log((Math.pow(re, 2.0) + Math.pow(im, 2.0))) / Math.log(base));
	} else {
		tmp = Math.log(im) / Math.log(base);
	}
	return tmp;
}
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))
def code(re, im, base):
	tmp = 0
	if im <= 4e-133:
		tmp = math.log(-re) / math.log(base)
	elif im <= 3.3e+83:
		tmp = 0.5 * (math.log((math.pow(re, 2.0) + math.pow(im, 2.0))) / math.log(base))
	else:
		tmp = math.log(im) / math.log(base)
	return tmp
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 code(re, im, base)
	tmp = 0.0
	if (im <= 4e-133)
		tmp = Float64(log(Float64(-re)) / log(base));
	elseif (im <= 3.3e+83)
		tmp = Float64(0.5 * Float64(log(Float64((re ^ 2.0) + (im ^ 2.0))) / log(base)));
	else
		tmp = Float64(log(im) / log(base));
	end
	return tmp
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
function tmp_2 = code(re, im, base)
	tmp = 0.0;
	if (im <= 4e-133)
		tmp = log(-re) / log(base);
	elseif (im <= 3.3e+83)
		tmp = 0.5 * (log(((re ^ 2.0) + (im ^ 2.0))) / log(base));
	else
		tmp = log(im) / log(base);
	end
	tmp_2 = tmp;
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]
code[re_, im_, base_] := If[LessEqual[im, 4e-133], N[(N[Log[(-re)], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 3.3e+83], N[(0.5 * N[(N[Log[N[(N[Power[re, 2.0], $MachinePrecision] + N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Log[im], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision]]]
\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 \leq 4 \cdot 10^{-133}:\\
\;\;\;\;\frac{\log \left(-re\right)}{\log base}\\

\mathbf{elif}\;im \leq 3.3 \cdot 10^{+83}:\\
\;\;\;\;0.5 \cdot \frac{\log \left({re}^{2} + {im}^{2}\right)}{\log base}\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 3 regimes
  2. if im < 4.0000000000000003e-133

    1. Initial program 32.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. Simplified32.6

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

      [Start]32.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} \]

      rational_best-simplify-15 [=>]32.6

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

      rational_best-simplify-3 [=>]32.6

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

      rational_best-simplify-4 [=>]32.6

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

      metadata-eval [=>]32.6

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

      rational_best-simplify-4 [=>]32.6

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

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

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

      [Start]6.3

      \[ \frac{\log \left(-1 \cdot re\right) \cdot \log base}{\log base \cdot \log base} \]

      rational_best-simplify-2 [=>]6.3

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

      rational_best-simplify-12 [=>]6.3

      \[ \frac{\log \color{blue}{\left(-re\right)} \cdot \log base}{\log base \cdot \log base} \]
    5. Taylor expanded in base around 0 6.2

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

    if 4.0000000000000003e-133 < im < 3.29999999999999985e83

    1. Initial program 11.3

      \[\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. Simplified11.3

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

      [Start]11.3

      \[ \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} \]

      rational_best-simplify-15 [=>]11.3

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

      rational_best-simplify-3 [=>]11.3

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

      rational_best-simplify-4 [=>]11.3

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

      metadata-eval [=>]11.3

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

      rational_best-simplify-4 [=>]11.3

      \[ \frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \log base}{\color{blue}{\log base \cdot \log base}} \]
    3. Applied egg-rr11.3

      \[\leadsto \frac{\color{blue}{\frac{\log base \cdot \log \left(re \cdot re + im \cdot im\right)}{2}}}{\log base \cdot \log base} \]
    4. Taylor expanded in base around 0 11.2

      \[\leadsto \color{blue}{0.5 \cdot \frac{\log \left({re}^{2} + {im}^{2}\right)}{\log base}} \]

    if 3.29999999999999985e83 < im

    1. Initial program 49.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. Simplified49.0

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

      [Start]49.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} \]

      rational_best-simplify-15 [=>]49.0

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

      rational_best-simplify-3 [=>]49.0

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

      rational_best-simplify-4 [=>]49.0

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

      metadata-eval [=>]49.0

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

      rational_best-simplify-4 [=>]49.0

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 4 \cdot 10^{-133}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{elif}\;im \leq 3.3 \cdot 10^{+83}:\\ \;\;\;\;0.5 \cdot \frac{\log \left({re}^{2} + {im}^{2}\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array} \]

Alternatives

Alternative 1
Error10.3
Cost13188
\[\begin{array}{l} \mathbf{if}\;im \leq 1.9 \cdot 10^{-132}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array} \]
Alternative 2
Error31.0
Cost12992
\[\frac{\log im}{\log base} \]

Error

Reproduce?

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