
(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))))
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));
}
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
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));
}
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))
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 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
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]
\begin{array}{l}
\\
\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}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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))))
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));
}
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
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));
}
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))
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 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
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]
\begin{array}{l}
\\
\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}
\end{array}
im_m = (fabs.f64 im) NOTE: re, im_m, and base should be sorted in increasing order before calling this function. (FPCore (re im_m base) :precision binary64 (/ (log (hypot (exp (log im_m)) re)) (log base)))
im_m = fabs(im);
assert(re < im_m && im_m < base);
double code(double re, double im_m, double base) {
return log(hypot(exp(log(im_m)), re)) / log(base);
}
im_m = Math.abs(im);
assert re < im_m && im_m < base;
public static double code(double re, double im_m, double base) {
return Math.log(Math.hypot(Math.exp(Math.log(im_m)), re)) / Math.log(base);
}
im_m = math.fabs(im) [re, im_m, base] = sort([re, im_m, base]) def code(re, im_m, base): return math.log(math.hypot(math.exp(math.log(im_m)), re)) / math.log(base)
im_m = abs(im) re, im_m, base = sort([re, im_m, base]) function code(re, im_m, base) return Float64(log(hypot(exp(log(im_m)), re)) / log(base)) end
im_m = abs(im);
re, im_m, base = num2cell(sort([re, im_m, base])){:}
function tmp = code(re, im_m, base)
tmp = log(hypot(exp(log(im_m)), re)) / log(base);
end
im_m = N[Abs[im], $MachinePrecision] NOTE: re, im_m, and base should be sorted in increasing order before calling this function. code[re_, im$95$m_, base_] := N[(N[Log[N[Sqrt[N[Exp[N[Log[im$95$m], $MachinePrecision]], $MachinePrecision] ^ 2 + re ^ 2], $MachinePrecision]], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
[re, im_m, base] = \mathsf{sort}([re, im_m, base])\\
\\
\frac{\log \left(\mathsf{hypot}\left(e^{\log im\_m}, re\right)\right)}{\log base}
\end{array}
Initial program 50.4%
Taylor expanded in base around 0
lower-/.f64N/A
lower-log.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f64N/A
lower-log.f6499.5
Applied rewrites99.5%
Applied rewrites54.8%
im_m = (fabs.f64 im) NOTE: re, im_m, and base should be sorted in increasing order before calling this function. (FPCore (re im_m base) :precision binary64 (/ (log (hypot im_m re)) (log base)))
im_m = fabs(im);
assert(re < im_m && im_m < base);
double code(double re, double im_m, double base) {
return log(hypot(im_m, re)) / log(base);
}
im_m = Math.abs(im);
assert re < im_m && im_m < base;
public static double code(double re, double im_m, double base) {
return Math.log(Math.hypot(im_m, re)) / Math.log(base);
}
im_m = math.fabs(im) [re, im_m, base] = sort([re, im_m, base]) def code(re, im_m, base): return math.log(math.hypot(im_m, re)) / math.log(base)
im_m = abs(im) re, im_m, base = sort([re, im_m, base]) function code(re, im_m, base) return Float64(log(hypot(im_m, re)) / log(base)) end
im_m = abs(im);
re, im_m, base = num2cell(sort([re, im_m, base])){:}
function tmp = code(re, im_m, base)
tmp = log(hypot(im_m, re)) / log(base);
end
im_m = N[Abs[im], $MachinePrecision] NOTE: re, im_m, and base should be sorted in increasing order before calling this function. code[re_, im$95$m_, base_] := N[(N[Log[N[Sqrt[im$95$m ^ 2 + re ^ 2], $MachinePrecision]], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
[re, im_m, base] = \mathsf{sort}([re, im_m, base])\\
\\
\frac{\log \left(\mathsf{hypot}\left(im\_m, re\right)\right)}{\log base}
\end{array}
Initial program 50.4%
Taylor expanded in base around 0
lower-/.f64N/A
lower-log.f64N/A
unpow2N/A
unpow2N/A
lower-hypot.f64N/A
lower-log.f6499.5
Applied rewrites99.5%
im_m = (fabs.f64 im) NOTE: re, im_m, and base should be sorted in increasing order before calling this function. (FPCore (re im_m base) :precision binary64 (/ (log im_m) (log base)))
im_m = fabs(im);
assert(re < im_m && im_m < base);
double code(double re, double im_m, double base) {
return log(im_m) / log(base);
}
im_m = abs(im)
NOTE: re, im_m, and base should be sorted in increasing order before calling this function.
real(8) function code(re, im_m, base)
real(8), intent (in) :: re
real(8), intent (in) :: im_m
real(8), intent (in) :: base
code = log(im_m) / log(base)
end function
im_m = Math.abs(im);
assert re < im_m && im_m < base;
public static double code(double re, double im_m, double base) {
return Math.log(im_m) / Math.log(base);
}
im_m = math.fabs(im) [re, im_m, base] = sort([re, im_m, base]) def code(re, im_m, base): return math.log(im_m) / math.log(base)
im_m = abs(im) re, im_m, base = sort([re, im_m, base]) function code(re, im_m, base) return Float64(log(im_m) / log(base)) end
im_m = abs(im);
re, im_m, base = num2cell(sort([re, im_m, base])){:}
function tmp = code(re, im_m, base)
tmp = log(im_m) / log(base);
end
im_m = N[Abs[im], $MachinePrecision] NOTE: re, im_m, and base should be sorted in increasing order before calling this function. code[re_, im$95$m_, base_] := N[(N[Log[im$95$m], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
[re, im_m, base] = \mathsf{sort}([re, im_m, base])\\
\\
\frac{\log im\_m}{\log base}
\end{array}
Initial program 50.4%
Taylor expanded in re around 0
remove-double-negN/A
log-recN/A
lower-/.f64N/A
log-recN/A
remove-double-negN/A
lower-log.f64N/A
lower-log.f6430.4
Applied rewrites30.4%
herbie shell --seed 2024329
(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))))