
(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)
use fmin_fmax_functions
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]
\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}
Herbie found 4 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)
use fmin_fmax_functions
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]
\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}
(FPCore (re im base) :precision binary64 (* (copysign 1.0 (log base)) (/ (log (hypot re im)) (fabs (log base)))))
double code(double re, double im, double base) {
return copysign(1.0, log(base)) * (log(hypot(re, im)) / fabs(log(base)));
}
public static double code(double re, double im, double base) {
return Math.copySign(1.0, Math.log(base)) * (Math.log(Math.hypot(re, im)) / Math.abs(Math.log(base)));
}
def code(re, im, base): return math.copysign(1.0, math.log(base)) * (math.log(math.hypot(re, im)) / math.fabs(math.log(base)))
function code(re, im, base) return Float64(copysign(1.0, log(base)) * Float64(log(hypot(re, im)) / abs(log(base)))) end
function tmp = code(re, im, base) tmp = (sign(log(base)) * abs(1.0)) * (log(hypot(re, im)) / abs(log(base))); end
code[re_, im_, base_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[N[Log[base], $MachinePrecision]]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[Log[N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]], $MachinePrecision] / N[Abs[N[Log[base], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\mathsf{copysign}\left(1, \log base\right) \cdot \frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{\left|\log base\right|}
Initial program 25.5%
lift-/.f64N/A
lift-+.f64N/A
lift-*.f64N/A
mul0-rgtN/A
metadata-evalN/A
sub-flip-reverseN/A
--rgt-identityN/A
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
lift-*.f64N/A
metadata-evalN/A
+-rgt-identityN/A
lift-*.f64N/A
sqr-abs-revN/A
Applied rewrites25.5%
lift-sqrt.f64N/A
lift-fma.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-hypot.f6449.9%
Applied rewrites49.9%
(FPCore (re im base) :precision binary64 (* (/ 1.0 (log base)) (log (hypot re im))))
double code(double re, double im, double base) {
return (1.0 / log(base)) * log(hypot(re, im));
}
public static double code(double re, double im, double base) {
return (1.0 / Math.log(base)) * Math.log(Math.hypot(re, im));
}
def code(re, im, base): return (1.0 / math.log(base)) * math.log(math.hypot(re, im))
function code(re, im, base) return Float64(Float64(1.0 / log(base)) * log(hypot(re, im))) end
function tmp = code(re, im, base) tmp = (1.0 / log(base)) * log(hypot(re, im)); end
code[re_, im_, base_] := N[(N[(1.0 / N[Log[base], $MachinePrecision]), $MachinePrecision] * N[Log[N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\frac{1}{\log base} \cdot \log \left(\mathsf{hypot}\left(re, im\right)\right)
Initial program 25.5%
lift-/.f64N/A
mult-flipN/A
lift-+.f64N/A
lift-*.f64N/A
mul0-rgtN/A
+-rgt-identityN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites25.5%
lift-*.f64N/A
lift-*.f64N/A
associate-*r*N/A
lift-/.f64N/A
inv-powN/A
lift-*.f64N/A
pow-prod-downN/A
pow-prod-upN/A
metadata-evalN/A
metadata-evalN/A
pow-plusN/A
metadata-evalN/A
metadata-evalN/A
inv-powN/A
lower-*.f64N/A
lower-/.f6425.5%
Applied rewrites25.5%
lift-sqrt.f64N/A
pow1/2N/A
lift-fma.f64N/A
+-commutativeN/A
lift-*.f64N/A
pow1/2N/A
lift-hypot.f6449.9%
Applied rewrites49.9%
(FPCore (re im base) :precision binary64 (* -1.0 (/ (log (/ 1.0 (fmax (fabs re) (fabs im)))) (log base))))
double code(double re, double im, double base) {
return -1.0 * (log((1.0 / fmax(fabs(re), fabs(im)))) / log(base));
}
real(8) function code(re, im, base)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8), intent (in) :: base
code = (-1.0d0) * (log((1.0d0 / fmax(abs(re), abs(im)))) / log(base))
end function
public static double code(double re, double im, double base) {
return -1.0 * (Math.log((1.0 / fmax(Math.abs(re), Math.abs(im)))) / Math.log(base));
}
def code(re, im, base): return -1.0 * (math.log((1.0 / fmax(math.fabs(re), math.fabs(im)))) / math.log(base))
function code(re, im, base) return Float64(-1.0 * Float64(log(Float64(1.0 / fmax(abs(re), abs(im)))) / log(base))) end
function tmp = code(re, im, base) tmp = -1.0 * (log((1.0 / max(abs(re), abs(im)))) / log(base)); end
code[re_, im_, base_] := N[(-1.0 * N[(N[Log[N[(1.0 / N[Max[N[Abs[re], $MachinePrecision], N[Abs[im], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
-1 \cdot \frac{\log \left(\frac{1}{\mathsf{max}\left(\left|re\right|, \left|im\right|\right)}\right)}{\log base}
Initial program 25.5%
Taylor expanded in im around inf
lower-*.f64N/A
lower-/.f64N/A
lower-log.f64N/A
lower-/.f64N/A
lower-log.f6413.4%
Applied rewrites13.4%
(FPCore (re im base) :precision binary64 (/ (log (fmax (fabs re) (fabs im))) (log base)))
double code(double re, double im, double base) {
return log(fmax(fabs(re), fabs(im))) / log(base);
}
real(8) function code(re, im, base)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8), intent (in) :: base
code = log(fmax(abs(re), abs(im))) / log(base)
end function
public static double code(double re, double im, double base) {
return Math.log(fmax(Math.abs(re), Math.abs(im))) / Math.log(base);
}
def code(re, im, base): return math.log(fmax(math.fabs(re), math.fabs(im))) / math.log(base)
function code(re, im, base) return Float64(log(fmax(abs(re), abs(im))) / log(base)) end
function tmp = code(re, im, base) tmp = log(max(abs(re), abs(im))) / log(base); end
code[re_, im_, base_] := N[(N[Log[N[Max[N[Abs[re], $MachinePrecision], N[Abs[im], $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision]
\frac{\log \left(\mathsf{max}\left(\left|re\right|, \left|im\right|\right)\right)}{\log base}
Initial program 25.5%
Taylor expanded in im around -inf
lower-*.f64N/A
lower-/.f64N/A
lower-log.f64N/A
lower-/.f64N/A
lower-log.f6413.6%
Applied rewrites13.6%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lift-log.f64N/A
lift-/.f64N/A
log-divN/A
metadata-evalN/A
metadata-evalN/A
log-divN/A
log-recN/A
remove-double-negN/A
lower-log.f6413.4%
Applied rewrites13.4%
herbie shell --seed 2025313 -o setup:search
(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))))