
(FPCore (x.re x.im y.re y.im) :precision binary64 (/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.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)) / ((y_46_re * y_46_re) + (y_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)) / ((y_46re * y_46re) + (y_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)) / ((y_46_re * y_46_re) + (y_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)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im))
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(Float64(Float64(x_46_re * y_46_re) + Float64(x_46_im * y_46_im)) / Float64(Float64(y_46_re * y_46_re) + Float64(y_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)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im)); end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[(N[(x$46$re * y$46$re), $MachinePrecision] + N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision] / N[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x.re x.im y.re y.im) :precision binary64 (/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.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)) / ((y_46_re * y_46_re) + (y_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)) / ((y_46re * y_46re) + (y_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)) / ((y_46_re * y_46_re) + (y_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)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im))
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(Float64(Float64(x_46_re * y_46_re) + Float64(x_46_im * y_46_im)) / Float64(Float64(y_46_re * y_46_re) + Float64(y_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)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im)); end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[(N[(x$46$re * y$46$re), $MachinePrecision] + N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision] / N[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}
\end{array}
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (/ (+ (* x.re y.re) (* x.im y.im)) (fma y.re y.re (* y.im y.im))))
(t_1 (/ (fma x.im (/ y.im y.re) x.re) y.re)))
(if (<= y.re -1.05e+61)
t_1
(if (<= y.re -1.8e-156)
t_0
(if (<= y.re 2.6e-153)
(/ (fma y.re (/ x.re y.im) x.im) y.im)
(if (<= y.re 2.2e+83) t_0 t_1))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / fma(y_46_re, y_46_re, (y_46_im * y_46_im));
double t_1 = fma(x_46_im, (y_46_im / y_46_re), x_46_re) / y_46_re;
double tmp;
if (y_46_re <= -1.05e+61) {
tmp = t_1;
} else if (y_46_re <= -1.8e-156) {
tmp = t_0;
} else if (y_46_re <= 2.6e-153) {
tmp = fma(y_46_re, (x_46_re / y_46_im), x_46_im) / y_46_im;
} else if (y_46_re <= 2.2e+83) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = Float64(Float64(Float64(x_46_re * y_46_re) + Float64(x_46_im * y_46_im)) / fma(y_46_re, y_46_re, Float64(y_46_im * y_46_im))) t_1 = Float64(fma(x_46_im, Float64(y_46_im / y_46_re), x_46_re) / y_46_re) tmp = 0.0 if (y_46_re <= -1.05e+61) tmp = t_1; elseif (y_46_re <= -1.8e-156) tmp = t_0; elseif (y_46_re <= 2.6e-153) tmp = Float64(fma(y_46_re, Float64(x_46_re / y_46_im), x_46_im) / y_46_im); elseif (y_46_re <= 2.2e+83) tmp = t_0; else tmp = t_1; end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[(N[(N[(x$46$re * y$46$re), $MachinePrecision] + N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision] / N[(y$46$re * y$46$re + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x$46$im * N[(y$46$im / y$46$re), $MachinePrecision] + x$46$re), $MachinePrecision] / y$46$re), $MachinePrecision]}, If[LessEqual[y$46$re, -1.05e+61], t$95$1, If[LessEqual[y$46$re, -1.8e-156], t$95$0, If[LessEqual[y$46$re, 2.6e-153], N[(N[(y$46$re * N[(x$46$re / y$46$im), $MachinePrecision] + x$46$im), $MachinePrecision] / y$46$im), $MachinePrecision], If[LessEqual[y$46$re, 2.2e+83], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x.re \cdot y.re + x.im \cdot y.im}{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}\\
t_1 := \frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re}\\
\mathbf{if}\;y.re \leq -1.05 \cdot 10^{+61}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y.re \leq -1.8 \cdot 10^{-156}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y.re \leq 2.6 \cdot 10^{-153}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y.re, \frac{x.re}{y.im}, x.im\right)}{y.im}\\
\mathbf{elif}\;y.re \leq 2.2 \cdot 10^{+83}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y.re < -1.0500000000000001e61 or 2.19999999999999999e83 < y.re Initial program 42.7%
Taylor expanded in y.re around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6486.5
Applied rewrites86.5%
if -1.0500000000000001e61 < y.re < -1.79999999999999999e-156 or 2.6000000000000001e-153 < y.re < 2.19999999999999999e83Initial program 83.9%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lift-*.f6484.0
Applied rewrites84.0%
if -1.79999999999999999e-156 < y.re < 2.6000000000000001e-153Initial program 70.4%
Taylor expanded in y.re around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6425.3
Applied rewrites25.3%
Taylor expanded in y.re around 0
+-commutativeN/A
pow2N/A
frac-timesN/A
*-commutativeN/A
associate-*l/N/A
div-add-revN/A
lower-/.f64N/A
lower-fma.f64N/A
lift-/.f6494.6
Applied rewrites94.6%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (* x.re (/ y.re (fma y.im y.im (* y.re y.re))))))
(if (<= y.re -3.3e+147)
(/ x.re y.re)
(if (<= y.re -1.45e-101)
t_0
(if (<= y.re 5.2e-151)
(/ x.im y.im)
(if (<= y.re 2.65e-8)
t_0
(if (<= y.re 1.32e+82)
(/ (fma y.im x.im (* y.re x.re)) (* y.re y.re))
(/ x.re y.re))))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = x_46_re * (y_46_re / fma(y_46_im, y_46_im, (y_46_re * y_46_re)));
double tmp;
if (y_46_re <= -3.3e+147) {
tmp = x_46_re / y_46_re;
} else if (y_46_re <= -1.45e-101) {
tmp = t_0;
} else if (y_46_re <= 5.2e-151) {
tmp = x_46_im / y_46_im;
} else if (y_46_re <= 2.65e-8) {
tmp = t_0;
} else if (y_46_re <= 1.32e+82) {
tmp = fma(y_46_im, x_46_im, (y_46_re * x_46_re)) / (y_46_re * y_46_re);
} else {
tmp = x_46_re / y_46_re;
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = Float64(x_46_re * Float64(y_46_re / fma(y_46_im, y_46_im, Float64(y_46_re * y_46_re)))) tmp = 0.0 if (y_46_re <= -3.3e+147) tmp = Float64(x_46_re / y_46_re); elseif (y_46_re <= -1.45e-101) tmp = t_0; elseif (y_46_re <= 5.2e-151) tmp = Float64(x_46_im / y_46_im); elseif (y_46_re <= 2.65e-8) tmp = t_0; elseif (y_46_re <= 1.32e+82) tmp = Float64(fma(y_46_im, x_46_im, Float64(y_46_re * x_46_re)) / Float64(y_46_re * y_46_re)); else tmp = Float64(x_46_re / y_46_re); end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[(x$46$re * N[(y$46$re / N[(y$46$im * y$46$im + N[(y$46$re * y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y$46$re, -3.3e+147], N[(x$46$re / y$46$re), $MachinePrecision], If[LessEqual[y$46$re, -1.45e-101], t$95$0, If[LessEqual[y$46$re, 5.2e-151], N[(x$46$im / y$46$im), $MachinePrecision], If[LessEqual[y$46$re, 2.65e-8], t$95$0, If[LessEqual[y$46$re, 1.32e+82], N[(N[(y$46$im * x$46$im + N[(y$46$re * x$46$re), $MachinePrecision]), $MachinePrecision] / N[(y$46$re * y$46$re), $MachinePrecision]), $MachinePrecision], N[(x$46$re / y$46$re), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x.re \cdot \frac{y.re}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}\\
\mathbf{if}\;y.re \leq -3.3 \cdot 10^{+147}:\\
\;\;\;\;\frac{x.re}{y.re}\\
\mathbf{elif}\;y.re \leq -1.45 \cdot 10^{-101}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y.re \leq 5.2 \cdot 10^{-151}:\\
\;\;\;\;\frac{x.im}{y.im}\\
\mathbf{elif}\;y.re \leq 2.65 \cdot 10^{-8}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y.re \leq 1.32 \cdot 10^{+82}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y.im, x.im, y.re \cdot x.re\right)}{y.re \cdot y.re}\\
\mathbf{else}:\\
\;\;\;\;\frac{x.re}{y.re}\\
\end{array}
\end{array}
if y.re < -3.30000000000000025e147 or 1.32e82 < y.re Initial program 38.6%
Taylor expanded in y.re around inf
lower-/.f6481.0
Applied rewrites81.0%
if -3.30000000000000025e147 < y.re < -1.45e-101 or 5.2000000000000001e-151 < y.re < 2.6499999999999999e-8Initial program 79.6%
Taylor expanded in x.re around inf
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lift-*.f6468.8
Applied rewrites68.8%
if -1.45e-101 < y.re < 5.2000000000000001e-151Initial program 74.9%
Taylor expanded in y.re around 0
lower-/.f6471.0
Applied rewrites71.0%
if 2.6499999999999999e-8 < y.re < 1.32e82Initial program 77.3%
Taylor expanded in y.re around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6465.4
Applied rewrites65.4%
Taylor expanded in y.re around 0
+-commutativeN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
pow2N/A
lower-*.f6464.9
Applied rewrites64.9%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(if (<= y.re -3.3e+147)
(/ x.re y.re)
(if (<= y.re -2.15e-100)
(* x.re (/ y.re (fma y.im y.im (* y.re y.re))))
(if (<= y.re 1.7e-78)
(/ (fma y.re x.re (* y.im x.im)) (* y.im y.im))
(if (<= y.re 1.32e+82)
(/ (fma y.im x.im (* y.re x.re)) (* y.re y.re))
(/ x.re y.re))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double tmp;
if (y_46_re <= -3.3e+147) {
tmp = x_46_re / y_46_re;
} else if (y_46_re <= -2.15e-100) {
tmp = x_46_re * (y_46_re / fma(y_46_im, y_46_im, (y_46_re * y_46_re)));
} else if (y_46_re <= 1.7e-78) {
tmp = fma(y_46_re, x_46_re, (y_46_im * x_46_im)) / (y_46_im * y_46_im);
} else if (y_46_re <= 1.32e+82) {
tmp = fma(y_46_im, x_46_im, (y_46_re * x_46_re)) / (y_46_re * y_46_re);
} else {
tmp = x_46_re / y_46_re;
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = 0.0 if (y_46_re <= -3.3e+147) tmp = Float64(x_46_re / y_46_re); elseif (y_46_re <= -2.15e-100) tmp = Float64(x_46_re * Float64(y_46_re / fma(y_46_im, y_46_im, Float64(y_46_re * y_46_re)))); elseif (y_46_re <= 1.7e-78) tmp = Float64(fma(y_46_re, x_46_re, Float64(y_46_im * x_46_im)) / Float64(y_46_im * y_46_im)); elseif (y_46_re <= 1.32e+82) tmp = Float64(fma(y_46_im, x_46_im, Float64(y_46_re * x_46_re)) / Float64(y_46_re * y_46_re)); else tmp = Float64(x_46_re / y_46_re); end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[LessEqual[y$46$re, -3.3e+147], N[(x$46$re / y$46$re), $MachinePrecision], If[LessEqual[y$46$re, -2.15e-100], N[(x$46$re * N[(y$46$re / N[(y$46$im * y$46$im + N[(y$46$re * y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y$46$re, 1.7e-78], N[(N[(y$46$re * x$46$re + N[(y$46$im * x$46$im), $MachinePrecision]), $MachinePrecision] / N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision], If[LessEqual[y$46$re, 1.32e+82], N[(N[(y$46$im * x$46$im + N[(y$46$re * x$46$re), $MachinePrecision]), $MachinePrecision] / N[(y$46$re * y$46$re), $MachinePrecision]), $MachinePrecision], N[(x$46$re / y$46$re), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y.re \leq -3.3 \cdot 10^{+147}:\\
\;\;\;\;\frac{x.re}{y.re}\\
\mathbf{elif}\;y.re \leq -2.15 \cdot 10^{-100}:\\
\;\;\;\;x.re \cdot \frac{y.re}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}\\
\mathbf{elif}\;y.re \leq 1.7 \cdot 10^{-78}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y.re, x.re, y.im \cdot x.im\right)}{y.im \cdot y.im}\\
\mathbf{elif}\;y.re \leq 1.32 \cdot 10^{+82}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y.im, x.im, y.re \cdot x.re\right)}{y.re \cdot y.re}\\
\mathbf{else}:\\
\;\;\;\;\frac{x.re}{y.re}\\
\end{array}
\end{array}
if y.re < -3.30000000000000025e147 or 1.32e82 < y.re Initial program 38.6%
Taylor expanded in y.re around inf
lower-/.f6481.0
Applied rewrites81.0%
if -3.30000000000000025e147 < y.re < -2.14999999999999999e-100Initial program 77.0%
Taylor expanded in x.re around inf
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lift-*.f6470.2
Applied rewrites70.2%
if -2.14999999999999999e-100 < y.re < 1.70000000000000006e-78Initial program 77.2%
Taylor expanded in y.re around 0
pow2N/A
lift-*.f6468.2
Applied rewrites68.2%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6468.2
Applied rewrites68.2%
if 1.70000000000000006e-78 < y.re < 1.32e82Initial program 79.0%
Taylor expanded in y.re around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6465.2
Applied rewrites65.2%
Taylor expanded in y.re around 0
+-commutativeN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
pow2N/A
lower-*.f6464.8
Applied rewrites64.8%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(if (<= y.re -6.5e-12)
(/ x.re y.re)
(if (<= y.re 2.3e-78)
(/ x.im y.im)
(if (<= y.re 1.32e+82)
(/ (fma y.im x.im (* y.re x.re)) (* y.re y.re))
(/ x.re y.re)))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double tmp;
if (y_46_re <= -6.5e-12) {
tmp = x_46_re / y_46_re;
} else if (y_46_re <= 2.3e-78) {
tmp = x_46_im / y_46_im;
} else if (y_46_re <= 1.32e+82) {
tmp = fma(y_46_im, x_46_im, (y_46_re * x_46_re)) / (y_46_re * y_46_re);
} else {
tmp = x_46_re / y_46_re;
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = 0.0 if (y_46_re <= -6.5e-12) tmp = Float64(x_46_re / y_46_re); elseif (y_46_re <= 2.3e-78) tmp = Float64(x_46_im / y_46_im); elseif (y_46_re <= 1.32e+82) tmp = Float64(fma(y_46_im, x_46_im, Float64(y_46_re * x_46_re)) / Float64(y_46_re * y_46_re)); else tmp = Float64(x_46_re / y_46_re); end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[LessEqual[y$46$re, -6.5e-12], N[(x$46$re / y$46$re), $MachinePrecision], If[LessEqual[y$46$re, 2.3e-78], N[(x$46$im / y$46$im), $MachinePrecision], If[LessEqual[y$46$re, 1.32e+82], N[(N[(y$46$im * x$46$im + N[(y$46$re * x$46$re), $MachinePrecision]), $MachinePrecision] / N[(y$46$re * y$46$re), $MachinePrecision]), $MachinePrecision], N[(x$46$re / y$46$re), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y.re \leq -6.5 \cdot 10^{-12}:\\
\;\;\;\;\frac{x.re}{y.re}\\
\mathbf{elif}\;y.re \leq 2.3 \cdot 10^{-78}:\\
\;\;\;\;\frac{x.im}{y.im}\\
\mathbf{elif}\;y.re \leq 1.32 \cdot 10^{+82}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y.im, x.im, y.re \cdot x.re\right)}{y.re \cdot y.re}\\
\mathbf{else}:\\
\;\;\;\;\frac{x.re}{y.re}\\
\end{array}
\end{array}
if y.re < -6.5000000000000002e-12 or 1.32e82 < y.re Initial program 48.2%
Taylor expanded in y.re around inf
lower-/.f6475.8
Applied rewrites75.8%
if -6.5000000000000002e-12 < y.re < 2.3000000000000002e-78Initial program 78.4%
Taylor expanded in y.re around 0
lower-/.f6460.0
Applied rewrites60.0%
if 2.3000000000000002e-78 < y.re < 1.32e82Initial program 79.0%
Taylor expanded in y.re around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6465.2
Applied rewrites65.2%
Taylor expanded in y.re around 0
+-commutativeN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
pow2N/A
lower-*.f6464.8
Applied rewrites64.8%
(FPCore (x.re x.im y.re y.im) :precision binary64 (if (or (<= y.re -6e-12) (not (<= y.re 2.4e-78))) (/ (fma x.im (/ y.im y.re) x.re) y.re) (/ (fma x.re (/ y.re y.im) x.im) y.im)))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double tmp;
if ((y_46_re <= -6e-12) || !(y_46_re <= 2.4e-78)) {
tmp = fma(x_46_im, (y_46_im / y_46_re), x_46_re) / y_46_re;
} else {
tmp = fma(x_46_re, (y_46_re / y_46_im), x_46_im) / y_46_im;
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = 0.0 if ((y_46_re <= -6e-12) || !(y_46_re <= 2.4e-78)) tmp = Float64(fma(x_46_im, Float64(y_46_im / y_46_re), x_46_re) / y_46_re); else tmp = Float64(fma(x_46_re, Float64(y_46_re / y_46_im), x_46_im) / y_46_im); end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[Or[LessEqual[y$46$re, -6e-12], N[Not[LessEqual[y$46$re, 2.4e-78]], $MachinePrecision]], N[(N[(x$46$im * N[(y$46$im / y$46$re), $MachinePrecision] + x$46$re), $MachinePrecision] / y$46$re), $MachinePrecision], N[(N[(x$46$re * N[(y$46$re / y$46$im), $MachinePrecision] + x$46$im), $MachinePrecision] / y$46$im), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y.re \leq -6 \cdot 10^{-12} \lor \neg \left(y.re \leq 2.4 \cdot 10^{-78}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im}\\
\end{array}
\end{array}
if y.re < -6.0000000000000003e-12 or 2.4e-78 < y.re Initial program 54.9%
Taylor expanded in y.re around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6480.6
Applied rewrites80.6%
if -6.0000000000000003e-12 < y.re < 2.4e-78Initial program 78.4%
Taylor expanded in y.im around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6482.8
Applied rewrites82.8%
Final simplification81.5%
(FPCore (x.re x.im y.re y.im) :precision binary64 (if (or (<= y.im -1.2e+175) (not (<= y.im 2.65e+70))) (/ x.im y.im) (/ (fma x.im (/ y.im y.re) x.re) y.re)))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double tmp;
if ((y_46_im <= -1.2e+175) || !(y_46_im <= 2.65e+70)) {
tmp = x_46_im / y_46_im;
} else {
tmp = fma(x_46_im, (y_46_im / y_46_re), x_46_re) / y_46_re;
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = 0.0 if ((y_46_im <= -1.2e+175) || !(y_46_im <= 2.65e+70)) tmp = Float64(x_46_im / y_46_im); else tmp = Float64(fma(x_46_im, Float64(y_46_im / y_46_re), x_46_re) / y_46_re); end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[Or[LessEqual[y$46$im, -1.2e+175], N[Not[LessEqual[y$46$im, 2.65e+70]], $MachinePrecision]], N[(x$46$im / y$46$im), $MachinePrecision], N[(N[(x$46$im * N[(y$46$im / y$46$re), $MachinePrecision] + x$46$re), $MachinePrecision] / y$46$re), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y.im \leq -1.2 \cdot 10^{+175} \lor \neg \left(y.im \leq 2.65 \cdot 10^{+70}\right):\\
\;\;\;\;\frac{x.im}{y.im}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re}\\
\end{array}
\end{array}
if y.im < -1.2e175 or 2.65e70 < y.im Initial program 41.3%
Taylor expanded in y.re around 0
lower-/.f6473.4
Applied rewrites73.4%
if -1.2e175 < y.im < 2.65e70Initial program 74.6%
Taylor expanded in y.re around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6477.4
Applied rewrites77.4%
Final simplification76.2%
(FPCore (x.re x.im y.re y.im) :precision binary64 (if (or (<= y.re -6.5e-12) (not (<= y.re 2.4e-78))) (/ 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) {
double tmp;
if ((y_46_re <= -6.5e-12) || !(y_46_re <= 2.4e-78)) {
tmp = x_46_re / y_46_re;
} else {
tmp = x_46_im / 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 ((y_46re <= (-6.5d-12)) .or. (.not. (y_46re <= 2.4d-78))) then
tmp = x_46re / y_46re
else
tmp = x_46im / 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 ((y_46_re <= -6.5e-12) || !(y_46_re <= 2.4e-78)) {
tmp = x_46_re / y_46_re;
} else {
tmp = x_46_im / y_46_im;
}
return tmp;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): tmp = 0 if (y_46_re <= -6.5e-12) or not (y_46_re <= 2.4e-78): tmp = x_46_re / y_46_re else: tmp = x_46_im / y_46_im return tmp
function code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = 0.0 if ((y_46_re <= -6.5e-12) || !(y_46_re <= 2.4e-78)) tmp = Float64(x_46_re / y_46_re); else tmp = Float64(x_46_im / 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 ((y_46_re <= -6.5e-12) || ~((y_46_re <= 2.4e-78))) tmp = x_46_re / y_46_re; else tmp = x_46_im / y_46_im; end tmp_2 = tmp; end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[Or[LessEqual[y$46$re, -6.5e-12], N[Not[LessEqual[y$46$re, 2.4e-78]], $MachinePrecision]], N[(x$46$re / y$46$re), $MachinePrecision], N[(x$46$im / y$46$im), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y.re \leq -6.5 \cdot 10^{-12} \lor \neg \left(y.re \leq 2.4 \cdot 10^{-78}\right):\\
\;\;\;\;\frac{x.re}{y.re}\\
\mathbf{else}:\\
\;\;\;\;\frac{x.im}{y.im}\\
\end{array}
\end{array}
if y.re < -6.5000000000000002e-12 or 2.4e-78 < y.re Initial program 54.9%
Taylor expanded in y.re around inf
lower-/.f6466.6
Applied rewrites66.6%
if -6.5000000000000002e-12 < y.re < 2.4e-78Initial program 78.4%
Taylor expanded in y.re around 0
lower-/.f6460.0
Applied rewrites60.0%
Final simplification63.9%
(FPCore (x.re x.im y.re y.im) :precision binary64 (/ 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_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_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_im / y_46_im;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): return x_46_im / y_46_im
function code(x_46_re, x_46_im, y_46_re, y_46_im) return 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_im / y_46_im; end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(x$46$im / y$46$im), $MachinePrecision]
\begin{array}{l}
\\
\frac{x.im}{y.im}
\end{array}
Initial program 64.4%
Taylor expanded in y.re around 0
lower-/.f6435.9
Applied rewrites35.9%
herbie shell --seed 2025037
(FPCore (x.re x.im y.re y.im)
:name "_divideComplex, real part"
:precision binary64
(/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im))))