
(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}
Sampling outcomes in binary64 precision:
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
(/ (fma (- x.re) y.im (* y.re x.im)) (fma y.im y.im (* y.re y.re))))
(t_1 (/ (fma y.re (/ x.im y.im) (- x.re)) y.im)))
(if (<= y.im -2.6e+111)
t_1
(if (<= y.im -1850.0)
t_0
(if (<= y.im 5.6e-113)
(/ (fma (/ y.im y.re) (- x.re) x.im) y.re)
(if (<= y.im 2.6e+75) 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 = fma(-x_46_re, y_46_im, (y_46_re * x_46_im)) / fma(y_46_im, y_46_im, (y_46_re * y_46_re));
double t_1 = fma(y_46_re, (x_46_im / y_46_im), -x_46_re) / y_46_im;
double tmp;
if (y_46_im <= -2.6e+111) {
tmp = t_1;
} else if (y_46_im <= -1850.0) {
tmp = t_0;
} else if (y_46_im <= 5.6e-113) {
tmp = fma((y_46_im / y_46_re), -x_46_re, x_46_im) / y_46_re;
} else if (y_46_im <= 2.6e+75) {
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(fma(Float64(-x_46_re), y_46_im, Float64(y_46_re * x_46_im)) / fma(y_46_im, y_46_im, Float64(y_46_re * y_46_re))) t_1 = Float64(fma(y_46_re, Float64(x_46_im / y_46_im), Float64(-x_46_re)) / y_46_im) tmp = 0.0 if (y_46_im <= -2.6e+111) tmp = t_1; elseif (y_46_im <= -1850.0) tmp = t_0; elseif (y_46_im <= 5.6e-113) tmp = Float64(fma(Float64(y_46_im / y_46_re), Float64(-x_46_re), x_46_im) / y_46_re); elseif (y_46_im <= 2.6e+75) 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[((-x$46$re) * y$46$im + N[(y$46$re * x$46$im), $MachinePrecision]), $MachinePrecision] / N[(y$46$im * y$46$im + N[(y$46$re * y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(y$46$re * N[(x$46$im / y$46$im), $MachinePrecision] + (-x$46$re)), $MachinePrecision] / y$46$im), $MachinePrecision]}, If[LessEqual[y$46$im, -2.6e+111], t$95$1, If[LessEqual[y$46$im, -1850.0], t$95$0, If[LessEqual[y$46$im, 5.6e-113], N[(N[(N[(y$46$im / y$46$re), $MachinePrecision] * (-x$46$re) + x$46$im), $MachinePrecision] / y$46$re), $MachinePrecision], If[LessEqual[y$46$im, 2.6e+75], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(-x.re, y.im, y.re \cdot x.im\right)}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}\\
t_1 := \frac{\mathsf{fma}\left(y.re, \frac{x.im}{y.im}, -x.re\right)}{y.im}\\
\mathbf{if}\;y.im \leq -2.6 \cdot 10^{+111}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y.im \leq -1850:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y.im \leq 5.6 \cdot 10^{-113}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{y.im}{y.re}, -x.re, x.im\right)}{y.re}\\
\mathbf{elif}\;y.im \leq 2.6 \cdot 10^{+75}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y.im < -2.5999999999999999e111 or 2.59999999999999985e75 < y.im Initial program 43.0%
Taylor expanded in y.re around 0
+-commutativeN/A
associate-*l/N/A
associate-*l/N/A
unpow2N/A
associate-/r*N/A
associate-*r/N/A
div-addN/A
+-commutativeN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower-/.f64N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6482.3
Applied rewrites82.3%
Applied rewrites83.9%
if -2.5999999999999999e111 < y.im < -1850 or 5.6e-113 < y.im < 2.59999999999999985e75Initial program 91.0%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
lower-fma.f64N/A
lower-neg.f6491.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f6491.0
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6491.0
Applied rewrites91.0%
if -1850 < y.im < 5.6e-113Initial program 70.4%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
lower-fma.f64N/A
lower-neg.f6470.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6470.4
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6470.4
Applied rewrites70.4%
Taylor expanded in y.re around -inf
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f64N/A
mul-1-negN/A
lower-neg.f6485.1
Applied rewrites85.1%
Taylor expanded in y.re around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l/N/A
associate-*l*N/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6487.3
Applied rewrites87.3%
Final simplification86.9%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (/ (- x.re) y.im)))
(if (<= y.im -3.85e+158)
t_0
(if (<= y.im -9600.0)
(/ (- (* x.im y.re) (* x.re y.im)) (* y.im y.im))
(if (<= y.im 1e-9)
(/ x.im y.re)
(if (<= y.im 1.9e+139)
(* (- x.re) (/ y.im (fma y.im y.im (* y.re y.re))))
t_0))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = -x_46_re / y_46_im;
double tmp;
if (y_46_im <= -3.85e+158) {
tmp = t_0;
} else if (y_46_im <= -9600.0) {
tmp = ((x_46_im * y_46_re) - (x_46_re * y_46_im)) / (y_46_im * y_46_im);
} else if (y_46_im <= 1e-9) {
tmp = x_46_im / y_46_re;
} else if (y_46_im <= 1.9e+139) {
tmp = -x_46_re * (y_46_im / fma(y_46_im, y_46_im, (y_46_re * y_46_re)));
} else {
tmp = t_0;
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = Float64(Float64(-x_46_re) / y_46_im) tmp = 0.0 if (y_46_im <= -3.85e+158) tmp = t_0; elseif (y_46_im <= -9600.0) 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_im <= 1e-9) tmp = Float64(x_46_im / y_46_re); elseif (y_46_im <= 1.9e+139) tmp = Float64(Float64(-x_46_re) * Float64(y_46_im / fma(y_46_im, y_46_im, Float64(y_46_re * y_46_re)))); else tmp = t_0; 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) / y$46$im), $MachinePrecision]}, If[LessEqual[y$46$im, -3.85e+158], t$95$0, If[LessEqual[y$46$im, -9600.0], 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$im, 1e-9], N[(x$46$im / y$46$re), $MachinePrecision], If[LessEqual[y$46$im, 1.9e+139], N[((-x$46$re) * N[(y$46$im / N[(y$46$im * y$46$im + N[(y$46$re * y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x.re}{y.im}\\
\mathbf{if}\;y.im \leq -3.85 \cdot 10^{+158}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y.im \leq -9600:\\
\;\;\;\;\frac{x.im \cdot y.re - x.re \cdot y.im}{y.im \cdot y.im}\\
\mathbf{elif}\;y.im \leq 10^{-9}:\\
\;\;\;\;\frac{x.im}{y.re}\\
\mathbf{elif}\;y.im \leq 1.9 \cdot 10^{+139}:\\
\;\;\;\;\left(-x.re\right) \cdot \frac{y.im}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y.im < -3.84999999999999996e158 or 1.9e139 < y.im Initial program 32.2%
Taylor expanded in y.re around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6474.2
Applied rewrites74.2%
if -3.84999999999999996e158 < y.im < -9600Initial program 83.8%
Taylor expanded in y.re around 0
unpow2N/A
lower-*.f6467.4
Applied rewrites67.4%
if -9600 < y.im < 1.00000000000000006e-9Initial program 75.0%
Taylor expanded in y.re around inf
lower-/.f6472.0
Applied rewrites72.0%
if 1.00000000000000006e-9 < y.im < 1.9e139Initial program 76.2%
Taylor expanded in x.re around inf
associate-/l*N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6469.2
Applied rewrites69.2%
Final simplification71.6%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (/ (- x.re) y.im))
(t_1 (* (- x.re) (/ y.im (fma y.im y.im (* y.re y.re))))))
(if (<= y.im -3.85e+158)
t_0
(if (<= y.im -1.4e-115)
t_1
(if (<= y.im 1e-9) (/ x.im y.re) (if (<= y.im 1.9e+139) t_1 t_0))))))
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_im;
double t_1 = -x_46_re * (y_46_im / fma(y_46_im, y_46_im, (y_46_re * y_46_re)));
double tmp;
if (y_46_im <= -3.85e+158) {
tmp = t_0;
} else if (y_46_im <= -1.4e-115) {
tmp = t_1;
} else if (y_46_im <= 1e-9) {
tmp = x_46_im / y_46_re;
} else if (y_46_im <= 1.9e+139) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = Float64(Float64(-x_46_re) / y_46_im) t_1 = Float64(Float64(-x_46_re) * Float64(y_46_im / fma(y_46_im, y_46_im, Float64(y_46_re * y_46_re)))) tmp = 0.0 if (y_46_im <= -3.85e+158) tmp = t_0; elseif (y_46_im <= -1.4e-115) tmp = t_1; elseif (y_46_im <= 1e-9) tmp = Float64(x_46_im / y_46_re); elseif (y_46_im <= 1.9e+139) tmp = t_1; else tmp = t_0; 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) / y$46$im), $MachinePrecision]}, Block[{t$95$1 = N[((-x$46$re) * 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, -3.85e+158], t$95$0, If[LessEqual[y$46$im, -1.4e-115], t$95$1, If[LessEqual[y$46$im, 1e-9], N[(x$46$im / y$46$re), $MachinePrecision], If[LessEqual[y$46$im, 1.9e+139], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x.re}{y.im}\\
t_1 := \left(-x.re\right) \cdot \frac{y.im}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)}\\
\mathbf{if}\;y.im \leq -3.85 \cdot 10^{+158}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y.im \leq -1.4 \cdot 10^{-115}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y.im \leq 10^{-9}:\\
\;\;\;\;\frac{x.im}{y.re}\\
\mathbf{elif}\;y.im \leq 1.9 \cdot 10^{+139}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y.im < -3.84999999999999996e158 or 1.9e139 < y.im Initial program 32.2%
Taylor expanded in y.re around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6474.2
Applied rewrites74.2%
if -3.84999999999999996e158 < y.im < -1.39999999999999994e-115 or 1.00000000000000006e-9 < y.im < 1.9e139Initial program 77.5%
Taylor expanded in x.re around inf
associate-/l*N/A
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-/.f64N/A
unpow2N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6463.2
Applied rewrites63.2%
if -1.39999999999999994e-115 < y.im < 1.00000000000000006e-9Initial program 76.1%
Taylor expanded in y.re around inf
lower-/.f6475.3
Applied rewrites75.3%
Final simplification71.0%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (/ (- x.re) y.im)))
(if (<= y.im -3.85e+158)
t_0
(if (<= y.im -9600.0)
(/ (- (* x.im y.re) (* x.re y.im)) (* y.im y.im))
(if (<= y.im 2.65e+42)
(/ (fma (/ y.im y.re) (- x.re) x.im) y.re)
t_0)))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = -x_46_re / y_46_im;
double tmp;
if (y_46_im <= -3.85e+158) {
tmp = t_0;
} else if (y_46_im <= -9600.0) {
tmp = ((x_46_im * y_46_re) - (x_46_re * y_46_im)) / (y_46_im * y_46_im);
} else if (y_46_im <= 2.65e+42) {
tmp = fma((y_46_im / y_46_re), -x_46_re, x_46_im) / y_46_re;
} else {
tmp = t_0;
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = Float64(Float64(-x_46_re) / y_46_im) tmp = 0.0 if (y_46_im <= -3.85e+158) tmp = t_0; elseif (y_46_im <= -9600.0) 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_im <= 2.65e+42) tmp = Float64(fma(Float64(y_46_im / y_46_re), Float64(-x_46_re), x_46_im) / y_46_re); else tmp = t_0; 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) / y$46$im), $MachinePrecision]}, If[LessEqual[y$46$im, -3.85e+158], t$95$0, If[LessEqual[y$46$im, -9600.0], 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$im, 2.65e+42], N[(N[(N[(y$46$im / y$46$re), $MachinePrecision] * (-x$46$re) + x$46$im), $MachinePrecision] / y$46$re), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x.re}{y.im}\\
\mathbf{if}\;y.im \leq -3.85 \cdot 10^{+158}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y.im \leq -9600:\\
\;\;\;\;\frac{x.im \cdot y.re - x.re \cdot y.im}{y.im \cdot y.im}\\
\mathbf{elif}\;y.im \leq 2.65 \cdot 10^{+42}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{y.im}{y.re}, -x.re, x.im\right)}{y.re}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y.im < -3.84999999999999996e158 or 2.65000000000000014e42 < y.im Initial program 42.8%
Taylor expanded in y.re around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6472.2
Applied rewrites72.2%
if -3.84999999999999996e158 < y.im < -9600Initial program 83.8%
Taylor expanded in y.re around 0
unpow2N/A
lower-*.f6467.4
Applied rewrites67.4%
if -9600 < y.im < 2.65000000000000014e42Initial program 76.4%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
lower-fma.f64N/A
lower-neg.f6476.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6476.4
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6476.4
Applied rewrites76.4%
Taylor expanded in y.re around -inf
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f64N/A
mul-1-negN/A
lower-neg.f6480.0
Applied rewrites80.0%
Taylor expanded in y.re around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l/N/A
associate-*l*N/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6481.6
Applied rewrites81.6%
Final simplification76.5%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (/ (- x.re) y.im)))
(if (<= y.im -3.85e+158)
t_0
(if (<= y.im -9600.0)
(/ (- (* x.im y.re) (* x.re y.im)) (* y.im y.im))
(if (<= y.im 2.65e+42)
(/ (fma (- y.im) (/ x.re y.re) x.im) y.re)
t_0)))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double t_0 = -x_46_re / y_46_im;
double tmp;
if (y_46_im <= -3.85e+158) {
tmp = t_0;
} else if (y_46_im <= -9600.0) {
tmp = ((x_46_im * y_46_re) - (x_46_re * y_46_im)) / (y_46_im * y_46_im);
} else if (y_46_im <= 2.65e+42) {
tmp = fma(-y_46_im, (x_46_re / y_46_re), x_46_im) / y_46_re;
} else {
tmp = t_0;
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = Float64(Float64(-x_46_re) / y_46_im) tmp = 0.0 if (y_46_im <= -3.85e+158) tmp = t_0; elseif (y_46_im <= -9600.0) 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_im <= 2.65e+42) tmp = Float64(fma(Float64(-y_46_im), Float64(x_46_re / y_46_re), x_46_im) / y_46_re); else tmp = t_0; 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) / y$46$im), $MachinePrecision]}, If[LessEqual[y$46$im, -3.85e+158], t$95$0, If[LessEqual[y$46$im, -9600.0], 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$im, 2.65e+42], N[(N[((-y$46$im) * N[(x$46$re / y$46$re), $MachinePrecision] + x$46$im), $MachinePrecision] / y$46$re), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-x.re}{y.im}\\
\mathbf{if}\;y.im \leq -3.85 \cdot 10^{+158}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y.im \leq -9600:\\
\;\;\;\;\frac{x.im \cdot y.re - x.re \cdot y.im}{y.im \cdot y.im}\\
\mathbf{elif}\;y.im \leq 2.65 \cdot 10^{+42}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-y.im, \frac{x.re}{y.re}, x.im\right)}{y.re}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y.im < -3.84999999999999996e158 or 2.65000000000000014e42 < y.im Initial program 42.8%
Taylor expanded in y.re around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6472.2
Applied rewrites72.2%
if -3.84999999999999996e158 < y.im < -9600Initial program 83.8%
Taylor expanded in y.re around 0
unpow2N/A
lower-*.f6467.4
Applied rewrites67.4%
if -9600 < y.im < 2.65000000000000014e42Initial program 76.4%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
lower-fma.f64N/A
lower-neg.f6476.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6476.4
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6476.4
Applied rewrites76.4%
Taylor expanded in y.re around -inf
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f64N/A
mul-1-negN/A
lower-neg.f6480.0
Applied rewrites80.0%
Taylor expanded in y.re around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l/N/A
associate-*l*N/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6481.6
Applied rewrites81.6%
Applied rewrites80.0%
Final simplification75.6%
(FPCore (x.re x.im y.re y.im) :precision binary64 (if (or (<= y.im -9600.0) (not (<= y.im 6e-5))) (/ (fma y.re (/ x.im y.im) (- x.re)) y.im) (/ (fma (/ y.im y.re) (- x.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_im <= -9600.0) || !(y_46_im <= 6e-5)) {
tmp = fma(y_46_re, (x_46_im / y_46_im), -x_46_re) / y_46_im;
} else {
tmp = fma((y_46_im / y_46_re), -x_46_re, 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_im <= -9600.0) || !(y_46_im <= 6e-5)) tmp = Float64(fma(y_46_re, Float64(x_46_im / y_46_im), Float64(-x_46_re)) / y_46_im); else tmp = Float64(fma(Float64(y_46_im / y_46_re), Float64(-x_46_re), x_46_im) / 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, -9600.0], N[Not[LessEqual[y$46$im, 6e-5]], $MachinePrecision]], N[(N[(y$46$re * N[(x$46$im / y$46$im), $MachinePrecision] + (-x$46$re)), $MachinePrecision] / y$46$im), $MachinePrecision], N[(N[(N[(y$46$im / y$46$re), $MachinePrecision] * (-x$46$re) + x$46$im), $MachinePrecision] / y$46$re), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y.im \leq -9600 \lor \neg \left(y.im \leq 6 \cdot 10^{-5}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(y.re, \frac{x.im}{y.im}, -x.re\right)}{y.im}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{y.im}{y.re}, -x.re, x.im\right)}{y.re}\\
\end{array}
\end{array}
if y.im < -9600 or 6.00000000000000015e-5 < y.im Initial program 56.2%
Taylor expanded in y.re around 0
+-commutativeN/A
associate-*l/N/A
associate-*l/N/A
unpow2N/A
associate-/r*N/A
associate-*r/N/A
div-addN/A
+-commutativeN/A
+-commutativeN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower-/.f64N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6478.1
Applied rewrites78.1%
Applied rewrites79.2%
if -9600 < y.im < 6.00000000000000015e-5Initial program 74.9%
lift--.f64N/A
lift-*.f64N/A
fp-cancel-sub-sign-invN/A
+-commutativeN/A
lower-fma.f64N/A
lower-neg.f6474.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6474.9
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6474.9
Applied rewrites74.9%
Taylor expanded in y.re around -inf
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f64N/A
mul-1-negN/A
lower-neg.f6482.5
Applied rewrites82.5%
Taylor expanded in y.re around inf
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l/N/A
associate-*l*N/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6484.3
Applied rewrites84.3%
Final simplification81.7%
(FPCore (x.re x.im y.re y.im) :precision binary64 (if (or (<= y.im -1e+16) (not (<= y.im 2.1e-9))) (/ (- x.re) y.im) (/ x.im y.re)))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double tmp;
if ((y_46_im <= -1e+16) || !(y_46_im <= 2.1e-9)) {
tmp = -x_46_re / y_46_im;
} else {
tmp = x_46_im / 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 <= (-1d+16)) .or. (.not. (y_46im <= 2.1d-9))) then
tmp = -x_46re / y_46im
else
tmp = x_46im / 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 <= -1e+16) || !(y_46_im <= 2.1e-9)) {
tmp = -x_46_re / y_46_im;
} else {
tmp = x_46_im / 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 <= -1e+16) or not (y_46_im <= 2.1e-9): tmp = -x_46_re / y_46_im 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_im <= -1e+16) || !(y_46_im <= 2.1e-9)) tmp = Float64(Float64(-x_46_re) / y_46_im); else tmp = Float64(x_46_im / 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 <= -1e+16) || ~((y_46_im <= 2.1e-9))) tmp = -x_46_re / y_46_im; else tmp = x_46_im / 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, -1e+16], N[Not[LessEqual[y$46$im, 2.1e-9]], $MachinePrecision]], N[((-x$46$re) / y$46$im), $MachinePrecision], N[(x$46$im / y$46$re), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y.im \leq -1 \cdot 10^{+16} \lor \neg \left(y.im \leq 2.1 \cdot 10^{-9}\right):\\
\;\;\;\;\frac{-x.re}{y.im}\\
\mathbf{else}:\\
\;\;\;\;\frac{x.im}{y.re}\\
\end{array}
\end{array}
if y.im < -1e16 or 2.10000000000000019e-9 < y.im Initial program 55.3%
Taylor expanded in y.re around 0
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6464.1
Applied rewrites64.1%
if -1e16 < y.im < 2.10000000000000019e-9Initial program 75.8%
Taylor expanded in y.re around inf
lower-/.f6471.3
Applied rewrites71.3%
Final simplification67.6%
(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 65.3%
Taylor expanded in y.re around inf
lower-/.f6445.7
Applied rewrites45.7%
herbie shell --seed 2025017
(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))))