(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]
\begin{array}{l} \\ x.re \cdot y.im + x.im \cdot y.re \end{array}
Sampling outcomes in binary64 precision:
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]
\begin{array}{l} \\ x.re \cdot y.im + x.im \cdot y.re \end{array}
(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]
\begin{array}{l} \\ x.re \cdot y.im + x.im \cdot y.re \end{array}
Initial program 99.2%
(FPCore (x.re x.im y.re y.im) :precision binary64 (if (or (<= (* x.im y.re) -5e+14) (not (<= (* x.im y.re) 1e+21))) (* y.re x.im) (* y.im x.re)))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) { double tmp; if (((x_46_im * y_46_re) <= -5e+14) || !((x_46_im * y_46_re) <= 1e+21)) { tmp = y_46_re * x_46_im; } else { tmp = y_46_im * x_46_re; } 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_46im * y_46re) <= (-5d+14)) .or. (.not. ((x_46im * y_46re) <= 1d+21))) then tmp = y_46re * x_46im else tmp = y_46im * x_46re 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_im * y_46_re) <= -5e+14) || !((x_46_im * y_46_re) <= 1e+21)) { tmp = y_46_re * x_46_im; } else { tmp = y_46_im * x_46_re; } return tmp; }
def code(x_46_re, x_46_im, y_46_re, y_46_im): tmp = 0 if ((x_46_im * y_46_re) <= -5e+14) or not ((x_46_im * y_46_re) <= 1e+21): tmp = y_46_re * x_46_im else: tmp = y_46_im * x_46_re return tmp
function code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = 0.0 if ((Float64(x_46_im * y_46_re) <= -5e+14) || !(Float64(x_46_im * y_46_re) <= 1e+21)) tmp = Float64(y_46_re * x_46_im); else tmp = Float64(y_46_im * x_46_re); 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_im * y_46_re) <= -5e+14) || ~(((x_46_im * y_46_re) <= 1e+21))) tmp = y_46_re * x_46_im; else tmp = y_46_im * x_46_re; end tmp_2 = tmp; end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[Or[LessEqual[N[(x$46$im * y$46$re), $MachinePrecision], -5e+14], N[Not[LessEqual[N[(x$46$im * y$46$re), $MachinePrecision], 1e+21]], $MachinePrecision]], N[(y$46$re * x$46$im), $MachinePrecision], N[(y$46$im * x$46$re), $MachinePrecision]]
\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x.im \cdot y.re \leq -5 \cdot 10^{+14} \lor \neg \left(x.im \cdot y.re \leq 10^{+21}\right):\\ \;\;\;\;y.re \cdot x.im\\ \mathbf{else}:\\ \;\;\;\;y.im \cdot x.re\\ \end{array} \end{array}
if (*.f64 x.im y.re) < -5e14 or 1e21 < (*.f64 x.im y.re)
Initial program 98.1%
Taylor expanded in x.re around 0
*-commutative
N/A
lower-*.f64
81.7
Applied rewrites81.7%
if -5e14 < (*.f64 x.im y.re) < 1e21
Initial program 100.0%
Taylor expanded in x.re around inf
*-commutative
N/A
lower-*.f64
79.3
Applied rewrites79.3%
Final simplification80.3%
(FPCore (x.re x.im y.re y.im) :precision binary64 (* y.im x.re))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) { return y_46_im * x_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 = y_46im * x_46re end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) { return y_46_im * x_46_re; }
def code(x_46_re, x_46_im, y_46_re, y_46_im): return y_46_im * x_46_re
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(y_46_im * x_46_re) end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = y_46_im * x_46_re; end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(y$46$im * x$46$re), $MachinePrecision]
\begin{array}{l} \\ y.im \cdot x.re \end{array}
Initial program 99.2%
Taylor expanded in x.re around inf
*-commutative
N/A
lower-*.f64
56.0
Applied rewrites56.0%
herbie shell --seed 2025058
(FPCore (x.re x.im y.re y.im)
:name "_multiplyComplex, imaginary part"
:precision binary64
(+ (* x.re y.im) (* x.im y.re)))