
(FPCore (x.re x.im y.re y.im) :precision binary64 (- (* x.re y.re) (* x.im y.im)))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return (x_46_re * y_46_re) - (x_46_im * y_46_im);
}
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_46re) - (x_46im * y_46im)
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_re) - (x_46_im * y_46_im);
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): return (x_46_re * y_46_re) - (x_46_im * y_46_im)
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(Float64(x_46_re * y_46_re) - Float64(x_46_im * y_46_im)) end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = (x_46_re * y_46_re) - (x_46_im * y_46_im); end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[(x$46$re * y$46$re), $MachinePrecision] - N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]
x.re \cdot y.re - x.im \cdot y.im
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x.re x.im y.re y.im) :precision binary64 (- (* x.re y.re) (* x.im y.im)))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return (x_46_re * y_46_re) - (x_46_im * y_46_im);
}
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_46re) - (x_46im * y_46im)
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_re) - (x_46_im * y_46_im);
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): return (x_46_re * y_46_re) - (x_46_im * y_46_im)
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(Float64(x_46_re * y_46_re) - Float64(x_46_im * y_46_im)) end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = (x_46_re * y_46_re) - (x_46_im * y_46_im); end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[(x$46$re * y$46$re), $MachinePrecision] - N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]
x.re \cdot y.re - x.im \cdot y.im
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (* (- y.im) x.im)))
(if (<=
(* x.im y.im)
-6805647338418769/680564733841876926926749214863536422912)
t_0
(if (<=
(* x.im y.im)
99999999999999997168788049560464200849936328366177157906432)
(* x.re y.re)
t_0))))double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = -y_46_im * x_46_im;
double tmp;
if ((x_46_im * y_46_im) <= -1e-23) {
tmp = t_0;
} else if ((x_46_im * y_46_im) <= 1e+59) {
tmp = x_46_re * y_46_re;
} else {
tmp = t_0;
}
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) :: t_0
real(8) :: tmp
t_0 = -y_46im * x_46im
if ((x_46im * y_46im) <= (-1d-23)) then
tmp = t_0
else if ((x_46im * y_46im) <= 1d+59) then
tmp = x_46re * y_46re
else
tmp = t_0
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 t_0 = -y_46_im * x_46_im;
double tmp;
if ((x_46_im * y_46_im) <= -1e-23) {
tmp = t_0;
} else if ((x_46_im * y_46_im) <= 1e+59) {
tmp = x_46_re * y_46_re;
} else {
tmp = t_0;
}
return tmp;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): t_0 = -y_46_im * x_46_im tmp = 0 if (x_46_im * y_46_im) <= -1e-23: tmp = t_0 elif (x_46_im * y_46_im) <= 1e+59: tmp = x_46_re * y_46_re else: tmp = t_0 return tmp
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = Float64(Float64(-y_46_im) * x_46_im) tmp = 0.0 if (Float64(x_46_im * y_46_im) <= -1e-23) tmp = t_0; elseif (Float64(x_46_im * y_46_im) <= 1e+59) tmp = Float64(x_46_re * y_46_re); else tmp = t_0; end return tmp end
function tmp_2 = code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = -y_46_im * x_46_im; tmp = 0.0; if ((x_46_im * y_46_im) <= -1e-23) tmp = t_0; elseif ((x_46_im * y_46_im) <= 1e+59) tmp = x_46_re * y_46_re; else tmp = t_0; end tmp_2 = tmp; end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[((-y$46$im) * x$46$im), $MachinePrecision]}, If[LessEqual[N[(x$46$im * y$46$im), $MachinePrecision], -6805647338418769/680564733841876926926749214863536422912], t$95$0, If[LessEqual[N[(x$46$im * y$46$im), $MachinePrecision], 99999999999999997168788049560464200849936328366177157906432], N[(x$46$re * y$46$re), $MachinePrecision], t$95$0]]]
\begin{array}{l}
t_0 := \left(-y.im\right) \cdot x.im\\
\mathbf{if}\;x.im \cdot y.im \leq \frac{-6805647338418769}{680564733841876926926749214863536422912}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x.im \cdot y.im \leq 99999999999999997168788049560464200849936328366177157906432:\\
\;\;\;\;x.re \cdot y.re\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
if (*.f64 x.im y.im) < -9.9999999999999996e-24 or 9.9999999999999997e58 < (*.f64 x.im y.im) Initial program 99.4%
Taylor expanded in x.re around 0
lower-*.f64N/A
lower-*.f6451.7%
Applied rewrites51.7%
lift-*.f64N/A
mul-1-negN/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f6451.7%
Applied rewrites51.7%
if -9.9999999999999996e-24 < (*.f64 x.im y.im) < 9.9999999999999997e58Initial program 99.4%
Taylor expanded in y.re around inf
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6491.7%
Applied rewrites91.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6491.7%
lift-+.f64N/A
add-flipN/A
lower--.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
mul-1-negN/A
distribute-neg-frac2N/A
frac-2negN/A
mult-flipN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
mult-flip-revN/A
lower-/.f6487.6%
Applied rewrites87.6%
Taylor expanded in x.re around inf
lower-*.f6452.5%
Applied rewrites52.5%
(FPCore (x.re x.im y.re y.im) :precision binary64 (* x.re 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_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_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_re;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): return x_46_re * y_46_re
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(x_46_re * 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_re; end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(x$46$re * y$46$re), $MachinePrecision]
x.re \cdot y.re
Initial program 99.4%
Taylor expanded in y.re around inf
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-*.f6491.7%
Applied rewrites91.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6491.7%
lift-+.f64N/A
add-flipN/A
lower--.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
mul-1-negN/A
distribute-neg-frac2N/A
frac-2negN/A
mult-flipN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
mult-flip-revN/A
lower-/.f6487.6%
Applied rewrites87.6%
Taylor expanded in x.re around inf
lower-*.f6452.5%
Applied rewrites52.5%
herbie shell --seed 2025285 -o generate:evaluate
(FPCore (x.re x.im y.re y.im)
:name "_multiplyComplex, real part"
:precision binary64
(- (* x.re y.re) (* x.im y.im)))