
(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]
0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}
Herbie found 9 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]
0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}
(FPCore (re im) :precision binary64 (if (<= (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))) 0.0) (* (sqrt (* -1.0 (/ (pow im 2.0) re))) 0.5) (* 0.5 (sqrt (* 2.0 (+ (hypot re im) re))))))
double code(double re, double im) {
double tmp;
if ((0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re)))) <= 0.0) {
tmp = sqrt((-1.0 * (pow(im, 2.0) / re))) * 0.5;
} else {
tmp = 0.5 * sqrt((2.0 * (hypot(re, im) + re)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if ((0.5 * Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) + re)))) <= 0.0) {
tmp = Math.sqrt((-1.0 * (Math.pow(im, 2.0) / re))) * 0.5;
} else {
tmp = 0.5 * Math.sqrt((2.0 * (Math.hypot(re, im) + re)));
}
return tmp;
}
def code(re, im): tmp = 0 if (0.5 * math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) + re)))) <= 0.0: tmp = math.sqrt((-1.0 * (math.pow(im, 2.0) / re))) * 0.5 else: tmp = 0.5 * math.sqrt((2.0 * (math.hypot(re, im) + re))) return tmp
function code(re, im) tmp = 0.0 if (Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) + re)))) <= 0.0) tmp = Float64(sqrt(Float64(-1.0 * Float64((im ^ 2.0) / re))) * 0.5); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(hypot(re, im) + re)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re)))) <= 0.0) tmp = sqrt((-1.0 * ((im ^ 2.0) / re))) * 0.5; else tmp = 0.5 * sqrt((2.0 * (hypot(re, im) + re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[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], 0.0], N[(N[Sqrt[N[(-1.0 * N[(N[Power[im, 2.0], $MachinePrecision] / re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)} \leq 0:\\
\;\;\;\;\sqrt{-1 \cdot \frac{{im}^{2}}{re}} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) + re\right)}\\
\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)))) < 0.0Initial program 41.3%
Taylor expanded in im around inf
lower-*.f64N/A
lower-+.f64N/A
lower-/.f6429.0%
Applied rewrites29.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6429.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6429.0%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
lift-/.f64N/A
sum-to-mult-revN/A
lower-+.f6430.0%
Applied rewrites30.0%
Taylor expanded in re around -inf
lower-*.f64N/A
lower-/.f64N/A
lower-pow.f6415.0%
Applied rewrites15.0%
if 0.0 < (*.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 41.3%
lift-sqrt.f64N/A
sqrt-fabs-revN/A
lift-sqrt.f64N/A
rem-sqrt-square-revN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
rem-square-sqrtN/A
lift-+.f64N/A
add-flipN/A
sub-flipN/A
lift-*.f64N/A
sqr-abs-revN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-outN/A
fp-cancel-sign-sub-invN/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
remove-double-negN/A
sqr-neg-revN/A
sqr-abs-revN/A
Applied rewrites79.5%
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 (+ (hypot re im) re)))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * (hypot(re, im) + re)));
}
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * (Math.hypot(re, im) + re)));
}
def code(re, im): return 0.5 * math.sqrt((2.0 * (math.hypot(re, im) + re)))
function code(re, im) return Float64(0.5 * sqrt(Float64(2.0 * Float64(hypot(re, im) + re)))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((2.0 * (hypot(re, im) + re))); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) + re\right)}
Initial program 41.3%
lift-sqrt.f64N/A
sqrt-fabs-revN/A
lift-sqrt.f64N/A
rem-sqrt-square-revN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
rem-square-sqrtN/A
lift-+.f64N/A
add-flipN/A
sub-flipN/A
lift-*.f64N/A
sqr-abs-revN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-outN/A
fp-cancel-sign-sub-invN/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
remove-double-negN/A
sqr-neg-revN/A
sqr-abs-revN/A
Applied rewrites79.5%
(FPCore (re im)
:precision binary64
(if (<=
(*
0.5
(sqrt (* 2.0 (+ (sqrt (+ (* re re) (* (fabs im) (fabs im)))) re))))
2e+77)
(* (sqrt (* (+ (sqrt (fma (fabs im) (fabs im) (* re re))) re) 2.0)) 0.5)
(* (sqrt (* (+ (fabs im) re) 2.0)) 0.5)))double code(double re, double im) {
double tmp;
if ((0.5 * sqrt((2.0 * (sqrt(((re * re) + (fabs(im) * fabs(im)))) + re)))) <= 2e+77) {
tmp = sqrt(((sqrt(fma(fabs(im), fabs(im), (re * re))) + re) * 2.0)) * 0.5;
} else {
tmp = sqrt(((fabs(im) + re) * 2.0)) * 0.5;
}
return tmp;
}
function code(re, im) tmp = 0.0 if (Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(abs(im) * abs(im)))) + re)))) <= 2e+77) tmp = Float64(sqrt(Float64(Float64(sqrt(fma(abs(im), abs(im), Float64(re * re))) + re) * 2.0)) * 0.5); else tmp = Float64(sqrt(Float64(Float64(abs(im) + re) * 2.0)) * 0.5); end return tmp end
code[re_, im_] := If[LessEqual[N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(N[Abs[im], $MachinePrecision] * N[Abs[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2e+77], N[(N[Sqrt[N[(N[(N[Sqrt[N[(N[Abs[im], $MachinePrecision] * N[Abs[im], $MachinePrecision] + N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + re), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(N[Sqrt[N[(N[(N[Abs[im], $MachinePrecision] + re), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + \left|im\right| \cdot \left|im\right|} + re\right)} \leq 2 \cdot 10^{+77}:\\
\;\;\;\;\sqrt{\left(\sqrt{\mathsf{fma}\left(\left|im\right|, \left|im\right|, re \cdot re\right)} + re\right) \cdot 2} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(\left|im\right| + re\right) \cdot 2} \cdot 0.5\\
\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)))) < 1.99999999999999997e77Initial program 41.3%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6441.3%
Applied rewrites41.3%
if 1.99999999999999997e77 < (*.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 41.3%
Taylor expanded in im around inf
lower-*.f64N/A
lower-+.f64N/A
lower-/.f6429.0%
Applied rewrites29.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6429.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6429.0%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
lift-/.f64N/A
sum-to-mult-revN/A
lower-+.f6430.0%
Applied rewrites30.0%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* -2.0 (fabs im))))
(if (<= re -1.3e+75)
(* 0.5 (sqrt (sqrt (* t_0 t_0))))
(if (<= re 8e+32)
(* 0.5 (sqrt (* 2.0 (* (fabs im) (+ 1.0 (/ re (fabs im)))))))
(* 0.5 (* re (sqrt (/ 4.0 re))))))))double code(double re, double im) {
double t_0 = -2.0 * fabs(im);
double tmp;
if (re <= -1.3e+75) {
tmp = 0.5 * sqrt(sqrt((t_0 * t_0)));
} else if (re <= 8e+32) {
tmp = 0.5 * sqrt((2.0 * (fabs(im) * (1.0 + (re / fabs(im))))));
} else {
tmp = 0.5 * (re * sqrt((4.0 / re)));
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: tmp
t_0 = (-2.0d0) * abs(im)
if (re <= (-1.3d+75)) then
tmp = 0.5d0 * sqrt(sqrt((t_0 * t_0)))
else if (re <= 8d+32) then
tmp = 0.5d0 * sqrt((2.0d0 * (abs(im) * (1.0d0 + (re / abs(im))))))
else
tmp = 0.5d0 * (re * sqrt((4.0d0 / re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = -2.0 * Math.abs(im);
double tmp;
if (re <= -1.3e+75) {
tmp = 0.5 * Math.sqrt(Math.sqrt((t_0 * t_0)));
} else if (re <= 8e+32) {
tmp = 0.5 * Math.sqrt((2.0 * (Math.abs(im) * (1.0 + (re / Math.abs(im))))));
} else {
tmp = 0.5 * (re * Math.sqrt((4.0 / re)));
}
return tmp;
}
def code(re, im): t_0 = -2.0 * math.fabs(im) tmp = 0 if re <= -1.3e+75: tmp = 0.5 * math.sqrt(math.sqrt((t_0 * t_0))) elif re <= 8e+32: tmp = 0.5 * math.sqrt((2.0 * (math.fabs(im) * (1.0 + (re / math.fabs(im)))))) else: tmp = 0.5 * (re * math.sqrt((4.0 / re))) return tmp
function code(re, im) t_0 = Float64(-2.0 * abs(im)) tmp = 0.0 if (re <= -1.3e+75) tmp = Float64(0.5 * sqrt(sqrt(Float64(t_0 * t_0)))); elseif (re <= 8e+32) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(abs(im) * Float64(1.0 + Float64(re / abs(im))))))); else tmp = Float64(0.5 * Float64(re * sqrt(Float64(4.0 / re)))); end return tmp end
function tmp_2 = code(re, im) t_0 = -2.0 * abs(im); tmp = 0.0; if (re <= -1.3e+75) tmp = 0.5 * sqrt(sqrt((t_0 * t_0))); elseif (re <= 8e+32) tmp = 0.5 * sqrt((2.0 * (abs(im) * (1.0 + (re / abs(im)))))); else tmp = 0.5 * (re * sqrt((4.0 / re))); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(-2.0 * N[Abs[im], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -1.3e+75], N[(0.5 * N[Sqrt[N[Sqrt[N[(t$95$0 * t$95$0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 8e+32], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Abs[im], $MachinePrecision] * N[(1.0 + N[(re / N[Abs[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(re * N[Sqrt[N[(4.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
t_0 := -2 \cdot \left|im\right|\\
\mathbf{if}\;re \leq -1.3 \cdot 10^{+75}:\\
\;\;\;\;0.5 \cdot \sqrt{\sqrt{t\_0 \cdot t\_0}}\\
\mathbf{elif}\;re \leq 8 \cdot 10^{+32}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\left|im\right| \cdot \left(1 + \frac{re}{\left|im\right|}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(re \cdot \sqrt{\frac{4}{re}}\right)\\
\end{array}
if re < -1.29999999999999992e75Initial program 41.3%
Taylor expanded in im around -inf
lower-*.f6426.8%
Applied rewrites26.8%
rem-square-sqrtN/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f6431.4%
Applied rewrites31.4%
if -1.29999999999999992e75 < re < 8.00000000000000043e32Initial program 41.3%
Taylor expanded in im around inf
lower-*.f64N/A
lower-+.f64N/A
lower-/.f6429.0%
Applied rewrites29.0%
if 8.00000000000000043e32 < re Initial program 41.3%
Taylor expanded in re around inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f6425.5%
Applied rewrites25.5%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* -2.0 (fabs im))))
(if (<= re -1.3e+75)
(* 0.5 (sqrt (sqrt (* t_0 t_0))))
(if (<= re 8e+32)
(* (sqrt (* (+ (fabs im) re) 2.0)) 0.5)
(* 0.5 (* re (sqrt (/ 4.0 re))))))))double code(double re, double im) {
double t_0 = -2.0 * fabs(im);
double tmp;
if (re <= -1.3e+75) {
tmp = 0.5 * sqrt(sqrt((t_0 * t_0)));
} else if (re <= 8e+32) {
tmp = sqrt(((fabs(im) + re) * 2.0)) * 0.5;
} else {
tmp = 0.5 * (re * sqrt((4.0 / re)));
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: tmp
t_0 = (-2.0d0) * abs(im)
if (re <= (-1.3d+75)) then
tmp = 0.5d0 * sqrt(sqrt((t_0 * t_0)))
else if (re <= 8d+32) then
tmp = sqrt(((abs(im) + re) * 2.0d0)) * 0.5d0
else
tmp = 0.5d0 * (re * sqrt((4.0d0 / re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = -2.0 * Math.abs(im);
double tmp;
if (re <= -1.3e+75) {
tmp = 0.5 * Math.sqrt(Math.sqrt((t_0 * t_0)));
} else if (re <= 8e+32) {
tmp = Math.sqrt(((Math.abs(im) + re) * 2.0)) * 0.5;
} else {
tmp = 0.5 * (re * Math.sqrt((4.0 / re)));
}
return tmp;
}
def code(re, im): t_0 = -2.0 * math.fabs(im) tmp = 0 if re <= -1.3e+75: tmp = 0.5 * math.sqrt(math.sqrt((t_0 * t_0))) elif re <= 8e+32: tmp = math.sqrt(((math.fabs(im) + re) * 2.0)) * 0.5 else: tmp = 0.5 * (re * math.sqrt((4.0 / re))) return tmp
function code(re, im) t_0 = Float64(-2.0 * abs(im)) tmp = 0.0 if (re <= -1.3e+75) tmp = Float64(0.5 * sqrt(sqrt(Float64(t_0 * t_0)))); elseif (re <= 8e+32) tmp = Float64(sqrt(Float64(Float64(abs(im) + re) * 2.0)) * 0.5); else tmp = Float64(0.5 * Float64(re * sqrt(Float64(4.0 / re)))); end return tmp end
function tmp_2 = code(re, im) t_0 = -2.0 * abs(im); tmp = 0.0; if (re <= -1.3e+75) tmp = 0.5 * sqrt(sqrt((t_0 * t_0))); elseif (re <= 8e+32) tmp = sqrt(((abs(im) + re) * 2.0)) * 0.5; else tmp = 0.5 * (re * sqrt((4.0 / re))); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(-2.0 * N[Abs[im], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[re, -1.3e+75], N[(0.5 * N[Sqrt[N[Sqrt[N[(t$95$0 * t$95$0), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 8e+32], N[(N[Sqrt[N[(N[(N[Abs[im], $MachinePrecision] + re), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(0.5 * N[(re * N[Sqrt[N[(4.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
t_0 := -2 \cdot \left|im\right|\\
\mathbf{if}\;re \leq -1.3 \cdot 10^{+75}:\\
\;\;\;\;0.5 \cdot \sqrt{\sqrt{t\_0 \cdot t\_0}}\\
\mathbf{elif}\;re \leq 8 \cdot 10^{+32}:\\
\;\;\;\;\sqrt{\left(\left|im\right| + re\right) \cdot 2} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(re \cdot \sqrt{\frac{4}{re}}\right)\\
\end{array}
if re < -1.29999999999999992e75Initial program 41.3%
Taylor expanded in im around -inf
lower-*.f6426.8%
Applied rewrites26.8%
rem-square-sqrtN/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f6431.4%
Applied rewrites31.4%
if -1.29999999999999992e75 < re < 8.00000000000000043e32Initial program 41.3%
Taylor expanded in im around inf
lower-*.f64N/A
lower-+.f64N/A
lower-/.f6429.0%
Applied rewrites29.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6429.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6429.0%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
lift-/.f64N/A
sum-to-mult-revN/A
lower-+.f6430.0%
Applied rewrites30.0%
if 8.00000000000000043e32 < re Initial program 41.3%
Taylor expanded in re around inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f6425.5%
Applied rewrites25.5%
(FPCore (re im)
:precision binary64
(if (<= re -1.6e+79)
(* (sqrt (* (+ (- re) re) 2.0)) 0.5)
(if (<= re 8e+32)
(* (sqrt (* (+ (fabs im) re) 2.0)) 0.5)
(* 0.5 (* re (sqrt (/ 4.0 re)))))))double code(double re, double im) {
double tmp;
if (re <= -1.6e+79) {
tmp = sqrt(((-re + re) * 2.0)) * 0.5;
} else if (re <= 8e+32) {
tmp = sqrt(((fabs(im) + re) * 2.0)) * 0.5;
} else {
tmp = 0.5 * (re * sqrt((4.0 / re)));
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-1.6d+79)) then
tmp = sqrt(((-re + re) * 2.0d0)) * 0.5d0
else if (re <= 8d+32) then
tmp = sqrt(((abs(im) + re) * 2.0d0)) * 0.5d0
else
tmp = 0.5d0 * (re * sqrt((4.0d0 / re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.6e+79) {
tmp = Math.sqrt(((-re + re) * 2.0)) * 0.5;
} else if (re <= 8e+32) {
tmp = Math.sqrt(((Math.abs(im) + re) * 2.0)) * 0.5;
} else {
tmp = 0.5 * (re * Math.sqrt((4.0 / re)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.6e+79: tmp = math.sqrt(((-re + re) * 2.0)) * 0.5 elif re <= 8e+32: tmp = math.sqrt(((math.fabs(im) + re) * 2.0)) * 0.5 else: tmp = 0.5 * (re * math.sqrt((4.0 / re))) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.6e+79) tmp = Float64(sqrt(Float64(Float64(Float64(-re) + re) * 2.0)) * 0.5); elseif (re <= 8e+32) tmp = Float64(sqrt(Float64(Float64(abs(im) + re) * 2.0)) * 0.5); else tmp = Float64(0.5 * Float64(re * sqrt(Float64(4.0 / re)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.6e+79) tmp = sqrt(((-re + re) * 2.0)) * 0.5; elseif (re <= 8e+32) tmp = sqrt(((abs(im) + re) * 2.0)) * 0.5; else tmp = 0.5 * (re * sqrt((4.0 / re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.6e+79], N[(N[Sqrt[N[(N[((-re) + re), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[re, 8e+32], N[(N[Sqrt[N[(N[(N[Abs[im], $MachinePrecision] + re), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(0.5 * N[(re * N[Sqrt[N[(4.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;re \leq -1.6 \cdot 10^{+79}:\\
\;\;\;\;\sqrt{\left(\left(-re\right) + re\right) \cdot 2} \cdot 0.5\\
\mathbf{elif}\;re \leq 8 \cdot 10^{+32}:\\
\;\;\;\;\sqrt{\left(\left|im\right| + re\right) \cdot 2} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(re \cdot \sqrt{\frac{4}{re}}\right)\\
\end{array}
if re < -1.60000000000000001e79Initial program 41.3%
Taylor expanded in re around -inf
lower-*.f646.1%
Applied rewrites6.1%
lift-*.f64N/A
*-commutativeN/A
lower-*.f646.1%
lift-*.f64N/A
*-commutativeN/A
lower-*.f646.1%
lift-*.f64N/A
mul-1-negN/A
lower-neg.f646.1%
Applied rewrites6.1%
if -1.60000000000000001e79 < re < 8.00000000000000043e32Initial program 41.3%
Taylor expanded in im around inf
lower-*.f64N/A
lower-+.f64N/A
lower-/.f6429.0%
Applied rewrites29.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6429.0%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6429.0%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
lift-/.f64N/A
sum-to-mult-revN/A
lower-+.f6430.0%
Applied rewrites30.0%
if 8.00000000000000043e32 < re Initial program 41.3%
Taylor expanded in re around inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f6425.5%
Applied rewrites25.5%
(FPCore (re im) :precision binary64 (if (<= re 8e+32) (* (sqrt (+ (fabs im) (fabs im))) 0.5) (* 0.5 (* re (sqrt (/ 4.0 re))))))
double code(double re, double im) {
double tmp;
if (re <= 8e+32) {
tmp = sqrt((fabs(im) + fabs(im))) * 0.5;
} else {
tmp = 0.5 * (re * sqrt((4.0 / re)));
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= 8d+32) then
tmp = sqrt((abs(im) + abs(im))) * 0.5d0
else
tmp = 0.5d0 * (re * sqrt((4.0d0 / re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 8e+32) {
tmp = Math.sqrt((Math.abs(im) + Math.abs(im))) * 0.5;
} else {
tmp = 0.5 * (re * Math.sqrt((4.0 / re)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 8e+32: tmp = math.sqrt((math.fabs(im) + math.fabs(im))) * 0.5 else: tmp = 0.5 * (re * math.sqrt((4.0 / re))) return tmp
function code(re, im) tmp = 0.0 if (re <= 8e+32) tmp = Float64(sqrt(Float64(abs(im) + abs(im))) * 0.5); else tmp = Float64(0.5 * Float64(re * sqrt(Float64(4.0 / re)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 8e+32) tmp = sqrt((abs(im) + abs(im))) * 0.5; else tmp = 0.5 * (re * sqrt((4.0 / re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 8e+32], N[(N[Sqrt[N[(N[Abs[im], $MachinePrecision] + N[Abs[im], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(0.5 * N[(re * N[Sqrt[N[(4.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;re \leq 8 \cdot 10^{+32}:\\
\;\;\;\;\sqrt{\left|im\right| + \left|im\right|} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(re \cdot \sqrt{\frac{4}{re}}\right)\\
\end{array}
if re < 8.00000000000000043e32Initial program 41.3%
Taylor expanded in im around inf
lower-*.f6426.3%
Applied rewrites26.3%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6426.3%
lift-*.f64N/A
count-2-revN/A
lower-+.f6426.3%
Applied rewrites26.3%
if 8.00000000000000043e32 < re Initial program 41.3%
Taylor expanded in re around inf
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f6425.5%
Applied rewrites25.5%
(FPCore (re im) :precision binary64 (if (<= re 8e+32) (* (sqrt (+ (fabs im) (fabs im))) 0.5) (* 0.5 (sqrt (* 4.0 re)))))
double code(double re, double im) {
double tmp;
if (re <= 8e+32) {
tmp = sqrt((fabs(im) + fabs(im))) * 0.5;
} else {
tmp = 0.5 * sqrt((4.0 * re));
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= 8d+32) then
tmp = sqrt((abs(im) + abs(im))) * 0.5d0
else
tmp = 0.5d0 * sqrt((4.0d0 * re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 8e+32) {
tmp = Math.sqrt((Math.abs(im) + Math.abs(im))) * 0.5;
} else {
tmp = 0.5 * Math.sqrt((4.0 * re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 8e+32: tmp = math.sqrt((math.fabs(im) + math.fabs(im))) * 0.5 else: tmp = 0.5 * math.sqrt((4.0 * re)) return tmp
function code(re, im) tmp = 0.0 if (re <= 8e+32) tmp = Float64(sqrt(Float64(abs(im) + abs(im))) * 0.5); else tmp = Float64(0.5 * sqrt(Float64(4.0 * re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 8e+32) tmp = sqrt((abs(im) + abs(im))) * 0.5; else tmp = 0.5 * sqrt((4.0 * re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 8e+32], N[(N[Sqrt[N[(N[Abs[im], $MachinePrecision] + N[Abs[im], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(0.5 * N[Sqrt[N[(4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;re \leq 8 \cdot 10^{+32}:\\
\;\;\;\;\sqrt{\left|im\right| + \left|im\right|} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{4 \cdot re}\\
\end{array}
if re < 8.00000000000000043e32Initial program 41.3%
Taylor expanded in im around inf
lower-*.f6426.3%
Applied rewrites26.3%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6426.3%
lift-*.f64N/A
count-2-revN/A
lower-+.f6426.3%
Applied rewrites26.3%
if 8.00000000000000043e32 < re Initial program 41.3%
Taylor expanded in re around inf
lower-*.f6425.5%
Applied rewrites25.5%
(FPCore (re im) :precision binary64 (* (sqrt (+ (fabs im) (fabs im))) 0.5))
double code(double re, double im) {
return sqrt((fabs(im) + fabs(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((abs(im) + abs(im))) * 0.5d0
end function
public static double code(double re, double im) {
return Math.sqrt((Math.abs(im) + Math.abs(im))) * 0.5;
}
def code(re, im): return math.sqrt((math.fabs(im) + math.fabs(im))) * 0.5
function code(re, im) return Float64(sqrt(Float64(abs(im) + abs(im))) * 0.5) end
function tmp = code(re, im) tmp = sqrt((abs(im) + abs(im))) * 0.5; end
code[re_, im_] := N[(N[Sqrt[N[(N[Abs[im], $MachinePrecision] + N[Abs[im], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]
\sqrt{\left|im\right| + \left|im\right|} \cdot 0.5
Initial program 41.3%
Taylor expanded in im around inf
lower-*.f6426.3%
Applied rewrites26.3%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6426.3%
lift-*.f64N/A
count-2-revN/A
lower-+.f6426.3%
Applied rewrites26.3%
(FPCore (re im)
:precision binary64
(let* ((t_0 (sqrt (+ (* re re) (* im im)))))
(if (< re 0.0)
(* 0.5 (* (sqrt 2.0) (sqrt (/ (* im im) (- t_0 re)))))
(* 0.5 (sqrt (* 2.0 (+ t_0 re)))))))double code(double re, double im) {
double t_0 = sqrt(((re * re) + (im * im)));
double tmp;
if (re < 0.0) {
tmp = 0.5 * (sqrt(2.0) * sqrt(((im * im) / (t_0 - re))));
} else {
tmp = 0.5 * sqrt((2.0 * (t_0 + re)));
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt(((re * re) + (im * im)))
if (re < 0.0d0) then
tmp = 0.5d0 * (sqrt(2.0d0) * sqrt(((im * im) / (t_0 - re))))
else
tmp = 0.5d0 * sqrt((2.0d0 * (t_0 + re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = Math.sqrt(((re * re) + (im * im)));
double tmp;
if (re < 0.0) {
tmp = 0.5 * (Math.sqrt(2.0) * Math.sqrt(((im * im) / (t_0 - re))));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (t_0 + re)));
}
return tmp;
}
def code(re, im): t_0 = math.sqrt(((re * re) + (im * im))) tmp = 0 if re < 0.0: tmp = 0.5 * (math.sqrt(2.0) * math.sqrt(((im * im) / (t_0 - re)))) else: tmp = 0.5 * math.sqrt((2.0 * (t_0 + re))) return tmp
function code(re, im) t_0 = sqrt(Float64(Float64(re * re) + Float64(im * im))) tmp = 0.0 if (re < 0.0) tmp = Float64(0.5 * Float64(sqrt(2.0) * sqrt(Float64(Float64(im * im) / Float64(t_0 - re))))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(t_0 + re)))); end return tmp end
function tmp_2 = code(re, im) t_0 = sqrt(((re * re) + (im * im))); tmp = 0.0; if (re < 0.0) tmp = 0.5 * (sqrt(2.0) * sqrt(((im * im) / (t_0 - re)))); else tmp = 0.5 * sqrt((2.0 * (t_0 + re))); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[re, 0.0], N[(0.5 * N[(N[Sqrt[2.0], $MachinePrecision] * N[Sqrt[N[(N[(im * im), $MachinePrecision] / N[(t$95$0 - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(t$95$0 + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
t_0 := \sqrt{re \cdot re + im \cdot im}\\
\mathbf{if}\;re < 0:\\
\;\;\;\;0.5 \cdot \left(\sqrt{2} \cdot \sqrt{\frac{im \cdot im}{t\_0 - re}}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(t\_0 + re\right)}\\
\end{array}
herbie shell --seed 2025187
(FPCore (re im)
:name "math.sqrt on complex, real part"
:precision binary64
:alt
(! :herbie-platform c (if (< re 0) (* 1/2 (* (sqrt 2) (sqrt (/ (* im im) (- (modulus re im) re))))) (* 1/2 (sqrt (* 2 (+ (modulus re im) re))))))
(* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))