?

Average Error: 31.8 → 7.4
Time: 16.3s
Precision: binary64
Cost: 26312

?

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

\mathbf{elif}\;im \leq 4.2 \cdot 10^{+107}:\\
\;\;\;\;\frac{1}{\frac{1}{\log \left(\sqrt{re \cdot re + im \cdot im}\right)} \cdot \log base}\\

\mathbf{else}:\\
\;\;\;\;\frac{\log im}{\log base \cdot \log base} \cdot \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 < 3.89999999999999987e-99

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

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

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

      rational.json-simplify-14 [=>]30.4

      \[ \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.json-simplify-4 [=>]30.4

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

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

      rational.json-simplify-4 [=>]30.4

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

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

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

      [Start]7.9

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

      rational.json-simplify-2 [=>]7.9

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

      rational.json-simplify-9 [=>]7.9

      \[ \frac{\log \color{blue}{\left(-re\right)} \cdot \log base}{\log base \cdot \log base} \]
    5. Applied egg-rr7.9

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

    if 3.89999999999999987e-99 < im < 4.1999999999999999e107

    1. Initial program 9.8

      \[\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. Simplified9.7

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

      [Start]9.8

      \[ \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.json-simplify-14 [=>]9.8

      \[ \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.json-simplify-4 [=>]9.8

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

      rational.json-simplify-2 [=>]9.8

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

      metadata-eval [=>]9.8

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

      rational.json-simplify-4 [=>]9.8

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

      rational.json-simplify-49 [=>]9.8

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

      rational.json-simplify-46 [=>]9.7

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

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

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

    if 4.1999999999999999e107 < im

    1. Initial program 52.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. Simplified52.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]52.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.json-simplify-14 [=>]52.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.json-simplify-4 [=>]52.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 [=>]52.3

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

      rational.json-simplify-4 [=>]52.3

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

      \[\leadsto \frac{\log \color{blue}{im} \cdot \log base}{\log base \cdot \log base} \]
    4. Applied egg-rr4.6

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 3.9 \cdot 10^{-99}:\\ \;\;\;\;\frac{1}{\log base} \cdot \log \left(-re\right)\\ \mathbf{elif}\;im \leq 4.2 \cdot 10^{+107}:\\ \;\;\;\;\frac{1}{\frac{1}{\log \left(\sqrt{re \cdot re + im \cdot im}\right)} \cdot \log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base \cdot \log base} \cdot \log base\\ \end{array} \]

Alternatives

Alternative 1
Error7.3
Cost20296
\[\begin{array}{l} \mathbf{if}\;im \leq 6.2 \cdot 10^{-100}:\\ \;\;\;\;\frac{1}{\log base} \cdot \log \left(-re\right)\\ \mathbf{elif}\;im \leq 8 \cdot 10^{+89}:\\ \;\;\;\;\frac{1}{\frac{1}{\log \left(\sqrt{re \cdot re + im \cdot im}\right)} \cdot \log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array} \]
Alternative 2
Error7.3
Cost20040
\[\begin{array}{l} \mathbf{if}\;im \leq 6 \cdot 10^{-100}:\\ \;\;\;\;\frac{1}{\log base} \cdot \log \left(-re\right)\\ \mathbf{elif}\;im \leq 6.8 \cdot 10^{+81}:\\ \;\;\;\;\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array} \]
Alternative 3
Error9.7
Cost13188
\[\begin{array}{l} \mathbf{if}\;im \leq 1.55 \cdot 10^{-60}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array} \]
Alternative 4
Error30.4
Cost12992
\[\frac{\log im}{\log base} \]

Error

Reproduce?

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