
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) - 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(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((2.0d0 * (sqrt(((re * re) + (im * im))) - re)))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) - re)));
}
def code(re, im): return 0.5 * math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) - re)))
function code(re, im) return Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re)))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re))); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) - 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(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((2.0d0 * (sqrt(((re * re) + (im * im))) - re)))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) - re)));
}
def code(re, im): return 0.5 * math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) - re)))
function code(re, im) return Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re)))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re))); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}
\end{array}
(FPCore (re im)
:precision binary64
(if (<= re -1.85e+68)
(* 0.5 (sqrt (* -4.0 re)))
(if (<= re -9.6e-95)
(* 0.5 (sqrt (* 2.0 (- (sqrt (fma re re (* im im))) re))))
(if (<= re 5.6e-27)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* (* (pow re -0.5) im) 0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -1.85e+68) {
tmp = 0.5 * sqrt((-4.0 * re));
} else if (re <= -9.6e-95) {
tmp = 0.5 * sqrt((2.0 * (sqrt(fma(re, re, (im * im))) - re)));
} else if (re <= 5.6e-27) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = (pow(re, -0.5) * im) * 0.5;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= -1.85e+68) tmp = Float64(0.5 * sqrt(Float64(-4.0 * re))); elseif (re <= -9.6e-95) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(re, re, Float64(im * im))) - re)))); elseif (re <= 5.6e-27) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(Float64((re ^ -0.5) * im) * 0.5); end return tmp end
code[re_, im_] := If[LessEqual[re, -1.85e+68], N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -9.6e-95], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(re * re + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 5.6e-27], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[re, -0.5], $MachinePrecision] * im), $MachinePrecision] * 0.5), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.85 \cdot 10^{+68}:\\
\;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\
\mathbf{elif}\;re \leq -9.6 \cdot 10^{-95}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(re, re, im \cdot im\right)} - re\right)}\\
\mathbf{elif}\;re \leq 5.6 \cdot 10^{-27}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\left({re}^{-0.5} \cdot im\right) \cdot 0.5\\
\end{array}
\end{array}
if re < -1.84999999999999999e68Initial program 30.1%
Taylor expanded in re around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6431.0
Applied rewrites31.0%
Taylor expanded in re around -inf
lower-*.f6487.5
Applied rewrites87.5%
if -1.84999999999999999e68 < re < -9.6e-95Initial program 94.0%
lift-+.f64N/A
lift-*.f64N/A
sqr-abs-revN/A
fp-cancel-sign-sub-invN/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
remove-double-negN/A
remove-double-negN/A
remove-double-negN/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
rem-sqrt-square-revN/A
Applied rewrites94.0%
if -9.6e-95 < re < 5.5999999999999999e-27Initial program 53.0%
Taylor expanded in re around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6484.7
Applied rewrites84.7%
if 5.5999999999999999e-27 < re Initial program 6.1%
Taylor expanded in re around inf
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6478.3
Applied rewrites78.3%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6478.3
Applied rewrites78.9%
Applied rewrites79.0%
(FPCore (re im)
:precision binary64
(if (<= re -1.85e+68)
(* 0.5 (sqrt (* -4.0 re)))
(if (<= re -9.6e-95)
(* 0.5 (sqrt (* 2.0 (- (sqrt (fma re re (* im im))) re))))
(if (<= re 5.6e-27)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* (/ im (sqrt re)) 0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -1.85e+68) {
tmp = 0.5 * sqrt((-4.0 * re));
} else if (re <= -9.6e-95) {
tmp = 0.5 * sqrt((2.0 * (sqrt(fma(re, re, (im * im))) - re)));
} else if (re <= 5.6e-27) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = (im / sqrt(re)) * 0.5;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= -1.85e+68) tmp = Float64(0.5 * sqrt(Float64(-4.0 * re))); elseif (re <= -9.6e-95) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(re, re, Float64(im * im))) - re)))); elseif (re <= 5.6e-27) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(Float64(im / sqrt(re)) * 0.5); end return tmp end
code[re_, im_] := If[LessEqual[re, -1.85e+68], N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -9.6e-95], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(re * re + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 5.6e-27], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.85 \cdot 10^{+68}:\\
\;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\
\mathbf{elif}\;re \leq -9.6 \cdot 10^{-95}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(re, re, im \cdot im\right)} - re\right)}\\
\mathbf{elif}\;re \leq 5.6 \cdot 10^{-27}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{im}{\sqrt{re}} \cdot 0.5\\
\end{array}
\end{array}
if re < -1.84999999999999999e68Initial program 30.1%
Taylor expanded in re around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6431.0
Applied rewrites31.0%
Taylor expanded in re around -inf
lower-*.f6487.5
Applied rewrites87.5%
if -1.84999999999999999e68 < re < -9.6e-95Initial program 94.0%
lift-+.f64N/A
lift-*.f64N/A
sqr-abs-revN/A
fp-cancel-sign-sub-invN/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
remove-double-negN/A
remove-double-negN/A
remove-double-negN/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
rem-sqrt-square-revN/A
Applied rewrites94.0%
if -9.6e-95 < re < 5.5999999999999999e-27Initial program 53.0%
Taylor expanded in re around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6484.7
Applied rewrites84.7%
if 5.5999999999999999e-27 < re Initial program 6.1%
Taylor expanded in re around inf
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6478.3
Applied rewrites78.3%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6478.3
Applied rewrites78.9%
Applied rewrites78.9%
(FPCore (re im)
:precision binary64
(if (<= re -3.3e-9)
(* 0.5 (sqrt (* -4.0 re)))
(if (<= re 5.6e-27)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* (/ im (sqrt re)) 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -3.3e-9) {
tmp = 0.5 * sqrt((-4.0 * re));
} else if (re <= 5.6e-27) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = (im / sqrt(re)) * 0.5;
}
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(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-3.3d-9)) then
tmp = 0.5d0 * sqrt(((-4.0d0) * re))
else if (re <= 5.6d-27) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else
tmp = (im / sqrt(re)) * 0.5d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -3.3e-9) {
tmp = 0.5 * Math.sqrt((-4.0 * re));
} else if (re <= 5.6e-27) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = (im / Math.sqrt(re)) * 0.5;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -3.3e-9: tmp = 0.5 * math.sqrt((-4.0 * re)) elif re <= 5.6e-27: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = (im / math.sqrt(re)) * 0.5 return tmp
function code(re, im) tmp = 0.0 if (re <= -3.3e-9) tmp = Float64(0.5 * sqrt(Float64(-4.0 * re))); elseif (re <= 5.6e-27) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(Float64(im / sqrt(re)) * 0.5); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -3.3e-9) tmp = 0.5 * sqrt((-4.0 * re)); elseif (re <= 5.6e-27) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = (im / sqrt(re)) * 0.5; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -3.3e-9], N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 5.6e-27], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(im / N[Sqrt[re], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.3 \cdot 10^{-9}:\\
\;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\
\mathbf{elif}\;re \leq 5.6 \cdot 10^{-27}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{im}{\sqrt{re}} \cdot 0.5\\
\end{array}
\end{array}
if re < -3.30000000000000018e-9Initial program 45.9%
Taylor expanded in re around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6430.7
Applied rewrites30.7%
Taylor expanded in re around -inf
lower-*.f6487.9
Applied rewrites87.9%
if -3.30000000000000018e-9 < re < 5.5999999999999999e-27Initial program 57.7%
Taylor expanded in re around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6483.0
Applied rewrites83.0%
if 5.5999999999999999e-27 < re Initial program 6.1%
Taylor expanded in re around inf
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6478.3
Applied rewrites78.3%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6478.3
Applied rewrites78.9%
Applied rewrites78.9%
(FPCore (re im) :precision binary64 (if (<= re -3.3e-9) (* 0.5 (sqrt (* -4.0 re))) (if (<= re 8.5e+180) (* 0.5 (sqrt (* 2.0 (- im re)))) 0.0)))
double code(double re, double im) {
double tmp;
if (re <= -3.3e-9) {
tmp = 0.5 * sqrt((-4.0 * re));
} else if (re <= 8.5e+180) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = 0.0;
}
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(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-3.3d-9)) then
tmp = 0.5d0 * sqrt(((-4.0d0) * re))
else if (re <= 8.5d+180) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -3.3e-9) {
tmp = 0.5 * Math.sqrt((-4.0 * re));
} else if (re <= 8.5e+180) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = 0.0;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -3.3e-9: tmp = 0.5 * math.sqrt((-4.0 * re)) elif re <= 8.5e+180: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = 0.0 return tmp
function code(re, im) tmp = 0.0 if (re <= -3.3e-9) tmp = Float64(0.5 * sqrt(Float64(-4.0 * re))); elseif (re <= 8.5e+180) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = 0.0; end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -3.3e-9) tmp = 0.5 * sqrt((-4.0 * re)); elseif (re <= 8.5e+180) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = 0.0; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -3.3e-9], N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 8.5e+180], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.3 \cdot 10^{-9}:\\
\;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\
\mathbf{elif}\;re \leq 8.5 \cdot 10^{+180}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if re < -3.30000000000000018e-9Initial program 45.9%
Taylor expanded in re around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6430.7
Applied rewrites30.7%
Taylor expanded in re around -inf
lower-*.f6487.9
Applied rewrites87.9%
if -3.30000000000000018e-9 < re < 8.50000000000000077e180Initial program 48.3%
Taylor expanded in re around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6473.2
Applied rewrites73.2%
if 8.50000000000000077e180 < re Initial program 2.6%
Applied rewrites32.5%
(FPCore (re im) :precision binary64 (if (<= re -1.5e-9) (* 0.5 (sqrt (* -4.0 re))) (if (<= re 8.5e+180) (* (sqrt (+ im im)) 0.5) 0.0)))
double code(double re, double im) {
double tmp;
if (re <= -1.5e-9) {
tmp = 0.5 * sqrt((-4.0 * re));
} else if (re <= 8.5e+180) {
tmp = sqrt((im + im)) * 0.5;
} else {
tmp = 0.0;
}
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(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-1.5d-9)) then
tmp = 0.5d0 * sqrt(((-4.0d0) * re))
else if (re <= 8.5d+180) then
tmp = sqrt((im + im)) * 0.5d0
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.5e-9) {
tmp = 0.5 * Math.sqrt((-4.0 * re));
} else if (re <= 8.5e+180) {
tmp = Math.sqrt((im + im)) * 0.5;
} else {
tmp = 0.0;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.5e-9: tmp = 0.5 * math.sqrt((-4.0 * re)) elif re <= 8.5e+180: tmp = math.sqrt((im + im)) * 0.5 else: tmp = 0.0 return tmp
function code(re, im) tmp = 0.0 if (re <= -1.5e-9) tmp = Float64(0.5 * sqrt(Float64(-4.0 * re))); elseif (re <= 8.5e+180) tmp = Float64(sqrt(Float64(im + im)) * 0.5); else tmp = 0.0; end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.5e-9) tmp = 0.5 * sqrt((-4.0 * re)); elseif (re <= 8.5e+180) tmp = sqrt((im + im)) * 0.5; else tmp = 0.0; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.5e-9], N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 8.5e+180], N[(N[Sqrt[N[(im + im), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.5 \cdot 10^{-9}:\\
\;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\
\mathbf{elif}\;re \leq 8.5 \cdot 10^{+180}:\\
\;\;\;\;\sqrt{im + im} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if re < -1.49999999999999999e-9Initial program 45.9%
Taylor expanded in re around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6430.7
Applied rewrites30.7%
Taylor expanded in re around -inf
lower-*.f6487.9
Applied rewrites87.9%
if -1.49999999999999999e-9 < re < 8.50000000000000077e180Initial program 48.3%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6472.3
Applied rewrites72.3%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6472.3
Applied rewrites72.9%
Applied rewrites72.9%
if 8.50000000000000077e180 < re Initial program 2.6%
Applied rewrites32.5%
(FPCore (re im) :precision binary64 (if (<= im 1.9e-210) 0.0 (* (sqrt (+ im im)) 0.5)))
double code(double re, double im) {
double tmp;
if (im <= 1.9e-210) {
tmp = 0.0;
} else {
tmp = sqrt((im + im)) * 0.5;
}
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(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 1.9d-210) then
tmp = 0.0d0
else
tmp = sqrt((im + im)) * 0.5d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 1.9e-210) {
tmp = 0.0;
} else {
tmp = Math.sqrt((im + im)) * 0.5;
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 1.9e-210: tmp = 0.0 else: tmp = math.sqrt((im + im)) * 0.5 return tmp
function code(re, im) tmp = 0.0 if (im <= 1.9e-210) tmp = 0.0; else tmp = Float64(sqrt(Float64(im + im)) * 0.5); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 1.9e-210) tmp = 0.0; else tmp = sqrt((im + im)) * 0.5; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 1.9e-210], 0.0, N[(N[Sqrt[N[(im + im), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.9 \cdot 10^{-210}:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{im + im} \cdot 0.5\\
\end{array}
\end{array}
if im < 1.90000000000000002e-210Initial program 28.3%
Applied rewrites24.3%
if 1.90000000000000002e-210 < im Initial program 45.5%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f6459.3
Applied rewrites59.3%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6459.3
Applied rewrites59.7%
Applied rewrites59.7%
(FPCore (re im) :precision binary64 0.0)
double code(double re, double im) {
return 0.0;
}
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(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.0d0
end function
public static double code(double re, double im) {
return 0.0;
}
def code(re, im): return 0.0
function code(re, im) return 0.0 end
function tmp = code(re, im) tmp = 0.0; end
code[re_, im_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 42.8%
Applied rewrites6.4%
herbie shell --seed 2024358
(FPCore (re im)
:name "math.sqrt on complex, imaginary part, im greater than 0 branch"
:precision binary64
:pre (> im 0.0)
(* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))