
(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 8 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)
(* 0.5 (exp (* (+ (log (/ -1.0 re)) (log (pow im 2.0))) 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 = 0.5 * exp(((log((-1.0 / re)) + log(pow(im, 2.0))) * 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 = 0.5 * Math.exp(((Math.log((-1.0 / re)) + Math.log(Math.pow(im, 2.0))) * 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 = 0.5 * math.exp(((math.log((-1.0 / re)) + math.log(math.pow(im, 2.0))) * 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(0.5 * exp(Float64(Float64(log(Float64(-1.0 / re)) + log((im ^ 2.0))) * 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 = 0.5 * exp(((log((-1.0 / re)) + log((im ^ 2.0))) * 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[(0.5 * N[Exp[N[(N[(N[Log[N[(-1.0 / re), $MachinePrecision]], $MachinePrecision] + N[Log[N[Power[im, 2.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]], $MachinePrecision]), $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:\\
\;\;\;\;0.5 \cdot e^{\left(\log \left(\frac{-1}{re}\right) + \log \left({im}^{2}\right)\right) \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 40.1%
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 rewrites78.6%
Taylor expanded in im around inf
lower-*.f6426.2%
Applied rewrites26.2%
lift-sqrt.f64N/A
pow1/2N/A
pow-to-expN/A
lower-unsound-exp.f64N/A
lower-unsound-*.f64N/A
lower-unsound-log.f6424.3%
lift-*.f64N/A
count-2-revN/A
lower-+.f6424.3%
Applied rewrites24.3%
Taylor expanded in re around -inf
lower-+.f64N/A
lower-log.f64N/A
lower-/.f64N/A
lower-log.f64N/A
lower-pow.f6416.9%
Applied rewrites16.9%
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 40.1%
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 rewrites78.6%
(FPCore (re im)
:precision binary64
(if (<=
(* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re))))
0.0)
(* (sqrt (* (- im) (/ im 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((-im * (im / 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((-im * (im / 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((-im * (im / 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(Float64(-im) * Float64(im / 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((-im * (im / 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[((-im) * N[(im / 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{\left(-im\right) \cdot \frac{im}{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 40.1%
Taylor expanded in re around -inf
lower-*.f64N/A
lower-/.f64N/A
lower-pow.f6415.2%
Applied rewrites15.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6415.2%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
lift-pow.f64N/A
pow2N/A
mult-flipN/A
associate-*l*N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
mult-flip-revN/A
lower-/.f6418.0%
Applied rewrites18.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 40.1%
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 rewrites78.6%
(FPCore (re im)
:precision binary64
(if (<= re -1.5e+83)
(* (sqrt (* (- (fabs im)) (/ (fabs im) re))) 0.5)
(if (<= re 8.5e+129)
(* (sqrt (* (+ (fabs im) re) 2.0)) 0.5)
(* 0.5 (sqrt (* 4.0 re))))))double code(double re, double im) {
double tmp;
if (re <= -1.5e+83) {
tmp = sqrt((-fabs(im) * (fabs(im) / re))) * 0.5;
} else if (re <= 8.5e+129) {
tmp = sqrt(((fabs(im) + re) * 2.0)) * 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 <= (-1.5d+83)) then
tmp = sqrt((-abs(im) * (abs(im) / re))) * 0.5d0
else if (re <= 8.5d+129) then
tmp = sqrt(((abs(im) + re) * 2.0d0)) * 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 <= -1.5e+83) {
tmp = Math.sqrt((-Math.abs(im) * (Math.abs(im) / re))) * 0.5;
} else if (re <= 8.5e+129) {
tmp = Math.sqrt(((Math.abs(im) + re) * 2.0)) * 0.5;
} else {
tmp = 0.5 * Math.sqrt((4.0 * re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.5e+83: tmp = math.sqrt((-math.fabs(im) * (math.fabs(im) / re))) * 0.5 elif re <= 8.5e+129: tmp = math.sqrt(((math.fabs(im) + re) * 2.0)) * 0.5 else: tmp = 0.5 * math.sqrt((4.0 * re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.5e+83) tmp = Float64(sqrt(Float64(Float64(-abs(im)) * Float64(abs(im) / re))) * 0.5); elseif (re <= 8.5e+129) tmp = Float64(sqrt(Float64(Float64(abs(im) + re) * 2.0)) * 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 <= -1.5e+83) tmp = sqrt((-abs(im) * (abs(im) / re))) * 0.5; elseif (re <= 8.5e+129) tmp = sqrt(((abs(im) + re) * 2.0)) * 0.5; else tmp = 0.5 * sqrt((4.0 * re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.5e+83], N[(N[Sqrt[N[((-N[Abs[im], $MachinePrecision]) * N[(N[Abs[im], $MachinePrecision] / re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[re, 8.5e+129], N[(N[Sqrt[N[(N[(N[Abs[im], $MachinePrecision] + re), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(0.5 * N[Sqrt[N[(4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;re \leq -1.5 \cdot 10^{+83}:\\
\;\;\;\;\sqrt{\left(-\left|im\right|\right) \cdot \frac{\left|im\right|}{re}} \cdot 0.5\\
\mathbf{elif}\;re \leq 8.5 \cdot 10^{+129}:\\
\;\;\;\;\sqrt{\left(\left|im\right| + re\right) \cdot 2} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{4 \cdot re}\\
\end{array}
if re < -1.5e83Initial program 40.1%
Taylor expanded in re around -inf
lower-*.f64N/A
lower-/.f64N/A
lower-pow.f6415.2%
Applied rewrites15.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6415.2%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
lift-pow.f64N/A
pow2N/A
mult-flipN/A
associate-*l*N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
mult-flip-revN/A
lower-/.f6418.0%
Applied rewrites18.0%
if -1.5e83 < re < 8.5000000000000001e129Initial program 40.1%
Taylor expanded in im around inf
lower-*.f64N/A
lower-+.f64N/A
lower-/.f6428.8%
Applied rewrites28.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6428.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6428.8%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
lift-/.f64N/A
sum-to-mult-revN/A
lower-+.f6429.9%
Applied rewrites29.9%
if 8.5000000000000001e129 < re Initial program 40.1%
Taylor expanded in im around inf
lower-*.f64N/A
lower-+.f64N/A
lower-/.f6428.8%
Applied rewrites28.8%
Taylor expanded in re around inf
lower-*.f6426.3%
Applied rewrites26.3%
(FPCore (re im)
:precision binary64
(if (<= re -1.5e+83)
(* 0.5 (sqrt (/ (* (- (fabs im)) (fabs im)) re)))
(if (<= re 8.5e+129)
(* (sqrt (* (+ (fabs im) re) 2.0)) 0.5)
(* 0.5 (sqrt (* 4.0 re))))))double code(double re, double im) {
double tmp;
if (re <= -1.5e+83) {
tmp = 0.5 * sqrt(((-fabs(im) * fabs(im)) / re));
} else if (re <= 8.5e+129) {
tmp = sqrt(((fabs(im) + re) * 2.0)) * 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 <= (-1.5d+83)) then
tmp = 0.5d0 * sqrt(((-abs(im) * abs(im)) / re))
else if (re <= 8.5d+129) then
tmp = sqrt(((abs(im) + re) * 2.0d0)) * 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 <= -1.5e+83) {
tmp = 0.5 * Math.sqrt(((-Math.abs(im) * Math.abs(im)) / re));
} else if (re <= 8.5e+129) {
tmp = Math.sqrt(((Math.abs(im) + re) * 2.0)) * 0.5;
} else {
tmp = 0.5 * Math.sqrt((4.0 * re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.5e+83: tmp = 0.5 * math.sqrt(((-math.fabs(im) * math.fabs(im)) / re)) elif re <= 8.5e+129: tmp = math.sqrt(((math.fabs(im) + re) * 2.0)) * 0.5 else: tmp = 0.5 * math.sqrt((4.0 * re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.5e+83) tmp = Float64(0.5 * sqrt(Float64(Float64(Float64(-abs(im)) * abs(im)) / re))); elseif (re <= 8.5e+129) tmp = Float64(sqrt(Float64(Float64(abs(im) + re) * 2.0)) * 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 <= -1.5e+83) tmp = 0.5 * sqrt(((-abs(im) * abs(im)) / re)); elseif (re <= 8.5e+129) tmp = sqrt(((abs(im) + re) * 2.0)) * 0.5; else tmp = 0.5 * sqrt((4.0 * re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.5e+83], N[(0.5 * N[Sqrt[N[(N[((-N[Abs[im], $MachinePrecision]) * N[Abs[im], $MachinePrecision]), $MachinePrecision] / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 8.5e+129], N[(N[Sqrt[N[(N[(N[Abs[im], $MachinePrecision] + re), $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision], N[(0.5 * N[Sqrt[N[(4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\mathbf{if}\;re \leq -1.5 \cdot 10^{+83}:\\
\;\;\;\;0.5 \cdot \sqrt{\frac{\left(-\left|im\right|\right) \cdot \left|im\right|}{re}}\\
\mathbf{elif}\;re \leq 8.5 \cdot 10^{+129}:\\
\;\;\;\;\sqrt{\left(\left|im\right| + re\right) \cdot 2} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{4 \cdot re}\\
\end{array}
if re < -1.5e83Initial program 40.1%
Taylor expanded in re around -inf
lower-*.f64N/A
lower-/.f64N/A
lower-pow.f6415.2%
Applied rewrites15.2%
lift-*.f64N/A
mul-1-negN/A
lift-/.f64N/A
lift-pow.f64N/A
pow2N/A
distribute-neg-fracN/A
lower-/.f64N/A
distribute-lft-neg-outN/A
lower-*.f64N/A
lower-neg.f6415.2%
Applied rewrites15.2%
if -1.5e83 < re < 8.5000000000000001e129Initial program 40.1%
Taylor expanded in im around inf
lower-*.f64N/A
lower-+.f64N/A
lower-/.f6428.8%
Applied rewrites28.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6428.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6428.8%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
lift-/.f64N/A
sum-to-mult-revN/A
lower-+.f6429.9%
Applied rewrites29.9%
if 8.5000000000000001e129 < re Initial program 40.1%
Taylor expanded in im around inf
lower-*.f64N/A
lower-+.f64N/A
lower-/.f6428.8%
Applied rewrites28.8%
Taylor expanded in re around inf
lower-*.f6426.3%
Applied rewrites26.3%
(FPCore (re im) :precision binary64 (if (<= re 8.5e+129) (* (sqrt (* (+ (fabs im) re) 2.0)) 0.5) (* 0.5 (sqrt (* 4.0 re)))))
double code(double re, double im) {
double tmp;
if (re <= 8.5e+129) {
tmp = sqrt(((fabs(im) + re) * 2.0)) * 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 <= 8.5d+129) then
tmp = sqrt(((abs(im) + re) * 2.0d0)) * 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 <= 8.5e+129) {
tmp = Math.sqrt(((Math.abs(im) + re) * 2.0)) * 0.5;
} else {
tmp = 0.5 * Math.sqrt((4.0 * re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 8.5e+129: tmp = math.sqrt(((math.fabs(im) + re) * 2.0)) * 0.5 else: tmp = 0.5 * math.sqrt((4.0 * re)) return tmp
function code(re, im) tmp = 0.0 if (re <= 8.5e+129) tmp = Float64(sqrt(Float64(Float64(abs(im) + re) * 2.0)) * 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 <= 8.5e+129) tmp = sqrt(((abs(im) + re) * 2.0)) * 0.5; else tmp = 0.5 * sqrt((4.0 * re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 8.5e+129], N[(N[Sqrt[N[(N[(N[Abs[im], $MachinePrecision] + re), $MachinePrecision] * 2.0), $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.5 \cdot 10^{+129}:\\
\;\;\;\;\sqrt{\left(\left|im\right| + re\right) \cdot 2} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{4 \cdot re}\\
\end{array}
if re < 8.5000000000000001e129Initial program 40.1%
Taylor expanded in im around inf
lower-*.f64N/A
lower-+.f64N/A
lower-/.f6428.8%
Applied rewrites28.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6428.8%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6428.8%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
lift-/.f64N/A
sum-to-mult-revN/A
lower-+.f6429.9%
Applied rewrites29.9%
if 8.5000000000000001e129 < re Initial program 40.1%
Taylor expanded in im around inf
lower-*.f64N/A
lower-+.f64N/A
lower-/.f6428.8%
Applied rewrites28.8%
Taylor expanded in re around inf
lower-*.f6426.3%
Applied rewrites26.3%
(FPCore (re im) :precision binary64 (if (<= re 3.25e+100) (* (sqrt (+ (fabs im) (fabs im))) 0.5) (* 0.5 (sqrt (* 4.0 re)))))
double code(double re, double im) {
double tmp;
if (re <= 3.25e+100) {
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 <= 3.25d+100) 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 <= 3.25e+100) {
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 <= 3.25e+100: 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 <= 3.25e+100) 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 <= 3.25e+100) 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, 3.25e+100], 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 3.25 \cdot 10^{+100}:\\
\;\;\;\;\sqrt{\left|im\right| + \left|im\right|} \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{4 \cdot re}\\
\end{array}
if re < 3.25e100Initial program 40.1%
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 rewrites78.6%
Taylor expanded in im around inf
lower-*.f6426.2%
Applied rewrites26.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6426.2%
lift-*.f64N/A
count-2-revN/A
lower-+.f6426.2%
Applied rewrites26.2%
if 3.25e100 < re Initial program 40.1%
Taylor expanded in im around inf
lower-*.f64N/A
lower-+.f64N/A
lower-/.f6428.8%
Applied rewrites28.8%
Taylor expanded in re around inf
lower-*.f6426.3%
Applied rewrites26.3%
(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 40.1%
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 rewrites78.6%
Taylor expanded in im around inf
lower-*.f6426.2%
Applied rewrites26.2%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6426.2%
lift-*.f64N/A
count-2-revN/A
lower-+.f6426.2%
Applied rewrites26.2%
(FPCore (re im) :precision binary64 (* 0.7071067811865476 (sqrt (fabs im))))
double code(double re, double im) {
return 0.7071067811865476 * sqrt(fabs(im));
}
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.7071067811865476d0 * sqrt(abs(im))
end function
public static double code(double re, double im) {
return 0.7071067811865476 * Math.sqrt(Math.abs(im));
}
def code(re, im): return 0.7071067811865476 * math.sqrt(math.fabs(im))
function code(re, im) return Float64(0.7071067811865476 * sqrt(abs(im))) end
function tmp = code(re, im) tmp = 0.7071067811865476 * sqrt(abs(im)); end
code[re_, im_] := N[(0.7071067811865476 * N[Sqrt[N[Abs[im], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
0.7071067811865476 \cdot \sqrt{\left|im\right|}
Initial program 40.1%
lift-sqrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
sqrt-prodN/A
lower-unsound-*.f64N/A
Applied rewrites39.8%
Evaluated real constant39.8%
Taylor expanded in im around inf
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f6426.0%
Applied rewrites26.0%
Taylor expanded in im around 0
lower-sqrt.f6426.0%
Applied rewrites26.0%
(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 2025223
(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)))))