
(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);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
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]
\begin{array}{l}
\\
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}
\end{array}
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);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
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]
\begin{array}{l}
\\
\frac{\log \left(\sqrt{re \cdot re + im \cdot im}\right)}{\log 10}
\end{array}
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (/ (log (hypot (* (sqrt im_m) (sqrt im_m)) re)) (log 10.0)))
im_m = fabs(im);
double code(double re, double im_m) {
return log(hypot((sqrt(im_m) * sqrt(im_m)), re)) / log(10.0);
}
im_m = Math.abs(im);
public static double code(double re, double im_m) {
return Math.log(Math.hypot((Math.sqrt(im_m) * Math.sqrt(im_m)), re)) / Math.log(10.0);
}
im_m = math.fabs(im) def code(re, im_m): return math.log(math.hypot((math.sqrt(im_m) * math.sqrt(im_m)), re)) / math.log(10.0)
im_m = abs(im) function code(re, im_m) return Float64(log(hypot(Float64(sqrt(im_m) * sqrt(im_m)), re)) / log(10.0)) end
im_m = abs(im); function tmp = code(re, im_m) tmp = log(hypot((sqrt(im_m) * sqrt(im_m)), re)) / log(10.0); end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := N[(N[Log[N[Sqrt[N[(N[Sqrt[im$95$m], $MachinePrecision] * N[Sqrt[im$95$m], $MachinePrecision]), $MachinePrecision] ^ 2 + re ^ 2], $MachinePrecision]], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
\frac{\log \left(\mathsf{hypot}\left(\sqrt{im\_m} \cdot \sqrt{im\_m}, re\right)\right)}{\log 10}
\end{array}
Initial program 50.2%
lift-sqrt.f64N/A
lift-*.f64N/A
lift-+.f64N/A
pow2N/A
lift-*.f64N/A
pow2N/A
+-commutativeN/A
rem-square-sqrtN/A
unpow2N/A
pow-to-expN/A
exp-lft-sqrN/A
pow2N/A
lower-hypot.f64N/A
lower-exp.f64N/A
lower-log.f64N/A
pow2N/A
rem-sqrt-square-revN/A
lower-fabs.f6499.1
Applied rewrites99.1%
lift-exp.f64N/A
lift-fabs.f64N/A
lift-log.f64N/A
rem-exp-logN/A
rem-sqrt-square-revN/A
sqrt-prodN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6499.1
Applied rewrites99.1%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (/ (log (hypot re im_m)) (log 10.0)))
im_m = fabs(im);
double code(double re, double im_m) {
return log(hypot(re, im_m)) / log(10.0);
}
im_m = Math.abs(im);
public static double code(double re, double im_m) {
return Math.log(Math.hypot(re, im_m)) / Math.log(10.0);
}
im_m = math.fabs(im) def code(re, im_m): return math.log(math.hypot(re, im_m)) / math.log(10.0)
im_m = abs(im) function code(re, im_m) return Float64(log(hypot(re, im_m)) / log(10.0)) end
im_m = abs(im); function tmp = code(re, im_m) tmp = log(hypot(re, im_m)) / log(10.0); end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := N[(N[Log[N[Sqrt[re ^ 2 + im$95$m ^ 2], $MachinePrecision]], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
\frac{\log \left(\mathsf{hypot}\left(re, im\_m\right)\right)}{\log 10}
\end{array}
Initial program 50.2%
lift-sqrt.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lower-hypot.f6499.1
Applied rewrites99.1%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (/ (log im_m) (log 10.0)))
im_m = fabs(im);
double code(double re, double im_m) {
return log(im_m) / log(10.0);
}
im_m = private
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(re, im_m)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im_m
code = log(im_m) / log(10.0d0)
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
return Math.log(im_m) / Math.log(10.0);
}
im_m = math.fabs(im) def code(re, im_m): return math.log(im_m) / math.log(10.0)
im_m = abs(im) function code(re, im_m) return Float64(log(im_m) / log(10.0)) end
im_m = abs(im); function tmp = code(re, im_m) tmp = log(im_m) / log(10.0); end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := N[(N[Log[im$95$m], $MachinePrecision] / N[Log[10.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
\frac{\log im\_m}{\log 10}
\end{array}
Initial program 50.2%
Taylor expanded in im around inf
log-pow-revN/A
unpow-1N/A
inv-powN/A
pow-negN/A
metadata-evalN/A
unpow1N/A
lower-log.f6454.7
Applied rewrites54.7%
herbie shell --seed 2025143
(FPCore (re im)
:name "math.log10 on complex, real part"
:precision binary64
(/ (log (sqrt (+ (* re re) (* im im)))) (log 10.0)))