
(FPCore (x.re x.im y.re y.im) :precision binary64 (/ (- (* x.im y.re) (* x.re 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_im * y_46_re) - (x_46_re * 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_46im * y_46re) - (x_46re * 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_im * y_46_re) - (x_46_re * 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_im * y_46_re) - (x_46_re * 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_im * y_46_re) - Float64(x_46_re * 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_im * y_46_re) - (x_46_re * 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$im * y$46$re), $MachinePrecision] - N[(x$46$re * 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.im \cdot y.re - x.re \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}
\end{array}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x.re x.im y.re y.im) :precision binary64 (/ (- (* x.im y.re) (* x.re 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_im * y_46_re) - (x_46_re * 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_46im * y_46re) - (x_46re * 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_im * y_46_re) - (x_46_re * 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_im * y_46_re) - (x_46_re * 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_im * y_46_re) - Float64(x_46_re * 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_im * y_46_re) - (x_46_re * 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$im * y$46$re), $MachinePrecision] - N[(x$46$re * 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.im \cdot y.re - x.re \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.im y.re) (* x.re y.im)) (fma y.re y.re (* y.im y.im)))))
(if (<= y.im -1.65e+131)
(/ (fma x.im (/ y.re y.im) (- x.re)) y.im)
(if (<= y.im -4e-110)
t_0
(if (<= y.im 8.5e-78)
(/ (- x.im (/ (* y.im x.re) y.re)) y.re)
(if (<= y.im 2.55e+70)
t_0
(fma (/ x.im y.im) (/ y.re y.im) (/ (- x.re) 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_im * y_46_re) - (x_46_re * y_46_im)) / fma(y_46_re, y_46_re, (y_46_im * y_46_im));
double tmp;
if (y_46_im <= -1.65e+131) {
tmp = fma(x_46_im, (y_46_re / y_46_im), -x_46_re) / y_46_im;
} else if (y_46_im <= -4e-110) {
tmp = t_0;
} else if (y_46_im <= 8.5e-78) {
tmp = (x_46_im - ((y_46_im * x_46_re) / y_46_re)) / y_46_re;
} else if (y_46_im <= 2.55e+70) {
tmp = t_0;
} else {
tmp = fma((x_46_im / y_46_im), (y_46_re / y_46_im), (-x_46_re / 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_im * y_46_re) - Float64(x_46_re * y_46_im)) / fma(y_46_re, y_46_re, Float64(y_46_im * y_46_im))) tmp = 0.0 if (y_46_im <= -1.65e+131) tmp = Float64(fma(x_46_im, Float64(y_46_re / y_46_im), Float64(-x_46_re)) / y_46_im); elseif (y_46_im <= -4e-110) tmp = t_0; elseif (y_46_im <= 8.5e-78) tmp = Float64(Float64(x_46_im - Float64(Float64(y_46_im * x_46_re) / y_46_re)) / y_46_re); elseif (y_46_im <= 2.55e+70) tmp = t_0; else tmp = fma(Float64(x_46_im / y_46_im), Float64(y_46_re / y_46_im), Float64(Float64(-x_46_re) / 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$im * y$46$re), $MachinePrecision] - N[(x$46$re * y$46$im), $MachinePrecision]), $MachinePrecision] / N[(y$46$re * y$46$re + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y$46$im, -1.65e+131], N[(N[(x$46$im * N[(y$46$re / y$46$im), $MachinePrecision] + (-x$46$re)), $MachinePrecision] / y$46$im), $MachinePrecision], If[LessEqual[y$46$im, -4e-110], t$95$0, If[LessEqual[y$46$im, 8.5e-78], N[(N[(x$46$im - N[(N[(y$46$im * x$46$re), $MachinePrecision] / y$46$re), $MachinePrecision]), $MachinePrecision] / y$46$re), $MachinePrecision], If[LessEqual[y$46$im, 2.55e+70], t$95$0, N[(N[(x$46$im / y$46$im), $MachinePrecision] * N[(y$46$re / y$46$im), $MachinePrecision] + N[((-x$46$re) / y$46$im), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x.im \cdot y.re - x.re \cdot y.im}{\mathsf{fma}\left(y.re, y.re, y.im \cdot y.im\right)}\\
\mathbf{if}\;y.im \leq -1.65 \cdot 10^{+131}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x.im, \frac{y.re}{y.im}, -x.re\right)}{y.im}\\
\mathbf{elif}\;y.im \leq -4 \cdot 10^{-110}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y.im \leq 8.5 \cdot 10^{-78}:\\
\;\;\;\;\frac{x.im - \frac{y.im \cdot x.re}{y.re}}{y.re}\\
\mathbf{elif}\;y.im \leq 2.55 \cdot 10^{+70}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x.im}{y.im}, \frac{y.re}{y.im}, \frac{-x.re}{y.im}\right)\\
\end{array}
\end{array}
if y.im < -1.6499999999999999e131Initial program 31.8%
Taylor expanded in y.im around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6492.4
Applied rewrites92.4%
if -1.6499999999999999e131 < y.im < -4.0000000000000002e-110 or 8.49999999999999957e-78 < y.im < 2.55000000000000007e70Initial program 83.8%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lift-*.f6483.8
Applied rewrites83.8%
if -4.0000000000000002e-110 < y.im < 8.49999999999999957e-78Initial program 64.3%
Taylor expanded in y.re around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
times-fracN/A
mul-1-negN/A
mul-1-negN/A
frac-2negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6480.9
Applied rewrites80.9%
if 2.55000000000000007e70 < y.im Initial program 41.9%
Taylor expanded in y.re around 0
+-commutativeN/A
pow2N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6487.0
Applied rewrites87.0%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (/ (- (* x.im y.re) (* x.re y.im)) (fma y.re y.re (* y.im y.im))))
(t_1 (/ (fma x.im (/ y.re y.im) (- x.re)) y.im)))
(if (<= y.im -1.65e+131)
t_1
(if (<= y.im -4e-110)
t_0
(if (<= y.im 8.5e-78)
(/ (- x.im (/ (* y.im x.re) y.re)) y.re)
(if (<= y.im 2.55e+70) 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_im * y_46_re) - (x_46_re * 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_re / y_46_im), -x_46_re) / y_46_im;
double tmp;
if (y_46_im <= -1.65e+131) {
tmp = t_1;
} else if (y_46_im <= -4e-110) {
tmp = t_0;
} else if (y_46_im <= 8.5e-78) {
tmp = (x_46_im - ((y_46_im * x_46_re) / y_46_re)) / y_46_re;
} else if (y_46_im <= 2.55e+70) {
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_im * y_46_re) - Float64(x_46_re * 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_re / y_46_im), Float64(-x_46_re)) / y_46_im) tmp = 0.0 if (y_46_im <= -1.65e+131) tmp = t_1; elseif (y_46_im <= -4e-110) tmp = t_0; elseif (y_46_im <= 8.5e-78) tmp = Float64(Float64(x_46_im - Float64(Float64(y_46_im * x_46_re) / y_46_re)) / y_46_re); elseif (y_46_im <= 2.55e+70) 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$im * y$46$re), $MachinePrecision] - N[(x$46$re * 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$re / y$46$im), $MachinePrecision] + (-x$46$re)), $MachinePrecision] / y$46$im), $MachinePrecision]}, If[LessEqual[y$46$im, -1.65e+131], t$95$1, If[LessEqual[y$46$im, -4e-110], t$95$0, If[LessEqual[y$46$im, 8.5e-78], N[(N[(x$46$im - N[(N[(y$46$im * x$46$re), $MachinePrecision] / y$46$re), $MachinePrecision]), $MachinePrecision] / y$46$re), $MachinePrecision], If[LessEqual[y$46$im, 2.55e+70], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x.im \cdot y.re - x.re \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.re}{y.im}, -x.re\right)}{y.im}\\
\mathbf{if}\;y.im \leq -1.65 \cdot 10^{+131}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y.im \leq -4 \cdot 10^{-110}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y.im \leq 8.5 \cdot 10^{-78}:\\
\;\;\;\;\frac{x.im - \frac{y.im \cdot x.re}{y.re}}{y.re}\\
\mathbf{elif}\;y.im \leq 2.55 \cdot 10^{+70}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y.im < -1.6499999999999999e131 or 2.55000000000000007e70 < y.im Initial program 38.0%
Taylor expanded in y.im around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6489.1
Applied rewrites89.1%
if -1.6499999999999999e131 < y.im < -4.0000000000000002e-110 or 8.49999999999999957e-78 < y.im < 2.55000000000000007e70Initial program 83.8%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow2N/A
lower-fma.f64N/A
pow2N/A
lift-*.f6483.8
Applied rewrites83.8%
if -4.0000000000000002e-110 < y.im < 8.49999999999999957e-78Initial program 64.3%
Taylor expanded in y.re around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
times-fracN/A
mul-1-negN/A
mul-1-negN/A
frac-2negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6480.9
Applied rewrites80.9%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(if (<= y.re -2e+137)
(/ x.im y.re)
(if (<= y.re 2.1e-269)
(/ (- x.re) y.im)
(if (<= y.re 3.4e-75)
(/ (- (* x.im y.re) (* x.re y.im)) (* y.im y.im))
(if (<= y.re 1e+138)
(* x.im (/ y.re (fma y.im y.im (* y.re y.re))))
(/ x.im 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 <= -2e+137) {
tmp = x_46_im / y_46_re;
} else if (y_46_re <= 2.1e-269) {
tmp = -x_46_re / y_46_im;
} else if (y_46_re <= 3.4e-75) {
tmp = ((x_46_im * y_46_re) - (x_46_re * y_46_im)) / (y_46_im * y_46_im);
} else if (y_46_re <= 1e+138) {
tmp = x_46_im * (y_46_re / fma(y_46_im, y_46_im, (y_46_re * y_46_re)));
} else {
tmp = x_46_im / 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 <= -2e+137) tmp = Float64(x_46_im / y_46_re); elseif (y_46_re <= 2.1e-269) tmp = Float64(Float64(-x_46_re) / y_46_im); elseif (y_46_re <= 3.4e-75) tmp = Float64(Float64(Float64(x_46_im * y_46_re) - Float64(x_46_re * y_46_im)) / Float64(y_46_im * y_46_im)); elseif (y_46_re <= 1e+138) tmp = Float64(x_46_im * Float64(y_46_re / fma(y_46_im, y_46_im, Float64(y_46_re * y_46_re)))); else tmp = Float64(x_46_im / 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, -2e+137], N[(x$46$im / y$46$re), $MachinePrecision], If[LessEqual[y$46$re, 2.1e-269], N[((-x$46$re) / y$46$im), $MachinePrecision], If[LessEqual[y$46$re, 3.4e-75], N[(N[(N[(x$46$im * y$46$re), $MachinePrecision] - N[(x$46$re * y$46$im), $MachinePrecision]), $MachinePrecision] / N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision], If[LessEqual[y$46$re, 1e+138], N[(x$46$im * N[(y$46$re / N[(y$46$im * y$46$im + N[(y$46$re * y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$46$im / y$46$re), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y.re \leq -2 \cdot 10^{+137}:\\
\;\;\;\;\frac{x.im}{y.re}\\
\mathbf{elif}\;y.re \leq 2.1 \cdot 10^{-269}:\\
\;\;\;\;\frac{-x.re}{y.im}\\
\mathbf{elif}\;y.re \leq 3.4 \cdot 10^{-75}:\\
\;\;\;\;\frac{x.im \cdot y.re - x.re \cdot y.im}{y.im \cdot y.im}\\
\mathbf{elif}\;y.re \leq 10^{+138}:\\
\;\;\;\;x.im \cdot \frac{y.re}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{x.im}{y.re}\\
\end{array}
\end{array}
if y.re < -2.0000000000000001e137 or 1e138 < y.re Initial program 30.6%
Taylor expanded in y.re around inf
lower-/.f6477.1
Applied rewrites77.1%
if -2.0000000000000001e137 < y.re < 2.10000000000000005e-269Initial program 64.7%
Taylor expanded in y.re around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6463.9
Applied rewrites63.9%
if 2.10000000000000005e-269 < y.re < 3.40000000000000015e-75Initial program 77.7%
Taylor expanded in y.re around 0
pow2N/A
lift-*.f6473.2
Applied rewrites73.2%
if 3.40000000000000015e-75 < y.re < 1e138Initial program 72.2%
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-*.f6464.7
Applied rewrites64.7%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(if (<= y.re -8.5e+135)
(/ (- x.im (* y.im (/ x.re y.re))) y.re)
(if (<= y.re 1.02e-38)
(/ (fma x.im (/ y.re y.im) (- x.re)) y.im)
(if (<= y.re 2.7e+96)
(* x.im (/ y.re (fma y.im y.im (* y.re y.re))))
(/ (- x.im (* x.re (/ y.im y.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 <= -8.5e+135) {
tmp = (x_46_im - (y_46_im * (x_46_re / y_46_re))) / y_46_re;
} else if (y_46_re <= 1.02e-38) {
tmp = fma(x_46_im, (y_46_re / y_46_im), -x_46_re) / y_46_im;
} else if (y_46_re <= 2.7e+96) {
tmp = x_46_im * (y_46_re / fma(y_46_im, y_46_im, (y_46_re * y_46_re)));
} else {
tmp = (x_46_im - (x_46_re * (y_46_im / y_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 <= -8.5e+135) tmp = Float64(Float64(x_46_im - Float64(y_46_im * Float64(x_46_re / y_46_re))) / y_46_re); elseif (y_46_re <= 1.02e-38) tmp = Float64(fma(x_46_im, Float64(y_46_re / y_46_im), Float64(-x_46_re)) / y_46_im); elseif (y_46_re <= 2.7e+96) tmp = Float64(x_46_im * Float64(y_46_re / fma(y_46_im, y_46_im, Float64(y_46_re * y_46_re)))); else tmp = Float64(Float64(x_46_im - Float64(x_46_re * Float64(y_46_im / y_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, -8.5e+135], N[(N[(x$46$im - N[(y$46$im * N[(x$46$re / y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y$46$re), $MachinePrecision], If[LessEqual[y$46$re, 1.02e-38], N[(N[(x$46$im * N[(y$46$re / y$46$im), $MachinePrecision] + (-x$46$re)), $MachinePrecision] / y$46$im), $MachinePrecision], If[LessEqual[y$46$re, 2.7e+96], N[(x$46$im * N[(y$46$re / N[(y$46$im * y$46$im + N[(y$46$re * y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x$46$im - N[(x$46$re * N[(y$46$im / y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y$46$re), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y.re \leq -8.5 \cdot 10^{+135}:\\
\;\;\;\;\frac{x.im - y.im \cdot \frac{x.re}{y.re}}{y.re}\\
\mathbf{elif}\;y.re \leq 1.02 \cdot 10^{-38}:\\
\;\;\;\;\frac{\mathsf{fma}\left(x.im, \frac{y.re}{y.im}, -x.re\right)}{y.im}\\
\mathbf{elif}\;y.re \leq 2.7 \cdot 10^{+96}:\\
\;\;\;\;x.im \cdot \frac{y.re}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{x.im - x.re \cdot \frac{y.im}{y.re}}{y.re}\\
\end{array}
\end{array}
if y.re < -8.49999999999999992e135Initial program 29.4%
Taylor expanded in y.re around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
times-fracN/A
mul-1-negN/A
mul-1-negN/A
frac-2negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6475.9
Applied rewrites75.9%
lift-*.f64N/A
lift-/.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6490.6
Applied rewrites90.6%
if -8.49999999999999992e135 < y.re < 1.01999999999999998e-38Initial program 68.1%
Taylor expanded in y.im around inf
lower-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6480.6
Applied rewrites80.6%
if 1.01999999999999998e-38 < y.re < 2.70000000000000022e96Initial program 81.9%
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-*.f6471.4
Applied rewrites71.4%
if 2.70000000000000022e96 < y.re Initial program 39.1%
Taylor expanded in y.re around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
times-fracN/A
mul-1-negN/A
mul-1-negN/A
frac-2negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6479.6
Applied rewrites79.6%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6479.9
Applied rewrites79.9%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(if (<= y.re -2e+137)
(/ x.im y.re)
(if (<= y.re 3.9e-45)
(/ (- x.re) y.im)
(if (<= y.re 1e+138)
(* x.im (/ y.re (fma y.im y.im (* y.re y.re))))
(/ x.im 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 <= -2e+137) {
tmp = x_46_im / y_46_re;
} else if (y_46_re <= 3.9e-45) {
tmp = -x_46_re / y_46_im;
} else if (y_46_re <= 1e+138) {
tmp = x_46_im * (y_46_re / fma(y_46_im, y_46_im, (y_46_re * y_46_re)));
} else {
tmp = x_46_im / 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 <= -2e+137) tmp = Float64(x_46_im / y_46_re); elseif (y_46_re <= 3.9e-45) tmp = Float64(Float64(-x_46_re) / y_46_im); elseif (y_46_re <= 1e+138) tmp = Float64(x_46_im * Float64(y_46_re / fma(y_46_im, y_46_im, Float64(y_46_re * y_46_re)))); else tmp = Float64(x_46_im / 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, -2e+137], N[(x$46$im / y$46$re), $MachinePrecision], If[LessEqual[y$46$re, 3.9e-45], N[((-x$46$re) / y$46$im), $MachinePrecision], If[LessEqual[y$46$re, 1e+138], N[(x$46$im * N[(y$46$re / N[(y$46$im * y$46$im + N[(y$46$re * y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$46$im / y$46$re), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y.re \leq -2 \cdot 10^{+137}:\\
\;\;\;\;\frac{x.im}{y.re}\\
\mathbf{elif}\;y.re \leq 3.9 \cdot 10^{-45}:\\
\;\;\;\;\frac{-x.re}{y.im}\\
\mathbf{elif}\;y.re \leq 10^{+138}:\\
\;\;\;\;x.im \cdot \frac{y.re}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{x.im}{y.re}\\
\end{array}
\end{array}
if y.re < -2.0000000000000001e137 or 1e138 < y.re Initial program 30.6%
Taylor expanded in y.re around inf
lower-/.f6477.1
Applied rewrites77.1%
if -2.0000000000000001e137 < y.re < 3.9e-45Initial program 67.5%
Taylor expanded in y.re around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6462.7
Applied rewrites62.7%
if 3.9e-45 < y.re < 1e138Initial program 76.1%
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-*.f6468.0
Applied rewrites68.0%
(FPCore (x.re x.im y.re y.im) :precision binary64 (if (or (<= y.im -3.3e+91) (not (<= y.im 1.8e+72))) (/ (- x.re) y.im) (/ (- x.im (* x.re (/ y.im y.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 <= -3.3e+91) || !(y_46_im <= 1.8e+72)) {
tmp = -x_46_re / y_46_im;
} else {
tmp = (x_46_im - (x_46_re * (y_46_im / y_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 <= (-3.3d+91)) .or. (.not. (y_46im <= 1.8d+72))) then
tmp = -x_46re / y_46im
else
tmp = (x_46im - (x_46re * (y_46im / y_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 <= -3.3e+91) || !(y_46_im <= 1.8e+72)) {
tmp = -x_46_re / y_46_im;
} else {
tmp = (x_46_im - (x_46_re * (y_46_im / y_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 <= -3.3e+91) or not (y_46_im <= 1.8e+72): tmp = -x_46_re / y_46_im else: tmp = (x_46_im - (x_46_re * (y_46_im / y_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 <= -3.3e+91) || !(y_46_im <= 1.8e+72)) tmp = Float64(Float64(-x_46_re) / y_46_im); else tmp = Float64(Float64(x_46_im - Float64(x_46_re * Float64(y_46_im / y_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 <= -3.3e+91) || ~((y_46_im <= 1.8e+72))) tmp = -x_46_re / y_46_im; else tmp = (x_46_im - (x_46_re * (y_46_im / y_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, -3.3e+91], N[Not[LessEqual[y$46$im, 1.8e+72]], $MachinePrecision]], N[((-x$46$re) / y$46$im), $MachinePrecision], N[(N[(x$46$im - N[(x$46$re * N[(y$46$im / y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / y$46$re), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y.im \leq -3.3 \cdot 10^{+91} \lor \neg \left(y.im \leq 1.8 \cdot 10^{+72}\right):\\
\;\;\;\;\frac{-x.re}{y.im}\\
\mathbf{else}:\\
\;\;\;\;\frac{x.im - x.re \cdot \frac{y.im}{y.re}}{y.re}\\
\end{array}
\end{array}
if y.im < -3.30000000000000017e91 or 1.80000000000000017e72 < y.im Initial program 41.1%
Taylor expanded in y.re around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6477.2
Applied rewrites77.2%
if -3.30000000000000017e91 < y.im < 1.80000000000000017e72Initial program 73.2%
Taylor expanded in y.re around inf
lower-/.f64N/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
times-fracN/A
mul-1-negN/A
mul-1-negN/A
frac-2negN/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6467.3
Applied rewrites67.3%
lift-*.f64N/A
lift-/.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6467.9
Applied rewrites67.9%
Final simplification71.6%
(FPCore (x.re x.im y.re y.im) :precision binary64 (if (or (<= y.re -2e+137) (not (<= y.re 5.6e-38))) (/ x.im y.re) (/ (- x.re) y.im)))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double tmp;
if ((y_46_re <= -2e+137) || !(y_46_re <= 5.6e-38)) {
tmp = x_46_im / y_46_re;
} else {
tmp = -x_46_re / y_46_im;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x_46re, x_46im, y_46re, y_46im)
use fmin_fmax_functions
real(8), intent (in) :: x_46re
real(8), intent (in) :: x_46im
real(8), intent (in) :: y_46re
real(8), intent (in) :: y_46im
real(8) :: tmp
if ((y_46re <= (-2d+137)) .or. (.not. (y_46re <= 5.6d-38))) then
tmp = x_46im / y_46re
else
tmp = -x_46re / y_46im
end if
code = tmp
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double tmp;
if ((y_46_re <= -2e+137) || !(y_46_re <= 5.6e-38)) {
tmp = x_46_im / y_46_re;
} else {
tmp = -x_46_re / y_46_im;
}
return tmp;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): tmp = 0 if (y_46_re <= -2e+137) or not (y_46_re <= 5.6e-38): tmp = x_46_im / y_46_re else: tmp = -x_46_re / y_46_im return tmp
function code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = 0.0 if ((y_46_re <= -2e+137) || !(y_46_re <= 5.6e-38)) tmp = Float64(x_46_im / y_46_re); else tmp = Float64(Float64(-x_46_re) / y_46_im); end return tmp end
function tmp_2 = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = 0.0; if ((y_46_re <= -2e+137) || ~((y_46_re <= 5.6e-38))) tmp = x_46_im / y_46_re; else tmp = -x_46_re / y_46_im; end tmp_2 = tmp; end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[Or[LessEqual[y$46$re, -2e+137], N[Not[LessEqual[y$46$re, 5.6e-38]], $MachinePrecision]], N[(x$46$im / y$46$re), $MachinePrecision], N[((-x$46$re) / y$46$im), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y.re \leq -2 \cdot 10^{+137} \lor \neg \left(y.re \leq 5.6 \cdot 10^{-38}\right):\\
\;\;\;\;\frac{x.im}{y.re}\\
\mathbf{else}:\\
\;\;\;\;\frac{-x.re}{y.im}\\
\end{array}
\end{array}
if y.re < -2.0000000000000001e137 or 5.6e-38 < y.re Initial program 47.8%
Taylor expanded in y.re around inf
lower-/.f6468.6
Applied rewrites68.6%
if -2.0000000000000001e137 < y.re < 5.6e-38Initial program 67.9%
Taylor expanded in y.re around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6462.6
Applied rewrites62.6%
Final simplification64.8%
(FPCore (x.re x.im y.re y.im) :precision binary64 (/ x.im y.re))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return x_46_im / y_46_re;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x_46re, x_46im, y_46re, y_46im)
use fmin_fmax_functions
real(8), intent (in) :: x_46re
real(8), intent (in) :: x_46im
real(8), intent (in) :: y_46re
real(8), intent (in) :: y_46im
code = x_46im / y_46re
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return x_46_im / y_46_re;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): return x_46_im / y_46_re
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(x_46_im / y_46_re) end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = x_46_im / y_46_re; end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(x$46$im / y$46$re), $MachinePrecision]
\begin{array}{l}
\\
\frac{x.im}{y.re}
\end{array}
Initial program 60.5%
Taylor expanded in y.re around inf
lower-/.f6437.0
Applied rewrites37.0%
herbie shell --seed 2025082
(FPCore (x.re x.im y.re y.im)
:name "_divideComplex, imaginary part"
:precision binary64
(/ (- (* x.im y.re) (* x.re y.im)) (+ (* y.re y.re) (* y.im y.im))))