
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re)));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((2.0d0 * (sqrt(((re * re) + (im * im))) + re)))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) + re)));
}
def code(re, im): return 0.5 * math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) + re)))
function code(re, im) return Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) + re)))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) + re))); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}
\end{array}
Herbie found 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]
\begin{array}{l}
\\
0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}
\end{array}
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (<= (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im_m im_m))) re)))) 0.0) (* 0.5 (* im_m (sqrt (* -1.0 (/ 1.0 re))))) (* 0.5 (sqrt (* 2.0 (+ (hypot re im_m) re))))))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if ((0.5 * sqrt((2.0 * (sqrt(((re * re) + (im_m * im_m))) + re)))) <= 0.0) {
tmp = 0.5 * (im_m * sqrt((-1.0 * (1.0 / re))));
} else {
tmp = 0.5 * sqrt((2.0 * (hypot(re, im_m) + re)));
}
return tmp;
}
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if ((0.5 * Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im_m * im_m))) + re)))) <= 0.0) {
tmp = 0.5 * (im_m * Math.sqrt((-1.0 * (1.0 / re))));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (Math.hypot(re, im_m) + re)));
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if (0.5 * math.sqrt((2.0 * (math.sqrt(((re * re) + (im_m * im_m))) + re)))) <= 0.0: tmp = 0.5 * (im_m * math.sqrt((-1.0 * (1.0 / re)))) else: tmp = 0.5 * math.sqrt((2.0 * (math.hypot(re, im_m) + re))) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im_m * im_m))) + re)))) <= 0.0) tmp = Float64(0.5 * Float64(im_m * sqrt(Float64(-1.0 * Float64(1.0 / re))))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(hypot(re, im_m) + re)))); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if ((0.5 * sqrt((2.0 * (sqrt(((re * re) + (im_m * im_m))) + re)))) <= 0.0) tmp = 0.5 * (im_m * sqrt((-1.0 * (1.0 / re)))); else tmp = 0.5 * sqrt((2.0 * (hypot(re, im_m) + re))); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im$95$m * im$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.0], N[(0.5 * N[(im$95$m * N[Sqrt[N[(-1.0 * N[(1.0 / re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[re ^ 2 + im$95$m ^ 2], $MachinePrecision] + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im\_m \cdot im\_m} + re\right)} \leq 0:\\
\;\;\;\;0.5 \cdot \left(im\_m \cdot \sqrt{-1 \cdot \frac{1}{re}}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\_m\right) + 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)))) < 0.0Initial program 9.6%
Taylor expanded in re around -inf
associate-*l*N/A
lower-*.f64N/A
sqrt-unprodN/A
metadata-evalN/A
sqrt-unprodN/A
metadata-evalN/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6499.6
Applied rewrites99.6%
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 46.0%
lift-sqrt.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lower-hypot.f6489.0
Applied rewrites89.0%
im_m = (fabs.f64 im)
(FPCore (re im_m)
:precision binary64
(if (<= re -4.2e-45)
(* 0.5 (* im_m (sqrt (* -1.0 (/ 1.0 re)))))
(if (<= re 8.7e-97)
(* (sqrt (fma (- (/ re im_m) -2.0) re (+ im_m im_m))) 0.5)
(if (<= re 2e+90)
(* (sqrt (* (+ (sqrt (fma im_m im_m (* re re))) re) 2.0)) 0.5)
(* 0.5 (sqrt (fma im_m (/ im_m re) (* 4.0 re))))))))im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (re <= -4.2e-45) {
tmp = 0.5 * (im_m * sqrt((-1.0 * (1.0 / re))));
} else if (re <= 8.7e-97) {
tmp = sqrt(fma(((re / im_m) - -2.0), re, (im_m + im_m))) * 0.5;
} else if (re <= 2e+90) {
tmp = sqrt(((sqrt(fma(im_m, im_m, (re * re))) + re) * 2.0)) * 0.5;
} else {
tmp = 0.5 * sqrt(fma(im_m, (im_m / re), (4.0 * re)));
}
return tmp;
}
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (re <= -4.2e-45) tmp = Float64(0.5 * Float64(im_m * sqrt(Float64(-1.0 * Float64(1.0 / re))))); elseif (re <= 8.7e-97) tmp = Float64(sqrt(fma(Float64(Float64(re / im_m) - -2.0), re, Float64(im_m + im_m))) * 0.5); elseif (re <= 2e+90) tmp = Float64(sqrt(Float64(Float64(sqrt(fma(im_m, im_m, Float64(re * re))) + re) * 2.0)) * 0.5); else tmp = Float64(0.5 * sqrt(fma(im_m, Float64(im_m / re), Float64(4.0 * re)))); end return tmp end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[re, -4.2e-45], N[(0.5 * N[(im$95$m * N[Sqrt[N[(-1.0 * N[(1.0 / re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 8.7e-97], N[(N[Sqrt[N[(N[(N[(re / im$95$m), $MachinePrecision] - -2.0), $MachinePrecision] * re + N[(im$95$m + im$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[re, 2e+90], N[(N[Sqrt[N[(N[(N[Sqrt[N[(im$95$m * im$95$m + N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + re), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(0.5 * N[Sqrt[N[(im$95$m * N[(im$95$m / re), $MachinePrecision] + N[(4.0 * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.2 \cdot 10^{-45}:\\
\;\;\;\;0.5 \cdot \left(im\_m \cdot \sqrt{-1 \cdot \frac{1}{re}}\right)\\
\mathbf{elif}\;re \leq 8.7 \cdot 10^{-97}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(\frac{re}{im\_m} - -2, re, im\_m + im\_m\right)} \cdot 0.5\\
\mathbf{elif}\;re \leq 2 \cdot 10^{+90}:\\
\;\;\;\;\sqrt{\left(\sqrt{\mathsf{fma}\left(im\_m, im\_m, re \cdot re\right)} + re\right) \cdot 2} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(im\_m, \frac{im\_m}{re}, 4 \cdot re\right)}\\
\end{array}
\end{array}
if re < -4.1999999999999999e-45Initial program 14.9%
Taylor expanded in re around -inf
associate-*l*N/A
lower-*.f64N/A
sqrt-unprodN/A
metadata-evalN/A
sqrt-unprodN/A
metadata-evalN/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6473.3
Applied rewrites73.3%
if -4.1999999999999999e-45 < re < 8.6999999999999998e-97Initial program 54.5%
Taylor expanded in re around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
rem-square-sqrtN/A
fp-cancel-sign-sub-invN/A
distribute-lft-neg-inN/A
rem-square-sqrtN/A
metadata-evalN/A
lower--.f64N/A
lower-/.f64N/A
count-2-revN/A
lower-+.f6481.8
Applied rewrites81.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6481.8
Applied rewrites81.8%
if 8.6999999999999998e-97 < re < 1.99999999999999993e90Initial program 75.9%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites75.9%
if 1.99999999999999993e90 < re Initial program 26.8%
Taylor expanded in im around 0
lower-fma.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f6474.8
Applied rewrites74.8%
lift-fma.f64N/A
lift-*.f64N/A
lift-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6484.2
Applied rewrites84.2%
im_m = (fabs.f64 im)
(FPCore (re im_m)
:precision binary64
(if (<= re -4.2e-45)
(* 0.5 (* im_m (sqrt (* -1.0 (/ 1.0 re)))))
(if (<= re 1.18e+60)
(* 0.5 (sqrt (* (fma (/ re im_m) 2.0 2.0) im_m)))
(* 0.5 (sqrt (fma im_m (/ im_m re) (* 4.0 re)))))))im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (re <= -4.2e-45) {
tmp = 0.5 * (im_m * sqrt((-1.0 * (1.0 / re))));
} else if (re <= 1.18e+60) {
tmp = 0.5 * sqrt((fma((re / im_m), 2.0, 2.0) * im_m));
} else {
tmp = 0.5 * sqrt(fma(im_m, (im_m / re), (4.0 * re)));
}
return tmp;
}
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (re <= -4.2e-45) tmp = Float64(0.5 * Float64(im_m * sqrt(Float64(-1.0 * Float64(1.0 / re))))); elseif (re <= 1.18e+60) tmp = Float64(0.5 * sqrt(Float64(fma(Float64(re / im_m), 2.0, 2.0) * im_m))); else tmp = Float64(0.5 * sqrt(fma(im_m, Float64(im_m / re), Float64(4.0 * re)))); end return tmp end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[re, -4.2e-45], N[(0.5 * N[(im$95$m * N[Sqrt[N[(-1.0 * N[(1.0 / re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.18e+60], N[(0.5 * N[Sqrt[N[(N[(N[(re / im$95$m), $MachinePrecision] * 2.0 + 2.0), $MachinePrecision] * im$95$m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(im$95$m * N[(im$95$m / re), $MachinePrecision] + N[(4.0 * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.2 \cdot 10^{-45}:\\
\;\;\;\;0.5 \cdot \left(im\_m \cdot \sqrt{-1 \cdot \frac{1}{re}}\right)\\
\mathbf{elif}\;re \leq 1.18 \cdot 10^{+60}:\\
\;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(\frac{re}{im\_m}, 2, 2\right) \cdot im\_m}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(im\_m, \frac{im\_m}{re}, 4 \cdot re\right)}\\
\end{array}
\end{array}
if re < -4.1999999999999999e-45Initial program 14.9%
Taylor expanded in re around -inf
associate-*l*N/A
lower-*.f64N/A
sqrt-unprodN/A
metadata-evalN/A
sqrt-unprodN/A
metadata-evalN/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6473.3
Applied rewrites73.3%
if -4.1999999999999999e-45 < re < 1.18000000000000008e60Initial program 59.5%
Taylor expanded in im around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6477.1
Applied rewrites77.1%
if 1.18000000000000008e60 < re Initial program 32.9%
Taylor expanded in im around 0
lower-fma.f64N/A
lower-/.f64N/A
pow2N/A
lift-*.f6473.9
Applied rewrites73.9%
lift-fma.f64N/A
lift-*.f64N/A
lift-/.f64N/A
+-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-*.f6482.3
Applied rewrites82.3%
im_m = (fabs.f64 im)
(FPCore (re im_m)
:precision binary64
(if (<= re -4.2e-45)
(* 0.5 (* im_m (sqrt (* -1.0 (/ 1.0 re)))))
(if (<= re 1.18e+60)
(* 0.5 (sqrt (* (fma (/ re im_m) 2.0 2.0) im_m)))
(* 0.5 (sqrt (* 4.0 re))))))im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (re <= -4.2e-45) {
tmp = 0.5 * (im_m * sqrt((-1.0 * (1.0 / re))));
} else if (re <= 1.18e+60) {
tmp = 0.5 * sqrt((fma((re / im_m), 2.0, 2.0) * im_m));
} else {
tmp = 0.5 * sqrt((4.0 * re));
}
return tmp;
}
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (re <= -4.2e-45) tmp = Float64(0.5 * Float64(im_m * sqrt(Float64(-1.0 * Float64(1.0 / re))))); elseif (re <= 1.18e+60) tmp = Float64(0.5 * sqrt(Float64(fma(Float64(re / im_m), 2.0, 2.0) * im_m))); else tmp = Float64(0.5 * sqrt(Float64(4.0 * re))); end return tmp end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[re, -4.2e-45], N[(0.5 * N[(im$95$m * N[Sqrt[N[(-1.0 * N[(1.0 / re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.18e+60], N[(0.5 * N[Sqrt[N[(N[(N[(re / im$95$m), $MachinePrecision] * 2.0 + 2.0), $MachinePrecision] * im$95$m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.2 \cdot 10^{-45}:\\
\;\;\;\;0.5 \cdot \left(im\_m \cdot \sqrt{-1 \cdot \frac{1}{re}}\right)\\
\mathbf{elif}\;re \leq 1.18 \cdot 10^{+60}:\\
\;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(\frac{re}{im\_m}, 2, 2\right) \cdot im\_m}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{4 \cdot re}\\
\end{array}
\end{array}
if re < -4.1999999999999999e-45Initial program 14.9%
Taylor expanded in re around -inf
associate-*l*N/A
lower-*.f64N/A
sqrt-unprodN/A
metadata-evalN/A
sqrt-unprodN/A
metadata-evalN/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6473.3
Applied rewrites73.3%
if -4.1999999999999999e-45 < re < 1.18000000000000008e60Initial program 59.5%
Taylor expanded in im around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6477.1
Applied rewrites77.1%
if 1.18000000000000008e60 < re Initial program 32.9%
Taylor expanded in re around inf
lower-*.f6482.2
Applied rewrites82.2%
im_m = (fabs.f64 im)
(FPCore (re im_m)
:precision binary64
(if (<= re -4.2e-45)
(* 0.5 (* im_m (sqrt (* -1.0 (/ 1.0 re)))))
(if (<= re 1.18e+60)
(* 0.5 (sqrt (* 2.0 (+ im_m re))))
(* 0.5 (sqrt (* 4.0 re))))))im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (re <= -4.2e-45) {
tmp = 0.5 * (im_m * sqrt((-1.0 * (1.0 / re))));
} else if (re <= 1.18e+60) {
tmp = 0.5 * sqrt((2.0 * (im_m + re)));
} else {
tmp = 0.5 * sqrt((4.0 * re));
}
return tmp;
}
im_m = private
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_m)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im_m
real(8) :: tmp
if (re <= (-4.2d-45)) then
tmp = 0.5d0 * (im_m * sqrt(((-1.0d0) * (1.0d0 / re))))
else if (re <= 1.18d+60) then
tmp = 0.5d0 * sqrt((2.0d0 * (im_m + re)))
else
tmp = 0.5d0 * sqrt((4.0d0 * re))
end if
code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if (re <= -4.2e-45) {
tmp = 0.5 * (im_m * Math.sqrt((-1.0 * (1.0 / re))));
} else if (re <= 1.18e+60) {
tmp = 0.5 * Math.sqrt((2.0 * (im_m + re)));
} else {
tmp = 0.5 * Math.sqrt((4.0 * re));
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if re <= -4.2e-45: tmp = 0.5 * (im_m * math.sqrt((-1.0 * (1.0 / re)))) elif re <= 1.18e+60: tmp = 0.5 * math.sqrt((2.0 * (im_m + re))) else: tmp = 0.5 * math.sqrt((4.0 * re)) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (re <= -4.2e-45) tmp = Float64(0.5 * Float64(im_m * sqrt(Float64(-1.0 * Float64(1.0 / re))))); elseif (re <= 1.18e+60) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im_m + re)))); else tmp = Float64(0.5 * sqrt(Float64(4.0 * re))); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if (re <= -4.2e-45) tmp = 0.5 * (im_m * sqrt((-1.0 * (1.0 / re)))); elseif (re <= 1.18e+60) tmp = 0.5 * sqrt((2.0 * (im_m + re))); else tmp = 0.5 * sqrt((4.0 * re)); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[re, -4.2e-45], N[(0.5 * N[(im$95$m * N[Sqrt[N[(-1.0 * N[(1.0 / re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.18e+60], N[(0.5 * N[Sqrt[N[(2.0 * N[(im$95$m + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.2 \cdot 10^{-45}:\\
\;\;\;\;0.5 \cdot \left(im\_m \cdot \sqrt{-1 \cdot \frac{1}{re}}\right)\\
\mathbf{elif}\;re \leq 1.18 \cdot 10^{+60}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im\_m + re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{4 \cdot re}\\
\end{array}
\end{array}
if re < -4.1999999999999999e-45Initial program 14.9%
Taylor expanded in re around -inf
associate-*l*N/A
lower-*.f64N/A
sqrt-unprodN/A
metadata-evalN/A
sqrt-unprodN/A
metadata-evalN/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f64N/A
lower-/.f6473.3
Applied rewrites73.3%
if -4.1999999999999999e-45 < re < 1.18000000000000008e60Initial program 59.5%
Taylor expanded in re around 0
Applied rewrites77.2%
if 1.18000000000000008e60 < re Initial program 32.9%
Taylor expanded in re around inf
lower-*.f6482.2
Applied rewrites82.2%
im_m = (fabs.f64 im)
(FPCore (re im_m)
:precision binary64
(if (<= re -4.2e-42)
(* (sqrt (* (- im_m) (/ im_m re))) 0.5)
(if (<= re 1.18e+60)
(* 0.5 (sqrt (* 2.0 (+ im_m re))))
(* 0.5 (sqrt (* 4.0 re))))))im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (re <= -4.2e-42) {
tmp = sqrt((-im_m * (im_m / re))) * 0.5;
} else if (re <= 1.18e+60) {
tmp = 0.5 * sqrt((2.0 * (im_m + re)));
} else {
tmp = 0.5 * sqrt((4.0 * re));
}
return tmp;
}
im_m = private
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_m)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im_m
real(8) :: tmp
if (re <= (-4.2d-42)) then
tmp = sqrt((-im_m * (im_m / re))) * 0.5d0
else if (re <= 1.18d+60) then
tmp = 0.5d0 * sqrt((2.0d0 * (im_m + re)))
else
tmp = 0.5d0 * sqrt((4.0d0 * re))
end if
code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if (re <= -4.2e-42) {
tmp = Math.sqrt((-im_m * (im_m / re))) * 0.5;
} else if (re <= 1.18e+60) {
tmp = 0.5 * Math.sqrt((2.0 * (im_m + re)));
} else {
tmp = 0.5 * Math.sqrt((4.0 * re));
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if re <= -4.2e-42: tmp = math.sqrt((-im_m * (im_m / re))) * 0.5 elif re <= 1.18e+60: tmp = 0.5 * math.sqrt((2.0 * (im_m + re))) else: tmp = 0.5 * math.sqrt((4.0 * re)) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (re <= -4.2e-42) tmp = Float64(sqrt(Float64(Float64(-im_m) * Float64(im_m / re))) * 0.5); elseif (re <= 1.18e+60) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im_m + re)))); else tmp = Float64(0.5 * sqrt(Float64(4.0 * re))); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if (re <= -4.2e-42) tmp = sqrt((-im_m * (im_m / re))) * 0.5; elseif (re <= 1.18e+60) tmp = 0.5 * sqrt((2.0 * (im_m + re))); else tmp = 0.5 * sqrt((4.0 * re)); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[re, -4.2e-42], N[(N[Sqrt[N[((-im$95$m) * N[(im$95$m / re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[re, 1.18e+60], N[(0.5 * N[Sqrt[N[(2.0 * N[(im$95$m + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.2 \cdot 10^{-42}:\\
\;\;\;\;\sqrt{\left(-im\_m\right) \cdot \frac{im\_m}{re}} \cdot 0.5\\
\mathbf{elif}\;re \leq 1.18 \cdot 10^{+60}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im\_m + re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{4 \cdot re}\\
\end{array}
\end{array}
if re < -4.20000000000000013e-42Initial program 14.5%
Taylor expanded in re around -inf
mul-1-negN/A
distribute-neg-fracN/A
lower-/.f64N/A
pow2N/A
distribute-lft-neg-outN/A
lower-*.f64N/A
lower-neg.f6443.7
Applied rewrites43.7%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6443.7
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6449.0
Applied rewrites49.0%
if -4.20000000000000013e-42 < re < 1.18000000000000008e60Initial program 59.5%
Taylor expanded in re around 0
Applied rewrites77.1%
if 1.18000000000000008e60 < re Initial program 32.9%
Taylor expanded in re around inf
lower-*.f6482.2
Applied rewrites82.2%
im_m = (fabs.f64 im)
(FPCore (re im_m)
:precision binary64
(if (<= re -4.2e-42)
(* 0.5 (sqrt (/ (* (- im_m) im_m) re)))
(if (<= re 1.18e+60)
(* 0.5 (sqrt (* 2.0 (+ im_m re))))
(* 0.5 (sqrt (* 4.0 re))))))im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (re <= -4.2e-42) {
tmp = 0.5 * sqrt(((-im_m * im_m) / re));
} else if (re <= 1.18e+60) {
tmp = 0.5 * sqrt((2.0 * (im_m + re)));
} else {
tmp = 0.5 * sqrt((4.0 * re));
}
return tmp;
}
im_m = private
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_m)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im_m
real(8) :: tmp
if (re <= (-4.2d-42)) then
tmp = 0.5d0 * sqrt(((-im_m * im_m) / re))
else if (re <= 1.18d+60) then
tmp = 0.5d0 * sqrt((2.0d0 * (im_m + re)))
else
tmp = 0.5d0 * sqrt((4.0d0 * re))
end if
code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if (re <= -4.2e-42) {
tmp = 0.5 * Math.sqrt(((-im_m * im_m) / re));
} else if (re <= 1.18e+60) {
tmp = 0.5 * Math.sqrt((2.0 * (im_m + re)));
} else {
tmp = 0.5 * Math.sqrt((4.0 * re));
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if re <= -4.2e-42: tmp = 0.5 * math.sqrt(((-im_m * im_m) / re)) elif re <= 1.18e+60: tmp = 0.5 * math.sqrt((2.0 * (im_m + re))) else: tmp = 0.5 * math.sqrt((4.0 * re)) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (re <= -4.2e-42) tmp = Float64(0.5 * sqrt(Float64(Float64(Float64(-im_m) * im_m) / re))); elseif (re <= 1.18e+60) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im_m + re)))); else tmp = Float64(0.5 * sqrt(Float64(4.0 * re))); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if (re <= -4.2e-42) tmp = 0.5 * sqrt(((-im_m * im_m) / re)); elseif (re <= 1.18e+60) tmp = 0.5 * sqrt((2.0 * (im_m + re))); else tmp = 0.5 * sqrt((4.0 * re)); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[re, -4.2e-42], N[(0.5 * N[Sqrt[N[(N[((-im$95$m) * im$95$m), $MachinePrecision] / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.18e+60], N[(0.5 * N[Sqrt[N[(2.0 * N[(im$95$m + re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4.2 \cdot 10^{-42}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{\left(-im\_m\right) \cdot im\_m}{re}}\\
\mathbf{elif}\;re \leq 1.18 \cdot 10^{+60}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im\_m + re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{4 \cdot re}\\
\end{array}
\end{array}
if re < -4.20000000000000013e-42Initial program 14.5%
Taylor expanded in re around -inf
mul-1-negN/A
distribute-neg-fracN/A
lower-/.f64N/A
pow2N/A
distribute-lft-neg-outN/A
lower-*.f64N/A
lower-neg.f6443.7
Applied rewrites43.7%
if -4.20000000000000013e-42 < re < 1.18000000000000008e60Initial program 59.5%
Taylor expanded in re around 0
Applied rewrites77.1%
if 1.18000000000000008e60 < re Initial program 32.9%
Taylor expanded in re around inf
lower-*.f6482.2
Applied rewrites82.2%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (if (<= re 3.9e+59) (* 0.5 (sqrt (+ im_m im_m))) (* 0.5 (sqrt (* 4.0 re)))))
im_m = fabs(im);
double code(double re, double im_m) {
double tmp;
if (re <= 3.9e+59) {
tmp = 0.5 * sqrt((im_m + im_m));
} else {
tmp = 0.5 * sqrt((4.0 * re));
}
return tmp;
}
im_m = private
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_m)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im_m
real(8) :: tmp
if (re <= 3.9d+59) then
tmp = 0.5d0 * sqrt((im_m + im_m))
else
tmp = 0.5d0 * sqrt((4.0d0 * re))
end if
code = tmp
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
double tmp;
if (re <= 3.9e+59) {
tmp = 0.5 * Math.sqrt((im_m + im_m));
} else {
tmp = 0.5 * Math.sqrt((4.0 * re));
}
return tmp;
}
im_m = math.fabs(im) def code(re, im_m): tmp = 0 if re <= 3.9e+59: tmp = 0.5 * math.sqrt((im_m + im_m)) else: tmp = 0.5 * math.sqrt((4.0 * re)) return tmp
im_m = abs(im) function code(re, im_m) tmp = 0.0 if (re <= 3.9e+59) tmp = Float64(0.5 * sqrt(Float64(im_m + im_m))); else tmp = Float64(0.5 * sqrt(Float64(4.0 * re))); end return tmp end
im_m = abs(im); function tmp_2 = code(re, im_m) tmp = 0.0; if (re <= 3.9e+59) tmp = 0.5 * sqrt((im_m + im_m)); else tmp = 0.5 * sqrt((4.0 * re)); end tmp_2 = tmp; end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := If[LessEqual[re, 3.9e+59], N[(0.5 * N[Sqrt[N[(im$95$m + im$95$m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
im_m = \left|im\right|
\\
\begin{array}{l}
\mathbf{if}\;re \leq 3.9 \cdot 10^{+59}:\\
\;\;\;\;0.5 \cdot \sqrt{im\_m + im\_m}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{4 \cdot re}\\
\end{array}
\end{array}
if re < 3.90000000000000021e59Initial program 43.7%
Taylor expanded in re around 0
count-2-revN/A
lower-+.f6459.9
Applied rewrites59.9%
if 3.90000000000000021e59 < re Initial program 33.1%
Taylor expanded in re around inf
lower-*.f6482.1
Applied rewrites82.1%
im_m = (fabs.f64 im) (FPCore (re im_m) :precision binary64 (* 0.5 (sqrt (+ im_m im_m))))
im_m = fabs(im);
double code(double re, double im_m) {
return 0.5 * sqrt((im_m + im_m));
}
im_m = private
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_m)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im_m
code = 0.5d0 * sqrt((im_m + im_m))
end function
im_m = Math.abs(im);
public static double code(double re, double im_m) {
return 0.5 * Math.sqrt((im_m + im_m));
}
im_m = math.fabs(im) def code(re, im_m): return 0.5 * math.sqrt((im_m + im_m))
im_m = abs(im) function code(re, im_m) return Float64(0.5 * sqrt(Float64(im_m + im_m))) end
im_m = abs(im); function tmp = code(re, im_m) tmp = 0.5 * sqrt((im_m + im_m)); end
im_m = N[Abs[im], $MachinePrecision] code[re_, im$95$m_] := N[(0.5 * N[Sqrt[N[(im$95$m + im$95$m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
im_m = \left|im\right|
\\
0.5 \cdot \sqrt{im\_m + im\_m}
\end{array}
Initial program 41.5%
Taylor expanded in re around 0
count-2-revN/A
lower-+.f6452.1
Applied rewrites52.1%
(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}
\\
\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}
\end{array}
herbie shell --seed 2025130
(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)))))