?

Average Error: 32.3 → 7.1
Time: 34.6s
Precision: binary64
Cost: 20040

?

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

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

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


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

    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}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \frac{\frac{\log base}{\log base}}{\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.json-simplify-14 [=>]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.json-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} \]

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

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

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

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

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

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

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

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

      [Start]32.6

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

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

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

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

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

      [Start]5.0

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

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

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

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

      \[ \frac{\log \color{blue}{\left(-re\right)}}{\log base} \]
    7. Taylor expanded in base around inf 5.1

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

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

      [Start]5.1

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

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

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

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

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

    if 1.65e-163 < im < 1.35999999999999999e137

    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}{\log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot \frac{\frac{\log base}{\log base}}{\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} \]

      rational.json-simplify-2 [=>]11.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 [=>]11.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 [=>]11.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 [=>]11.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 [=>]11.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-rr11.6

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

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

      [Start]11.6

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

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

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

    if 1.35999999999999999e137 < im

    1. Initial program 59.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. Simplified59.6

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

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

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

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

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

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

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

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

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

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

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

Alternatives

Alternative 1
Error11.1
Cost13772
\[\begin{array}{l} \mathbf{if}\;im \leq 1.65 \cdot 10^{-163}:\\ \;\;\;\;-\frac{\log \left(-re\right)}{\log \left(\frac{1}{base}\right)}\\ \mathbf{elif}\;im \leq 1.4 \cdot 10^{-126}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \mathbf{elif}\;im \leq 3.6 \cdot 10^{-14}:\\ \;\;\;\;\frac{\frac{2}{\log base}}{\frac{-2}{\log \left(\frac{-1}{re}\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\log base} \cdot \log im\\ \end{array} \]
Alternative 2
Error11.1
Cost13708
\[\begin{array}{l} t_0 := \log \left(-re\right)\\ \mathbf{if}\;im \leq 3.9 \cdot 10^{-164}:\\ \;\;\;\;-\frac{t_0}{\log \left(\frac{1}{base}\right)}\\ \mathbf{elif}\;im \leq 1.4 \cdot 10^{-126}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \mathbf{elif}\;im \leq 5.4 \cdot 10^{-14}:\\ \;\;\;\;\frac{\frac{2}{\log base}}{\frac{2}{t_0}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\log base} \cdot \log im\\ \end{array} \]
Alternative 3
Error11.1
Cost13516
\[\begin{array}{l} t_0 := \frac{\log \left(-re\right)}{\log base}\\ \mathbf{if}\;im \leq 1.65 \cdot 10^{-163}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 1.4 \cdot 10^{-126}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \mathbf{elif}\;im \leq 5.1 \cdot 10^{-14}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\log base} \cdot \log im\\ \end{array} \]
Alternative 4
Error11.1
Cost13516
\[\begin{array}{l} t_0 := \log \left(-re\right)\\ \mathbf{if}\;im \leq 1.65 \cdot 10^{-163}:\\ \;\;\;\;-\frac{t_0}{\log \left(\frac{1}{base}\right)}\\ \mathbf{elif}\;im \leq 1.4 \cdot 10^{-126}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \mathbf{elif}\;im \leq 4 \cdot 10^{-14}:\\ \;\;\;\;\frac{t_0}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\log base} \cdot \log im\\ \end{array} \]
Alternative 5
Error11.1
Cost13452
\[\begin{array}{l} t_0 := \frac{\log im}{\log base}\\ t_1 := \frac{\log \left(-re\right)}{\log base}\\ \mathbf{if}\;im \leq 1.65 \cdot 10^{-163}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;im \leq 5.7 \cdot 10^{-126}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;im \leq 5.6 \cdot 10^{-14}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error30.9
Cost12992
\[\frac{\log im}{\log base} \]

Error

Reproduce?

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