
(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 5 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}
re_m = (fabs.f64 re) NOTE: re_m, im, and base should be sorted in increasing order before calling this function. (FPCore (re_m im base) :precision binary64 (/ (* (log (hypot (exp (log im)) re_m)) (log base)) (pow (log base) 2.0)))
re_m = fabs(re);
assert(re_m < im && im < base);
double code(double re_m, double im, double base) {
return (log(hypot(exp(log(im)), re_m)) * log(base)) / pow(log(base), 2.0);
}
re_m = Math.abs(re);
assert re_m < im && im < base;
public static double code(double re_m, double im, double base) {
return (Math.log(Math.hypot(Math.exp(Math.log(im)), re_m)) * Math.log(base)) / Math.pow(Math.log(base), 2.0);
}
re_m = math.fabs(re) [re_m, im, base] = sort([re_m, im, base]) def code(re_m, im, base): return (math.log(math.hypot(math.exp(math.log(im)), re_m)) * math.log(base)) / math.pow(math.log(base), 2.0)
re_m = abs(re) re_m, im, base = sort([re_m, im, base]) function code(re_m, im, base) return Float64(Float64(log(hypot(exp(log(im)), re_m)) * log(base)) / (log(base) ^ 2.0)) end
re_m = abs(re);
re_m, im, base = num2cell(sort([re_m, im, base])){:}
function tmp = code(re_m, im, base)
tmp = (log(hypot(exp(log(im)), re_m)) * log(base)) / (log(base) ^ 2.0);
end
re_m = N[Abs[re], $MachinePrecision] NOTE: re_m, im, and base should be sorted in increasing order before calling this function. code[re$95$m_, im_, base_] := N[(N[(N[Log[N[Sqrt[N[Exp[N[Log[im], $MachinePrecision]], $MachinePrecision] ^ 2 + re$95$m ^ 2], $MachinePrecision]], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] / N[Power[N[Log[base], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
re_m = \left|re\right|
\\
[re_m, im, base] = \mathsf{sort}([re_m, im, base])\\
\\
\frac{\log \left(\mathsf{hypot}\left(e^{\log im}, re\_m\right)\right) \cdot \log base}{{\log base}^{2}}
\end{array}
Initial program 55.6%
+-commutativeN/A
pow2N/A
pow-to-expN/A
exp-lft-sqrN/A
accelerator-lowering-hypot.f64N/A
exp-lowering-exp.f64N/A
log-lowering-log.f6446.1
Applied egg-rr46.1%
mul0-rgt46.1
Applied egg-rr46.1%
metadata-eval46.1
Applied egg-rr46.1%
pow2N/A
pow-lowering-pow.f64N/A
log-lowering-log.f6446.1
Applied egg-rr46.1%
Final simplification46.1%
re_m = (fabs.f64 re) NOTE: re_m, im, and base should be sorted in increasing order before calling this function. (FPCore (re_m im base) :precision binary64 (/ (* (log base) (log (hypot im re_m))) (* (log base) (log base))))
re_m = fabs(re);
assert(re_m < im && im < base);
double code(double re_m, double im, double base) {
return (log(base) * log(hypot(im, re_m))) / (log(base) * log(base));
}
re_m = Math.abs(re);
assert re_m < im && im < base;
public static double code(double re_m, double im, double base) {
return (Math.log(base) * Math.log(Math.hypot(im, re_m))) / (Math.log(base) * Math.log(base));
}
re_m = math.fabs(re) [re_m, im, base] = sort([re_m, im, base]) def code(re_m, im, base): return (math.log(base) * math.log(math.hypot(im, re_m))) / (math.log(base) * math.log(base))
re_m = abs(re) re_m, im, base = sort([re_m, im, base]) function code(re_m, im, base) return Float64(Float64(log(base) * log(hypot(im, re_m))) / Float64(log(base) * log(base))) end
re_m = abs(re);
re_m, im, base = num2cell(sort([re_m, im, base])){:}
function tmp = code(re_m, im, base)
tmp = (log(base) * log(hypot(im, re_m))) / (log(base) * log(base));
end
re_m = N[Abs[re], $MachinePrecision] NOTE: re_m, im, and base should be sorted in increasing order before calling this function. code[re$95$m_, im_, base_] := N[(N[(N[Log[base], $MachinePrecision] * N[Log[N[Sqrt[im ^ 2 + re$95$m ^ 2], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(N[Log[base], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
re_m = \left|re\right|
\\
[re_m, im, base] = \mathsf{sort}([re_m, im, base])\\
\\
\frac{\log base \cdot \log \left(\mathsf{hypot}\left(im, re\_m\right)\right)}{\log base \cdot \log base}
\end{array}
Initial program 55.6%
+-commutativeN/A
pow2N/A
pow-to-expN/A
exp-lft-sqrN/A
accelerator-lowering-hypot.f64N/A
exp-lowering-exp.f64N/A
log-lowering-log.f6446.1
Applied egg-rr46.1%
mul0-rgt46.1
Applied egg-rr46.1%
metadata-eval46.1
Applied egg-rr46.1%
rem-exp-log99.2
Applied egg-rr99.2%
Final simplification99.2%
re_m = (fabs.f64 re) NOTE: re_m, im, and base should be sorted in increasing order before calling this function. (FPCore (re_m im base) :precision binary64 (/ (* (log base) (log (fma re_m (/ (* re_m 0.5) im) im))) (* (log base) (log base))))
re_m = fabs(re);
assert(re_m < im && im < base);
double code(double re_m, double im, double base) {
return (log(base) * log(fma(re_m, ((re_m * 0.5) / im), im))) / (log(base) * log(base));
}
re_m = abs(re) re_m, im, base = sort([re_m, im, base]) function code(re_m, im, base) return Float64(Float64(log(base) * log(fma(re_m, Float64(Float64(re_m * 0.5) / im), im))) / Float64(log(base) * log(base))) end
re_m = N[Abs[re], $MachinePrecision] NOTE: re_m, im, and base should be sorted in increasing order before calling this function. code[re$95$m_, im_, base_] := N[(N[(N[Log[base], $MachinePrecision] * N[Log[N[(re$95$m * N[(N[(re$95$m * 0.5), $MachinePrecision] / im), $MachinePrecision] + im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(N[Log[base], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
re_m = \left|re\right|
\\
[re_m, im, base] = \mathsf{sort}([re_m, im, base])\\
\\
\frac{\log base \cdot \log \left(\mathsf{fma}\left(re\_m, \frac{re\_m \cdot 0.5}{im}, im\right)\right)}{\log base \cdot \log base}
\end{array}
Initial program 55.6%
+-commutativeN/A
pow2N/A
pow-to-expN/A
exp-lft-sqrN/A
accelerator-lowering-hypot.f64N/A
exp-lowering-exp.f64N/A
log-lowering-log.f6446.1
Applied egg-rr46.1%
mul0-rgt46.1
Applied egg-rr46.1%
metadata-eval46.1
Applied egg-rr46.1%
Taylor expanded in re around 0
+-commutativeN/A
*-commutativeN/A
associate-*l/N/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
unpow2N/A
associate-*l*N/A
accelerator-lowering-fma.f64N/A
associate-*r/N/A
metadata-evalN/A
associate-*r/N/A
/-lowering-/.f64N/A
*-lowering-*.f6423.5
Simplified23.5%
Final simplification23.5%
re_m = (fabs.f64 re) NOTE: re_m, im, and base should be sorted in increasing order before calling this function. (FPCore (re_m im base) :precision binary64 (/ (log im) (log base)))
re_m = fabs(re);
assert(re_m < im && im < base);
double code(double re_m, double im, double base) {
return log(im) / log(base);
}
re_m = abs(re)
NOTE: re_m, im, and base should be sorted in increasing order before calling this function.
real(8) function code(re_m, im, base)
real(8), intent (in) :: re_m
real(8), intent (in) :: im
real(8), intent (in) :: base
code = log(im) / log(base)
end function
re_m = Math.abs(re);
assert re_m < im && im < base;
public static double code(double re_m, double im, double base) {
return Math.log(im) / Math.log(base);
}
re_m = math.fabs(re) [re_m, im, base] = sort([re_m, im, base]) def code(re_m, im, base): return math.log(im) / math.log(base)
re_m = abs(re) re_m, im, base = sort([re_m, im, base]) function code(re_m, im, base) return Float64(log(im) / log(base)) end
re_m = abs(re);
re_m, im, base = num2cell(sort([re_m, im, base])){:}
function tmp = code(re_m, im, base)
tmp = log(im) / log(base);
end
re_m = N[Abs[re], $MachinePrecision] NOTE: re_m, im, and base should be sorted in increasing order before calling this function. code[re$95$m_, im_, base_] := N[(N[Log[im], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
re_m = \left|re\right|
\\
[re_m, im, base] = \mathsf{sort}([re_m, im, base])\\
\\
\frac{\log im}{\log base}
\end{array}
Initial program 55.6%
Taylor expanded in re around 0
/-lowering-/.f64N/A
log-lowering-log.f64N/A
log-lowering-log.f6424.3
Simplified24.3%
re_m = (fabs.f64 re) NOTE: re_m, im, and base should be sorted in increasing order before calling this function. (FPCore (re_m im base) :precision binary64 0.0)
re_m = fabs(re);
assert(re_m < im && im < base);
double code(double re_m, double im, double base) {
return 0.0;
}
re_m = abs(re)
NOTE: re_m, im, and base should be sorted in increasing order before calling this function.
real(8) function code(re_m, im, base)
real(8), intent (in) :: re_m
real(8), intent (in) :: im
real(8), intent (in) :: base
code = 0.0d0
end function
re_m = Math.abs(re);
assert re_m < im && im < base;
public static double code(double re_m, double im, double base) {
return 0.0;
}
re_m = math.fabs(re) [re_m, im, base] = sort([re_m, im, base]) def code(re_m, im, base): return 0.0
re_m = abs(re) re_m, im, base = sort([re_m, im, base]) function code(re_m, im, base) return 0.0 end
re_m = abs(re);
re_m, im, base = num2cell(sort([re_m, im, base])){:}
function tmp = code(re_m, im, base)
tmp = 0.0;
end
re_m = N[Abs[re], $MachinePrecision] NOTE: re_m, im, and base should be sorted in increasing order before calling this function. code[re$95$m_, im_, base_] := 0.0
\begin{array}{l}
re_m = \left|re\right|
\\
[re_m, im, base] = \mathsf{sort}([re_m, im, base])\\
\\
0
\end{array}
Initial program 55.6%
Taylor expanded in re around 0
/-lowering-/.f64N/A
log-lowering-log.f64N/A
log-lowering-log.f6424.3
Simplified24.3%
Applied egg-rr3.1%
herbie shell --seed 2024199
(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))))