
(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}
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 3.2e+125) (* (sqrt (* (- (hypot im re) re) 2.0)) 0.5) (* (* (* (* im (sqrt 0.5)) (sqrt (/ 1.0 re))) (sqrt 2.0)) 0.5)))
double code(double re, double im) {
double tmp;
if (re <= 3.2e+125) {
tmp = sqrt(((hypot(im, re) - re) * 2.0)) * 0.5;
} else {
tmp = (((im * sqrt(0.5)) * sqrt((1.0 / re))) * sqrt(2.0)) * 0.5;
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= 3.2e+125) {
tmp = Math.sqrt(((Math.hypot(im, re) - re) * 2.0)) * 0.5;
} else {
tmp = (((im * Math.sqrt(0.5)) * Math.sqrt((1.0 / re))) * Math.sqrt(2.0)) * 0.5;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 3.2e+125: tmp = math.sqrt(((math.hypot(im, re) - re) * 2.0)) * 0.5 else: tmp = (((im * math.sqrt(0.5)) * math.sqrt((1.0 / re))) * math.sqrt(2.0)) * 0.5 return tmp
function code(re, im) tmp = 0.0 if (re <= 3.2e+125) tmp = Float64(sqrt(Float64(Float64(hypot(im, re) - re) * 2.0)) * 0.5); else tmp = Float64(Float64(Float64(Float64(im * sqrt(0.5)) * sqrt(Float64(1.0 / re))) * sqrt(2.0)) * 0.5); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 3.2e+125) tmp = sqrt(((hypot(im, re) - re) * 2.0)) * 0.5; else tmp = (((im * sqrt(0.5)) * sqrt((1.0 / re))) * sqrt(2.0)) * 0.5; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 3.2e+125], N[(N[Sqrt[N[(N[(N[Sqrt[im ^ 2 + re ^ 2], $MachinePrecision] - re), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(N[(im * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 3.2 \cdot 10^{+125}:\\
\;\;\;\;\sqrt{\left(\mathsf{hypot}\left(im, re\right) - re\right) \cdot 2} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(im \cdot \sqrt{0.5}\right) \cdot \sqrt{\frac{1}{re}}\right) \cdot \sqrt{2}\right) \cdot 0.5\\
\end{array}
\end{array}
if re < 3.19999999999999983e125Initial program 47.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6447.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6447.7
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6487.0
Applied rewrites87.0%
if 3.19999999999999983e125 < re Initial program 5.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f645.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f645.0
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6435.2
Applied rewrites35.2%
lift-sqrt.f64N/A
lift-*.f64N/A
sqrt-prodN/A
lift-hypot.f64N/A
lift-*.f64N/A
pow2N/A
exp-to-powN/A
lift-log.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
+-commutativeN/A
lift-+.f64N/A
lift-sqrt.f64N/A
lower-*.f64N/A
Applied rewrites35.2%
lift-hypot.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
pow1/2N/A
unpow1N/A
sqr-powN/A
metadata-evalN/A
pow1/2N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-hypot.f64N/A
metadata-evalN/A
pow1/2N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-hypot.f64N/A
pow-prod-downN/A
lift-pow.f64N/A
lift-pow.f64N/A
pow2N/A
lower-pow.f6427.7
Applied rewrites27.7%
Taylor expanded in re around inf
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f6483.4
Applied rewrites83.4%
(FPCore (re im)
:precision binary64
(if (<= re -1.05e+126)
(* 0.5 (sqrt (* -4.0 re)))
(if (<= re -7.5e-79)
(* 0.5 (sqrt (* 2.0 (- (sqrt (fma re re (* im im))) re))))
(if (<= re 1.3e-104)
(* (* (sqrt (- im re)) (sqrt 2.0)) 0.5)
(* (* (* (* im (sqrt 0.5)) (sqrt (/ 1.0 re))) (sqrt 2.0)) 0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -1.05e+126) {
tmp = 0.5 * sqrt((-4.0 * re));
} else if (re <= -7.5e-79) {
tmp = 0.5 * sqrt((2.0 * (sqrt(fma(re, re, (im * im))) - re)));
} else if (re <= 1.3e-104) {
tmp = (sqrt((im - re)) * sqrt(2.0)) * 0.5;
} else {
tmp = (((im * sqrt(0.5)) * sqrt((1.0 / re))) * sqrt(2.0)) * 0.5;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= -1.05e+126) tmp = Float64(0.5 * sqrt(Float64(-4.0 * re))); elseif (re <= -7.5e-79) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(re, re, Float64(im * im))) - re)))); elseif (re <= 1.3e-104) tmp = Float64(Float64(sqrt(Float64(im - re)) * sqrt(2.0)) * 0.5); else tmp = Float64(Float64(Float64(Float64(im * sqrt(0.5)) * sqrt(Float64(1.0 / re))) * sqrt(2.0)) * 0.5); end return tmp end
code[re_, im_] := If[LessEqual[re, -1.05e+126], N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -7.5e-79], 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, 1.3e-104], N[(N[(N[Sqrt[N[(im - re), $MachinePrecision]], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(N[(im * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.05 \cdot 10^{+126}:\\
\;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\
\mathbf{elif}\;re \leq -7.5 \cdot 10^{-79}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(re, re, im \cdot im\right)} - re\right)}\\
\mathbf{elif}\;re \leq 1.3 \cdot 10^{-104}:\\
\;\;\;\;\left(\sqrt{im - re} \cdot \sqrt{2}\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(im \cdot \sqrt{0.5}\right) \cdot \sqrt{\frac{1}{re}}\right) \cdot \sqrt{2}\right) \cdot 0.5\\
\end{array}
\end{array}
if re < -1.05e126Initial program 14.8%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6414.8
Applied rewrites14.8%
lift-fma.f64N/A
pow2N/A
exp-to-powN/A
lift-log.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
flip3-+N/A
lower-/.f64N/A
Applied rewrites0.0%
lift-*.f64N/A
rem-exp-logN/A
lift-log.f64N/A
rem-exp-logN/A
lift-log.f64N/A
exp-lft-sqr-revN/A
lower-exp.f64N/A
lower-*.f640.0
Applied rewrites0.0%
Taylor expanded in re around -inf
lower-*.f6486.3
Applied rewrites86.3%
if -1.05e126 < re < -7.49999999999999969e-79Initial program 76.8%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6476.8
Applied rewrites76.8%
if -7.49999999999999969e-79 < re < 1.30000000000000001e-104Initial program 57.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6457.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6457.2
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6493.3
Applied rewrites93.3%
lift-sqrt.f64N/A
lift-*.f64N/A
sqrt-prodN/A
lift-hypot.f64N/A
lift-*.f64N/A
pow2N/A
exp-to-powN/A
lift-log.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
+-commutativeN/A
lift-+.f64N/A
lift-sqrt.f64N/A
lower-*.f64N/A
Applied rewrites92.7%
lift-hypot.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
pow1/2N/A
unpow1N/A
sqr-powN/A
metadata-evalN/A
pow1/2N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-hypot.f64N/A
metadata-evalN/A
pow1/2N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-hypot.f64N/A
pow-prod-downN/A
lift-pow.f64N/A
lift-pow.f64N/A
pow2N/A
lower-pow.f6492.6
Applied rewrites92.6%
Taylor expanded in re around 0
Applied rewrites83.1%
if 1.30000000000000001e-104 < re Initial program 18.9%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6418.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6418.9
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6445.0
Applied rewrites45.0%
lift-sqrt.f64N/A
lift-*.f64N/A
sqrt-prodN/A
lift-hypot.f64N/A
lift-*.f64N/A
pow2N/A
exp-to-powN/A
lift-log.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
+-commutativeN/A
lift-+.f64N/A
lift-sqrt.f64N/A
lower-*.f64N/A
Applied rewrites44.8%
lift-hypot.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
pow1/2N/A
unpow1N/A
sqr-powN/A
metadata-evalN/A
pow1/2N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-hypot.f64N/A
metadata-evalN/A
pow1/2N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-hypot.f64N/A
pow-prod-downN/A
lift-pow.f64N/A
lift-pow.f64N/A
pow2N/A
lower-pow.f6440.7
Applied rewrites40.7%
Taylor expanded in re around inf
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f6467.5
Applied rewrites67.5%
(FPCore (re im)
:precision binary64
(if (<= re -1.05e+126)
(* 0.5 (sqrt (* -4.0 re)))
(if (<= re -7.5e-79)
(* 0.5 (sqrt (* 2.0 (- (sqrt (fma re re (* im im))) re))))
(if (<= re 1.3e-104)
(* (* (sqrt (- im re)) (sqrt 2.0)) 0.5)
(* (* (* im (* (sqrt 0.5) (sqrt 2.0))) (sqrt (/ 1.0 re))) 0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -1.05e+126) {
tmp = 0.5 * sqrt((-4.0 * re));
} else if (re <= -7.5e-79) {
tmp = 0.5 * sqrt((2.0 * (sqrt(fma(re, re, (im * im))) - re)));
} else if (re <= 1.3e-104) {
tmp = (sqrt((im - re)) * sqrt(2.0)) * 0.5;
} else {
tmp = ((im * (sqrt(0.5) * sqrt(2.0))) * sqrt((1.0 / re))) * 0.5;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= -1.05e+126) tmp = Float64(0.5 * sqrt(Float64(-4.0 * re))); elseif (re <= -7.5e-79) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(re, re, Float64(im * im))) - re)))); elseif (re <= 1.3e-104) tmp = Float64(Float64(sqrt(Float64(im - re)) * sqrt(2.0)) * 0.5); else tmp = Float64(Float64(Float64(im * Float64(sqrt(0.5) * sqrt(2.0))) * sqrt(Float64(1.0 / re))) * 0.5); end return tmp end
code[re_, im_] := If[LessEqual[re, -1.05e+126], N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -7.5e-79], 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, 1.3e-104], N[(N[(N[Sqrt[N[(im - re), $MachinePrecision]], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(im * N[(N[Sqrt[0.5], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.05 \cdot 10^{+126}:\\
\;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\
\mathbf{elif}\;re \leq -7.5 \cdot 10^{-79}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(re, re, im \cdot im\right)} - re\right)}\\
\mathbf{elif}\;re \leq 1.3 \cdot 10^{-104}:\\
\;\;\;\;\left(\sqrt{im - re} \cdot \sqrt{2}\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(\left(im \cdot \left(\sqrt{0.5} \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{re}}\right) \cdot 0.5\\
\end{array}
\end{array}
if re < -1.05e126Initial program 14.8%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6414.8
Applied rewrites14.8%
lift-fma.f64N/A
pow2N/A
exp-to-powN/A
lift-log.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
flip3-+N/A
lower-/.f64N/A
Applied rewrites0.0%
lift-*.f64N/A
rem-exp-logN/A
lift-log.f64N/A
rem-exp-logN/A
lift-log.f64N/A
exp-lft-sqr-revN/A
lower-exp.f64N/A
lower-*.f640.0
Applied rewrites0.0%
Taylor expanded in re around -inf
lower-*.f6486.3
Applied rewrites86.3%
if -1.05e126 < re < -7.49999999999999969e-79Initial program 76.8%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6476.8
Applied rewrites76.8%
if -7.49999999999999969e-79 < re < 1.30000000000000001e-104Initial program 57.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6457.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6457.2
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6493.3
Applied rewrites93.3%
lift-sqrt.f64N/A
lift-*.f64N/A
sqrt-prodN/A
lift-hypot.f64N/A
lift-*.f64N/A
pow2N/A
exp-to-powN/A
lift-log.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
+-commutativeN/A
lift-+.f64N/A
lift-sqrt.f64N/A
lower-*.f64N/A
Applied rewrites92.7%
lift-hypot.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
pow1/2N/A
unpow1N/A
sqr-powN/A
metadata-evalN/A
pow1/2N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-hypot.f64N/A
metadata-evalN/A
pow1/2N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-hypot.f64N/A
pow-prod-downN/A
lift-pow.f64N/A
lift-pow.f64N/A
pow2N/A
lower-pow.f6492.6
Applied rewrites92.6%
Taylor expanded in re around 0
Applied rewrites83.1%
if 1.30000000000000001e-104 < re Initial program 18.9%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6418.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6418.9
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6445.0
Applied rewrites45.0%
lift-sqrt.f64N/A
lift-*.f64N/A
sqrt-prodN/A
lift-hypot.f64N/A
lift-*.f64N/A
pow2N/A
exp-to-powN/A
lift-log.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
+-commutativeN/A
lift-+.f64N/A
lift-sqrt.f64N/A
lower-*.f64N/A
Applied rewrites44.8%
lift-hypot.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
pow1/2N/A
unpow1N/A
sqr-powN/A
metadata-evalN/A
pow1/2N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-hypot.f64N/A
metadata-evalN/A
pow1/2N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-hypot.f64N/A
pow-prod-downN/A
lift-pow.f64N/A
lift-pow.f64N/A
pow2N/A
lower-pow.f6440.7
Applied rewrites40.7%
Taylor expanded in re around inf
lower-*.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f6467.1
Applied rewrites67.1%
(FPCore (re im)
:precision binary64
(if (<= re -1.05e+126)
(* 0.5 (sqrt (* -4.0 re)))
(if (<= re -7.5e-79)
(* 0.5 (sqrt (* 2.0 (- (sqrt (fma re re (* im im))) re))))
(* (* (sqrt im) (sqrt 2.0)) 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -1.05e+126) {
tmp = 0.5 * sqrt((-4.0 * re));
} else if (re <= -7.5e-79) {
tmp = 0.5 * sqrt((2.0 * (sqrt(fma(re, re, (im * im))) - re)));
} else {
tmp = (sqrt(im) * sqrt(2.0)) * 0.5;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= -1.05e+126) tmp = Float64(0.5 * sqrt(Float64(-4.0 * re))); elseif (re <= -7.5e-79) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(re, re, Float64(im * im))) - re)))); else tmp = Float64(Float64(sqrt(im) * sqrt(2.0)) * 0.5); end return tmp end
code[re_, im_] := If[LessEqual[re, -1.05e+126], N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -7.5e-79], 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], N[(N[(N[Sqrt[im], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.05 \cdot 10^{+126}:\\
\;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\
\mathbf{elif}\;re \leq -7.5 \cdot 10^{-79}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(re, re, im \cdot im\right)} - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(\sqrt{im} \cdot \sqrt{2}\right) \cdot 0.5\\
\end{array}
\end{array}
if re < -1.05e126Initial program 14.8%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6414.8
Applied rewrites14.8%
lift-fma.f64N/A
pow2N/A
exp-to-powN/A
lift-log.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
flip3-+N/A
lower-/.f64N/A
Applied rewrites0.0%
lift-*.f64N/A
rem-exp-logN/A
lift-log.f64N/A
rem-exp-logN/A
lift-log.f64N/A
exp-lft-sqr-revN/A
lower-exp.f64N/A
lower-*.f640.0
Applied rewrites0.0%
Taylor expanded in re around -inf
lower-*.f6486.3
Applied rewrites86.3%
if -1.05e126 < re < -7.49999999999999969e-79Initial program 76.8%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6476.8
Applied rewrites76.8%
if -7.49999999999999969e-79 < re Initial program 38.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6438.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6438.5
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6469.7
Applied rewrites69.7%
lift-sqrt.f64N/A
lift-*.f64N/A
sqrt-prodN/A
lift-hypot.f64N/A
lift-*.f64N/A
pow2N/A
exp-to-powN/A
lift-log.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
+-commutativeN/A
lift-+.f64N/A
lift-sqrt.f64N/A
lower-*.f64N/A
Applied rewrites69.3%
lift-hypot.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
pow1/2N/A
unpow1N/A
sqr-powN/A
metadata-evalN/A
pow1/2N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-hypot.f64N/A
metadata-evalN/A
pow1/2N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-hypot.f64N/A
pow-prod-downN/A
lift-pow.f64N/A
lift-pow.f64N/A
pow2N/A
lower-pow.f6467.3
Applied rewrites67.3%
Taylor expanded in re around 0
Applied rewrites59.9%
(FPCore (re im) :precision binary64 (if (<= re -2.4e-46) (* 0.5 (sqrt (* -4.0 re))) (* (* (sqrt im) (sqrt 2.0)) 0.5)))
double code(double re, double im) {
double tmp;
if (re <= -2.4e-46) {
tmp = 0.5 * sqrt((-4.0 * re));
} else {
tmp = (sqrt(im) * sqrt(2.0)) * 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 <= (-2.4d-46)) then
tmp = 0.5d0 * sqrt(((-4.0d0) * re))
else
tmp = (sqrt(im) * sqrt(2.0d0)) * 0.5d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -2.4e-46) {
tmp = 0.5 * Math.sqrt((-4.0 * re));
} else {
tmp = (Math.sqrt(im) * Math.sqrt(2.0)) * 0.5;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2.4e-46: tmp = 0.5 * math.sqrt((-4.0 * re)) else: tmp = (math.sqrt(im) * math.sqrt(2.0)) * 0.5 return tmp
function code(re, im) tmp = 0.0 if (re <= -2.4e-46) tmp = Float64(0.5 * sqrt(Float64(-4.0 * re))); else tmp = Float64(Float64(sqrt(im) * sqrt(2.0)) * 0.5); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2.4e-46) tmp = 0.5 * sqrt((-4.0 * re)); else tmp = (sqrt(im) * sqrt(2.0)) * 0.5; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.4e-46], N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[im], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.4 \cdot 10^{-46}:\\
\;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\
\mathbf{else}:\\
\;\;\;\;\left(\sqrt{im} \cdot \sqrt{2}\right) \cdot 0.5\\
\end{array}
\end{array}
if re < -2.40000000000000013e-46Initial program 45.1%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6445.1
Applied rewrites45.1%
lift-fma.f64N/A
pow2N/A
exp-to-powN/A
lift-log.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
flip3-+N/A
lower-/.f64N/A
Applied rewrites16.9%
lift-*.f64N/A
rem-exp-logN/A
lift-log.f64N/A
rem-exp-logN/A
lift-log.f64N/A
exp-lft-sqr-revN/A
lower-exp.f64N/A
lower-*.f640.0
Applied rewrites0.0%
Taylor expanded in re around -inf
lower-*.f6474.8
Applied rewrites74.8%
if -2.40000000000000013e-46 < re Initial program 39.9%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6439.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6439.9
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6470.9
Applied rewrites70.9%
lift-sqrt.f64N/A
lift-*.f64N/A
sqrt-prodN/A
lift-hypot.f64N/A
lift-*.f64N/A
pow2N/A
exp-to-powN/A
lift-log.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
+-commutativeN/A
lift-+.f64N/A
lift-sqrt.f64N/A
lower-*.f64N/A
Applied rewrites70.5%
lift-hypot.f64N/A
lift-*.f64N/A
lift-fma.f64N/A
pow1/2N/A
unpow1N/A
sqr-powN/A
metadata-evalN/A
pow1/2N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-hypot.f64N/A
metadata-evalN/A
pow1/2N/A
lift-fma.f64N/A
lift-*.f64N/A
lift-hypot.f64N/A
pow-prod-downN/A
lift-pow.f64N/A
lift-pow.f64N/A
pow2N/A
lower-pow.f6468.5
Applied rewrites68.5%
Taylor expanded in re around 0
Applied rewrites59.9%
(FPCore (re im) :precision binary64 (if (<= re -2.4e-46) (* 0.5 (sqrt (* -4.0 re))) (* 0.5 (sqrt (* 2.0 im)))))
double code(double re, double im) {
double tmp;
if (re <= -2.4e-46) {
tmp = 0.5 * sqrt((-4.0 * re));
} else {
tmp = 0.5 * sqrt((2.0 * 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(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-2.4d-46)) then
tmp = 0.5d0 * sqrt(((-4.0d0) * re))
else
tmp = 0.5d0 * sqrt((2.0d0 * im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -2.4e-46) {
tmp = 0.5 * Math.sqrt((-4.0 * re));
} else {
tmp = 0.5 * Math.sqrt((2.0 * im));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -2.4e-46: tmp = 0.5 * math.sqrt((-4.0 * re)) else: tmp = 0.5 * math.sqrt((2.0 * im)) return tmp
function code(re, im) tmp = 0.0 if (re <= -2.4e-46) tmp = Float64(0.5 * sqrt(Float64(-4.0 * re))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -2.4e-46) tmp = 0.5 * sqrt((-4.0 * re)); else tmp = 0.5 * sqrt((2.0 * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -2.4e-46], N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -2.4 \cdot 10^{-46}:\\
\;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\end{array}
\end{array}
if re < -2.40000000000000013e-46Initial program 45.1%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6445.1
Applied rewrites45.1%
lift-fma.f64N/A
pow2N/A
exp-to-powN/A
lift-log.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
flip3-+N/A
lower-/.f64N/A
Applied rewrites16.9%
lift-*.f64N/A
rem-exp-logN/A
lift-log.f64N/A
rem-exp-logN/A
lift-log.f64N/A
exp-lft-sqr-revN/A
lower-exp.f64N/A
lower-*.f640.0
Applied rewrites0.0%
Taylor expanded in re around -inf
lower-*.f6474.8
Applied rewrites74.8%
if -2.40000000000000013e-46 < re Initial program 39.9%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6439.9
Applied rewrites39.9%
lift-fma.f64N/A
pow2N/A
exp-to-powN/A
lift-log.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
flip3-+N/A
lower-/.f64N/A
Applied rewrites12.1%
lift-*.f64N/A
rem-exp-logN/A
lift-log.f64N/A
rem-exp-logN/A
lift-log.f64N/A
exp-lft-sqr-revN/A
lower-exp.f64N/A
lower-*.f646.1
Applied rewrites6.1%
Taylor expanded in re around 0
Applied rewrites60.2%
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* -4.0 re))))
double code(double re, double im) {
return 0.5 * sqrt((-4.0 * 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(((-4.0d0) * re))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((-4.0 * re));
}
def code(re, im): return 0.5 * math.sqrt((-4.0 * re))
function code(re, im) return Float64(0.5 * sqrt(Float64(-4.0 * re))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((-4.0 * re)); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{-4 \cdot re}
\end{array}
Initial program 41.4%
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6441.4
Applied rewrites41.4%
lift-fma.f64N/A
pow2N/A
exp-to-powN/A
lift-log.f64N/A
lift-*.f64N/A
lift-exp.f64N/A
flip3-+N/A
lower-/.f64N/A
Applied rewrites13.5%
lift-*.f64N/A
rem-exp-logN/A
lift-log.f64N/A
rem-exp-logN/A
lift-log.f64N/A
exp-lft-sqr-revN/A
lower-exp.f64N/A
lower-*.f644.4
Applied rewrites4.4%
Taylor expanded in re around -inf
lower-*.f6427.4
Applied rewrites27.4%
herbie shell --seed 2025108
(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)))))