?

Average Error: 31.9 → 7.0
Time: 33.3s
Precision: binary64
Cost: 19848

?

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

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

\mathbf{else}:\\
\;\;\;\;\log \left({im}^{\left(\frac{0.5}{\log base}\right)}\right) \cdot 2\\


\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 < 9.50000000000000012e-163

    1. Initial program 32.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. Simplified32.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]32.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} \]

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

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

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

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

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

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

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

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

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

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

      [Start]4.8

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

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

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

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

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

    if 9.50000000000000012e-163 < im < 3e103

    1. Initial program 11.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. Simplified11.7

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

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

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

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

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

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

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

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

      [Start]12.1

      \[ \log \left({\left({\left(re \cdot re + im \cdot im\right)}^{0.5}\right)}^{\left(\frac{1}{\log base}\right)}\right) \]

      exponential.json-simplify-32 [=>]12.1

      \[ \log \color{blue}{\left({\left(re \cdot re + im \cdot im\right)}^{\left(0.5 \cdot \frac{1}{\log base}\right)}\right)} \]
    5. Applied egg-rr11.6

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

    if 3e103 < im

    1. Initial program 52.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. Simplified52.0

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

      [Start]52.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.json-simplify-14 [=>]52.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.json-simplify-4 [=>]52.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} \]

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\log im}{\log base}} \]
    4. Applied egg-rr5.1

      \[\leadsto \color{blue}{\log \left({im}^{\left(\frac{0.5}{\log base}\right)}\right) \cdot 2} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification7.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;im \leq 9.5 \cdot 10^{-163}:\\ \;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;im \leq 3 \cdot 10^{+103}:\\ \;\;\;\;\frac{\log \left(re \cdot re + im \cdot im\right)}{\log base \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\log \left({im}^{\left(\frac{0.5}{\log base}\right)}\right) \cdot 2\\ \end{array} \]

Alternatives

Alternative 1
Error7.0
Cost19720
\[\begin{array}{l} \mathbf{if}\;im \leq 3 \cdot 10^{-161}:\\ \;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;im \leq 1.4 \cdot 10^{+103}:\\ \;\;\;\;\frac{\log \left(re \cdot re + im \cdot im\right)}{\log base \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\log \left({im}^{\left(\frac{1}{\log base}\right)}\right)\\ \end{array} \]
Alternative 2
Error7.1
Cost13768
\[\begin{array}{l} \mathbf{if}\;im \leq 1.2 \cdot 10^{-149}:\\ \;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;im \leq 1.5 \cdot 10^{+95}:\\ \;\;\;\;\frac{0.5}{\log base} \cdot \log \left(re \cdot re + im \cdot im\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array} \]
Alternative 3
Error7.0
Cost13768
\[\begin{array}{l} \mathbf{if}\;im \leq 1.75 \cdot 10^{-162}:\\ \;\;\;\;-\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{elif}\;im \leq 3.05 \cdot 10^{+94}:\\ \;\;\;\;\frac{\log \left(re \cdot re + im \cdot im\right)}{\log base \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array} \]
Alternative 4
Error10.2
Cost13580
\[\begin{array}{l} t_0 := \frac{\log im}{\log base}\\ t_1 := -\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{if}\;im \leq 5 \cdot 10^{-148}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 4 \cdot 10^{-136}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 1.55 \cdot 10^{-94}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error10.2
Cost13580
\[\begin{array}{l} t_0 := -\frac{\log \left(\frac{-1}{re}\right)}{\log base}\\ \mathbf{if}\;im \leq 5 \cdot 10^{-148}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 4 \cdot 10^{-136}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \mathbf{elif}\;im \leq 1.5 \cdot 10^{-94}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;-\frac{\log \left(\frac{1}{im}\right)}{\log base}\\ \end{array} \]
Alternative 6
Error30.5
Cost12992
\[\frac{\log im}{\log base} \]

Error

Reproduce?

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