?

Average Error: 32.3 → 7.4
Time: 16.5s
Precision: binary64
Cost: 32712

?

\[ \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 6.1 \cdot 10^{-145}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{elif}\;im \leq 4.1 \cdot 10^{+126}:\\ \;\;\;\;\frac{\log \left(\sqrt{{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 6.1e-145)
   (/ (log (- re)) (log base))
   (if (<= im 4.1e+126)
     (/ (log (sqrt (+ (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 <= 6.1e-145) {
		tmp = log(-re) / log(base);
	} else if (im <= 4.1e+126) {
		tmp = log(sqrt((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 <= 6.1d-145) then
        tmp = log(-re) / log(base)
    else if (im <= 4.1d+126) then
        tmp = log(sqrt(((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 <= 6.1e-145) {
		tmp = Math.log(-re) / Math.log(base);
	} else if (im <= 4.1e+126) {
		tmp = Math.log(Math.sqrt((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 <= 6.1e-145:
		tmp = math.log(-re) / math.log(base)
	elif im <= 4.1e+126:
		tmp = math.log(math.sqrt((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 <= 6.1e-145)
		tmp = Float64(log(Float64(-re)) / log(base));
	elseif (im <= 4.1e+126)
		tmp = Float64(log(sqrt(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 <= 6.1e-145)
		tmp = log(-re) / log(base);
	elseif (im <= 4.1e+126)
		tmp = log(sqrt(((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, 6.1e-145], N[(N[Log[(-re)], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 4.1e+126], N[(N[Log[N[Sqrt[N[(N[Power[re, 2.0], $MachinePrecision] + N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / N[Log[base], $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 6.1 \cdot 10^{-145}:\\
\;\;\;\;\frac{\log \left(-re\right)}{\log base}\\

\mathbf{elif}\;im \leq 4.1 \cdot 10^{+126}:\\
\;\;\;\;\frac{\log \left(\sqrt{{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 < 6.1e-145

    1. Initial program 32.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. Simplified32.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]32.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_best_oopsla_all_46_json_45_simplify-38 [=>]32.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_best_oopsla_all_46_json_45_simplify-85 [=>]32.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 [=>]32.4

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

      rational_best_oopsla_all_46_json_45_simplify-85 [=>]32.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 base around 0 32.4

      \[\leadsto \color{blue}{\frac{\log \left(\sqrt{{re}^{2} + {im}^{2}}\right)}{\log base}} \]
    4. Taylor expanded in re around -inf 6.0

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

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

      [Start]6.0

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]6.0

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

      rational_best_oopsla_all_46_json_45_simplify-92 [=>]6.0

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

    if 6.1e-145 < im < 4.1000000000000001e126

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

      \[\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.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_best_oopsla_all_46_json_45_simplify-38 [=>]11.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_best_oopsla_all_46_json_45_simplify-85 [=>]11.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} \]

      metadata-eval [=>]11.8

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

      rational_best_oopsla_all_46_json_45_simplify-85 [=>]11.8

      \[ \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 base around 0 11.7

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

    if 4.1000000000000001e126 < im

    1. Initial program 56.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. Simplified56.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]56.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_oopsla_all_46_json_45_simplify-38 [=>]56.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_oopsla_all_46_json_45_simplify-85 [=>]56.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 [=>]56.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_oopsla_all_46_json_45_simplify-85 [=>]56.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 \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 6.1 \cdot 10^{-145}:\\ \;\;\;\;\frac{\log \left(-re\right)}{\log base}\\ \mathbf{elif}\;im \leq 4.1 \cdot 10^{+126}:\\ \;\;\;\;\frac{\log \left(\sqrt{{re}^{2} + {im}^{2}}\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log im}{\log base}\\ \end{array} \]

Alternatives

Alternative 1
Error11.6
Cost26776
\[\begin{array}{l} t_0 := \frac{\log \left(-re\right)}{\log base}\\ t_1 := \frac{\log im}{\log base}\\ \mathbf{if}\;re \leq -4.8 \cdot 10^{-17}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq -1.65 \cdot 10^{-33}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;re \leq -3.9 \cdot 10^{-88}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq -3.7 \cdot 10^{-116}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;re \leq -2.15 \cdot 10^{-161}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq -1.6 \cdot 10^{-173}:\\ \;\;\;\;\frac{\log im \cdot \log base}{{\log base}^{2}}\\ \mathbf{elif}\;re \leq -8.5 \cdot 10^{-212}:\\ \;\;\;\;\frac{\log \left(-0.5 \cdot \frac{{im}^{2}}{re} - re\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error11.6
Cost20764
\[\begin{array}{l} t_0 := \frac{\log \left(-re\right)}{\log base}\\ t_1 := \frac{\log im}{\log base}\\ \mathbf{if}\;re \leq -1.3 \cdot 10^{-17}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq -3.2 \cdot 10^{-33}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;re \leq -1.9 \cdot 10^{-89}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq -4.4 \cdot 10^{-116}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;re \leq -2.15 \cdot 10^{-161}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq -1.6 \cdot 10^{-173}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;re \leq -8.5 \cdot 10^{-212}:\\ \;\;\;\;\frac{\log \left(-0.5 \cdot \frac{{im}^{2}}{re} - re\right)}{\log base}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error11.6
Cost13980
\[\begin{array}{l} t_0 := \frac{\log \left(-re\right)}{\log base}\\ t_1 := \frac{\log im}{\log base}\\ \mathbf{if}\;re \leq -2.6 \cdot 10^{-17}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq -5.5 \cdot 10^{-33}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;re \leq -3.2 \cdot 10^{-88}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq -4 \cdot 10^{-116}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;re \leq -2.15 \cdot 10^{-161}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;re \leq -1.7 \cdot 10^{-173}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;re \leq -8.5 \cdot 10^{-212}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error31.0
Cost12992
\[\frac{\log im}{\log base} \]

Error

Reproduce?

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