
(FPCore (re im base) :precision binary64 (/ (- (* (atan2 im re) (log base)) (* (log (sqrt (+ (* re re) (* im im)))) 0.0)) (+ (* (log base) (log base)) (* 0.0 0.0))))
double code(double re, double im, double base) {
return ((atan2(im, re) * log(base)) - (log(sqrt(((re * re) + (im * im)))) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.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, base)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8), intent (in) :: base
code = ((atan2(im, re) * log(base)) - (log(sqrt(((re * re) + (im * im)))) * 0.0d0)) / ((log(base) * log(base)) + (0.0d0 * 0.0d0))
end function
public static double code(double re, double im, double base) {
return ((Math.atan2(im, re) * Math.log(base)) - (Math.log(Math.sqrt(((re * re) + (im * im)))) * 0.0)) / ((Math.log(base) * Math.log(base)) + (0.0 * 0.0));
}
def code(re, im, base): return ((math.atan2(im, re) * math.log(base)) - (math.log(math.sqrt(((re * re) + (im * im)))) * 0.0)) / ((math.log(base) * math.log(base)) + (0.0 * 0.0))
function code(re, im, base) return Float64(Float64(Float64(atan(im, re) * log(base)) - Float64(log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) * 0.0)) / Float64(Float64(log(base) * log(base)) + Float64(0.0 * 0.0))) end
function tmp = code(re, im, base) tmp = ((atan2(im, re) * log(base)) - (log(sqrt(((re * re) + (im * im)))) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.0)); end
code[re_, im_, base_] := N[(N[(N[(N[ArcTan[im / re], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] - N[(N[Log[N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $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{\tan^{-1}_* \frac{im}{re} \cdot \log base - \log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot 0}{\log base \cdot \log base + 0 \cdot 0}
Herbie found 1 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im base) :precision binary64 (/ (- (* (atan2 im re) (log base)) (* (log (sqrt (+ (* re re) (* im im)))) 0.0)) (+ (* (log base) (log base)) (* 0.0 0.0))))
double code(double re, double im, double base) {
return ((atan2(im, re) * log(base)) - (log(sqrt(((re * re) + (im * im)))) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.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, base)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8), intent (in) :: base
code = ((atan2(im, re) * log(base)) - (log(sqrt(((re * re) + (im * im)))) * 0.0d0)) / ((log(base) * log(base)) + (0.0d0 * 0.0d0))
end function
public static double code(double re, double im, double base) {
return ((Math.atan2(im, re) * Math.log(base)) - (Math.log(Math.sqrt(((re * re) + (im * im)))) * 0.0)) / ((Math.log(base) * Math.log(base)) + (0.0 * 0.0));
}
def code(re, im, base): return ((math.atan2(im, re) * math.log(base)) - (math.log(math.sqrt(((re * re) + (im * im)))) * 0.0)) / ((math.log(base) * math.log(base)) + (0.0 * 0.0))
function code(re, im, base) return Float64(Float64(Float64(atan(im, re) * log(base)) - Float64(log(sqrt(Float64(Float64(re * re) + Float64(im * im)))) * 0.0)) / Float64(Float64(log(base) * log(base)) + Float64(0.0 * 0.0))) end
function tmp = code(re, im, base) tmp = ((atan2(im, re) * log(base)) - (log(sqrt(((re * re) + (im * im)))) * 0.0)) / ((log(base) * log(base)) + (0.0 * 0.0)); end
code[re_, im_, base_] := N[(N[(N[(N[ArcTan[im / re], $MachinePrecision] * N[Log[base], $MachinePrecision]), $MachinePrecision] - N[(N[Log[N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $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{\tan^{-1}_* \frac{im}{re} \cdot \log base - \log \left(\sqrt{re \cdot re + im \cdot im}\right) \cdot 0}{\log base \cdot \log base + 0 \cdot 0}
(FPCore (re im base) :precision binary64 (/ (atan2 im re) (log base)))
double code(double re, double im, double base) {
return atan2(im, re) / log(base);
}
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, base)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8), intent (in) :: base
code = atan2(im, re) / log(base)
end function
public static double code(double re, double im, double base) {
return Math.atan2(im, re) / Math.log(base);
}
def code(re, im, base): return math.atan2(im, re) / math.log(base)
function code(re, im, base) return Float64(atan(im, re) / log(base)) end
function tmp = code(re, im, base) tmp = atan2(im, re) / log(base); end
code[re_, im_, base_] := N[(N[ArcTan[im / re], $MachinePrecision] / N[Log[base], $MachinePrecision]), $MachinePrecision]
\frac{\tan^{-1}_* \frac{im}{re}}{\log base}
Initial program 49.8%
lift-/.f64N/A
lift--.f64N/A
lift-*.f64N/A
mul0-rgtN/A
--rgt-identityN/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
metadata-evalN/A
+-rgt-identityN/A
associate-/l*N/A
lift-*.f64N/A
associate-/r*N/A
*-inversesN/A
mult-flipN/A
lower-/.f6499.5%
Applied rewrites99.5%
herbie shell --seed 2025217
(FPCore (re im base)
:name "math.log/2 on complex, imaginary part"
:precision binary64
(/ (- (* (atan2 im re) (log base)) (* (log (sqrt (+ (* re re) (* im im)))) 0.0)) (+ (* (log base) (log base)) (* 0.0 0.0))))