
(FPCore (x.re x.im y.re y.im) :precision binary64 (/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x_46re, x_46im, y_46re, y_46im)
use fmin_fmax_functions
real(8), intent (in) :: x_46re
real(8), intent (in) :: x_46im
real(8), intent (in) :: y_46re
real(8), intent (in) :: y_46im
code = ((x_46re * y_46re) + (x_46im * y_46im)) / ((y_46re * y_46re) + (y_46im * y_46im))
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): return ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im))
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(Float64(Float64(x_46_re * y_46_re) + Float64(x_46_im * y_46_im)) / Float64(Float64(y_46_re * y_46_re) + Float64(y_46_im * y_46_im))) end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im)); end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[(N[(x$46$re * y$46$re), $MachinePrecision] + N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision] / N[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x.re x.im y.re y.im) :precision binary64 (/ (+ (* x.re y.re) (* x.im y.im)) (+ (* y.re y.re) (* y.im y.im))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x_46re, x_46im, y_46re, y_46im)
use fmin_fmax_functions
real(8), intent (in) :: x_46re
real(8), intent (in) :: x_46im
real(8), intent (in) :: y_46re
real(8), intent (in) :: y_46im
code = ((x_46re * y_46re) + (x_46im * y_46im)) / ((y_46re * y_46re) + (y_46im * y_46im))
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
return ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im));
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): return ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im))
function code(x_46_re, x_46_im, y_46_re, y_46_im) return Float64(Float64(Float64(x_46_re * y_46_re) + Float64(x_46_im * y_46_im)) / Float64(Float64(y_46_re * y_46_re) + Float64(y_46_im * y_46_im))) end
function tmp = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = ((x_46_re * y_46_re) + (x_46_im * y_46_im)) / ((y_46_re * y_46_re) + (y_46_im * y_46_im)); end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := N[(N[(N[(x$46$re * y$46$re), $MachinePrecision] + N[(x$46$im * y$46$im), $MachinePrecision]), $MachinePrecision] / N[(N[(y$46$re * y$46$re), $MachinePrecision] + N[(y$46$im * y$46$im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x.re \cdot y.re + x.im \cdot y.im}{y.re \cdot y.re + y.im \cdot y.im}
\end{array}
(FPCore (x.re x.im y.re y.im)
:precision binary64
(let* ((t_0 (/ (fma y.im (/ x.im y.re) x.re) y.re)))
(if (<= y.re -9.5e+68)
t_0
(if (<= y.re -1.65e-43)
(* (/ (fma (/ x.re x.im) y.re y.im) (fma y.im y.im (* y.re y.re))) x.im)
(if (<= y.re 1.75e+24) (/ (fma y.re (/ x.re y.im) x.im) y.im) t_0)))))
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, (x_46_im / y_46_re), x_46_re) / y_46_re;
double tmp;
if (y_46_re <= -9.5e+68) {
tmp = t_0;
} else if (y_46_re <= -1.65e-43) {
tmp = (fma((x_46_re / x_46_im), y_46_re, y_46_im) / fma(y_46_im, y_46_im, (y_46_re * y_46_re))) * x_46_im;
} else if (y_46_re <= 1.75e+24) {
tmp = fma(y_46_re, (x_46_re / y_46_im), x_46_im) / y_46_im;
} else {
tmp = t_0;
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) t_0 = Float64(fma(y_46_im, Float64(x_46_im / y_46_re), x_46_re) / y_46_re) tmp = 0.0 if (y_46_re <= -9.5e+68) tmp = t_0; elseif (y_46_re <= -1.65e-43) tmp = Float64(Float64(fma(Float64(x_46_re / x_46_im), y_46_re, y_46_im) / fma(y_46_im, y_46_im, Float64(y_46_re * y_46_re))) * x_46_im); elseif (y_46_re <= 1.75e+24) tmp = Float64(fma(y_46_re, Float64(x_46_re / y_46_im), x_46_im) / y_46_im); 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[(N[(y$46$im * N[(x$46$im / y$46$re), $MachinePrecision] + x$46$re), $MachinePrecision] / y$46$re), $MachinePrecision]}, If[LessEqual[y$46$re, -9.5e+68], t$95$0, If[LessEqual[y$46$re, -1.65e-43], N[(N[(N[(N[(x$46$re / x$46$im), $MachinePrecision] * y$46$re + y$46$im), $MachinePrecision] / N[(y$46$im * y$46$im + N[(y$46$re * y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x$46$im), $MachinePrecision], If[LessEqual[y$46$re, 1.75e+24], N[(N[(y$46$re * N[(x$46$re / y$46$im), $MachinePrecision] + x$46$im), $MachinePrecision] / y$46$im), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(y.im, \frac{x.im}{y.re}, x.re\right)}{y.re}\\
\mathbf{if}\;y.re \leq -9.5 \cdot 10^{+68}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y.re \leq -1.65 \cdot 10^{-43}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{x.re}{x.im}, y.re, y.im\right)}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)} \cdot x.im\\
\mathbf{elif}\;y.re \leq 1.75 \cdot 10^{+24}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y.re, \frac{x.re}{y.im}, x.im\right)}{y.im}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y.re < -9.50000000000000069e68 or 1.7500000000000001e24 < y.re Initial program 46.0%
Taylor expanded in y.re around inf
Applied rewrites86.1%
Applied rewrites87.7%
if -9.50000000000000069e68 < y.re < -1.65000000000000008e-43Initial program 78.8%
Taylor expanded in x.im around inf
Applied rewrites82.9%
if -1.65000000000000008e-43 < y.re < 1.7500000000000001e24Initial program 70.3%
Taylor expanded in y.re around 0
Applied rewrites85.8%
Applied rewrites86.0%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(if (<= y.re -1.5e+194)
(/ x.re y.re)
(if (<= y.re -4.5e+67)
(/ (* (/ x.im y.re) y.im) y.re)
(if (<= y.re 2e-23)
(/ x.im y.im)
(if (<= y.re 6.3e+122)
(* (/ y.re (fma y.im y.im (* y.re y.re))) x.re)
(/ x.re y.re))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double tmp;
if (y_46_re <= -1.5e+194) {
tmp = x_46_re / y_46_re;
} else if (y_46_re <= -4.5e+67) {
tmp = ((x_46_im / y_46_re) * y_46_im) / y_46_re;
} else if (y_46_re <= 2e-23) {
tmp = x_46_im / y_46_im;
} else if (y_46_re <= 6.3e+122) {
tmp = (y_46_re / fma(y_46_im, y_46_im, (y_46_re * y_46_re))) * x_46_re;
} else {
tmp = x_46_re / y_46_re;
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = 0.0 if (y_46_re <= -1.5e+194) tmp = Float64(x_46_re / y_46_re); elseif (y_46_re <= -4.5e+67) tmp = Float64(Float64(Float64(x_46_im / y_46_re) * y_46_im) / y_46_re); elseif (y_46_re <= 2e-23) tmp = Float64(x_46_im / y_46_im); elseif (y_46_re <= 6.3e+122) tmp = Float64(Float64(y_46_re / fma(y_46_im, y_46_im, Float64(y_46_re * y_46_re))) * x_46_re); else tmp = Float64(x_46_re / y_46_re); end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[LessEqual[y$46$re, -1.5e+194], N[(x$46$re / y$46$re), $MachinePrecision], If[LessEqual[y$46$re, -4.5e+67], N[(N[(N[(x$46$im / y$46$re), $MachinePrecision] * y$46$im), $MachinePrecision] / y$46$re), $MachinePrecision], If[LessEqual[y$46$re, 2e-23], N[(x$46$im / y$46$im), $MachinePrecision], If[LessEqual[y$46$re, 6.3e+122], N[(N[(y$46$re / N[(y$46$im * y$46$im + N[(y$46$re * y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x$46$re), $MachinePrecision], N[(x$46$re / y$46$re), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y.re \leq -1.5 \cdot 10^{+194}:\\
\;\;\;\;\frac{x.re}{y.re}\\
\mathbf{elif}\;y.re \leq -4.5 \cdot 10^{+67}:\\
\;\;\;\;\frac{\frac{x.im}{y.re} \cdot y.im}{y.re}\\
\mathbf{elif}\;y.re \leq 2 \cdot 10^{-23}:\\
\;\;\;\;\frac{x.im}{y.im}\\
\mathbf{elif}\;y.re \leq 6.3 \cdot 10^{+122}:\\
\;\;\;\;\frac{y.re}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)} \cdot x.re\\
\mathbf{else}:\\
\;\;\;\;\frac{x.re}{y.re}\\
\end{array}
\end{array}
if y.re < -1.5000000000000002e194 or 6.3000000000000001e122 < y.re Initial program 33.3%
Taylor expanded in y.re around inf
Applied rewrites82.7%
if -1.5000000000000002e194 < y.re < -4.4999999999999998e67Initial program 49.5%
Taylor expanded in y.re around inf
Applied rewrites69.1%
Applied rewrites72.5%
Taylor expanded in x.re around 0
Applied rewrites51.0%
if -4.4999999999999998e67 < y.re < 1.99999999999999992e-23Initial program 70.8%
Taylor expanded in y.re around 0
Applied rewrites69.0%
if 1.99999999999999992e-23 < y.re < 6.3000000000000001e122Initial program 84.2%
Taylor expanded in x.re around inf
Applied rewrites78.6%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(if (<= y.re -1.5e+194)
(/ x.re y.re)
(if (<= y.re -4.2e+67)
(* (/ (/ x.im y.re) y.re) y.im)
(if (<= y.re 2e-23)
(/ x.im y.im)
(if (<= y.re 6.3e+122)
(* (/ y.re (fma y.im y.im (* y.re y.re))) x.re)
(/ x.re y.re))))))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double tmp;
if (y_46_re <= -1.5e+194) {
tmp = x_46_re / y_46_re;
} else if (y_46_re <= -4.2e+67) {
tmp = ((x_46_im / y_46_re) / y_46_re) * y_46_im;
} else if (y_46_re <= 2e-23) {
tmp = x_46_im / y_46_im;
} else if (y_46_re <= 6.3e+122) {
tmp = (y_46_re / fma(y_46_im, y_46_im, (y_46_re * y_46_re))) * x_46_re;
} else {
tmp = x_46_re / y_46_re;
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = 0.0 if (y_46_re <= -1.5e+194) tmp = Float64(x_46_re / y_46_re); elseif (y_46_re <= -4.2e+67) tmp = Float64(Float64(Float64(x_46_im / y_46_re) / y_46_re) * y_46_im); elseif (y_46_re <= 2e-23) tmp = Float64(x_46_im / y_46_im); elseif (y_46_re <= 6.3e+122) tmp = Float64(Float64(y_46_re / fma(y_46_im, y_46_im, Float64(y_46_re * y_46_re))) * x_46_re); else tmp = Float64(x_46_re / y_46_re); end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[LessEqual[y$46$re, -1.5e+194], N[(x$46$re / y$46$re), $MachinePrecision], If[LessEqual[y$46$re, -4.2e+67], N[(N[(N[(x$46$im / y$46$re), $MachinePrecision] / y$46$re), $MachinePrecision] * y$46$im), $MachinePrecision], If[LessEqual[y$46$re, 2e-23], N[(x$46$im / y$46$im), $MachinePrecision], If[LessEqual[y$46$re, 6.3e+122], N[(N[(y$46$re / N[(y$46$im * y$46$im + N[(y$46$re * y$46$re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x$46$re), $MachinePrecision], N[(x$46$re / y$46$re), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y.re \leq -1.5 \cdot 10^{+194}:\\
\;\;\;\;\frac{x.re}{y.re}\\
\mathbf{elif}\;y.re \leq -4.2 \cdot 10^{+67}:\\
\;\;\;\;\frac{\frac{x.im}{y.re}}{y.re} \cdot y.im\\
\mathbf{elif}\;y.re \leq 2 \cdot 10^{-23}:\\
\;\;\;\;\frac{x.im}{y.im}\\
\mathbf{elif}\;y.re \leq 6.3 \cdot 10^{+122}:\\
\;\;\;\;\frac{y.re}{\mathsf{fma}\left(y.im, y.im, y.re \cdot y.re\right)} \cdot x.re\\
\mathbf{else}:\\
\;\;\;\;\frac{x.re}{y.re}\\
\end{array}
\end{array}
if y.re < -1.5000000000000002e194 or 6.3000000000000001e122 < y.re Initial program 33.3%
Taylor expanded in y.re around inf
Applied rewrites82.7%
if -1.5000000000000002e194 < y.re < -4.2000000000000003e67Initial program 49.5%
Taylor expanded in y.re around inf
Applied rewrites69.1%
Taylor expanded in x.re around 0
Applied rewrites50.8%
if -4.2000000000000003e67 < y.re < 1.99999999999999992e-23Initial program 70.8%
Taylor expanded in y.re around 0
Applied rewrites69.0%
if 1.99999999999999992e-23 < y.re < 6.3000000000000001e122Initial program 84.2%
Taylor expanded in x.re around inf
Applied rewrites78.6%
(FPCore (x.re x.im y.re y.im) :precision binary64 (if (or (<= y.re -3.4e+43) (not (<= y.re 1.75e+24))) (/ (fma y.im (/ x.im y.re) x.re) y.re) (/ (fma y.re (/ x.re y.im) x.im) y.im)))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double tmp;
if ((y_46_re <= -3.4e+43) || !(y_46_re <= 1.75e+24)) {
tmp = fma(y_46_im, (x_46_im / y_46_re), x_46_re) / y_46_re;
} else {
tmp = fma(y_46_re, (x_46_re / y_46_im), x_46_im) / y_46_im;
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = 0.0 if ((y_46_re <= -3.4e+43) || !(y_46_re <= 1.75e+24)) tmp = Float64(fma(y_46_im, Float64(x_46_im / y_46_re), x_46_re) / y_46_re); else tmp = Float64(fma(y_46_re, Float64(x_46_re / y_46_im), x_46_im) / y_46_im); end return tmp end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[Or[LessEqual[y$46$re, -3.4e+43], N[Not[LessEqual[y$46$re, 1.75e+24]], $MachinePrecision]], N[(N[(y$46$im * N[(x$46$im / y$46$re), $MachinePrecision] + x$46$re), $MachinePrecision] / y$46$re), $MachinePrecision], N[(N[(y$46$re * N[(x$46$re / y$46$im), $MachinePrecision] + x$46$im), $MachinePrecision] / y$46$im), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y.re \leq -3.4 \cdot 10^{+43} \lor \neg \left(y.re \leq 1.75 \cdot 10^{+24}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(y.im, \frac{x.im}{y.re}, x.re\right)}{y.re}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(y.re, \frac{x.re}{y.im}, x.im\right)}{y.im}\\
\end{array}
\end{array}
if y.re < -3.40000000000000012e43 or 1.7500000000000001e24 < y.re Initial program 48.0%
Taylor expanded in y.re around inf
Applied rewrites84.7%
Applied rewrites86.2%
if -3.40000000000000012e43 < y.re < 1.7500000000000001e24Initial program 71.4%
Taylor expanded in y.re around 0
Applied rewrites83.0%
Applied rewrites83.2%
Final simplification84.6%
(FPCore (x.re x.im y.re y.im) :precision binary64 (if (or (<= y.re -2e+42) (not (<= y.re 2.9e-31))) (/ (fma y.im (/ x.im y.re) x.re) y.re) (/ x.im y.im)))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double tmp;
if ((y_46_re <= -2e+42) || !(y_46_re <= 2.9e-31)) {
tmp = fma(y_46_im, (x_46_im / y_46_re), x_46_re) / y_46_re;
} else {
tmp = x_46_im / y_46_im;
}
return tmp;
}
function code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = 0.0 if ((y_46_re <= -2e+42) || !(y_46_re <= 2.9e-31)) tmp = Float64(fma(y_46_im, Float64(x_46_im / y_46_re), x_46_re) / y_46_re); 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[Or[LessEqual[y$46$re, -2e+42], N[Not[LessEqual[y$46$re, 2.9e-31]], $MachinePrecision]], N[(N[(y$46$im * N[(x$46$im / y$46$re), $MachinePrecision] + x$46$re), $MachinePrecision] / y$46$re), $MachinePrecision], N[(x$46$im / y$46$im), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y.re \leq -2 \cdot 10^{+42} \lor \neg \left(y.re \leq 2.9 \cdot 10^{-31}\right):\\
\;\;\;\;\frac{\mathsf{fma}\left(y.im, \frac{x.im}{y.re}, x.re\right)}{y.re}\\
\mathbf{else}:\\
\;\;\;\;\frac{x.im}{y.im}\\
\end{array}
\end{array}
if y.re < -2.00000000000000009e42 or 2.9000000000000001e-31 < y.re Initial program 50.5%
Taylor expanded in y.re around inf
Applied rewrites81.1%
Applied rewrites82.4%
if -2.00000000000000009e42 < y.re < 2.9000000000000001e-31Initial program 71.0%
Taylor expanded in y.re around 0
Applied rewrites70.6%
Final simplification76.9%
(FPCore (x.re x.im y.re y.im)
:precision binary64
(if (<= y.re -1.5e+194)
(/ x.re y.re)
(if (<= y.re -4.2e+67)
(* (/ (/ x.im y.re) y.re) y.im)
(if (<= y.re 2.15e-23) (/ 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_re <= -1.5e+194) {
tmp = x_46_re / y_46_re;
} else if (y_46_re <= -4.2e+67) {
tmp = ((x_46_im / y_46_re) / y_46_re) * y_46_im;
} else if (y_46_re <= 2.15e-23) {
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_46re <= (-1.5d+194)) then
tmp = x_46re / y_46re
else if (y_46re <= (-4.2d+67)) then
tmp = ((x_46im / y_46re) / y_46re) * y_46im
else if (y_46re <= 2.15d-23) 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_re <= -1.5e+194) {
tmp = x_46_re / y_46_re;
} else if (y_46_re <= -4.2e+67) {
tmp = ((x_46_im / y_46_re) / y_46_re) * y_46_im;
} else if (y_46_re <= 2.15e-23) {
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_re <= -1.5e+194: tmp = x_46_re / y_46_re elif y_46_re <= -4.2e+67: tmp = ((x_46_im / y_46_re) / y_46_re) * y_46_im elif y_46_re <= 2.15e-23: 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_re <= -1.5e+194) tmp = Float64(x_46_re / y_46_re); elseif (y_46_re <= -4.2e+67) tmp = Float64(Float64(Float64(x_46_im / y_46_re) / y_46_re) * y_46_im); elseif (y_46_re <= 2.15e-23) 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_re <= -1.5e+194) tmp = x_46_re / y_46_re; elseif (y_46_re <= -4.2e+67) tmp = ((x_46_im / y_46_re) / y_46_re) * y_46_im; elseif (y_46_re <= 2.15e-23) 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[LessEqual[y$46$re, -1.5e+194], N[(x$46$re / y$46$re), $MachinePrecision], If[LessEqual[y$46$re, -4.2e+67], N[(N[(N[(x$46$im / y$46$re), $MachinePrecision] / y$46$re), $MachinePrecision] * y$46$im), $MachinePrecision], If[LessEqual[y$46$re, 2.15e-23], 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.re \leq -1.5 \cdot 10^{+194}:\\
\;\;\;\;\frac{x.re}{y.re}\\
\mathbf{elif}\;y.re \leq -4.2 \cdot 10^{+67}:\\
\;\;\;\;\frac{\frac{x.im}{y.re}}{y.re} \cdot y.im\\
\mathbf{elif}\;y.re \leq 2.15 \cdot 10^{-23}:\\
\;\;\;\;\frac{x.im}{y.im}\\
\mathbf{else}:\\
\;\;\;\;\frac{x.re}{y.re}\\
\end{array}
\end{array}
if y.re < -1.5000000000000002e194 or 2.15000000000000001e-23 < y.re Initial program 49.1%
Taylor expanded in y.re around inf
Applied rewrites76.7%
if -1.5000000000000002e194 < y.re < -4.2000000000000003e67Initial program 49.5%
Taylor expanded in y.re around inf
Applied rewrites69.1%
Taylor expanded in x.re around 0
Applied rewrites50.8%
if -4.2000000000000003e67 < y.re < 2.15000000000000001e-23Initial program 70.8%
Taylor expanded in y.re around 0
Applied rewrites69.0%
(FPCore (x.re x.im y.re y.im) :precision binary64 (if (or (<= y.re -2.4e+43) (not (<= y.re 2.15e-23))) (/ x.re y.re) (/ x.im y.im)))
double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double tmp;
if ((y_46_re <= -2.4e+43) || !(y_46_re <= 2.15e-23)) {
tmp = x_46_re / y_46_re;
} else {
tmp = x_46_im / y_46_im;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(x_46re, x_46im, y_46re, y_46im)
use fmin_fmax_functions
real(8), intent (in) :: x_46re
real(8), intent (in) :: x_46im
real(8), intent (in) :: y_46re
real(8), intent (in) :: y_46im
real(8) :: tmp
if ((y_46re <= (-2.4d+43)) .or. (.not. (y_46re <= 2.15d-23))) then
tmp = x_46re / y_46re
else
tmp = x_46im / y_46im
end if
code = tmp
end function
public static double code(double x_46_re, double x_46_im, double y_46_re, double y_46_im) {
double tmp;
if ((y_46_re <= -2.4e+43) || !(y_46_re <= 2.15e-23)) {
tmp = x_46_re / y_46_re;
} else {
tmp = x_46_im / y_46_im;
}
return tmp;
}
def code(x_46_re, x_46_im, y_46_re, y_46_im): tmp = 0 if (y_46_re <= -2.4e+43) or not (y_46_re <= 2.15e-23): tmp = x_46_re / y_46_re else: tmp = x_46_im / y_46_im return tmp
function code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = 0.0 if ((y_46_re <= -2.4e+43) || !(y_46_re <= 2.15e-23)) tmp = Float64(x_46_re / y_46_re); else tmp = Float64(x_46_im / y_46_im); end return tmp end
function tmp_2 = code(x_46_re, x_46_im, y_46_re, y_46_im) tmp = 0.0; if ((y_46_re <= -2.4e+43) || ~((y_46_re <= 2.15e-23))) tmp = x_46_re / y_46_re; else tmp = x_46_im / y_46_im; end tmp_2 = tmp; end
code[x$46$re_, x$46$im_, y$46$re_, y$46$im_] := If[Or[LessEqual[y$46$re, -2.4e+43], N[Not[LessEqual[y$46$re, 2.15e-23]], $MachinePrecision]], N[(x$46$re / y$46$re), $MachinePrecision], N[(x$46$im / y$46$im), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y.re \leq -2.4 \cdot 10^{+43} \lor \neg \left(y.re \leq 2.15 \cdot 10^{-23}\right):\\
\;\;\;\;\frac{x.re}{y.re}\\
\mathbf{else}:\\
\;\;\;\;\frac{x.im}{y.im}\\
\end{array}
\end{array}
if y.re < -2.40000000000000023e43 or 2.15000000000000001e-23 < y.re Initial program 50.4%
Taylor expanded in y.re around inf
Applied rewrites66.8%
if -2.40000000000000023e43 < y.re < 2.15000000000000001e-23Initial program 70.7%
Taylor expanded in y.re around 0
Applied rewrites70.3%
Final simplification68.5%
(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 60.1%
Taylor expanded in y.re around 0
Applied rewrites42.1%
herbie shell --seed 2025018
(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))))