
(FPCore (re im) :precision binary64 (/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))
double code(double re, double im) {
return log(sqrt(((re * re) + (im * im)))) / log(10.0);
}
real(8) function code(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
code = log(sqrt(((re * re) + (im * im)))) / log(10.0d0)
end function
public static double code(double re, double im) {
return Math.log(Math.sqrt(((re * re) + (im * im)))) / Math.log(10.0);
}
def code(re, im): return math.log(math.sqrt(((re * re) + (im * im)))) / math.log(10.0)
function code(re, im) return Float64(log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) / log(10.0)) end
function tmp = code(re, im) tmp = log(sqrt(((re * re) + (im * im)))) / log(10.0); end
code[re_, im_] := N[(N[Log[N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))
double code(double re, double im) {
return log(sqrt(((re * re) + (im * im)))) / log(10.0);
}
real(8) function code(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
code = log(sqrt(((re * re) + (im * im)))) / log(10.0d0)
end function
public static double code(double re, double im) {
return Math.log(Math.sqrt(((re * re) + (im * im)))) / Math.log(10.0);
}
def code(re, im): return math.log(math.sqrt(((re * re) + (im * im)))) / math.log(10.0)
function code(re, im) return Float64(log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) / log(10.0)) end
function tmp = code(re, im) tmp = log(sqrt(((re * re) + (im * im)))) / log(10.0); end
code[re_, im_] := N[(N[Log[N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}
(FPCore (re im) :precision binary64 (/ (log (hypot re im)) 2.302585092994046))
double code(double re, double im) {
return log(hypot(re, im)) / 2.302585092994046;
}
public static double code(double re, double im) {
return Math.log(Math.hypot(re, im)) / 2.302585092994046;
}
def code(re, im): return math.log(math.hypot(re, im)) / 2.302585092994046
function code(re, im) return Float64(log(hypot(re, im)) / 2.302585092994046) end
function tmp = code(re, im) tmp = log(hypot(re, im)) / 2.302585092994046; end
code[re_, im_] := N[(N[Log[N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision]], $MachinePrecision] / 2.302585092994046), $MachinePrecision]
\frac{\log \left(\mathsf{hypot}\left(re, im\right)\right)}{2.302585092994046}
Initial program 51.4%
lift-sqrt.f64N/A
sqrt-fabs-revN/A
lift-sqrt.f64N/A
rem-sqrt-square-revN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
rem-square-sqrtN/A
lift-+.f64N/A
lift-*.f64N/A
sqr-neg-revN/A
fp-cancel-sign-sub-invN/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
distribute-rgt-neg-outN/A
sqr-neg-revN/A
sqr-neg-revN/A
lower-hypot.f6499.1%
Applied rewrites99.1%
Evaluated real constant99.1%
(FPCore (re im) :precision binary64 (/ (log (fmax (fabs re) (fabs im))) 2.302585092994046))
double code(double re, double im) {
return log(fmax(fabs(re), fabs(im))) / 2.302585092994046;
}
real(8) function code(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
code = log(fmax(abs(re), abs(im))) / 2.302585092994046d0
end function
public static double code(double re, double im) {
return Math.log(fmax(Math.abs(re), Math.abs(im))) / 2.302585092994046;
}
def code(re, im): return math.log(fmax(math.fabs(re), math.fabs(im))) / 2.302585092994046
function code(re, im) return Float64(log(fmax(abs(re), abs(im))) / 2.302585092994046) end
function tmp = code(re, im) tmp = log(max(abs(re), abs(im))) / 2.302585092994046; end
code[re_, im_] := N[(N[Log[N[Max[N[Abs[re], $MachinePrecision], N[Abs[im], $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / 2.302585092994046), $MachinePrecision]
\frac{\log \left(\mathsf{max}\left(\left|re\right|, \left|im\right|\right)\right)}{2.302585092994046}
Initial program 51.4%
Evaluated real constant51.4%
Taylor expanded in im around inf
lower-*.f64N/A
lower-log.f64N/A
lower-/.f6427.9%
Applied rewrites27.9%
lift-/.f64N/A
mult-flipN/A
lower-*.f64N/A
lift-*.f64N/A
mul-1-negN/A
lift-log.f64N/A
lift-/.f64N/A
log-recN/A
remove-double-negN/A
lower-log.f64N/A
lower-log.f64N/A
Applied rewrites27.8%
lift-*.f64N/A
metadata-evalN/A
metadata-evalN/A
mult-flip-revN/A
lower-/.f64N/A
metadata-eval27.9%
Applied rewrites27.9%
(FPCore (re im) :precision binary64 (* (log (fmax (fabs re) (fabs im))) 0.43429448190325176))
double code(double re, double im) {
return log(fmax(fabs(re), fabs(im))) * 0.43429448190325176;
}
real(8) function code(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
code = log(fmax(abs(re), abs(im))) * 0.43429448190325176d0
end function
public static double code(double re, double im) {
return Math.log(fmax(Math.abs(re), Math.abs(im))) * 0.43429448190325176;
}
def code(re, im): return math.log(fmax(math.fabs(re), math.fabs(im))) * 0.43429448190325176
function code(re, im) return Float64(log(fmax(abs(re), abs(im))) * 0.43429448190325176) end
function tmp = code(re, im) tmp = log(max(abs(re), abs(im))) * 0.43429448190325176; end
code[re_, im_] := N[(N[Log[N[Max[N[Abs[re], $MachinePrecision], N[Abs[im], $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * 0.43429448190325176), $MachinePrecision]
\log \left(\mathsf{max}\left(\left|re\right|, \left|im\right|\right)\right) \cdot 0.43429448190325176
Initial program 51.4%
Evaluated real constant51.4%
Taylor expanded in im around inf
lower-*.f64N/A
lower-log.f64N/A
lower-/.f6427.9%
Applied rewrites27.9%
lift-/.f64N/A
mult-flipN/A
lower-*.f64N/A
lift-*.f64N/A
mul-1-negN/A
lift-log.f64N/A
lift-/.f64N/A
log-recN/A
remove-double-negN/A
lower-log.f64N/A
lower-log.f64N/A
Applied rewrites27.8%
herbie shell --seed 2025313 -o setup:search
(FPCore (re im)
:name "math.log10 on complex, real part"
:precision binary64
(/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))