
(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 9 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 (fma y.im y.im (* y.re y.re)))
(t_1 (fma x.re (/ y.re t_0) (* x.im (/ y.im t_0))))
(t_2 (/ (fma x.re (/ y.re y.im) x.im) y.im)))
(if (<= y.im -3.7e+98)
t_2
(if (<= y.im -5.5e-162)
t_1
(if (<= y.im 2.7e-162)
(/ (fma x.im (/ y.im y.re) x.re) y.re)
(if (<= y.im 5.2e+95) t_1 t_2))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = fma(y_46_im, y_46_im, (y_46_re * y_46_re));
double t_1 = fma(x_46_re, (y_46_re / t_0), (x_46_im * (y_46_im / t_0)));
double t_2 = fma(x_46_re, (y_46_re / y_46_im), x_46_im) / y_46_im;
double tmp;
if (y_46_im <= -3.7e+98) {
tmp = t_2;
} else if (y_46_im <= -5.5e-162) {
tmp = t_1;
} else if (y_46_im <= 2.7e-162) {
tmp = fma(x_46_im, (y_46_im / y_46_re), x_46_re) / y_46_re;
} else if (y_46_im <= 5.2e+95) {
tmp = t_1;
} else {
tmp = t_2;
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = fma(y_46_im, y_46_im, Float64(y_46_re * y_46_re)) t_1 = fma(x_46_re, Float64(y_46_re / t_0), Float64(x_46_im * Float64(y_46_im / t_0))) t_2 = Float64(fma(x_46_re, Float64(y_46_re / y_46_im), x_46_im) / y_46_im) tmp = 0.0 if (y_46_im <= -3.7e+98) tmp = t_2; elseif (y_46_im <= -5.5e-162) tmp = t_1; elseif (y_46_im <= 2.7e-162) tmp = Float64(fma(x_46_im, Float64(y_46_im / y_46_re), x_46_re) / y_46_re); elseif (y_46_im <= 5.2e+95) tmp = t_1; else tmp = t_2; end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := Block[{t$95$0 = N[(y$46$im * y$46$im + N[(y$46$re * y$46$re), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x$46$re * N[(y$46$re / t$95$0), $MachinePrecision] + N[(x$46$im * N[(y$46$im / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x$46$re * N[(y$46$re / y$46$im), $MachinePrecision] + x$46$im), $MachinePrecision] / y$46$im), $MachinePrecision]}, If[LessEqual[y$46$im, -3.7e+98], t$95$2, If[LessEqual[y$46$im, -5.5e-162], t$95$1, If[LessEqual[y$46$im, 2.7e-162], 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$im, 5.2e+95], t$95$1, t$95$2]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)\\
t_1 := \mathsf{fma}\left(x.re, \frac{y.re}{t\_0}, x.im \cdot \frac{y.im}{t\_0}\right)\\
t_2 := \frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im}\\
\mathbf{if}\;y.im \leq -3.7 \cdot 10^{+98}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;y.im \leq -5.5 \cdot 10^{-162}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y.im \leq 2.7 \cdot 10^{-162}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re}\\
\mathbf{elif}\;y.im \leq 5.2 \cdot 10^{+95}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if y.im < -3.6999999999999999e98 or 5.19999999999999981e95 < y.im Initial program 34.5%
Taylor expanded in y.im around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6485.3
Applied rewrites85.3%
if -3.6999999999999999e98 < y.im < -5.50000000000000006e-162 or 2.69999999999999984e-162 < y.im < 5.19999999999999981e95Initial program 77.8%
lift-/.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
pow2N/A
+-commutativeN/A
div-add-revN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
Applied rewrites83.3%
if -5.50000000000000006e-162 < y.im < 2.69999999999999984e-162Initial program 58.8%
Taylor expanded in y.re around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6491.4
Applied rewrites91.4%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0
(/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im)))))
(if (<= y.im -2.35e+81)
(fma (/ x.re y.im) (/ y.re y.im) (/ x.im y.im))
(if (<= y.im -3.6e-91)
t_0
(if (<= y.im 1.25e-91)
(/ (fma x.im (/ y.im y.re) x.re) y.re)
(if (<= y.im 6.5e+53) t_0 (/ (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 t_0 = ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
double tmp;
if (y_46_im <= -2.35e+81) {
tmp = fma((x_46_re / y_46_im), (y_46_re / y_46_im), (x_46_im / y_46_im));
} else if (y_46_im <= -3.6e-91) {
tmp = t_0;
} else if (y_46_im <= 1.25e-91) {
tmp = fma(x_46_im, (y_46_im / y_46_re), x_46_re) / y_46_re;
} else if (y_46_im <= 6.5e+53) {
tmp = t_0;
} 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) t_0 = 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))) tmp = 0.0 if (y_46_im <= -2.35e+81) tmp = fma(Float64(x_46_re / y_46_im), Float64(y_46_re / y_46_im), Float64(x_46_im / y_46_im)); elseif (y_46_im <= -3.6e-91) tmp = t_0; elseif (y_46_im <= 1.25e-91) tmp = Float64(fma(x_46_im, Float64(y_46_im / y_46_re), x_46_re) / y_46_re); elseif (y_46_im <= 6.5e+53) tmp = t_0; 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_] := Block[{t$95$0 = 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]}, If[LessEqual[y$46$im, -2.35e+81], N[(N[(x$46$re / y$46$im), $MachinePrecision] * N[(y$46$re / y$46$im), $MachinePrecision] + N[(x$46$im / y$46$im), $MachinePrecision]), $MachinePrecision], If[LessEqual[y$46$im, -3.6e-91], t$95$0, If[LessEqual[y$46$im, 1.25e-91], 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$im, 6.5e+53], t$95$0, 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}
t_0 := \frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}\\
\mathbf{if}\;y.im \leq -2.35 \cdot 10^{+81}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x.re}{y.im}, \frac{y.re}{y.im}, \frac{x.im}{y.im}\right)\\
\mathbf{elif}\;y.im \leq -3.6 \cdot 10^{-91}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y.im \leq 1.25 \cdot 10^{-91}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re}\\
\mathbf{elif}\;y.im \leq 6.5 \cdot 10^{+53}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im}\\
\end{array}
\end{array}
if y.im < -2.3500000000000001e81Initial program 27.2%
Taylor expanded in y.re around 0
+-commutativeN/A
pow2N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f64N/A
lower-/.f6488.5
Applied rewrites88.5%
if -2.3500000000000001e81 < y.im < -3.6e-91 or 1.24999999999999999e-91 < y.im < 6.50000000000000017e53Initial program 86.1%
if -3.6e-91 < y.im < 1.24999999999999999e-91Initial program 63.8%
Taylor expanded in y.re around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6486.6
Applied rewrites86.6%
if 6.50000000000000017e53 < y.im Initial program 45.0%
Taylor expanded in y.im around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6475.3
Applied rewrites75.3%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0
(/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im))))
(t_1 (/ (fma x.re (/ y.re y.im) x.im) y.im)))
(if (<= y.im -1.05e+84)
t_1
(if (<= y.im -3.6e-91)
t_0
(if (<= y.im 1.25e-91)
(/ (fma x.im (/ y.im y.re) x.re) y.re)
(if (<= y.im 6.5e+53) 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)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
double t_1 = fma(x_46_re, (y_46_re / y_46_im), x_46_im) / y_46_im;
double tmp;
if (y_46_im <= -1.05e+84) {
tmp = t_1;
} else if (y_46_im <= -3.6e-91) {
tmp = t_0;
} else if (y_46_im <= 1.25e-91) {
tmp = fma(x_46_im, (y_46_im / y_46_re), x_46_re) / y_46_re;
} else if (y_46_im <= 6.5e+53) {
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)) / Float64(Float64(y_46_re * y_46_re) + Float64(y_46_im * y_46_im))) t_1 = Float64(fma(x_46_re, Float64(y_46_re / y_46_im), x_46_im) / y_46_im) tmp = 0.0 if (y_46_im <= -1.05e+84) tmp = t_1; elseif (y_46_im <= -3.6e-91) tmp = t_0; elseif (y_46_im <= 1.25e-91) tmp = Float64(fma(x_46_im, Float64(y_46_im / y_46_re), x_46_re) / y_46_re); elseif (y_46_im <= 6.5e+53) 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[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x$46$re * N[(y$46$re / y$46$im), $MachinePrecision] + x$46$im), $MachinePrecision] / y$46$im), $MachinePrecision]}, If[LessEqual[y$46$im, -1.05e+84], t$95$1, If[LessEqual[y$46$im, -3.6e-91], t$95$0, If[LessEqual[y$46$im, 1.25e-91], 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$im, 6.5e+53], 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}{y.re \cdot y.re + y.im \cdot y.im}\\
t_1 := \frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{y.im}\\
\mathbf{if}\;y.im \leq -1.05 \cdot 10^{+84}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y.im \leq -3.6 \cdot 10^{-91}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y.im \leq 1.25 \cdot 10^{-91}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x.im, \frac{y.im}{y.re}, x.re\right)}{y.re}\\
\mathbf{elif}\;y.im \leq 6.5 \cdot 10^{+53}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y.im < -1.05000000000000009e84 or 6.50000000000000017e53 < y.im Initial program 35.5%
Taylor expanded in y.im around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6481.7
Applied rewrites81.7%
if -1.05000000000000009e84 < y.im < -3.6e-91 or 1.24999999999999999e-91 < y.im < 6.50000000000000017e53Initial program 86.3%
if -3.6e-91 < y.im < 1.24999999999999999e-91Initial program 63.8%
Taylor expanded in y.re around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6486.6
Applied rewrites86.6%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(if (<= y.im -1.32e+98)
(/ x.im y.im)
(if (<= y.im -3.3e-100)
(* x.im (/ y.im (fma y.im y.im (* y.re y.re))))
(if (<= y.im 1.4e-84)
(/ x.re y.re)
(if (<= y.im 4.6e+152)
(/ (fma y.im x.im (* y.re x.re)) (* y.im 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_im <= -1.32e+98) {
tmp = x_46_im / y_46_im;
} else if (y_46_im <= -3.3e-100) {
tmp = x_46_im * (y_46_im / fma(y_46_im, y_46_im, (y_46_re * y_46_re)));
} else if (y_46_im <= 1.4e-84) {
tmp = x_46_re / y_46_re;
} else if (y_46_im <= 4.6e+152) {
tmp = fma(y_46_im, x_46_im, (y_46_re * x_46_re)) / (y_46_im * y_46_im);
} 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_im <= -1.32e+98) tmp = Float64(x_46_im / y_46_im); elseif (y_46_im <= -3.3e-100) tmp = Float64(x_46_im * Float64(y_46_im / fma(y_46_im, y_46_im, Float64(y_46_re * y_46_re)))); elseif (y_46_im <= 1.4e-84) tmp = Float64(x_46_re / y_46_re); elseif (y_46_im <= 4.6e+152) tmp = Float64(fma(y_46_im, x_46_im, Float64(y_46_re * x_46_re)) / Float64(y_46_im * y_46_im)); else tmp = Float64(x_46_im / y_46_im); end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[LessEqual[y$46$im, -1.32e+98], N[(x$46$im / y$46$im), $MachinePrecision], If[LessEqual[y$46$im, -3.3e-100], N[(x$46$im * N[(y$46$im / N[(y$46$im * y$46$im + N[(y$46$re * y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y$46$im, 1.4e-84], N[(x$46$re / y$46$re), $MachinePrecision], If[LessEqual[y$46$im, 4.6e+152], N[(N[(y$46$im * x$46$im + N[(y$46$re * x$46$re), $MachinePrecision]), $MachinePrecision] / N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision], N[(x$46$im / y$46$im), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y.im \leq -1.32 \cdot 10^{+98}:\\
\;\;\;\;\frac{x.im}{y.im}\\
\mathbf{elif}\;y.im \leq -3.3 \cdot 10^{-100}:\\
\;\;\;\;x.im \cdot \frac{y.im}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}\\
\mathbf{elif}\;y.im \leq 1.4 \cdot 10^{-84}:\\
\;\;\;\;\frac{x.re}{y.re}\\
\mathbf{elif}\;y.im \leq 4.6 \cdot 10^{+152}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y.im, x.im, y.re \cdot x.re\right)}{y.im \cdot y.im}\\
\mathbf{else}:\\
\;\;\;\;\frac{x.im}{y.im}\\
\end{array}
\end{array}
if y.im < -1.3200000000000001e98 or 4.5999999999999997e152 < y.im Initial program 28.3%
Taylor expanded in y.re around 0
lower-/.f6476.7
Applied rewrites76.7%
if -1.3200000000000001e98 < y.im < -3.29999999999999996e-100Initial program 80.5%
Taylor expanded in x.re around 0
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lift-*.f6460.1
Applied rewrites60.1%
if -3.29999999999999996e-100 < y.im < 1.39999999999999991e-84Initial program 63.7%
Taylor expanded in y.re around inf
lower-/.f6470.7
Applied rewrites70.7%
if 1.39999999999999991e-84 < y.im < 4.5999999999999997e152Initial program 73.8%
Taylor expanded in y.im around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6456.7
Applied rewrites56.7%
Taylor expanded in y.im around 0
div-addN/A
associate-*l/N/A
*-commutativeN/A
lower-/.f64N/A
*-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
pow2N/A
lower-*.f6454.2
Applied rewrites54.2%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(if (<= y.im -9e-12)
(/ x.im y.im)
(if (<= y.im 1.4e-84)
(/ x.re y.re)
(if (<= y.im 4.6e+152)
(/ (fma y.im x.im (* y.re x.re)) (* y.im 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_im <= -9e-12) {
tmp = x_46_im / y_46_im;
} else if (y_46_im <= 1.4e-84) {
tmp = x_46_re / y_46_re;
} else if (y_46_im <= 4.6e+152) {
tmp = fma(y_46_im, x_46_im, (y_46_re * x_46_re)) / (y_46_im * y_46_im);
} 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_im <= -9e-12) tmp = Float64(x_46_im / y_46_im); elseif (y_46_im <= 1.4e-84) tmp = Float64(x_46_re / y_46_re); elseif (y_46_im <= 4.6e+152) tmp = Float64(fma(y_46_im, x_46_im, Float64(y_46_re * x_46_re)) / Float64(y_46_im * y_46_im)); else tmp = Float64(x_46_im / y_46_im); end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[LessEqual[y$46$im, -9e-12], N[(x$46$im / y$46$im), $MachinePrecision], If[LessEqual[y$46$im, 1.4e-84], N[(x$46$re / y$46$re), $MachinePrecision], If[LessEqual[y$46$im, 4.6e+152], N[(N[(y$46$im * x$46$im + N[(y$46$re * x$46$re), $MachinePrecision]), $MachinePrecision] / N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision], N[(x$46$im / y$46$im), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y.im \leq -9 \cdot 10^{-12}:\\
\;\;\;\;\frac{x.im}{y.im}\\
\mathbf{elif}\;y.im \leq 1.4 \cdot 10^{-84}:\\
\;\;\;\;\frac{x.re}{y.re}\\
\mathbf{elif}\;y.im \leq 4.6 \cdot 10^{+152}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y.im, x.im, y.re \cdot x.re\right)}{y.im \cdot y.im}\\
\mathbf{else}:\\
\;\;\;\;\frac{x.im}{y.im}\\
\end{array}
\end{array}
if y.im < -8.99999999999999962e-12 or 4.5999999999999997e152 < y.im Initial program 39.0%
Taylor expanded in y.re around 0
lower-/.f6472.0
Applied rewrites72.0%
if -8.99999999999999962e-12 < y.im < 1.39999999999999991e-84Initial program 66.2%
Taylor expanded in y.re around inf
lower-/.f6466.4
Applied rewrites66.4%
if 1.39999999999999991e-84 < y.im < 4.5999999999999997e152Initial program 73.8%
Taylor expanded in y.im around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6456.7
Applied rewrites56.7%
Taylor expanded in y.im around 0
div-addN/A
associate-*l/N/A
*-commutativeN/A
lower-/.f64N/A
*-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
pow2N/A
lower-*.f6454.2
Applied rewrites54.2%
(FPCore (x.re x.im y.re y.im) :precision binary64 (if (or (<= y.im -7e-12) (not (<= y.im 1.55e+84))) (/ (fma x.re (/ y.re y.im) 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 <= -7e-12) || !(y_46_im <= 1.55e+84)) {
tmp = fma(x_46_re, (y_46_re / y_46_im), 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 <= -7e-12) || !(y_46_im <= 1.55e+84)) tmp = Float64(fma(x_46_re, Float64(y_46_re / y_46_im), 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, -7e-12], N[Not[LessEqual[y$46$im, 1.55e+84]], $MachinePrecision]], N[(N[(x$46$re * N[(y$46$re / y$46$im), $MachinePrecision] + x$46$im), $MachinePrecision] / 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 -7 \cdot 10^{-12} \lor \neg \left(y.im \leq 1.55 \cdot 10^{+84}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(x.re, \frac{y.re}{y.im}, x.im\right)}{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 < -7.0000000000000001e-12 or 1.55000000000000001e84 < y.im Initial program 42.8%
Taylor expanded in y.im around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6481.8
Applied rewrites81.8%
if -7.0000000000000001e-12 < y.im < 1.55000000000000001e84Initial program 69.1%
Taylor expanded in y.re around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6478.0
Applied rewrites78.0%
Final simplification79.6%
(FPCore (x.re x.im y.re y.im) :precision binary64 (if (or (<= y.im -30000.0) (not (<= y.im 3.5e+99))) (/ 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 <= -30000.0) || !(y_46_im <= 3.5e+99)) {
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 <= -30000.0) || !(y_46_im <= 3.5e+99)) 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, -30000.0], N[Not[LessEqual[y$46$im, 3.5e+99]], $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 -30000 \lor \neg \left(y.im \leq 3.5 \cdot 10^{+99}\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 < -3e4 or 3.4999999999999998e99 < y.im Initial program 41.8%
Taylor expanded in y.re around 0
lower-/.f6470.0
Applied rewrites70.0%
if -3e4 < y.im < 3.4999999999999998e99Initial program 68.6%
Taylor expanded in y.re around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f6476.5
Applied rewrites76.5%
Final simplification73.9%
(FPCore (x.re x.im y.re y.im) :precision binary64 (if (or (<= y.im -9e-12) (not (<= y.im 2.7e+28))) (/ x.im y.im) (/ 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 <= -9e-12) || !(y_46_im <= 2.7e+28)) {
tmp = x_46_im / y_46_im;
} else {
tmp = x_46_re / y_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 ((y_46im <= (-9d-12)) .or. (.not. (y_46im <= 2.7d+28))) then
tmp = x_46im / y_46im
else
tmp = x_46re / y_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 ((y_46_im <= -9e-12) || !(y_46_im <= 2.7e+28)) {
tmp = x_46_im / y_46_im;
} else {
tmp = x_46_re / y_46_re;
}
return tmp;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): tmp = 0 if (y_46_im <= -9e-12) or not (y_46_im <= 2.7e+28): tmp = x_46_im / y_46_im 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_im <= -9e-12) || !(y_46_im <= 2.7e+28)) tmp = Float64(x_46_im / y_46_im); else tmp = Float64(x_46_re / y_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 ((y_46_im <= -9e-12) || ~((y_46_im <= 2.7e+28))) tmp = x_46_im / y_46_im; else tmp = x_46_re / y_46_re; end tmp_2 = tmp; end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[Or[LessEqual[y$46$im, -9e-12], N[Not[LessEqual[y$46$im, 2.7e+28]], $MachinePrecision]], N[(x$46$im / y$46$im), $MachinePrecision], N[(x$46$re / y$46$re), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y.im \leq -9 \cdot 10^{-12} \lor \neg \left(y.im \leq 2.7 \cdot 10^{+28}\right):\\
\;\;\;\;\frac{x.im}{y.im}\\
\mathbf{else}:\\
\;\;\;\;\frac{x.re}{y.re}\\
\end{array}
\end{array}
if y.im < -8.99999999999999962e-12 or 2.7000000000000002e28 < y.im Initial program 44.2%
Taylor expanded in y.re around 0
lower-/.f6466.2
Applied rewrites66.2%
if -8.99999999999999962e-12 < y.im < 2.7000000000000002e28Initial program 69.4%
Taylor expanded in y.re around inf
lower-/.f6463.4
Applied rewrites63.4%
Final simplification64.7%
(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 57.8%
Taylor expanded in y.re around 0
lower-/.f6441.3
Applied rewrites41.3%
herbie shell --seed 2025061
(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))))