
(FPCore (x.re x.im y.re y.im) :precision binary64 (+ (* x.re y.im) (* x.im y.re)))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return (x_46_re * y_46_im) + (x_46_im * y_46_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 code(x_46re, x_46im, y_46re, y_46im)
use fmin_fmax_functions
real(8), intent (in) :: x_46re
real(8), intent (in) :: x_46im
real(8), intent (in) :: y_46re
real(8), intent (in) :: y_46im
code = (x_46re * y_46im) + (x_46im * y_46re)
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return (x_46_re * y_46_im) + (x_46_im * y_46_re);
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): return (x_46_re * y_46_im) + (x_46_im * y_46_re)
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(Float64(x_46_re * y_46_im) + Float64(x_46_im * y_46_re)) end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = (x_46_re * y_46_im) + (x_46_im * y_46_re); end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[(x$46$re * y$46$im), $MachinePrecision] + N[(x$46$im * y$46$re), $MachinePrecision]), $MachinePrecision]
x.re \cdot y.im + x.im \cdot y.re
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x.re x.im y.re y.im) :precision binary64 (+ (* x.re y.im) (* x.im y.re)))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return (x_46_re * y_46_im) + (x_46_im * y_46_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 code(x_46re, x_46im, y_46re, y_46im)
use fmin_fmax_functions
real(8), intent (in) :: x_46re
real(8), intent (in) :: x_46im
real(8), intent (in) :: y_46re
real(8), intent (in) :: y_46im
code = (x_46re * y_46im) + (x_46im * y_46re)
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return (x_46_re * y_46_im) + (x_46_im * y_46_re);
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): return (x_46_re * y_46_im) + (x_46_im * y_46_re)
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(Float64(x_46_re * y_46_im) + Float64(x_46_im * y_46_re)) end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = (x_46_re * y_46_im) + (x_46_im * y_46_re); end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[(x$46$re * y$46$im), $MachinePrecision] + N[(x$46$im * y$46$re), $MachinePrecision]), $MachinePrecision]
x.re \cdot y.im + x.im \cdot y.re
(FPCore (x.re x.im y.re y.im) :precision binary64 (fma y.im x.re (* y.re x.im)))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return fma(y_46_im, x_46_re, (y_46_re * x_46_im));
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) return fma(y_46_im, x_46_re, Float64(y_46_re * x_46_im)) end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(y$46$im * x$46$re + N[(y$46$re * x$46$im), $MachinePrecision]), $MachinePrecision]
\mathsf{fma}\left(y.im, x.re, y.re \cdot x.im\right)
Initial program 99.4%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
fp-cancel-sign-sub-invN/A
*-commutativeN/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-outN/A
lift-*.f64N/A
remove-double-negN/A
lower-fma.f6499.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.7%
Applied rewrites99.7%
(FPCore (x.re x.im y.re y.im) :precision binary64 (if (<= (* x.re y.im) -1.8e+113) (* x.re y.im) (if (<= (* x.re y.im) 29000000000.0) (* x.im y.re) (* x.re y.im))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double tmp;
if ((x_46_re * y_46_im) <= -1.8e+113) {
tmp = x_46_re * y_46_im;
} else if ((x_46_re * y_46_im) <= 29000000000.0) {
tmp = x_46_im * y_46_re;
} else {
tmp = x_46_re * y_46_im;
}
return tmp;
}
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(x_46re, x_46im, y_46re, y_46im)
use fmin_fmax_functions
real(8), intent (in) :: x_46re
real(8), intent (in) :: x_46im
real(8), intent (in) :: y_46re
real(8), intent (in) :: y_46im
real(8) :: tmp
if ((x_46re * y_46im) <= (-1.8d+113)) then
tmp = x_46re * y_46im
else if ((x_46re * y_46im) <= 29000000000.0d0) then
tmp = x_46im * y_46re
else
tmp = x_46re * y_46im
end if
code = tmp
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double tmp;
if ((x_46_re * y_46_im) <= -1.8e+113) {
tmp = x_46_re * y_46_im;
} else if ((x_46_re * y_46_im) <= 29000000000.0) {
tmp = x_46_im * y_46_re;
} else {
tmp = x_46_re * y_46_im;
}
return tmp;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): tmp = 0 if (x_46_re * y_46_im) <= -1.8e+113: tmp = x_46_re * y_46_im elif (x_46_re * y_46_im) <= 29000000000.0: tmp = x_46_im * y_46_re else: tmp = x_46_re * y_46_im return tmp
function code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = 0.0 if (Float64(x_46_re * y_46_im) <= -1.8e+113) tmp = Float64(x_46_re * y_46_im); elseif (Float64(x_46_re * y_46_im) <= 29000000000.0) tmp = Float64(x_46_im * y_46_re); else tmp = Float64(x_46_re * y_46_im); end return tmp end
function tmp_2 = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = 0.0; if ((x_46_re * y_46_im) <= -1.8e+113) tmp = x_46_re * y_46_im; elseif ((x_46_re * y_46_im) <= 29000000000.0) tmp = x_46_im * y_46_re; else tmp = x_46_re * y_46_im; end tmp_2 = tmp; end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[LessEqual[N[(x$46$re * y$46$im), $MachinePrecision], -1.8e+113], N[(x$46$re * y$46$im), $MachinePrecision], If[LessEqual[N[(x$46$re * y$46$im), $MachinePrecision], 29000000000.0], N[(x$46$im * y$46$re), $MachinePrecision], N[(x$46$re * y$46$im), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;x.re \cdot y.im \leq -1.8 \cdot 10^{+113}:\\
\;\;\;\;x.re \cdot y.im\\
\mathbf{elif}\;x.re \cdot y.im \leq 29000000000:\\
\;\;\;\;x.im \cdot y.re\\
\mathbf{else}:\\
\;\;\;\;x.re \cdot y.im\\
\end{array}
if (*.f64 x.re y.im) < -1.79999999999999996e113 or 2.9e10 < (*.f64 x.re y.im) Initial program 99.4%
Taylor expanded in x.re around 0
lower-*.f6452.0%
Applied rewrites52.0%
Taylor expanded in x.re around inf
lower-*.f6452.0%
Applied rewrites52.0%
if -1.79999999999999996e113 < (*.f64 x.re y.im) < 2.9e10Initial program 99.4%
Taylor expanded in x.re around 0
lower-*.f6452.0%
Applied rewrites52.0%
(FPCore (x.re x.im y.re y.im) :precision binary64 (* x.im y.re))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return x_46_im * y_46_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 code(x_46re, x_46im, y_46re, y_46im)
use fmin_fmax_functions
real(8), intent (in) :: x_46re
real(8), intent (in) :: x_46im
real(8), intent (in) :: y_46re
real(8), intent (in) :: y_46im
code = x_46im * y_46re
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return x_46_im * y_46_re;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): return x_46_im * y_46_re
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(x_46_im * y_46_re) end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = x_46_im * y_46_re; end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(x$46$im * y$46$re), $MachinePrecision]
x.im \cdot y.re
Initial program 99.4%
Taylor expanded in x.re around 0
lower-*.f6452.0%
Applied rewrites52.0%
herbie shell --seed 2025188
(FPCore (x.re x.im y.re y.im)
:name "_multiplyComplex, imaginary part"
:precision binary64
(+ (* x.re y.im) (* x.im y.re)))