
(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 13 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 2.1e-35)
(* (sqrt (* (- (hypot im re) re) 2.0)) 0.5)
(*
(* (* (pow 0.5 0.25) (pow 0.5 0.25)) 0.5)
(* im (* (pow re -0.5) (sqrt 2.0))))))
double code(double re, double im) {
double tmp;
if (re <= 2.1e-35) {
tmp = sqrt(((hypot(im, re) - re) * 2.0)) * 0.5;
} else {
tmp = ((pow(0.5, 0.25) * pow(0.5, 0.25)) * 0.5) * (im * (pow(re, -0.5) * sqrt(2.0)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= 2.1e-35) {
tmp = Math.sqrt(((Math.hypot(im, re) - re) * 2.0)) * 0.5;
} else {
tmp = ((Math.pow(0.5, 0.25) * Math.pow(0.5, 0.25)) * 0.5) * (im * (Math.pow(re, -0.5) * Math.sqrt(2.0)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 2.1e-35: tmp = math.sqrt(((math.hypot(im, re) - re) * 2.0)) * 0.5 else: tmp = ((math.pow(0.5, 0.25) * math.pow(0.5, 0.25)) * 0.5) * (im * (math.pow(re, -0.5) * math.sqrt(2.0))) return tmp
function code(re, im) tmp = 0.0 if (re <= 2.1e-35) tmp = Float64(sqrt(Float64(Float64(hypot(im, re) - re) * 2.0)) * 0.5); else tmp = Float64(Float64(Float64((0.5 ^ 0.25) * (0.5 ^ 0.25)) * 0.5) * Float64(im * Float64((re ^ -0.5) * sqrt(2.0)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 2.1e-35) tmp = sqrt(((hypot(im, re) - re) * 2.0)) * 0.5; else tmp = (((0.5 ^ 0.25) * (0.5 ^ 0.25)) * 0.5) * (im * ((re ^ -0.5) * sqrt(2.0))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 2.1e-35], 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[Power[0.5, 0.25], $MachinePrecision] * N[Power[0.5, 0.25], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision] * N[(im * N[(N[Power[re, -0.5], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 2.1 \cdot 10^{-35}:\\
\;\;\;\;\sqrt{\left(\mathsf{hypot}\left(im, re\right) - re\right) \cdot 2} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(\left({0.5}^{0.25} \cdot {0.5}^{0.25}\right) \cdot 0.5\right) \cdot \left(im \cdot \left({re}^{-0.5} \cdot \sqrt{2}\right)\right)\\
\end{array}
\end{array}
if re < 2.1e-35Initial program 55.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6455.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6455.2
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6495.2
Applied rewrites95.2%
if 2.1e-35 < re Initial program 10.5%
Taylor expanded in re around inf
associate-*r*N/A
lower-*.f64N/A
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f6475.6
Applied rewrites75.6%
Applied rewrites75.8%
Applied rewrites76.2%
(FPCore (re im)
:precision binary64
(if (<= re 2.1e-35)
(* (sqrt (* (- (hypot im re) re) 2.0)) 0.5)
(*
(* (* (sqrt (pow re -1.0)) (* (sqrt 0.5) im)) (exp (* (log 2.0) 0.5)))
0.5)))
double code(double re, double im) {
double tmp;
if (re <= 2.1e-35) {
tmp = sqrt(((hypot(im, re) - re) * 2.0)) * 0.5;
} else {
tmp = ((sqrt(pow(re, -1.0)) * (sqrt(0.5) * im)) * exp((log(2.0) * 0.5))) * 0.5;
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= 2.1e-35) {
tmp = Math.sqrt(((Math.hypot(im, re) - re) * 2.0)) * 0.5;
} else {
tmp = ((Math.sqrt(Math.pow(re, -1.0)) * (Math.sqrt(0.5) * im)) * Math.exp((Math.log(2.0) * 0.5))) * 0.5;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 2.1e-35: tmp = math.sqrt(((math.hypot(im, re) - re) * 2.0)) * 0.5 else: tmp = ((math.sqrt(math.pow(re, -1.0)) * (math.sqrt(0.5) * im)) * math.exp((math.log(2.0) * 0.5))) * 0.5 return tmp
function code(re, im) tmp = 0.0 if (re <= 2.1e-35) tmp = Float64(sqrt(Float64(Float64(hypot(im, re) - re) * 2.0)) * 0.5); else tmp = Float64(Float64(Float64(sqrt((re ^ -1.0)) * Float64(sqrt(0.5) * im)) * exp(Float64(log(2.0) * 0.5))) * 0.5); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 2.1e-35) tmp = sqrt(((hypot(im, re) - re) * 2.0)) * 0.5; else tmp = ((sqrt((re ^ -1.0)) * (sqrt(0.5) * im)) * exp((log(2.0) * 0.5))) * 0.5; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 2.1e-35], 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[Sqrt[N[Power[re, -1.0], $MachinePrecision]], $MachinePrecision] * N[(N[Sqrt[0.5], $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[Log[2.0], $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 2.1 \cdot 10^{-35}:\\
\;\;\;\;\sqrt{\left(\mathsf{hypot}\left(im, re\right) - re\right) \cdot 2} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\sqrt{{re}^{-1}} \cdot \left(\sqrt{0.5} \cdot im\right)\right) \cdot e^{\log 2 \cdot 0.5}\right) \cdot 0.5\\
\end{array}
\end{array}
if re < 2.1e-35Initial program 55.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6455.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6455.2
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6495.2
Applied rewrites95.2%
if 2.1e-35 < re Initial program 10.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6410.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6410.5
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6438.4
Applied rewrites38.4%
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.f6475.6
Applied rewrites75.6%
Applied rewrites76.1%
Final simplification89.6%
(FPCore (re im)
:precision binary64
(if (<= re -7e+146)
(* (sqrt (* -4.0 re)) 0.5)
(if (<= re -9e-125)
(* 0.5 (sqrt (* 2.0 (- (sqrt (fma im im (* re re))) re))))
(if (<= re 2.1e-35)
(* (sqrt (+ (fma -2.0 re im) im)) 0.5)
(* (* (sqrt 0.5) 0.5) (* im (* (sqrt (pow re -1.0)) (sqrt 2.0))))))))
double code(double re, double im) {
double tmp;
if (re <= -7e+146) {
tmp = sqrt((-4.0 * re)) * 0.5;
} else if (re <= -9e-125) {
tmp = 0.5 * sqrt((2.0 * (sqrt(fma(im, im, (re * re))) - re)));
} else if (re <= 2.1e-35) {
tmp = sqrt((fma(-2.0, re, im) + im)) * 0.5;
} else {
tmp = (sqrt(0.5) * 0.5) * (im * (sqrt(pow(re, -1.0)) * sqrt(2.0)));
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= -7e+146) tmp = Float64(sqrt(Float64(-4.0 * re)) * 0.5); elseif (re <= -9e-125) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(im, im, Float64(re * re))) - re)))); elseif (re <= 2.1e-35) tmp = Float64(sqrt(Float64(fma(-2.0, re, im) + im)) * 0.5); else tmp = Float64(Float64(sqrt(0.5) * 0.5) * Float64(im * Float64(sqrt((re ^ -1.0)) * sqrt(2.0)))); end return tmp end
code[re_, im_] := If[LessEqual[re, -7e+146], N[(N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[re, -9e-125], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(im * im + N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.1e-35], N[(N[Sqrt[N[(N[(-2.0 * re + im), $MachinePrecision] + im), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[Sqrt[0.5], $MachinePrecision] * 0.5), $MachinePrecision] * N[(im * N[(N[Sqrt[N[Power[re, -1.0], $MachinePrecision]], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -7 \cdot 10^{+146}:\\
\;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\
\mathbf{elif}\;re \leq -9 \cdot 10^{-125}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)} - re\right)}\\
\mathbf{elif}\;re \leq 2.1 \cdot 10^{-35}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, re, im\right) + im} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(\sqrt{0.5} \cdot 0.5\right) \cdot \left(im \cdot \left(\sqrt{{re}^{-1}} \cdot \sqrt{2}\right)\right)\\
\end{array}
\end{array}
if re < -7.0000000000000002e146Initial program 4.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f644.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f644.2
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f64100.0
Applied rewrites100.0%
Taylor expanded in re around -inf
lower-*.f6484.4
Applied rewrites84.4%
if -7.0000000000000002e146 < re < -9.00000000000000024e-125Initial program 79.6%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6479.6
Applied rewrites79.6%
if -9.00000000000000024e-125 < re < 2.1e-35Initial program 50.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6450.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6450.4
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6490.7
Applied rewrites90.7%
Taylor expanded in re around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6483.8
Applied rewrites83.8%
Applied rewrites83.8%
Taylor expanded in re around 0
Applied rewrites84.1%
if 2.1e-35 < re Initial program 10.5%
Taylor expanded in re around inf
associate-*r*N/A
lower-*.f64N/A
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f6475.6
Applied rewrites75.6%
Applied rewrites75.8%
Taylor expanded in re around 0
Applied rewrites75.7%
Final simplification80.5%
(FPCore (re im) :precision binary64 (if (<= re 2.45e-32) (* (sqrt (* (- (hypot im re) re) 2.0)) 0.5) (* (* (sqrt 0.5) 0.5) (* im (* (sqrt (pow re -1.0)) (sqrt 2.0))))))
double code(double re, double im) {
double tmp;
if (re <= 2.45e-32) {
tmp = sqrt(((hypot(im, re) - re) * 2.0)) * 0.5;
} else {
tmp = (sqrt(0.5) * 0.5) * (im * (sqrt(pow(re, -1.0)) * sqrt(2.0)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= 2.45e-32) {
tmp = Math.sqrt(((Math.hypot(im, re) - re) * 2.0)) * 0.5;
} else {
tmp = (Math.sqrt(0.5) * 0.5) * (im * (Math.sqrt(Math.pow(re, -1.0)) * Math.sqrt(2.0)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 2.45e-32: tmp = math.sqrt(((math.hypot(im, re) - re) * 2.0)) * 0.5 else: tmp = (math.sqrt(0.5) * 0.5) * (im * (math.sqrt(math.pow(re, -1.0)) * math.sqrt(2.0))) return tmp
function code(re, im) tmp = 0.0 if (re <= 2.45e-32) tmp = Float64(sqrt(Float64(Float64(hypot(im, re) - re) * 2.0)) * 0.5); else tmp = Float64(Float64(sqrt(0.5) * 0.5) * Float64(im * Float64(sqrt((re ^ -1.0)) * sqrt(2.0)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 2.45e-32) tmp = sqrt(((hypot(im, re) - re) * 2.0)) * 0.5; else tmp = (sqrt(0.5) * 0.5) * (im * (sqrt((re ^ -1.0)) * sqrt(2.0))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 2.45e-32], N[(N[Sqrt[N[(N[(N[Sqrt[im ^ 2 + re ^ 2], $MachinePrecision] - re), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[Sqrt[0.5], $MachinePrecision] * 0.5), $MachinePrecision] * N[(im * N[(N[Sqrt[N[Power[re, -1.0], $MachinePrecision]], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 2.45 \cdot 10^{-32}:\\
\;\;\;\;\sqrt{\left(\mathsf{hypot}\left(im, re\right) - re\right) \cdot 2} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(\sqrt{0.5} \cdot 0.5\right) \cdot \left(im \cdot \left(\sqrt{{re}^{-1}} \cdot \sqrt{2}\right)\right)\\
\end{array}
\end{array}
if re < 2.4499999999999999e-32Initial program 55.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6455.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6455.2
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6495.2
Applied rewrites95.2%
if 2.4499999999999999e-32 < re Initial program 10.5%
Taylor expanded in re around inf
associate-*r*N/A
lower-*.f64N/A
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f6475.6
Applied rewrites75.6%
Applied rewrites75.8%
Taylor expanded in re around 0
Applied rewrites75.7%
Final simplification89.5%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re))))))
(if (<= t_0 5e-83)
(* (sqrt (/ (* im im) re)) 0.5)
(if (<= t_0 2e+73)
(* 0.5 (sqrt (* 2.0 (- (sqrt (fma im im (* re re))) re))))
(* 0.5 (sqrt (* 2.0 (- im re))))))))
double code(double re, double im) {
double t_0 = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re)));
double tmp;
if (t_0 <= 5e-83) {
tmp = sqrt(((im * im) / re)) * 0.5;
} else if (t_0 <= 2e+73) {
tmp = 0.5 * sqrt((2.0 * (sqrt(fma(im, im, (re * re))) - re)));
} else {
tmp = 0.5 * sqrt((2.0 * (im - re)));
}
return tmp;
}
function code(re, im) t_0 = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re)))) tmp = 0.0 if (t_0 <= 5e-83) tmp = Float64(sqrt(Float64(Float64(im * im) / re)) * 0.5); elseif (t_0 <= 2e+73) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(im, im, Float64(re * re))) - re)))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); end return tmp end
code[re_, im_] := Block[{t$95$0 = 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]}, If[LessEqual[t$95$0, 5e-83], N[(N[Sqrt[N[(N[(im * im), $MachinePrecision] / re), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[t$95$0, 2e+73], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(im * im + N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\\
\mathbf{if}\;t\_0 \leq 5 \cdot 10^{-83}:\\
\;\;\;\;\sqrt{\frac{im \cdot im}{re}} \cdot 0.5\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+73}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)} - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\end{array}
\end{array}
if (*.f64 #s(literal 1/2 binary64) (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re)))) < 5e-83Initial program 12.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6412.7
lift-*.f64N/A
*-commutativeN/A
lower-*.f6412.7
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6426.3
Applied rewrites26.3%
Taylor expanded in re around inf
lower-/.f64N/A
unpow2N/A
lower-*.f6449.0
Applied rewrites49.0%
if 5e-83 < (*.f64 #s(literal 1/2 binary64) (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re)))) < 1.99999999999999997e73Initial program 98.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6498.8
Applied rewrites98.8%
if 1.99999999999999997e73 < (*.f64 #s(literal 1/2 binary64) (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re)))) Initial program 6.7%
Taylor expanded in re around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6459.5
Applied rewrites59.5%
(FPCore (re im) :precision binary64 (if (<= re 2.45e-32) (* (sqrt (* (- (hypot im re) re) 2.0)) 0.5) (* (* (sqrt 0.5) 0.5) (* im (* (pow re -0.5) (sqrt 2.0))))))
double code(double re, double im) {
double tmp;
if (re <= 2.45e-32) {
tmp = sqrt(((hypot(im, re) - re) * 2.0)) * 0.5;
} else {
tmp = (sqrt(0.5) * 0.5) * (im * (pow(re, -0.5) * sqrt(2.0)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= 2.45e-32) {
tmp = Math.sqrt(((Math.hypot(im, re) - re) * 2.0)) * 0.5;
} else {
tmp = (Math.sqrt(0.5) * 0.5) * (im * (Math.pow(re, -0.5) * Math.sqrt(2.0)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 2.45e-32: tmp = math.sqrt(((math.hypot(im, re) - re) * 2.0)) * 0.5 else: tmp = (math.sqrt(0.5) * 0.5) * (im * (math.pow(re, -0.5) * math.sqrt(2.0))) return tmp
function code(re, im) tmp = 0.0 if (re <= 2.45e-32) tmp = Float64(sqrt(Float64(Float64(hypot(im, re) - re) * 2.0)) * 0.5); else tmp = Float64(Float64(sqrt(0.5) * 0.5) * Float64(im * Float64((re ^ -0.5) * sqrt(2.0)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 2.45e-32) tmp = sqrt(((hypot(im, re) - re) * 2.0)) * 0.5; else tmp = (sqrt(0.5) * 0.5) * (im * ((re ^ -0.5) * sqrt(2.0))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 2.45e-32], N[(N[Sqrt[N[(N[(N[Sqrt[im ^ 2 + re ^ 2], $MachinePrecision] - re), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[Sqrt[0.5], $MachinePrecision] * 0.5), $MachinePrecision] * N[(im * N[(N[Power[re, -0.5], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 2.45 \cdot 10^{-32}:\\
\;\;\;\;\sqrt{\left(\mathsf{hypot}\left(im, re\right) - re\right) \cdot 2} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(\sqrt{0.5} \cdot 0.5\right) \cdot \left(im \cdot \left({re}^{-0.5} \cdot \sqrt{2}\right)\right)\\
\end{array}
\end{array}
if re < 2.4499999999999999e-32Initial program 55.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6455.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f6455.2
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6495.2
Applied rewrites95.2%
if 2.4499999999999999e-32 < re Initial program 10.5%
Taylor expanded in re around inf
associate-*r*N/A
lower-*.f64N/A
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f6475.6
Applied rewrites75.6%
Applied rewrites75.8%
(FPCore (re im)
:precision binary64
(if (<= re -7e+146)
(* (sqrt (* -4.0 re)) 0.5)
(if (<= re -9e-125)
(* 0.5 (sqrt (* 2.0 (- (sqrt (fma im im (* re re))) re))))
(if (<= re 2.1e-35)
(* (sqrt (+ (fma -2.0 re im) im)) 0.5)
(* (/ (* (* (sqrt 2.0) im) (sqrt 0.5)) (sqrt re)) 0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -7e+146) {
tmp = sqrt((-4.0 * re)) * 0.5;
} else if (re <= -9e-125) {
tmp = 0.5 * sqrt((2.0 * (sqrt(fma(im, im, (re * re))) - re)));
} else if (re <= 2.1e-35) {
tmp = sqrt((fma(-2.0, re, im) + im)) * 0.5;
} else {
tmp = (((sqrt(2.0) * im) * sqrt(0.5)) / sqrt(re)) * 0.5;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= -7e+146) tmp = Float64(sqrt(Float64(-4.0 * re)) * 0.5); elseif (re <= -9e-125) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(im, im, Float64(re * re))) - re)))); elseif (re <= 2.1e-35) tmp = Float64(sqrt(Float64(fma(-2.0, re, im) + im)) * 0.5); else tmp = Float64(Float64(Float64(Float64(sqrt(2.0) * im) * sqrt(0.5)) / sqrt(re)) * 0.5); end return tmp end
code[re_, im_] := If[LessEqual[re, -7e+146], N[(N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[re, -9e-125], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(im * im + N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.1e-35], N[(N[Sqrt[N[(N[(-2.0 * re + im), $MachinePrecision] + im), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(N[(N[Sqrt[2.0], $MachinePrecision] * im), $MachinePrecision] * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -7 \cdot 10^{+146}:\\
\;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\
\mathbf{elif}\;re \leq -9 \cdot 10^{-125}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)} - re\right)}\\
\mathbf{elif}\;re \leq 2.1 \cdot 10^{-35}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, re, im\right) + im} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\sqrt{2} \cdot im\right) \cdot \sqrt{0.5}}{\sqrt{re}} \cdot 0.5\\
\end{array}
\end{array}
if re < -7.0000000000000002e146Initial program 4.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f644.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f644.2
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f64100.0
Applied rewrites100.0%
Taylor expanded in re around -inf
lower-*.f6484.4
Applied rewrites84.4%
if -7.0000000000000002e146 < re < -9.00000000000000024e-125Initial program 79.6%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6479.6
Applied rewrites79.6%
if -9.00000000000000024e-125 < re < 2.1e-35Initial program 50.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6450.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6450.4
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6490.7
Applied rewrites90.7%
Taylor expanded in re around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6483.8
Applied rewrites83.8%
Applied rewrites83.8%
Taylor expanded in re around 0
Applied rewrites84.1%
if 2.1e-35 < re Initial program 10.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6410.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6410.5
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6438.4
Applied rewrites38.4%
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.f6475.6
Applied rewrites75.6%
Applied rewrites75.6%
Applied rewrites75.6%
(FPCore (re im)
:precision binary64
(if (<= re -7e+146)
(* (sqrt (* -4.0 re)) 0.5)
(if (<= re -9e-125)
(* 0.5 (sqrt (* 2.0 (- (sqrt (fma im im (* re re))) re))))
(if (<= re 2.1e-35)
(* (sqrt (+ (fma -2.0 re im) im)) 0.5)
(* (* (sqrt 2.0) (/ (* (sqrt 0.5) im) (sqrt re))) 0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -7e+146) {
tmp = sqrt((-4.0 * re)) * 0.5;
} else if (re <= -9e-125) {
tmp = 0.5 * sqrt((2.0 * (sqrt(fma(im, im, (re * re))) - re)));
} else if (re <= 2.1e-35) {
tmp = sqrt((fma(-2.0, re, im) + im)) * 0.5;
} else {
tmp = (sqrt(2.0) * ((sqrt(0.5) * im) / sqrt(re))) * 0.5;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= -7e+146) tmp = Float64(sqrt(Float64(-4.0 * re)) * 0.5); elseif (re <= -9e-125) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(im, im, Float64(re * re))) - re)))); elseif (re <= 2.1e-35) tmp = Float64(sqrt(Float64(fma(-2.0, re, im) + im)) * 0.5); else tmp = Float64(Float64(sqrt(2.0) * Float64(Float64(sqrt(0.5) * im) / sqrt(re))) * 0.5); end return tmp end
code[re_, im_] := If[LessEqual[re, -7e+146], N[(N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[re, -9e-125], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(im * im + N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.1e-35], N[(N[Sqrt[N[(N[(-2.0 * re + im), $MachinePrecision] + im), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[Sqrt[2.0], $MachinePrecision] * N[(N[(N[Sqrt[0.5], $MachinePrecision] * im), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -7 \cdot 10^{+146}:\\
\;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\
\mathbf{elif}\;re \leq -9 \cdot 10^{-125}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)} - re\right)}\\
\mathbf{elif}\;re \leq 2.1 \cdot 10^{-35}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(-2, re, im\right) + im} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(\sqrt{2} \cdot \frac{\sqrt{0.5} \cdot im}{\sqrt{re}}\right) \cdot 0.5\\
\end{array}
\end{array}
if re < -7.0000000000000002e146Initial program 4.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f644.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f644.2
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f64100.0
Applied rewrites100.0%
Taylor expanded in re around -inf
lower-*.f6484.4
Applied rewrites84.4%
if -7.0000000000000002e146 < re < -9.00000000000000024e-125Initial program 79.6%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6479.6
Applied rewrites79.6%
if -9.00000000000000024e-125 < re < 2.1e-35Initial program 50.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6450.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6450.4
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6490.7
Applied rewrites90.7%
Taylor expanded in re around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6483.8
Applied rewrites83.8%
Applied rewrites83.8%
Taylor expanded in re around 0
Applied rewrites84.1%
if 2.1e-35 < re Initial program 10.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6410.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6410.5
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6438.4
Applied rewrites38.4%
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.f6475.6
Applied rewrites75.6%
Applied rewrites75.6%
Applied rewrites75.6%
(FPCore (re im)
:precision binary64
(if (<= re -7e+146)
(* (sqrt (* -4.0 re)) 0.5)
(if (<= re -6.5e-89)
(* 0.5 (sqrt (* 2.0 (- (sqrt (fma im im (* re re))) re))))
(if (<= re 3.9e+135)
(* (sqrt (+ (fma (- (/ re im) 2.0) re im) im)) 0.5)
(* (* 0.5 (sqrt 2.0)) (sqrt (* (* (/ im re) im) 0.5)))))))
double code(double re, double im) {
double tmp;
if (re <= -7e+146) {
tmp = sqrt((-4.0 * re)) * 0.5;
} else if (re <= -6.5e-89) {
tmp = 0.5 * sqrt((2.0 * (sqrt(fma(im, im, (re * re))) - re)));
} else if (re <= 3.9e+135) {
tmp = sqrt((fma(((re / im) - 2.0), re, im) + im)) * 0.5;
} else {
tmp = (0.5 * sqrt(2.0)) * sqrt((((im / re) * im) * 0.5));
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= -7e+146) tmp = Float64(sqrt(Float64(-4.0 * re)) * 0.5); elseif (re <= -6.5e-89) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(im, im, Float64(re * re))) - re)))); elseif (re <= 3.9e+135) tmp = Float64(sqrt(Float64(fma(Float64(Float64(re / im) - 2.0), re, im) + im)) * 0.5); else tmp = Float64(Float64(0.5 * sqrt(2.0)) * sqrt(Float64(Float64(Float64(im / re) * im) * 0.5))); end return tmp end
code[re_, im_] := If[LessEqual[re, -7e+146], N[(N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[re, -6.5e-89], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(im * im + N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 3.9e+135], N[(N[Sqrt[N[(N[(N[(N[(re / im), $MachinePrecision] - 2.0), $MachinePrecision] * re + im), $MachinePrecision] + im), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(0.5 * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(N[(N[(im / re), $MachinePrecision] * im), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -7 \cdot 10^{+146}:\\
\;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\
\mathbf{elif}\;re \leq -6.5 \cdot 10^{-89}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)} - re\right)}\\
\mathbf{elif}\;re \leq 3.9 \cdot 10^{+135}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, im\right) + im} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \sqrt{2}\right) \cdot \sqrt{\left(\frac{im}{re} \cdot im\right) \cdot 0.5}\\
\end{array}
\end{array}
if re < -7.0000000000000002e146Initial program 4.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f644.2
lift-*.f64N/A
*-commutativeN/A
lower-*.f644.2
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f64100.0
Applied rewrites100.0%
Taylor expanded in re around -inf
lower-*.f6484.4
Applied rewrites84.4%
if -7.0000000000000002e146 < re < -6.50000000000000034e-89Initial program 78.1%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6478.1
Applied rewrites78.1%
if -6.50000000000000034e-89 < re < 3.90000000000000032e135Initial program 46.1%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6446.1
lift-*.f64N/A
*-commutativeN/A
lower-*.f6446.1
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6481.9
Applied rewrites81.9%
Taylor expanded in re around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6475.4
Applied rewrites75.4%
Applied rewrites75.4%
if 3.90000000000000032e135 < re Initial program 5.3%
Taylor expanded in re around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6415.2
Applied rewrites15.2%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
sqrt-prodN/A
lift-sqrt.f64N/A
pow1/2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f6415.1
Applied rewrites15.1%
Taylor expanded in re around inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6458.9
Applied rewrites58.9%
Applied rewrites78.0%
(FPCore (re im)
:precision binary64
(if (<= re -0.00024)
(* (sqrt (* -4.0 re)) 0.5)
(if (<= re 3.9e+135)
(* (sqrt (+ (fma (- (/ re im) 2.0) re im) im)) 0.5)
(* (sqrt (/ (* im im) re)) 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -0.00024) {
tmp = sqrt((-4.0 * re)) * 0.5;
} else if (re <= 3.9e+135) {
tmp = sqrt((fma(((re / im) - 2.0), re, im) + im)) * 0.5;
} else {
tmp = sqrt(((im * im) / re)) * 0.5;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= -0.00024) tmp = Float64(sqrt(Float64(-4.0 * re)) * 0.5); elseif (re <= 3.9e+135) tmp = Float64(sqrt(Float64(fma(Float64(Float64(re / im) - 2.0), re, im) + im)) * 0.5); else tmp = Float64(sqrt(Float64(Float64(im * im) / re)) * 0.5); end return tmp end
code[re_, im_] := If[LessEqual[re, -0.00024], N[(N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[re, 3.9e+135], N[(N[Sqrt[N[(N[(N[(N[(re / im), $MachinePrecision] - 2.0), $MachinePrecision] * re + im), $MachinePrecision] + im), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[Sqrt[N[(N[(im * im), $MachinePrecision] / re), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.00024:\\
\;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\
\mathbf{elif}\;re \leq 3.9 \cdot 10^{+135}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(\frac{re}{im} - 2, re, im\right) + im} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{im \cdot im}{re}} \cdot 0.5\\
\end{array}
\end{array}
if re < -2.40000000000000006e-4Initial program 50.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6450.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6450.4
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f64100.0
Applied rewrites100.0%
Taylor expanded in re around -inf
lower-*.f6477.7
Applied rewrites77.7%
if -2.40000000000000006e-4 < re < 3.90000000000000032e135Initial program 50.1%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6450.1
lift-*.f64N/A
*-commutativeN/A
lower-*.f6450.1
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6484.7
Applied rewrites84.7%
Taylor expanded in re around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6473.8
Applied rewrites73.8%
Applied rewrites73.8%
if 3.90000000000000032e135 < re Initial program 5.3%
lift-*.f64N/A
*-commutativeN/A
lower-*.f645.3
lift-*.f64N/A
*-commutativeN/A
lower-*.f645.3
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6431.9
Applied rewrites31.9%
Taylor expanded in re around inf
lower-/.f64N/A
unpow2N/A
lower-*.f6459.2
Applied rewrites59.2%
(FPCore (re im)
:precision binary64
(if (<= re -0.00029)
(* (sqrt (* -4.0 re)) 0.5)
(if (<= re 1.5e-30)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* (sqrt (/ (* im im) re)) 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -0.00029) {
tmp = sqrt((-4.0 * re)) * 0.5;
} else if (re <= 1.5e-30) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = sqrt(((im * im) / 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 <= (-0.00029d0)) then
tmp = sqrt(((-4.0d0) * re)) * 0.5d0
else if (re <= 1.5d-30) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else
tmp = sqrt(((im * im) / re)) * 0.5d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -0.00029) {
tmp = Math.sqrt((-4.0 * re)) * 0.5;
} else if (re <= 1.5e-30) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = Math.sqrt(((im * im) / re)) * 0.5;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.00029: tmp = math.sqrt((-4.0 * re)) * 0.5 elif re <= 1.5e-30: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = math.sqrt(((im * im) / re)) * 0.5 return tmp
function code(re, im) tmp = 0.0 if (re <= -0.00029) tmp = Float64(sqrt(Float64(-4.0 * re)) * 0.5); elseif (re <= 1.5e-30) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(sqrt(Float64(Float64(im * im) / re)) * 0.5); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -0.00029) tmp = sqrt((-4.0 * re)) * 0.5; elseif (re <= 1.5e-30) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = sqrt(((im * im) / re)) * 0.5; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.00029], N[(N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[re, 1.5e-30], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(N[(im * im), $MachinePrecision] / re), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.00029:\\
\;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\
\mathbf{elif}\;re \leq 1.5 \cdot 10^{-30}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{im \cdot im}{re}} \cdot 0.5\\
\end{array}
\end{array}
if re < -2.9e-4Initial program 50.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6450.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6450.4
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f64100.0
Applied rewrites100.0%
Taylor expanded in re around -inf
lower-*.f6477.7
Applied rewrites77.7%
if -2.9e-4 < re < 1.49999999999999995e-30Initial program 57.4%
Taylor expanded in re around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6481.1
Applied rewrites81.1%
if 1.49999999999999995e-30 < re Initial program 10.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6410.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6410.5
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6438.4
Applied rewrites38.4%
Taylor expanded in re around inf
lower-/.f64N/A
unpow2N/A
lower-*.f6452.7
Applied rewrites52.7%
(FPCore (re im) :precision binary64 (if (<= re -0.00024) (* (sqrt (* -4.0 re)) 0.5) (* (sqrt (+ im im)) 0.5)))
double code(double re, double im) {
double tmp;
if (re <= -0.00024) {
tmp = sqrt((-4.0 * re)) * 0.5;
} 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 (re <= (-0.00024d0)) then
tmp = sqrt(((-4.0d0) * re)) * 0.5d0
else
tmp = sqrt((im + im)) * 0.5d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -0.00024) {
tmp = Math.sqrt((-4.0 * re)) * 0.5;
} else {
tmp = Math.sqrt((im + im)) * 0.5;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.00024: tmp = math.sqrt((-4.0 * re)) * 0.5 else: tmp = math.sqrt((im + im)) * 0.5 return tmp
function code(re, im) tmp = 0.0 if (re <= -0.00024) tmp = Float64(sqrt(Float64(-4.0 * re)) * 0.5); else tmp = Float64(sqrt(Float64(im + im)) * 0.5); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -0.00024) tmp = sqrt((-4.0 * re)) * 0.5; else tmp = sqrt((im + im)) * 0.5; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.00024], N[(N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[Sqrt[N[(im + im), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.00024:\\
\;\;\;\;\sqrt{-4 \cdot re} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\sqrt{im + im} \cdot 0.5\\
\end{array}
\end{array}
if re < -2.40000000000000006e-4Initial program 50.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6450.4
lift-*.f64N/A
*-commutativeN/A
lower-*.f6450.4
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f64100.0
Applied rewrites100.0%
Taylor expanded in re around -inf
lower-*.f6477.7
Applied rewrites77.7%
if -2.40000000000000006e-4 < re Initial program 39.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6439.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6439.8
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6472.6
Applied rewrites72.6%
Taylor expanded in re around 0
lower-*.f6460.5
Applied rewrites60.5%
Applied rewrites60.5%
(FPCore (re im) :precision binary64 (* (sqrt (+ im im)) 0.5))
double code(double re, double im) {
return sqrt((im + im)) * 0.5;
}
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 = sqrt((im + im)) * 0.5d0
end function
public static double code(double re, double im) {
return Math.sqrt((im + im)) * 0.5;
}
def code(re, im): return math.sqrt((im + im)) * 0.5
function code(re, im) return Float64(sqrt(Float64(im + im)) * 0.5) end
function tmp = code(re, im) tmp = sqrt((im + im)) * 0.5; end
code[re_, im_] := N[(N[Sqrt[N[(im + im), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{im + im} \cdot 0.5
\end{array}
Initial program 42.1%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6442.1
lift-*.f64N/A
*-commutativeN/A
lower-*.f6442.1
lift-sqrt.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
lower-hypot.f6478.6
Applied rewrites78.6%
Taylor expanded in re around 0
lower-*.f6452.9
Applied rewrites52.9%
Applied rewrites52.9%
herbie shell --seed 2024360
(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)))))