
(FPCore im_sqr (re im) :precision binary64 (+ (* re im) (* im re)))
double im_sqr(double re, double im) {
return (re * im) + (im * re);
}
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 im_sqr(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
im_sqr = (re * im) + (im * re)
end function
public static double im_sqr(double re, double im) {
return (re * im) + (im * re);
}
def im_sqr(re, im): return (re * im) + (im * re)
function im_sqr(re, im) return Float64(Float64(re * im) + Float64(im * re)) end
function tmp = im_sqr(re, im) tmp = (re * im) + (im * re); end
im$95$sqr[re_, im_] := N[(N[(re * im), $MachinePrecision] + N[(im * re), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
re \cdot im + im \cdot re
\end{array}
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore im_sqr (re im) :precision binary64 (+ (* re im) (* im re)))
double im_sqr(double re, double im) {
return (re * im) + (im * re);
}
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 im_sqr(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
im_sqr = (re * im) + (im * re)
end function
public static double im_sqr(double re, double im) {
return (re * im) + (im * re);
}
def im_sqr(re, im): return (re * im) + (im * re)
function im_sqr(re, im) return Float64(Float64(re * im) + Float64(im * re)) end
function tmp = im_sqr(re, im) tmp = (re * im) + (im * re); end
im$95$sqr[re_, im_] := N[(N[(re * im), $MachinePrecision] + N[(im * re), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
re \cdot im + im \cdot re
\end{array}
re_m = (fabs.f64 re) im_m = (fabs.f64 im) (FPCore im_sqr (re_m im_m) :precision binary64 (* 2.0 (* im_m re_m)))
re_m = fabs(re);
im_m = fabs(im);
double im_sqr(double re_m, double im_m) {
return 2.0 * (im_m * re_m);
}
re_m = private
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 im_sqr(re_m, im_m)
use fmin_fmax_functions
real(8), intent (in) :: re_m
real(8), intent (in) :: im_m
im_sqr = 2.0d0 * (im_m * re_m)
end function
re_m = Math.abs(re);
im_m = Math.abs(im);
public static double im_sqr(double re_m, double im_m) {
return 2.0 * (im_m * re_m);
}
re_m = math.fabs(re) im_m = math.fabs(im) def im_sqr(re_m, im_m): return 2.0 * (im_m * re_m)
re_m = abs(re) im_m = abs(im) function im_sqr(re_m, im_m) return Float64(2.0 * Float64(im_m * re_m)) end
re_m = abs(re); im_m = abs(im); function tmp = im_sqr(re_m, im_m) tmp = 2.0 * (im_m * re_m); end
re_m = N[Abs[re], $MachinePrecision] im_m = N[Abs[im], $MachinePrecision] im$95$sqr[re$95$m_, im$95$m_] := N[(2.0 * N[(im$95$m * re$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
re_m = \left|re\right|
\\
im_m = \left|im\right|
\\
2 \cdot \left(im\_m \cdot re\_m\right)
\end{array}
Initial program 56.4%
Taylor expanded in re around 0
Applied rewrites56.4%
re_m = (fabs.f64 re) im_m = (fabs.f64 im) (FPCore im_sqr (re_m im_m) :precision binary64 (* im_m re_m))
re_m = fabs(re);
im_m = fabs(im);
double im_sqr(double re_m, double im_m) {
return im_m * re_m;
}
re_m = private
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 im_sqr(re_m, im_m)
use fmin_fmax_functions
real(8), intent (in) :: re_m
real(8), intent (in) :: im_m
im_sqr = im_m * re_m
end function
re_m = Math.abs(re);
im_m = Math.abs(im);
public static double im_sqr(double re_m, double im_m) {
return im_m * re_m;
}
re_m = math.fabs(re) im_m = math.fabs(im) def im_sqr(re_m, im_m): return im_m * re_m
re_m = abs(re) im_m = abs(im) function im_sqr(re_m, im_m) return Float64(im_m * re_m) end
re_m = abs(re); im_m = abs(im); function tmp = im_sqr(re_m, im_m) tmp = im_m * re_m; end
re_m = N[Abs[re], $MachinePrecision] im_m = N[Abs[im], $MachinePrecision] im$95$sqr[re$95$m_, im$95$m_] := N[(im$95$m * re$95$m), $MachinePrecision]
\begin{array}{l}
re_m = \left|re\right|
\\
im_m = \left|im\right|
\\
im\_m \cdot re\_m
\end{array}
Initial program 56.4%
Taylor expanded in re around 0
Applied rewrites56.4%
Applied rewrites26.1%
re_m = (fabs.f64 re) im_m = (fabs.f64 im) (FPCore im_sqr (re_m im_m) :precision binary64 0.0)
re_m = fabs(re);
im_m = fabs(im);
double im_sqr(double re_m, double im_m) {
return 0.0;
}
re_m = private
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 im_sqr(re_m, im_m)
use fmin_fmax_functions
real(8), intent (in) :: re_m
real(8), intent (in) :: im_m
im_sqr = 0.0d0
end function
re_m = Math.abs(re);
im_m = Math.abs(im);
public static double im_sqr(double re_m, double im_m) {
return 0.0;
}
re_m = math.fabs(re) im_m = math.fabs(im) def im_sqr(re_m, im_m): return 0.0
re_m = abs(re) im_m = abs(im) function im_sqr(re_m, im_m) return 0.0 end
re_m = abs(re); im_m = abs(im); function tmp = im_sqr(re_m, im_m) tmp = 0.0; end
re_m = N[Abs[re], $MachinePrecision] im_m = N[Abs[im], $MachinePrecision] im$95$sqr[re$95$m_, im$95$m_] := 0.0
\begin{array}{l}
re_m = \left|re\right|
\\
im_m = \left|im\right|
\\
0
\end{array}
Initial program 56.4%
Applied rewrites14.9%
herbie shell --seed 2025159
(FPCore im_sqr (re im)
:name "math.square on complex, imaginary part"
:precision binary64
(+ (* re im) (* im re)))