?

Average Error: 32.0 → 7.0
Time: 1.0min
Precision: binary64
Cost: 13768

?

\[ \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}\;re \leq -1.22 \cdot 10^{+148}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{elif}\;re \leq -1.95 \cdot 10^{-136}:\\ \;\;\;\;\frac{\log \left(re \cdot re + im \cdot im\right)}{\log base} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;-\frac{\log \left(\frac{1}{im}\right)}{\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 (<= re -1.22e+148)
   (/ (log (- re)) (log base))
   (if (<= re -1.95e-136)
     (* (/ (log (+ (* re re) (* im im))) (log base)) 0.5)
     (- (/ (log (/ 1.0 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 (re <= -1.22e+148) {
		tmp = log(-re) / log(base);
	} else if (re <= -1.95e-136) {
		tmp = (log(((re * re) + (im * im))) / log(base)) * 0.5;
	} else {
		tmp = -(log((1.0 / 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 (re <= (-1.22d+148)) then
        tmp = log(-re) / log(base)
    else if (re <= (-1.95d-136)) then
        tmp = (log(((re * re) + (im * im))) / log(base)) * 0.5d0
    else
        tmp = -(log((1.0d0 / 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 (re <= -1.22e+148) {
		tmp = Math.log(-re) / Math.log(base);
	} else if (re <= -1.95e-136) {
		tmp = (Math.log(((re * re) + (im * im))) / Math.log(base)) * 0.5;
	} else {
		tmp = -(Math.log((1.0 / 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 re <= -1.22e+148:
		tmp = math.log(-re) / math.log(base)
	elif re <= -1.95e-136:
		tmp = (math.log(((re * re) + (im * im))) / math.log(base)) * 0.5
	else:
		tmp = -(math.log((1.0 / 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 (re <= -1.22e+148)
		tmp = Float64(log(Float64(-re)) / log(base));
	elseif (re <= -1.95e-136)
		tmp = Float64(Float64(log(Float64(Float64(re * re) + Float64(im * im))) / log(base)) * 0.5);
	else
		tmp = Float64(-Float64(log(Float64(1.0 / 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 (re <= -1.22e+148)
		tmp = log(-re) / log(base);
	elseif (re <= -1.95e-136)
		tmp = (log(((re * re) + (im * im))) / log(base)) * 0.5;
	else
		tmp = -(log((1.0 / 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[re, -1.22e+148], N[(N[Log[(-re)], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -1.95e-136], N[(N[(N[Log[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], (-N[(N[Log[N[(1.0 / im), $MachinePrecision]], $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}\;re \leq -1.22 \cdot 10^{+148}:\\
\;\;\;\;\frac{\log \left(-re\right)}{\log base}\\

\mathbf{elif}\;re \leq -1.95 \cdot 10^{-136}:\\
\;\;\;\;\frac{\log \left(re \cdot re + im \cdot im\right)}{\log base} \cdot 0.5\\

\mathbf{else}:\\
\;\;\;\;-\frac{\log \left(\frac{1}{im}\right)}{\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 re < -1.22000000000000007e148

    1. Initial program 61.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. Simplified61.9

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

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

      rational_best-simplify-65 [=>]61.9

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

      rational_best-simplify-17 [=>]61.9

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

      rational_best-simplify-5 [=>]61.9

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

      rational_best-simplify-64 [=>]61.9

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

      trig-simplify-13 [=>]61.9

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

      rational_best-simplify-6 [=>]61.9

      \[ \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 [=>]61.9

      \[ \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-3 [=>]61.9

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

      rational_best-simplify-6 [=>]61.9

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

      rational_best-simplify-90 [=>]61.9

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

      rational_best-simplify-64 [=>]61.9

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

      rational_best-simplify-3 [=>]61.9

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

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

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

      [Start]3.7

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

      rational_best-simplify-1 [=>]3.7

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

      rational_best-simplify-11 [<=]3.7

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

    if -1.22000000000000007e148 < re < -1.94999999999999988e-136

    1. Initial program 10.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. Simplified10.8

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

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

      rational_best-simplify-65 [=>]10.9

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

      rational_best-simplify-17 [=>]10.9

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

      rational_best-simplify-5 [=>]10.9

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

      rational_best-simplify-64 [=>]10.9

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

      trig-simplify-13 [=>]10.9

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

      rational_best-simplify-6 [=>]10.9

      \[ \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 [=>]10.9

      \[ \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-3 [=>]10.9

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

      rational_best-simplify-6 [=>]10.9

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

      rational_best-simplify-90 [=>]10.8

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

      rational_best-simplify-64 [=>]10.8

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

      rational_best-simplify-3 [=>]10.8

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

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

    if -1.94999999999999988e-136 < re

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

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

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

      rational_best-simplify-65 [=>]30.9

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

      rational_best-simplify-17 [=>]30.9

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

      rational_best-simplify-5 [=>]30.9

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

      rational_best-simplify-64 [=>]30.9

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

      trig-simplify-13 [=>]30.9

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

      rational_best-simplify-6 [=>]30.9

      \[ \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 [=>]30.9

      \[ \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-3 [=>]30.9

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

      rational_best-simplify-6 [=>]30.9

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

      rational_best-simplify-90 [=>]30.9

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

      rational_best-simplify-64 [=>]30.9

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

      rational_best-simplify-3 [=>]30.9

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

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

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

      [Start]5.9

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

      rational_best-simplify-1 [=>]5.9

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

      rational_best-simplify-10 [=>]5.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;re \leq -1.22 \cdot 10^{+148}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{elif}\;re \leq -1.95 \cdot 10^{-136}:\\ \;\;\;\;\frac{\log \left(re \cdot re + im \cdot im\right)}{\log base} \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;-\frac{\log \left(\frac{1}{im}\right)}{\log base}\\ \end{array} \]

Alternatives

Alternative 1
Error6.9
Cost13768
\[\begin{array}{l} \mathbf{if}\;re \leq -1.3 \cdot 10^{+148}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{elif}\;re \leq -3.5 \cdot 10^{-141}:\\ \;\;\;\;\frac{0.5}{\log base} \cdot \log \left(re \cdot re + im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;-\frac{\log \left(\frac{1}{im}\right)}{\log base}\\ \end{array} \]
Alternative 2
Error9.8
Cost13316
\[\begin{array}{l} \mathbf{if}\;re \leq -7.8 \cdot 10^{-41}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;-\frac{\log \left(\frac{1}{im}\right)}{\log base}\\ \end{array} \]
Alternative 3
Error9.8
Cost13188
\[\begin{array}{l} \mathbf{if}\;re \leq -7.8 \cdot 10^{-41}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array} \]
Alternative 4
Error31.2
Cost12992
\[\frac{\log im}{\log base} \]

Error

Reproduce?

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